@Test public void testUpdate() throws Exception { Patient patient = new Patient(); patient.addIdentifier("urn:foo", "123"); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(httpClient.execute(capt.capture())).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK")); when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.updatePatient(new IdDt("100"), patient); assertEquals(HttpPut.class, capt.getValue().getClass()); HttpPut post = (HttpPut) capt.getValue(); assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/100")); assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString("<Patient")); assertEquals("http://example.com/fhir/Patient/100/_history/200", response.getId().getValue()); assertEquals("200", response.getId().getVersionIdPart()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(0).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); }
@Test public void testUpdateWithVersion() throws Exception { Patient patient = new Patient(); patient.addIdentifier("urn:foo", "123"); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(httpClient.execute(capt.capture())).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK")); when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.updatePatient(new IdDt("Patient/100/_history/200"), patient); assertEquals(HttpPut.class, capt.getValue().getClass()); HttpPut post = (HttpPut) capt.getValue(); assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/100")); assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString("<Patient")); assertThat(post.getFirstHeader("Content-Location").getValue(), StringEndsWith.endsWith("Patient/100/_history/200")); assertEquals("http://example.com/fhir/Patient/100/_history/200", response.getId().getValue()); assertEquals("200", response.getId().getVersionIdPart()); }
@Test public void testValidate() throws Exception { Patient patient = new Patient(); patient.addIdentifier("urn:foo", "123"); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(httpClient.execute(capt.capture())).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK")); when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.validatePatient(patient); assertEquals(HttpPost.class, capt.getValue().getClass()); HttpPost post = (HttpPost) capt.getValue(); assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/_validate")); assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString("<Patient")); assertEquals("http://example.com/fhir/Patient/100/_history/200", response.getId().getValue()); assertEquals("200", response.getId().getVersionIdPart()); }
@Test public void testUpdate() throws Exception { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:foo").setValue("123"); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK")); when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8")); when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.updatePatient(new IdType("100"), patient); assertEquals(HttpPut.class, capt.getValue().getClass()); HttpPut post = (HttpPut) capt.getValue(); assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/100")); assertThat(IOUtils.toString(post.getEntity().getContent(), Charsets.UTF_8), StringContains.containsString("<Patient")); assertEquals("http://example.com/fhir/Patient/100/_history/200", response.getId().getValue()); assertEquals("200", response.getId().getVersionIdPart()); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(0).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); }
@Test public void testUpdateWithVersion() throws Exception { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:foo").setValue("123"); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK")); when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8")); when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.updatePatient(new IdType("Patient/100/_history/200"), patient); assertEquals(HttpPut.class, capt.getValue().getClass()); HttpPut post = (HttpPut) capt.getValue(); assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/100")); assertThat(IOUtils.toString(post.getEntity().getContent(), Charsets.UTF_8), StringContains.containsString("<Patient")); assertEquals("http://example.com/fhir/Patient/100/_history/200", response.getId().getValue()); assertEquals("200", response.getId().getVersionIdPart()); }
@Test public void testValidateNoContentResponse() throws Exception { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:foo").setValue("123"); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_204_NO_CONTENT, "OK")); when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8")); when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.validatePatient(patient); assertEquals(HttpPost.class, capt.getValue().getClass()); HttpPost post = (HttpPost) capt.getValue(); assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/$validate")); assertThat(IOUtils.toString(post.getEntity().getContent(), Charsets.UTF_8), StringContains.containsString("<Patient")); assertNull(response.getOperationOutcome()); assertNull(response.getResource()); }
private static Collection<String> getClassesInPackage(String packageName, String sampleClass) { String sampleClassPathSuffix = sampleClass.replaceAll("\\.", "/") + ".class"; String sampleClassPath = CheckParserUsagesDT.class.getClassLoader().getResource(sampleClassPathSuffix).getPath(); assertThat(sampleClassPath, new StringEndsWith(sampleClassPathSuffix)); String packagePath = sampleClassPath.substring(0,sampleClassPath.length()-sampleClassPathSuffix.length()) + packageName.replaceAll("\\.", "/"); return getAllClassesInDirectory(new File(packagePath)); }
@Test public void call_a_method_that_is_not_implemented() { // GIVEN // THEN this.expectedException.expect(FakeJedisNotImplementedException.class); this.expectedException.expectMessage(StringStartsWith.startsWith("The method ")); this.expectedException.expectMessage(StringContains.containsString("FakeJedis.mget")); this.expectedException.expectMessage(StringEndsWith.endsWith(" is not implemented in your version of FakeJedis. Contribute on github! https://github.com/vdurmont/fake-jedis")); // WHEN this.jedis.mget(KEY); }
@Test public void testValidateOutcomeResponse() throws Exception { OperationOutcome oo = new OperationOutcome(); oo.addIssue().setDiagnostics("ALL GOOD"); String resp = ourCtx.newJsonParser().encodeResourceToString(oo); Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:foo").setValue("123"); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8")); when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(resp), Charset.forName("UTF-8"))); when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.validatePatient(patient); assertEquals(HttpPost.class, capt.getValue().getClass()); HttpPost post = (HttpPost) capt.getValue(); assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/$validate")); assertThat(IOUtils.toString(post.getEntity().getContent(), Charsets.UTF_8), StringContains.containsString("<Patient")); assertNotNull(response.getOperationOutcome()); assertEquals("ALL GOOD", ((OperationOutcome)response.getOperationOutcome()).getIssueFirstRep().getDiagnostics()); assertNull(response.getResource()); }
private void expectMessageEndingWith(String end) { delegate.expectMessage(StringEndsWith.endsWith(format(end))); }
@Test public void toString_() { assertThat(this.connection.toString(), new StringStartsWith(Connection.class.getName() + "@")); assertThat(this.connection.toString(), new StringEndsWith("[sessionId=ABC123]")); }
@Test public void toString_() { assertThat(this.session.toString(), new StringStartsWith(Session.class.getName() + "@")); assertThat(this.session.toString(), new StringEndsWith("[connection=conn,session=delegate]")); }
@Test public void testLoader() throws IOException, InterruptedException { List<String> fileNames = _createFileNames(); _createTestFiles(dir, fileNames); File mainJnlp = _createJnlps(dir, fileNames); Path store1Path = dir.toPath().resolve("store1"); Path store2Path = dir.toPath().resolve("store2"); IResourcePack remoteResourcePack = ResourcePackFactory.get(mainJnlp.toURI().toURL()); IStore localStore = new LocalStore(store1Path); Thread.sleep(1000); IStoreResourcePack localResourcePack = new Loader().load(localStore, remoteResourcePack, null); _check(remoteResourcePack, localResourcePack); Path localResourcePackPath = store1Path.resolve(localResourcePack.getId() + ".jlr.xml"); remoteResourcePack = ResourcePackFactory.get(localResourcePackPath.toUri().toURL()); localStore = new LocalStore(store2Path); Thread.sleep(1000); localResourcePack = new Loader().load(localStore, remoteResourcePack, null); _check(remoteResourcePack, localResourcePack); JLoaderConfig loaderConfig = new JLoaderConfig(); IStoreResource configResource = localResourcePack.getResource(JLoaderConfig.CONFIG_ID); Assert.assertNotNull(configResource); try (InputStream inputStream = configResource.getInputStream()) { loaderConfig.load(inputStream); } Path workingDirectory = store2Path.resolve(localResourcePack.getId()).toAbsolutePath(); Process process = new ProcessBuilder(loaderConfig.getStartCommands(workingDirectory, null)) .directory(workingDirectory.toFile()) .start(); process.waitFor(10, TimeUnit.SECONDS); Assert.assertEquals(0, process.exitValue()); String sout = _readString(process.getInputStream()); String serr = _readString(process.getErrorStream()); Assert.assertEquals("arg1\ntrue\n", sout); Assert.assertThat(serr, StringEndsWith.endsWith("arg2\n")); }