Replace hamcrest with assertj (#5911)

* optimize imports

* optimize imports

* Hamcrest replacement

* Hamcrest replacement

* Test failures

* migrate hapi-fhir-base

* docs

* Few more cutovers

* Full rewrite of all assert cases

* Full rewrite of all assert cases

* Partial cutover

* assert library conversion

* wip

* fix imports

* remove equalto

* once-over again

* minor cutover

* wip

* wip

* wip

* wip

* wip

* Remove hamcrest asserts replace with assertj

* wip

* Partial hamcrest rip-out

* More hamcrest stripping

* wip

* Partial completion

* spotless

* it compiles now

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fixing compile issues

* fix compile issues

* fix compile issues

* hapi-fhir now compiles

* fix test

* fix test

* fix test

* fix tests

* fix tests

* fix tests

* fix test

* fix test

* fix tests

* fix tests

* fix tests

* yay all tests pass now!

* revert assertEquals change

* revert assertEquals change

* organize imports

* organize imports

* organize imports

* post merge cleanup

* organize imports

* more cleanup

* more cleanup

* removing hamcrest stragglers

* removing hamcrest stragglers

* removing hamcrest stragglers

* removing hamcrest stragglers

* removing hamcrest stragglers

* removing hamcrest stragglers

* removing hamcrest stragglers

* removing hamcrest stragglers

* removing hamcrest stragglers

* removing hamcrest stragglers

* removing hamcrest stragglers

* organize imports

* organize imports

* remove final hamcrest stuff

* remove final hamcrest usages

* remove final hamcrest usages

* Revert "remove final hamcrest usages"

This reverts commit eaf5107396.

* fix compile issues from a hacky search/replace

* compiles with fixmes

* fix tests

* fix test

* fix test

* fix post merge compile issues

* fix post merge compile issues

* fix post merge compile issues

* fix post merge compile issues

* fix post merge compile issues

* fix post merge test issues

* fix test

* fix test

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* replace hamcrest with assertj

* all but mdm tests

* final hamcrest removed from hapi-fhir yay!

* revert mdm changes. it's too hard for now

* revert cdr breaking change

* revert cdr breaking changes

* revert cdr breaking changes

* revert cdr breaking changes

* revert cdr breaking changes

* revert changes that break cdr

* merge master with compile errors

* review feedback

* review feedback

* review feedback: revert bad regexp change

* fix test

* fix test

* convert new hamcrest entries

* convert new hamcrest entries

---------

Co-authored-by: Tadgh <garygrantgraham@gmail.com>
This commit is contained in:
Ken Stevens 2024-06-05 16:02:46 -04:00 committed by GitHub
parent 575b689d76
commit cdf5b602c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2145 changed files with 26354 additions and 28490 deletions

View File

@ -60,7 +60,7 @@ public class BuiltJarDstu2IT {
ctx.newXmlParser().encodeResourceToString(p); ctx.newXmlParser().encodeResourceToString(p);
fail(); fail();
} catch (ca.uhn.fhir.context.ConfigurationException e) { } catch (ca.uhn.fhir.context.ConfigurationException e) {
assertEquals(Msg.code(1754) + "Unable to initialize StAX - XML processing is disabled",e.getMessage()); assertEquals(Msg.code(1754) + "Unable to initialize StAX - XML processing is disabled", e.getMessage());
} }
} }

View File

@ -37,9 +37,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import static org.hamcrest.CoreMatchers.startsWith; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
@ -126,7 +124,7 @@ public class GenericClientDstu3IT {
Request request = capt.getAllValues().get(0); Request request = capt.getAllValues().get(0);
ourLog.info(request.headers().toString()); ourLog.info(request.headers().toString());
assertThat(request.url().toString(), startsWith("http://example.com/fhir/Binary")); assertThat(request.url().toString()).startsWith("http://example.com/fhir/Binary");
validateUserAgent(capt); validateUserAgent(capt);
assertEquals(Constants.CT_FHIR_JSON_NEW + ";charset=utf-8", request.body().contentType().toString().toLowerCase().replace(" ", "")); assertEquals(Constants.CT_FHIR_JSON_NEW + ";charset=utf-8", request.body().contentType().toString().toLowerCase().replace(" ", ""));
@ -201,7 +199,7 @@ public class GenericClientDstu3IT {
assertEquals(Constants.CT_FHIR_JSON_NEW + ";charset=utf-8", request.body().contentType().toString().toLowerCase().replace(" ", "")); assertEquals(Constants.CT_FHIR_JSON_NEW + ";charset=utf-8", request.body().contentType().toString().toLowerCase().replace(" ", ""));
assertEquals(Constants.HEADER_ACCEPT_VALUE_JSON_NON_LEGACY, request.header("Accept")); assertEquals(Constants.HEADER_ACCEPT_VALUE_JSON_NON_LEGACY, request.header("Accept"));
assertArrayEquals(new byte[] { 0, 1, 2, 3, 4 }, ourCtx.newJsonParser().parseResource(Binary.class, extractBodyAsString(capt)).getContent()); assertThat(ourCtx.newJsonParser().parseResource(Binary.class, extractBodyAsString(capt)).getContent()).containsExactly(new byte[]{0, 1, 2, 3, 4});
} }
@ -270,7 +268,7 @@ public class GenericClientDstu3IT {
assertNull(outcome.getOperationOutcome()); assertNull(outcome.getOperationOutcome());
assertNotNull(outcome.getResource()); assertNotNull(outcome.getResource());
assertEquals(1, capt.getAllValues().size()); assertThat(capt.getAllValues()).hasSize(1);
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">FINAL VALUE</div>", ((Patient) outcome.getResource()).getText().getDivAsString()); assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">FINAL VALUE</div>", ((Patient) outcome.getResource()).getText().getDivAsString());
assertEquals("http://example.com/fhir/Patient?_format=json", capt.getAllValues().get(0).url().toString()); assertEquals("http://example.com/fhir/Patient?_format=json", capt.getAllValues().get(0).url().toString());
} }

View File

@ -4,7 +4,6 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class RuntimeSearchParamTest { public class RuntimeSearchParamTest {

View File

@ -1,16 +1,14 @@
package ca.uhn.fhir.context.phonetic; package ca.uhn.fhir.context.phonetic;
import ca.uhn.fhir.util.PhoneticEncoderUtil; import ca.uhn.fhir.util.PhoneticEncoderUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.EnumSource;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class PhoneticEncoderTest { public class PhoneticEncoderTest {
private static final Logger ourLog = LoggerFactory.getLogger(PhoneticEncoderTest.class); private static final Logger ourLog = LoggerFactory.getLogger(PhoneticEncoderTest.class);
@ -24,14 +22,14 @@ public class PhoneticEncoderTest {
@EnumSource(PhoneticEncoderEnum.class) @EnumSource(PhoneticEncoderEnum.class)
public void testEncodeAddress(PhoneticEncoderEnum thePhoneticEncoderEnum) { public void testEncodeAddress(PhoneticEncoderEnum thePhoneticEncoderEnum) {
IPhoneticEncoder encoder = PhoneticEncoderUtil.getEncoder(thePhoneticEncoderEnum.name()); IPhoneticEncoder encoder = PhoneticEncoderUtil.getEncoder(thePhoneticEncoderEnum.name());
Assertions.assertNotNull(encoder); assertNotNull(encoder);
String encoded = encoder.encode(ADDRESS_LINE); String encoded = encoder.encode(ADDRESS_LINE);
ourLog.info("{}: {}", thePhoneticEncoderEnum.name(), encoded); ourLog.info("{}: {}", thePhoneticEncoderEnum.name(), encoded);
if (thePhoneticEncoderEnum == PhoneticEncoderEnum.NUMERIC) { if (thePhoneticEncoderEnum == PhoneticEncoderEnum.NUMERIC) {
assertEquals(NUMBER + SUITE, encoded); assertEquals(NUMBER + SUITE, encoded);
} else { } else {
assertThat(encoded, startsWith(NUMBER + " ")); assertThat(encoded).startsWith(NUMBER + " ");
assertThat(encoded, endsWith(" " + SUITE)); assertThat(encoded).endsWith(" " + SUITE);
} }
} }
} }

View File

@ -4,10 +4,7 @@ import org.junit.jupiter.api.Test;
import java.util.Set; import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class HapiLocalizerTest { public class HapiLocalizerTest {
@ -18,7 +15,7 @@ public class HapiLocalizerTest {
assertEquals("some message", loc.newMessageFormat("some message").format(new Object[]{})); assertEquals("some message", loc.newMessageFormat("some message").format(new Object[]{}));
assertEquals("var1 {var2} var3 {var4}", loc.newMessageFormat("var1 {var2} var3 {var4}").format(new Object[]{})); assertEquals("var1 {var2} var3 {var4}", loc.newMessageFormat("var1 {var2} var3 {var4}").format(new Object[]{}));
assertEquals("var1 A var3 B", loc.newMessageFormat("var1 {0} var3 {1}").format(new Object[]{ "A", "B"})); assertEquals("var1 A var3 B", loc.newMessageFormat("var1 {0} var3 {1}").format(new Object[]{"A", "B"}));
} }
@ -26,7 +23,7 @@ public class HapiLocalizerTest {
public void testAllKeys() { public void testAllKeys() {
HapiLocalizer svc = new HapiLocalizer(); HapiLocalizer svc = new HapiLocalizer();
Set<String> allKeys = svc.getAllKeys(); Set<String> allKeys = svc.getAllKeys();
assertThat(allKeys, not(empty())); assertThat(allKeys).isNotEmpty();
for (String next : allKeys) { for (String next : allKeys) {
svc.getMessage(next); svc.getMessage(next);
@ -37,7 +34,7 @@ public class HapiLocalizerTest {
public void testGetVersion() { public void testGetVersion() {
HapiLocalizer svc = new HapiLocalizer(); HapiLocalizer svc = new HapiLocalizer();
String version = svc.getMessage("hapi.version"); String version = svc.getMessage("hapi.version");
assertThat(version, matchesPattern("[0-9]+.*")); assertThat(version).matches("[0-9]+.*");
} }
} }

View File

@ -19,10 +19,13 @@ import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.hamcrest.CoreMatchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.Matchers.contains; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class InterceptorServiceTest { public class InterceptorServiceTest {
@ -185,7 +188,7 @@ public class InterceptorServiceTest {
// good // good
} }
assertEquals(initialSize, svc.getGlobalInterceptorsForUnitTest().size()); assertThat(svc.getGlobalInterceptorsForUnitTest()).hasSize(initialSize);
} }
@ -206,7 +209,7 @@ public class InterceptorServiceTest {
MyTestInterceptorManual myInterceptorManual = new MyTestInterceptorManual(); MyTestInterceptorManual myInterceptorManual = new MyTestInterceptorManual();
svc.registerInterceptor(myInterceptorManual); svc.registerInterceptor(myInterceptorManual);
List<Object> globalInterceptors = svc.getGlobalInterceptorsForUnitTest(); List<Object> globalInterceptors = svc.getGlobalInterceptorsForUnitTest();
assertEquals(3, globalInterceptors.size()); assertThat(globalInterceptors).hasSize(3);
assertInstanceOf(MyTestInterceptorOne.class, globalInterceptors.get(0), globalInterceptors.get(0).getClass().toString()); assertInstanceOf(MyTestInterceptorOne.class, globalInterceptors.get(0), globalInterceptors.get(0).getClass().toString());
assertInstanceOf(MyTestInterceptorManual.class, globalInterceptors.get(1), globalInterceptors.get(1).getClass().toString()); assertInstanceOf(MyTestInterceptorManual.class, globalInterceptors.get(1), globalInterceptors.get(1).getClass().toString());
assertInstanceOf(MyTestInterceptorTwo.class, globalInterceptors.get(2), globalInterceptors.get(2).getClass().toString()); assertInstanceOf(MyTestInterceptorTwo.class, globalInterceptors.get(2), globalInterceptors.get(2).getClass().toString());
@ -214,21 +217,21 @@ public class InterceptorServiceTest {
// Try to register again (should have no effect // Try to register again (should have no effect
svc.registerInterceptor(myInterceptorManual); svc.registerInterceptor(myInterceptorManual);
globalInterceptors = svc.getGlobalInterceptorsForUnitTest(); globalInterceptors = svc.getGlobalInterceptorsForUnitTest();
assertEquals(3, globalInterceptors.size()); assertThat(globalInterceptors).hasSize(3);
assertInstanceOf(MyTestInterceptorOne.class, globalInterceptors.get(0), globalInterceptors.get(0).getClass().toString()); assertInstanceOf(MyTestInterceptorOne.class, globalInterceptors.get(0), globalInterceptors.get(0).getClass().toString());
assertInstanceOf(MyTestInterceptorManual.class, globalInterceptors.get(1), globalInterceptors.get(1).getClass().toString()); assertInstanceOf(MyTestInterceptorManual.class, globalInterceptors.get(1), globalInterceptors.get(1).getClass().toString());
assertInstanceOf(MyTestInterceptorTwo.class, globalInterceptors.get(2), globalInterceptors.get(2).getClass().toString()); assertInstanceOf(MyTestInterceptorTwo.class, globalInterceptors.get(2), globalInterceptors.get(2).getClass().toString());
// Make sure we have the right invokers in the right order // Make sure we have the right invokers in the right order
List<Object> invokers = svc.getInterceptorsWithInvokersForPointcut(Pointcut.TEST_RB); List<Object> invokers = svc.getInterceptorsWithInvokersForPointcut(Pointcut.TEST_RB);
assertSame(interceptor0, invokers.get(0)); assertThat(invokers.get(0)).isSameAs(interceptor0);
assertSame(myInterceptorManual, invokers.get(1)); assertThat(invokers.get(1)).isSameAs(myInterceptorManual);
assertSame(interceptor1, invokers.get(2)); assertThat(invokers.get(2)).isSameAs(interceptor1);
// Finally, unregister it // Finally, unregister it
svc.unregisterInterceptor(myInterceptorManual); svc.unregisterInterceptor(myInterceptorManual);
globalInterceptors = svc.getGlobalInterceptorsForUnitTest(); globalInterceptors = svc.getGlobalInterceptorsForUnitTest();
assertEquals(2, globalInterceptors.size()); assertThat(globalInterceptors).hasSize(2);
assertInstanceOf(MyTestInterceptorOne.class, globalInterceptors.get(0), globalInterceptors.get(0).getClass().toString()); assertInstanceOf(MyTestInterceptorOne.class, globalInterceptors.get(0), globalInterceptors.get(0).getClass().toString());
assertInstanceOf(MyTestInterceptorTwo.class, globalInterceptors.get(1), globalInterceptors.get(1).getClass().toString()); assertInstanceOf(MyTestInterceptorTwo.class, globalInterceptors.get(1), globalInterceptors.get(1).getClass().toString());
@ -255,10 +258,10 @@ public class InterceptorServiceTest {
assertTrue(outcome); assertTrue(outcome);
} }
assertThat(myInvocations, contains("MyTestInterceptorOne.testRb", "MyTestInterceptorTwo.testRb")); assertThat(myInvocations).containsExactly("MyTestInterceptorOne.testRb", "MyTestInterceptorTwo.testRb");
assertSame("A", interceptor0.myLastString0); assertThat(interceptor0.myLastString0).isSameAs("A");
assertSame("A", interceptor1.myLastString0); assertThat(interceptor1.myLastString0).isSameAs("A");
assertSame("B", interceptor1.myLastString1); assertThat(interceptor1.myLastString1).isSameAs("B");
} }
@Test @Test
@ -275,10 +278,10 @@ public class InterceptorServiceTest {
assertTrue(outcome); assertTrue(outcome);
} }
assertThat(myInvocations, contains("MyTestAnonymousInterceptorOne.testRb", "MyTestAnonymousInterceptorTwo.testRb")); assertThat(myInvocations).containsExactly("MyTestAnonymousInterceptorOne.testRb", "MyTestAnonymousInterceptorTwo.testRb");
assertSame("A", interceptor0.myLastString0); assertThat(interceptor0.myLastString0).isSameAs("A");
assertSame("A", interceptor1.myLastString0); assertThat(interceptor1.myLastString0).isSameAs("A");
assertSame("B", interceptor1.myLastString1); assertThat(interceptor1.myLastString1).isSameAs("B");
} }
@Test @Test
@ -293,10 +296,10 @@ public class InterceptorServiceTest {
boolean outcome = svc.callHooks(Pointcut.TEST_RB, new HookParams("A", "B")); boolean outcome = svc.callHooks(Pointcut.TEST_RB, new HookParams("A", "B"));
assertTrue(outcome); assertTrue(outcome);
assertThat(myInvocations, contains("MyTestInterceptorOne.testRb", "MyTestInterceptorTwo.testRb")); assertThat(myInvocations).containsExactly("MyTestInterceptorOne.testRb", "MyTestInterceptorTwo.testRb");
assertSame("A", interceptor0.myLastString0); assertThat(interceptor0.myLastString0).isSameAs("A");
assertSame("A", interceptor1.myLastString0); assertThat(interceptor1.myLastString0).isSameAs("A");
assertSame("B", interceptor1.myLastString1); assertThat(interceptor1.myLastString1).isSameAs("B");
} }
@Test @Test
@ -313,10 +316,10 @@ public class InterceptorServiceTest {
boolean outcome = svc.callHooks(Pointcut.TEST_RB, new HookParams("A", "B")); boolean outcome = svc.callHooks(Pointcut.TEST_RB, new HookParams("A", "B"));
assertFalse(outcome); assertFalse(outcome);
assertThat(myInvocations, contains("MyTestInterceptorOne.testRb")); assertThat(myInvocations).containsExactly("MyTestInterceptorOne.testRb");
assertSame("A", interceptor0.myLastString0); assertThat(interceptor0.myLastString0).isSameAs("A");
assertSame(null, interceptor1.myLastString0); assertThat(interceptor1.myLastString0).isSameAs(null);
assertSame(null, interceptor1.myLastString1); assertThat(interceptor1.myLastString1).isSameAs(null);
} }
@Test @Test
@ -440,7 +443,7 @@ public class InterceptorServiceTest {
svc.callHooks(Pointcut.TEST_RB, params); svc.callHooks(Pointcut.TEST_RB, params);
fail(); fail();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Invalid params for pointcut " + Pointcut.TEST_RB + " - Wanted java.lang.String,java.lang.String but found ")); assertThat(e.getMessage()).contains("Invalid params for pointcut " + Pointcut.TEST_RB + " - Wanted java.lang.String,java.lang.String but found ");
} }
} }
@ -521,7 +524,7 @@ public class InterceptorServiceTest {
InterceptorService svc = new InterceptorService(); InterceptorService svc = new InterceptorService();
assertTrue(svc.callHooks(Pointcut.TEST_RB, params)); assertTrue(svc.callHooks(Pointcut.TEST_RB, params));
assertTrue(svc.ifHasCallHooks(Pointcut.TEST_RB, ()->params)); assertTrue(svc.ifHasCallHooks(Pointcut.TEST_RB, () -> params));
} }
@Test @Test
@ -531,7 +534,7 @@ public class InterceptorServiceTest {
svc.registerInterceptor(new BooleanHook(true)); svc.registerInterceptor(new BooleanHook(true));
assertTrue(svc.callHooks(Pointcut.TEST_RB, params)); assertTrue(svc.callHooks(Pointcut.TEST_RB, params));
assertTrue(svc.ifHasCallHooks(Pointcut.TEST_RB, ()->params)); assertTrue(svc.ifHasCallHooks(Pointcut.TEST_RB, () -> params));
} }
@Test @Test
@ -542,7 +545,7 @@ public class InterceptorServiceTest {
svc.registerInterceptor(new BooleanHook(true)); svc.registerInterceptor(new BooleanHook(true));
assertFalse(svc.callHooks(Pointcut.TEST_RB, params)); assertFalse(svc.callHooks(Pointcut.TEST_RB, params));
assertFalse(svc.ifHasCallHooks(Pointcut.TEST_RB, ()->params)); assertFalse(svc.ifHasCallHooks(Pointcut.TEST_RB, () -> params));
} }
@ -551,7 +554,7 @@ public class InterceptorServiceTest {
InterceptorService svc = new InterceptorService(); InterceptorService svc = new InterceptorService();
assertNull(svc.callHooksAndReturnObject(Pointcut.TEST_RO, params)); assertNull(svc.callHooksAndReturnObject(Pointcut.TEST_RO, params));
assertNull(svc.ifHasCallHooksAndReturnObject(Pointcut.TEST_RO, ()->params)); assertNull(svc.ifHasCallHooksAndReturnObject(Pointcut.TEST_RO, () -> params));
} }
@Test @Test
@ -561,7 +564,7 @@ public class InterceptorServiceTest {
svc.registerInterceptor(new ObjectHook<>(null)); svc.registerInterceptor(new ObjectHook<>(null));
assertNull(svc.callHooksAndReturnObject(Pointcut.TEST_RO, params)); assertNull(svc.callHooksAndReturnObject(Pointcut.TEST_RO, params));
assertNull(svc.ifHasCallHooksAndReturnObject(Pointcut.TEST_RO, ()->params)); assertNull(svc.ifHasCallHooksAndReturnObject(Pointcut.TEST_RO, () -> params));
} }
@Test @Test

View File

@ -8,11 +8,10 @@ import org.slf4j.LoggerFactory;
import java.time.LocalDate; import java.time.LocalDate;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class RequestPartitionIdTest { public class RequestPartitionIdTest {
@ -26,8 +25,8 @@ public class RequestPartitionIdTest {
@Test @Test
public void testEquals() { public void testEquals() {
assertEquals(RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1)), RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1))); assertEquals(RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1)), RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1)));
assertNotEquals(RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1)), null); assertNotNull(RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1)));
assertNotEquals(RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1)), "123"); assertThat("123").isNotEqualTo(RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1)));
} }
@Test @Test
@ -47,13 +46,13 @@ public class RequestPartitionIdTest {
{ {
RequestPartitionId start = RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1)); RequestPartitionId start = RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1));
String json = assertSerDeserSer(start); String json = assertSerDeserSer(start);
assertThat(json, containsString("\"partitionDate\":[2020,1,1]")); assertThat(json).contains("\"partitionDate\":[2020,1,1]");
assertThat(json, containsString("\"partitionIds\":[123]")); assertThat(json).contains("\"partitionIds\":[123]");
} }
{ {
RequestPartitionId start = RequestPartitionId.forPartitionIdsAndNames(Lists.newArrayList("Name1", "Name2"), null, null); RequestPartitionId start = RequestPartitionId.forPartitionIdsAndNames(Lists.newArrayList("Name1", "Name2"), null, null);
String json = assertSerDeserSer(start); String json = assertSerDeserSer(start);
assertThat(json, containsString("partitionNames\":[\"Name1\",\"Name2\"]")); assertThat(json).contains("partitionNames\":[\"Name1\",\"Name2\"]");
} }
assertSerDeserSer(RequestPartitionId.allPartitions()); assertSerDeserSer(RequestPartitionId.allPartitions());
assertSerDeserSer(RequestPartitionId.defaultPartition()); assertSerDeserSer(RequestPartitionId.defaultPartition());

View File

@ -8,7 +8,7 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
@ -67,15 +67,14 @@ public class BaseBatchJobParametersTest {
if (theParams.isExpectedToWork()) { if (theParams.isExpectedToWork()) {
parameters.setUserData(key, testValue); parameters.setUserData(key, testValue);
assertFalse(parameters.getUserData().isEmpty()); assertFalse(parameters.getUserData().isEmpty());
assertEquals(testValue, parameters.getUserData().get(key)); assertThat(parameters.getUserData()).containsEntry(key, testValue);
} else { } else {
try { try {
parameters.setUserData(key, testValue); parameters.setUserData(key, testValue);
fail(); fail();
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
String dataType = testValue.getClass().getName(); String dataType = testValue.getClass().getName();
assertTrue(ex.getMessage().contains("Invalid data type provided " + dataType), assertThat(ex.getMessage().contains("Invalid data type provided " + dataType)).as(ex.getMessage()).isTrue();
ex.getMessage());
assertTrue(parameters.getUserData().isEmpty()); assertTrue(parameters.getUserData().isEmpty());
} }
} }
@ -92,8 +91,7 @@ public class BaseBatchJobParametersTest {
parameters.setUserData(key, "test"); parameters.setUserData(key, "test");
fail(); fail();
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
assertTrue(ex.getMessage().contains("Invalid key; key must be non-empty, non-null"), assertThat(ex.getMessage().contains("Invalid key; key must be non-empty, non-null")).as(ex.getMessage()).isTrue();
ex.getMessage());
} }
} }
} }
@ -106,7 +104,7 @@ public class BaseBatchJobParametersTest {
// test // test
parameters.setUserData(key, "test"); parameters.setUserData(key, "test");
assertTrue(parameters.getUserData().containsKey(key)); assertThat(parameters.getUserData()).containsKey(key);
parameters.setUserData(key, null); parameters.setUserData(key, null);
assertFalse(parameters.getUserData().containsKey(key)); assertFalse(parameters.getUserData().containsKey(key));

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -55,7 +56,7 @@ public class PagingIteratorTest {
String next = myPagingIterator.next(); String next = myPagingIterator.next();
assertNotNull(next); assertNotNull(next);
assertFalse(next.isEmpty()); assertThat(next).isNotEmpty();
} }
@Test @Test
@ -84,7 +85,7 @@ public class PagingIteratorTest {
myPagingIterator.next(); myPagingIterator.next();
fail(); fail();
} catch (NoSuchElementException ex) { } catch (NoSuchElementException ex) {
assertTrue(ex.getMessage().contains("Nothing to fetch")); assertThat(ex.getMessage()).contains("Nothing to fetch");
} }
} }
} }

View File

@ -2,8 +2,9 @@ package ca.uhn.fhir.model.api;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull;
public class ResourceMetadataKeyEnumTest { public class ResourceMetadataKeyEnumTest {
@ -14,18 +15,18 @@ public class ResourceMetadataKeyEnumTest {
@Test @Test
public void testEquals() { public void testEquals() {
assertNotEquals(ResourceMetadataKeyEnum.PROFILES, null); assertNotNull(ResourceMetadataKeyEnum.PROFILES);
assertNotEquals(ResourceMetadataKeyEnum.PROFILES, ""); assertThat("").isNotEqualTo(ResourceMetadataKeyEnum.PROFILES);
assertNotEquals(ResourceMetadataKeyEnum.PROFILES, ResourceMetadataKeyEnum.PUBLISHED); assertThat(ResourceMetadataKeyEnum.PUBLISHED).isNotEqualTo(ResourceMetadataKeyEnum.PROFILES);
assertEquals(ResourceMetadataKeyEnum.PROFILES, ResourceMetadataKeyEnum.PROFILES); assertEquals(ResourceMetadataKeyEnum.PROFILES, ResourceMetadataKeyEnum.PROFILES);
} }
@Test @Test
public void testExtensionResourceEquals() { public void testExtensionResourceEquals() {
assertNotEquals(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"), new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://bar")); assertThat(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://bar")).isNotEqualTo(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"));
assertNotEquals(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"), null); assertNotNull(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"));
assertNotEquals(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"), ""); assertThat("").isNotEqualTo(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"));
assertEquals(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"), new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo")); assertEquals(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"), new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"));
ResourceMetadataKeyEnum.ExtensionResourceMetadataKey foo = new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo"); ResourceMetadataKeyEnum.ExtensionResourceMetadataKey foo = new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey("http://foo");

View File

@ -5,9 +5,9 @@ import org.junit.jupiter.api.Test;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class TagTest { public class TagTest {
@ -19,12 +19,13 @@ public class TagTest {
Tag tag3 = new Tag().setScheme("scheme2").setTerm("term").setLabel("label"); Tag tag3 = new Tag().setScheme("scheme2").setTerm("term").setLabel("label");
Tag tag4 = new Tag().setScheme("scheme").setTerm("term2").setLabel("label"); Tag tag4 = new Tag().setScheme("scheme").setTerm("term2").setLabel("label");
assertEquals(tag1, tag1); assertThat(tag1)
.isEqualTo(tag1)
.isNotNull();
assertEquals(tag1, tag2); assertEquals(tag1, tag2);
assertNotEquals(tag1, tag3); assertThat(tag3).isNotEqualTo(tag1);
assertNotEquals(tag1, tag4); assertThat(tag4).isNotEqualTo(tag1);
assertNotEquals(tag1, null); assertThat("").isNotEqualTo(tag1);
assertNotEquals(tag1, "");
} }
@Test @Test
@ -39,7 +40,7 @@ public class TagTest {
assertFalse(new Tag("http://foo").isEmpty()); assertFalse(new Tag("http://foo").isEmpty());
assertFalse(new Tag("http://foo", "http://bar").isEmpty()); assertFalse(new Tag("http://foo", "http://bar").isEmpty());
assertFalse(new Tag(new URI("http://foo"), new URI("http://bar"), "Label").isEmpty()); assertFalse(new Tag(new URI("http://foo"), new URI("http://bar"), "Label").isEmpty());
assertTrue(new Tag((URI)null, null, "Label").isEmpty()); assertTrue(new Tag((URI) null, null, "Label").isEmpty());
assertEquals("http://foo", new Tag(new URI("http://foo"), new URI("http://bar"), "Label").getSystem()); assertEquals("http://foo", new Tag(new URI("http://foo"), new URI("http://bar"), "Label").getSystem());
assertEquals("http://bar", new Tag(new URI("http://foo"), new URI("http://bar"), "Label").getCode()); assertEquals("http://bar", new Tag(new URI("http://foo"), new URI("http://bar"), "Label").getCode());

View File

@ -44,7 +44,7 @@ public class JsonLikeStructureTest {
jsonStructure.load(reader); jsonStructure.load(reader);
BaseJsonLikeObject rootObject = jsonStructure.getRootObject(); BaseJsonLikeObject rootObject = jsonStructure.getRootObject();
assertNotNull(rootObject); assertNotNull(rootObject);
assertEquals(BaseJsonLikeValue.ValueType.OBJECT, rootObject.getJsonType()); assertEquals(BaseJsonLikeValue.ValueType.OBJECT, rootObject.getJsonType());
} }
@ -75,7 +75,7 @@ public class JsonLikeStructureTest {
jsonStructure.load(reader); jsonStructure.load(reader);
BaseJsonLikeObject rootObject = jsonStructure.getRootObject(); BaseJsonLikeObject rootObject = jsonStructure.getRootObject();
assertNotNull(rootObject); assertNotNull(rootObject);
BaseJsonLikeValue value = rootObject.get("object-value"); BaseJsonLikeValue value = rootObject.get("object-value");

View File

@ -7,6 +7,7 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; 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.assertTrue;
public class CacheControlDirectiveTest { public class CacheControlDirectiveTest {
@ -27,7 +28,7 @@ public class CacheControlDirectiveTest {
ccd.parse(values); ccd.parse(values);
assertTrue(ccd.isNoCache()); assertTrue(ccd.isNoCache());
assertTrue(ccd.isNoStore()); assertTrue(ccd.isNoStore());
assertEquals(null, ccd.getMaxResults()); assertNull(ccd.getMaxResults());
} }
@Test @Test
@ -47,7 +48,7 @@ public class CacheControlDirectiveTest {
ccd.parse(values); ccd.parse(values);
assertFalse(ccd.isNoCache()); assertFalse(ccd.isNoCache());
assertTrue(ccd.isNoStore()); assertTrue(ccd.isNoStore());
assertEquals(null, ccd.getMaxResults()); assertNull(ccd.getMaxResults());
} }
@Test @Test

View File

@ -7,7 +7,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Optional; import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
class MethodOutcomeTest { class MethodOutcomeTest {
@ -34,8 +34,8 @@ class MethodOutcomeTest {
Optional<String> firstHeader = myMethodOutcome.getFirstResponseHeader("some-header"); Optional<String> firstHeader = myMethodOutcome.getFirstResponseHeader("some-header");
assertTrue(firstHeader.isPresent()); assertThat(firstHeader).isPresent();
assertEquals("value1", firstHeader.get()); assertThat(firstHeader).contains("value1");
} }
} }

View File

@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class QualifiedParamListTest { public class QualifiedParamListTest {
@ -13,14 +14,14 @@ public class QualifiedParamListTest {
@Test @Test
public void testSplit1() { public void testSplit1() {
List<String> actual = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(null,"aaa"); List<String> actual = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(null,"aaa");
assertEquals(1, actual.size()); assertThat(actual).hasSize(1);
assertEquals("aaa", actual.get(0)); assertEquals("aaa", actual.get(0));
} }
@Test @Test
public void testSplit2() { public void testSplit2() {
List<String> actual = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(null,"aaa,bbb"); List<String> actual = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(null,"aaa,bbb");
assertEquals(2, actual.size()); assertThat(actual).hasSize(2);
assertEquals("aaa", actual.get(0)); assertEquals("aaa", actual.get(0));
assertEquals("bbb", actual.get(1)); assertEquals("bbb", actual.get(1));
} }
@ -29,7 +30,7 @@ public class QualifiedParamListTest {
public void testSplit3() { public void testSplit3() {
List<String> actual = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(null,"aaa,b\\,bb"); List<String> actual = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(null,"aaa,b\\,bb");
System.out.println(actual); System.out.println(actual);
assertEquals(2, actual.size()); assertThat(actual).hasSize(2);
assertEquals("aaa", actual.get(0)); assertEquals("aaa", actual.get(0));
assertEquals("b,bb", actual.get(1)); assertEquals("b,bb", actual.get(1));
} }

View File

@ -14,13 +14,12 @@ import java.util.TimeZone;
import static ca.uhn.fhir.rest.param.ParamPrefixEnum.EQUAL; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.EQUAL;
import static ca.uhn.fhir.rest.param.ParamPrefixEnum.NOT_EQUAL; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.NOT_EQUAL;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class DateParamTest { public class DateParamTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateParamTest.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateParamTest.class);
@ -32,9 +31,9 @@ public class DateParamTest {
// too bad value is a j.u.Date instead of a new JSR-310 type // too bad value is a j.u.Date instead of a new JSR-310 type
// DataParam parses using default tz, so go backwards. // DataParam parses using default tz, so go backwards.
ZonedDateTime zonedDateTime = input.getValue().toInstant().atZone(ZoneId.systemDefault()); ZonedDateTime zonedDateTime = input.getValue().toInstant().atZone(ZoneId.systemDefault());
assertEquals(2020,zonedDateTime.getYear()); assertEquals(2020, zonedDateTime.getYear());
assertEquals(Month.JANUARY,zonedDateTime.getMonth()); assertEquals(Month.JANUARY, zonedDateTime.getMonth());
assertEquals(1,zonedDateTime.getDayOfMonth()); assertEquals(1, zonedDateTime.getDayOfMonth());
assertNull(input.getPrefix()); assertNull(input.getPrefix());
} }
@ -147,8 +146,8 @@ public class DateParamTest {
InstantDt dt = new InstantDt(new Date(param.getValue().getTime())); InstantDt dt = new InstantDt(new Date(param.getValue().getTime()));
dt.setTimeZone(TimeZone.getTimeZone("America/Toronto")); dt.setTimeZone(TimeZone.getTimeZone("America/Toronto"));
ourLog.debug("POST: " + dt.getValue()); ourLog.debug("POST: " + dt.getValue());
assertThat(dt.getValueAsString(), startsWith("2016-06-09T")); assertThat(dt.getValueAsString()).startsWith("2016-06-09T");
assertThat(dt.getValueAsString(), endsWith("8:00.000-04:00")); assertThat(dt.getValueAsString()).endsWith("8:00.000-04:00");
} }
@Test @Test

View File

@ -7,15 +7,14 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class DateRangeParamTest { public class DateRangeParamTest {
private FhirContext fhirContext; private FhirContext fhirContext;

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static ca.uhn.fhir.rest.api.Constants.PARAMQUALIFIER_STRING_TEXT; import static ca.uhn.fhir.rest.api.Constants.PARAMQUALIFIER_STRING_TEXT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
@ -51,7 +52,7 @@ public class StringParamTest {
@Test @Test
public void testEquals() { public void testEquals() {
StringParam input = new StringParam("foo", true); StringParam input = new StringParam("foo", true);
assertTrue(input.equals(input)); assertTrue(input.equals(input));
assertFalse(input.equals(null)); assertFalse(input.equals(null));
assertFalse(input.equals("")); assertFalse(input.equals(""));
@ -177,9 +178,9 @@ public class StringParamTest {
.collect(Collectors.toList()); .collect(Collectors.toList());
if (theWasLogged) { if (theWasLogged) {
assertEquals(1, warningLogs.size()); assertThat(warningLogs).hasSize(1);
} else { } else {
assertTrue(warningLogs.isEmpty()); assertThat(warningLogs).isEmpty();
} }
} }

View File

@ -17,10 +17,9 @@ import static ca.uhn.fhir.rest.param.ParamPrefixEnum.GREATERTHAN;
import static ca.uhn.fhir.rest.param.ParamPrefixEnum.GREATERTHAN_OR_EQUALS; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.GREATERTHAN_OR_EQUALS;
import static ca.uhn.fhir.rest.param.ParamPrefixEnum.LESSTHAN; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.LESSTHAN;
import static ca.uhn.fhir.rest.param.ParamPrefixEnum.LESSTHAN_OR_EQUALS; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.LESSTHAN_OR_EQUALS;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.hamcrest.Matchers.notNullValue; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.hamcrest.Matchers.nullValue;
class DateRangeUtilTest { class DateRangeUtilTest {
@ -123,11 +122,11 @@ class DateRangeUtilTest {
DateRangeParam result = DateRangeUtil.narrowDateRange(c.range, c.narrowStart, c.narrowEnd); DateRangeParam result = DateRangeUtil.narrowDateRange(c.range, c.narrowStart, c.narrowEnd);
if (c.resultStart == null && c.resultEnd == null) { if (c.resultStart == null && c.resultEnd == null) {
assertThat(result, nullValue()); assertNull(result);
} else { } else {
assertThat(result, notNullValue()); assertNotNull(result);
assertThat("range start", result.getLowerBound(), equalTo(c.resultStart)); assertThat(result.getLowerBound()).as("range start").isEqualTo(c.resultStart);
assertThat("range end", result.getUpperBound(), equalTo(c.resultEnd)); assertThat(result.getUpperBound()).as("range end").isEqualTo(c.resultEnd);
} }
} }

View File

@ -1,18 +1,18 @@
package ca.uhn.fhir.util; package ca.uhn.fhir.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class DateUtilTest { public class DateUtilTest {
@Test @Test
public void testCompletedDate() { public void testCompletedDate() {
Pair<String, String> result = DateUtils.getCompletedDate(null); Pair<String, String> result = DateUtils.getCompletedDate(null);
assertNull(result.getLeft()); assertNull(result.getLeft());
assertNull(result.getRight()); assertNull(result.getRight());
result = DateUtils.getCompletedDate("2020"); result = DateUtils.getCompletedDate("2020");

View File

@ -6,10 +6,7 @@ import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.containsString; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
class JsonUtilTest { class JsonUtilTest {
@ -46,9 +43,9 @@ class JsonUtilTest {
object.setSensitiveField("Sensitive Value!"); object.setSensitiveField("Sensitive Value!");
String sensitiveExcluded = JsonUtil.serializeOrInvalidRequest(object); String sensitiveExcluded = JsonUtil.serializeOrInvalidRequest(object);
assertThat(sensitiveExcluded, is(not(containsString("Sensitive Value!")))); assertThat(sensitiveExcluded).doesNotContain("Sensitive Value!");
String sensitiveIncluded = JsonUtil.serializeWithSensitiveData(object); String sensitiveIncluded = JsonUtil.serializeWithSensitiveData(object);
assertThat(sensitiveIncluded, is(containsString("Sensitive Value!"))); assertThat(sensitiveIncluded).contains("Sensitive Value!");
} }
} }

View File

@ -34,8 +34,8 @@ public class NumericParamRangeUtilTest {
theExpectedRange.getLeft(), theExpectedRange.getRight(), theExpectedRange.getLeft(), theExpectedRange.getRight(),
range.getLeft(), range.getRight() ); range.getLeft(), range.getRight() );
assertEquals(theExpectedRange.getLeft(), range.getLeft().doubleValue() ); assertEquals(theExpectedRange.getLeft(), range.getLeft().doubleValue());
assertEquals(theExpectedRange.getRight(), range.getRight().doubleValue() ); assertEquals(theExpectedRange.getRight(), range.getRight().doubleValue());
} }

View File

@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test;
import java.util.Optional; import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -67,7 +68,7 @@ class ObjectUtilTest {
Optional<Boolean> result = ObjectUtil.castIfInstanceof(value, Boolean.class); Optional<Boolean> result = ObjectUtil.castIfInstanceof(value, Boolean.class);
assertTrue(result.isPresent()); assertThat(result).isPresent();
} }
@Test @Test

View File

@ -12,6 +12,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
@ -67,10 +68,9 @@ public class PhoneticEncoderUtilTests {
assertNull(encoder); assertNull(encoder);
ArgumentCaptor<ILoggingEvent> loggingCaptor = ArgumentCaptor.forClass(ILoggingEvent.class); ArgumentCaptor<ILoggingEvent> loggingCaptor = ArgumentCaptor.forClass(ILoggingEvent.class);
Mockito.verify(myListAppender).doAppend(loggingCaptor.capture()); Mockito.verify(myListAppender).doAppend(loggingCaptor.capture());
assertEquals(1, loggingCaptor.getAllValues().size()); assertThat(loggingCaptor.getAllValues()).hasSize(1);
ILoggingEvent event = loggingCaptor.getValue(); ILoggingEvent event = loggingCaptor.getValue();
assertEquals("Invalid encoder max character length: " + num, assertEquals("Invalid encoder max character length: " + num, event.getMessage());
event.getMessage());
} }
@Test @Test
@ -86,10 +86,9 @@ public class PhoneticEncoderUtilTests {
ArgumentCaptor<ILoggingEvent> captor = ArgumentCaptor.forClass(ILoggingEvent.class); ArgumentCaptor<ILoggingEvent> captor = ArgumentCaptor.forClass(ILoggingEvent.class);
Mockito.verify(myListAppender) Mockito.verify(myListAppender)
.doAppend(captor.capture()); .doAppend(captor.capture());
assertEquals(1, captor.getAllValues().size()); assertThat(captor.getAllValues()).hasSize(1);
ILoggingEvent event = captor.getValue(); ILoggingEvent event = captor.getValue();
assertEquals("Invalid phonetic param string " + theString, assertEquals("Invalid phonetic param string " + theString, event.getMessage());
event.getMessage());
} }
@Test @Test
@ -142,9 +141,8 @@ public class PhoneticEncoderUtilTests {
assertNull(theEncoder); assertNull(theEncoder);
ArgumentCaptor<ILoggingEvent> loggingCaptor = ArgumentCaptor.forClass(ILoggingEvent.class); ArgumentCaptor<ILoggingEvent> loggingCaptor = ArgumentCaptor.forClass(ILoggingEvent.class);
Mockito.verify(myListAppender).doAppend(loggingCaptor.capture()); Mockito.verify(myListAppender).doAppend(loggingCaptor.capture());
assertEquals(1, loggingCaptor.getAllValues().size()); assertThat(loggingCaptor.getAllValues()).hasSize(1);
ILoggingEvent event = loggingCaptor.getValue(); ILoggingEvent event = loggingCaptor.getValue();
assertEquals("Invalid encoder max character length: " + theNumberParam, assertEquals("Invalid encoder max character length: " + theNumberParam, event.getMessage());
event.getMessage());
} }
} }

View File

@ -10,9 +10,11 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; 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.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class ReflectionUtilTest { public class ReflectionUtilTest {
@Test @Test
@ -27,7 +29,7 @@ public class ReflectionUtilTest {
@Test @Test
public void testNewInstanceOrReturnNullWrong1() { public void testNewInstanceOrReturnNullWrong1() {
assertEquals(null, ReflectionUtil.newInstanceOrReturnNull("foo.Foo", List.class)); assertNull(ReflectionUtil.newInstanceOrReturnNull("foo.Foo", List.class));
} }
@Test @Test

View File

@ -2,7 +2,7 @@ package ca.uhn.fhir.util;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertTrue;
class SleepUtilTest { class SleepUtilTest {

View File

@ -1,18 +1,13 @@
package ca.uhn.fhir.util; package ca.uhn.fhir.util;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Date; import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.Matchers.oneOf;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class StopWatchTest { public class StopWatchTest {
@ -150,10 +145,10 @@ public class StopWatchTest {
StopWatch.setNowForUnitTest(2200L); StopWatch.setNowForUnitTest(2200L);
String taskDurations = sw.formatTaskDurations(); String taskDurations = sw.formatTaskDurations();
ourLog.info(taskDurations); ourLog.info(taskDurations);
assertEquals("TASK1: 500ms\n" + assertThat(taskDurations).isEqualTo("TASK1: 500ms\n" +
"Between: 500ms\n" + "Between: 500ms\n" +
"TASK2: 100ms\n" + "TASK2: 100ms\n" +
"After last task: 100ms", taskDurations); "After last task: 100ms");
} }
@Test @Test
@ -186,7 +181,7 @@ public class StopWatchTest {
StopWatch sw = new StopWatch(DateUtils.addMinutes(new Date(), -4)); StopWatch sw = new StopWatch(DateUtils.addMinutes(new Date(), -4));
String throughput = sw.formatThroughput(60, TimeUnit.MINUTES).replace(',', '.'); String throughput = sw.formatThroughput(60, TimeUnit.MINUTES).replace(',', '.');
ourLog.info("{} operations in {}ms = {} ops / second", 60, sw.getMillis(), throughput); ourLog.info("{} operations in {}ms = {} ops / second", 60, sw.getMillis(), throughput);
assertThat(throughput, oneOf("14.9", "15.0", "15.1", "14,9", "15,0", "15,1")); assertThat(throughput).isIn("14.9", "15.0", "15.1", "14,9", "15,0", "15,1");
} }
@Test @Test
@ -197,29 +192,29 @@ public class StopWatchTest {
long millis = sw.getMillisPerOperation(numOperations); long millis = sw.getMillisPerOperation(numOperations);
ourLog.info("{} operations in {}ms = {}ms / operation", numOperations, minutes * DateUtils.MILLIS_PER_MINUTE, millis); ourLog.info("{} operations in {}ms = {}ms / operation", numOperations, minutes * DateUtils.MILLIS_PER_MINUTE, millis);
assertThat(millis, Matchers.lessThan(62000L)); assertThat(millis).isLessThan(62000L);
assertThat(millis, Matchers.greaterThan(58000L)); assertThat(millis).isGreaterThan(58000L);
} }
@Test @Test
public void testOperationThroughput30Ops1Min() { public void testOperationThroughput30Ops1Min() {
double throughput = calculateThroughput(1, 30); double throughput = calculateThroughput(1, 30);
assertThat(throughput, greaterThan(29.0)); assertThat(throughput).isGreaterThan(29.0);
assertThat(throughput, lessThan(31.0)); assertThat(throughput).isLessThan(31.0);
} }
@Test @Test
public void testOperationThroughput60Ops1Min() { public void testOperationThroughput60Ops1Min() {
double throughput = calculateThroughput(1, 60); double throughput = calculateThroughput(1, 60);
assertThat(throughput, greaterThan(59.0)); assertThat(throughput).isGreaterThan(59.0);
assertThat(throughput, lessThan(61.0)); assertThat(throughput).isLessThan(61.0);
} }
@Test @Test
public void testOperationThroughput60Ops4Min() { public void testOperationThroughput60Ops4Min() {
double throughput = calculateThroughput(4, 60); double throughput = calculateThroughput(4, 60);
assertThat(throughput, greaterThan(14.0)); assertThat(throughput).isGreaterThan(14.0);
assertThat(throughput, lessThan(16.0)); assertThat(throughput).isLessThan(16.0);
} }
@Test @Test
@ -227,7 +222,7 @@ public class StopWatchTest {
StopWatch sw = new StopWatch(); StopWatch sw = new StopWatch();
Thread.sleep(500); Thread.sleep(500);
sw.restart(); sw.restart();
assertThat(sw.getMillis(), lessThan(100L)); assertThat(sw.getMillis()).isLessThan(100L);
} }
@Test @Test
@ -236,9 +231,9 @@ public class StopWatchTest {
Thread.sleep(100); Thread.sleep(100);
assertThat(sw.getMillis(new Date()), greaterThan(10L)); assertThat(sw.getMillis(new Date())).isGreaterThan(10L);
assertThat(sw.getMillis(), greaterThan(10L)); assertThat(sw.getMillis()).isGreaterThan(10L);
assertThat(sw.getStartedDate().getTime(), lessThan(System.currentTimeMillis())); assertThat(sw.getStartedDate().getTime()).isLessThan(System.currentTimeMillis());
} }
@Test @Test
@ -247,9 +242,9 @@ public class StopWatchTest {
Thread.sleep(100); Thread.sleep(100);
assertThat(sw.getMillis(new Date()), greaterThan(10L)); assertThat(sw.getMillis(new Date())).isGreaterThan(10L);
assertThat(sw.getMillis(), greaterThan(10L)); assertThat(sw.getMillis()).isGreaterThan(10L);
assertThat(sw.getStartedDate().getTime(), lessThan(System.currentTimeMillis())); assertThat(sw.getStartedDate().getTime()).isLessThan(System.currentTimeMillis());
} }
@Test @Test
@ -260,7 +255,7 @@ public class StopWatchTest {
String string = sw.toString(); String string = sw.toString();
ourLog.info(string); ourLog.info(string);
assertThat(string, matchesPattern("^[0-9]{3,4}ms$")); assertThat(string).matches("^[0-9]{3,4}ms$");
} }

View File

@ -6,12 +6,9 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
class StreamUtilTest { class StreamUtilTest {
@ -20,7 +17,7 @@ class StreamUtilTest {
void testStreamPartitionBy4(String theCase, List<Integer> theInput, List<List<Integer>> theOutput) { void testStreamPartitionBy4(String theCase, List<Integer> theInput, List<List<Integer>> theOutput) {
List<List<Integer>> result = StreamUtil.partition(theInput.stream(), 4).toList(); List<List<Integer>> result = StreamUtil.partition(theInput.stream(), 4).toList();
assertEquals(theOutput, result, theCase); assertThat(result).as(theCase).isEqualTo(theOutput);
} }
static Object[][] streamPartitionTestCases() { static Object[][] streamPartitionTestCases() {
@ -58,7 +55,7 @@ class StreamUtilTest {
StreamUtil.partition(baseStream, 2).close(); StreamUtil.partition(baseStream, 2).close();
// then // then
assertThat("partition closed underlying stream", closed.get()); assertThat(closed.get()).as("partition closed underlying stream").isTrue();
} }

View File

@ -30,7 +30,7 @@ public class StringUtilTest {
assertEquals("TEST TEST", StringUtil.normalizeStringForSearchIndexing("TEST teSt")); assertEquals("TEST TEST", StringUtil.normalizeStringForSearchIndexing("TEST teSt"));
assertEquals("AEIØU", StringUtil.normalizeStringForSearchIndexing("åéîøü")); assertEquals("AEIØU", StringUtil.normalizeStringForSearchIndexing("åéîøü"));
assertEquals("杨浩", StringUtil.normalizeStringForSearchIndexing("杨浩")); assertEquals("杨浩", StringUtil.normalizeStringForSearchIndexing("杨浩"));
assertEquals(null, StringUtil.normalizeStringForSearchIndexing(null)); assertNull(StringUtil.normalizeStringForSearchIndexing(null));
} }
@Test @Test
@ -56,7 +56,7 @@ public class StringUtilTest {
@Test @Test
public void testChompCharacter() { public void testChompCharacter() {
assertEquals(null, StringUtil.chompCharacter(null, '/')); assertNull(StringUtil.chompCharacter(null, '/'));
assertEquals("", StringUtil.chompCharacter("", '/')); assertEquals("", StringUtil.chompCharacter("", '/'));
assertEquals("", StringUtil.chompCharacter("/", '/')); assertEquals("", StringUtil.chompCharacter("/", '/'));
assertEquals("a", StringUtil.chompCharacter("a/", '/')); assertEquals("a", StringUtil.chompCharacter("a/", '/'));

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.util; package ca.uhn.fhir.util;
import com.google.common.collect.Lists; import jakarta.annotation.Nonnull;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@ -8,17 +8,14 @@ import org.mockito.Captor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import jakarta.annotation.Nonnull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.times;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class TaskChunkerTest { public class TaskChunkerTest {

View File

@ -1,21 +1,21 @@
package ca.uhn.fhir.util; package ca.uhn.fhir.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class ValidateUtilTest { public class ValidateUtilTest {
@Test @Test
public void testIsTrueOrThrowInvalidRequest() { public void testIsTrueOrThrowInvalidRequest() {
ValidateUtil.isTrueOrThrowInvalidRequest(true, ""); ValidateUtil.isTrueOrThrowInvalidRequest(true, "");
try { try {
ValidateUtil.isTrueOrThrowInvalidRequest(false, "The message"); ValidateUtil.isTrueOrThrowInvalidRequest(false, "The message");
fail(); fail();
@ -23,17 +23,15 @@ public class ValidateUtilTest {
assertEquals(Msg.code(1769) + "The message", e.getMessage()); assertEquals(Msg.code(1769) + "The message", e.getMessage());
} }
} }
@Test @Test
public void testIsTrueOrThrowResourceNotFound() { public void testIsTrueOrThrowResourceNotFound() {
ValidateUtil.isTrueOrThrowResourceNotFound(true, ""); ValidateUtil.isTrueOrThrowResourceNotFound(true, "");
try { assertThatThrownBy(() ->
ValidateUtil.isTrueOrThrowResourceNotFound(false, "The message"); ValidateUtil.isTrueOrThrowResourceNotFound(false, "The message"))
fail(); .isInstanceOf(ResourceNotFoundException.class)
} catch (ResourceNotFoundException e) { .hasMessage(Msg.code(2494) + "The message");
assertEquals(Msg.code(2494) + "The message", e.getMessage());
}
} }
@Test @Test
@ -61,7 +59,7 @@ public class ValidateUtilTest {
@Test @Test
public void testIsNotBlank() { public void testIsNotBlank() {
ValidateUtil.isNotBlankOrThrowInvalidRequest("aa", ""); ValidateUtil.isNotBlankOrThrowInvalidRequest("aa", "");
try { try {
ValidateUtil.isNotBlankOrThrowInvalidRequest("", "The message"); ValidateUtil.isNotBlankOrThrowInvalidRequest("", "The message");
fail(); fail();

View File

@ -6,8 +6,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.hasItem; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class VersionEnumTest { public class VersionEnumTest {
@ -38,7 +37,7 @@ public class VersionEnumTest {
version = "V" + version.replace(".", "_"); version = "V" + version.replace(".", "_");
assertThat(versions, hasItem(version)); assertThat(versions).contains(version);
} }

View File

@ -2,17 +2,16 @@ package ca.uhn.fhir.util;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.not; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.blankOrNullString;
public class VersionUtilTest { public class VersionUtilTest {
@Test @Test
public void testProperties() { public void testProperties() {
assertThat(VersionUtil.getVersion(), not(blankOrNullString())); assertThat(VersionUtil.getVersion()).isNotEmpty();
assertThat(VersionUtil.getBuildNumber(), not(blankOrNullString())); assertThat(VersionUtil.getBuildNumber()).isNotEmpty();
assertThat(VersionUtil.getBuildTime(), not(blankOrNullString())); assertThat(VersionUtil.getBuildTime()).isNotEmpty();
} }

View File

@ -11,8 +11,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
@ -31,7 +30,7 @@ class FhirValidatorTest {
List<SingleValidationMessage> resultMessages = FhirValidator.buildValidationMessages(tasks); List<SingleValidationMessage> resultMessages = FhirValidator.buildValidationMessages(tasks);
// validate // validate
assertThat(resultMessages, hasSize(1)); assertThat(resultMessages).hasSize(1);
assertEquals(MESSAGE, resultMessages.get(0).getMessage()); assertEquals(MESSAGE, resultMessages.get(0).getMessage());
assertEquals(PREFIX + ".name.first", resultMessages.get(0).getLocationString()); assertEquals(PREFIX + ".name.first", resultMessages.get(0).getLocationString());
} }
@ -45,7 +44,7 @@ class FhirValidatorTest {
List<SingleValidationMessage> resultMessages = FhirValidator.buildValidationMessages(tasks); List<SingleValidationMessage> resultMessages = FhirValidator.buildValidationMessages(tasks);
// validate // validate
assertThat(resultMessages, hasSize(1)); assertThat(resultMessages).hasSize(1);
assertEquals(MESSAGE, resultMessages.get(0).getMessage()); assertEquals(MESSAGE, resultMessages.get(0).getMessage());
assertEquals(PREFIX + ".name", resultMessages.get(0).getLocationString()); assertEquals(PREFIX + ".name", resultMessages.get(0).getLocationString());
} }
@ -59,7 +58,7 @@ class FhirValidatorTest {
List<SingleValidationMessage> resultMessages = FhirValidator.buildValidationMessages(tasks); List<SingleValidationMessage> resultMessages = FhirValidator.buildValidationMessages(tasks);
// validate // validate
assertThat(resultMessages, hasSize(1)); assertThat(resultMessages).hasSize(1);
assertEquals(MESSAGE, resultMessages.get(0).getMessage()); assertEquals(MESSAGE, resultMessages.get(0).getMessage());
assertEquals(PREFIX, resultMessages.get(0).getLocationString()); assertEquals(PREFIX, resultMessages.get(0).getLocationString());
} }
@ -73,7 +72,7 @@ class FhirValidatorTest {
List<SingleValidationMessage> resultMessages = FhirValidator.buildValidationMessages(tasks); List<SingleValidationMessage> resultMessages = FhirValidator.buildValidationMessages(tasks);
// validate // validate
assertThat(resultMessages, hasSize(1)); assertThat(resultMessages).hasSize(1);
assertEquals(MESSAGE, resultMessages.get(0).getMessage()); assertEquals(MESSAGE, resultMessages.get(0).getMessage());
assertEquals(PREFIX + ".patient", resultMessages.get(0).getLocationString()); assertEquals(PREFIX + ".patient", resultMessages.get(0).getLocationString());
} }

View File

@ -7,8 +7,8 @@ import org.mockito.Mock;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
class ValidationResultTest { class ValidationResultTest {
@ -20,7 +20,7 @@ class ValidationResultTest {
List<SingleValidationMessage> validationMessages = getTestValidationErrors(2); List<SingleValidationMessage> validationMessages = getTestValidationErrors(2);
ValidationResult vr = new ValidationResult(myFhirContext, validationMessages); ValidationResult vr = new ValidationResult(myFhirContext, validationMessages);
String toStringValue = vr.toString(); String toStringValue = vr.toString();
assertTrue(toStringValue.contains("Error message #" + 1)); assertThat(toStringValue).contains("Error message #" + 1);
assertFalse(toStringValue.contains("Error message #" + 2)); assertFalse(toStringValue.contains("Error message #" + 2));
} }
@ -30,7 +30,7 @@ class ValidationResultTest {
getTestValidationErrors(ValidationResult.ERROR_DISPLAY_LIMIT_DEFAULT * 2); getTestValidationErrors(ValidationResult.ERROR_DISPLAY_LIMIT_DEFAULT * 2);
ValidationResult vr = new ValidationResult(myFhirContext, validationMessages); ValidationResult vr = new ValidationResult(myFhirContext, validationMessages);
String toStringValue = vr.toString(); String toStringValue = vr.toString();
assertTrue(toStringValue.contains("Error message #" + ValidationResult.ERROR_DISPLAY_LIMIT_DEFAULT)); assertThat(toStringValue).contains("Error message #" + ValidationResult.ERROR_DISPLAY_LIMIT_DEFAULT);
assertFalse(toStringValue.contains("Error message #" + (ValidationResult.ERROR_DISPLAY_LIMIT_DEFAULT + 1))); assertFalse(toStringValue.contains("Error message #" + (ValidationResult.ERROR_DISPLAY_LIMIT_DEFAULT + 1)));
} }
@ -40,7 +40,7 @@ class ValidationResultTest {
ValidationResult vr = new ValidationResult(myFhirContext, validationMessages); ValidationResult vr = new ValidationResult(myFhirContext, validationMessages);
vr.setErrorDisplayLimit(8); vr.setErrorDisplayLimit(8);
String toStringValue = vr.toString(); String toStringValue = vr.toString();
assertTrue(toStringValue.contains("Error message #" + 8)); assertThat(toStringValue).contains("Error message #" + 8);
assertFalse(toStringValue.contains("Error message #" + 9)); assertFalse(toStringValue.contains("Error message #" + 9));
} }

View File

@ -29,6 +29,10 @@
<property name="format" value="System\.out\.println"/> <property name="format" value="System\.out\.println"/>
<property name="ignoreComments" value="true"/> <property name="ignoreComments" value="true"/>
</module> </module>
<module name="RegexpSinglelineJava">
<property name="format" value="org.hamcrest.MatcherAssert.assertThat"/>
<property name="message" value="Incorrect assertThat import used: The &quot;org.assertj.core.api.Assertions.assertThat&quot; import should be used for tests"/>
</module>
<module name="RegexpSinglelineJava"> <module name="RegexpSinglelineJava">
<property name="format" value="org\.jetbrains\.annotations\.NotNull"/> <property name="format" value="org\.jetbrains\.annotations\.NotNull"/>
<property name="message" value="Incorrect &quot;org.jetbrains.annotation.NotNull&quot; annotation used: The &quot;jakarta.annotation.Nonnull&quot; annotation should be used for non-null values"/> <property name="message" value="Incorrect &quot;org.jetbrains.annotation.NotNull&quot; annotation used: The &quot;jakarta.annotation.Nonnull&quot; annotation should be used for non-null values"/>

View File

@ -17,10 +17,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
class HapiErrorCodeCheckTest { class HapiErrorCodeCheckTest {
@ -45,12 +42,14 @@ class HapiErrorCodeCheckTest {
String[] errorLines = errors.toString().split("\r?\n"); String[] errorLines = errors.toString().split("\r?\n");
Arrays.stream(errorLines).forEach(ourLog::info); Arrays.stream(errorLines).forEach(ourLog::info);
assertEquals(4, errorLines.length); assertEquals(4, errorLines.length);
assertThat(errorLines[0], startsWith("[ERROR] ")); assertThat(errorLines[0])
assertThat(errorLines[0], endsWith("BadClass.java:7: Exception thrown that does not call Msg.code() [HapiErrorCode]")); .startsWith("[ERROR] ")
assertThat(errorLines[1], startsWith("[ERROR] ")); .endsWith("BadClass.java:7: Exception thrown that does not call Msg.code() [HapiErrorCode]");
assertThat(errorLines[1], containsString("Two different exception messages call Msg.code(2258).")); assertThat(errorLines[1])
assertThat(errorLines[2], containsString("Each thrown exception must call Msg.code() with a different code.")); .startsWith("[ERROR] ")
assertThat(errorLines[3], containsString("Previously found at:")); .contains("Two different exception messages call Msg.code(2258).");
assertThat(errorLines[2]).contains("Each thrown exception must call Msg.code() with a different code.");
assertThat(errorLines[3]).contains("Previously found at:");
} }
private Checker buildChecker() throws CheckstyleException { private Checker buildChecker() throws CheckstyleException {

View File

@ -15,10 +15,11 @@ import org.junit.jupiter.params.provider.MethodSource;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class ApacheRestfulClientFactoryTest extends BaseFhirVersionParameterizedTest { public class ApacheRestfulClientFactoryTest extends BaseFhirVersionParameterizedTest {
@ParameterizedTest @ParameterizedTest
@ -47,8 +48,7 @@ public class ApacheRestfulClientFactoryTest extends BaseFhirVersionParameterized
try{ try{
HttpUriRequest request = new HttpGet(fhirVersionParams.getSecuredPatientEndpoint()); HttpUriRequest request = new HttpGet(fhirVersionParams.getSecuredPatientEndpoint());
unauthenticatedClient.execute(request); unauthenticatedClient.execute(request);
fail(); fail(); }
}
catch(Exception e){ catch(Exception e){
assertEquals(SSLHandshakeException.class, e.getClass()); assertEquals(SSLHandshakeException.class, e.getClass());
} }
@ -74,9 +74,8 @@ public class ApacheRestfulClientFactoryTest extends BaseFhirVersionParameterized
context.setRestfulClientFactory(new ApacheRestfulClientFactory(context)); context.setRestfulClientFactory(new ApacheRestfulClientFactory(context));
try { try {
context.newRestfulGenericClient(secureBase).search().forResource("Patient").execute(); context.newRestfulGenericClient(secureBase).search().forResource("Patient").execute();
fail(); fail(); } catch (Exception e) {
} catch (Exception e) { assertThat(e.getMessage()).contains("HAPI-1357: Failed to retrieve the server metadata statement during client initialization");
assertTrue(e.getMessage().contains("HAPI-1357: Failed to retrieve the server metadata statement during client initialization"));
assertEquals(SSLHandshakeException.class, e.getCause().getCause().getClass()); assertEquals(SSLHandshakeException.class, e.getCause().getCause().getClass());
} }
} }

View File

@ -18,7 +18,7 @@ import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGenerating
import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH; import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH;
import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION; import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION;
import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.values; import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.values;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -32,7 +32,7 @@ class BaseRequestGeneratingCommandTest {
@Test @Test
void getOptions() { void getOptions() {
Options options = tested.getOptions(); Options options = tested.getOptions();
assertEquals(7, options.getOptions().size()); assertThat(options.getOptions()).hasSize(7);
assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM)); assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM)); assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));
@ -52,7 +52,7 @@ class BaseRequestGeneratingCommandTest {
// BASIC_AUTH exclusion excludes 2 options // BASIC_AUTH exclusion excludes 2 options
int expectedSize = excludedOption == BASIC_AUTH ? 5 : 6; int expectedSize = excludedOption == BASIC_AUTH ? 5 : 6;
assertEquals(expectedSize, options.getOptions().size()); assertThat(options.getOptions()).hasSize(expectedSize);
assertFalse(options.hasShortOption(getOptionForExcludedOption(excludedOption))); assertFalse(options.hasShortOption(getOptionForExcludedOption(excludedOption)));
if (excludedOption == BASIC_AUTH) { if (excludedOption == BASIC_AUTH) {
@ -98,7 +98,7 @@ class BaseRequestGeneratingCommandTest {
void getSomeOptionsExcludeTwo() { void getSomeOptionsExcludeTwo() {
Options options = tested.getSomeOptions(Lists.newArrayList(VERSION, HEADER_PASSTHROUGH)); Options options = tested.getSomeOptions(Lists.newArrayList(VERSION, HEADER_PASSTHROUGH));
assertEquals(5, options.getOptions().size()); assertThat(options.getOptions()).hasSize(5);
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM)); assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME)); assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME));

View File

@ -45,8 +45,8 @@ import java.nio.file.Path;
import java.util.Date; import java.util.Date;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
@ -120,7 +120,7 @@ public class BulkImportCommandTest {
})).start(); })).start();
ourLog.info("Waiting for initiation requests"); ourLog.info("Waiting for initiation requests");
await().until(() -> myRestfulServerExtension.getRequestContentTypes().size(), equalTo(2)); await().untilAsserted(() -> assertThat(myRestfulServerExtension.getRequestContentTypes()).hasSize(2));
ourLog.info("Initiation requests complete"); ourLog.info("Initiation requests complete");
verify(myJobCoordinator, timeout(10000).times(1)).startInstance(any(RequestDetails.class), myStartCaptor.capture()); verify(myJobCoordinator, timeout(10000).times(1)).startInstance(any(RequestDetails.class), myStartCaptor.capture());
@ -129,7 +129,7 @@ public class BulkImportCommandTest {
BulkImportJobParameters jobParameters = startRequest.getParameters(BulkImportJobParameters.class); BulkImportJobParameters jobParameters = startRequest.getParameters(BulkImportJobParameters.class);
// Reverse order because Patient should be first // Reverse order because Patient should be first
assertEquals(2, jobParameters.getNdJsonUrls().size()); assertThat(jobParameters.getNdJsonUrls()).hasSize(2);
assertEquals(fileContents2, fetchFile(jobParameters.getNdJsonUrls().get(0))); assertEquals(fileContents2, fetchFile(jobParameters.getNdJsonUrls().get(0)));
assertEquals(fileContents1, fetchFile(jobParameters.getNdJsonUrls().get(1))); assertEquals(fileContents1, fetchFile(jobParameters.getNdJsonUrls().get(1)));
} }
@ -163,7 +163,7 @@ public class BulkImportCommandTest {
})).start(); })).start();
ourLog.info("Waiting for initiation requests"); ourLog.info("Waiting for initiation requests");
await().until(() -> myRestfulServerExtension.getRequestContentTypes().size(), equalTo(2)); await().untilAsserted(() -> assertThat(myRestfulServerExtension.getRequestContentTypes()).hasSize(2));
ourLog.info("Initiation requests complete"); ourLog.info("Initiation requests complete");
verify(myJobCoordinator, timeout(10000).times(1)).startInstance(any(RequestDetails.class), myStartCaptor.capture()); verify(myJobCoordinator, timeout(10000).times(1)).startInstance(any(RequestDetails.class), myStartCaptor.capture());
@ -172,7 +172,7 @@ public class BulkImportCommandTest {
BulkImportJobParameters jobParameters = startRequest.getParameters(BulkImportJobParameters.class); BulkImportJobParameters jobParameters = startRequest.getParameters(BulkImportJobParameters.class);
// Reverse order because Patient should be first // Reverse order because Patient should be first
assertEquals(2, jobParameters.getNdJsonUrls().size()); assertThat(jobParameters.getNdJsonUrls()).hasSize(2);
assertEquals(fileContents2, fetchFile(jobParameters.getNdJsonUrls().get(0))); assertEquals(fileContents2, fetchFile(jobParameters.getNdJsonUrls().get(0)));
assertEquals(fileContents1, fetchFile(jobParameters.getNdJsonUrls().get(1))); assertEquals(fileContents1, fetchFile(jobParameters.getNdJsonUrls().get(1)));
} }
@ -205,7 +205,7 @@ public class BulkImportCommandTest {
})).start(); })).start();
ourLog.info("Waiting for initiation requests"); ourLog.info("Waiting for initiation requests");
await().until(() -> myRestfulServerExtension.getRequestContentTypes().size(), equalTo(2)); await().untilAsserted(() -> assertThat(myRestfulServerExtension.getRequestContentTypes()).hasSize(2));
ourLog.info("Initiation requests complete"); ourLog.info("Initiation requests complete");
verify(myJobCoordinator, timeout(10000).times(1)).startInstance(any(RequestDetails.class), myStartCaptor.capture()); verify(myJobCoordinator, timeout(10000).times(1)).startInstance(any(RequestDetails.class), myStartCaptor.capture());
@ -215,7 +215,7 @@ public class BulkImportCommandTest {
BulkImportJobParameters jobParameters = startRequest.getParameters(BulkImportJobParameters.class); BulkImportJobParameters jobParameters = startRequest.getParameters(BulkImportJobParameters.class);
// Reverse order because Patient should be first // Reverse order because Patient should be first
assertEquals(2, jobParameters.getNdJsonUrls().size()); assertThat(jobParameters.getNdJsonUrls()).hasSize(2);
assertEquals(fileContents2, fetchFile(jobParameters.getNdJsonUrls().get(0))); assertEquals(fileContents2, fetchFile(jobParameters.getNdJsonUrls().get(0)));
assertEquals(fileContents1, fetchFile(jobParameters.getNdJsonUrls().get(1))); assertEquals(fileContents1, fetchFile(jobParameters.getNdJsonUrls().get(1)));
} }

View File

@ -19,12 +19,10 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.hamcrest.CoreMatchers.hasItems; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class ExampleDataUploaderTest { class ExampleDataUploaderTest {
@ -70,12 +68,12 @@ class ExampleDataUploaderTest {
Map<String, List<String>> allHeaders = myCapturingInterceptor.getLastRequest().getAllHeaders(); Map<String, List<String>> allHeaders = myCapturingInterceptor.getLastRequest().getAllHeaders();
assertFalse(allHeaders.isEmpty()); assertFalse(allHeaders.isEmpty());
assertTrue(allHeaders.containsKey(headerKey)); assertThat(allHeaders).containsKey(headerKey);
assertEquals(1, allHeaders.get(headerKey).size()); assertThat(allHeaders.get(headerKey)).hasSize(1);
assertThat(allHeaders.get(headerKey), hasItems(headerValue)); assertThat(allHeaders.get(headerKey)).contains(headerValue);
assertEquals(1, myRestServerR4Helper.getTransactions().size()); assertThat(myRestServerR4Helper.getTransactions()).hasSize(1);
Bundle bundle = myRestServerR4Helper.getTransactions().get(0); Bundle bundle = myRestServerR4Helper.getTransactions().get(0);
Resource resource = bundle.getEntry().get(0).getResource(); Resource resource = bundle.getEntry().get(0).getResource();
assertEquals(Patient.class, resource.getClass()); assertEquals(Patient.class, resource.getClass());

View File

@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.migrate.dao.HapiMigrationDao;
import ca.uhn.fhir.jpa.migrate.entity.HapiMigrationEntity; import ca.uhn.fhir.jpa.migrate.entity.HapiMigrationEntity;
import ca.uhn.fhir.system.HapiSystemProperties; import ca.uhn.fhir.system.HapiSystemProperties;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import jakarta.annotation.Nonnull;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -14,7 +15,6 @@ import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatemen
import org.springframework.jdbc.support.lob.DefaultLobHandler; import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobCreator; import org.springframework.jdbc.support.lob.LobCreator;
import jakarta.annotation.Nonnull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -30,8 +30,7 @@ import java.util.UUID;
import static ca.uhn.fhir.jpa.migrate.HapiMigrationLock.LOCK_PID; import static ca.uhn.fhir.jpa.migrate.HapiMigrationLock.LOCK_PID;
import static ca.uhn.fhir.jpa.migrate.HapiMigrationStorageSvc.LOCK_TYPE; import static ca.uhn.fhir.jpa.migrate.HapiMigrationStorageSvc.LOCK_TYPE;
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.hamcrest.CoreMatchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
@ -66,9 +65,8 @@ public class HapiClearMigrationLockCommandTest extends ConsoleOutputCapturingBas
int beforeClearMigrationCount = dao.findAll().size(); int beforeClearMigrationCount = dao.findAll().size();
try { try {
App.main(args); App.main(args);
fail(); fail(); } catch (CommandFailureException e) {
} catch (CommandFailureException e) { assertThat(e.getMessage()).contains("HAPI-2152: Internal error: on unlocking, a competing lock was found");
assertThat(e.getMessage(), containsString("HAPI-2152: Internal error: on unlocking, a competing lock was found"));
} }
} }
@Test @Test
@ -91,7 +89,7 @@ public class HapiClearMigrationLockCommandTest extends ConsoleOutputCapturingBas
int afterClearMigrationCount = dao.findAll().size(); int afterClearMigrationCount = dao.findAll().size();
int removedRows = beforeClearMigrationCount - afterClearMigrationCount; int removedRows = beforeClearMigrationCount - afterClearMigrationCount;
assertEquals(0, removedRows); assertEquals(0, removedRows);
assertThat(getConsoleOutput(), containsString("Did not successfully remove lock entry. [uuid="+ lockUUID +"]")); assertThat(getConsoleOutput()).contains("Did not successfully remove lock entry. [uuid=" + lockUUID + "]");
} }
@Test @Test
public void testMigrateAndClearExistingLock() throws IOException, SQLException { public void testMigrateAndClearExistingLock() throws IOException, SQLException {
@ -115,7 +113,7 @@ public class HapiClearMigrationLockCommandTest extends ConsoleOutputCapturingBas
int removedRows = beforeClearMigrationCount - afterClearMigrationCount; int removedRows = beforeClearMigrationCount - afterClearMigrationCount;
assertEquals(1, removedRows); assertEquals(1, removedRows);
assertThat(getConsoleOutput(), containsString("Successfully removed lock entry. [uuid="+ lockUUID +"]")); assertThat(getConsoleOutput()).contains("Successfully removed lock entry. [uuid=" + lockUUID + "]");
} }
private record ConnectionData(DriverTypeEnum.ConnectionProperties connectionProperties, String url) {} private record ConnectionData(DriverTypeEnum.ConnectionProperties connectionProperties, String url) {}

View File

@ -5,12 +5,10 @@ import ca.uhn.fhir.jpa.migrate.JdbcUtils;
import ca.uhn.fhir.jpa.migrate.SchemaMigrator; import ca.uhn.fhir.jpa.migrate.SchemaMigrator;
import ca.uhn.fhir.jpa.migrate.dao.HapiMigrationDao; import ca.uhn.fhir.jpa.migrate.dao.HapiMigrationDao;
import ca.uhn.fhir.jpa.migrate.entity.HapiMigrationEntity; import ca.uhn.fhir.jpa.migrate.entity.HapiMigrationEntity;
import ca.uhn.fhir.jpa.migrate.SchemaMigrator;
import ca.uhn.fhir.jpa.migrate.dao.HapiMigrationDao;
import ca.uhn.fhir.jpa.migrate.entity.HapiMigrationEntity;
import ca.uhn.fhir.jpa.util.RandomTextUtils; import ca.uhn.fhir.jpa.util.RandomTextUtils;
import ca.uhn.fhir.system.HapiSystemProperties; import ca.uhn.fhir.system.HapiSystemProperties;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import jakarta.annotation.Nonnull;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.MethodOrderer;
@ -23,7 +21,6 @@ import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatemen
import org.springframework.jdbc.support.lob.DefaultLobHandler; import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobCreator; import org.springframework.jdbc.support.lob.LobCreator;
import jakarta.annotation.Nonnull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -37,6 +34,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -76,43 +74,43 @@ public class HapiFlywayMigrateDatabaseCommandTest {
"-p", "SA" "-p", "SA"
}; };
assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_RES_REINDEX_JOB")); assertThat(JdbcUtils.getTableNames(connectionProperties)).doesNotContain("HFJ_RES_REINDEX_JOB");
// Verify that HFJ_SEARCH_PARM exists along with index and foreign key dependencies. // Verify that HFJ_SEARCH_PARM exists along with index and foreign key dependencies.
assertTrue(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_SEARCH_PARM")); assertThat(JdbcUtils.getTableNames(connectionProperties)).contains("HFJ_SEARCH_PARM");
Set<String> indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_SEARCH_PARM"); Set<String> indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_SEARCH_PARM");
assertTrue(indexNames.contains("IDX_SEARCHPARM_RESTYPE_SPNAME")); assertThat(indexNames).contains("IDX_SEARCHPARM_RESTYPE_SPNAME");
Set<String> foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_SEARCH_PARM", "HFJ_RES_PARAM_PRESENT"); Set<String> foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_SEARCH_PARM", "HFJ_RES_PARAM_PRESENT");
assertTrue(foreignKeys.contains("FK_RESPARMPRES_SPID")); assertThat(foreignKeys).contains("FK_RESPARMPRES_SPID");
// Verify that IDX_FORCEDID_TYPE_FORCEDID index exists on HFJ_FORCED_ID table // Verify that IDX_FORCEDID_TYPE_FORCEDID index exists on HFJ_FORCED_ID table
indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_FORCED_ID"); indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_FORCED_ID");
assertTrue(indexNames.contains("IDX_FORCEDID_TYPE_FORCEDID")); assertThat(indexNames).contains("IDX_FORCEDID_TYPE_FORCEDID");
// Verify that HFJ_RES_PARAM_PRESENT has column SP_ID // Verify that HFJ_RES_PARAM_PRESENT has column SP_ID
Set<String> columnNames = JdbcUtils.getColumnNames(connectionProperties, "HFJ_RES_PARAM_PRESENT"); Set<String> columnNames = JdbcUtils.getColumnNames(connectionProperties, "HFJ_RES_PARAM_PRESENT");
assertTrue(columnNames.contains("SP_ID")); assertThat(columnNames).contains("SP_ID");
// Verify that SEQ_SEARCHPARM_ID sequence exists // Verify that SEQ_SEARCHPARM_ID sequence exists
Set<String> seqNames = JdbcUtils.getSequenceNames(connectionProperties); Set<String> seqNames = JdbcUtils.getSequenceNames(connectionProperties);
assertTrue(seqNames.contains("SEQ_SEARCHPARM_ID")); assertThat(seqNames).contains("SEQ_SEARCHPARM_ID");
// Verify that foreign key FK_SEARCHRES_RES on HFJ_SEARCH_RESULT exists // Verify that foreign key FK_SEARCHRES_RES on HFJ_SEARCH_RESULT exists
foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_RESOURCE", "HFJ_SEARCH_RESULT"); foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_RESOURCE", "HFJ_SEARCH_RESULT");
assertTrue(foreignKeys.contains("FK_SEARCHRES_RES")); assertThat(foreignKeys).contains("FK_SEARCHRES_RES");
App.main(args); App.main(args);
assertTrue(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_RES_REINDEX_JOB")); assertThat(JdbcUtils.getTableNames(connectionProperties)).contains("HFJ_RES_REINDEX_JOB");
// Verify that HFJ_SEARCH_PARM has been removed // Verify that HFJ_SEARCH_PARM has been removed
assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_SEARCH_PARM")); assertThat(JdbcUtils.getTableNames(connectionProperties)).doesNotContain("HFJ_SEARCH_PARM");
// Verify that IDX_FORCEDID_TYPE_FORCEDID index no longer exists on HFJ_FORCED_ID table // Verify that IDX_FORCEDID_TYPE_FORCEDID index no longer exists on HFJ_FORCED_ID table
indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_FORCED_ID"); indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_FORCED_ID");
assertFalse(indexNames.contains("IDX_FORCEDID_TYPE_FORCEDID")); assertThat(indexNames).doesNotContain("IDX_FORCEDID_TYPE_FORCEDID");
// Verify that HFJ_RES_PARAM_PRESENT no longer has column SP_ID // Verify that HFJ_RES_PARAM_PRESENT no longer has column SP_ID
columnNames = JdbcUtils.getColumnNames(connectionProperties, "HFJ_RES_PARAM_PRESENT"); columnNames = JdbcUtils.getColumnNames(connectionProperties, "HFJ_RES_PARAM_PRESENT");
assertFalse(columnNames.contains("SP_ID")); assertThat(columnNames).doesNotContain("SP_ID");
// Verify that SEQ_SEARCHPARM_ID sequence no longer exists // Verify that SEQ_SEARCHPARM_ID sequence no longer exists
seqNames = JdbcUtils.getSequenceNames(connectionProperties); seqNames = JdbcUtils.getSequenceNames(connectionProperties);
assertFalse(seqNames.contains("SEQ_SEARCHPARM_ID")); assertThat(seqNames).doesNotContain("SEQ_SEARCHPARM_ID");
// Verify that foreign key FK_SEARCHRES_RES on HFJ_SEARCH_RESULT no longer exists // Verify that foreign key FK_SEARCHRES_RES on HFJ_SEARCH_RESULT no longer exists
foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_RESOURCE", "HFJ_SEARCH_RESULT"); foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_RESOURCE", "HFJ_SEARCH_RESULT");
assertFalse(foreignKeys.contains("FK_SEARCHRES_RES")); assertThat(foreignKeys).doesNotContain("FK_SEARCHRES_RES");
connectionProperties.getTxTemplate().execute(t -> { connectionProperties.getTxTemplate().execute(t -> {
JdbcTemplate jdbcTemplate = connectionProperties.newJdbcTemplate(); JdbcTemplate jdbcTemplate = connectionProperties.newJdbcTemplate();
@ -155,45 +153,45 @@ public class HapiFlywayMigrateDatabaseCommandTest {
}; };
// Verify that HFJ_SEARCH_PARM exists along with index and foreign key dependencies. // Verify that HFJ_SEARCH_PARM exists along with index and foreign key dependencies.
assertTrue(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_SEARCH_PARM")); assertThat(JdbcUtils.getTableNames(connectionProperties)).contains("HFJ_SEARCH_PARM");
Set<String> indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_SEARCH_PARM"); Set<String> indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_SEARCH_PARM");
assertTrue(indexNames.contains("IDX_SEARCHPARM_RESTYPE_SPNAME")); assertThat(indexNames).contains("IDX_SEARCHPARM_RESTYPE_SPNAME");
Set<String> foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_SEARCH_PARM", "HFJ_RES_PARAM_PRESENT"); Set<String> foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_SEARCH_PARM", "HFJ_RES_PARAM_PRESENT");
assertTrue(foreignKeys.contains("FK_RESPARMPRES_SPID")); assertThat(foreignKeys).contains("FK_RESPARMPRES_SPID");
// Verify that IDX_FORCEDID_TYPE_FORCEDID index exists on HFJ_FORCED_ID table // Verify that IDX_FORCEDID_TYPE_FORCEDID index exists on HFJ_FORCED_ID table
indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_FORCED_ID"); indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_FORCED_ID");
assertTrue(indexNames.contains("IDX_FORCEDID_TYPE_FORCEDID")); assertThat(indexNames).contains("IDX_FORCEDID_TYPE_FORCEDID");
// Verify that HFJ_RES_PARAM_PRESENT has column SP_ID // Verify that HFJ_RES_PARAM_PRESENT has column SP_ID
Set<String> columnNames = JdbcUtils.getColumnNames(connectionProperties, "HFJ_RES_PARAM_PRESENT"); Set<String> columnNames = JdbcUtils.getColumnNames(connectionProperties, "HFJ_RES_PARAM_PRESENT");
assertTrue(columnNames.contains("SP_ID")); assertThat(columnNames).contains("SP_ID");
// Verify that SEQ_SEARCHPARM_ID sequence exists // Verify that SEQ_SEARCHPARM_ID sequence exists
Set<String> seqNames = JdbcUtils.getSequenceNames(connectionProperties); Set<String> seqNames = JdbcUtils.getSequenceNames(connectionProperties);
assertTrue(seqNames.contains("SEQ_SEARCHPARM_ID")); assertThat(seqNames).contains("SEQ_SEARCHPARM_ID");
// Verify that foreign key FK_SEARCHRES_RES on HFJ_SEARCH_RESULT exists // Verify that foreign key FK_SEARCHRES_RES on HFJ_SEARCH_RESULT exists
foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_RESOURCE", "HFJ_SEARCH_RESULT"); foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_RESOURCE", "HFJ_SEARCH_RESULT");
assertTrue(foreignKeys.contains("FK_SEARCHRES_RES")); assertThat(foreignKeys).contains("FK_SEARCHRES_RES");
int expectedMigrationEntities = hapiMigrationDao.findAll().size(); int expectedMigrationEntities = hapiMigrationDao.findAll().size();
App.main(args); App.main(args);
// Verify that HFJ_SEARCH_PARM still exists along with index and foreign key dependencies. // Verify that HFJ_SEARCH_PARM still exists along with index and foreign key dependencies.
assertTrue(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_SEARCH_PARM")); assertThat(JdbcUtils.getTableNames(connectionProperties)).contains("HFJ_SEARCH_PARM");
indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_SEARCH_PARM"); indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_SEARCH_PARM");
assertTrue(indexNames.contains("IDX_SEARCHPARM_RESTYPE_SPNAME")); assertThat(indexNames).contains("IDX_SEARCHPARM_RESTYPE_SPNAME");
foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_SEARCH_PARM", "HFJ_RES_PARAM_PRESENT"); foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_SEARCH_PARM", "HFJ_RES_PARAM_PRESENT");
assertTrue(foreignKeys.contains("FK_RESPARMPRES_SPID")); assertThat(foreignKeys).contains("FK_RESPARMPRES_SPID");
// Verify that IDX_FORCEDID_TYPE_FORCEDID index still exists on HFJ_FORCED_ID table // Verify that IDX_FORCEDID_TYPE_FORCEDID index still exists on HFJ_FORCED_ID table
indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_FORCED_ID"); indexNames = JdbcUtils.getIndexNames(connectionProperties, "HFJ_FORCED_ID");
assertTrue(indexNames.contains("IDX_FORCEDID_TYPE_FORCEDID")); assertThat(indexNames).contains("IDX_FORCEDID_TYPE_FORCEDID");
// Verify that HFJ_RES_PARAM_PRESENT still has column SP_ID // Verify that HFJ_RES_PARAM_PRESENT still has column SP_ID
columnNames = JdbcUtils.getColumnNames(connectionProperties, "HFJ_RES_PARAM_PRESENT"); columnNames = JdbcUtils.getColumnNames(connectionProperties, "HFJ_RES_PARAM_PRESENT");
assertTrue(columnNames.contains("SP_ID")); assertThat(columnNames).contains("SP_ID");
// Verify that SEQ_SEARCHPARM_ID sequence still exists // Verify that SEQ_SEARCHPARM_ID sequence still exists
seqNames = JdbcUtils.getSequenceNames(connectionProperties); seqNames = JdbcUtils.getSequenceNames(connectionProperties);
assertTrue(seqNames.contains("SEQ_SEARCHPARM_ID")); assertThat(seqNames).contains("SEQ_SEARCHPARM_ID");
// Verify that foreign key FK_SEARCHRES_RES on HFJ_SEARCH_RESULT still exists // Verify that foreign key FK_SEARCHRES_RES on HFJ_SEARCH_RESULT still exists
foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_RESOURCE", "HFJ_SEARCH_RESULT"); foreignKeys = JdbcUtils.getForeignKeys(connectionProperties, "HFJ_RESOURCE", "HFJ_SEARCH_RESULT");
assertTrue(foreignKeys.contains("FK_SEARCHRES_RES")); assertThat(foreignKeys).contains("FK_SEARCHRES_RES");
assertTrue(expectedMigrationEntities == hapiMigrationDao.findAll().size()); assertTrue(expectedMigrationEntities == hapiMigrationDao.findAll().size());
} }
@ -223,8 +221,8 @@ public class HapiFlywayMigrateDatabaseCommandTest {
assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_RESOURCE")); assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_RESOURCE"));
assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_BLK_EXPORT_JOB")); assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_BLK_EXPORT_JOB"));
App.main(args); App.main(args);
assertTrue(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_RESOURCE")); // Early table assertThat(JdbcUtils.getTableNames(connectionProperties)).contains("HFJ_RESOURCE"); // Early table
assertTrue(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_BLK_EXPORT_JOB")); // Late table assertThat(JdbcUtils.getTableNames(connectionProperties)).contains("HFJ_BLK_EXPORT_JOB"); // Late table
} }
@Test @Test
@ -256,7 +254,7 @@ public class HapiFlywayMigrateDatabaseCommandTest {
App.main(args); App.main(args);
assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("FLY_HFJ_MIGRATION")); assertThat(JdbcUtils.getTableNames(connectionProperties)).doesNotContain("FLY_HFJ_MIGRATION");
} }
@Nonnull @Nonnull

View File

@ -6,16 +6,10 @@ import ca.uhn.fhir.jpa.term.UploadStatistics;
import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc; import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc;
import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.interceptor.CapturingInterceptor; import ca.uhn.fhir.rest.client.interceptor.CapturingInterceptor;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.test.utilities.JettyUtil;
import ca.uhn.fhir.test.utilities.server.HttpServletExtension;
import ca.uhn.fhir.test.utilities.server.RestfulServerExtension; import ca.uhn.fhir.test.utilities.server.RestfulServerExtension;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.ee10.servlet.ServletHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.IdType;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -33,12 +27,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.hamcrest.CoreMatchers.hasItems; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
@ -98,10 +90,10 @@ public class HeaderPassthroughOptionTest {
Map<String, List<String>> allHeaders = myCapturingInterceptor.getLastRequest().getAllHeaders(); Map<String, List<String>> allHeaders = myCapturingInterceptor.getLastRequest().getAllHeaders();
assertFalse(allHeaders.isEmpty()); assertFalse(allHeaders.isEmpty());
assertTrue(allHeaders.containsKey(headerKey1)); assertThat(allHeaders).containsKey(headerKey1);
assertEquals(1, allHeaders.get(headerKey1).size()); assertThat(allHeaders.get(headerKey1)).hasSize(1);
assertThat(allHeaders.get(headerKey1), hasItems(headerValue1)); assertThat(allHeaders.get(headerKey1)).contains(headerValue1);
} }
@Test @Test
@ -128,10 +120,10 @@ public class HeaderPassthroughOptionTest {
assertNotNull(myCapturingInterceptor.getLastRequest()); assertNotNull(myCapturingInterceptor.getLastRequest());
Map<String, List<String>> allHeaders = myCapturingInterceptor.getLastRequest().getAllHeaders(); Map<String, List<String>> allHeaders = myCapturingInterceptor.getLastRequest().getAllHeaders();
assertFalse(allHeaders.isEmpty()); assertFalse(allHeaders.isEmpty());
assertEquals(2, allHeaders.get(headerKey1).size()); assertThat(allHeaders.get(headerKey1)).hasSize(2);
assertTrue(allHeaders.containsKey(headerKey1)); assertThat(allHeaders).containsKey(headerKey1);
assertEquals(2, allHeaders.get(headerKey1).size()); assertThat(allHeaders.get(headerKey1)).hasSize(2);
assertEquals(headerValue1, allHeaders.get(headerKey1).get(0)); assertEquals(headerValue1, allHeaders.get(headerKey1).get(0));
assertEquals(headerValue2, allHeaders.get(headerKey1).get(1)); assertEquals(headerValue2, allHeaders.get(headerKey1).get(1));
@ -163,13 +155,13 @@ public class HeaderPassthroughOptionTest {
Map<String, List<String>> allHeaders = myCapturingInterceptor.getLastRequest().getAllHeaders(); Map<String, List<String>> allHeaders = myCapturingInterceptor.getLastRequest().getAllHeaders();
assertFalse(allHeaders.isEmpty()); assertFalse(allHeaders.isEmpty());
assertTrue(allHeaders.containsKey(headerKey1)); assertThat(allHeaders).containsKey(headerKey1);
assertEquals(1, allHeaders.get(headerKey1).size()); assertThat(allHeaders.get(headerKey1)).hasSize(1);
assertThat(allHeaders.get(headerKey1), hasItems(headerValue1)); assertThat(allHeaders.get(headerKey1)).contains(headerValue1);
assertTrue(allHeaders.containsKey(headerKey2)); assertThat(allHeaders).containsKey(headerKey2);
assertEquals(1, allHeaders.get(headerKey2).size()); assertThat(allHeaders.get(headerKey2)).hasSize(1);
assertThat(allHeaders.get(headerKey2), hasItems(headerValue2)); assertThat(allHeaders.get(headerKey2)).contains(headerValue2);
} }
private static void writeConceptAndHierarchyFiles(int theFilenameCounter) throws IOException { private static void writeConceptAndHierarchyFiles(int theFilenameCounter) throws IOException {

View File

@ -1,13 +1,12 @@
package ca.uhn.fhir.cli; package ca.uhn.fhir.cli;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
public class HelpOptionTest extends ConsoleOutputCapturingBaseTest { public class HelpOptionTest extends ConsoleOutputCapturingBaseTest {
@Test @Test
public void testHelpOption() { public void testHelpOption() {
App.main(new String[]{"help", "create-package"}); App.main(new String[]{"help", "create-package"});
assertThat(outputStreamCaptor.toString().trim(), outputStreamCaptor.toString().trim(), containsString("Usage")); assertThat(outputStreamCaptor.toString().trim()).as(outputStreamCaptor.toString().trim()).contains("Usage");
} }
} }

View File

@ -23,6 +23,7 @@ import org.junit.jupiter.params.provider.ValueSource;
import java.io.File; import java.io.File;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
@ -153,7 +154,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals(VS_URL_1, conceptMap.getSourceUriType().getValueAsString()); assertEquals(VS_URL_1, conceptMap.getSourceUriType().getValueAsString());
assertEquals(VS_URL_2, conceptMap.getTargetUriType().getValueAsString()); assertEquals(VS_URL_2, conceptMap.getTargetUriType().getValueAsString());
assertEquals(3, conceptMap.getGroup().size()); assertThat(conceptMap.getGroup()).hasSize(3);
ConceptMapGroupComponent group = conceptMap.getGroup().get(0); ConceptMapGroupComponent group = conceptMap.getGroup().get(0);
assertEquals(CS_URL_1, group.getSource()); assertEquals(CS_URL_1, group.getSource());
@ -161,13 +162,13 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals(CS_URL_2, group.getTarget()); assertEquals(CS_URL_2, group.getTarget());
assertEquals("Version 2t", group.getTargetVersion()); assertEquals("Version 2t", group.getTargetVersion());
assertEquals(4, group.getElement().size()); assertThat(group.getElement()).hasSize(4);
SourceElementComponent source = group.getElement().get(0); SourceElementComponent source = group.getElement().get(0);
assertEquals("Code 1a", source.getCode()); assertEquals("Code 1a", source.getCode());
assertEquals("Display 1a", source.getDisplay()); assertEquals("Display 1a", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
TargetElementComponent target = source.getTarget().get(0); TargetElementComponent target = source.getTarget().get(0);
assertEquals("Code 2a", target.getCode()); assertEquals("Code 2a", target.getCode());
@ -179,7 +180,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 1b", source.getCode()); assertEquals("Code 1b", source.getCode());
assertEquals("Display 1b", source.getDisplay()); assertEquals("Display 1b", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 2b", target.getCode()); assertEquals("Code 2b", target.getCode());
@ -191,7 +192,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 1c", source.getCode()); assertEquals("Code 1c", source.getCode());
assertEquals("Display 1c", source.getDisplay()); assertEquals("Display 1c", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 2c", target.getCode()); assertEquals("Code 2c", target.getCode());
@ -203,7 +204,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 1d", source.getCode()); assertEquals("Code 1d", source.getCode());
assertEquals("Display 1d", source.getDisplay()); assertEquals("Display 1d", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 2d", target.getCode()); assertEquals("Code 2d", target.getCode());
@ -217,13 +218,13 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals(CS_URL_3, group.getTarget()); assertEquals(CS_URL_3, group.getTarget());
assertEquals("Version 3t", group.getTargetVersion()); assertEquals("Version 3t", group.getTargetVersion());
assertEquals(4, group.getElement().size()); assertThat(group.getElement()).hasSize(4);
source = group.getElement().get(0); source = group.getElement().get(0);
assertEquals("Code 1a", source.getCode()); assertEquals("Code 1a", source.getCode());
assertEquals("Display 1a", source.getDisplay()); assertEquals("Display 1a", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3a", target.getCode()); assertEquals("Code 3a", target.getCode());
@ -235,7 +236,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 1b", source.getCode()); assertEquals("Code 1b", source.getCode());
assertEquals("Display 1b", source.getDisplay()); assertEquals("Display 1b", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3b", target.getCode()); assertEquals("Code 3b", target.getCode());
@ -247,7 +248,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 1c", source.getCode()); assertEquals("Code 1c", source.getCode());
assertEquals("Display 1c", source.getDisplay()); assertEquals("Display 1c", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3c", target.getCode()); assertEquals("Code 3c", target.getCode());
@ -259,7 +260,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 1d", source.getCode()); assertEquals("Code 1d", source.getCode());
assertEquals("Display 1d", source.getDisplay()); assertEquals("Display 1d", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3d", target.getCode()); assertEquals("Code 3d", target.getCode());
@ -279,7 +280,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 2a", source.getCode()); assertEquals("Code 2a", source.getCode());
assertEquals("Display 2a", source.getDisplay()); assertEquals("Display 2a", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3a", target.getCode()); assertEquals("Code 3a", target.getCode());
@ -291,7 +292,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 2b", source.getCode()); assertEquals("Code 2b", source.getCode());
assertEquals("Display 2b", source.getDisplay()); assertEquals("Display 2b", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3b", target.getCode()); assertEquals("Code 3b", target.getCode());
@ -303,7 +304,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 2c", source.getCode()); assertEquals("Code 2c", source.getCode());
assertEquals("Display 2c", source.getDisplay()); assertEquals("Display 2c", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3c", target.getCode()); assertEquals("Code 3c", target.getCode());
@ -315,7 +316,7 @@ public class ImportCsvToConceptMapCommandDstu3Test {
assertEquals("Code 2d", source.getCode()); assertEquals("Code 2d", source.getCode());
assertEquals("Display 2d", source.getDisplay()); assertEquals("Display 2d", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3d", target.getCode()); assertEquals("Code 3d", target.getCode());

View File

@ -23,11 +23,13 @@ import org.junit.jupiter.params.provider.ValueSource;
import java.io.File; import java.io.File;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class ImportCsvToConceptMapCommandR4Test { public class ImportCsvToConceptMapCommandR4Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ImportCsvToConceptMapCommandR4Test.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ImportCsvToConceptMapCommandR4Test.class);
private static final String CM_URL = "http://example.com/conceptmap"; private static final String CM_URL = "http://example.com/conceptmap";
@ -164,7 +166,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals(VS_URL_1, conceptMap.getSourceUriType().getValueAsString()); assertEquals(VS_URL_1, conceptMap.getSourceUriType().getValueAsString());
assertEquals(VS_URL_2, conceptMap.getTargetUriType().getValueAsString()); assertEquals(VS_URL_2, conceptMap.getTargetUriType().getValueAsString());
assertEquals(3, conceptMap.getGroup().size()); assertThat(conceptMap.getGroup()).hasSize(3);
ConceptMapGroupComponent group = conceptMap.getGroup().get(0); ConceptMapGroupComponent group = conceptMap.getGroup().get(0);
assertEquals(CS_URL_1, group.getSource()); assertEquals(CS_URL_1, group.getSource());
@ -172,13 +174,13 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals(CS_URL_2, group.getTarget()); assertEquals(CS_URL_2, group.getTarget());
assertEquals("Version 2t", group.getTargetVersion()); assertEquals("Version 2t", group.getTargetVersion());
assertEquals(4, group.getElement().size()); assertThat(group.getElement()).hasSize(4);
SourceElementComponent source = group.getElement().get(0); SourceElementComponent source = group.getElement().get(0);
assertEquals("Code 1a", source.getCode()); assertEquals("Code 1a", source.getCode());
assertEquals("Display 1a", source.getDisplay()); assertEquals("Display 1a", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
TargetElementComponent target = source.getTarget().get(0); TargetElementComponent target = source.getTarget().get(0);
assertEquals("Code 2a", target.getCode()); assertEquals("Code 2a", target.getCode());
@ -190,7 +192,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 1b", source.getCode()); assertEquals("Code 1b", source.getCode());
assertEquals("Display 1b", source.getDisplay()); assertEquals("Display 1b", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 2b", target.getCode()); assertEquals("Code 2b", target.getCode());
@ -202,7 +204,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 1c", source.getCode()); assertEquals("Code 1c", source.getCode());
assertEquals("Display 1c", source.getDisplay()); assertEquals("Display 1c", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 2c", target.getCode()); assertEquals("Code 2c", target.getCode());
@ -214,7 +216,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 1d", source.getCode()); assertEquals("Code 1d", source.getCode());
assertEquals("Display 1d", source.getDisplay()); assertEquals("Display 1d", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 2d", target.getCode()); assertEquals("Code 2d", target.getCode());
@ -228,13 +230,13 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals(CS_URL_3, group.getTarget()); assertEquals(CS_URL_3, group.getTarget());
assertEquals("Version 3t", group.getTargetVersion()); assertEquals("Version 3t", group.getTargetVersion());
assertEquals(4, group.getElement().size()); assertThat(group.getElement()).hasSize(4);
source = group.getElement().get(0); source = group.getElement().get(0);
assertEquals("Code 1a", source.getCode()); assertEquals("Code 1a", source.getCode());
assertEquals("Display 1a", source.getDisplay()); assertEquals("Display 1a", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3a", target.getCode()); assertEquals("Code 3a", target.getCode());
@ -246,7 +248,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 1b", source.getCode()); assertEquals("Code 1b", source.getCode());
assertEquals("Display 1b", source.getDisplay()); assertEquals("Display 1b", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3b", target.getCode()); assertEquals("Code 3b", target.getCode());
@ -258,7 +260,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 1c", source.getCode()); assertEquals("Code 1c", source.getCode());
assertEquals("Display 1c", source.getDisplay()); assertEquals("Display 1c", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3c", target.getCode()); assertEquals("Code 3c", target.getCode());
@ -270,7 +272,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 1d", source.getCode()); assertEquals("Code 1d", source.getCode());
assertEquals("Display 1d", source.getDisplay()); assertEquals("Display 1d", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3d", target.getCode()); assertEquals("Code 3d", target.getCode());
@ -290,7 +292,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 2a", source.getCode()); assertEquals("Code 2a", source.getCode());
assertEquals("Display 2a", source.getDisplay()); assertEquals("Display 2a", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3a", target.getCode()); assertEquals("Code 3a", target.getCode());
@ -302,7 +304,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 2b", source.getCode()); assertEquals("Code 2b", source.getCode());
assertEquals("Display 2b", source.getDisplay()); assertEquals("Display 2b", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3b", target.getCode()); assertEquals("Code 3b", target.getCode());
@ -314,7 +316,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 2c", source.getCode()); assertEquals("Code 2c", source.getCode());
assertEquals("Display 2c", source.getDisplay()); assertEquals("Display 2c", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3c", target.getCode()); assertEquals("Code 3c", target.getCode());
@ -326,7 +328,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("Code 2d", source.getCode()); assertEquals("Code 2d", source.getCode());
assertEquals("Display 2d", source.getDisplay()); assertEquals("Display 2d", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
target = source.getTarget().get(0); target = source.getTarget().get(0);
assertEquals("Code 3d", target.getCode()); assertEquals("Code 3d", target.getCode());
@ -412,7 +414,7 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("http://loinc.org", conceptMap.getSourceUriType().getValueAsString()); assertEquals("http://loinc.org", conceptMap.getSourceUriType().getValueAsString());
assertEquals("http://phenxtoolkit.org", conceptMap.getTargetUriType().getValueAsString()); assertEquals("http://phenxtoolkit.org", conceptMap.getTargetUriType().getValueAsString());
assertEquals(1, conceptMap.getGroup().size()); assertThat(conceptMap.getGroup()).hasSize(1);
ConceptMapGroupComponent group = conceptMap.getGroup().get(0); ConceptMapGroupComponent group = conceptMap.getGroup().get(0);
assertEquals("http://loinc.org", group.getSource()); assertEquals("http://loinc.org", group.getSource());
@ -420,13 +422,13 @@ public class ImportCsvToConceptMapCommandR4Test {
assertEquals("http://phenxtoolkit.org", group.getTarget()); assertEquals("http://phenxtoolkit.org", group.getTarget());
assertNull(group.getTargetVersion()); assertNull(group.getTargetVersion());
assertEquals(1, group.getElement().size()); assertThat(group.getElement()).hasSize(1);
SourceElementComponent source = group.getElement().get(0); SourceElementComponent source = group.getElement().get(0);
assertEquals("65191-9", source.getCode()); assertEquals("65191-9", source.getCode());
assertEquals("During the past 30 days, about how often did you feel restless or fidgety [Kessler 6 Distress]", source.getDisplay()); assertEquals("During the past 30 days, about how often did you feel restless or fidgety [Kessler 6 Distress]", source.getDisplay());
assertEquals(1, source.getTarget().size()); assertThat(source.getTarget()).hasSize(1);
TargetElementComponent target = source.getTarget().get(0); TargetElementComponent target = source.getTarget().get(0);
assertEquals("PX121301010300", target.getCode()); assertEquals("PX121301010300", target.getCode());
@ -479,9 +481,8 @@ public class ImportCsvToConceptMapCommandR4Test {
}, },
"-t", true, myRestServerR4Helper "-t", true, myRestServerR4Helper
)); ));
fail(); fail(); } catch (Error e) {
} catch (Error e) { assertThat(e.getMessage()).contains("Missing required option: s");
assertTrue(e.getMessage().contains("Missing required option: s"));
} }
} }
} }

View File

@ -6,9 +6,9 @@ import ca.uhn.fhir.system.HapiSystemProperties;
import ca.uhn.fhir.test.utilities.RestServerR4Helper; import ca.uhn.fhir.test.utilities.RestServerR4Helper;
import ca.uhn.fhir.test.utilities.TlsAuthenticationTestHelper; import ca.uhn.fhir.test.utilities.TlsAuthenticationTestHelper;
import ca.uhn.fhir.util.ParametersUtil; import ca.uhn.fhir.util.ParametersUtil;
import ca.uhn.test.util.LogbackCaptureTestExtension; import ca.uhn.test.util.LogEventIterableAssert;
import ca.uhn.test.util.LogbackTestExtension;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IBaseParameters; import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -21,10 +21,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.util.function.Consumer; import java.util.function.Consumer;
import static ca.uhn.fhir.jpa.provider.BaseJpaSystemProvider.RESP_PARAM_SUCCESS; import static ca.uhn.fhir.jpa.provider.BaseJpaSystemProvider.RESP_PARAM_SUCCESS;
import static ca.uhn.test.util.LogbackCaptureTestExtension.eventWithMessageContains; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
@ -44,7 +41,7 @@ class ReindexTerminologyCommandTest {
public TlsAuthenticationTestHelper myTlsAuthenticationTestHelper = new TlsAuthenticationTestHelper(); public TlsAuthenticationTestHelper myTlsAuthenticationTestHelper = new TlsAuthenticationTestHelper();
// Deliberately not registered - we manually run this later because App startup resets the logging. // Deliberately not registered - we manually run this later because App startup resets the logging.
LogbackCaptureTestExtension myAppLogCapture; LogbackTestExtension myAppLogCapture;
static { static {
HapiSystemProperties.enableTestMode(); HapiSystemProperties.enableTestMode();
@ -71,7 +68,7 @@ class ReindexTerminologyCommandTest {
); );
runAppWithStartupHook(args, getLoggingStartupHook()); runAppWithStartupHook(args, getLoggingStartupHook());
assertThat(myAppLogCapture.getLogEvents(), Matchers.not(hasItem(eventWithMessageContains("FAILURE")))); LogEventIterableAssert.assertThat(myAppLogCapture.getLogEvents()).hasNoFailureMessages();
} }
@ -92,7 +89,7 @@ class ReindexTerminologyCommandTest {
App.main(args); App.main(args);
fail(); fail();
} catch (Error e) { } catch (Error e) {
assertThat(e.getMessage(), containsString("Missing required option: v")); assertThat(e.getMessage()).contains("Missing required option: v");
} }
} }
@ -114,7 +111,7 @@ class ReindexTerminologyCommandTest {
)); ));
fail(); fail();
} catch (Error e) { } catch (Error e) {
assertThat(e.getMessage(), containsString("Missing required option: t")); assertThat(e.getMessage()).contains("Missing required option: t");
} }
} }
@ -134,8 +131,8 @@ class ReindexTerminologyCommandTest {
); );
runAppWithStartupHook(args, getLoggingStartupHook()); runAppWithStartupHook(args, getLoggingStartupHook());
assertThat(myAppLogCapture.getLogEvents(), hasItem(eventWithMessageContains("FAILURE"))); LogEventIterableAssert.assertThat(myAppLogCapture.getLogEvents()).hasAtLeastOneFailureMessage();
assertThat(myAppLogCapture.getLogEvents(), hasItem(eventWithMessageContains("Internal error. Command result unknown. Check system logs for details"))); LogEventIterableAssert.assertThat(myAppLogCapture.getLogEvents()).hasAtLeastOneEventWithMessage("Internal error. Command result unknown. Check system logs for details");
} }
@ParameterizedTest @ParameterizedTest
@ -158,8 +155,8 @@ class ReindexTerminologyCommandTest {
); );
runAppWithStartupHook(args, getLoggingStartupHook()); runAppWithStartupHook(args, getLoggingStartupHook());
assertThat(myAppLogCapture.getLogEvents(), hasItem(eventWithMessageContains("FAILURE"))); LogEventIterableAssert.assertThat(myAppLogCapture.getLogEvents()).hasAtLeastOneFailureMessage();
assertThat(myAppLogCapture.getLogEvents(), hasItem(eventWithMessageContains("Freetext service is not configured. Operation didn't run."))); LogEventIterableAssert.assertThat(myAppLogCapture.getLogEvents()).hasAtLeastOneEventWithMessage("Freetext service is not configured. Operation didn't run.");
} }
static void runAppWithStartupHook(String[] args, Consumer<BaseApp> startupHook) { static void runAppWithStartupHook(String[] args, Consumer<BaseApp> startupHook) {
@ -177,7 +174,7 @@ class ReindexTerminologyCommandTest {
*/ */
Consumer<BaseApp> getLoggingStartupHook() { Consumer<BaseApp> getLoggingStartupHook() {
return (unused) -> { return (unused) -> {
myAppLogCapture = new LogbackCaptureTestExtension((Logger) BaseApp.ourLog); myAppLogCapture = new LogbackTestExtension((Logger) BaseApp.ourLog);
myAppLogCapture.setUp(); myAppLogCapture.setUp();
}; };
} }

View File

@ -17,7 +17,6 @@ import com.google.common.base.Charsets;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.hamcrest.Matchers;
import org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService; import org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService;
import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport;
import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain;
@ -52,12 +51,7 @@ import java.util.stream.Stream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import static org.hamcrest.CoreMatchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -171,9 +165,9 @@ public class UploadTerminologyCommandTest {
verify(myTermLoaderSvc, times(1)).loadDeltaAdd(eq("http://foo"), myDescriptorListCaptor.capture(), any()); verify(myTermLoaderSvc, times(1)).loadDeltaAdd(eq("http://foo"), myDescriptorListCaptor.capture(), any());
List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue(); List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue();
assertEquals(1, listOfDescriptors.size()); assertThat(listOfDescriptors).hasSize(1);
assertEquals("file:/files.zip", listOfDescriptors.get(0).getFilename()); assertEquals("file:/files.zip", listOfDescriptors.get(0).getFilename());
assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length, greaterThan(100)); assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length).isGreaterThan(100);
} }
@ParameterizedTest @ParameterizedTest
@ -211,10 +205,10 @@ public class UploadTerminologyCommandTest {
verify(myTermLoaderSvc, times(1)).loadDeltaAdd(eq("http://foo"), myDescriptorListCaptor.capture(), any()); verify(myTermLoaderSvc, times(1)).loadDeltaAdd(eq("http://foo"), myDescriptorListCaptor.capture(), any());
List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue(); List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue();
assertEquals(2, listOfDescriptors.size()); assertThat(listOfDescriptors).hasSize(2);
assertEquals("concepts.csv", listOfDescriptors.get(0).getFilename()); assertEquals("concepts.csv", listOfDescriptors.get(0).getFilename());
String uploadFile = IOUtils.toString(listOfDescriptors.get(0).getInputStream(), Charsets.UTF_8); String uploadFile = IOUtils.toString(listOfDescriptors.get(0).getInputStream(), Charsets.UTF_8);
assertThat(uploadFile, uploadFile, containsString("\"CODE\",\"Display\"")); assertThat(uploadFile).as(uploadFile).contains("\"CODE\",\"Display\"");
} }
@ParameterizedTest @ParameterizedTest
@ -247,9 +241,8 @@ public class UploadTerminologyCommandTest {
}, },
"-t", theIncludeTls, myBaseRestServerHelper "-t", theIncludeTls, myBaseRestServerHelper
)); ));
fail(); fail(); } catch (Error e) {
} catch (Error e) { assertThat(e.toString()).contains("HTTP 400 Bad Request: " + Msg.code(362) + "Request has parameter codeSystem of type Patient but method expects type CodeSystem");
assertThat(e.toString(), containsString("HTTP 400 Bad Request: " + Msg.code(362) + "Request has parameter codeSystem of type Patient but method expects type CodeSystem"));
} }
} }
@ -272,9 +265,8 @@ public class UploadTerminologyCommandTest {
"-t", theIncludeTls, myBaseRestServerHelper "-t", theIncludeTls, myBaseRestServerHelper
)); ));
fail(); fail(); } catch (Error e) {
} catch (Error e) { assertThat(e.toString()).contains("Don't know how to handle file:");
assertThat(e.toString(), containsString("Don't know how to handle file:"));
} }
} }
@ -284,15 +276,15 @@ public class UploadTerminologyCommandTest {
UploadTerminologyCommand uploadTerminologyCommand = new UploadTerminologyCommand(); UploadTerminologyCommand uploadTerminologyCommand = new UploadTerminologyCommand();
uploadTerminologyCommand.setTransferSizeLimitHuman("1GB"); uploadTerminologyCommand.setTransferSizeLimitHuman("1GB");
long bytes = uploadTerminologyCommand.getTransferSizeLimit(); long bytes = uploadTerminologyCommand.getTransferSizeLimit();
assertThat(bytes, is(equalTo(1024L * 1024L * 1024L))); assertEquals(1024L * 1024L * 1024L, bytes);
uploadTerminologyCommand.setTransferSizeLimitHuman("500KB"); uploadTerminologyCommand.setTransferSizeLimitHuman("500KB");
bytes = uploadTerminologyCommand.getTransferSizeLimit(); bytes = uploadTerminologyCommand.getTransferSizeLimit();
assertThat(bytes, is(equalTo(1024L * 500L))); assertEquals(1024L * 500L, bytes);
uploadTerminologyCommand.setTransferSizeLimitHuman("10MB"); uploadTerminologyCommand.setTransferSizeLimitHuman("10MB");
bytes = uploadTerminologyCommand.getTransferSizeLimit(); bytes = uploadTerminologyCommand.getTransferSizeLimit();
assertThat(bytes, is(equalTo(1024L * 1024L * 10L))); assertEquals(1024L * 1024L * 10L, bytes);
} }
@ParameterizedTest @ParameterizedTest
@ -316,9 +308,9 @@ public class UploadTerminologyCommandTest {
verify(myTermLoaderSvc, times(1)).loadDeltaAdd(eq("http://foo"), myDescriptorListCaptor.capture(), any()); verify(myTermLoaderSvc, times(1)).loadDeltaAdd(eq("http://foo"), myDescriptorListCaptor.capture(), any());
List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue(); List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue();
assertEquals(1, listOfDescriptors.size()); assertThat(listOfDescriptors).hasSize(1);
assertThat(listOfDescriptors.get(0).getFilename(), matchesPattern("^file:.*temp.*\\.zip$")); assertThat(listOfDescriptors.get(0).getFilename()).matches("^file:.*temp.*\\.zip$");
assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length, greaterThan(100)); assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length).isGreaterThan(100);
} }
@ParameterizedTest @ParameterizedTest
@ -336,9 +328,8 @@ public class UploadTerminologyCommandTest {
}, },
"-t", theIncludeTls, myBaseRestServerHelper "-t", theIncludeTls, myBaseRestServerHelper
)); ));
fail(); fail(); } catch (Error e) {
} catch (Error e) { assertThat(e.toString().replace('\\', '/')).contains("FileNotFoundException: target/concepts.csv/foo.csv");
assertThat(e.toString().replace('\\', '/'), Matchers.containsString("FileNotFoundException: target/concepts.csv/foo.csv"));
} }
} }
@ -368,9 +359,9 @@ public class UploadTerminologyCommandTest {
verify(myTermLoaderSvc, times(1)).loadDeltaRemove(eq("http://foo"), myDescriptorListCaptor.capture(), any()); verify(myTermLoaderSvc, times(1)).loadDeltaRemove(eq("http://foo"), myDescriptorListCaptor.capture(), any());
List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue(); List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue();
assertEquals(1, listOfDescriptors.size()); assertThat(listOfDescriptors).hasSize(1);
assertEquals("file:/files.zip", listOfDescriptors.get(0).getFilename()); assertEquals("file:/files.zip", listOfDescriptors.get(0).getFilename());
assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length, greaterThan(100)); assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length).isGreaterThan(100);
} }
@ParameterizedTest @ParameterizedTest
@ -399,9 +390,9 @@ public class UploadTerminologyCommandTest {
verify(myTermLoaderSvc, times(1)).loadCustom(any(), myDescriptorListCaptor.capture(), any()); verify(myTermLoaderSvc, times(1)).loadCustom(any(), myDescriptorListCaptor.capture(), any());
List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue(); List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue();
assertEquals(1, listOfDescriptors.size()); assertThat(listOfDescriptors).hasSize(1);
assertEquals("file:/files.zip", listOfDescriptors.get(0).getFilename()); assertEquals("file:/files.zip", listOfDescriptors.get(0).getFilename());
assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length, greaterThan(100)); assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length).isGreaterThan(100);
} }
@ParameterizedTest @ParameterizedTest
@ -433,9 +424,9 @@ public class UploadTerminologyCommandTest {
verify(myTermLoaderSvc, times(1)).loadCustom(any(), myDescriptorListCaptor.capture(), any()); verify(myTermLoaderSvc, times(1)).loadCustom(any(), myDescriptorListCaptor.capture(), any());
List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue(); List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue();
assertEquals(1, listOfDescriptors.size()); assertThat(listOfDescriptors).hasSize(1);
assertThat(listOfDescriptors.get(0).getFilename(), matchesPattern(".*\\.zip$")); assertThat(listOfDescriptors.get(0).getFilename()).matches(".*\\.zip$");
assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length, greaterThan(100)); assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length).isGreaterThan(100);
} }
@ParameterizedTest @ParameterizedTest
@ -466,9 +457,9 @@ public class UploadTerminologyCommandTest {
verify(myTermLoaderSvc, times(1)).loadCustom(any(), myDescriptorListCaptor.capture(), any()); verify(myTermLoaderSvc, times(1)).loadCustom(any(), myDescriptorListCaptor.capture(), any());
List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue(); List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue();
assertEquals(1, listOfDescriptors.size()); assertThat(listOfDescriptors).hasSize(1);
assertThat(listOfDescriptors.get(0).getFilename(), matchesPattern(".*\\.zip$")); assertThat(listOfDescriptors.get(0).getFilename()).matches(".*\\.zip$");
assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length, greaterThan(100)); assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length).isGreaterThan(100);
} }
@ParameterizedTest @ParameterizedTest
@ -588,9 +579,9 @@ public class UploadTerminologyCommandTest {
verify(myTermLoaderSvc, times(1)).loadIcd10cm(myDescriptorListCaptor.capture(), any()); verify(myTermLoaderSvc, times(1)).loadIcd10cm(myDescriptorListCaptor.capture(), any());
List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue(); List<ITermLoaderSvc.FileDescriptor> listOfDescriptors = myDescriptorListCaptor.getValue();
assertEquals(1, listOfDescriptors.size()); assertThat(listOfDescriptors).hasSize(1);
assertThat(listOfDescriptors.get(0).getFilename(), matchesPattern("^file:.*files.*\\.zip$")); assertThat(listOfDescriptors.get(0).getFilename()).matches("^file:.*files.*\\.zip$");
assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length, greaterThan(100)); assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length).isGreaterThan(100);
} }
private RequestValidatingInterceptor createRequestValidatingInterceptor(){ private RequestValidatingInterceptor createRequestValidatingInterceptor(){

View File

@ -15,10 +15,11 @@ import org.junit.jupiter.params.provider.MethodSource;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class HapiFhirCliRestfulClientFactoryTest extends BaseFhirVersionParameterizedTest{ public class HapiFhirCliRestfulClientFactoryTest extends BaseFhirVersionParameterizedTest{
@ParameterizedTest @ParameterizedTest
@ -63,8 +64,7 @@ public class HapiFhirCliRestfulClientFactoryTest extends BaseFhirVersionParamete
try{ try{
HttpUriRequest request = new HttpGet(fhirVersionParams.getSecuredPatientEndpoint()); HttpUriRequest request = new HttpGet(fhirVersionParams.getSecuredPatientEndpoint());
unauthenticatedClient.execute(request); unauthenticatedClient.execute(request);
fail(); fail(); }
}
catch(Exception e){ catch(Exception e){
assertEquals(SSLHandshakeException.class, e.getClass()); assertEquals(SSLHandshakeException.class, e.getClass());
} }
@ -101,9 +101,8 @@ public class HapiFhirCliRestfulClientFactoryTest extends BaseFhirVersionParamete
context.setRestfulClientFactory(new HapiFhirCliRestfulClientFactory(context)); context.setRestfulClientFactory(new HapiFhirCliRestfulClientFactory(context));
try { try {
context.newRestfulGenericClient(secureBase).search().forResource("Patient").execute(); context.newRestfulGenericClient(secureBase).search().forResource("Patient").execute();
fail(); fail(); } catch (Exception e) {
} catch (Exception e) { assertThat(e.getMessage()).contains("HAPI-1357: Failed to retrieve the server metadata statement during client initialization");
assertTrue(e.getMessage().contains("HAPI-1357: Failed to retrieve the server metadata statement during client initialization"));
assertEquals(SSLHandshakeException.class, e.getCause().getCause().getClass()); assertEquals(SSLHandshakeException.class, e.getCause().getCause().getClass());
} }
} }

View File

@ -29,7 +29,12 @@ import okhttp3.MediaType;
import okhttp3.Response; import okhttp3.Response;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import java.io.*; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View File

@ -43,23 +43,16 @@ import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class GenericOkHttpClientDstu2Test { public class GenericOkHttpClientDstu2Test {
@ -150,18 +143,18 @@ public class GenericOkHttpClientDstu2Test {
client.fetchConformance().ofType(Conformance.class).execute(); client.fetchConformance().ofType(Conformance.class).execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", MY_SERVLET.ourRequestUri);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY)); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue()).contains(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY);
client.fetchConformance().ofType(Conformance.class).encodedJson().execute(); client.fetchConformance().ofType(Conformance.class).encodedJson().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", MY_SERVLET.ourRequestUri);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
client.fetchConformance().ofType(Conformance.class).encodedXml().execute(); client.fetchConformance().ofType(Conformance.class).encodedXml().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=xml", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=xml", MY_SERVLET.ourRequestUri);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_XML);
} }
@Test @Test
@ -183,15 +176,15 @@ public class GenericOkHttpClientDstu2Test {
Patient resp = client.read(Patient.class, new IdDt("123")); Patient resp = client.read(Patient.class, new IdDt("123"));
assertEquals("FAMILY", resp.getName().get(0).getFamily().get(0).getValue()); assertEquals("FAMILY", resp.getName().get(0).getFamily().get(0).getValue());
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", MY_SERVLET.ourRequestUriAll.get(0)); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", MY_SERVLET.ourRequestUriAll.get(0));
assertEquals(1, MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_XML);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123", MY_SERVLET.ourRequestUriAll.get(1)); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123", MY_SERVLET.ourRequestUriAll.get(1));
assertEquals(1, MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_XML);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
} }
@Test @Test
@ -214,13 +207,13 @@ public class GenericOkHttpClientDstu2Test {
Patient resp = client.read(Patient.class, new IdDt("123")); Patient resp = client.read(Patient.class, new IdDt("123"));
assertEquals("FAMILY", resp.getName().get(0).getFamily().get(0).getValue()); assertEquals("FAMILY", resp.getName().get(0).getFamily().get(0).getValue());
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", MY_SERVLET.ourRequestUriAll.get(0)); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", MY_SERVLET.ourRequestUriAll.get(0));
assertEquals(1, MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), not(containsString(Constants.CT_FHIR_XML))); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).doesNotContain(Constants.CT_FHIR_XML);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=json", MY_SERVLET.ourRequestUriAll.get(1)); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=json", MY_SERVLET.ourRequestUriAll.get(1));
assertEquals(1, MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), not(containsString(Constants.CT_FHIR_XML))); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).doesNotContain(Constants.CT_FHIR_XML);
} }
@Test @Test
@ -254,20 +247,20 @@ public class GenericOkHttpClientDstu2Test {
client.create().resource(p).encodedXml().execute(); client.create().resource(p).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
p.setId("123"); p.setId("123");
client.create().resource(p).encodedXml().execute(); client.create().resource(p).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
String body = MY_SERVLET.ourRequestBodyString; String body = MY_SERVLET.ourRequestBodyString;
assertThat(body, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(body).contains("<family value=\"FOOFAMILY\"/>");
assertThat(body, not(containsString("123"))); assertThat(body).doesNotContain("123");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
} }
@ -282,26 +275,26 @@ public class GenericOkHttpClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.create().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute(); client.create().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
String expectedContentTypeHeader = EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8; String expectedContentTypeHeader = EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8;
assertContentTypeEquals(expectedContentTypeHeader); assertContentTypeEquals(expectedContentTypeHeader);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue());
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
client.create().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); client.create().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(expectedContentTypeHeader); assertContentTypeEquals(expectedContentTypeHeader);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue());
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
client.create().resource(p).conditional().where(Patient.NAME.matches().value("foo")).encodedXml().execute(); client.create().resource(p).conditional().where(Patient.NAME.matches().value("foo")).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(expectedContentTypeHeader); assertContentTypeEquals(expectedContentTypeHeader);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue());
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -310,7 +303,7 @@ public class GenericOkHttpClientDstu2Test {
private void assertContentTypeEquals(String expectedContentTypeHeader) { private void assertContentTypeEquals(String expectedContentTypeHeader) {
// charsets are case-insensitive according to the HTTP spec (e.g. utf-8 == UTF-8): // charsets are case-insensitive according to the HTTP spec (e.g. utf-8 == UTF-8):
// https://tools.ietf.org/html/rfc2616#section-3.4 // https://tools.ietf.org/html/rfc2616#section-3.4
assertThat(getActualContentTypeHeader(), equalToIgnoringCase(expectedContentTypeHeader)); assertThat(getActualContentTypeHeader()).isEqualToIgnoringCase(expectedContentTypeHeader);
} }
@Test @Test
@ -323,11 +316,11 @@ public class GenericOkHttpClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.create().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); client.create().resource(p).prefer(PreferReturnEnum.MINIMAL).execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
client.create().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); client.create().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
} }
@ -402,7 +395,7 @@ public class GenericOkHttpClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
.history() .history()
@ -413,7 +406,7 @@ public class GenericOkHttpClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
.history() .history()
@ -423,7 +416,7 @@ public class GenericOkHttpClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
.history() .history()
@ -432,7 +425,7 @@ public class GenericOkHttpClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
.history() .history()
@ -441,7 +434,7 @@ public class GenericOkHttpClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
.history() .history()
@ -451,9 +444,11 @@ public class GenericOkHttpClientDstu2Test {
.since(new InstantDt("2001-01-02T11:22:33Z")) .since(new InstantDt("2001-01-02T11:22:33Z"))
.execute(); .execute();
assertThat(MY_SERVLET.ourRequestUri, either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123")) assertThat(MY_SERVLET.ourRequestUri).isIn(
.or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z"))); ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123",
assertEquals(1, response.getEntry().size()); ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z");
assertThat(response.getEntry()).hasSize(1);
response = client response = client
.history() .history()
@ -462,8 +457,8 @@ public class GenericOkHttpClientDstu2Test {
.since(new InstantDt("2001-01-02T11:22:33Z").getValue()) .since(new InstantDt("2001-01-02T11:22:33Z").getValue())
.execute(); .execute();
assertThat(MY_SERVLET.ourRequestUri, containsString("_since=2001-01")); assertThat(MY_SERVLET.ourRequestUri).contains("_since=2001-01");
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
} }
@Test @Test
@ -492,8 +487,7 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$meta-add", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$meta-add", MY_SERVLET.ourRequestUri);
assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue());
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"meta\"/><valueMeta><profile value=\"urn:profile:in\"/></valueMeta></parameter></Parameters>", assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"meta\"/><valueMeta><profile value=\"urn:profile:in\"/></valueMeta></parameter></Parameters>", MY_SERVLET.ourRequestBodyString);
MY_SERVLET.ourRequestBodyString);
} }
@Test @Test
@ -723,11 +717,11 @@ public class GenericOkHttpClientDstu2Test {
.withParameters(inParams).encodedXml().execute(); .withParameters(inParams).encodedXml().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals(1, resp.getParameter().size()); assertThat(resp.getParameter()).hasSize(1);
assertEquals(ca.uhn.fhir.model.dstu2.resource.Bundle.class, resp.getParameter().get(0).getResource().getClass()); assertEquals(ca.uhn.fhir.model.dstu2.resource.Bundle.class, resp.getParameter().get(0).getResource().getClass());
} }
@ -756,12 +750,10 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals( assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueString value=\"value1\"/></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", (MY_SERVLET.ourRequestBodyString));
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueString value=\"value1\"/></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>",
(MY_SERVLET.ourRequestBodyString));
/* /*
* Composite type * Composite type
@ -778,12 +770,10 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals( assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", (MY_SERVLET.ourRequestBodyString));
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>",
(MY_SERVLET.ourRequestBodyString));
/* /*
* Resource * Resource
@ -800,12 +790,10 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals( assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><active value=\"true\"/></Patient></resource></parameter></Parameters>", (MY_SERVLET.ourRequestBodyString));
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><active value=\"true\"/></Patient></resource></parameter></Parameters>",
(MY_SERVLET.ourRequestBodyString));
} }
@Test @Test
@ -847,7 +835,7 @@ public class GenericOkHttpClientDstu2Test {
} }
}; };
assertThrows(IllegalArgumentException.class, () -> { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
client client
.operation() .operation()
.onServer() .onServer()
@ -894,9 +882,7 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/1/$validate-code", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/1/$validate-code", MY_SERVLET.ourRequestUri);
ourLog.info(MY_SERVLET.ourRequestBodyString); ourLog.info(MY_SERVLET.ourRequestBodyString);
assertEquals( assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"code\"/><valueCode value=\"8495-4\"/></parameter><parameter><name value=\"system\"/><valueUri value=\"http://loinc.org\"/></parameter></Parameters>", MY_SERVLET.ourRequestBodyString);
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"code\"/><valueCode value=\"8495-4\"/></parameter><parameter><name value=\"system\"/><valueUri value=\"http://loinc.org\"/></parameter></Parameters>",
MY_SERVLET.ourRequestBodyString);
} }
@Test @Test
@ -926,7 +912,7 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -939,7 +925,7 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -952,7 +938,7 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -987,7 +973,7 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -1000,7 +986,7 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -1013,7 +999,7 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -1044,7 +1030,7 @@ public class GenericOkHttpClientDstu2Test {
.next(sourceBundle) .next(sourceBundle)
.execute(); .execute();
assertEquals(1, resp.getEntry().size()); assertThat(resp.getEntry()).hasSize(1);
assertEquals(ourServer.getBaseUrl() + "/fhir/next", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/next", MY_SERVLET.ourRequestUri);
} }
@ -1056,7 +1042,7 @@ public class GenericOkHttpClientDstu2Test {
try { try {
client.loadPage().next(sourceBundle).execute(); client.loadPage().next(sourceBundle).execute();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Can not perform paging operation because no link was found in Bundle with relation \"next\"")); assertThat(e.getMessage()).contains("Can not perform paging operation because no link was found in Bundle with relation \"next\"");
} }
} }
@ -1075,7 +1061,7 @@ public class GenericOkHttpClientDstu2Test {
.previous(sourceBundle) .previous(sourceBundle)
.execute(); .execute();
assertEquals(1, resp.getEntry().size()); assertThat(resp.getEntry()).hasSize(1);
assertEquals(ourServer.getBaseUrl() + "/fhir/prev", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/prev", MY_SERVLET.ourRequestUri);
/* /*
@ -1090,7 +1076,7 @@ public class GenericOkHttpClientDstu2Test {
.previous(sourceBundle) .previous(sourceBundle)
.execute(); .execute();
assertEquals(1, resp.getEntry().size()); assertThat(resp.getEntry()).hasSize(1);
assertEquals(ourServer.getBaseUrl() + "/fhir/prev", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/prev", MY_SERVLET.ourRequestUri);
} }
@ -1178,8 +1164,9 @@ public class GenericOkHttpClientDstu2Test {
.elementsSubset("name", "identifier") .elementsSubset("name", "identifier")
.execute(); .execute();
assertThat(MY_SERVLET.ourRequestUri, either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=name%2Cidentifier")) assertThat(MY_SERVLET.ourRequestUri).isIn(
.or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=identifier%2Cname"))); ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=name%2Cidentifier",
ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=identifier%2Cname");
assertEquals(Patient.class, response.getClass()); assertEquals(Patient.class, response.getClass());
} }
@ -1200,7 +1187,7 @@ public class GenericOkHttpClientDstu2Test {
.execute(); .execute();
fail(); fail();
} catch (InvalidResponseException e) { } catch (InvalidResponseException e) {
assertThat(e.getMessage(), containsString("String does not appear to be valid")); assertThat(e.getMessage()).contains("String does not appear to be valid");
} }
} }
@ -1347,13 +1334,14 @@ public class GenericOkHttpClientDstu2Test {
.returnBundle(Bundle.class) .returnBundle(Bundle.class)
.execute(); .execute();
assertThat(MY_SERVLET.ourRequestUri, either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier")) assertThat(MY_SERVLET.ourRequestUri).isIn(
.or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname"))); ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier",
ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname");
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
} }
@Test @Test
public void testSearchByPost() throws Exception { public void testSearchByPost() {
String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
MY_SERVLET.ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; MY_SERVLET.ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8";
@ -1381,11 +1369,11 @@ public class GenericOkHttpClientDstu2Test {
assertEquals("application/x-www-form-urlencoded", MY_SERVLET.ourRequestContentType.replace(";char", "; char").toLowerCase()); assertEquals("application/x-www-form-urlencoded", MY_SERVLET.ourRequestContentType.replace(";char", "; char").toLowerCase());
assertEquals(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY, MY_SERVLET.ourRequestFirstHeaders.get("Accept").getValue()); assertEquals(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY, MY_SERVLET.ourRequestFirstHeaders.get("Accept").getValue());
assertThat(MY_SERVLET.ourRequestFirstHeaders.get("User-Agent").getValue(), not(emptyString())); assertThat(MY_SERVLET.ourRequestFirstHeaders.get("User-Agent").getValue()).isNotEmpty();
} }
@Test @Test
public void testSearchByPostUseJson() throws Exception { public void testSearchByPostUseJson() {
String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
MY_SERVLET.ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; MY_SERVLET.ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8";
@ -1402,9 +1390,9 @@ public class GenericOkHttpClientDstu2Test {
.returnBundle(Bundle.class) .returnBundle(Bundle.class)
.execute(); .execute();
assertThat(MY_SERVLET.ourRequestUri, containsString(ourServer.getBaseUrl() + "/fhir/Patient/_search?")); assertThat(MY_SERVLET.ourRequestUri).contains(ourServer.getBaseUrl() + "/fhir/Patient/_search?");
assertThat(MY_SERVLET.ourRequestUri, containsString("_elements=identifier%2Cname")); assertThat(MY_SERVLET.ourRequestUri).contains("_elements=identifier%2Cname");
assertThat(MY_SERVLET.ourRequestUri, not(containsString("_format=json"))); assertThat(MY_SERVLET.ourRequestUri).doesNotContain("_format=json");
// assertThat(MY_SERVLET.ourRequestUri, // assertThat(MY_SERVLET.ourRequestUri,
// either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() + // either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() +
@ -1462,7 +1450,7 @@ public class GenericOkHttpClientDstu2Test {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Test @Test
public void testSearchWithReverseInclude() throws Exception { public void testSearchWithReverseInclude() {
String msg = getPatientFeedWithOneResult(); String msg = getPatientFeedWithOneResult();
MY_SERVLET.ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; MY_SERVLET.ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8";
@ -1481,7 +1469,7 @@ public class GenericOkHttpClientDstu2Test {
} }
@Test @Test
public void testSearchWithSummaryParam() throws Exception { public void testSearchWithSummaryParam() {
String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
MY_SERVLET.ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; MY_SERVLET.ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8";
@ -1501,7 +1489,7 @@ public class GenericOkHttpClientDstu2Test {
} }
@Test @Test
public void testTransactionWithString() throws Exception { public void testTransactionWithString() {
ca.uhn.fhir.model.dstu2.resource.Bundle req = new ca.uhn.fhir.model.dstu2.resource.Bundle(); ca.uhn.fhir.model.dstu2.resource.Bundle req = new ca.uhn.fhir.model.dstu2.resource.Bundle();
Patient patient = new Patient(); Patient patient = new Patient();
patient.addName().addFamily("PAT_FAMILY"); patient.addName().addFamily("PAT_FAMILY");
@ -1525,7 +1513,7 @@ public class GenericOkHttpClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/", MY_SERVLET.ourRequestUri);
assertThat(response, containsString("\"Bundle\"")); assertThat(response).contains("\"Bundle\"");
assertContentTypeEquals("application/json+fhir; charset=UTF-8"); assertContentTypeEquals("application/json+fhir; charset=UTF-8");
response = client.transaction() response = client.transaction()
@ -1566,7 +1554,7 @@ public class GenericOkHttpClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir", MY_SERVLET.ourRequestUri);
assertEquals(2, response.getEntry().size()); assertThat(response.getEntry()).hasSize(2);
assertEquals("Patient/1/_history/1", response.getEntry().get(0).getResponse().getLocation()); assertEquals("Patient/1/_history/1", response.getEntry().get(0).getResponse().getLocation());
assertEquals("Patient/2/_history/2", response.getEntry().get(1).getResponse().getLocation()); assertEquals("Patient/2/_history/2", response.getEntry().get(1).getResponse().getLocation());
@ -1582,37 +1570,37 @@ public class GenericOkHttpClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.update().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute(); client.update().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestUri);
client.update().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); client.update().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", MY_SERVLET.ourRequestUri);
client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditionalByUrl("Patient?name=foo").encodedXml().execute(); client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditionalByUrl("Patient?name=foo").encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestUri);
client.update().resource(p).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); client.update().resource(p).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", MY_SERVLET.ourRequestUri);
client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", MY_SERVLET.ourRequestUri);
} }
@ -1632,18 +1620,18 @@ public class GenericOkHttpClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.update(new IdDt("Patient/123"), p); client.update(new IdDt("Patient/123"), p);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
String expectedContentTypeHeader = EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8; String expectedContentTypeHeader = EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8;
assertThat(getActualContentTypeHeader(), equalToIgnoringCase(expectedContentTypeHeader)); assertThat(getActualContentTypeHeader()).isEqualToIgnoringCase(expectedContentTypeHeader);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", MY_SERVLET.ourRequestUri);
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
client.update("123", p); client.update("123", p);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertThat(getActualContentTypeHeader(), equalToIgnoringCase(expectedContentTypeHeader)); assertThat(getActualContentTypeHeader()).isEqualToIgnoringCase(expectedContentTypeHeader);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", MY_SERVLET.ourRequestUri);
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
} }
@ -1659,11 +1647,11 @@ public class GenericOkHttpClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.update().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); client.update().resource(p).prefer(PreferReturnEnum.MINIMAL).execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
client.update().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); client.update().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
} }
@ -1707,18 +1695,14 @@ public class GenericOkHttpClientDstu2Test {
response = client.validate().resource(p).encodedXml().execute(); response = client.validate().resource(p).encodedXml().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals( assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>", MY_SERVLET.ourRequestBodyString);
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>",
MY_SERVLET.ourRequestBodyString);
assertNotNull(response.getOperationOutcome()); assertNotNull(response.getOperationOutcome());
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
response = client.validate().resource(ourCtx.newXmlParser().encodeResourceToString(p)).execute(); response = client.validate().resource(ourCtx.newXmlParser().encodeResourceToString(p)).execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals( assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>", MY_SERVLET.ourRequestBodyString);
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>",
MY_SERVLET.ourRequestBodyString);
assertNotNull(response.getOperationOutcome()); assertNotNull(response.getOperationOutcome());
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
@ -1732,7 +1716,7 @@ public class GenericOkHttpClientDstu2Test {
response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute(); response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate?_pretty=true", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate?_pretty=true", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("\"resourceType\": \"Parameters\",\n")); assertThat(MY_SERVLET.ourRequestBodyString).contains("\"resourceType\": \"Parameters\",\n");
assertNotNull(response.getOperationOutcome()); assertNotNull(response.getOperationOutcome());
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
} }
@ -1758,9 +1742,7 @@ public class GenericOkHttpClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate?_format=xml", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate?_format=xml", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals( assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>", MY_SERVLET.ourRequestBodyString);
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>",
MY_SERVLET.ourRequestBodyString);
assertNotNull(response.getOperationOutcome()); assertNotNull(response.getOperationOutcome());
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
} }

View File

@ -2,7 +2,6 @@ package ca.uhn.fhir.okhttp;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory; import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory;
import ca.uhn.fhir.test.BaseFhirVersionParameterizedTest; import ca.uhn.fhir.test.BaseFhirVersionParameterizedTest;
import okhttp3.Call; import okhttp3.Call;
@ -18,12 +17,13 @@ import org.junit.jupiter.params.provider.MethodSource;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame; 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.junit.jupiter.api.Assertions.fail;
public class OkHttpRestfulClientFactoryTest extends BaseFhirVersionParameterizedTest { public class OkHttpRestfulClientFactoryTest extends BaseFhirVersionParameterizedTest {
private OkHttpRestfulClientFactory clientFactory; private OkHttpRestfulClientFactory clientFactory;
@ -44,7 +44,7 @@ public class OkHttpRestfulClientFactoryTest extends BaseFhirVersionParameterized
public void testGetNativeClient_noProxySet_defaultHasNoProxySet() throws Exception { public void testGetNativeClient_noProxySet_defaultHasNoProxySet() throws Exception {
OkHttpClient actualNativeClient = (OkHttpClient) clientFactory.getNativeClient(); OkHttpClient actualNativeClient = (OkHttpClient) clientFactory.getNativeClient();
assertEquals(null, actualNativeClient.proxy()); assertNull(actualNativeClient.proxy());
} }
@Test @Test
@ -53,7 +53,7 @@ public class OkHttpRestfulClientFactoryTest extends BaseFhirVersionParameterized
clientFactory.setHttpClient(okHttpClient); clientFactory.setHttpClient(okHttpClient);
assertSame(okHttpClient, clientFactory.getNativeClient()); assertThat(clientFactory.getNativeClient()).isSameAs(okHttpClient);
} }
@Test @Test
@ -129,7 +129,7 @@ public class OkHttpRestfulClientFactoryTest extends BaseFhirVersionParameterized
context.newRestfulGenericClient(secureBase).search().forResource("Patient").execute(); context.newRestfulGenericClient(secureBase).search().forResource("Patient").execute();
fail(); fail();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage().contains("HAPI-1357: Failed to retrieve the server metadata statement during client initialization")); assertThat(e.getMessage()).contains("HAPI-1357: Failed to retrieve the server metadata statement during client initialization");
assertEquals(SSLHandshakeException.class, e.getCause().getCause().getClass()); assertEquals(SSLHandshakeException.class, e.getCause().getCause().getClass());
} }
} }

View File

@ -2,8 +2,7 @@ package ca.uhn.fhir.okhttp.client;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
public class OkHttpRestfulClientTest { public class OkHttpRestfulClientTest {
@ -11,14 +10,14 @@ public class OkHttpRestfulClientTest {
public void testNewHeaderBuilder_urlHasTrailingSlash_shouldTrim() { public void testNewHeaderBuilder_urlHasTrailingSlash_shouldTrim() {
StringBuilder headerBuilder = OkHttpRestfulClient.newHeaderBuilder(new StringBuilder("http://localhost/")); StringBuilder headerBuilder = OkHttpRestfulClient.newHeaderBuilder(new StringBuilder("http://localhost/"));
assertThat(headerBuilder.toString(), equalTo("http://localhost")); assertEquals("http://localhost", headerBuilder.toString());
} }
@Test @Test
public void testNewHeaderBuilder_urlHasNoTrailingSlash_shouldNotTrimLastCharacter() { public void testNewHeaderBuilder_urlHasNoTrailingSlash_shouldNotTrimLastCharacter() {
StringBuilder headerBuilder = OkHttpRestfulClient.newHeaderBuilder(new StringBuilder("http://example.com")); StringBuilder headerBuilder = OkHttpRestfulClient.newHeaderBuilder(new StringBuilder("http://example.com"));
assertThat(headerBuilder.toString(), equalTo("http://example.com")); assertEquals("http://example.com", headerBuilder.toString());
} }
} }

View File

@ -1,7 +1,5 @@
package ca.uhn.fhir.rest.client.apache; package ca.uhn.fhir.rest.client.apache;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -9,6 +7,8 @@ import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ApacheHttpRequestTest { public class ApacheHttpRequestTest {
private final String ENTITY_CONTENT = "Some entity with special characters: é"; private final String ENTITY_CONTENT = "Some entity with special characters: é";

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.rest.client.interceptor;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class SimpleRequestHeaderInterceptorTest { public class SimpleRequestHeaderInterceptorTest {
@Test @Test
@ -16,7 +17,7 @@ public class SimpleRequestHeaderInterceptorTest {
public void testParseComnpleteHeaderNameOnly(){ public void testParseComnpleteHeaderNameOnly(){
SimpleRequestHeaderInterceptor i = new SimpleRequestHeaderInterceptor("Authorization"); SimpleRequestHeaderInterceptor i = new SimpleRequestHeaderInterceptor("Authorization");
assertEquals("Authorization", i.getHeaderName()); assertEquals("Authorization", i.getHeaderName());
assertEquals(null, i.getHeaderValue()); assertNull(i.getHeaderValue());
} }
} }

View File

@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class StoreInfoTest { public class StoreInfoTest {
@Test @Test
@ -31,9 +32,8 @@ public class StoreInfoTest {
public void testPathTypeInvalid(){ public void testPathTypeInvalid(){
try { try {
new KeyStoreInfo("invalid:///my-file.p12", "storePassword" , "keyPassword", "alias"); new KeyStoreInfo("invalid:///my-file.p12", "storePassword" , "keyPassword", "alias");
fail(); fail(); } catch (Exception e) {
} catch (Exception e) { assertEquals(Msg.code(2117) + "Invalid path prefix", e.getMessage());
assertEquals(Msg.code(2117)+"Invalid path prefix", e.getMessage());
} }
} }
@ -53,9 +53,8 @@ public class StoreInfoTest {
public void testFileTypeInvalid(){ public void testFileTypeInvalid(){
try { try {
new KeyStoreInfo("file:///my-file.invalid", "storePassword" , "keyPassword", "alias"); new KeyStoreInfo("file:///my-file.invalid", "storePassword" , "keyPassword", "alias");
fail(); fail(); } catch (Exception e) {
} catch (Exception e) { assertEquals(Msg.code(2121) + "Invalid KeyStore Type", e.getMessage());
assertEquals(Msg.code(2121)+"Invalid KeyStore Type", e.getMessage());
} }
} }

View File

@ -16,11 +16,12 @@ import java.security.KeyStore;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.util.Optional; import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class TlsAuthenticationSvcTest { public class TlsAuthenticationSvcTest {
private KeyStoreInfo myServerKeyStoreInfo; private KeyStoreInfo myServerKeyStoreInfo;
@ -47,8 +48,7 @@ public class TlsAuthenticationSvcTest {
TlsAuthentication emptyAuthentication = null; TlsAuthentication emptyAuthentication = null;
try { try {
TlsAuthenticationSvc.createSslContext(emptyAuthentication); TlsAuthenticationSvc.createSslContext(emptyAuthentication);
fail(); fail(); } catch (Exception e) {
} catch (Exception e) {
assertEquals("theTlsAuthentication cannot be null", e.getMessage()); assertEquals("theTlsAuthentication cannot be null", e.getMessage());
} }
} }
@ -65,9 +65,8 @@ public class TlsAuthenticationSvcTest {
TlsAuthentication invalidTlsAuthentication = new TlsAuthentication(Optional.of(invalidKeyStoreInfo), Optional.of(myServerTrustStoreInfo)); TlsAuthentication invalidTlsAuthentication = new TlsAuthentication(Optional.of(invalidKeyStoreInfo), Optional.of(myServerTrustStoreInfo));
try { try {
TlsAuthenticationSvc.createSslContext(invalidTlsAuthentication); TlsAuthenticationSvc.createSslContext(invalidTlsAuthentication);
fail(); fail(); } catch (Exception e) {
} catch (Exception e) { assertEquals(Msg.code(2102) + "Failed to create SSLContext", e.getMessage());
assertEquals(Msg.code(2102)+"Failed to create SSLContext", e.getMessage());
} }
} }
@ -89,10 +88,9 @@ public class TlsAuthenticationSvcTest {
KeyStoreInfo keyStoreInfo = new KeyStoreInfo("classpath:/non-existent.p12", "changeit", "changeit", "server"); KeyStoreInfo keyStoreInfo = new KeyStoreInfo("classpath:/non-existent.p12", "changeit", "changeit", "server");
try { try {
TlsAuthenticationSvc.createKeyStore(keyStoreInfo); TlsAuthenticationSvc.createKeyStore(keyStoreInfo);
fail(); fail(); }
}
catch (Exception e) { catch (Exception e) {
assertEquals(Msg.code(2103)+"Failed to create KeyStore", e.getMessage()); assertEquals(Msg.code(2103) + "Failed to create KeyStore", e.getMessage());
} }
} }
@ -114,9 +112,8 @@ public class TlsAuthenticationSvcTest {
TrustStoreInfo trustStoreInfo = new TrustStoreInfo("classpath:/non-existent.p12", "changeit", "server"); TrustStoreInfo trustStoreInfo = new TrustStoreInfo("classpath:/non-existent.p12", "changeit", "server");
try { try {
TlsAuthenticationSvc.createKeyStore(trustStoreInfo); TlsAuthenticationSvc.createKeyStore(trustStoreInfo);
fail(); fail(); } catch (Exception e) {
} catch (Exception e) { assertEquals(Msg.code(2103) + "Failed to create KeyStore", e.getMessage());
assertEquals(Msg.code(2103)+"Failed to create KeyStore", e.getMessage());
} }
} }
@ -134,7 +131,7 @@ public class TlsAuthenticationSvcTest {
public void testCreateTrustManagerNoTrustStore() { public void testCreateTrustManagerNoTrustStore() {
// trust manager should contain common certifications if no trust store information is used // trust manager should contain common certifications if no trust store information is used
X509TrustManager trustManager = TlsAuthenticationSvc.createTrustManager(Optional.empty()); X509TrustManager trustManager = TlsAuthenticationSvc.createTrustManager(Optional.empty());
assertNotEquals(0, trustManager.getAcceptedIssuers().length); assertThat(trustManager.getAcceptedIssuers().length).isNotEqualTo(0);
} }
@Test @Test
@ -142,9 +139,8 @@ public class TlsAuthenticationSvcTest {
TrustStoreInfo invalidKeyStoreInfo = new TrustStoreInfo("file:///INVALID.p12", "changeit", "client"); TrustStoreInfo invalidKeyStoreInfo = new TrustStoreInfo("file:///INVALID.p12", "changeit", "client");
try { try {
TlsAuthenticationSvc.createTrustManager(Optional.of(invalidKeyStoreInfo)); TlsAuthenticationSvc.createTrustManager(Optional.of(invalidKeyStoreInfo));
fail(); fail(); } catch (Exception e) {
} catch (Exception e) { assertEquals(Msg.code(2105) + "Failed to create X509TrustManager", e.getMessage());
assertEquals(Msg.code(2105)+"Failed to create X509TrustManager", e.getMessage());
} }
} }

View File

@ -18,9 +18,7 @@ import org.junit.jupiter.api.Test;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static ca.uhn.fhir.util.ExtensionUtil.getExtensionPrimitiveValues; import static ca.uhn.fhir.util.ExtensionUtil.getExtensionPrimitiveValues;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -41,10 +39,10 @@ class VersionCanonicalizerTest {
org.hl7.fhir.r5.model.SearchParameter actual = ourCanonicalizer.searchParameterToCanonical(input); org.hl7.fhir.r5.model.SearchParameter actual = ourCanonicalizer.searchParameterToCanonical(input);
// Verify // Verify
assertThat(actual.getBase().stream().map(Enumeration::getCode).collect(Collectors.toList()), contains("Patient", "Observation")); assertThat(actual.getBase().stream().map(Enumeration::getCode).collect(Collectors.toList())).containsExactly("Patient", "Observation");
assertThat(actual.getTarget().stream().map(Enumeration::getCode).collect(Collectors.toList()), contains("Organization")); assertThat(actual.getTarget().stream().map(Enumeration::getCode).collect(Collectors.toList())).containsExactly("Organization");
assertThat(getExtensionPrimitiveValues(actual, HapiExtensions.EXTENSION_SEARCHPARAM_CUSTOM_BASE_RESOURCE), empty()); assertThat(getExtensionPrimitiveValues(actual, HapiExtensions.EXTENSION_SEARCHPARAM_CUSTOM_BASE_RESOURCE)).isEmpty();
assertThat(getExtensionPrimitiveValues(actual, HapiExtensions.EXTENSION_SEARCHPARAM_CUSTOM_TARGET_RESOURCE), empty()); assertThat(getExtensionPrimitiveValues(actual, HapiExtensions.EXTENSION_SEARCHPARAM_CUSTOM_TARGET_RESOURCE)).isEmpty();
} }
@ -61,13 +59,13 @@ class VersionCanonicalizerTest {
org.hl7.fhir.r5.model.SearchParameter actual = ourCanonicalizer.searchParameterToCanonical(input); org.hl7.fhir.r5.model.SearchParameter actual = ourCanonicalizer.searchParameterToCanonical(input);
// Verify // Verify
assertThat(actual.getBase().stream().map(Enumeration::getCode).collect(Collectors.toList()), empty()); assertThat(actual.getBase().stream().map(Enumeration::getCode).collect(Collectors.toList())).isEmpty();
assertThat(actual.getTarget().stream().map(Enumeration::getCode).collect(Collectors.toList()), empty()); assertThat(actual.getTarget().stream().map(Enumeration::getCode).collect(Collectors.toList())).isEmpty();
assertThat(getExtensionPrimitiveValues(actual, HapiExtensions.EXTENSION_SEARCHPARAM_CUSTOM_BASE_RESOURCE), contains("Base1", "Base2")); assertThat(getExtensionPrimitiveValues(actual, HapiExtensions.EXTENSION_SEARCHPARAM_CUSTOM_BASE_RESOURCE)).containsExactly("Base1", "Base2");
assertThat(getExtensionPrimitiveValues(actual, HapiExtensions.EXTENSION_SEARCHPARAM_CUSTOM_TARGET_RESOURCE), contains("Target1", "Target2")); assertThat(getExtensionPrimitiveValues(actual, HapiExtensions.EXTENSION_SEARCHPARAM_CUSTOM_TARGET_RESOURCE)).containsExactly("Target1", "Target2");
// Original shouldn't be modified // Original shouldn't be modified
assertThat(input.getBase().stream().map(CodeType::getCode).toList(), contains("Base1", "Base2")); assertThat(input.getBase().stream().map(CodeType::getCode).toList()).containsExactly("Base1", "Base2");
assertThat(input.getTarget().stream().map(CodeType::getCode).toList(), contains("Target1", "Target2")); assertThat(input.getTarget().stream().map(CodeType::getCode).toList()).containsExactly("Target1", "Target2");
} }
} }

View File

@ -4,36 +4,25 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.test.utilities.HttpClientExtension; import ca.uhn.fhir.test.utilities.HttpClientExtension;
import ca.uhn.fhir.test.utilities.JettyUtil;
import ca.uhn.fhir.test.utilities.server.RestfulServerExtension; import ca.uhn.fhir.test.utilities.server.RestfulServerExtension;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import ca.uhn.fhir.util.UrlUtil; import ca.uhn.fhir.util.UrlUtil;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.ee10.servlet.ServletHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.hl7.fhir.dstu3.model.HumanName; import org.hl7.fhir.dstu3.model.HumanName;
import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
public class VersionedApiConverterInterceptorR4Test { public class VersionedApiConverterInterceptorR4Test {
@ -56,7 +45,7 @@ public class VersionedApiConverterInterceptorR4Test {
try (CloseableHttpResponse status = ourClient.execute(httpGet)) { try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
ourLog.info(responseContent); ourLog.info(responseContent);
assertThat(responseContent, containsString("\"family\": \"FAMILY\"")); assertThat(responseContent).contains("\"family\": \"FAMILY\"");
} }
} }
@ -67,7 +56,7 @@ public class VersionedApiConverterInterceptorR4Test {
try (CloseableHttpResponse status = ourClient.execute(httpGet)) { try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
ourLog.info(responseContent); ourLog.info(responseContent);
assertThat(responseContent, containsString("\"family\": [")); assertThat(responseContent).contains("\"family\": [");
} }
} }
@ -77,7 +66,7 @@ public class VersionedApiConverterInterceptorR4Test {
try (CloseableHttpResponse status = ourClient.execute(httpGet)) { try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
ourLog.info(responseContent); ourLog.info(responseContent);
assertThat(responseContent, containsString("\"family\": [")); assertThat(responseContent).contains("\"family\": [");
} }
} }

View File

@ -1,16 +1,24 @@
package org.hl7.fhir.converter; package org.hl7.fhir.converter;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.dstu2.model.Resource; import org.hl7.fhir.dstu2.model.Resource;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.Extension;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.SimpleQuantity;
import org.hl7.fhir.dstu3.model.Specimen;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.exceptions.FHIRException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class VersionConvertor_10_30Test { public class VersionConvertor_10_30Test {
@Test @Test
@ -21,7 +29,7 @@ public class VersionConvertor_10_30Test {
org.hl7.fhir.dstu3.model.Observation output = (Observation) VersionConvertorFactory_10_30.convertResource(input); org.hl7.fhir.dstu3.model.Observation output = (Observation) VersionConvertorFactory_10_30.convertResource(input);
String context = output.getContext().getReference(); String context = output.getContext().getReference();
assertEquals("Encounter/123", context); assertEquals("Encounter/123", context);
} }

View File

@ -1,12 +1,12 @@
package org.hl7.fhir.converter; package org.hl7.fhir.converter;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_30; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_30;
import org.hl7.fhir.dstu3.model.Questionnaire; import org.hl7.fhir.dstu3.model.Questionnaire;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class VersionConvertor_14_30Test { public class VersionConvertor_14_30Test {
@Test @Test
@ -17,7 +17,7 @@ public class VersionConvertor_14_30Test {
org.hl7.fhir.dstu3.model.Questionnaire output = (Questionnaire) VersionConvertorFactory_14_30.convertResource(input); org.hl7.fhir.dstu3.model.Questionnaire output = (Questionnaire) VersionConvertorFactory_14_30.convertResource(input);
String context = output.getTitle(); String context = output.getTitle();
assertEquals("My title", context); assertEquals("My title", context);
} }

View File

@ -17,6 +17,7 @@
* limitations under the License. * limitations under the License.
* #L% * #L%
*/ */
import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.i18n.Msg;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="614px" height="153px" version="1.1"><defs/><g transform="translate(0.5,0.5)"><path d="M 17 1 L 121 1 L 121 61 L 17 61 L 17 49 L 1 49 L 1 37 L 17 37 L 17 25 L 1 25 L 1 13 L 17 13 Z" fill="#ffffff" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 17 13 L 33 13 L 33 25 L 17 25 M 17 37 L 33 37 L 33 49 L 17 49" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><g fill="#000000" font-family="Helvetica" font-size="12px"><text x="39" y="35">hapi-fhir</text></g><rect x="321" y="1" width="110" height="60" rx="9" ry="9" fill="#ffffff" stroke="#000000" pointer-events="none"/><g transform="translate(323,24)"><switch><foreignObject pointer-events="all" width="106" height="15" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.26; vertical-align: top; width: 106px; white-space: normal; text-align: center;">slf4j-api</div></foreignObject><text x="53" y="14" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><path d="M 121 31 L 315 31" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 320 31 L 313 35 L 315 31 L 313 28 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 67 91 L 171 91 L 171 151 L 67 151 L 67 139 L 51 139 L 51 127 L 67 127 L 67 115 L 51 115 L 51 103 L 67 103 Z" fill="#ffffff" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 67 103 L 83 103 L 83 115 L 67 115 M 67 127 L 83 127 L 83 139 L 67 139" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><g fill="#000000" font-family="Helvetica" font-size="12px"><text x="89" y="118">commons-</text><text x="89" y="132">httpclient</text></g><rect x="221" y="91" width="110" height="60" rx="9" ry="9" fill="#ffffff" stroke="#000000" pointer-events="none"/><g transform="translate(223,114)"><switch><foreignObject pointer-events="all" width="106" height="15" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.26; vertical-align: top; width: 106px; white-space: normal; text-align: center;">jcl-over-slf4j</div></foreignObject><text x="53" y="14" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><path d="M 91 61 L 107 86" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 110 90 L 104 86 L 107 86 L 109 82 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 171 121 L 215 121" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 220 121 L 213 125 L 215 121 L 213 118 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 309 91 L 338 65" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 342 62 L 339 69 L 338 65 L 334 64 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 441 36 L 441 26 L 461 26 L 461 16 L 491 31 L 461 46 L 461 36 Z" fill="#ffffff" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><rect x="501" y="11" width="80" height="40" fill="none" stroke="none" pointer-events="none"/><g fill="#000000" font-family="Helvetica" font-size="12px"><text x="503" y="14">Underlying </text><text x="503" y="28">Logging</text><text x="503" y="42">Framework</text><text x="503" y="56">(logback, log4j, etc.)</text></g></g></svg> <svg xmlns="http://www.w3.org/2000/svg" width="614px" height="153px" version="1.1"><defs/><g transform="translate(0.5,0.5)"><path d="M 17 1 L 121 1 L 121 61 L 17 61 L 17 49 L 1 49 L 1 37 L 17 37 L 17 25 L 1 25 L 1 13 L 17 13 Z" fill="#ffffff" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 17 13 L 33 13 L 33 25 L 17 25 M 17 37 L 33 37 L 33 49 L 17 49" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><g fill="#000000" font-family="Helvetica" font-size="12px"><text x="39" y="35">hapi-fhir</text></g><rect x="321" y="1" width="110" height="60" rx="9" ry="9" fill="#ffffff" stroke="#000000" pointer-events="none"/><g transform="translate(323,24)"><switch><foreignObject pointer-events="all" width="106" height="15" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.26; vertical-align: top; width: 106px; white-space: normal; text-align: center;">slf4j-api</div></foreignObject><text x="53" y="14" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><path d="M 121 31 L 315 31" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 320 31 L 313 35 L 315 31 L 313 28 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 67 91 L 171 91 L 171 151 L 67 151 L 67 139 L 51 139 L 51 127 L 67 127 L 67 115 L 51 115 L 51 103 L 67 103 Z" fill="#ffffff" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 67 103 L 83 103 L 83 115 L 67 115 M 67 127 L 83 127 L 83 139 L 67 139" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><g fill="#000000" font-family="Helvetica" font-size="12px"><text x="89" y="118">commons-</text><text x="89" y="132">httpclient</text></g><rect x="221" y="91" width="110" height="60" rx="9" ry="9" fill="#ffffff" stroke="#000000" pointer-events="none"/><g transform="translate(223,114)"><switch><foreignObject pointer-events="all" width="106" height="15" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.26; vertical-align: top; width: 106px; white-space: normal; text-align: center;">jcl-over-slf4j</div></foreignObject><text x="53" y="14" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><path d="M 91 61 L 107 86" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 110 90 L 104 86 L 107 86 L 109 82 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 171 121 L 215 121" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 220 121 L 213 125 L 215 121 L 213 118 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 309 91 L 338 65" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 342 62 L 339 69 L 338 65 L 334 64 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 441 36 L 441 26 L 461 26 L 461 16 L 491 31 L 461 46 L 461 36 Z" fill="#ffffff" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><rect x="501" y="11" width="80" height="40" fill="none" stroke="none" pointer-events="none"/><g fill="#000000" font-family="Helvetica" font-size="12px"><text x="503" y="14">Underlying </text><text x="503" y="28">Logging</text><text x="503" y="42">Framework</text><text x="503" y="56">(logback, log4j, etc.)</text></g></g></svg>

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" <svg xmlns="http://www.w3.org/2000/svg"
width="672px" height="468px" version="1.1"> width="672px" height="468px" version="1.1">
<defs> <defs>
<linearGradient x1="0%" y1="0%" x2="0%" y2="100%" <linearGradient x1="0%" y1="0%" x2="0%" y2="100%"
id="mx-gradient-fff2cc-1-ffd966-1-s-0"> id="mx-gradient-fff2cc-1-ffd966-1-s-0">

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -17,9 +17,7 @@ import java.io.InputStreamReader;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class ChangelogFilesTest { public class ChangelogFilesTest {
@ -58,10 +56,10 @@ public class ChangelogFilesTest {
List<String> fieldNames = IteratorUtils.toList(tree.fieldNames()); List<String> fieldNames = IteratorUtils.toList(tree.fieldNames());
boolean title = fieldNames.remove("title"); boolean title = fieldNames.remove("title");
assertTrue(title, "No 'title' element in " + next); assertThat(title).as("No 'title' element in " + next).isTrue();
boolean type = fieldNames.remove("type"); boolean type = fieldNames.remove("type");
assertTrue(type, "No 'type' element in " + next); assertThat(type).as("No 'type' element in " + next).isTrue();
// this one is optional // this one is optional
boolean haveIssue = fieldNames.remove("issue"); boolean haveIssue = fieldNames.remove("issue");
@ -72,7 +70,7 @@ public class ChangelogFilesTest {
// this one is optional // this one is optional
fieldNames.remove("jira"); fieldNames.remove("jira");
assertThat("Invalid element in " + next + ": " + fieldNames, fieldNames, empty()); assertThat(fieldNames).as("Invalid element in " + next + ": " + fieldNames).isEmpty();
if (haveIssue) { if (haveIssue) {
String issue = tree.get("issue").asText(); String issue = tree.get("issue").asText();

View File

@ -25,7 +25,11 @@ import ca.uhn.fhir.util.StopWatch;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import java.io.*; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;

View File

@ -25,8 +25,11 @@ import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsExceptionInterceptor; import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsExceptionInterceptor;
import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsResponseException; import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsResponseException;
import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest; import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.PreferReturnEnum;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.server.IRestfulServer; import ca.uhn.fhir.rest.api.server.IRestfulServer;
import ca.uhn.fhir.rest.api.*;
import ca.uhn.fhir.rest.server.IPagingProvider; import ca.uhn.fhir.rest.server.IPagingProvider;
import ca.uhn.fhir.rest.server.PageProvider; import ca.uhn.fhir.rest.server.PageProvider;
import ca.uhn.fhir.rest.server.method.PageMethodBinding; import ca.uhn.fhir.rest.server.method.PageMethodBinding;

View File

@ -26,9 +26,16 @@ import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsExceptionInterceptor;
import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsResponseException; import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsResponseException;
import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest; import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest;
import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest.Builder; import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest.Builder;
import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.server.ETagSupportEnum;
import ca.uhn.fhir.rest.server.ElementsSupportEnum;
import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
import ca.uhn.fhir.rest.server.IPagingProvider;
import ca.uhn.fhir.rest.server.IRestfulServerDefaults;
import ca.uhn.fhir.rest.server.IServerAddressStrategy;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
import ca.uhn.fhir.rest.server.*;
import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.core.MultivaluedMap;
@ -37,8 +44,11 @@ import jakarta.ws.rs.core.UriInfo;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.*;
/** /**
* This is the abstract superclass for all jaxrs providers. It contains some defaults implementing * This is the abstract superclass for all jaxrs providers. It contains some defaults implementing

View File

@ -25,8 +25,11 @@ import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsExceptionInterceptor;
import ca.uhn.fhir.jaxrs.server.util.JaxRsMethodBindings; import ca.uhn.fhir.jaxrs.server.util.JaxRsMethodBindings;
import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest; import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest;
import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest.Builder; import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest.Builder;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.PreferReturnEnum;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.server.IRestfulServer; import ca.uhn.fhir.rest.api.server.IRestfulServer;
import ca.uhn.fhir.rest.api.*;
import ca.uhn.fhir.rest.server.IPagingProvider; import ca.uhn.fhir.rest.server.IPagingProvider;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.method.BaseMethodBinding; import ca.uhn.fhir.rest.server.method.BaseMethodBinding;

View File

@ -41,22 +41,16 @@ import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class GenericJaxRsClientDstu2Test { public class GenericJaxRsClientDstu2Test {
@ -117,20 +111,20 @@ public class GenericJaxRsClientDstu2Test {
client.fetchConformance().ofType(Conformance.class).execute(); client.fetchConformance().ofType(Conformance.class).execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", CAPTURE_SERVLET.ourRequestUri);
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get("Accept").size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get("Accept")).hasSize(1);
assertThat(CAPTURE_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY)); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue()).contains(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY);
client.fetchConformance().ofType(Conformance.class).encodedJson().execute(); client.fetchConformance().ofType(Conformance.class).encodedJson().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", CAPTURE_SERVLET.ourRequestUri);
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get("Accept").size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get("Accept")).hasSize(1);
assertThat(CAPTURE_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
client.fetchConformance().ofType(Conformance.class).encodedXml().execute(); client.fetchConformance().ofType(Conformance.class).encodedXml().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=xml", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=xml", CAPTURE_SERVLET.ourRequestUri);
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get("Accept").size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get("Accept")).hasSize(1);
assertThat(CAPTURE_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_XML);
} }
@ -153,15 +147,15 @@ public class GenericJaxRsClientDstu2Test {
Patient resp = client.read(Patient.class, new IdDt("123")); Patient resp = client.read(Patient.class, new IdDt("123"));
assertEquals("FAMILY", resp.getName().get(0).getFamily().get(0).getValue()); assertEquals("FAMILY", resp.getName().get(0).getFamily().get(0).getValue());
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", CAPTURE_SERVLET.ourRequestUriAll.get(0)); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", CAPTURE_SERVLET.ourRequestUriAll.get(0));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").size()); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept")).hasSize(1);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY)); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_XML);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123", CAPTURE_SERVLET.ourRequestUriAll.get(1)); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123", CAPTURE_SERVLET.ourRequestUriAll.get(1));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").size()); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept")).hasSize(1);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY)); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_XML);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
} }
@Test @Test
@ -184,13 +178,13 @@ public class GenericJaxRsClientDstu2Test {
Patient resp = client.read(Patient.class, new IdDt("123")); Patient resp = client.read(Patient.class, new IdDt("123"));
assertEquals("FAMILY", resp.getName().get(0).getFamily().get(0).getValue()); assertEquals("FAMILY", resp.getName().get(0).getFamily().get(0).getValue());
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", CAPTURE_SERVLET.ourRequestUriAll.get(0)); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", CAPTURE_SERVLET.ourRequestUriAll.get(0));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").size()); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept")).hasSize(1);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), not(containsString(Constants.CT_FHIR_XML))); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).doesNotContain(Constants.CT_FHIR_XML);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=json", CAPTURE_SERVLET.ourRequestUriAll.get(1)); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=json", CAPTURE_SERVLET.ourRequestUriAll.get(1));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").size()); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept")).hasSize(1);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), not(containsString(Constants.CT_FHIR_XML))); assertThat(CAPTURE_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).doesNotContain(Constants.CT_FHIR_XML);
} }
@Test @Test
@ -242,9 +236,9 @@ public class GenericJaxRsClientDstu2Test {
client.create().resource(p).encodedXml().execute(); client.create().resource(p).encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
@ -252,11 +246,11 @@ public class GenericJaxRsClientDstu2Test {
p.setId("123"); p.setId("123");
client.create().resource(p).encodedXml().execute(); client.create().resource(p).encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
String body = CAPTURE_SERVLET.ourRequestBodyString; String body = CAPTURE_SERVLET.ourRequestBodyString;
assertThat(body, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(body).contains("<family value=\"FOOFAMILY\"/>");
assertThat(body, not(containsString("123"))); assertThat(body).doesNotContain("123");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
@ -276,27 +270,27 @@ public class GenericJaxRsClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.create().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute(); client.create().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue());
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
client.create().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); client.create().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue());
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
client.create().resource(p).conditional().where(Patient.NAME.matches().value("foo")).encodedXml().execute(); client.create().resource(p).conditional().where(Patient.NAME.matches().value("foo")).encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", CAPTURE_SERVLET.ourRequestUri);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue());
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
@ -317,12 +311,12 @@ public class GenericJaxRsClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.create().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); client.create().resource(p).prefer(PreferReturnEnum.MINIMAL).execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
client.create().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); client.create().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
@ -408,7 +402,7 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/_history", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/_history", CAPTURE_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
@ -420,7 +414,7 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/_history", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/_history", CAPTURE_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
@ -431,7 +425,7 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/_history", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/_history", CAPTURE_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
@ -441,7 +435,7 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/_history", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/_history", CAPTURE_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
@ -451,7 +445,7 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/_history", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/_history", CAPTURE_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
response = client response = client
@ -462,8 +456,10 @@ public class GenericJaxRsClientDstu2Test {
.since(new InstantDt("2001-01-02T11:22:33Z")) .since(new InstantDt("2001-01-02T11:22:33Z"))
.execute(); .execute();
assertThat(CAPTURE_SERVLET.ourRequestUri, either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z"))); assertThat(CAPTURE_SERVLET.ourRequestUri).isIn(
assertEquals(1, response.getEntry().size()); ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123",
ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z");
assertThat(response.getEntry()).hasSize(1);
response = client response = client
@ -473,8 +469,8 @@ public class GenericJaxRsClientDstu2Test {
.since(new InstantDt("2001-01-02T11:22:33Z").getValue()) .since(new InstantDt("2001-01-02T11:22:33Z").getValue())
.execute(); .execute();
assertThat(CAPTURE_SERVLET.ourRequestUri, containsString("_since=2001-01")); assertThat(CAPTURE_SERVLET.ourRequestUri).contains("_since=2001-01");
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
} }
@ -758,11 +754,11 @@ public class GenericJaxRsClientDstu2Test {
.withParameters(inParams).encodedXml().execute(); .withParameters(inParams).encodedXml().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString); assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
assertEquals(1, resp.getParameter().size()); assertThat(resp.getParameter()).hasSize(1);
assertEquals(ca.uhn.fhir.model.dstu2.resource.Bundle.class, resp.getParameter().get(0).getResource().getClass()); assertEquals(ca.uhn.fhir.model.dstu2.resource.Bundle.class, resp.getParameter().get(0).getResource().getClass());
} }
@ -793,7 +789,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueString value=\"value1\"/></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", (CAPTURE_SERVLET.ourRequestBodyString)); assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueString value=\"value1\"/></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", (CAPTURE_SERVLET.ourRequestBodyString));
@ -815,11 +811,10 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", (CAPTURE_SERVLET.ourRequestBodyString));
(CAPTURE_SERVLET.ourRequestBodyString));
/* /*
@ -838,12 +833,10 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
assertEquals( assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><active value=\"true\"/></Patient></resource></parameter></Parameters>", (CAPTURE_SERVLET.ourRequestBodyString));
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><active value=\"true\"/></Patient></resource></parameter></Parameters>",
(CAPTURE_SERVLET.ourRequestBodyString));
} }
@ -887,7 +880,7 @@ public class GenericJaxRsClientDstu2Test {
} }
}; };
assertThrows(IllegalArgumentException.class, () -> { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
client client
.operation() .operation()
.onServer() .onServer()
@ -973,7 +966,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString); assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
@ -987,7 +980,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString); assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
@ -1003,7 +996,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString); assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
@ -1042,7 +1035,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString); assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
@ -1056,7 +1049,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString); assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
@ -1070,7 +1063,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", CAPTURE_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString); assertEquals(CAPTURE_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
@ -1108,7 +1101,7 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertEquals(1, resp.getEntry().size()); assertThat(resp.getEntry()).hasSize(1);
assertEquals(ourServer.getBaseUrl() + "/fhir/next", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/next", CAPTURE_SERVLET.ourRequestUri);
@ -1122,7 +1115,7 @@ public class GenericJaxRsClientDstu2Test {
try { try {
client.loadPage().next(sourceBundle).execute(); client.loadPage().next(sourceBundle).execute();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Can not perform paging operation because no link was found in Bundle with relation \"next\"")); assertThat(e.getMessage()).contains("Can not perform paging operation because no link was found in Bundle with relation \"next\"");
} }
} }
@ -1146,7 +1139,7 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertEquals(1, resp.getEntry().size()); assertThat(resp.getEntry()).hasSize(1);
assertEquals(ourServer.getBaseUrl() + "/fhir/prev", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/prev", CAPTURE_SERVLET.ourRequestUri);
@ -1164,7 +1157,7 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertEquals(1, resp.getEntry().size()); assertThat(resp.getEntry()).hasSize(1);
assertEquals(ourServer.getBaseUrl() + "/fhir/prev", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/prev", CAPTURE_SERVLET.ourRequestUri);
@ -1260,7 +1253,8 @@ public class GenericJaxRsClientDstu2Test {
.elementsSubset("name", "identifier") .elementsSubset("name", "identifier")
.execute(); .execute();
assertThat(CAPTURE_SERVLET.ourRequestUri, either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=identifier%2Cname"))); assertThat(CAPTURE_SERVLET.ourRequestUri).isIn(ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=name%2Cidentifier",
ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=identifier%2Cname");
assertEquals(Patient.class, response.getClass()); assertEquals(Patient.class, response.getClass());
} }
@ -1285,7 +1279,7 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
fail(); fail();
} catch (InvalidResponseException e) { } catch (InvalidResponseException e) {
assertThat(e.getMessage(), containsString("String does not appear to be valid")); assertThat(e.getMessage()).contains("String does not appear to be valid");
} }
} }
@ -1453,7 +1447,8 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertThat(CAPTURE_SERVLET.ourRequestUri, either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname"))); assertThat(CAPTURE_SERVLET.ourRequestUri).isIn(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier",
ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname");
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
} }
@ -1490,7 +1485,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals("application/x-www-form-urlencoded", CAPTURE_SERVLET.ourRequestContentType.replace(";char", "; char").toLowerCase()); assertEquals("application/x-www-form-urlencoded", CAPTURE_SERVLET.ourRequestContentType.replace(";char", "; char").toLowerCase());
assertEquals(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY, CAPTURE_SERVLET.ourRequestFirstHeaders.get("Accept").getValue()); assertEquals(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY, CAPTURE_SERVLET.ourRequestFirstHeaders.get("Accept").getValue());
assertThat(CAPTURE_SERVLET.ourRequestFirstHeaders.get("User-Agent").getValue(), not(emptyString())); assertThat(CAPTURE_SERVLET.ourRequestFirstHeaders.get("User-Agent").getValue()).isNotEmpty();
} }
@Test @Test
@ -1515,8 +1510,8 @@ public class GenericJaxRsClientDstu2Test {
.execute(); .execute();
assertThat(CAPTURE_SERVLET.ourRequestUri, containsString(ourServer.getBaseUrl() + "/fhir/Patient/_search?")); assertThat(CAPTURE_SERVLET.ourRequestUri).contains(ourServer.getBaseUrl() + "/fhir/Patient/_search?");
assertThat(CAPTURE_SERVLET.ourRequestUri, containsString("_elements=identifier%2Cname")); assertThat(CAPTURE_SERVLET.ourRequestUri).contains("_elements=identifier%2Cname");
// assertThat(MY_SERVLET.ourRequestUri, // assertThat(MY_SERVLET.ourRequestUri,
// either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname"))); // either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname")));
@ -1665,11 +1660,11 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir", CAPTURE_SERVLET.ourRequestUri);
assertEquals(2, response.size()); assertThat(response).hasSize(2);
String requestString = CAPTURE_SERVLET.ourRequestBodyString; String requestString = CAPTURE_SERVLET.ourRequestBodyString;
ca.uhn.fhir.model.dstu2.resource.Bundle requestBundle = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, requestString); ca.uhn.fhir.model.dstu2.resource.Bundle requestBundle = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, requestString);
assertEquals(2, requestBundle.getEntry().size()); assertThat(requestBundle.getEntry()).hasSize(2);
assertEquals("POST", requestBundle.getEntry().get(0).getRequest().getMethod()); assertEquals("POST", requestBundle.getEntry().get(0).getRequest().getMethod());
assertEquals("PUT", requestBundle.getEntry().get(1).getRequest().getMethod()); assertEquals("PUT", requestBundle.getEntry().get(1).getRequest().getMethod());
assertEquals("http://example.com/Patient/2", requestBundle.getEntry().get(1).getFullUrl()); assertEquals("http://example.com/Patient/2", requestBundle.getEntry().get(1).getFullUrl());
@ -1712,7 +1707,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir/", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/", CAPTURE_SERVLET.ourRequestUri);
assertThat(response, containsString("\"Bundle\"")); assertThat(response).contains("\"Bundle\"");
assertEquals("application/json+fhir;charset=UTF-8", CAPTURE_SERVLET.ourRequestFirstHeaders.get("Content-Type").getValue()); assertEquals("application/json+fhir;charset=UTF-8", CAPTURE_SERVLET.ourRequestFirstHeaders.get("Content-Type").getValue());
@ -1760,7 +1755,7 @@ public class GenericJaxRsClientDstu2Test {
assertEquals(ourServer.getBaseUrl() + "/fhir", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir", CAPTURE_SERVLET.ourRequestUri);
assertEquals(2, response.getEntry().size()); assertThat(response.getEntry()).hasSize(2);
assertEquals("Patient/1/_history/1", response.getEntry().get(0).getResponse().getLocation()); assertEquals("Patient/1/_history/1", response.getEntry().get(0).getResponse().getLocation());
assertEquals("Patient/2/_history/2", response.getEntry().get(1).getResponse().getLocation()); assertEquals("Patient/2/_history/2", response.getEntry().get(1).getResponse().getLocation());
@ -1779,41 +1774,41 @@ public class GenericJaxRsClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.update().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute(); client.update().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod); assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", CAPTURE_SERVLET.ourRequestUri);
client.update().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); client.update().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod); assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", CAPTURE_SERVLET.ourRequestUri);
client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditionalByUrl("Patient?name=foo").encodedXml().execute(); client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditionalByUrl("Patient?name=foo").encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod); assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", CAPTURE_SERVLET.ourRequestUri);
client.update().resource(p).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); client.update().resource(p).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod); assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", CAPTURE_SERVLET.ourRequestUri);
client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod); assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", CAPTURE_SERVLET.ourRequestUri);
@ -1834,17 +1829,17 @@ public class GenericJaxRsClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.update(new IdDt("Patient/123"), p); client.update(new IdDt("Patient/123"), p);
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", CAPTURE_SERVLET.ourRequestUri);
assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod); assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod);
client.update("123", p); client.update("123", p);
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, CAPTURE_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", CAPTURE_SERVLET.ourRequestUri);
assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod); assertEquals("PUT", CAPTURE_SERVLET.ourRequestMethod);
@ -1864,12 +1859,12 @@ public class GenericJaxRsClientDstu2Test {
p.addName().addFamily("FOOFAMILY"); p.addName().addFamily("FOOFAMILY");
client.update().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); client.update().resource(p).prefer(PreferReturnEnum.MINIMAL).execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
client.update().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); client.update().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute();
assertEquals(1, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, CAPTURE_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
@ -1943,7 +1938,7 @@ public class GenericJaxRsClientDstu2Test {
response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute(); response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate?_pretty=true", CAPTURE_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate?_pretty=true", CAPTURE_SERVLET.ourRequestUri);
assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod); assertEquals("POST", CAPTURE_SERVLET.ourRequestMethod);
assertThat(CAPTURE_SERVLET.ourRequestBodyString, containsString("\"resourceType\": \"Parameters\",\n")); assertThat(CAPTURE_SERVLET.ourRequestBodyString).contains("\"resourceType\": \"Parameters\",\n");
assertNotNull(response.getOperationOutcome()); assertNotNull(response.getOperationOutcome());
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());

View File

@ -11,24 +11,15 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.PreferReturnEnum; import ca.uhn.fhir.rest.api.PreferReturnEnum;
import ca.uhn.fhir.rest.api.SearchStyleEnum; import ca.uhn.fhir.rest.api.SearchStyleEnum;
import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.client.api.Header;
import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException; import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException;
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.system.HapiSystemProperties; import ca.uhn.fhir.system.HapiSystemProperties;
import ca.uhn.fhir.test.utilities.JettyUtil;
import ca.uhn.fhir.test.utilities.server.HttpServletExtension; import ca.uhn.fhir.test.utilities.server.HttpServletExtension;
import ca.uhn.fhir.test.utilities.server.RequestCaptureServlet; import ca.uhn.fhir.test.utilities.server.RequestCaptureServlet;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent; import org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent;
@ -52,31 +43,18 @@ import org.hl7.fhir.dstu3.model.UriType;
import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class GenericJaxRsClientDstu3Test { public class GenericJaxRsClientDstu3Test {
@ -137,20 +115,20 @@ public class GenericJaxRsClientDstu3Test {
client.fetchConformance().ofType(CapabilityStatement.class).execute(); client.fetchConformance().ofType(CapabilityStatement.class).execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", MY_SERVLET.ourRequestUri);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY)); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue()).contains(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY);
client.fetchConformance().ofType(CapabilityStatement.class).encodedJson().execute(); client.fetchConformance().ofType(CapabilityStatement.class).encodedJson().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", MY_SERVLET.ourRequestUri);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
client.fetchConformance().ofType(CapabilityStatement.class).encodedXml().execute(); client.fetchConformance().ofType(CapabilityStatement.class).encodedXml().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=xml", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=xml", MY_SERVLET.ourRequestUri);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); assertThat(MY_SERVLET.ourRequestHeaders.get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_XML);
} }
@ -173,15 +151,15 @@ public class GenericJaxRsClientDstu3Test {
Patient resp = client.read(Patient.class, new IdType("123").getValue()); Patient resp = client.read(Patient.class, new IdType("123").getValue());
assertEquals("FAMILY", resp.getName().get(0).getFamily()); assertEquals("FAMILY", resp.getName().get(0).getFamily());
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", MY_SERVLET.ourRequestUriAll.get(0)); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata", MY_SERVLET.ourRequestUriAll.get(0));
assertEquals(1, MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_XML);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123", MY_SERVLET.ourRequestUriAll.get(1)); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123", MY_SERVLET.ourRequestUriAll.get(1));
assertEquals(1, MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_XML);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
} }
@Test @Test
@ -204,13 +182,13 @@ public class GenericJaxRsClientDstu3Test {
Patient resp = client.read(Patient.class, new IdType("123").getValue()); Patient resp = client.read(Patient.class, new IdType("123").getValue());
assertEquals("FAMILY", resp.getName().get(0).getFamily()); assertEquals("FAMILY", resp.getName().get(0).getFamily());
assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", MY_SERVLET.ourRequestUriAll.get(0)); assertEquals(ourServer.getBaseUrl() + "/fhir/metadata?_format=json", MY_SERVLET.ourRequestUriAll.get(0));
assertEquals(1, MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue(), not(containsString(Constants.CT_FHIR_XML))); assertThat(MY_SERVLET.ourRequestHeadersAll.get(0).get("Accept").get(0).getValue()).doesNotContain(Constants.CT_FHIR_XML);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=json", MY_SERVLET.ourRequestUriAll.get(1)); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=json", MY_SERVLET.ourRequestUriAll.get(1));
assertEquals(1, MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").size()); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept")).hasSize(1);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).contains(Constants.CT_FHIR_JSON);
assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue(), not(containsString(Constants.CT_FHIR_XML))); assertThat(MY_SERVLET.ourRequestHeadersAll.get(1).get("Accept").get(0).getValue()).doesNotContain(Constants.CT_FHIR_XML);
} }
@Test @Test
@ -264,9 +242,9 @@ public class GenericJaxRsClientDstu3Test {
client.create().resource(p).encodedXml().execute(); client.create().resource(p).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -274,11 +252,11 @@ public class GenericJaxRsClientDstu3Test {
p.setId("123"); p.setId("123");
client.create().resource(p).encodedXml().execute(); client.create().resource(p).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
String body = MY_SERVLET.ourRequestBodyString; String body = MY_SERVLET.ourRequestBodyString;
assertThat(body, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(body).contains("<family value=\"FOOFAMILY\"/>");
assertThat(body, not(containsString("123"))); assertThat(body).doesNotContain("123");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -298,27 +276,27 @@ public class GenericJaxRsClientDstu3Test {
p.addName().setFamily("FOOFAMILY"); p.addName().setFamily("FOOFAMILY");
client.create().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute(); client.create().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue());
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
client.create().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); client.create().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue());
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
client.create().resource(p).conditional().where(Patient.NAME.matches().value("foo")).encodedXml().execute(); client.create().resource(p).conditional().where(Patient.NAME.matches().value("foo")).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue());
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -338,9 +316,9 @@ public class GenericJaxRsClientDstu3Test {
client.create().resource(p).encodedXml().execute(); client.create().resource(p).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -359,12 +337,12 @@ public class GenericJaxRsClientDstu3Test {
p.addName().setFamily("FOOFAMILY"); p.addName().setFamily("FOOFAMILY");
client.create().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); client.create().resource(p).prefer(PreferReturnEnum.MINIMAL).execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
client.create().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); client.create().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
@ -450,7 +428,7 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
//@formatter:off //@formatter:off
@ -463,7 +441,7 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
//@formatter:off //@formatter:off
@ -475,7 +453,7 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
//@formatter:off //@formatter:off
@ -486,7 +464,7 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
//@formatter:off //@formatter:off
@ -497,7 +475,7 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/_history", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/_history", MY_SERVLET.ourRequestUri);
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
//@formatter:off //@formatter:off
@ -509,8 +487,9 @@ public class GenericJaxRsClientDstu3Test {
.since(new InstantType("2001-01-02T11:22:33Z")) .since(new InstantType("2001-01-02T11:22:33Z"))
.execute(); .execute();
//@formatter:on //@formatter:on
assertThat(MY_SERVLET.ourRequestUri, either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z"))); assertThat(MY_SERVLET.ourRequestUri).isIn(ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123",
assertEquals(1, response.getEntry().size()); ourServer.getBaseUrl() + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z");
assertThat(response.getEntry()).hasSize(1);
//@formatter:off //@formatter:off
@ -521,8 +500,8 @@ public class GenericJaxRsClientDstu3Test {
.since(new InstantType("2001-01-02T11:22:33Z").getValue()) .since(new InstantType("2001-01-02T11:22:33Z").getValue())
.execute(); .execute();
//@formatter:on //@formatter:on
assertThat(MY_SERVLET.ourRequestUri, containsString("_since=2001-01")); assertThat(MY_SERVLET.ourRequestUri).contains("_since=2001-01");
assertEquals(1, response.getEntry().size()); assertThat(response.getEntry()).hasSize(1);
} }
@ -819,11 +798,11 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals(1, resp.getParameter().size()); assertThat(resp.getParameter()).hasSize(1);
assertEquals(org.hl7.fhir.dstu3.model.Bundle.class, resp.getParameter().get(0).getResource().getClass()); assertEquals(org.hl7.fhir.dstu3.model.Bundle.class, resp.getParameter().get(0).getResource().getClass());
} }
@ -855,7 +834,7 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueString value=\"value1\"/></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", (MY_SERVLET.ourRequestBodyString)); assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueString value=\"value1\"/></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", (MY_SERVLET.ourRequestBodyString));
@ -877,11 +856,10 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", (MY_SERVLET.ourRequestBodyString));
(MY_SERVLET.ourRequestBodyString));
/* /*
@ -900,12 +878,10 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertEquals( assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><active value=\"true\"/></Patient></resource></parameter></Parameters>", (MY_SERVLET.ourRequestBodyString));
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><active value=\"true\"/></Patient></resource></parameter></Parameters>",
(MY_SERVLET.ourRequestBodyString));
} }
@ -949,7 +925,7 @@ public class GenericJaxRsClientDstu3Test {
} }
}; };
assertThrows(IllegalArgumentException.class, () -> { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
client client
.operation() .operation()
.onServer() .onServer()
@ -1038,7 +1014,7 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -1055,7 +1031,7 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -1072,7 +1048,7 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -1112,7 +1088,7 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -1127,7 +1103,7 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -1144,7 +1120,7 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123/$SOMEOPERATION", MY_SERVLET.ourRequestUri);
assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(respString, p.encodeResourceToString(resp));
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertEquals(MY_SERVLET.ourRequestBodyString, reqString); assertEquals(MY_SERVLET.ourRequestBodyString, reqString);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
@ -1182,7 +1158,7 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertEquals(1, resp.getEntry().size()); assertThat(resp.getEntry()).hasSize(1);
assertEquals(ourServer.getBaseUrl() + "/fhir/next", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/next", MY_SERVLET.ourRequestUri);
@ -1196,7 +1172,7 @@ public class GenericJaxRsClientDstu3Test {
try { try {
client.loadPage().next(sourceBundle).execute(); client.loadPage().next(sourceBundle).execute();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Can not perform paging operation because no link was found in Bundle with relation \"next\"")); assertThat(e.getMessage()).contains("Can not perform paging operation because no link was found in Bundle with relation \"next\"");
} }
} }
@ -1220,7 +1196,7 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertEquals(1, resp.getEntry().size()); assertThat(resp.getEntry()).hasSize(1);
assertEquals(ourServer.getBaseUrl() + "/fhir/prev", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/prev", MY_SERVLET.ourRequestUri);
@ -1238,7 +1214,7 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertEquals(1, resp.getEntry().size()); assertThat(resp.getEntry()).hasSize(1);
assertEquals(ourServer.getBaseUrl() + "/fhir/prev", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/prev", MY_SERVLET.ourRequestUri);
@ -1339,7 +1315,8 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertThat(MY_SERVLET.ourRequestUri, either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=identifier%2Cname"))); assertThat(MY_SERVLET.ourRequestUri).isIn(ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=name%2Cidentifier",
ourServer.getBaseUrl() + "/fhir/Patient/123?_elements=identifier%2Cname");
assertEquals(Patient.class, response.getClass()); assertEquals(Patient.class, response.getClass());
} }
@ -1364,7 +1341,7 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
fail(); fail();
} catch (InvalidResponseException e) { } catch (InvalidResponseException e) {
assertThat(e.getMessage(), containsString("Unable to Parse HTML")); assertThat(e.getMessage()).contains("Unable to Parse HTML");
} }
//@formatter:on //@formatter:on
} }
@ -1542,7 +1519,8 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertThat(MY_SERVLET.ourRequestUri, either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname"))); assertThat(MY_SERVLET.ourRequestUri).isIn(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier",
ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname");
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
} }
@ -1579,7 +1557,7 @@ public class GenericJaxRsClientDstu3Test {
assertEquals("application/x-www-form-urlencoded", MY_SERVLET.ourRequestContentType.replace(";char", "; char").toLowerCase()); assertEquals("application/x-www-form-urlencoded", MY_SERVLET.ourRequestContentType.replace(";char", "; char").toLowerCase());
assertEquals(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY, MY_SERVLET.ourRequestFirstHeaders.get("Accept").getValue()); assertEquals(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY, MY_SERVLET.ourRequestFirstHeaders.get("Accept").getValue());
assertThat(MY_SERVLET.ourRequestFirstHeaders.get("User-Agent").getValue(), not(emptyString())); assertThat(MY_SERVLET.ourRequestFirstHeaders.get("User-Agent").getValue()).isNotEmpty();
} }
@Test @Test
@ -1604,8 +1582,8 @@ public class GenericJaxRsClientDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
assertThat(MY_SERVLET.ourRequestUri, containsString(ourServer.getBaseUrl() + "/fhir/Patient/_search?")); assertThat(MY_SERVLET.ourRequestUri).contains(ourServer.getBaseUrl() + "/fhir/Patient/_search?");
assertThat(MY_SERVLET.ourRequestUri, containsString("_elements=identifier%2Cname")); assertThat(MY_SERVLET.ourRequestUri).contains("_elements=identifier%2Cname");
// assertThat(MY_SERVLET.ourRequestUri, // assertThat(MY_SERVLET.ourRequestUri,
// either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname"))); // either(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo(ourServer.getBaseUrl() + "/fhir/Patient?name=james&_elements=identifier%2Cname")));
@ -1754,11 +1732,11 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir", MY_SERVLET.ourRequestUri);
assertEquals(2, response.size()); assertThat(response).hasSize(2);
String requestString = MY_SERVLET.ourRequestBodyString; String requestString = MY_SERVLET.ourRequestBodyString;
org.hl7.fhir.dstu3.model.Bundle requestBundle = ourCtx.newJsonParser().parseResource(org.hl7.fhir.dstu3.model.Bundle.class, requestString); org.hl7.fhir.dstu3.model.Bundle requestBundle = ourCtx.newJsonParser().parseResource(org.hl7.fhir.dstu3.model.Bundle.class, requestString);
assertEquals(2, requestBundle.getEntry().size()); assertThat(requestBundle.getEntry()).hasSize(2);
assertEquals(HTTPVerb.POST, requestBundle.getEntry().get(0).getRequest().getMethod()); assertEquals(HTTPVerb.POST, requestBundle.getEntry().get(0).getRequest().getMethod());
assertEquals(HTTPVerb.PUT, requestBundle.getEntry().get(1).getRequest().getMethod()); assertEquals(HTTPVerb.PUT, requestBundle.getEntry().get(1).getRequest().getMethod());
assertEquals("http://example.com/Patient/2", requestBundle.getEntry().get(1).getFullUrl()); assertEquals("http://example.com/Patient/2", requestBundle.getEntry().get(1).getFullUrl());
@ -1817,7 +1795,7 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir/", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/", MY_SERVLET.ourRequestUri);
assertThat(response, containsString("\"Bundle\"")); assertThat(response).contains("\"Bundle\"");
assertEquals("application/fhir+json;charset=UTF-8", MY_SERVLET.ourRequestFirstHeaders.get("Content-Type").getValue()); assertEquals("application/fhir+json;charset=UTF-8", MY_SERVLET.ourRequestFirstHeaders.get("Content-Type").getValue());
//@formatter:off //@formatter:off
@ -1865,7 +1843,7 @@ public class GenericJaxRsClientDstu3Test {
//@formatter:on //@formatter:on
assertEquals(ourServer.getBaseUrl() + "/fhir", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir", MY_SERVLET.ourRequestUri);
assertEquals(2, response.getEntry().size()); assertThat(response.getEntry()).hasSize(2);
assertEquals("Patient/1/_history/1", response.getEntry().get(0).getResponse().getLocation()); assertEquals("Patient/1/_history/1", response.getEntry().get(0).getResponse().getLocation());
assertEquals("Patient/2/_history/2", response.getEntry().get(1).getResponse().getLocation()); assertEquals("Patient/2/_history/2", response.getEntry().get(1).getResponse().getLocation());
@ -1884,41 +1862,41 @@ public class GenericJaxRsClientDstu3Test {
p.addName().setFamily("FOOFAMILY"); p.addName().setFamily("FOOFAMILY");
client.update().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute(); client.update().resource(p).conditionalByUrl("Patient?name=foo").encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestUri);
client.update().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); client.update().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=http%3A//foo%7Cbar", MY_SERVLET.ourRequestUri);
client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditionalByUrl("Patient?name=foo").execute(); client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditionalByUrl("Patient?name=foo").execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo", MY_SERVLET.ourRequestUri);
client.update().resource(p).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); client.update().resource(p).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", MY_SERVLET.ourRequestUri);
client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", MY_SERVLET.ourRequestUri);
@ -1939,17 +1917,17 @@ public class GenericJaxRsClientDstu3Test {
p.addName().setFamily("FOOFAMILY"); p.addName().setFamily("FOOFAMILY");
client.update(new IdType("Patient/123").getValue(), p); client.update(new IdType("Patient/123").getValue(), p);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", MY_SERVLET.ourRequestUri);
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
client.update("123", p); client.update("123", p);
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE)).hasSize(1);
assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, MY_SERVLET.ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char"));
assertThat(MY_SERVLET.ourRequestBodyString, containsString("<family value=\"FOOFAMILY\"/>")); assertThat(MY_SERVLET.ourRequestBodyString).contains("<family value=\"FOOFAMILY\"/>");
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/123?_format=xml", MY_SERVLET.ourRequestUri);
assertEquals("PUT", MY_SERVLET.ourRequestMethod); assertEquals("PUT", MY_SERVLET.ourRequestMethod);
@ -1967,12 +1945,12 @@ public class GenericJaxRsClientDstu3Test {
p.addName().setFamily("FOOFAMILY"); p.addName().setFamily("FOOFAMILY");
client.update().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); client.update().resource(p).prefer(PreferReturnEnum.MINIMAL).execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
client.update().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); client.update().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute();
assertEquals(1, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertThat(MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER)).hasSize(1);
assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, MY_SERVLET.ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue());
@ -2046,7 +2024,7 @@ public class GenericJaxRsClientDstu3Test {
response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute(); response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute();
assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate?_pretty=true", MY_SERVLET.ourRequestUri); assertEquals(ourServer.getBaseUrl() + "/fhir/Patient/$validate?_pretty=true", MY_SERVLET.ourRequestUri);
assertEquals("POST", MY_SERVLET.ourRequestMethod); assertEquals("POST", MY_SERVLET.ourRequestMethod);
assertThat(MY_SERVLET.ourRequestBodyString, containsString("\"resourceType\": \"Parameters\",\n")); assertThat(MY_SERVLET.ourRequestBodyString).contains("\"resourceType\": \"Parameters\",\n");
assertNotNull(response.getOperationOutcome()); assertNotNull(response.getOperationOutcome());
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue());

View File

@ -4,6 +4,8 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.test.BaseFhirVersionParameterizedTest; import ca.uhn.fhir.test.BaseFhirVersionParameterizedTest;
import com.google.common.net.MediaType; import com.google.common.net.MediaType;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.core.Response;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -13,20 +15,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import static org.hamcrest.CoreMatchers.hasItem; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNot.not;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
/** /**
* Created by Sebastien Riviere on 31/07/2017. * Created by Sebastien Riviere on 31/07/2017.
*/ */
@ -57,7 +55,7 @@ public class JaxRsRestfulClientFactoryTest extends BaseFhirVersionParameterizedT
final Client result = factory.getNativeClientClient(); final Client result = factory.getNativeClientClient();
assertNotNull(result); assertNotNull(result);
ourLog.info("Classes: {}", result.getConfiguration().getClasses()); ourLog.info("Classes: {}", result.getConfiguration().getClasses());
assertThat(result.getConfiguration().getClasses(), not(hasItem(ca.uhn.fhir.jaxrs.client.MyFilter.class))); assertThat(result.getConfiguration().getClasses()).doesNotContain(ca.uhn.fhir.jaxrs.client.MyFilter.class);
} }
@Test @Test
@ -66,7 +64,7 @@ public class JaxRsRestfulClientFactoryTest extends BaseFhirVersionParameterizedT
final Client result = factory.getNativeClientClient(); final Client result = factory.getNativeClientClient();
assertNotNull(result); assertNotNull(result);
ourLog.info("Classes: {}", result.getConfiguration().getClasses()); ourLog.info("Classes: {}", result.getConfiguration().getClasses());
assertThat(result.getConfiguration().getClasses(), hasItem(ca.uhn.fhir.jaxrs.client.MyFilter.class)); assertThat(result.getConfiguration().getClasses()).contains(ca.uhn.fhir.jaxrs.client.MyFilter.class);
} }
@ParameterizedTest @ParameterizedTest

View File

@ -4,6 +4,7 @@ import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientResponseContext; import jakarta.ws.rs.client.ClientResponseContext;
import jakarta.ws.rs.client.ClientResponseFilter; import jakarta.ws.rs.client.ClientResponseFilter;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import java.io.IOException; import java.io.IOException;
/** /**

View File

@ -5,19 +5,19 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderDstu2Hl7Org;
import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu2Hl7Org; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu2Hl7Org;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import java.net.URI; import java.net.URI;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -66,8 +66,8 @@ public class AbstractJaxRsConformanceProviderDstu2Hl7OrgTest {
providers.put(TestJaxRsMockPatientRestProviderDstu2Hl7Org.class, new TestJaxRsMockPatientRestProviderDstu2Hl7Org()); providers.put(TestJaxRsMockPatientRestProviderDstu2Hl7Org.class, new TestJaxRsMockPatientRestProviderDstu2Hl7Org());
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
assertTrue(response.getEntity().toString().contains("\"type\": \"Patient\"")); assertThat(response.getEntity().toString()).contains("\"type\": \"Patient\"");
assertTrue(response.getEntity().toString().contains("someCustomOperation")); assertThat(response.getEntity().toString()).contains("someCustomOperation");
System.out.println(response); System.out.println(response);
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }
@ -80,8 +80,8 @@ public class AbstractJaxRsConformanceProviderDstu2Hl7OrgTest {
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
System.out.println(response.getEntity()); System.out.println(response.getEntity());
assertTrue(response.getEntity().toString().contains(" <type value=\"Patient\"/>")); assertThat(response.getEntity().toString()).contains(" <type value=\"Patient\"/>");
assertTrue(response.getEntity().toString().contains("someCustomOperation")); assertThat(response.getEntity().toString()).contains("someCustomOperation");
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }

View File

@ -5,20 +5,20 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderDstu2_1;
import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu2_1; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu2_1;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import org.jboss.resteasy.specimpl.ResteasyHttpHeaders;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo; import jakarta.ws.rs.core.UriInfo;
import org.jboss.resteasy.specimpl.ResteasyHttpHeaders;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.net.URI; import java.net.URI;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -67,8 +67,8 @@ public class AbstractJaxRsConformanceProviderDstu2_1Test {
providers.put(TestJaxRsMockPatientRestProviderDstu2_1.class, new TestJaxRsMockPatientRestProviderDstu2_1()); providers.put(TestJaxRsMockPatientRestProviderDstu2_1.class, new TestJaxRsMockPatientRestProviderDstu2_1());
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
assertTrue(response.getEntity().toString().contains("\"type\": \"Patient\"")); assertThat(response.getEntity().toString()).contains("\"type\": \"Patient\"");
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertThat(response.getEntity().toString()).contains("\"someCustomOperation");
System.out.println(response); System.out.println(response);
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }
@ -81,8 +81,8 @@ public class AbstractJaxRsConformanceProviderDstu2_1Test {
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
System.out.println(response.getEntity()); System.out.println(response.getEntity());
assertTrue(response.getEntity().toString().contains(" <type value=\"Patient\"/>")); assertThat(response.getEntity().toString()).contains(" <type value=\"Patient\"/>");
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertThat(response.getEntity().toString()).contains("\"someCustomOperation");
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }

View File

@ -5,19 +5,19 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderDstu3;
import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu3; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu3;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import java.net.URI; import java.net.URI;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -66,8 +66,8 @@ public class AbstractJaxRsConformanceProviderDstu3Test {
providers.put(TestJaxRsMockPatientRestProviderDstu3.class, new TestJaxRsMockPatientRestProviderDstu3()); providers.put(TestJaxRsMockPatientRestProviderDstu3.class, new TestJaxRsMockPatientRestProviderDstu3());
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
assertTrue(response.getEntity().toString().contains("\"type\": \"Patient\"")); assertThat(response.getEntity().toString()).contains("\"type\": \"Patient\"");
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertThat(response.getEntity().toString()).contains("\"someCustomOperation");
System.out.println(response); System.out.println(response);
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }
@ -80,8 +80,8 @@ public class AbstractJaxRsConformanceProviderDstu3Test {
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
System.out.println(response.getEntity()); System.out.println(response.getEntity());
assertTrue(response.getEntity().toString().contains(" <type value=\"Patient\"/>")); assertThat(response.getEntity().toString()).contains(" <type value=\"Patient\"/>");
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertThat(response.getEntity().toString()).contains("\"someCustomOperation");
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }

View File

@ -5,19 +5,19 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderR4;
import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderR4; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderR4;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import java.net.URI; import java.net.URI;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -66,8 +66,8 @@ public class AbstractJaxRsConformanceProviderR4Test {
providers.put(TestJaxRsMockPatientRestProviderR4.class, new TestJaxRsMockPatientRestProviderR4()); providers.put(TestJaxRsMockPatientRestProviderR4.class, new TestJaxRsMockPatientRestProviderR4());
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
assertTrue(response.getEntity().toString().contains("\"type\": \"Patient\"")); assertThat(response.getEntity().toString()).contains("\"type\": \"Patient\"");
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertThat(response.getEntity().toString()).contains("\"someCustomOperation");
System.out.println(response); System.out.println(response);
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }
@ -80,8 +80,8 @@ public class AbstractJaxRsConformanceProviderR4Test {
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
System.out.println(response.getEntity()); System.out.println(response.getEntity());
assertTrue(response.getEntity().toString().contains(" <type value=\"Patient\"/>")); assertThat(response.getEntity().toString()).contains(" <type value=\"Patient\"/>");
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertThat(response.getEntity().toString()).contains("\"someCustomOperation");
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }

View File

@ -4,19 +4,19 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProvider;
import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProvider; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProvider;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import java.net.URI; import java.net.URI;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -65,8 +65,8 @@ public class AbstractJaxRsConformanceProviderTest {
providers.put(TestJaxRsMockPatientRestProvider.class, new TestJaxRsMockPatientRestProvider()); providers.put(TestJaxRsMockPatientRestProvider.class, new TestJaxRsMockPatientRestProvider());
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
assertTrue(response.getEntity().toString().contains("\"type\": \"Patient\"")); assertThat(response.getEntity().toString()).contains("\"type\": \"Patient\"");
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertThat(response.getEntity().toString()).contains("\"someCustomOperation");
System.out.println(response); System.out.println(response);
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }
@ -79,8 +79,8 @@ public class AbstractJaxRsConformanceProviderTest {
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
System.out.println(response.getEntity()); System.out.println(response.getEntity());
assertTrue(response.getEntity().toString().contains(" <type value=\"Patient\"/>")); assertThat(response.getEntity().toString()).contains(" <type value=\"Patient\"/>");
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertThat(response.getEntity().toString()).contains("\"someCustomOperation");
System.out.println(response.getEntity()); System.out.println(response.getEntity());
} }

View File

@ -8,16 +8,16 @@ import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.IRestfulResponse; import ca.uhn.fhir.rest.api.server.IRestfulResponse;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;

View File

@ -19,9 +19,9 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.test.utilities.JettyUtil;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler; import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder; import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.server.Server;
import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.CapabilityStatement; import org.hl7.fhir.dstu3.model.CapabilityStatement;
@ -51,10 +51,10 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull; 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.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.argThat;
@ -383,8 +383,8 @@ public class AbstractJaxRsResourceProviderDstu3Test {
when(mock.update(idCaptor.capture(), patientCaptor.capture(), conditionalCaptor.capture())).thenReturn(new MethodOutcome()); when(mock.update(idCaptor.capture(), patientCaptor.capture(), conditionalCaptor.capture())).thenReturn(new MethodOutcome());
client.update().resource(createPatient(1)).conditional().where(Patient.IDENTIFIER.exactly().identifier("2")).execute(); client.update().resource(createPatient(1)).conditional().where(Patient.IDENTIFIER.exactly().identifier("2")).execute();
assertEquals(null, patientCaptor.getValue().getIdElement().getIdPart()); assertNull(patientCaptor.getValue().getIdElement().getIdPart());
assertEquals(null, patientCaptor.getValue().getIdElement().getVersionIdPart()); assertNull(patientCaptor.getValue().getIdElement().getVersionIdPart());
assertEquals("Patient?identifier=2&_format=json", conditionalCaptor.getValue()); assertEquals("Patient?identifier=2&_format=json", conditionalCaptor.getValue());
} }
@ -420,7 +420,7 @@ public class AbstractJaxRsResourceProviderDstu3Test {
fail(); fail();
} catch (final ResourceNotFoundException e) { } catch (final ResourceNotFoundException e) {
assertEquals(ResourceNotFoundException.STATUS_CODE, e.getStatusCode()); assertEquals(ResourceNotFoundException.STATUS_CODE, e.getStatusCode());
assertTrue(e.getMessage().contains("999955541264")); assertThat(e.getMessage()).contains("999955541264");
} }
} }

View File

@ -31,9 +31,9 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.test.utilities.JettyUtil;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler; import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder; import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.server.Server;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@ -49,10 +49,10 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull; 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.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.argThat;
@ -343,7 +343,7 @@ public class AbstractJaxRsResourceProviderTest {
when(mock.update(idCaptor.capture(), patientCaptor.capture(), conditionalCaptor.capture())).thenReturn(new MethodOutcome()); when(mock.update(idCaptor.capture(), patientCaptor.capture(), conditionalCaptor.capture())).thenReturn(new MethodOutcome());
client.update().resource(createPatient(1)).conditional().where(Patient.IDENTIFIER.exactly().identifier("2")).execute(); client.update().resource(createPatient(1)).conditional().where(Patient.IDENTIFIER.exactly().identifier("2")).execute();
assertEquals(null, patientCaptor.getValue().getId().getIdPart()); assertNull(patientCaptor.getValue().getId().getIdPart());
assertEquals("Patient?identifier=2&_format=json", conditionalCaptor.getValue()); assertEquals("Patient?identifier=2&_format=json", conditionalCaptor.getValue());
} }
@ -399,7 +399,7 @@ public class AbstractJaxRsResourceProviderTest {
fail(); fail();
} catch (final ResourceNotFoundException e) { } catch (final ResourceNotFoundException e) {
assertEquals(ResourceNotFoundException.STATUS_CODE, e.getStatusCode()); assertEquals(ResourceNotFoundException.STATUS_CODE, e.getStatusCode());
assertTrue(e.getMessage().contains("999955541264")); assertThat(e.getMessage()).contains("999955541264");
} }
} }

View File

@ -19,9 +19,8 @@ import org.junit.jupiter.api.Test;
import java.net.URI; import java.net.URI;
import java.util.HashMap; import java.util.HashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.ArgumentMatchers.isNull;
@ -75,7 +74,7 @@ public class JaxRsExceptionInterceptorTest {
interceptor.intercept(context); interceptor.intercept(context);
fail(); fail();
} catch (BaseServerResponseException e) { } catch (BaseServerResponseException e) {
assertTrue(e.getMessage().contains("someMessage")); assertThat(e.getMessage()).contains("someMessage");
} }
} }
@ -84,7 +83,7 @@ public class JaxRsExceptionInterceptorTest {
Object expected = new Object(); Object expected = new Object();
when(context.proceed()).thenReturn(expected); when(context.proceed()).thenReturn(expected);
Object result = interceptor.intercept(context); Object result = interceptor.intercept(context);
assertSame(expected, result); assertThat(result).isSameAs(expected);
} }
@Test @Test

View File

@ -1,10 +1,8 @@
package ca.uhn.fhir.jaxrs.server.test; package ca.uhn.fhir.jaxrs.server.test;
import ca.uhn.fhir.interceptor.api.IInterceptorService;
import org.hl7.fhir.dstu3.model.Patient;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider; import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider;
import org.hl7.fhir.dstu3.model.Patient;
/** /**
* A dummy patient provider exposing no methods * A dummy patient provider exposing no methods

View File

@ -1,14 +1,13 @@
package ca.uhn.fhir.jaxrs.server.test; package ca.uhn.fhir.jaxrs.server.test;
import jakarta.ejb.Stateless;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jaxrs.server.AbstractJaxRsPageProvider; import ca.uhn.fhir.jaxrs.server.AbstractJaxRsPageProvider;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.IPagingProvider; import ca.uhn.fhir.rest.server.IPagingProvider;
import jakarta.ejb.Stateless;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
@Path("/") @Path("/")
@Stateless @Stateless

View File

@ -1,27 +1,46 @@
package ca.uhn.fhir.jaxrs.server.test; package ca.uhn.fhir.jaxrs.server.test;
import java.util.List;
import jakarta.ejb.Stateless;
import jakarta.interceptor.Interceptors;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.hl7.fhir.dstu2.model.*;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.mockito.Mockito;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider; import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider;
import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsExceptionInterceptor; import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsExceptionInterceptor;
import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.annotation.ConditionalUrlParam;
import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.Delete;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.RequiredParam;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider; import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider;
import ca.uhn.fhir.rest.server.IPagingProvider; import ca.uhn.fhir.rest.server.IPagingProvider;
import jakarta.ejb.Stateless;
import jakarta.interceptor.Interceptors;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.hl7.fhir.dstu2.model.IdType;
import org.hl7.fhir.dstu2.model.OperationOutcome;
import org.hl7.fhir.dstu2.model.Parameters;
import org.hl7.fhir.dstu2.model.Patient;
import org.hl7.fhir.dstu2.model.StringType;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.mockito.Mockito;
import java.util.List;
/** /**
* A test server delegating each call to a mock * A test server delegating each call to a mock

View File

@ -1,27 +1,46 @@
package ca.uhn.fhir.jaxrs.server.test; package ca.uhn.fhir.jaxrs.server.test;
import java.util.List;
import jakarta.ejb.Stateless;
import jakarta.interceptor.Interceptors;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.mockito.Mockito;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider; import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider;
import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsExceptionInterceptor; import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsExceptionInterceptor;
import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.annotation.ConditionalUrlParam;
import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.Delete;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.RequiredParam;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider; import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider;
import ca.uhn.fhir.rest.server.IPagingProvider; import ca.uhn.fhir.rest.server.IPagingProvider;
import jakarta.ejb.Stateless;
import jakarta.interceptor.Interceptors;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.mockito.Mockito;
import java.util.List;
/** /**
* A test server delegating each call to a mock * A test server delegating each call to a mock

View File

@ -21,9 +21,9 @@ import org.junit.jupiter.api.Test;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class JaxRsMethodBindingsDstu3Test { public class JaxRsMethodBindingsDstu3Test {
@ -35,7 +35,7 @@ public class JaxRsMethodBindingsDstu3Test {
@Test @Test
public void testFindMethodsForProviderNotDefinedMappingMethods() { public void testFindMethodsForProviderNotDefinedMappingMethods() {
assertThrows(NotImplementedOperationException.class, () -> { assertThatExceptionOfType(NotImplementedOperationException.class).isThrownBy(() -> {
new TestJaxRsDummyPatientProviderDstu3().getBindings().getBinding(RestOperationTypeEnum.UPDATE, ""); new TestJaxRsDummyPatientProviderDstu3().getBindings().getBinding(RestOperationTypeEnum.UPDATE, "");
}); });
} }
@ -87,8 +87,8 @@ public class JaxRsMethodBindingsDstu3Test {
new TestDoubleSearchProvider(); new TestDoubleSearchProvider();
fail(); fail();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("search1")); assertThat(e.getMessage()).contains("search1");
assertTrue(e.getMessage().contains("search2")); assertThat(e.getMessage()).contains("search2");
} }
} }

View File

@ -21,9 +21,9 @@ import org.junit.jupiter.api.Test;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
public class JaxRsMethodBindingsTest { public class JaxRsMethodBindingsTest {
@ -35,7 +35,7 @@ public class JaxRsMethodBindingsTest {
@Test @Test
public void testFindMethodsForProviderNotDefinedMappingMethods() { public void testFindMethodsForProviderNotDefinedMappingMethods() {
assertThrows(NotImplementedOperationException.class, () -> { assertThatExceptionOfType(NotImplementedOperationException.class).isThrownBy(() -> {
new TestJaxRsDummyPatientProvider().getBindings().getBinding(RestOperationTypeEnum.UPDATE, ""); new TestJaxRsDummyPatientProvider().getBindings().getBinding(RestOperationTypeEnum.UPDATE, "");
}); });
} }
@ -87,8 +87,8 @@ public class JaxRsMethodBindingsTest {
new TestDoubleSearchProvider(); new TestDoubleSearchProvider();
fail(); fail();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("search1")); assertThat(e.getMessage()).contains("search1");
assertTrue(e.getMessage().contains("search2")); assertThat(e.getMessage()).contains("search2");
} }
} }

View File

@ -3,21 +3,24 @@ package ca.uhn.fhir.jaxrs.server.util;
import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderDstu3; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderDstu3;
import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.UriInfo;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.UriInfo;
import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays; import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*; import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.mockito.Mockito.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
public class JaxRsRequestDstu3Test { public class JaxRsRequestDstu3Test {
@ -69,14 +72,14 @@ public class JaxRsRequestDstu3Test {
@Test @Test
public void testGetReader() { public void testGetReader() {
assertThrows(UnsupportedOperationException.class, ()->{ assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> {
details.getReader(); details.getReader();
}); });
} }
@Test @Test
public void testGetInputStream() { public void testGetInputStream() {
assertThrows(UnsupportedOperationException.class, ()->{ assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> {
details.getInputStream(); details.getInputStream();
}); });
} }

View File

@ -3,20 +3,25 @@ package ca.uhn.fhir.jaxrs.server.util;
import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProvider; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProvider;
import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.UriInfo;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.UriInfo;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays; import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*; import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.mockito.Mockito.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
public class JaxRsRequestTest { public class JaxRsRequestTest {
@ -68,14 +73,14 @@ public class JaxRsRequestTest {
@Test @Test
public void testGetReader() throws IOException { public void testGetReader() throws IOException {
assertThrows(UnsupportedOperationException.class,()->{ assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> {
details.getReader(); details.getReader();
}); });
} }
@Test @Test
public void testGetInputStream() { public void testGetInputStream() {
assertThrows(UnsupportedOperationException.class, ()->{ assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> {
details.getInputStream(); details.getInputStream();
}); });
} }

View File

@ -1,25 +1,26 @@
package ca.uhn.fhir.jaxrs.server.util; package ca.uhn.fhir.jaxrs.server.util;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import ca.uhn.fhir.rest.api.Constants;
import static org.junit.jupiter.api.Assertions.assertEquals; import ca.uhn.fhir.rest.api.MethodOutcome;
import static org.junit.jupiter.api.Assertions.assertTrue; import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.server.RestfulServerUtils;
import jakarta.ws.rs.core.Response;
import org.hl7.fhir.dstu3.model.Binary;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.instance.model.api.IBaseBinary;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import jakarta.ws.rs.core.Response; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hl7.fhir.dstu3.model.*; import static org.junit.jupiter.api.Assertions.assertNull;
import org.hl7.fhir.instance.model.api.IBaseBinary;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.server.RestfulServerUtils;
public class JaxRsResponseDstu3Test { public class JaxRsResponseDstu3Test {
@ -44,9 +45,9 @@ public class JaxRsResponseDstu3Test {
boolean theAddContentLocationHeader = false; boolean theAddContentLocationHeader = false;
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), bundle, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), bundle, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals(Constants.CT_FHIR_JSON_NEW+Constants.CHARSET_UTF8_CTSUFFIX, result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertEquals(Constants.CT_FHIR_JSON_NEW + Constants.CHARSET_UTF8_CTSUFFIX, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
assertTrue(result.getEntity().toString().contains("Patient")); assertThat(result.getEntity().toString()).contains("Patient");
assertTrue(result.getEntity().toString().contains("15")); assertThat(result.getEntity().toString()).contains("15");
} }
@Test @Test
@ -62,7 +63,7 @@ public class JaxRsResponseDstu3Test {
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals(contentType, result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertEquals(contentType, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
assertArrayEquals(content, (byte[])result.getEntity()); assertThat((byte[]) result.getEntity()).containsExactly(content);
} }
@Test @Test
@ -74,8 +75,8 @@ public class JaxRsResponseDstu3Test {
boolean theAddContentLocationHeader = false; boolean theAddContentLocationHeader = false;
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals(null, result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertNull(result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
assertEquals(null, result.getEntity()); assertNull(result.getEntity());
} }
@Test @Test
@ -86,9 +87,9 @@ public class JaxRsResponseDstu3Test {
boolean theAddContentLocationHeader = false; boolean theAddContentLocationHeader = false;
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals("{\n" + assertThat(result.getEntity().toString()).isEqualTo("{\n" +
" \"resourceType\": \"Binary\"\n" + " \"resourceType\": \"Binary\"\n" +
"}", result.getEntity().toString()); "}");
} }
@Test @Test
@ -102,9 +103,9 @@ public class JaxRsResponseDstu3Test {
boolean respondGzip = true; boolean respondGzip = true;
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals(Constants.CT_FHIR_JSON_NEW+"; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertEquals(Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
assertTrue(result.getEntity().toString().contains("resourceType\": \"Patient")); assertThat(result.getEntity().toString()).contains("resourceType\": \"Patient");
assertTrue(result.getEntity().toString().contains("15")); assertThat(result.getEntity().toString()).contains("15");
} }
@ -121,8 +122,8 @@ public class JaxRsResponseDstu3Test {
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals("application/fhir+xml; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertEquals("application/fhir+xml; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
assertTrue(result.getEntity().toString().contains("<Patient")); assertThat(result.getEntity().toString()).contains("<Patient");
assertTrue(result.getEntity().toString().contains("15")); assertThat(result.getEntity().toString()).contains("15");
} }
@Test @Test
@ -132,7 +133,7 @@ public class JaxRsResponseDstu3Test {
boolean respondGzip = true; boolean respondGzip = true;
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), null, theSummaryMode, 204, addContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), null, theSummaryMode, 204, addContentLocationHeader, respondGzip, this.request);
assertEquals(204, result.getStatus()); assertEquals(204, result.getStatus());
assertEquals(null, result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertNull(result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
} }
private Bundle getSinglePatientResource() { private Bundle getSinglePatientResource() {

View File

@ -1,28 +1,24 @@
package ca.uhn.fhir.jaxrs.server.util; package ca.uhn.fhir.jaxrs.server.util;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Set;
import jakarta.ws.rs.core.Response;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IBaseBinary;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import ca.uhn.fhir.model.dstu2.resource.Binary; import ca.uhn.fhir.model.dstu2.resource.Binary;
import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.server.RestfulServerUtils; import ca.uhn.fhir.rest.server.RestfulServerUtils;
import jakarta.ws.rs.core.Response;
import org.hl7.fhir.instance.model.api.IBaseBinary;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class JaxRsResponseTest { public class JaxRsResponseTest {
@ -49,7 +45,7 @@ public class JaxRsResponseTest {
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals(contentType, result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertEquals(contentType, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
assertArrayEquals(content, (byte[])result.getEntity()); assertThat((byte[]) result.getEntity()).containsExactly(content);
} }
@Test @Test
@ -60,8 +56,8 @@ public class JaxRsResponseTest {
boolean theAddContentLocationHeader = false; boolean theAddContentLocationHeader = false;
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals(null, result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertNull(result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
assertEquals(null, result.getEntity()); assertNull(result.getEntity());
} }
@Test @Test
@ -71,9 +67,9 @@ public class JaxRsResponseTest {
boolean theAddContentLocationHeader = false; boolean theAddContentLocationHeader = false;
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals("{\n" + assertThat(result.getEntity().toString()).isEqualTo("{\n" +
" \"resourceType\": \"Binary\"\n" + " \"resourceType\": \"Binary\"\n" +
"}", result.getEntity().toString()); "}");
} }
@Test @Test
@ -85,8 +81,8 @@ public class JaxRsResponseTest {
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals("application/json+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertEquals("application/json+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
System.out.println(result.getEntity().toString()); System.out.println(result.getEntity().toString());
assertTrue(result.getEntity().toString().contains("resourceType\": \"Patient")); assertThat(result.getEntity().toString()).contains("resourceType\": \"Patient");
assertTrue(result.getEntity().toString().contains("15")); assertThat(result.getEntity().toString()).contains("15");
} }
@ -98,8 +94,8 @@ public class JaxRsResponseTest {
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals("application/xml+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertEquals("application/xml+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
assertTrue(result.getEntity().toString().contains("<Patient")); assertThat(result.getEntity().toString()).contains("<Patient");
assertTrue(result.getEntity().toString().contains("15")); assertThat(result.getEntity().toString()).contains("15");
} }
@Test @Test
@ -123,8 +119,8 @@ public class JaxRsResponseTest {
binary.setContent(new byte[] { 1 }); binary.setContent(new byte[] { 1 });
final Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, false, false, this.request); final Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, false, false, this.request);
assertThat(result.getHeaders().get("Authorization"), Matchers.contains("Basic", "Bearer")); assertThat(result.getHeaders().get("Authorization")).containsExactly("Basic", "Bearer");
assertThat(result.getHeaders().get("Cache-Control"), Matchers.contains("no-cache, no-store")); assertThat(result.getHeaders().get("Cache-Control")).containsExactly("no-cache, no-store");
} }
private Patient createPatient() { private Patient createPatient() {

Some files were not shown because too many files have changed in this diff Show More