From bb1e8b9ddd107123c0279846ef3f6614f9216767 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Mon, 17 Aug 2015 15:54:00 -0400 Subject: [PATCH] Last commit broke cobertura --- hapi-fhir-base/pom.xml | 1 - hapi-fhir-cobertura/pom.xml | 68 ++-- .../rest/client/LoggingInterceptorTest.java | 5 +- .../rest/server/ETagServerHl7OrgTest.java | 290 +++++++++--------- pom.xml | 8 +- 5 files changed, 185 insertions(+), 187 deletions(-) diff --git a/hapi-fhir-base/pom.xml b/hapi-fhir-base/pom.xml index dadb9fac6cb..335b37004eb 100644 --- a/hapi-fhir-base/pom.xml +++ b/hapi-fhir-base/pom.xml @@ -110,7 +110,6 @@ ch.qos.logback logback-classic - ${logback_version} true diff --git a/hapi-fhir-cobertura/pom.xml b/hapi-fhir-cobertura/pom.xml index 1bd5992a66e..47ad7cd8657 100644 --- a/hapi-fhir-cobertura/pom.xml +++ b/hapi-fhir-cobertura/pom.xml @@ -1,12 +1,8 @@ - + 4.0.0 - + ca.uhn.hapi.fhir hapi-deployable-pom @@ -62,17 +58,20 @@ ${thymeleaf-version} - - - org.slf4j - slf4j-api - 1.6.0 - - - org.slf4j - slf4j-simple - 1.6.0 - + + + org.slf4j + slf4j-api + 1.6.0 + + + ch.qos.logback + logback-classic + @@ -84,13 +83,11 @@ org.apache.derby derby - ${derby_version} test - commons-dbcp - commons-dbcp - 1.4 + org.apache.commons + commons-dbcp2 test @@ -205,7 +202,6 @@ org.codehaus.mojo cobertura-maven-plugin - ${maven_cobertura_plugin_version} false @@ -221,8 +217,7 @@ **/valueset/*.class **/exceptions/*.class - + @@ -321,8 +316,10 @@ org.codehaus.mojo cobertura-maven-plugin - ${maven_cobertura_plugin_version} + + true + @@ -333,15 +330,10 @@ - + @@ -365,12 +357,16 @@ org.codehaus.mojo cobertura-maven-plugin - ${maven_cobertura_plugin_version} cobertura + + + true + + diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java index 0bdb34a48c6..12347f33095 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java @@ -47,9 +47,12 @@ public class LoggingInterceptorTest { /* * This is a bit funky, but it's useful for verifying that the headers actually get logged */ - myLoggerRoot = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); myMockAppender = mock(Appender.class); when(myMockAppender.getName()).thenReturn("MOCK"); + + org.slf4j.Logger logger = LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); + + myLoggerRoot = (ch.qos.logback.classic.Logger) logger; myLoggerRoot.addAppender(myMockAppender); } diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/server/ETagServerHl7OrgTest.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/server/ETagServerHl7OrgTest.java index be1c37d0ee7..9ba85fff31e 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/server/ETagServerHl7OrgTest.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/server/ETagServerHl7OrgTest.java @@ -43,174 +43,170 @@ import ca.uhn.fhir.util.PortUtil; */ public class ETagServerHl7OrgTest { - private static CloseableHttpClient ourClient; - private static FhirContext ourCtx; - private static Date ourLastModifiedDate; - private static int ourPort; - private static Server ourServer; - private static PoolingHttpClientConnectionManager ourConnectionManager; + private static CloseableHttpClient ourClient; + private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org(); + private static Date ourLastModifiedDate; + private static int ourPort; + private static Server ourServer; + private static PoolingHttpClientConnectionManager ourConnectionManager; - @Test - public void testETagHeader() throws Exception { - ourLastModifiedDate = new InstantDt("2012-11-25T02:34:45.2222Z").getValue(); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2/_history/3"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); + @Test + public void testETagHeader() throws Exception { + ourLastModifiedDate = new InstantDt("2012-11-25T02:34:45.2222Z").getValue(); - assertEquals(200, status.getStatusLine().getStatusCode()); - Identifier dt = ourCtx.newXmlParser().parseResource(Patient.class, responseContent).getIdentifier().get(0); - assertEquals("2", dt.getSystemElement().getValueAsString()); - assertEquals("3", dt.getValue()); + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2/_history/3"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); - Header cl = status.getFirstHeader(Constants.HEADER_ETAG_LC); - assertNotNull(cl); - assertEquals("W/\"222\"", cl.getValue()); - } + assertEquals(200, status.getStatusLine().getStatusCode()); + Identifier dt = ourCtx.newXmlParser().parseResource(Patient.class, responseContent).getIdentifier().get(0); + assertEquals("2", dt.getSystemElement().getValueAsString()); + assertEquals("3", dt.getValue()); - - @Test - public void testAutomaticNotModified() throws Exception { - ourLastModifiedDate = new InstantDt("2012-11-25T02:34:45.2222Z").getValue(); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2"); - httpGet.addHeader(Constants.HEADER_IF_NONE_MATCH, "\"222\""); - HttpResponse status = ourClient.execute(httpGet); - assertEquals(Constants.STATUS_HTTP_304_NOT_MODIFIED, status.getStatusLine().getStatusCode()); - } + Header cl = status.getFirstHeader(Constants.HEADER_ETAG_LC); + assertNotNull(cl); + assertEquals("W/\"222\"", cl.getValue()); + } - - @Test - public void testLastModifiedHeader() throws Exception { - ourLastModifiedDate = new InstantDt("2012-11-25T02:34:45.2222Z").getValue(); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2/_history/3"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); + @Test + public void testAutomaticNotModified() throws Exception { + ourLastModifiedDate = new InstantDt("2012-11-25T02:34:45.2222Z").getValue(); - assertEquals(200, status.getStatusLine().getStatusCode()); - Identifier dt = ourCtx.newXmlParser().parseResource(Patient.class, responseContent).getIdentifier().get(0); - assertEquals("2", dt.getSystemElement().getValueAsString()); - assertEquals("3", dt.getValue()); + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2"); + httpGet.addHeader(Constants.HEADER_IF_NONE_MATCH, "\"222\""); + HttpResponse status = ourClient.execute(httpGet); + assertEquals(Constants.STATUS_HTTP_304_NOT_MODIFIED, status.getStatusLine().getStatusCode()); + } - Header cl = status.getFirstHeader(Constants.HEADER_LAST_MODIFIED_LOWERCASE); - assertNotNull(cl); - assertEquals("Sun, 25 Nov 2012 02:34:47 GMT", cl.getValue()); - } + @Test + public void testLastModifiedHeader() throws Exception { + ourLastModifiedDate = new InstantDt("2012-11-25T02:34:45.2222Z").getValue(); - @Before - public void before() throws IOException { - ourLastId=null; - } + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2/_history/3"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); - @Test - public void testUpdateWithNoVersion() throws Exception { - Patient p = new Patient(); - p.addIdentifier().setSystem("urn:system").setValue("001"); - String resBody = ourCtx.newXmlParser().encodeResourceToString(p); - - HttpPut http; - http = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); - http.setEntity(new StringEntity(resBody, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); - HttpResponse status = ourClient.execute(http); - IOUtils.closeQuietly(status.getEntity().getContent()); - assertEquals(200, status.getStatusLine().getStatusCode()); - - } + assertEquals(200, status.getStatusLine().getStatusCode()); + Identifier dt = ourCtx.newXmlParser().parseResource(Patient.class, responseContent).getIdentifier().get(0); + assertEquals("2", dt.getSystemElement().getValueAsString()); + assertEquals("3", dt.getValue()); - @Test - public void testUpdateWithIfMatch() throws Exception { - Patient p = new Patient(); - p.addIdentifier().setSystem("urn:system").setValue("001"); - String resBody = ourCtx.newXmlParser().encodeResourceToString(p); - - HttpPut http; - http = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); - http.setEntity(new StringEntity(resBody, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); - http.addHeader(Constants.HEADER_IF_MATCH, "\"221\""); - CloseableHttpResponse status = ourClient.execute(http); - IOUtils.closeQuietly(status.getEntity().getContent()); - assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals("Patient/2/_history/221", ourLastId.toUnqualified().getValue()); - - } + Header cl = status.getFirstHeader(Constants.HEADER_LAST_MODIFIED_LOWERCASE); + assertNotNull(cl); + assertEquals("Sun, 25 Nov 2012 02:34:47 GMT", cl.getValue()); + } - @Test - public void testUpdateWithIfMatchPreconditionFailed() throws Exception { - Patient p = new Patient(); - p.addIdentifier().setSystem("urn:system").setValue("001"); - String resBody = ourCtx.newXmlParser().encodeResourceToString(p); - - HttpPut http; - http = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); - http.setEntity(new StringEntity(resBody, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); - http.addHeader(Constants.HEADER_IF_MATCH, "\"222\""); - CloseableHttpResponse status = ourClient.execute(http); - IOUtils.closeQuietly(status.getEntity().getContent()); - assertEquals(Constants.STATUS_HTTP_412_PRECONDITION_FAILED, status.getStatusLine().getStatusCode()); - assertEquals("Patient/2/_history/222", ourLastId.toUnqualified().getValue()); - } + @Before + public void before() throws IOException { + ourLastId = null; + } - - @AfterClass - public static void afterClass() throws Exception { - ourServer.stop(); - } + @Test + public void testUpdateWithNoVersion() throws Exception { + Patient p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue("001"); + String resBody = ourCtx.newXmlParser().encodeResourceToString(p); - @BeforeClass - public static void beforeClass() throws Exception { - ourPort = PortUtil.findFreePort(); - ourServer = new Server(ourPort); + HttpPut http; + http = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); + http.setEntity(new StringEntity(resBody, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + HttpResponse status = ourClient.execute(http); + IOUtils.closeQuietly(status.getEntity().getContent()); + assertEquals(200, status.getStatusLine().getStatusCode()); - PatientProvider patientProvider = new PatientProvider(); + } - ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(ourCtx); - ourCtx = servlet.getFhirContext(); - servlet.setResourceProviders(patientProvider); - ServletHolder servletHolder = new ServletHolder(servlet); - proxyHandler.addServletWithMapping(servletHolder, "/*"); - ourServer.setHandler(proxyHandler); - ourServer.start(); + @Test + public void testUpdateWithIfMatch() throws Exception { + Patient p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue("001"); + String resBody = ourCtx.newXmlParser().encodeResourceToString(p); - ourConnectionManager = new PoolingHttpClientConnectionManager(50000, TimeUnit.MILLISECONDS); - HttpClientBuilder builder = HttpClientBuilder.create(); - builder.setConnectionManager(ourConnectionManager); - ourClient = builder.build(); + HttpPut http; + http = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); + http.setEntity(new StringEntity(resBody, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + http.addHeader(Constants.HEADER_IF_MATCH, "\"221\""); + CloseableHttpResponse status = ourClient.execute(http); + IOUtils.closeQuietly(status.getEntity().getContent()); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertEquals("Patient/2/_history/221", ourLastId.toUnqualified().getValue()); - } + } - private static IdDt ourLastId; - - public static class PatientProvider implements IResourceProvider { + @Test + public void testUpdateWithIfMatchPreconditionFailed() throws Exception { + Patient p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue("001"); + String resBody = ourCtx.newXmlParser().encodeResourceToString(p); - @Read(version = true) - public Patient findPatient(@IdParam IdDt theId) { - Patient patient = new Patient(); - patient.getMeta().setLastUpdated(ourLastModifiedDate); - patient.addIdentifier().setSystem(theId.getIdPart()).setValue(theId.getVersionIdPart()); - patient.setId(theId.withVersion("222")); - return patient; - } + HttpPut http; + http = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); + http.setEntity(new StringEntity(resBody, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + http.addHeader(Constants.HEADER_IF_MATCH, "\"222\""); + CloseableHttpResponse status = ourClient.execute(http); + IOUtils.closeQuietly(status.getEntity().getContent()); + assertEquals(Constants.STATUS_HTTP_412_PRECONDITION_FAILED, status.getStatusLine().getStatusCode()); + assertEquals("Patient/2/_history/222", ourLastId.toUnqualified().getValue()); + } - @Update - public MethodOutcome updatePatient(@IdParam IdDt theId, @ResourceParam Patient theResource) { - ourLastId = theId; - - if ("222".equals(theId.getVersionIdPart())) { - throw new PreconditionFailedException("Bad version"); - } - - return new MethodOutcome(theId.withVersion(theId.getVersionIdPart() + "0")); - } + @AfterClass + public static void afterClass() throws Exception { + ourServer.stop(); + } - @Override - public Class getResourceType() { - return Patient.class; - } + @BeforeClass + public static void beforeClass() throws Exception { + ourPort = PortUtil.findFreePort(); + ourServer = new Server(ourPort); - } + PatientProvider patientProvider = new PatientProvider(); + + ServletHandler proxyHandler = new ServletHandler(); + RestfulServer servlet = new RestfulServer(ourCtx); + servlet.setResourceProviders(patientProvider); + ServletHolder servletHolder = new ServletHolder(servlet); + proxyHandler.addServletWithMapping(servletHolder, "/*"); + ourServer.setHandler(proxyHandler); + ourServer.start(); + + ourConnectionManager = new PoolingHttpClientConnectionManager(50000, TimeUnit.MILLISECONDS); + HttpClientBuilder builder = HttpClientBuilder.create(); + builder.setConnectionManager(ourConnectionManager); + ourClient = builder.build(); + + } + + private static IdDt ourLastId; + + public static class PatientProvider implements IResourceProvider { + + @Read(version = true) + public Patient findPatient(@IdParam IdDt theId) { + Patient patient = new Patient(); + patient.getMeta().setLastUpdated(ourLastModifiedDate); + patient.addIdentifier().setSystem(theId.getIdPart()).setValue(theId.getVersionIdPart()); + patient.setId(theId.withVersion("222")); + return patient; + } + + @Update + public MethodOutcome updatePatient(@IdParam IdDt theId, @ResourceParam Patient theResource) { + ourLastId = theId; + + if ("222".equals(theId.getVersionIdPart())) { + throw new PreconditionFailedException("Bad version"); + } + + return new MethodOutcome(theId.withVersion(theId.getVersionIdPart() + "0")); + } + + @Override + public Class getResourceType() { + return Patient.class; + } + + } } diff --git a/pom.xml b/pom.xml index 8eb0ebc8d12..e8fba856f41 100644 --- a/pom.xml +++ b/pom.xml @@ -194,7 +194,6 @@ 1.8 1.9.1 2.5.3 - 2.7 2.18.1 1.6 2.10.1 @@ -222,6 +221,11 @@ + + ch.qos.logback + logback-classic + 1.1.2 + javax.servlet javax.servlet-api @@ -276,7 +280,7 @@ org.codehaus.mojo cobertura-maven-plugin - ${maven_cobertura_plugin_version} + 2.7 true