begin with failing test

This commit is contained in:
Ken Stevens 2021-02-03 15:01:12 -05:00
parent dd13827290
commit 3dac899e3a
1 changed files with 107 additions and 88 deletions

View File

@ -1,40 +1,61 @@
package ca.uhn.fhir.jpa.dao.r4; package ca.uhn.fhir.jpa.dao.r4;
import static ca.uhn.fhir.rest.api.Constants.PARAM_TYPE; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import static org.apache.commons.lang3.StringUtils.countMatches; import ca.uhn.fhir.interceptor.api.HookParams;
import static org.hamcrest.MatcherAssert.assertThat; import ca.uhn.fhir.interceptor.api.IAnonymousInterceptor;
import static org.hamcrest.Matchers.contains; import ca.uhn.fhir.interceptor.api.Pointcut;
import static org.hamcrest.Matchers.containsInAnyOrder; import ca.uhn.fhir.jpa.api.config.DaoConfig;
import static org.hamcrest.Matchers.containsString; import ca.uhn.fhir.jpa.entity.Search;
import static org.hamcrest.Matchers.empty; import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import static org.hamcrest.Matchers.endsWith; import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import ca.uhn.fhir.jpa.model.entity.NormalizedQuantitySearchLevel; import ca.uhn.fhir.jpa.model.entity.NormalizedQuantitySearchLevel;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamDate;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamNumber;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamQuantity;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamQuantityNormalized;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamUri;
import ca.uhn.fhir.jpa.model.entity.ResourceLink;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.model.search.StorageProcessingMessage;
import ca.uhn.fhir.jpa.model.util.UcumServiceUtil;
import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap.EverythingModeEnum;
import ca.uhn.fhir.jpa.util.SqlQuery;
import ca.uhn.fhir.jpa.util.TestUtil;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.parser.StrictErrorHandler;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.CompositeParam;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.HasOrListParam;
import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.NumberParam;
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
import ca.uhn.fhir.rest.param.QuantityParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.ReferenceOrListParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.param.TokenOrListParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.TokenParamModifier;
import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.param.UriParamQualifierEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import ca.uhn.fhir.util.HapiExtensions;
import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
@ -116,61 +137,38 @@ import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
import com.google.common.collect.Lists; import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import static ca.uhn.fhir.rest.api.Constants.PARAM_TYPE;
import ca.uhn.fhir.interceptor.api.HookParams; import static org.apache.commons.lang3.StringUtils.countMatches;
import ca.uhn.fhir.interceptor.api.IAnonymousInterceptor; import static org.hamcrest.MatcherAssert.assertThat;
import ca.uhn.fhir.interceptor.api.Pointcut; import static org.hamcrest.Matchers.contains;
import ca.uhn.fhir.jpa.api.config.DaoConfig; import static org.hamcrest.Matchers.containsInAnyOrder;
import ca.uhn.fhir.jpa.entity.Search; import static org.hamcrest.Matchers.containsString;
import ca.uhn.fhir.jpa.model.config.PartitionSettings; import static org.hamcrest.Matchers.empty;
import ca.uhn.fhir.jpa.model.entity.ModelConfig; import static org.hamcrest.Matchers.endsWith;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamDate; import static org.hamcrest.Matchers.hasItem;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamNumber; import static org.hamcrest.Matchers.hasItems;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamQuantity; import static org.hamcrest.Matchers.hasSize;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamQuantityNormalized; import static org.hamcrest.Matchers.not;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString; import static org.junit.jupiter.api.Assertions.assertEquals;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken; import static org.junit.jupiter.api.Assertions.assertFalse;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamUri; import static org.junit.jupiter.api.Assertions.assertNull;
import ca.uhn.fhir.jpa.model.entity.ResourceLink; import static org.junit.jupiter.api.Assertions.assertTrue;
import ca.uhn.fhir.jpa.model.entity.ResourceTable; import static org.junit.jupiter.api.Assertions.fail;
import ca.uhn.fhir.jpa.model.search.StorageProcessingMessage; import static org.mockito.Mockito.mock;
import ca.uhn.fhir.jpa.searchparam.MatchUrlService; import static org.mockito.Mockito.times;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import static org.mockito.Mockito.verify;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap.EverythingModeEnum;
import ca.uhn.fhir.jpa.util.SqlQuery;
import ca.uhn.fhir.jpa.util.TestUtil;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.parser.StrictErrorHandler;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.CompositeParam;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.HasOrListParam;
import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.NumberParam;
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
import ca.uhn.fhir.rest.param.QuantityParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.ReferenceOrListParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.param.TokenOrListParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.TokenParamModifier;
import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.param.UriParamQualifierEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import ca.uhn.fhir.util.HapiExtensions;
import ca.uhn.fhir.jpa.model.util.UcumServiceUtil;
@SuppressWarnings({"unchecked", "Duplicates"}) @SuppressWarnings({"unchecked", "Duplicates"})
public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
@ -5165,6 +5163,27 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
} }
} }
@Test
public void testIssueDateFormatError1465() {
try {
SearchParameterMap map = SearchParameterMap.newSynchronous();
map.add("birthdate", new DateParam("09-30-1960"));
myPatientDao.search(map);
fail();
} catch (DataFormatException e) {
assertEquals("Invalid date/time format: \"09-30-1960\"", e.getMessage());
}
try {
SearchParameterMap map = SearchParameterMap.newSynchronous();
map.add("birthdate", new DateParam("junk"));
myPatientDao.search(map);
fail();
} catch (DataFormatException e) {
assertEquals("Invalid date/time format: \"junk\"", e.getMessage());
}
}
@Test @Test
public void testDateSearchParametersShouldBeTimezoneIndependent() { public void testDateSearchParametersShouldBeTimezoneIndependent() {