Test fixes
This commit is contained in:
parent
9e8af58e81
commit
74c83f6148
|
@ -28,6 +28,8 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
public enum EncodingEnum {
|
||||
|
||||
JSON(Constants.CT_FHIR_JSON, Constants.CT_FHIR_JSON_NEW, Constants.FORMAT_JSON) {
|
||||
|
@ -166,7 +168,10 @@ public enum EncodingEnum {
|
|||
* is found.
|
||||
* <p>
|
||||
* <b>This method is lenient!</b> Things like "application/xml" will return {@link EncodingEnum#XML}
|
||||
* even if the "+fhir" part is missing from the expected content type.
|
||||
* even if the "+fhir" part is missing from the expected content type. Also,
|
||||
* spaces are treated as a plus (i.e. "application/fhir json" will be treated as
|
||||
* "application/fhir+json" in order to account for unescaped spaces in URL
|
||||
* parameters)
|
||||
* </p>
|
||||
*/
|
||||
public static EncodingEnum forContentType(final String theContentType) {
|
||||
|
@ -198,7 +203,7 @@ public enum EncodingEnum {
|
|||
}
|
||||
|
||||
static String getTypeWithoutCharset(final String theContentType) {
|
||||
if (theContentType == null) {
|
||||
if (isBlank(theContentType)) {
|
||||
return null;
|
||||
} else {
|
||||
|
||||
|
@ -210,12 +215,22 @@ public enum EncodingEnum {
|
|||
}
|
||||
int end = start;
|
||||
for (; end < theContentType.length(); end++) {
|
||||
if (theContentType.charAt(end) == ' ' || theContentType.charAt(end) == ';') {
|
||||
if (theContentType.charAt(end) == ';') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; end > start; end--) {
|
||||
if (theContentType.charAt(end - 1) != ' ') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return theContentType.substring(start, end);
|
||||
String retVal = theContentType.substring(start, end);
|
||||
|
||||
if (retVal.contains(" ")) {
|
||||
retVal = retVal.replace(' ', '+');
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,4 +14,11 @@ public class EncodingEnumTest {
|
|||
assertEquals("text/plain", EncodingEnum.getTypeWithoutCharset(" text/plain ; charset=utf-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTypeWithSpace() {
|
||||
assertEquals("application/fhir xml", EncodingEnum.getTypeWithoutCharset("application/fhir+xml"));
|
||||
assertEquals("application/fhir xml", EncodingEnum.getTypeWithoutCharset("application/fhir+xml; charset=utf-8"));
|
||||
assertEquals("application/fhir xml", EncodingEnum.getTypeWithoutCharset("application/fhir+xml ; charset=utf-8"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import ca.uhn.fhir.jpa.config.TestR4Config;
|
|||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.provider.r4.BaseResourceProviderR4Test;
|
||||
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||
import ca.uhn.fhir.jpa.search.ISearchCoordinatorSvc;
|
||||
import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl;
|
||||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||
import ca.uhn.fhir.rest.api.SortSpec;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
|
@ -35,6 +37,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.util.AopTestUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -77,6 +80,11 @@ public class StressTestR4Test extends BaseResourceProviderR4Test {
|
|||
myDaoConfig.setIndexMissingFields(DaoConfig.IndexEnabledEnum.ENABLED);
|
||||
|
||||
myPagingProvider.setMaximumPageSize(myPreviousMaxPageSize);
|
||||
|
||||
SearchCoordinatorSvcImpl searchCoordinator = AopTestUtils.getTargetObject(mySearchCoordinatorSvc);
|
||||
searchCoordinator.setLoadingThrottleForUnitTests(null);
|
||||
myDaoConfig.setSearchPreFetchThresholds(new DaoConfig().getSearchPreFetchThresholds());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,15 +101,22 @@ public class StressTestR4Test extends BaseResourceProviderR4Test {
|
|||
myPagingProvider.setMaximumPageSize(300);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private ISearchCoordinatorSvc mySearchCoordinatorSvc;
|
||||
|
||||
|
||||
@Test
|
||||
public void testNoDuplicatesInSearchResults() throws Exception {
|
||||
int count = 1000;
|
||||
int resourceCount = 1000;
|
||||
int queryCount = 30;
|
||||
myDaoConfig.setSearchPreFetchThresholds(Lists.newArrayList(50, 200, -1));
|
||||
|
||||
SearchCoordinatorSvcImpl searchCoordinator = AopTestUtils.getTargetObject(mySearchCoordinatorSvc);
|
||||
searchCoordinator.setLoadingThrottleForUnitTests(10);
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < resourceCount; i++) {
|
||||
Observation o = new Observation();
|
||||
o.setId("A" + leftPad(Integer.toString(i), 4, '0'));
|
||||
o.setEffective( DateTimeType.now());
|
||||
|
@ -124,7 +139,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test {
|
|||
Bundle searchResult = fhirClient
|
||||
.search()
|
||||
.byUrl(url)
|
||||
.count(300)
|
||||
.count(queryCount)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
while(true) {
|
||||
|
@ -150,10 +165,10 @@ public class StressTestR4Test extends BaseResourceProviderR4Test {
|
|||
if (searchResult.getLink(Constants.LINK_NEXT) == null) {
|
||||
break;
|
||||
} else {
|
||||
if (searchResult.getEntry().size() != 300) {
|
||||
if (searchResult.getEntry().size() != queryCount) {
|
||||
throw new Exception("Page had " + searchResult.getEntry().size() + " resources");
|
||||
}
|
||||
if (passIds.size() != 300) {
|
||||
if (passIds.size() != queryCount) {
|
||||
throw new Exception("Page had " + passIds.size() + " unique ids");
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +178,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test {
|
|||
searchResult = fhirClient.loadPage().next(searchResult).execute();
|
||||
}
|
||||
|
||||
assertEquals(count, ids.size());
|
||||
assertEquals(resourceCount, ids.size());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -319,16 +319,16 @@ public class ServerMimetypeR4Test {
|
|||
public void testSearchWithFormatJsonNew() throws Exception {
|
||||
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=" + Constants.CT_FHIR_JSON_NEW);
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
||||
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(responseContent, containsString("\"resourceType\""));
|
||||
assertEquals(Constants.CT_FHIR_JSON_NEW, status.getFirstHeader("content-type").getValue().replaceAll(";.*", ""));
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(responseContent, containsString("\"resourceType\""));
|
||||
assertEquals(Constants.CT_FHIR_JSON_NEW, status.getFirstHeader("content-type").getValue().replaceAll(";.*", ""));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue