diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/SMPPropertyEnum.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/enums/SMPPropertyEnum.java similarity index 98% rename from smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/SMPPropertyEnum.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/enums/SMPPropertyEnum.java index 88cb3e08b00206ee8f73621c1ab496a7ab1af56b..98a4294f7468e8af65df5dd2fc1cde8103136752 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/SMPPropertyEnum.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/enums/SMPPropertyEnum.java @@ -1,4 +1,4 @@ -package eu.europa.ec.edelivery.smp.utils; +package eu.europa.ec.edelivery.smp.data.ui.enums; public enum SMPPropertyEnum { BLUE_COAT_ENABLED ("authentication.blueCoat.enabled","false","Authentication with Blue Coat means that all HTTP requests " + @@ -34,8 +34,6 @@ public enum SMPPropertyEnum { ; - - String property; String defValue; String desc; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainService.java index a890d00a066b78fac19aa0cf63d13f1b8953c803..55ba05e2ff476db5a2cc5c3a56c32a10a49b60c5 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainService.java @@ -4,7 +4,6 @@ import eu.europa.ec.edelivery.smp.data.dao.BaseDao; import eu.europa.ec.edelivery.smp.data.dao.DomainDao; import eu.europa.ec.edelivery.smp.data.model.DBDomain; import eu.europa.ec.edelivery.smp.data.model.DBDomainDeleteValidation; -import eu.europa.ec.edelivery.smp.data.model.DBUserDeleteValidation; import eu.europa.ec.edelivery.smp.data.ui.DeleteEntityValidation; import eu.europa.ec.edelivery.smp.data.ui.DomainRO; import eu.europa.ec.edelivery.smp.data.ui.ServiceResult; @@ -12,7 +11,6 @@ import eu.europa.ec.edelivery.smp.data.ui.enums.EntityROStatus; import eu.europa.ec.edelivery.smp.logging.SMPLogger; import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory; import eu.europa.ec.edelivery.smp.sml.SmlConnector; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional; import java.io.StringWriter; import java.time.LocalDateTime; import java.util.List; -import java.util.Optional; @Service public class UIDomainService extends UIServiceBase<DBDomain, DomainRO> { @@ -49,8 +46,8 @@ public class UIDomainService extends UIServiceBase<DBDomain, DomainRO> { */ @Transactional public ServiceResult<DomainRO> getTableList(int page, int pageSize, - String sortField, - String sortOrder, Object filter) { + String sortField, + String sortOrder, Object filter) { return super.getTableList(page, pageSize, sortField, sortOrder, filter); } @@ -58,7 +55,7 @@ public class UIDomainService extends UIServiceBase<DBDomain, DomainRO> { @Transactional public void updateDomainList(List<DomainRO> lst) { boolean suc = false; - for (DomainRO dRo: lst){ + for (DomainRO dRo : lst) { if (dRo.getStatus() == EntityROStatus.NEW.getStatusNumber()) { DBDomain dDb = convertFromRo(dRo); domainDao.persistFlushDetach(dDb); @@ -80,24 +77,26 @@ public class UIDomainService extends UIServiceBase<DBDomain, DomainRO> { } } - public DeleteEntityValidation validateDeleteRequest(DeleteEntityValidation dev){ - List<DBDomainDeleteValidation> lstMessages = domainDao.validateDomainsForDelete(dev.getListIds()); + public DeleteEntityValidation validateDeleteRequest(DeleteEntityValidation dev) { + List<DBDomainDeleteValidation> lstMessages = domainDao.validateDomainsForDelete(dev.getListIds()); dev.setValidOperation(lstMessages.isEmpty()); - StringWriter sw = new StringWriter(); - sw.write("Could not delete domains used by Service groups! "); - lstMessages.forEach(msg ->{ - dev.getListDeleteNotPermitedIds().add(msg.getId()); - sw.write("Domain: "); - sw.write(msg.getDomainCode()); - sw.write(" ("); - sw.write(msg.getDomainCode()); - sw.write(" )"); - sw.write(" uses by:"); - sw.write( msg.getCount().toString()); - sw.write(" SG."); + if (!dev.isValidOperation()) { + StringWriter sw = new StringWriter(); + sw.write("Could not delete domains used by Service groups! "); + lstMessages.forEach(msg -> { + dev.getListDeleteNotPermitedIds().add(msg.getId()); + sw.write("Domain: "); + sw.write(msg.getDomainCode()); + sw.write(" ("); + sw.write(msg.getDomainCode()); + sw.write(" )"); + sw.write(" uses by:"); + sw.write(msg.getCount().toString()); + sw.write(" SG."); - }); - dev.setStringMessage(sw.toString()); + }); + dev.setStringMessage(sw.toString()); + } return dev; } diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/PropertiesConfig.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/PropertiesConfig.java index a7d8dc5cf49822acda3769f42ee1d503ec4e3d31..cb9bdfb4a5ba043d92c7d864dc99d153b100ee7a 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/PropertiesConfig.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/PropertiesConfig.java @@ -18,7 +18,7 @@ import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import eu.europa.ec.edelivery.smp.logging.SMPLogger; import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory; import eu.europa.ec.edelivery.smp.services.SecurityUtilsServices; -import eu.europa.ec.edelivery.smp.utils.SMPPropertyEnum; +import eu.europa.ec.edelivery.smp.data.ui.enums.SMPPropertyEnum; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.*; diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/DomainResource.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/DomainResource.java index 848123274b7f12df600e2c4e716498fe1e4d4ae9..57a16f3b541c8360d5a95eb2ab605b1b34d0ea53 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/DomainResource.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/DomainResource.java @@ -1,13 +1,10 @@ package eu.europa.ec.edelivery.smp.ui; -import eu.europa.ec.edelivery.smp.auth.SMPAuthenticationToken; import eu.europa.ec.edelivery.smp.auth.SMPAuthority; import eu.europa.ec.edelivery.smp.data.model.DBDomain; -import eu.europa.ec.edelivery.smp.data.model.DBUser; import eu.europa.ec.edelivery.smp.data.ui.DeleteEntityValidation; import eu.europa.ec.edelivery.smp.data.ui.DomainRO; -import eu.europa.ec.edelivery.smp.data.ui.KeystoreImportResult; import eu.europa.ec.edelivery.smp.data.ui.ServiceResult; import eu.europa.ec.edelivery.smp.logging.SMPLogger; import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory; @@ -16,21 +13,10 @@ import eu.europa.ec.edelivery.smp.services.ui.UIDomainService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; -import javax.annotation.PostConstruct; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; import java.util.Arrays; import java.util.List; -import java.util.Optional; /** * @author Joze Rihtarsic @@ -49,10 +35,6 @@ public class DomainResource { @Autowired private DomainService domainService; - @PostConstruct - protected void init() { - - } @PutMapping(produces = {"application/json"}) @ResponseBody @@ -63,14 +45,14 @@ public class DomainResource { @RequestParam(value = "orderBy", required = false) String orderBy, @RequestParam(value = "orderType", defaultValue = "asc", required = false) String orderType, @RequestParam(value = "user", required = false) String user - ) { - return uiDomainService.getTableList(page,pageSize, orderBy, orderType, null ); + ) { + return uiDomainService.getTableList(page, pageSize, orderBy, orderType, null); } @PutMapping(produces = {"application/json"}) @RequestMapping(method = RequestMethod.PUT) @Secured({SMPAuthority.S_AUTHORITY_TOKEN_SYSTEM_ADMIN}) - public void updateDomainList(@RequestBody(required = true) DomainRO [] updateEntities ){ + public void updateDomainList(@RequestBody(required = true) DomainRO[] updateEntities) { LOG.info("GOT LIST OF DomainRO to UPDATE: " + updateEntities.length); uiDomainService.updateDomainList(Arrays.asList(updateEntities)); } @@ -78,7 +60,7 @@ public class DomainResource { @PutMapping(produces = {"application/json"}) @RequestMapping(path = "validateDelete", method = RequestMethod.POST) @Secured({SMPAuthority.S_AUTHORITY_TOKEN_SYSTEM_ADMIN}) - public DeleteEntityValidation validateDeleteUsers(@RequestBody List<Long> query) { + public DeleteEntityValidation validateDeleteDomain(@RequestBody List<Long> query) { DeleteEntityValidation dres = new DeleteEntityValidation(); dres.getListIds().addAll(query); @@ -87,24 +69,24 @@ public class DomainResource { @PostMapping(value = "/{id}/smlregister/{domaincode}") @PreAuthorize("@smpAuthorizationService.systemAdministrator || @smpAuthorizationService.isCurrentlyLoggedIn(#id)") - public void registerDomain(@PathVariable("id") Long id, - @PathVariable("domaincode") String domaincode - ) { + public void registerDomainAndParticipants(@PathVariable("id") Long id, + @PathVariable("domaincode") String domaincode + ) { LOG.info("SML register domain code: {}, user id {}", domaincode, id); // try to open keystore - DBDomain dbDomain = domainService.getDomain(domaincode); + DBDomain dbDomain = domainService.getDomain(domaincode); domainService.registerDomainAndParticipants(dbDomain); } @PostMapping(value = "/{id}/smlunregister/{domaincode}") @PreAuthorize("@smpAuthorizationService.systemAdministrator || @smpAuthorizationService.isCurrentlyLoggedIn(#id)") - public void unregisterDomainAndParticiants(@PathVariable("id") Long id, + public void unregisterDomainAndParticipants(@PathVariable("id") Long id, @PathVariable("domaincode") String domaincode ) { LOG.info("SML unregister domain code: {}, user id {}", domaincode, id); // try to open keystore - DBDomain dbDomain = domainService.getDomain(domaincode); + DBDomain dbDomain = domainService.getDomain(domaincode); domainService.unregisterDomainAndParticipantsFromSml(dbDomain); } } 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 29f00b7ba3ed74e981dfbd0f59508678149a5ee6..8ec0ebce9666ab8f9837c0d7b9c7a4ad3a2831cb 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 @@ -74,7 +74,7 @@ public class ServiceGroupControllerTest { 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"; - private static final String HTTP_DOMAIN = "domain"; + private static final String HTTP_DOMAIN_VALUE = "domain"; private static final String OTHER_OWNER_NAME_URL_ENCODED = "CN=utf-8_%C5%BC_SMP,O=EC,C=BE:0000000000000666"; @@ -112,6 +112,7 @@ public class ServiceGroupControllerTest { public void adminCanCreateServiceGroup() throws Exception { mvc.perform(put(URL_PATH) .with(ADMIN_CREDENTIALS) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .content(SERVICE_GROUP_INPUT_BODY)) .andExpect(status().isCreated()); @@ -120,7 +121,7 @@ public class ServiceGroupControllerTest { @Test public void adminCanUpdateServiceGroup() throws Exception { mvc.perform(put(URL_PATH) - .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .with(ADMIN_CREDENTIALS) .contentType(APPLICATION_XML_VALUE) .content(SERVICE_GROUP_INPUT_BODY)) @@ -128,6 +129,7 @@ public class ServiceGroupControllerTest { mvc.perform(put(URL_PATH) .with(ADMIN_CREDENTIALS) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .content(SERVICE_GROUP_INPUT_BODY)) .andExpect(status().isOk()); @@ -137,6 +139,7 @@ public class ServiceGroupControllerTest { public void existingServiceGroupCanBeRetrievedByEverybody() throws Exception { mvc.perform(put(URL_PATH) .with(ADMIN_CREDENTIALS) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .content(SERVICE_GROUP_INPUT_BODY)) .andExpect(status().isCreated()); @@ -154,11 +157,13 @@ public class ServiceGroupControllerTest { // crate service group mvc.perform(put(URL_PATH) .with(ADMIN_CREDENTIALS) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .content(xmlSG)) .andExpect(status().isCreated()); // add service metadata mvc.perform(put(URL_DOC_PATH) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .with(ADMIN_CREDENTIALS) .contentType(APPLICATION_XML_VALUE) @@ -253,6 +258,7 @@ public class ServiceGroupControllerTest { @Test public void anonymousUserCannotCreateServiceGroup() throws Exception { mvc.perform(put(URL_PATH) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .content(SERVICE_GROUP_INPUT_BODY)) .andExpect(status().isUnauthorized()); @@ -263,8 +269,9 @@ public class ServiceGroupControllerTest { @Test public void adminCanDeleteServiceGroup() throws Exception { - mvc.perform(put(URL_PATH).header("Domain", "domain") + mvc.perform(put(URL_PATH) .with(ADMIN_CREDENTIALS) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .content(SERVICE_GROUP_INPUT_BODY)) .andExpect(status().isCreated()); @@ -280,6 +287,7 @@ public class ServiceGroupControllerTest { public void malformedInputReturnsBadRequest() throws Exception { mvc.perform(put(URL_PATH) .with(ADMIN_CREDENTIALS) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .content("malformed input XML")) .andExpect(status().isBadRequest()); @@ -293,6 +301,7 @@ public class ServiceGroupControllerTest { mvc.perform(put(urlPath) .with(ADMIN_CREDENTIALS) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .content(getSampleServiceGroupBodyWithScheme(scheme))) .andExpect(status().isBadRequest()); @@ -324,6 +333,7 @@ public class ServiceGroupControllerTest { public void adminCanAssignNewServiceGroupToOtherOwner() throws Exception { mvc.perform(put(URL_PATH) .with(ADMIN_CREDENTIALS) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .header(HTTP_HEADER_KEY_SERVICE_GROUP_OWNER, OTHER_OWNER_NAME_URL_ENCODED) .content(SERVICE_GROUP_INPUT_BODY)) @@ -334,6 +344,7 @@ public class ServiceGroupControllerTest { public void adminCannotAssignNewServiceGroupToNotExistingOwner() throws Exception { mvc.perform(put(URL_PATH) .with(ADMIN_CREDENTIALS) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .contentType(APPLICATION_XML_VALUE) .header(HTTP_HEADER_KEY_SERVICE_GROUP_OWNER, "not-existing-user") .content(SERVICE_GROUP_INPUT_BODY)) @@ -345,12 +356,14 @@ public class ServiceGroupControllerTest { String xmlMD = generateServiceMetadata(PARTICIPANT_ID, PARTICIPANT_SCHEME, DOCUMENT_ID, DOCUMENT_SCHEME, "test"); // crate service group mvc.perform(put(URL_PATH) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .with(ADMIN_CREDENTIALS) .contentType(APPLICATION_XML_VALUE) .content(xmlSG)) .andExpect(status().isCreated()); // add service metadata mvc.perform(put(URL_DOC_PATH) + .header(HTTP_HEADER_KEY_DOMAIN, HTTP_DOMAIN_VALUE) .with(ADMIN_CREDENTIALS) .contentType(APPLICATION_XML_VALUE) diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTestSingleDomain.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTestSingleDomain.java new file mode 100644 index 0000000000000000000000000000000000000000..22b6f2329221a3b9834b9692416e08262489b56e --- /dev/null +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerTestSingleDomain.java @@ -0,0 +1,225 @@ +/* + * Copyright 2017 European Commission | CEF eDelivery + * + * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * + * You may obtain a copy of the Licence attached in file: LICENCE-EUPL-v1.2.pdf + * + * Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and limitations under the Licence. + */ + +package eu.europa.ec.edelivery.smp.controllers; + +import eu.europa.ec.edelivery.smp.config.PropertiesTestConfig; +import eu.europa.ec.edelivery.smp.config.SmpAppConfig; +import eu.europa.ec.edelivery.smp.config.SmpWebAppConfig; +import eu.europa.ec.edelivery.smp.config.SpringSecurityConfig; +import eu.europa.ec.edelivery.smp.services.ui.UIKeystoreService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockServletContext; +import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.jdbc.Sql; +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.web.context.ContextLoaderListener; +import org.springframework.web.context.WebApplicationContext; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import static eu.europa.ec.edelivery.smp.ServiceGroupBodyUtil.*; +import static java.lang.String.format; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.springframework.http.MediaType.APPLICATION_XML_VALUE; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * Created by gutowpa on 02/08/2017. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { + PropertiesTestConfig.class, + SmpAppConfig.class, + SmpWebAppConfig.class, + SpringSecurityConfig.class, + UIKeystoreService.class +}) +@WebAppConfiguration +@Sql("classpath:/cleanup-database.sql") +@Sql("classpath:/webapp_integration_test_data_one_domain.sql") +@SqlConfig(encoding = "UTF-8") +public class ServiceGroupControllerTestSingleDomain { + + 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"; + + + private static final String OTHER_OWNER_NAME_URL_ENCODED = "CN=utf-8_%C5%BC_SMP,O=EC,C=BE:0000000000000666"; + + private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("smp_admin", "test123"); + + @Autowired + private WebApplicationContext webAppContext; + + private MockMvc mvc; + + @Before + public void setup() { + mvc = MockMvcBuilders.webAppContextSetup(webAppContext) + .apply(SecurityMockMvcConfigurers.springSecurity()) + .build(); + + initServletContext(); + } + + private void initServletContext() { + MockServletContext sc = new MockServletContext(""); + ServletContextListener listener = new ContextLoaderListener(webAppContext); + ServletContextEvent event = new ServletContextEvent(sc); + listener.contextInitialized(event); + } + + @Test + public void adminCanCreateServiceGroupNoDomain() throws Exception { + mvc.perform(put(URL_PATH) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .content(SERVICE_GROUP_INPUT_BODY)) + .andExpect(status().isCreated()); + } + + @Test + public void adminCanUpdateServiceGroupNoDomain() throws Exception { + mvc.perform(put(URL_PATH) + + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .content(SERVICE_GROUP_INPUT_BODY)) + .andExpect(status().isCreated()); + + mvc.perform(put(URL_PATH) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .content(SERVICE_GROUP_INPUT_BODY)) + .andExpect(status().isOk()); + } + + + @Test + public void existingServiceMetadataCanBeRetrievedByEverybodyNoDomain() 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) + .contentType(APPLICATION_XML_VALUE) + .content(SERVICE_GROUP_INPUT_BODY)) + .andExpect(status().isUnauthorized()); + + mvc.perform(get(URL_PATH)) + .andExpect(status().isNotFound()); + } + + @Test + public void malformedInputReturnsBadRequestNoDomain() throws Exception { + mvc.perform(put(URL_PATH) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .content("malformed input XML")) + .andExpect(status().isBadRequest()); + } + + @Test + public void invalidParticipantSchemeReturnsBadRequestNoDomain() throws Exception { + + String scheme = "length-exceeeeeeds-25chars"; + String urlPath = format("/%s::%s", scheme, PARTICIPANT_ID); + + mvc.perform(put(urlPath) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .content(getSampleServiceGroupBodyWithScheme(scheme))) + .andExpect(status().isBadRequest()); + } + + @Test + public void creatingServiceGroupUnderBadFormatedDomainReturnsBadRequestNoDomain() throws Exception { + mvc.perform(put(URL_PATH) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .header(HTTP_HEADER_KEY_DOMAIN, "not-existing-domain") + .content(SERVICE_GROUP_INPUT_BODY)) + .andExpect(status().isBadRequest()) + .andExpect(content().string(stringContainsInOrder("FORMAT_ERROR"))); + } + + @Test + public void creatingServiceGroupUnderNotExistingDomainReturnsBadRequestNoDomain() throws Exception { + mvc.perform(put(URL_PATH) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .header(HTTP_HEADER_KEY_DOMAIN, "notExistingDomain") + .content(SERVICE_GROUP_INPUT_BODY)) + .andExpect(status().isNotFound()) + .andExpect(content().string(stringContainsInOrder("NOT_FOUND"))); + } + + @Test + public void adminCanAssignNewServiceGroupToOtherOwnerNoDomain() throws Exception { + mvc.perform(put(URL_PATH) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .header(HTTP_HEADER_KEY_SERVICE_GROUP_OWNER, OTHER_OWNER_NAME_URL_ENCODED) + .content(SERVICE_GROUP_INPUT_BODY)) + .andExpect(status().isCreated()); + } +} diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/DomainResourceTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/DomainResourceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..3c091601d1b7ca250c2fa3a06e92bae4ad693c77 --- /dev/null +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/DomainResourceTest.java @@ -0,0 +1,212 @@ +package eu.europa.ec.edelivery.smp.ui; + +import com.fasterxml.jackson.databind.ObjectMapper; +import eu.europa.ec.edelivery.smp.config.*; +import eu.europa.ec.edelivery.smp.data.dao.DomainDao; +import eu.europa.ec.edelivery.smp.data.ui.DeleteEntityValidation; +import eu.europa.ec.edelivery.smp.data.ui.DomainRO; +import eu.europa.ec.edelivery.smp.data.ui.ServiceResult; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockServletContext; +import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.jdbc.Sql; +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.web.context.ContextLoaderListener; +import org.springframework.web.context.WebApplicationContext; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.Assert.*; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { + PropertiesTestConfig.class, + SmpAppConfig.class, + SmpWebAppConfig.class, + SpringSecurityConfig.class}) +@WebAppConfiguration +@Sql("classpath:/cleanup-database.sql") +@Sql("classpath:/webapp_integration_test_data.sql") +@SqlConfig(encoding = "UTF-8") +@TestPropertySource(properties = { + "smp.artifact.name=TestApplicationSmpName", + "smp.artifact.version=TestApplicationVersion", + "smp.artifact.build.time=2018-11-27 00:00:00", + "bdmsl.integration.enabled=false"}) +public class DomainResourceTest { + private static final String PATH = "/ui/rest/domain"; + + @Autowired + private WebApplicationContext webAppContext; + + + @Autowired + DomainDao domainDao; + + private MockMvc mvc; + private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("smp_admin", "test123"); + private static final RequestPostProcessor SYSTEM_CREDENTIALS = httpBasic("sys_admin", "test123"); + + @Before + public void setup() { + mvc = MockMvcBuilders.webAppContextSetup(webAppContext) + .apply(SecurityMockMvcConfigurers.springSecurity()) + .build(); + + initServletContext(); + } + + private void initServletContext() { + MockServletContext sc = new MockServletContext(""); + ServletContextListener listener = new ContextLoaderListener(webAppContext); + ServletContextEvent event = new ServletContextEvent(sc); + } + + + @Test + public void geDomainList() throws Exception { + + // given when + MvcResult result = mvc.perform(get(PATH).with(SYSTEM_CREDENTIALS)). + andExpect(status().isOk()).andReturn(); + + //them + ObjectMapper mapper = new ObjectMapper(); + ServiceResult res = mapper.readValue(result.getResponse().getContentAsString(), ServiceResult.class); + + + assertNotNull(res); + assertEquals(2, res.getServiceEntities().size()); + res.getServiceEntities().forEach(sgMap -> { + DomainRO sgro = mapper.convertValue(sgMap, DomainRO.class); + assertNotNull(sgro.getId()); + assertNotNull(sgro.getDomainCode()); + assertNotNull(sgro.getSmlSmpId()); + }); + } + + @Test + public void updateDomainListOkDelete() throws Exception { +// given when + assertEquals("CEF-SMP-002", domainDao.getDomainByCode("domainTwo").get().getSmlSmpId()); + + MvcResult result = mvc.perform(put(PATH ) + .with(SYSTEM_CREDENTIALS) + .header("Content-Type", " application/json") + .content("[{\"status\":3,\"index\":9,\"id\":2,\"domainCode\":\"domainTwo\",\"smlSubdomain\":\"newdomain\",\"smlSmpId\":\"CEF-SMP-010\",\"smlParticipantIdentifierRegExp\":null,\"smlClientCertHeader\":null,\"smlClientKeyAlias\":null,\"signatureKeyAlias\":\"sig-key\",\"smlBlueCoatAuth\":true,\"smlRegistered\":false,\"deleted\":true}]")) // delete domain with id 2 + .andExpect(status().isOk()).andReturn(); + + // check if exists + assertFalse(domainDao.getDomainByCode("domainTwo").isPresent()); + } + + + @Test + public void updateDomainListNotExists() throws Exception { +// given when + MvcResult result = mvc.perform(put(PATH ) + .with(SYSTEM_CREDENTIALS) + .header("Content-Type", " application/json") + .content("[{\"status\":3,\"index\":9,\"id\":10,\"domainCode\":\"domainTwoNotExist\",\"smlSubdomain\":\"newdomain\",\"smlSmpId\":\"CEF-SMP-010\",\"smlParticipantIdentifierRegExp\":null,\"smlClientCertHeader\":null,\"smlClientKeyAlias\":null,\"signatureKeyAlias\":\"sig-key\",\"smlBlueCoatAuth\":true,\"smlRegistered\":false,\"deleted\":true}]")) // delete domain with id 2 + .andExpect(status().isOk()).andReturn(); + } + + @Test + public void validateDeleteDomainOK() throws Exception { + // given when + MvcResult result = mvc.perform(post(PATH + "/validateDelete") + .with(SYSTEM_CREDENTIALS) + .header("Content-Type", " application/json") + .content("[2]")) // delete domain with id 2 + .andExpect(status().isOk()).andReturn(); + + //them + ObjectMapper mapper = new ObjectMapper(); + DeleteEntityValidation res = mapper.readValue(result.getResponse().getContentAsString(), DeleteEntityValidation.class); + + assertNotNull(res); + assertTrue(res.getListDeleteNotPermitedIds().isEmpty()); + assertEquals(1, res.getListIds().size()); + assertEquals(true, res.isValidOperation()); + assertNull(res.getStringMessage()); + } + + @Test + public void updateDomainListOkUpdate() throws Exception { +// given when + assertEquals("CEF-SMP-002", domainDao.getDomainByCode("domainTwo").get().getSmlSmpId()); + + MvcResult result = mvc.perform(put(PATH ) + .with(SYSTEM_CREDENTIALS) + .header("Content-Type", " application/json") + .content("[{\"status\":1,\"index\":9,\"id\":2,\"domainCode\":\"domainTwo\",\"smlSubdomain\":\"newdomain\",\"smlSmpId\":\"CEF-SMP-010\",\"smlParticipantIdentifierRegExp\":null,\"smlClientCertHeader\":null,\"smlClientKeyAlias\":null,\"signatureKeyAlias\":\"sig-key\",\"smlBlueCoatAuth\":true,\"smlRegistered\":false,\"deleted\":true}]")) // delete domain with id 2 + .andExpect(status().isOk()).andReturn(); + + // check if exists + assertEquals("CEF-SMP-010", domainDao.getDomainByCode("domainTwo").get().getSmlSmpId()); + + } + @Test + public void validateDeleteDomainFalse() throws Exception { + // given when + MvcResult result = mvc.perform(post(PATH + "/validateDelete") + .with(SYSTEM_CREDENTIALS) + .header("Content-Type", " application/json") + .content("[1]")) // delete domain with id 2 + .andExpect(status().isOk()).andReturn(); + + //them + ObjectMapper mapper = new ObjectMapper(); + DeleteEntityValidation res = mapper.readValue(result.getResponse().getContentAsString(), DeleteEntityValidation.class); + + assertNotNull(res); + assertEquals(1, res.getListDeleteNotPermitedIds().size()); + assertEquals(1, res.getListIds().size()); + assertEquals(false, res.isValidOperation()); + assertEquals("Could not delete domains used by Service groups! Domain: domain (domain ) uses by:2 SG.",res.getStringMessage()); + } + + @Test + public void registerDomainAndParticipantsNotEnabled() throws Exception { + // given when + // 3- user id + // domainTwo - domain code + mvc.perform(post(PATH + "/3/smlregister/domainTwo") + .with(SYSTEM_CREDENTIALS) + .header("Content-Type", " application/json")) + .andExpect(status().is5xxServerError()) + .andExpect(content().string(stringContainsInOrder("Configuration error: SML integration is not enabled!!"))); + } + + @Test + public void unregisterDomainAndParticipants() throws Exception { + // given when + // 3- user id + // domainTwo - domain code + mvc.perform(post(PATH + "/3/smlunregister/domainTwo") + .with(SYSTEM_CREDENTIALS) + .header("Content-Type", " application/json")) + .andExpect(status().is5xxServerError()) + .andExpect(content().string(stringContainsInOrder("Configuration error: SML integration is not enabled!!"))); + } +} \ No newline at end of file diff --git a/smp-webapp/src/test/resources/webapp_integration_test_data.sql b/smp-webapp/src/test/resources/webapp_integration_test_data.sql index 24e22eca4769ba8785d6bb14ebacca4529c3f51d..41c2207924e07cde206e09ad4228f6a999d24985 100644 --- a/smp-webapp/src/test/resources/webapp_integration_test_data.sql +++ b/smp-webapp/src/test/resources/webapp_integration_test_data.sql @@ -35,7 +35,9 @@ insert into SMP_SERVICE_GROUP(ID, PARTICIPANT_IDENTIFIER, PARTICIPANT_SCHEME, CR insert into SMP_OWNERSHIP (FK_SG_ID, FK_USER_ID) values (100000, 4); insert into SMP_OWNERSHIP (FK_SG_ID, FK_USER_ID) values (200000, 2); -insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS,SML_REGISTERED,SML_BLUE_COAT_AUTH, CREATED_ON, LAST_UPDATED_ON) values (1, 'domain','subdomain', 'CEF-SMP-001','single_domain_key',0,1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS,SML_REGISTERED,SML_BLUE_COAT_AUTH,SML_CLIENT_CERT_HEADER, CREATED_ON, LAST_UPDATED_ON) values (1, 'domain','subdomain', 'CEF-SMP-001','single_domain_key',0,1,'SML_CLIENT_CERT_HEADER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS,SML_REGISTERED,SML_BLUE_COAT_AUTH,SML_CLIENT_CERT_HEADER, CREATED_ON, LAST_UPDATED_ON) values (2, 'domainTwo','newdomain', 'CEF-SMP-002','single_domain_key',0,1,'SML_CLIENT_CERT_HEADER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + insert into SMP_SERVICE_GROUP_DOMAIN (ID, FK_SG_ID, FK_DOMAIN_ID,SML_REGISTERED, CREATED_ON, LAST_UPDATED_ON) values (1000,200000, 1, 0, CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); diff --git a/smp-webapp/src/test/resources/webapp_integration_test_data_one_domain.sql b/smp-webapp/src/test/resources/webapp_integration_test_data_one_domain.sql new file mode 100644 index 0000000000000000000000000000000000000000..f384141f2c82af4aa12f6e691127a2d051858f82 --- /dev/null +++ b/smp-webapp/src/test/resources/webapp_integration_test_data_one_domain.sql @@ -0,0 +1,46 @@ +-- Copyright 2018 European Commission | CEF eDelivery +-- +-- Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"); +-- You may not use this work except in compliance with the Licence. +-- +-- You may obtain a copy of the Licence attached in file: LICENCE-EUPL-v1.2.pdf +-- +-- Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (1, 'smp_admin', '$2a$06$AXSSUDJlpzzq/gPZb7eIBeb8Mi0.PTKqDjzujZH.bWPwj5.ePEInW', 'SMP_ADMIN', 1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (2, 'sg_admin', '$2a$06$AXSSUDJlpzzq/gPZb7eIBeb8Mi0.PTKqDjzujZH.bWPwj5.ePEInW', 'SERVICE_GROUP_ADMIN', 1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (3, 'sys_admin', '$2a$06$AXSSUDJlpzzq/gPZb7eIBeb8Mi0.PTKqDjzujZH.bWPwj5.ePEInW', 'SYSTEM_ADMIN', 1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +insert into SMP_USER(ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (4, 'test_user_hashed_pass', '$2a$06$AXSSUDJlpzzq/gPZb7eIBeb8Mi0.PTKqDjzujZH.bWPwj5.ePEInW', 'SERVICE_GROUP_ADMIN',1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_USER(ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (5, 'test_user_clear_pass', 'test123', 'SERVICE_GROUP_ADMIN',1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_USER(ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (6, 'cert1', '', 'SMP_ADMIN', 1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO, CREATED_ON, LAST_UPDATED_ON) values (6, 'CN=comon name,O=org,C=BE:0000000000000066', null,null,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +insert into SMP_USER(ID, USERNAME, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (7, 'cert2', 'SMP_ADMIN', 1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO, CREATED_ON, LAST_UPDATED_ON) values (7, 'CN=EHEALTH_SMP_TEST_BRAZIL,O=European Commission,C=BE:48b681ee8e0dcc08', null,null,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +insert into SMP_USER(ID, USERNAME, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (8, 'Cert3', 'SMP_ADMIN', 1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO, CREATED_ON, LAST_UPDATED_ON) values (8, 'CN=utf-8_ż_SMP,O=EC,C=BE:0000000000000666', null,null,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +insert into SMP_USER(ID, USERNAME, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (9, 'Cert4', 'SMP_ADMIN', 1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO, CREATED_ON, LAST_UPDATED_ON) values (9, 'CN=EHEALTH_SMP_EC,O=European Commission,C=BEf71ee8b11cb3b787', null,null,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + + +-- set the ids to higher values - tests are using sequnce which stars from 1 +insert into SMP_SERVICE_GROUP(ID, PARTICIPANT_IDENTIFIER, PARTICIPANT_SCHEME, CREATED_ON, LAST_UPDATED_ON) values (100000, 'urn:australia:ncpb', 'ehealth-actorid-qns', CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_SERVICE_GROUP(ID, PARTICIPANT_IDENTIFIER, PARTICIPANT_SCHEME, CREATED_ON, LAST_UPDATED_ON) values (200000, 'urn:brazil:ncpb', 'ehealth-actorid-qns', CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +-- set ownership +insert into SMP_OWNERSHIP (FK_SG_ID, FK_USER_ID) values (100000, 4); +insert into SMP_OWNERSHIP (FK_SG_ID, FK_USER_ID) values (200000, 2); + +insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS,SML_REGISTERED,SML_BLUE_COAT_AUTH, CREATED_ON, LAST_UPDATED_ON) values (1, 'domain','subdomain', 'CEF-SMP-001','single_domain_key',0,1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + + +insert into SMP_SERVICE_GROUP_DOMAIN (ID, FK_SG_ID, FK_DOMAIN_ID,SML_REGISTERED, CREATED_ON, LAST_UPDATED_ON) values (1000,200000, 1, 0, CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +insert into SMP_SERVICE_GROUP_DOMAIN (ID, FK_SG_ID, FK_DOMAIN_ID,SML_REGISTERED, CREATED_ON, LAST_UPDATED_ON) values (1001,100000, 1, 0 ,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); +insert into SMP_SERVICE_METADATA (ID, FK_SG_DOM_ID, DOCUMENT_IDENTIFIER, DOCUMENT_SCHEME, LAST_UPDATED_ON, CREATED_ON) values (1000,1001,'doc_7','busdox-docid-qns',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +