@Test public void testTwoInclude() throws Exception { HttpGet httpGet = new HttpGet( "http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=bar&_pretty=true"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info(responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); assertEquals(2, p.getName().size()); assertEquals("Hello", p.getId().getIdPart()); Set<String> values = new HashSet<String>(); values.add(p.getName().get(0).getFamilyFirstRep().getValue()); values.add(p.getName().get(1).getFamilyFirstRep().getValue()); assertThat(values, containsInAnyOrder("foo", "bar")); }
@Test public void testServerReturnsWrongVersionForDstu2() throws Exception { Conformance conf = new Conformance(); conf.setFhirVersion("0.80"); String msg = myCtx.newXmlParser().encodeResourceToString(conf); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); 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_XML + "; charset=UTF-8")); when(myHttpResponse.getEntity().getContent()) .thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); myCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); try { myCtx.newRestfulGenericClient("http://foo").read(new UriDt("http://foo/Patient/123")); fail(); } catch (FhirClientInappropriateForServerException e) { String out = e.toString(); String want = "The server at base URL \"http://foo/metadata\" returned a conformance statement indicating that it supports FHIR version \"0.80\" which corresponds to DSTU1, but this client is configured to use DSTU2 (via the FhirContext)"; ourLog.info(out); ourLog.info(want); assertThat(out, containsString(want)); } }
@Test public void testUpdateNoResponse() throws Exception { DiagnosticReport dr = new DiagnosticReport(); dr.setId("001"); dr.addCodedDiagnosis().addCoding().setCode("AAA"); String encoded = ourCtx.newXmlParser().encodeResourceToString(dr); ourLog.info("OUT: {}", encoded); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPost.setEntity( new StringEntity(encoded, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); try { ourLog.info(IOUtils.toString(status.getEntity().getContent())); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals( "http://localhost:" + ourPort + "/DiagnosticReport/001/_history/002", status.getFirstHeader("location").getValue()); } finally { IOUtils.closeQuietly(status.getEntity().getContent()); } }
@Test public void testUpdateWithWrongResourceType() throws Exception { Patient patient = new Patient(); patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/AAAAAA"); httpPost.setEntity( new StringEntity( ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); assertEquals(400, status.getStatusLine().getStatusCode()); String expected = "<OperationOutcome xmlns=\"http://hl7.org/fhir\"><issue><severity value=\"error\"/><details value=\"Failed to parse request body as XML resource. Error was: DataFormatException at [[row,col {unknown-source}]: [1,1]]: Incorrect resource type found, expected "DiagnosticReport" but found "Patient"\"/></issue></OperationOutcome>"; assertEquals(expected, responseContent); }
@Test public void testUpdate() throws Exception { Patient patient = new Patient(); patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient/001"); httpPost.setEntity( new StringEntity( ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent); assertEquals("OODETAILS", oo.getIssueFirstRep().getDetails().getValue()); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals( "http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); assertEquals( "http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue()); }
@Test public void testUpdateWithoutConditionalUrl() throws Exception { Patient patient = new Patient(); patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); httpPost.setEntity( new StringEntity( ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals( "http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); assertEquals( "http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue()); assertEquals("Patient/2", new IdType(ourLastId).toUnqualified().getValue()); assertEquals("Patient/2", ourLastIdParam.toUnqualified().getValue()); assertNull(ourLastConditionalUrl); }
@Test public void testIIncludedResourcesNonContainedInExtensionJson() throws Exception { HttpGet httpGet = new HttpGet( "http://localhost:" + ourPort + "/Patient?_query=extInclude&_pretty=true&_format=json"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent); ourLog.info(responseContent); assertEquals(3, bundle.size()); assertEquals( new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless()); assertEquals( new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless()); assertEquals( new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless()); assertEquals( BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(2).getSearchMode().getValueAsEnum()); Patient p1 = (Patient) bundle.toListOfResources().get(0); assertEquals(0, p1.getContained().getContainedResources().size()); Patient p2 = (Patient) bundle.toListOfResources().get(1); assertEquals(0, p2.getContained().getContainedResources().size()); }
@Test public void testTransaction() throws Exception { String retVal = ourCtx.newXmlParser().encodeBundleToString(new Bundle()); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(ourHttpClient.execute(capt.capture())).thenReturn(ourHttpResponse); when(ourHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); when(ourHttpResponse.getEntity().getContentType()) .thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8")); when(ourHttpResponse.getEntity().getContent()) .thenReturn(new ReaderInputStream(new StringReader(retVal), Charset.forName("UTF-8"))); Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("value"); IGenericClient client = ourCtx.newRestfulGenericClient("http://foo"); client.transaction().withResources(Arrays.asList((IBaseResource) p1)).execute(); HttpUriRequest value = capt.getValue(); assertTrue("Expected request of type POST on long params list", value instanceof HttpPost); HttpPost post = (HttpPost) value; String body = IOUtils.toString(post.getEntity().getContent()); IOUtils.closeQuietly(post.getEntity().getContent()); ourLog.info(body); assertThat( body, Matchers.containsString("<type value=\"" + BundleTypeEnum.TRANSACTION.getCode())); }
private boolean testb(LineNumberReader LNR) { CueSheetLoader cp = new CueSheetLoader(LNR); cp.load(); log.info(cp.toString()); ProhibitedCharacterChecker instance = new ProhibitedCharacterChecker(); boolean result = instance.check(cp.getCueSheet()); return result; }
@After public void tearDown() { try { if (this.LNR1 != null) { this.LNR1.close(); } if (this.LNR2 != null) { this.LNR2.close(); } if (this.LNR3 != null) { this.LNR3.close(); } if (this.LNR4 != null) { this.LNR4.close(); } if (this.LNR5 != null) { this.LNR5.close(); } if (this.LNR6 != null) { this.LNR6.close(); } if (this.LNR7 != null) { this.LNR7.close(); } if (this.LNR8 != null) { this.LNR8.close(); } if (this.LNR9 != null) { this.LNR9.close(); } if (this.LNR10 != null) { this.LNR10.close(); } if (this.LNR11 != null) { this.LNR11.close(); } if (this.LNR12 != null) { this.LNR12.close(); } if (this.LNR13 != null) { this.LNR13.close(); } if (this.LNR14 != null) { this.LNR14.close(); } if (this.LNR15 != null) { this.LNR15.close(); } if (this.LNR16 != null) { this.LNR16.close(); } if (this.LNR17 != null) { this.LNR17.close(); } } catch (IOException ex) { log.error("例外発生", ex); } }
@Before public void setUp() { try { this.LNR1 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_normal), charset)); this.LNR2 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_error_1), charset)); this.LNR3 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_error_2), charset)); this.LNR4 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_error_3), charset)); this.LNR5 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_error_4), charset)); this.LNR6 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_error_5), charset)); this.LNR7 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_error_6), charset)); this.LNR8 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_error_7), charset)); this.LNR9 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_error_8), charset)); this.LNR10 = new LineNumberReader(new InputStreamReader(new FileInputStream(target_error_9), charset)); this.LNR11 = new LineNumberReader( new InputStreamReader(new FileInputStream(target_error_10), charset)); this.LNR12 = new LineNumberReader( new InputStreamReader(new FileInputStream(target_error_11), charset)); this.LNR13 = new LineNumberReader( new InputStreamReader(new FileInputStream(target_error_12), charset)); this.LNR14 = new LineNumberReader( new InputStreamReader(new FileInputStream(target_error_13), charset)); this.LNR15 = new LineNumberReader( new InputStreamReader(new FileInputStream(target_error_14), charset)); this.LNR16 = new LineNumberReader( new InputStreamReader(new FileInputStream(target_error_15), charset)); this.LNR17 = new LineNumberReader( new InputStreamReader(new FileInputStream(target_error_16), charset)); } catch (IOException ex) { log.error("例外発生", ex); } }
// @Test public void testMixedContainedAndNonContained() throws Exception { HttpGet httpGet = new HttpGet( "http://localhost:" + ourPort + "/DiagnosticReport?_query=stitchedInclude&_pretty=true"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info(responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(4, bundle.size()); }
@Test public void testSearchSummaryData() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_elements=name,maritalStatus"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info(responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); assertThat(responseContent, containsString("<Patient")); assertThat(responseContent, not(containsString("THE DIV"))); assertThat(responseContent, containsString("family")); assertThat(responseContent, containsString("maritalStatus")); assertThat(ourLastElements, containsInAnyOrder("name", "maritalStatus")); }
@SuppressWarnings("deprecation") @Test public void testExceptionsAreGood() throws Exception { ImmutableSet<ClassInfo> classes = ClassPath.from(Thread.currentThread().getContextClassLoader()) .getTopLevelClasses(BaseServerResponseException.class.getPackage().getName()); assertTrue(classes.size() > 5); for (ClassInfo classInfo : classes) { ourLog.info("Scanning {}", classInfo.getName()); Class<?> next = Class.forName(classInfo.getName()); assertNotNull(next); if (next == getClass()) { continue; } if (next == BaseServerResponseException.class) { continue; } if (next == UnclassifiedServerFailureException.class) { continue; } if (next == ResourceVersionNotSpecifiedException.class) { // This one is deprocated continue; } assertTrue( "Type " + next + " is not registered", BaseServerResponseException.isExceptionTypeRegistered(next)); if (next == AuthenticationException.class) { continue; } try { next.getConstructor(String.class, IBaseOperationOutcome.class); } catch (NoSuchMethodException e) { fail( classInfo.getName() + " has no constructor with params: (String, IBaseOperationOutcome)"); } } }
@Test public void testReadSummaryTrue() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_elements=name"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info(responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals( Constants.CT_FHIR_XML + Constants.CHARSET_UTF8_CTSUFFIX.replace(" ", "").toLowerCase(), status.getEntity().getContentType().getValue().replace(" ", "").replace("UTF", "utf")); assertThat(responseContent, not(containsString("<Bundle"))); assertThat(responseContent, (containsString("<Patien"))); assertThat(responseContent, not(containsString("<div>THE DIV</div>"))); assertThat(responseContent, (containsString("family"))); assertThat(responseContent, not(containsString("maritalStatus"))); assertThat(ourLastElements, containsInAnyOrder("name")); }
@Test public void testOneIncludeXml() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); ourLog.info(responseContent); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); assertEquals(1, p.getName().size()); assertEquals("Hello", p.getId().getIdPart()); assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue()); }
@Test public void testSearchStillWorks() throws Exception { Patient patient = new Patient(); patient.addIdentifier().setValue("002"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_pretty=true"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); assertTrue(ourLastRequestWasSearch); assertNull(ourLastId); assertNull(ourLastIdParam); assertNull(ourLastConditionalUrl); }
@Test() public void testUpdateWithVersionBadContentLocationHeader() throws Exception { DiagnosticReport dr = new DiagnosticReport(); dr.setId("001"); dr.getIdentifier().setValue("001"); HttpPut httpPut = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPut.addHeader("Content-Location", "/Patient/001/_history/002"); httpPut.setEntity( new StringEntity( ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); CloseableHttpResponse status = ourClient.execute(httpPut); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(400, status.getStatusLine().getStatusCode()); ourLog.info("Response was:\n{}", responseContent); }
@Test public void testGeneratedXsd() throws SAXException, IOException, HL7Exception { InputStream xsdInputStream = XsdConfGenMojo.class.getResourceAsStream("/XSDGEN.xsd"); Validate.notNull(xsdInputStream); Source xsdSource = new StreamSource(xsdInputStream); Validate.notNull(xsdSource); // InputStream xsdXsdInputStream = // XsdConfGenMojo.class.getResourceAsStream("/XMLSchema.xsd"); // Validate.notNull(xsdXsdInputStream); // // StreamSource xsdXsdSource = new StreamSource(xsdXsdInputStream); // Validate.notNull(xsdXsdSource); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(xsdSource); Validator validator = schema.newValidator(); DefaultHapiContext ctx = new DefaultHapiContext(new ValidationContextImpl()); ADT_A01 a01 = new ADT_A01(); a01.initQuickstart("ADT", "A01", "T"); a01.setParser(ctx.getXMLParser()); try { validator.validate(new StreamSource(new StringReader(a01.encode()))); fail(); } catch (SAXParseException e) { // expected } populateFully(a01); ourLog.info("Message:\n{}", ctx.getPipeParser().encode(a01).replace('\r', '\n')); validator.validate(new StreamSource(new StringReader(a01.encode()))); }
@Test public void testModelExtension() throws DataFormatException { MyOrganization org = new MyOrganization(); org.getName().setValue("org0"); MyPatient patient = new MyPatient(); patient.addIdentifier("foo", "bar"); patient.getManagingOrganization().setResource(org); IParser p = ourCtx.newXmlParser().setPrettyPrint(true); String str = p.encodeResourceToString(patient); ourLog.info(str); MyPatient parsed = ourCtx.newXmlParser().parseResource(MyPatient.class, str); assertEquals("foo", parsed.getIdentifierFirstRep().getSystem().getValueAsString()); // assertEquals(MyOrganization.class, // parsed.getManagingOrganization().getResource().getClass()); // MyOrganization parsedOrg = (MyOrganization) parsed.getManagingOrganization().getResource(); // assertEquals("arg0", parsedOrg.getName().getValue()); }
@Test public void testCheck_01() { System.out.println("check_01"); boolean expResult; boolean ret; expResult = false; log.info("**********************************************************************"); log.info("想定= " + expResult); log.info("エラーなし"); ret = testb(this.LNR1); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("**********************************************************************"); expResult = false; log.info("**********************************************************************"); log.info("想定= " + expResult); log.info("Titleが空欄"); log.info("アルバム"); ret = testb(this.LNR2); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("トラック"); ret = testb(this.LNR3); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("**********************************************************************"); log.info("**********************************************************************"); log.info("想定= " + expResult); log.info("Performerが空欄"); log.info("アルバム"); ret = testb(this.LNR4); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("トラック"); ret = testb(this.LNR5); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("**********************************************************************"); }
/** Test of check method, of class TitleAndPerformerChecker. */ @Test public void testCheck_02() { System.out.println("check02"); boolean expResult; boolean ret; expResult = true; log.info("**********************************************************************"); log.info("想定= " + expResult); log.info("Titleに禁止文字(<)あり。"); log.info("アルバム"); ret = testb(this.LNR6); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("トラック"); ret = testb(this.LNR7); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("**********************************************************************"); log.info("**********************************************************************"); log.info("想定= " + expResult); log.info("Titleに禁止文字(>)あり。"); log.info("アルバム"); ret = testb(this.LNR8); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("トラック"); ret = testb(this.LNR9); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("**********************************************************************"); log.info("**********************************************************************"); log.info("想定= " + expResult); log.info("Titleに禁止文字(~)あり。"); log.info("アルバム"); ret = testb(this.LNR10); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("トラック"); ret = testb(this.LNR11); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("**********************************************************************"); log.info("**********************************************************************"); log.info("想定= " + expResult); log.info("Performerに禁止文字(<)あり。"); log.info("アルバム"); ret = testb(this.LNR12); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("トラック"); ret = testb(this.LNR13); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("**********************************************************************"); log.info("**********************************************************************"); log.info("想定= " + expResult); log.info("Performerに禁止文字(>)あり。"); log.info("アルバム"); ret = testb(this.LNR14); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("トラック"); ret = testb(this.LNR15); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("**********************************************************************"); log.info("**********************************************************************"); log.info("想定= " + expResult); log.info("Performerに禁止文字(~)あり。"); log.info("アルバム"); ret = testb(this.LNR16); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("トラック"); ret = testb(this.LNR17); log.info("結果= " + ret); assertEquals(ret, expResult); log.info("**********************************************************************"); }