diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ServiceGroupBodyUtil.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ServiceGroupBodyUtil.java index ba96ee4e7399ec0a3812728d33d5183cbd3e6132..a3a28a84deb3fccd24b9941a9ef79487e444a3d2 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ServiceGroupBodyUtil.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ServiceGroupBodyUtil.java @@ -20,10 +20,21 @@ import static java.lang.String.format; */ public class ServiceGroupBodyUtil { + public static final String SIMPLE_DOCUMENT_XML ="<ServiceMetadata xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\"><ServiceInformation><ParticipantIdentifier scheme=\"%s\">%s</ParticipantIdentifier><DocumentIdentifier scheme=\"%s\">%s</DocumentIdentifier><ProcessList><Process><ProcessIdentifier scheme=\"cenbii-procid-ubl\">urn:www.cenbii.eu:profile:bii04:ver1.0</ProcessIdentifier><ServiceEndpointList><Endpoint transportProfile=\"bdxr-transport-ebms3-as4-v1p0\"><EndpointURI>http://localhost:8080/domibus-weblogic/services/msh</EndpointURI><RequireBusinessLevelSignature>true</RequireBusinessLevelSignature><ServiceActivationDate>2003-01-01T00:00:00</ServiceActivationDate><ServiceExpirationDate>2020-05-01T00:00:00</ServiceExpirationDate><Certificate>dGVzdHdvcmRz</Certificate><ServiceDescription>Sample description of %s</ServiceDescription><TechnicalContactUrl>https://example.com</TechnicalContactUrl></Endpoint></ServiceEndpointList></Process></ProcessList></ServiceInformation></ServiceMetadata>"; + + public static String getSampleServiceGroupBodyWithScheme(String scheme) { + return getSampleServiceGroupBody(scheme, "urn:poland:ncpb"); + } + + public static String getSampleServiceGroupBody(String scheme, String identifier) { return format("<ServiceGroup xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\">\n" + - " <ParticipantIdentifier scheme=\"%s\">urn:poland:ncpb</ParticipantIdentifier>\n" + + " <ParticipantIdentifier scheme=\"%s\">%s</ParticipantIdentifier>\n" + " <ServiceMetadataReferenceCollection/>\n" + - " </ServiceGroup>", scheme); + " </ServiceGroup>", scheme, identifier); + } + + public static String generateServiceMetadata(String partcId, String partcSch, String docId, String docSch, String desc){ + return String.format(SIMPLE_DOCUMENT_XML,partcSch, partcId,docSch, docId, desc); } } diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTest.java index 0bd193813b481a5fc6297a28a2c14e0257e575f9..4b2c56a7d03909697c55010d695543fc4e9455f0 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTest.java @@ -27,6 +27,7 @@ import org.springframework.test.context.jdbc.SqlConfig; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.transaction.annotation.Transactional; @@ -36,6 +37,8 @@ import org.springframework.web.context.WebApplicationContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import static eu.europa.ec.edelivery.smp.ServiceGroupBodyUtil.generateServiceMetadata; +import static eu.europa.ec.edelivery.smp.ServiceGroupBodyUtil.getSampleServiceGroupBody; import static eu.europa.ec.edelivery.smp.ServiceGroupBodyUtil.getSampleServiceGroupBodyWithScheme; import static java.lang.String.format; import static org.hamcrest.Matchers.stringContainsInOrder; @@ -62,7 +65,13 @@ public class ServiceGroupControllerTest { private static final String PARTICIPANT_SCHEME = "ehealth-participantid-qns"; private static final String PARTICIPANT_ID = "urn:poland:ncpb"; + + private static final String DOCUMENT_SCHEME = "doctype"; + private static final String DOCUMENT_ID = "invoice"; + private static final String URL_PATH = format("/%s::%s", PARTICIPANT_SCHEME, PARTICIPANT_ID); + private static final String URL_DOC_PATH = format("%s/services/%s::%s",URL_PATH, DOCUMENT_SCHEME, DOCUMENT_ID); + private static final String SERVICE_GROUP_INPUT_BODY = getSampleServiceGroupBodyWithScheme(PARTICIPANT_SCHEME); private static final String HTTP_HEADER_KEY_DOMAIN = "Domain"; private static final String HTTP_HEADER_KEY_SERVICE_GROUP_OWNER = "ServiceGroup-Owner"; @@ -138,6 +147,34 @@ public class ServiceGroupControllerTest { } + @Test + public void existingServiceMetadataCanBeRetrievedByEverybody() throws Exception { + + String xmlSG = getSampleServiceGroupBody(PARTICIPANT_SCHEME, PARTICIPANT_ID); + String xmlMD = generateServiceMetadata(PARTICIPANT_ID, PARTICIPANT_SCHEME, DOCUMENT_ID, DOCUMENT_SCHEME, "test"); + // crate service group + mvc.perform(put(URL_PATH) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .content(xmlSG)) + .andExpect(status().isCreated()); + // add service metadata + mvc.perform(put(URL_DOC_PATH) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + + .content(xmlMD)) + .andExpect(status().isCreated()); + + MvcResult mr = mvc.perform(get(URL_PATH).header("X-Forwarded-Host","ec.test.eu") + .header("X-Forwarded-Port","443") + .header("X-Forwarded-Proto","https")).andReturn(); + System.out.println(mr.getResponse().getContentAsString()); + mvc.perform(get(URL_PATH)) + .andExpect(content().xml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ServiceGroup xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\" xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\"><ParticipantIdentifier scheme=\"ehealth-participantid-qns\">urn:poland:ncpb</ParticipantIdentifier><ServiceMetadataReferenceCollection><ServiceMetadataReference href=\"http://localhost/ehealth-participantid-qns%3A%3Aurn%3Apoland%3Ancpb/services/doctype%3A%3Ainvoice\"/></ServiceMetadataReferenceCollection></ServiceGroup>")); + + } + @Test public void anonymousUserCannotCreateServiceGroup() throws Exception { mvc.perform(put(URL_PATH)