From d40ca5642c1037cc8ad846104b39bae17e1c6010 Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Wed, 13 Aug 2025 23:32:48 +0300 Subject: [PATCH 1/5] yamls changed --- src/main/resources/application-testing.yml | 8 ++++++++ src/main/resources/application.yml | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/resources/application-testing.yml b/src/main/resources/application-testing.yml index 1c08e30a..a92f3339 100644 --- a/src/main/resources/application-testing.yml +++ b/src/main/resources/application-testing.yml @@ -200,6 +200,14 @@ EVENT_PRODUCT_OFFERING_PRICE_DELETE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.DELET EVENT_PRODUCT_OFFERING_PRICE_ATTRIBUTE_VALUE_CHANGE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.ATTRCHANGED" EVENT_PRODUCT_OFFERING_PRICE_STATE_CHANGE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.STATECHANGED" +EVENT_SERVICE_CATALOG_CREATE: "jms:topic:EVENT.SERVICECATALOG.CREATE" +EVENT_SERVICE_CATALOG_DELETE: "jms:topic:EVENT.SERVICECATALOG.DELETE" +EVENT_SERVICE_CATEGORY_CREATE: "jms:topic:EVENT.SERVICECATEGORY.CREATE" +EVENT_SERVICE_CATEGORY_DELETE: "jms:topic:EVENT.SERVICECATEGORY.DELETE" +EVENT_SERVICE_SPECIFICATION_CREATE: "jms:topic:EVENT.SERVICESPECIFICATION.CREATE" +EVENT_SERVICE_SPECIFICATION_DELETE: "jms:topic:EVENT.SERVICESPECIFICATION.DELETE" +EVENT_SERVICE_SPECIFICATION_CHANGE: "jms:topic:EVENT.SERVICESPECIFICATION.CHANGE" + #QUEUE MESSSAGES WITH VNFNSD CATALOG NFV_CATALOG_GET_NSD_BY_ID: "jms:queue:NFVCATALOG.GET.NSD_BY_ID" diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2cf3438a..30bccc8b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -225,6 +225,14 @@ EVENT_PRODUCT_OFFERING_PRICE_DELETE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.DELET EVENT_PRODUCT_OFFERING_PRICE_ATTRIBUTE_VALUE_CHANGE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.ATTRCHANGED" EVENT_PRODUCT_OFFERING_PRICE_STATE_CHANGE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.STATECHANGED" +EVENT_SERVICE_CATALOG_CREATE: "jms:topic:EVENT.SERVICECATALOG.CREATE" +EVENT_SERVICE_CATALOG_DELETE: "jms:topic:EVENT.SERVICECATALOG.DELETE" +EVENT_SERVICE_CATEGORY_CREATE: "jms:topic:EVENT.SERVICECATEGORY.CREATE" +EVENT_SERVICE_CATEGORY_DELETE: "jms:topic:EVENT.SERVICECATEGORY.DELETE" +EVENT_SERVICE_SPECIFICATION_CREATE: "jms:topic:EVENT.SERVICESPECIFICATION.CREATE" +EVENT_SERVICE_SPECIFICATION_DELETE: "jms:topic:EVENT.SERVICESPECIFICATION.DELETE" +EVENT_SERVICE_SPECIFICATION_CHANGE: "jms:topic:EVENT.SERVICESPECIFICATION.CHANGE" + #QUEUE MESSSAGES WITH VNFNSD CATALOG NFV_CATALOG_GET_NSD_BY_ID: "jms:queue:NFVCATALOG.GET.NSD_BY_ID" -- GitLab From 68e920d5d7b235d0bf52215af132067b4878c730 Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Wed, 13 Aug 2025 23:35:23 +0300 Subject: [PATCH 2/5] scm633 hubApi with repo implementation --- .../org/etsi/osl/tmf/scm633/api/HubApi.java | 13 ++++ .../osl/tmf/scm633/api/HubApiController.java | 60 ++++++++++++---- .../repo/EventSubscriptionRepository.java | 37 ++++++++++ .../EventSubscriptionRepoService.java | 72 +++++++++++++++++++ .../api/scm633/HubApiControllerTest.java | 6 +- 5 files changed, 173 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/etsi/osl/tmf/scm633/repo/EventSubscriptionRepository.java create mode 100644 src/main/java/org/etsi/osl/tmf/scm633/reposervices/EventSubscriptionRepoService.java diff --git a/src/main/java/org/etsi/osl/tmf/scm633/api/HubApi.java b/src/main/java/org/etsi/osl/tmf/scm633/api/HubApi.java index cd7d1306..1f0678cb 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/api/HubApi.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/api/HubApi.java @@ -27,6 +27,7 @@ package org.etsi.osl.tmf.scm633.api; import org.etsi.osl.tmf.scm633.model.EventSubscription; import org.etsi.osl.tmf.scm633.model.EventSubscriptionInput; import org.springframework.http.ResponseEntity; +import java.util.List; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -74,4 +75,16 @@ public interface HubApi { method = RequestMethod.DELETE) ResponseEntity unregisterListener(@Parameter(description = "The id of the registered listener",required=true) @PathVariable("id") String id); + @Operation(summary = "Get all registered listeners", operationId = "getListeners", description = "Retrieves all registered event subscriptions", tags={ "events subscription", }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Success" ), + @ApiResponse(responseCode = "400", description = "Bad Request" ), + @ApiResponse(responseCode = "401", description = "Unauthorized" ), + @ApiResponse(responseCode = "403", description = "Forbidden" ), + @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) + @RequestMapping(value = "/hub", + produces = { "application/json;charset=utf-8" }, + method = RequestMethod.GET) + ResponseEntity> getListeners(); + } diff --git a/src/main/java/org/etsi/osl/tmf/scm633/api/HubApiController.java b/src/main/java/org/etsi/osl/tmf/scm633/api/HubApiController.java index 2d7ec59a..ce6adb20 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/api/HubApiController.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/api/HubApiController.java @@ -20,18 +20,24 @@ package org.etsi.osl.tmf.scm633.api; import java.io.IOException; +import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; import org.etsi.osl.tmf.scm633.model.EventSubscription; import org.etsi.osl.tmf.scm633.model.EventSubscriptionInput; +import org.etsi.osl.tmf.scm633.reposervices.EventSubscriptionRepoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import io.swagger.v3.oas.annotations.Parameter; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; @@ -46,6 +52,10 @@ public class HubApiController implements HubApi { private final ObjectMapper objectMapper; private final HttpServletRequest request; + + @Autowired + @Qualifier("scm633EventSubscriptionRepoService") + EventSubscriptionRepoService eventSubscriptionRepoService; @org.springframework.beans.factory.annotation.Autowired public HubApiController(ObjectMapper objectMapper, HttpServletRequest request) { @@ -53,23 +63,49 @@ public class HubApiController implements HubApi { this.request = request; } + @Override + @PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_USER')") public ResponseEntity registerListener(@Parameter(description = "Data containing the callback endpoint to deliver the information" ,required=true ) @Valid @RequestBody EventSubscriptionInput data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + EventSubscription eventSubscription = eventSubscriptionRepoService.addEventSubscription(data); + return new ResponseEntity<>(eventSubscription, HttpStatus.CREATED); + } catch (IllegalArgumentException e) { + log.error("Invalid input for listener registration: {}", e.getMessage()); + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } catch (Exception e) { + log.error("Error registering listener", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override + @PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_USER')") + @RequestMapping(value = "/hub/{id}", method = RequestMethod.DELETE, produces = { "application/json;charset=utf-8" }) public ResponseEntity unregisterListener(@Parameter(description = "The id of the registered listener",required=true) @PathVariable("id") String id) { - String accept = request.getHeader("Accept"); - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); + try { + EventSubscription existing = eventSubscriptionRepoService.findById(id); + if (existing == null) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + eventSubscriptionRepoService.deleteById(id); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } catch (Exception e) { + log.error("Error unregistering listener with id: " + id, e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @Override + @PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_USER')") + public ResponseEntity> getListeners() { + try { + List eventSubscriptions = eventSubscriptionRepoService.findAll(); + return new ResponseEntity<>(eventSubscriptions, HttpStatus.OK); + } catch (Exception e) { + log.error("Error retrieving listeners", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } } } diff --git a/src/main/java/org/etsi/osl/tmf/scm633/repo/EventSubscriptionRepository.java b/src/main/java/org/etsi/osl/tmf/scm633/repo/EventSubscriptionRepository.java new file mode 100644 index 00000000..732bd912 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/scm633/repo/EventSubscriptionRepository.java @@ -0,0 +1,37 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.tmf.api + * %% + * Copyright (C) 2019 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.tmf.scm633.repo; + +import java.util.List; +import java.util.Optional; +import org.etsi.osl.tmf.scm633.model.EventSubscription; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.stereotype.Repository; + +@Repository("scm633EventSubscriptionRepository") +public interface EventSubscriptionRepository extends CrudRepository, PagingAndSortingRepository { + + Optional findById(String id); + + void deleteById(String id); + + List findAll(); +} \ No newline at end of file diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/EventSubscriptionRepoService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/EventSubscriptionRepoService.java new file mode 100644 index 00000000..b47eb549 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/EventSubscriptionRepoService.java @@ -0,0 +1,72 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.tmf.api + * %% + * Copyright (C) 2019 - 2021 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.tmf.scm633.reposervices; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import org.etsi.osl.tmf.scm633.model.EventSubscription; +import org.etsi.osl.tmf.scm633.model.EventSubscriptionInput; +import org.etsi.osl.tmf.scm633.repo.EventSubscriptionRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import jakarta.validation.Valid; + +@Service("scm633EventSubscriptionRepoService") +@Transactional +public class EventSubscriptionRepoService { + + @Autowired + @Qualifier("scm633EventSubscriptionRepository") + EventSubscriptionRepository eventSubscriptionRepo; + + public EventSubscription addEventSubscription(@Valid EventSubscriptionInput eventSubscriptionInput) { + if (eventSubscriptionInput.getCallback() == null || eventSubscriptionInput.getCallback().trim().isEmpty()) { + throw new IllegalArgumentException("Callback URL is required and cannot be empty"); + } + + EventSubscription eventSubscription = new EventSubscription(); + eventSubscription.setId(UUID.randomUUID().toString()); + eventSubscription.setCallback(eventSubscriptionInput.getCallback()); + eventSubscription.setQuery(eventSubscriptionInput.getQuery()); + + return this.eventSubscriptionRepo.save(eventSubscription); + } + + public EventSubscription findById(String id) { + Optional optionalEventSubscription = this.eventSubscriptionRepo.findById(id); + return optionalEventSubscription.orElse(null); + } + + public void deleteById(String id) { + Optional optionalEventSubscription = this.eventSubscriptionRepo.findById(id); + if (optionalEventSubscription.isPresent()) { + this.eventSubscriptionRepo.delete(optionalEventSubscription.get()); + } + } + + public List findAll() { + return (List) this.eventSubscriptionRepo.findAll(); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java index db51361f..84e40bd6 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java @@ -70,14 +70,14 @@ public class HubApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( eventSubscriptionInput ) )) - .andExpect(status().is(501)); + .andExpect(status().isCreated()); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/hub") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( eventSubscriptionInput ) )) - .andExpect(status().is(501)); + .andExpect(status().isCreated()); } @@ -89,6 +89,6 @@ public class HubApiControllerTest { .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); + .andExpect(status().isNotFound()); } } \ No newline at end of file -- GitLab From 0807e1289ea6cbdfb70c7c33e6e208829206e80d Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Thu, 14 Aug 2025 00:19:53 +0300 Subject: [PATCH 3/5] fix for #84 --- .../ServiceCatalogApiRouteBuilderEvents.java | 164 ++++++++ .../reposervices/CatalogRepoService.java | 20 +- .../reposervices/CategoryRepoService.java | 32 +- .../ServiceCatalogCallbackService.java | 362 ++++++++++++++++++ .../ServiceCatalogNotificationService.java | 129 +++++++ .../ServiceCategoryNotificationService.java | 129 +++++++ ...rviceSpecificationNotificationService.java | 171 +++++++++ .../ServiceSpecificationRepoService.java | 10 +- ...rviceCatalogApiRouteBuilderEventsTest.java | 248 ++++++++++++ ...iceCatalogCallbackServiceExtendedTest.java | 248 ++++++++++++ ...logManagementNotificationEndToEndTest.java | 307 +++++++++++++++ ...ceCategoryNotificationIntegrationTest.java | 150 ++++++++ ...erviceCategoryNotificationServiceTest.java | 102 +++++ ...cificationNotificationIntegrationTest.java | 199 ++++++++++ ...eSpecificationNotificationServiceTest.java | 134 +++++++ .../resources/testEventSubscriptionInput.json | 1 + 16 files changed, 2390 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilderEvents.java create mode 100644 src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogCallbackService.java create mode 100644 src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogNotificationService.java create mode 100644 src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCategoryNotificationService.java create mode 100644 src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationNotificationService.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiRouteBuilderEventsTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogCallbackServiceExtendedTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogManagementNotificationEndToEndTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryNotificationIntegrationTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryNotificationServiceTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationNotificationIntegrationTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationNotificationServiceTest.java diff --git a/src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilderEvents.java b/src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilderEvents.java new file mode 100644 index 00000000..7ac8e2be --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilderEvents.java @@ -0,0 +1,164 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.tmf.api + * %% + * Copyright (C) 2019 - 2020 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.tmf.scm633.api; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; + +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.etsi.osl.centrallog.client.CLevel; +import org.etsi.osl.centrallog.client.CentralLogger; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogDeleteNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeNotification; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; + +@Component +public class ServiceCatalogApiRouteBuilderEvents extends RouteBuilder { + + private static final transient Log logger = LogFactory.getLog(ServiceCatalogApiRouteBuilderEvents.class.getName()); + + @Value("${EVENT_SERVICE_CATALOG_CREATE}") + private String EVENT_SERVICE_CATALOG_CREATE = "direct:EVENT_SERVICE_CATALOG_CREATE"; + + @Value("${EVENT_SERVICE_CATALOG_DELETE}") + private String EVENT_SERVICE_CATALOG_DELETE = "direct:EVENT_SERVICE_CATALOG_DELETE"; + + @Value("${EVENT_SERVICE_CATEGORY_CREATE}") + private String EVENT_SERVICE_CATEGORY_CREATE = "direct:EVENT_SERVICE_CATEGORY_CREATE"; + + @Value("${EVENT_SERVICE_CATEGORY_DELETE}") + private String EVENT_SERVICE_CATEGORY_DELETE = "direct:EVENT_SERVICE_CATEGORY_DELETE"; + + @Value("${EVENT_SERVICE_SPECIFICATION_CREATE}") + private String EVENT_SERVICE_SPECIFICATION_CREATE = "direct:EVENT_SERVICE_SPECIFICATION_CREATE"; + + @Value("${EVENT_SERVICE_SPECIFICATION_DELETE}") + private String EVENT_SERVICE_SPECIFICATION_DELETE = "direct:EVENT_SERVICE_SPECIFICATION_DELETE"; + + @Value("${EVENT_SERVICE_SPECIFICATION_CHANGE}") + private String EVENT_SERVICE_SPECIFICATION_CHANGE = "direct:EVENT_SERVICE_SPECIFICATION_CHANGE"; + + @Autowired + private ApplicationContext context; + + @Autowired + private ProducerTemplate template; + + + @Autowired + private CentralLogger centralLogger; + + @Override + public void configure() throws Exception { + + } + + public void publishEvent(Object notification, String objId) { + + try { + String msgtopic = ""; + + if (notification instanceof ServiceCatalogCreateNotification) { + msgtopic = EVENT_SERVICE_CATALOG_CREATE; + } else if (notification instanceof ServiceCatalogDeleteNotification) { + msgtopic = EVENT_SERVICE_CATALOG_DELETE; + } else if (notification instanceof ServiceCategoryCreateNotification) { + msgtopic = EVENT_SERVICE_CATEGORY_CREATE; + } else if (notification instanceof ServiceCategoryDeleteNotification) { + msgtopic = EVENT_SERVICE_CATEGORY_DELETE; + } else if (notification instanceof ServiceSpecificationCreateNotification) { + msgtopic = EVENT_SERVICE_SPECIFICATION_CREATE; + } else if (notification instanceof ServiceSpecificationDeleteNotification) { + msgtopic = EVENT_SERVICE_SPECIFICATION_DELETE; + } else if (notification instanceof ServiceSpecificationChangeNotification) { + msgtopic = EVENT_SERVICE_SPECIFICATION_CHANGE; + } + + Map map = new HashMap<>(); + String eventId = null; + + if (notification instanceof ServiceCatalogCreateNotification) { + eventId = ((ServiceCatalogCreateNotification) notification).getEventId(); + } else if (notification instanceof ServiceCatalogDeleteNotification) { + eventId = ((ServiceCatalogDeleteNotification) notification).getEventId(); + } else if (notification instanceof ServiceCategoryCreateNotification) { + eventId = ((ServiceCategoryCreateNotification) notification).getEventId(); + } else if (notification instanceof ServiceCategoryDeleteNotification) { + eventId = ((ServiceCategoryDeleteNotification) notification).getEventId(); + } else if (notification instanceof ServiceSpecificationCreateNotification) { + eventId = ((ServiceSpecificationCreateNotification) notification).getEventId(); + } else if (notification instanceof ServiceSpecificationDeleteNotification) { + eventId = ((ServiceSpecificationDeleteNotification) notification).getEventId(); + } else if (notification instanceof ServiceSpecificationChangeNotification) { + eventId = ((ServiceSpecificationChangeNotification) notification).getEventId(); + } + + map.put("eventid", eventId); + map.put("objId", objId); + + String apayload = toJsonString(notification); + map.put("event", apayload); + + template.sendBodyAndHeaders(msgtopic, apayload, map); + + String msgtxt = "EVENT " + notification.getClass().getName() + " sent"; + logger.info(msgtxt); + centralLogger.log(CLevel.INFO, msgtxt, compname()); + + } catch (Exception e) { + e.printStackTrace(); + logger.error("Cannot send Event . " + e.getMessage()); + } + } + + static String toJsonString(Object object) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + return mapper.writeValueAsString(object); + } + + static T toJsonObj(String content, Class valueType) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + return mapper.readValue(content, valueType); + } + + private String compname() { + return "ServiceCatalogApiRouteBuilderEvents"; + } +} \ No newline at end of file diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/CatalogRepoService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/CatalogRepoService.java index 124f9612..26d52c04 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/CatalogRepoService.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/CatalogRepoService.java @@ -60,11 +60,14 @@ public class CatalogRepoService { @Autowired ServiceSpecificationRepoService specRepoService; - - public ServiceCatalog addCatalog(ServiceCatalog c) { + @Autowired + ServiceCatalogNotificationService serviceCatalogNotificationService; - return this.catalogRepo.save(c); + public ServiceCatalog addCatalog(ServiceCatalog c) { + ServiceCatalog savedCatalog = this.catalogRepo.save(c); + serviceCatalogNotificationService.publishServiceCatalogCreateNotification(savedCatalog); + return savedCatalog; } public ServiceCatalog addCatalog(@Valid ServiceCatalogCreate serviceCat) { @@ -72,7 +75,9 @@ public class CatalogRepoService { ServiceCatalog sc = new ServiceCatalog(); sc = updateCatalogDataFromAPICall(sc, serviceCat); - return this.catalogRepo.save(sc); + ServiceCatalog savedCatalog = this.catalogRepo.save(sc); + serviceCatalogNotificationService.publishServiceCatalogCreateNotification(savedCatalog); + return savedCatalog; } public String findAllEager() { @@ -157,9 +162,12 @@ public class CatalogRepoService { public Void deleteById(String id) { Optional optionalCat = this.catalogRepo.findByUuid(id); - this.catalogRepo.delete(optionalCat.get()); + if (optionalCat.isPresent()) { + ServiceCatalog catalogToDelete = optionalCat.get(); + serviceCatalogNotificationService.publishServiceCatalogDeleteNotification(catalogToDelete); + this.catalogRepo.delete(catalogToDelete); + } return null; - } public ServiceCatalog updateCatalog(String id, ServiceCatalogUpdate serviceCatalog) { diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/CategoryRepoService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/CategoryRepoService.java index 2ebf74d0..59eb00e6 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/CategoryRepoService.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/CategoryRepoService.java @@ -55,6 +55,9 @@ public class CategoryRepoService { private final CategoriesRepository categsRepo; private final CandidateRepository candidateRepo; + + @Autowired + private ServiceCategoryNotificationService serviceCategoryNotificationService; @Autowired @@ -64,8 +67,9 @@ public class CategoryRepoService { } public ServiceCategory addCategory(ServiceCategory c) { - - return this.getCategsRepo().save( c ); + ServiceCategory savedCategory = this.getCategsRepo().save(c); + serviceCategoryNotificationService.publishServiceCategoryCreateNotification(savedCategory); + return savedCategory; } public ServiceCategory addCategory(@Valid ServiceCategoryCreate serviceCategory) { @@ -73,7 +77,9 @@ public class CategoryRepoService { ServiceCategory sc = new ServiceCategory() ; sc = updateCategoryDataFromAPICall(sc, serviceCategory); - return this.getCategsRepo().save( sc ); + ServiceCategory savedCategory = this.getCategsRepo().save(sc); + serviceCategoryNotificationService.publishServiceCategoryCreateNotification(savedCategory); + return savedCategory; } @@ -159,17 +165,25 @@ public class CategoryRepoService { public boolean deleteById(String id) { Optional optionalCat = this.getCategsRepo().findByUuid( id ); - if ( optionalCat.get().getCategoryObj().size()>0 ) { + + // Check if category exists + if (!optionalCat.isPresent()) { + return false; // Category not found + } + + ServiceCategory category = optionalCat.get(); + + if ( category.getCategoryObj().size()>0 ) { return false; //has children } - if ( optionalCat.get().getParentId() != null ) { - ServiceCategory parentCat = (this.getCategsRepo().findByUuid( optionalCat.get().getParentId() )).get(); + if ( category.getParentId() != null ) { + ServiceCategory parentCat = (this.getCategsRepo().findByUuid( category.getParentId() )).get(); //remove from parent category for (ServiceCategory ss : parentCat.getCategoryObj()) { - if ( ss.getId() == optionalCat.get().getId() ) { + if ( ss.getId() == category.getId() ) { parentCat.getCategoryObj().remove(ss); break; } @@ -177,8 +191,8 @@ public class CategoryRepoService { parentCat = this.getCategsRepo().save(parentCat); } - - this.getCategsRepo().delete( optionalCat.get()); + serviceCategoryNotificationService.publishServiceCategoryDeleteNotification(category); + this.getCategsRepo().delete(category); return true; } diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogCallbackService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogCallbackService.java new file mode 100644 index 00000000..592b834b --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogCallbackService.java @@ -0,0 +1,362 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.tmf.api + * %% + * Copyright (C) 2019 - 2021 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.tmf.scm633.reposervices; + +import java.util.List; + +import org.etsi.osl.tmf.scm633.model.ServiceCatalogCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeEvent; +import org.etsi.osl.tmf.scm633.model.EventSubscription; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class ServiceCatalogCallbackService { + + private static final Logger logger = LoggerFactory.getLogger(ServiceCatalogCallbackService.class); + + @Autowired + @Qualifier("scm633EventSubscriptionRepoService") + private EventSubscriptionRepoService eventSubscriptionRepoService; + + @Autowired + private RestTemplate restTemplate; + + /** + * Send service catalog create event to all registered callback URLs + * @param serviceCatalogCreateEvent The service catalog create event to send + */ + public void sendServiceCatalogCreateCallback(ServiceCatalogCreateEvent serviceCatalogCreateEvent) { + List subscriptions = eventSubscriptionRepoService.findAll(); + + for (EventSubscription subscription : subscriptions) { + if (shouldNotifySubscription(subscription, "serviceCatalogCreateEvent")) { + sendServiceCatalogCreateEventToCallback(subscription.getCallback(), serviceCatalogCreateEvent); + } + } + } + + /** + * Send service catalog delete event to all registered callback URLs + * @param serviceCatalogDeleteEvent The service catalog delete event to send + */ + public void sendServiceCatalogDeleteCallback(ServiceCatalogDeleteEvent serviceCatalogDeleteEvent) { + List subscriptions = eventSubscriptionRepoService.findAll(); + + for (EventSubscription subscription : subscriptions) { + if (shouldNotifySubscription(subscription, "serviceCatalogDeleteEvent")) { + sendServiceCatalogDeleteEventToCallback(subscription.getCallback(), serviceCatalogDeleteEvent); + } + } + } + + /** + * Send service catalog create event to a specific callback URL + * @param callbackUrl The callback URL to send to + * @param event The service catalog create event + */ + private void sendServiceCatalogCreateEventToCallback(String callbackUrl, ServiceCatalogCreateEvent event) { + try { + String url = buildCallbackUrl(callbackUrl, "/listener/serviceCatalogCreateEvent"); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(event, headers); + + ResponseEntity response = restTemplate.exchange( + url, HttpMethod.POST, entity, String.class); + + logger.info("Successfully sent service catalog create event to callback URL: {} - Response: {}", + url, response.getStatusCode()); + + } catch (Exception e) { + logger.error("Failed to send service catalog create event to callback URL: {}", callbackUrl, e); + } + } + + /** + * Send service catalog delete event to a specific callback URL + * @param callbackUrl The callback URL to send to + * @param event The service catalog delete event + */ + private void sendServiceCatalogDeleteEventToCallback(String callbackUrl, ServiceCatalogDeleteEvent event) { + try { + String url = buildCallbackUrl(callbackUrl, "/listener/serviceCatalogDeleteEvent"); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(event, headers); + + ResponseEntity response = restTemplate.exchange( + url, HttpMethod.POST, entity, String.class); + + logger.info("Successfully sent service catalog delete event to callback URL: {} - Response: {}", + url, response.getStatusCode()); + + } catch (Exception e) { + logger.error("Failed to send service catalog delete event to callback URL: {}", callbackUrl, e); + } + } + + /** + * Build the full callback URL with the listener endpoint + * @param baseUrl The base callback URL + * @param listenerPath The listener path to append + * @return The complete callback URL + */ + private String buildCallbackUrl(String baseUrl, String listenerPath) { + if (baseUrl.endsWith("/")) { + return baseUrl.substring(0, baseUrl.length() - 1) + listenerPath; + } else { + return baseUrl + listenerPath; + } + } + + /** + * Send service category create event to all registered callback URLs + * @param serviceCategoryCreateEvent The service category create event to send + */ + public void sendServiceCategoryCreateCallback(ServiceCategoryCreateEvent serviceCategoryCreateEvent) { + List subscriptions = eventSubscriptionRepoService.findAll(); + + for (EventSubscription subscription : subscriptions) { + if (shouldNotifySubscription(subscription, "serviceCategoryCreateEvent")) { + sendServiceCategoryCreateEventToCallback(subscription.getCallback(), serviceCategoryCreateEvent); + } + } + } + + /** + * Send service category delete event to all registered callback URLs + * @param serviceCategoryDeleteEvent The service category delete event to send + */ + public void sendServiceCategoryDeleteCallback(ServiceCategoryDeleteEvent serviceCategoryDeleteEvent) { + List subscriptions = eventSubscriptionRepoService.findAll(); + + for (EventSubscription subscription : subscriptions) { + if (shouldNotifySubscription(subscription, "serviceCategoryDeleteEvent")) { + sendServiceCategoryDeleteEventToCallback(subscription.getCallback(), serviceCategoryDeleteEvent); + } + } + } + + /** + * Send service specification create event to all registered callback URLs + * @param serviceSpecificationCreateEvent The service specification create event to send + */ + public void sendServiceSpecificationCreateCallback(ServiceSpecificationCreateEvent serviceSpecificationCreateEvent) { + List subscriptions = eventSubscriptionRepoService.findAll(); + + for (EventSubscription subscription : subscriptions) { + if (shouldNotifySubscription(subscription, "serviceSpecificationCreateEvent")) { + sendServiceSpecificationCreateEventToCallback(subscription.getCallback(), serviceSpecificationCreateEvent); + } + } + } + + /** + * Send service specification delete event to all registered callback URLs + * @param serviceSpecificationDeleteEvent The service specification delete event to send + */ + public void sendServiceSpecificationDeleteCallback(ServiceSpecificationDeleteEvent serviceSpecificationDeleteEvent) { + List subscriptions = eventSubscriptionRepoService.findAll(); + + for (EventSubscription subscription : subscriptions) { + if (shouldNotifySubscription(subscription, "serviceSpecificationDeleteEvent")) { + sendServiceSpecificationDeleteEventToCallback(subscription.getCallback(), serviceSpecificationDeleteEvent); + } + } + } + + /** + * Send service specification change event to all registered callback URLs + * @param serviceSpecificationChangeEvent The service specification change event to send + */ + public void sendServiceSpecificationChangeCallback(ServiceSpecificationChangeEvent serviceSpecificationChangeEvent) { + List subscriptions = eventSubscriptionRepoService.findAll(); + + for (EventSubscription subscription : subscriptions) { + if (shouldNotifySubscription(subscription, "serviceSpecificationChangeEvent")) { + sendServiceSpecificationChangeEventToCallback(subscription.getCallback(), serviceSpecificationChangeEvent); + } + } + } + + /** + * Send service category create event to a specific callback URL + * @param callbackUrl The callback URL to send to + * @param event The service category create event + */ + private void sendServiceCategoryCreateEventToCallback(String callbackUrl, ServiceCategoryCreateEvent event) { + try { + String url = buildCallbackUrl(callbackUrl, "/listener/serviceCategoryCreateEvent"); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(event, headers); + + ResponseEntity response = restTemplate.exchange( + url, HttpMethod.POST, entity, String.class); + + logger.info("Successfully sent service category create event to callback URL: {} - Response: {}", + url, response.getStatusCode()); + + } catch (Exception e) { + logger.error("Failed to send service category create event to callback URL: {}", callbackUrl, e); + } + } + + /** + * Send service category delete event to a specific callback URL + * @param callbackUrl The callback URL to send to + * @param event The service category delete event + */ + private void sendServiceCategoryDeleteEventToCallback(String callbackUrl, ServiceCategoryDeleteEvent event) { + try { + String url = buildCallbackUrl(callbackUrl, "/listener/serviceCategoryDeleteEvent"); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(event, headers); + + ResponseEntity response = restTemplate.exchange( + url, HttpMethod.POST, entity, String.class); + + logger.info("Successfully sent service category delete event to callback URL: {} - Response: {}", + url, response.getStatusCode()); + + } catch (Exception e) { + logger.error("Failed to send service category delete event to callback URL: {}", callbackUrl, e); + } + } + + /** + * Send service specification create event to a specific callback URL + * @param callbackUrl The callback URL to send to + * @param event The service specification create event + */ + private void sendServiceSpecificationCreateEventToCallback(String callbackUrl, ServiceSpecificationCreateEvent event) { + try { + String url = buildCallbackUrl(callbackUrl, "/listener/serviceSpecificationCreateEvent"); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(event, headers); + + ResponseEntity response = restTemplate.exchange( + url, HttpMethod.POST, entity, String.class); + + logger.info("Successfully sent service specification create event to callback URL: {} - Response: {}", + url, response.getStatusCode()); + + } catch (Exception e) { + logger.error("Failed to send service specification create event to callback URL: {}", callbackUrl, e); + } + } + + /** + * Send service specification delete event to a specific callback URL + * @param callbackUrl The callback URL to send to + * @param event The service specification delete event + */ + private void sendServiceSpecificationDeleteEventToCallback(String callbackUrl, ServiceSpecificationDeleteEvent event) { + try { + String url = buildCallbackUrl(callbackUrl, "/listener/serviceSpecificationDeleteEvent"); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(event, headers); + + ResponseEntity response = restTemplate.exchange( + url, HttpMethod.POST, entity, String.class); + + logger.info("Successfully sent service specification delete event to callback URL: {} - Response: {}", + url, response.getStatusCode()); + + } catch (Exception e) { + logger.error("Failed to send service specification delete event to callback URL: {}", callbackUrl, e); + } + } + + /** + * Send service specification change event to a specific callback URL + * @param callbackUrl The callback URL to send to + * @param event The service specification change event + */ + private void sendServiceSpecificationChangeEventToCallback(String callbackUrl, ServiceSpecificationChangeEvent event) { + try { + String url = buildCallbackUrl(callbackUrl, "/listener/serviceSpecificationChangeEvent"); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(event, headers); + + ResponseEntity response = restTemplate.exchange( + url, HttpMethod.POST, entity, String.class); + + logger.info("Successfully sent service specification change event to callback URL: {} - Response: {}", + url, response.getStatusCode()); + + } catch (Exception e) { + logger.error("Failed to send service specification change event to callback URL: {}", callbackUrl, e); + } + } + + /** + * Check if a subscription should be notified for a specific event type + * @param subscription The event subscription + * @param eventType The event type to check + * @return true if the subscription should be notified + */ + private boolean shouldNotifySubscription(EventSubscription subscription, String eventType) { + // If no query is specified, notify all events + if (subscription.getQuery() == null || subscription.getQuery().trim().isEmpty()) { + return true; + } + + // Check if the query contains the event type + String query = subscription.getQuery().toLowerCase(); + return query.contains("servicecatalog") || + query.contains("servicecategory") || + query.contains("servicespecification") || + query.contains(eventType.toLowerCase()) || + query.contains("servicecatalog.create") || + query.contains("servicecatalog.delete") || + query.contains("servicecategory.create") || + query.contains("servicecategory.delete") || + query.contains("servicespecification.create") || + query.contains("servicespecification.delete") || + query.contains("servicespecification.change"); + } +} \ No newline at end of file diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogNotificationService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogNotificationService.java new file mode 100644 index 00000000..74351777 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogNotificationService.java @@ -0,0 +1,129 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.tmf.api + * %% + * Copyright (C) 2019 - 2021 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.tmf.scm633.reposervices; + +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.util.UUID; + +import org.etsi.osl.tmf.scm633.api.ServiceCatalogApiRouteBuilderEvents; +import org.etsi.osl.tmf.scm633.model.ServiceCatalog; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogDeleteNotification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class ServiceCatalogNotificationService { + + private static final Logger logger = LoggerFactory.getLogger(ServiceCatalogNotificationService.class); + + @Autowired + private ServiceCatalogApiRouteBuilderEvents eventPublisher; + + @Autowired + private ServiceCatalogCallbackService serviceCatalogCallbackService; + + /** + * Publish a service catalog create notification + * @param serviceCatalog The created service catalog + */ + public void publishServiceCatalogCreateNotification(ServiceCatalog serviceCatalog) { + try { + ServiceCatalogCreateNotification notification = createServiceCatalogCreateNotification(serviceCatalog); + eventPublisher.publishEvent(notification, serviceCatalog.getUuid()); + + // Send callbacks to registered subscribers + serviceCatalogCallbackService.sendServiceCatalogCreateCallback(notification.getEvent()); + + logger.info("Published service catalog create notification for service catalog ID: {}", serviceCatalog.getUuid()); + } catch (Exception e) { + logger.error("Error publishing service catalog create notification for service catalog ID: {}", serviceCatalog.getUuid(), e); + } + } + + /** + * Publish a service catalog delete notification + * @param serviceCatalog The deleted service catalog + */ + public void publishServiceCatalogDeleteNotification(ServiceCatalog serviceCatalog) { + try { + ServiceCatalogDeleteNotification notification = createServiceCatalogDeleteNotification(serviceCatalog); + eventPublisher.publishEvent(notification, serviceCatalog.getUuid()); + + // Send callbacks to registered subscribers + serviceCatalogCallbackService.sendServiceCatalogDeleteCallback(notification.getEvent()); + + logger.info("Published service catalog delete notification for service catalog ID: {}", serviceCatalog.getUuid()); + } catch (Exception e) { + logger.error("Error publishing service catalog delete notification for service catalog ID: {}", serviceCatalog.getUuid(), e); + } + } + + /** + * Create a service catalog create notification + * @param serviceCatalog The created service catalog + * @return ServiceCatalogCreateNotification + */ + private ServiceCatalogCreateNotification createServiceCatalogCreateNotification(ServiceCatalog serviceCatalog) { + ServiceCatalogCreateNotification notification = new ServiceCatalogCreateNotification(); + + // Set common notification properties + notification.setEventId(UUID.randomUUID().toString()); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + notification.setEventType(ServiceCatalogCreateNotification.class.getName()); + notification.setResourcePath("/serviceCatalogManagement/v4/serviceCatalog/" + serviceCatalog.getUuid()); + + // Create event + ServiceCatalogCreateEvent event = new ServiceCatalogCreateEvent(); + event.setServiceCatalog(serviceCatalog); + + notification.setEvent(event); + return notification; + } + + /** + * Create a service catalog delete notification + * @param serviceCatalog The deleted service catalog + * @return ServiceCatalogDeleteNotification + */ + private ServiceCatalogDeleteNotification createServiceCatalogDeleteNotification(ServiceCatalog serviceCatalog) { + ServiceCatalogDeleteNotification notification = new ServiceCatalogDeleteNotification(); + + // Set common notification properties + notification.setEventId(UUID.randomUUID().toString()); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + notification.setEventType(ServiceCatalogDeleteNotification.class.getName()); + notification.setResourcePath("/serviceCatalogManagement/v4/serviceCatalog/" + serviceCatalog.getUuid()); + + // Create event + ServiceCatalogDeleteEvent event = new ServiceCatalogDeleteEvent(); + event.setServiceCatalog(serviceCatalog); + + notification.setEvent(event); + return notification; + } +} \ No newline at end of file diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCategoryNotificationService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCategoryNotificationService.java new file mode 100644 index 00000000..4d5f6274 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCategoryNotificationService.java @@ -0,0 +1,129 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.tmf.api + * %% + * Copyright (C) 2019 - 2021 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.tmf.scm633.reposervices; + +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.util.UUID; + +import org.etsi.osl.tmf.scm633.api.ServiceCatalogApiRouteBuilderEvents; +import org.etsi.osl.tmf.scm633.model.ServiceCategory; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteNotification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class ServiceCategoryNotificationService { + + private static final Logger logger = LoggerFactory.getLogger(ServiceCategoryNotificationService.class); + + @Autowired + private ServiceCatalogApiRouteBuilderEvents eventPublisher; + + @Autowired + private ServiceCatalogCallbackService serviceCatalogCallbackService; + + /** + * Publish a service category create notification + * @param serviceCategory The created service category + */ + public void publishServiceCategoryCreateNotification(ServiceCategory serviceCategory) { + try { + ServiceCategoryCreateNotification notification = createServiceCategoryCreateNotification(serviceCategory); + eventPublisher.publishEvent(notification, serviceCategory.getUuid()); + + // Send callbacks to registered subscribers + serviceCatalogCallbackService.sendServiceCategoryCreateCallback(notification.getEvent()); + + logger.info("Published service category create notification for service category ID: {}", serviceCategory.getUuid()); + } catch (Exception e) { + logger.error("Error publishing service category create notification for service category ID: {}", serviceCategory.getUuid(), e); + } + } + + /** + * Publish a service category delete notification + * @param serviceCategory The deleted service category + */ + public void publishServiceCategoryDeleteNotification(ServiceCategory serviceCategory) { + try { + ServiceCategoryDeleteNotification notification = createServiceCategoryDeleteNotification(serviceCategory); + eventPublisher.publishEvent(notification, serviceCategory.getUuid()); + + // Send callbacks to registered subscribers + serviceCatalogCallbackService.sendServiceCategoryDeleteCallback(notification.getEvent()); + + logger.info("Published service category delete notification for service category ID: {}", serviceCategory.getUuid()); + } catch (Exception e) { + logger.error("Error publishing service category delete notification for service category ID: {}", serviceCategory.getUuid(), e); + } + } + + /** + * Create a service category create notification + * @param serviceCategory The created service category + * @return ServiceCategoryCreateNotification + */ + private ServiceCategoryCreateNotification createServiceCategoryCreateNotification(ServiceCategory serviceCategory) { + ServiceCategoryCreateNotification notification = new ServiceCategoryCreateNotification(); + + // Set common notification properties + notification.setEventId(UUID.randomUUID().toString()); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + notification.setEventType(ServiceCategoryCreateNotification.class.getName()); + notification.setResourcePath("/serviceCatalogManagement/v4/serviceCategory/" + serviceCategory.getUuid()); + + // Create event + ServiceCategoryCreateEvent event = new ServiceCategoryCreateEvent(); + event.setServiceCategory(serviceCategory); + + notification.setEvent(event); + return notification; + } + + /** + * Create a service category delete notification + * @param serviceCategory The deleted service category + * @return ServiceCategoryDeleteNotification + */ + private ServiceCategoryDeleteNotification createServiceCategoryDeleteNotification(ServiceCategory serviceCategory) { + ServiceCategoryDeleteNotification notification = new ServiceCategoryDeleteNotification(); + + // Set common notification properties + notification.setEventId(UUID.randomUUID().toString()); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + notification.setEventType(ServiceCategoryDeleteNotification.class.getName()); + notification.setResourcePath("/serviceCatalogManagement/v4/serviceCategory/" + serviceCategory.getUuid()); + + // Create event + ServiceCategoryDeleteEvent event = new ServiceCategoryDeleteEvent(); + event.setServiceCategory(serviceCategory); + + notification.setEvent(event); + return notification; + } +} \ No newline at end of file diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationNotificationService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationNotificationService.java new file mode 100644 index 00000000..e694454f --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationNotificationService.java @@ -0,0 +1,171 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.tmf.api + * %% + * Copyright (C) 2019 - 2021 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.tmf.scm633.reposervices; + +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.util.UUID; + +import org.etsi.osl.tmf.scm633.api.ServiceCatalogApiRouteBuilderEvents; +import org.etsi.osl.tmf.scm633.model.ServiceSpecification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteNotification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class ServiceSpecificationNotificationService { + + private static final Logger logger = LoggerFactory.getLogger(ServiceSpecificationNotificationService.class); + + @Autowired + private ServiceCatalogApiRouteBuilderEvents eventPublisher; + + @Autowired + private ServiceCatalogCallbackService serviceCatalogCallbackService; + + /** + * Publish a service specification create notification + * @param serviceSpecification The created service specification + */ + public void publishServiceSpecificationCreateNotification(ServiceSpecification serviceSpecification) { + try { + ServiceSpecificationCreateNotification notification = createServiceSpecificationCreateNotification(serviceSpecification); + eventPublisher.publishEvent(notification, serviceSpecification.getUuid()); + + // Send callbacks to registered subscribers + serviceCatalogCallbackService.sendServiceSpecificationCreateCallback(notification.getEvent()); + + logger.info("Published service specification create notification for service specification ID: {}", serviceSpecification.getUuid()); + } catch (Exception e) { + logger.error("Error publishing service specification create notification for service specification ID: {}", serviceSpecification.getUuid(), e); + } + } + + /** + * Publish a service specification delete notification + * @param serviceSpecification The deleted service specification + */ + public void publishServiceSpecificationDeleteNotification(ServiceSpecification serviceSpecification) { + try { + ServiceSpecificationDeleteNotification notification = createServiceSpecificationDeleteNotification(serviceSpecification); + eventPublisher.publishEvent(notification, serviceSpecification.getUuid()); + + // Send callbacks to registered subscribers + serviceCatalogCallbackService.sendServiceSpecificationDeleteCallback(notification.getEvent()); + + logger.info("Published service specification delete notification for service specification ID: {}", serviceSpecification.getUuid()); + } catch (Exception e) { + logger.error("Error publishing service specification delete notification for service specification ID: {}", serviceSpecification.getUuid(), e); + } + } + + /** + * Publish a service specification change notification + * @param serviceSpecification The changed service specification + */ + public void publishServiceSpecificationChangeNotification(ServiceSpecification serviceSpecification) { + try { + ServiceSpecificationChangeNotification notification = createServiceSpecificationChangeNotification(serviceSpecification); + eventPublisher.publishEvent(notification, serviceSpecification.getUuid()); + + // Send callbacks to registered subscribers + serviceCatalogCallbackService.sendServiceSpecificationChangeCallback(notification.getEvent()); + + logger.info("Published service specification change notification for service specification ID: {}", serviceSpecification.getUuid()); + } catch (Exception e) { + logger.error("Error publishing service specification change notification for service specification ID: {}", serviceSpecification.getUuid(), e); + } + } + + /** + * Create a service specification create notification + * @param serviceSpecification The created service specification + * @return ServiceSpecificationCreateNotification + */ + private ServiceSpecificationCreateNotification createServiceSpecificationCreateNotification(ServiceSpecification serviceSpecification) { + ServiceSpecificationCreateNotification notification = new ServiceSpecificationCreateNotification(); + + // Set common notification properties + notification.setEventId(UUID.randomUUID().toString()); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + notification.setEventType(ServiceSpecificationCreateNotification.class.getName()); + notification.setResourcePath("/serviceCatalogManagement/v4/serviceSpecification/" + serviceSpecification.getUuid()); + + // Create event + ServiceSpecificationCreateEvent event = new ServiceSpecificationCreateEvent(); + event.setServiceSpecification(serviceSpecification); + + notification.setEvent(event); + return notification; + } + + /** + * Create a service specification delete notification + * @param serviceSpecification The deleted service specification + * @return ServiceSpecificationDeleteNotification + */ + private ServiceSpecificationDeleteNotification createServiceSpecificationDeleteNotification(ServiceSpecification serviceSpecification) { + ServiceSpecificationDeleteNotification notification = new ServiceSpecificationDeleteNotification(); + + // Set common notification properties + notification.setEventId(UUID.randomUUID().toString()); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + notification.setEventType(ServiceSpecificationDeleteNotification.class.getName()); + notification.setResourcePath("/serviceCatalogManagement/v4/serviceSpecification/" + serviceSpecification.getUuid()); + + // Create event + ServiceSpecificationDeleteEvent event = new ServiceSpecificationDeleteEvent(); + event.setServiceSpecification(serviceSpecification); + + notification.setEvent(event); + return notification; + } + + /** + * Create a service specification change notification + * @param serviceSpecification The changed service specification + * @return ServiceSpecificationChangeNotification + */ + private ServiceSpecificationChangeNotification createServiceSpecificationChangeNotification(ServiceSpecification serviceSpecification) { + ServiceSpecificationChangeNotification notification = new ServiceSpecificationChangeNotification(); + + // Set common notification properties + notification.setEventId(UUID.randomUUID().toString()); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + notification.setEventType(ServiceSpecificationChangeNotification.class.getName()); + notification.setResourcePath("/serviceCatalogManagement/v4/serviceSpecification/" + serviceSpecification.getUuid()); + + // Create event + ServiceSpecificationChangeEvent event = new ServiceSpecificationChangeEvent(); + event.setServiceSpecification(serviceSpecification); + + notification.setEvent(event); + return notification; + } +} \ No newline at end of file diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java index 9b3f2fdf..1fa88214 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java @@ -134,6 +134,9 @@ public class ServiceSpecificationRepoService { @Autowired ServiceTestSpecificationRepoService serviceTestSpecificationRepoService; + @Autowired + ServiceSpecificationNotificationService serviceSpecificationNotificationService; + private SessionFactory sessionFactory; private static final String METADATADIR = System.getProperty("user.home") + File.separator + ".attachments" @@ -156,6 +159,8 @@ public class ServiceSpecificationRepoService { serviceSpec = this.updateServiceSpecDataFromAPIcall(serviceSpec, serviceServiceSpecification); serviceSpec = this.serviceSpecificationRepo.save(serviceSpec); serviceSpec.fixSpecCharRelationhsipIDs(); + + serviceSpecificationNotificationService.publishServiceSpecificationCreateNotification(serviceSpec); /** * we automatically create s Service Candidate for this spec ready to be @@ -338,7 +343,8 @@ public class ServiceSpecificationRepoService { /** * prior deleting we need to delete other dependency objects */ - + + serviceSpecificationNotificationService.publishServiceSpecificationDeleteNotification(s); this.serviceSpecificationRepo.delete(s); return null; } @@ -377,6 +383,8 @@ public class ServiceSpecificationRepoService { serviceSpec = this.serviceSpecificationRepo.save(serviceSpec); serviceSpec.fixSpecCharRelationhsipIDs(); + serviceSpecificationNotificationService.publishServiceSpecificationChangeNotification(serviceSpec); + //save the equivalent candidate ServiceCandidate serviceCandidateObj = candidateRepoService.findById( serviceSpec.getServiceCandidateObjId() ); if ( serviceCandidateObj!=null) { diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiRouteBuilderEventsTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiRouteBuilderEventsTest.java new file mode 100644 index 00000000..f57e3524 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiRouteBuilderEventsTest.java @@ -0,0 +1,248 @@ +package org.etsi.osl.services.api.scm633; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.time.OffsetDateTime; +import java.time.ZoneOffset; + +import org.apache.camel.ProducerTemplate; +import org.etsi.osl.centrallog.client.CentralLogger; +import org.etsi.osl.tmf.scm633.api.ServiceCatalogApiRouteBuilderEvents; +import org.etsi.osl.tmf.scm633.model.ServiceCatalog; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogDeleteNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCategory; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeNotification; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.Map; + +@RunWith(SpringRunner.class) +@ActiveProfiles("testing") +public class ServiceCatalogApiRouteBuilderEventsTest { + + @Mock + private ProducerTemplate template; + + @Mock + private CentralLogger centralLogger; + + @InjectMocks + private ServiceCatalogApiRouteBuilderEvents routeBuilderEvents; + + @Before + public void setup() { + MockitoAnnotations.openMocks(this); + + // Set event topic properties using reflection + ReflectionTestUtils.setField(routeBuilderEvents, "EVENT_SERVICE_CATALOG_CREATE", "direct:EVENT_SERVICE_CATALOG_CREATE"); + ReflectionTestUtils.setField(routeBuilderEvents, "EVENT_SERVICE_CATALOG_DELETE", "direct:EVENT_SERVICE_CATALOG_DELETE"); + ReflectionTestUtils.setField(routeBuilderEvents, "EVENT_SERVICE_CATEGORY_CREATE", "direct:EVENT_SERVICE_CATEGORY_CREATE"); + ReflectionTestUtils.setField(routeBuilderEvents, "EVENT_SERVICE_CATEGORY_DELETE", "direct:EVENT_SERVICE_CATEGORY_DELETE"); + ReflectionTestUtils.setField(routeBuilderEvents, "EVENT_SERVICE_SPECIFICATION_CREATE", "direct:EVENT_SERVICE_SPECIFICATION_CREATE"); + ReflectionTestUtils.setField(routeBuilderEvents, "EVENT_SERVICE_SPECIFICATION_DELETE", "direct:EVENT_SERVICE_SPECIFICATION_DELETE"); + ReflectionTestUtils.setField(routeBuilderEvents, "EVENT_SERVICE_SPECIFICATION_CHANGE", "direct:EVENT_SERVICE_SPECIFICATION_CHANGE"); + } + + @Test + public void testPublishServiceCatalogCreateEvent() { + // Arrange + ServiceCatalog serviceCatalog = new ServiceCatalog(); + serviceCatalog.setUuid("test-catalog-123"); + + ServiceCatalogCreateNotification notification = new ServiceCatalogCreateNotification(); + notification.setEventId("event-123"); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + + // Act + routeBuilderEvents.publishEvent(notification, "test-catalog-123"); + + // Assert + verify(template, times(1)).sendBodyAndHeaders( + eq("direct:EVENT_SERVICE_CATALOG_CREATE"), + any(String.class), + any(Map.class) + ); + } + + @Test + public void testPublishServiceCatalogDeleteEvent() { + // Arrange + ServiceCatalogDeleteNotification notification = new ServiceCatalogDeleteNotification(); + notification.setEventId("event-456"); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + + // Act + routeBuilderEvents.publishEvent(notification, "test-catalog-456"); + + // Assert + verify(template, times(1)).sendBodyAndHeaders( + eq("direct:EVENT_SERVICE_CATALOG_DELETE"), + any(String.class), + any(Map.class) + ); + } + + @Test + public void testPublishServiceCategoryCreateEvent() { + // Arrange + ServiceCategoryCreateNotification notification = new ServiceCategoryCreateNotification(); + notification.setEventId("event-789"); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + + // Act + routeBuilderEvents.publishEvent(notification, "test-category-789"); + + // Assert + verify(template, times(1)).sendBodyAndHeaders( + eq("direct:EVENT_SERVICE_CATEGORY_CREATE"), + any(String.class), + any(Map.class) + ); + } + + @Test + public void testPublishServiceCategoryDeleteEvent() { + // Arrange + ServiceCategoryDeleteNotification notification = new ServiceCategoryDeleteNotification(); + notification.setEventId("event-101112"); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + + // Act + routeBuilderEvents.publishEvent(notification, "test-category-101112"); + + // Assert + verify(template, times(1)).sendBodyAndHeaders( + eq("direct:EVENT_SERVICE_CATEGORY_DELETE"), + any(String.class), + any(Map.class) + ); + } + + @Test + public void testPublishServiceSpecificationCreateEvent() { + // Arrange + ServiceSpecificationCreateNotification notification = new ServiceSpecificationCreateNotification(); + notification.setEventId("event-131415"); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + + // Act + routeBuilderEvents.publishEvent(notification, "test-spec-131415"); + + // Assert + verify(template, times(1)).sendBodyAndHeaders( + eq("direct:EVENT_SERVICE_SPECIFICATION_CREATE"), + any(String.class), + any(Map.class) + ); + } + + @Test + public void testPublishServiceSpecificationDeleteEvent() { + // Arrange + ServiceSpecificationDeleteNotification notification = new ServiceSpecificationDeleteNotification(); + notification.setEventId("event-161718"); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + + // Act + routeBuilderEvents.publishEvent(notification, "test-spec-161718"); + + // Assert + verify(template, times(1)).sendBodyAndHeaders( + eq("direct:EVENT_SERVICE_SPECIFICATION_DELETE"), + any(String.class), + any(Map.class) + ); + } + + @Test + public void testPublishServiceSpecificationChangeEvent() { + // Arrange + ServiceSpecificationChangeNotification notification = new ServiceSpecificationChangeNotification(); + notification.setEventId("event-192021"); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + + // Act + routeBuilderEvents.publishEvent(notification, "test-spec-192021"); + + // Assert + verify(template, times(1)).sendBodyAndHeaders( + eq("direct:EVENT_SERVICE_SPECIFICATION_CHANGE"), + any(String.class), + any(Map.class) + ); + } + + @Test + public void testPublishEventWithNullEventId() { + // Arrange + ServiceCatalogCreateNotification notification = new ServiceCatalogCreateNotification(); + notification.setEventId(null); + notification.setEventTime(OffsetDateTime.now(ZoneOffset.UTC)); + + // Act + routeBuilderEvents.publishEvent(notification, "test-catalog-null"); + + // Assert + verify(template, times(1)).sendBodyAndHeaders( + eq("direct:EVENT_SERVICE_CATALOG_CREATE"), + any(String.class), + any(Map.class) + ); + } + + @Test + public void testPublishEventWithDifferentNotificationTypes() { + // Test that all notification types are handled correctly + + // Service Catalog + ServiceCatalogCreateNotification catalogCreate = new ServiceCatalogCreateNotification(); + catalogCreate.setEventId("catalog-create"); + routeBuilderEvents.publishEvent(catalogCreate, "catalog-id"); + + ServiceCatalogDeleteNotification catalogDelete = new ServiceCatalogDeleteNotification(); + catalogDelete.setEventId("catalog-delete"); + routeBuilderEvents.publishEvent(catalogDelete, "catalog-id"); + + // Service Category + ServiceCategoryCreateNotification categoryCreate = new ServiceCategoryCreateNotification(); + categoryCreate.setEventId("category-create"); + routeBuilderEvents.publishEvent(categoryCreate, "category-id"); + + ServiceCategoryDeleteNotification categoryDelete = new ServiceCategoryDeleteNotification(); + categoryDelete.setEventId("category-delete"); + routeBuilderEvents.publishEvent(categoryDelete, "category-id"); + + // Service Specification + ServiceSpecificationCreateNotification specCreate = new ServiceSpecificationCreateNotification(); + specCreate.setEventId("spec-create"); + routeBuilderEvents.publishEvent(specCreate, "spec-id"); + + ServiceSpecificationDeleteNotification specDelete = new ServiceSpecificationDeleteNotification(); + specDelete.setEventId("spec-delete"); + routeBuilderEvents.publishEvent(specDelete, "spec-id"); + + ServiceSpecificationChangeNotification specChange = new ServiceSpecificationChangeNotification(); + specChange.setEventId("spec-change"); + routeBuilderEvents.publishEvent(specChange, "spec-id"); + + // Assert all events were published + verify(template, times(7)).sendBodyAndHeaders(any(String.class), any(String.class), any(Map.class)); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogCallbackServiceExtendedTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogCallbackServiceExtendedTest.java new file mode 100644 index 00000000..ada8e9c8 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogCallbackServiceExtendedTest.java @@ -0,0 +1,248 @@ +package org.etsi.osl.services.api.scm633; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.List; + +import org.etsi.osl.tmf.scm633.model.EventSubscription; +import org.etsi.osl.tmf.scm633.model.ServiceCategory; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeEvent; +import org.etsi.osl.tmf.scm633.reposervices.EventSubscriptionRepoService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceCatalogCallbackService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +@RunWith(SpringRunner.class) +@ActiveProfiles("testing") +public class ServiceCatalogCallbackServiceExtendedTest { + + @Mock + private EventSubscriptionRepoService eventSubscriptionRepoService; + + @Mock + private RestTemplate restTemplate; + + @InjectMocks + private ServiceCatalogCallbackService serviceCatalogCallbackService; + + @Before + public void setup() { + MockitoAnnotations.openMocks(this); + } + + @Test + public void testSendServiceCategoryCreateCallback() { + // Arrange + ServiceCategory serviceCategory = new ServiceCategory(); + serviceCategory.setUuid("test-category-123"); + serviceCategory.setName("Test Category"); + + ServiceCategoryCreateEvent event = new ServiceCategoryCreateEvent(); + event.setServiceCategory(serviceCategory); + + EventSubscription subscription1 = new EventSubscription(); + subscription1.setId("sub-1"); + subscription1.setCallback("http://localhost:8080/callback"); + + EventSubscription subscription2 = new EventSubscription(); + subscription2.setId("sub-2"); + subscription2.setCallback("http://localhost:8081/callback"); + subscription2.setQuery("servicecategory"); + + List subscriptions = Arrays.asList(subscription1, subscription2); + + when(eventSubscriptionRepoService.findAll()).thenReturn(subscriptions); + when(restTemplate.exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Act + serviceCatalogCallbackService.sendServiceCategoryCreateCallback(event); + + // Assert + verify(restTemplate, times(2)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); + } + + @Test + public void testSendServiceCategoryDeleteCallback() { + // Arrange + ServiceCategory serviceCategory = new ServiceCategory(); + serviceCategory.setUuid("test-category-456"); + serviceCategory.setName("Test Category to Delete"); + + ServiceCategoryDeleteEvent event = new ServiceCategoryDeleteEvent(); + event.setServiceCategory(serviceCategory); + + EventSubscription subscription = new EventSubscription(); + subscription.setId("sub-1"); + subscription.setCallback("http://localhost:8080/callback"); + subscription.setQuery("servicecategory.delete"); + + List subscriptions = Arrays.asList(subscription); + + when(eventSubscriptionRepoService.findAll()).thenReturn(subscriptions); + when(restTemplate.exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Act + serviceCatalogCallbackService.sendServiceCategoryDeleteCallback(event); + + // Assert + verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); + } + + @Test + public void testSendServiceSpecificationCreateCallback() { + // Arrange + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setUuid("test-spec-123"); + serviceSpecification.setName("Test Specification"); + + ServiceSpecificationCreateEvent event = new ServiceSpecificationCreateEvent(); + event.setServiceSpecification(serviceSpecification); + + EventSubscription subscription = new EventSubscription(); + subscription.setId("sub-1"); + subscription.setCallback("http://localhost:8080/callback"); + subscription.setQuery("servicespecification.create"); + + List subscriptions = Arrays.asList(subscription); + + when(eventSubscriptionRepoService.findAll()).thenReturn(subscriptions); + when(restTemplate.exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Act + serviceCatalogCallbackService.sendServiceSpecificationCreateCallback(event); + + // Assert + verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); + } + + @Test + public void testSendServiceSpecificationDeleteCallback() { + // Arrange + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setUuid("test-spec-456"); + serviceSpecification.setName("Test Specification to Delete"); + + ServiceSpecificationDeleteEvent event = new ServiceSpecificationDeleteEvent(); + event.setServiceSpecification(serviceSpecification); + + EventSubscription subscription = new EventSubscription(); + subscription.setId("sub-1"); + subscription.setCallback("http://localhost:8080/callback"); + + List subscriptions = Arrays.asList(subscription); + + when(eventSubscriptionRepoService.findAll()).thenReturn(subscriptions); + when(restTemplate.exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Act + serviceCatalogCallbackService.sendServiceSpecificationDeleteCallback(event); + + // Assert + verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); + } + + @Test + public void testSendServiceSpecificationChangeCallback() { + // Arrange + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setUuid("test-spec-789"); + serviceSpecification.setName("Test Specification to Change"); + + ServiceSpecificationChangeEvent event = new ServiceSpecificationChangeEvent(); + event.setServiceSpecification(serviceSpecification); + + EventSubscription subscription = new EventSubscription(); + subscription.setId("sub-1"); + subscription.setCallback("http://localhost:8080/callback"); + subscription.setQuery("servicespecification.change"); + + List subscriptions = Arrays.asList(subscription); + + when(eventSubscriptionRepoService.findAll()).thenReturn(subscriptions); + when(restTemplate.exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Act + serviceCatalogCallbackService.sendServiceSpecificationChangeCallback(event); + + // Assert + verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); + } + + @Test + public void testShouldNotifySubscriptionWithNoQuery() { + // Test that subscriptions with no query receive all events + EventSubscription subscription = new EventSubscription(); + subscription.setId("sub-1"); + subscription.setCallback("http://localhost:8080/callback"); + // No query set + + ServiceCategoryCreateEvent event = new ServiceCategoryCreateEvent(); + ServiceCategory serviceCategory = new ServiceCategory(); + serviceCategory.setName("Test"); + event.setServiceCategory(serviceCategory); + + List subscriptions = Arrays.asList(subscription); + + when(eventSubscriptionRepoService.findAll()).thenReturn(subscriptions); + when(restTemplate.exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Act + serviceCatalogCallbackService.sendServiceCategoryCreateCallback(event); + + // Assert - should call callback even with no query + verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); + } + + @Test + public void testShouldNotifySubscriptionWithMatchingQuery() { + // Test specific query matching + EventSubscription subscription = new EventSubscription(); + subscription.setId("sub-1"); + subscription.setCallback("http://localhost:8080/callback"); + subscription.setQuery("servicespecification"); + + ServiceSpecificationCreateEvent event = new ServiceSpecificationCreateEvent(); + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setName("Test"); + event.setServiceSpecification(serviceSpecification); + + List subscriptions = Arrays.asList(subscription); + + when(eventSubscriptionRepoService.findAll()).thenReturn(subscriptions); + when(restTemplate.exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Act + serviceCatalogCallbackService.sendServiceSpecificationCreateCallback(event); + + // Assert + verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogManagementNotificationEndToEndTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogManagementNotificationEndToEndTest.java new file mode 100644 index 00000000..b8021f7a --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogManagementNotificationEndToEndTest.java @@ -0,0 +1,307 @@ +package org.etsi.osl.services.api.scm633; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.List; + +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.scm633.api.ServiceCatalogApiRouteBuilderEvents; +import org.etsi.osl.tmf.scm633.model.EventSubscription; +import org.etsi.osl.tmf.scm633.model.ServiceCatalog; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogCreate; +import org.etsi.osl.tmf.scm633.model.ServiceCategory; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreate; +import org.etsi.osl.tmf.scm633.model.ServiceSpecification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreate; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationUpdate; +import org.etsi.osl.tmf.scm633.reposervices.CatalogRepoService; +import org.etsi.osl.tmf.scm633.reposervices.CategoryRepoService; +import org.etsi.osl.tmf.scm633.reposervices.EventSubscriptionRepoService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceCatalogCallbackService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceCatalogNotificationService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceCategoryNotificationService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceSpecificationNotificationService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceSpecificationRepoService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.context.WebApplicationContext; + +@RunWith(SpringRunner.class) +@Transactional +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = OpenAPISpringBoot.class) +@AutoConfigureMockMvc +@ActiveProfiles("testing") +@AutoConfigureTestDatabase +public class ServiceCatalogManagementNotificationEndToEndTest { + + @Autowired + private MockMvc mvc; + + @Autowired + private WebApplicationContext context; + + @Autowired + private CatalogRepoService catalogRepoService; + + @Autowired + private CategoryRepoService categoryRepoService; + + @Autowired + private ServiceSpecificationRepoService serviceSpecificationRepoService; + + @SpyBean + @Qualifier("scm633EventSubscriptionRepoService") + private EventSubscriptionRepoService eventSubscriptionRepoService; + + @SpyBean + private ServiceCatalogNotificationService serviceCatalogNotificationService; + + @SpyBean + private ServiceCategoryNotificationService serviceCategoryNotificationService; + + @SpyBean + private ServiceSpecificationNotificationService serviceSpecificationNotificationService; + + // NOTE: We don't use @SpyBean on ServiceCatalogApiRouteBuilderEvents because it extends Camel's RouteBuilder + // which has void methods that cause Mockito conflicts during Spring context initialization. + // Instead, we verify the notification flow at the service level, which provides sufficient coverage. + + @SpyBean + private ServiceCatalogCallbackService callbackService; + + @MockBean + private RestTemplate restTemplate; + + @Before + public void setup() { + MockitoAnnotations.openMocks(this); + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + + // Reset all mocks to clear state between tests + reset(eventSubscriptionRepoService); + reset(serviceCatalogNotificationService); + reset(serviceCategoryNotificationService); + reset(serviceSpecificationNotificationService); + reset(callbackService); + reset(restTemplate); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testCompleteServiceCatalogManagementNotificationFlow() { + // Setup event subscription for testing callbacks + EventSubscription subscription = new EventSubscription(); + subscription.setCallback("http://localhost:8080/test-callback"); + subscription.setQuery("servicecatalog"); + + when(eventSubscriptionRepoService.findAll()).thenReturn(Arrays.asList(subscription)); + when(restTemplate.exchange(any(String.class), any(), any(), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Test Service Catalog lifecycle + ServiceCatalogCreate catalogCreate = new ServiceCatalogCreate(); + catalogCreate.setName("End-to-End Test Catalog"); + catalogCreate.setDescription("A catalog for end-to-end testing"); + + ServiceCatalog createdCatalog = catalogRepoService.addCatalog(catalogCreate); + + // Verify catalog create notification flow + verify(serviceCatalogNotificationService, timeout(5000).times(1)) + .publishServiceCatalogCreateNotification(any(ServiceCatalog.class)); + verify(callbackService, timeout(5000).times(1)) + .sendServiceCatalogCreateCallback(any()); + + // Delete catalog + catalogRepoService.deleteById(createdCatalog.getUuid()); + + // Verify catalog delete notification flow + verify(serviceCatalogNotificationService, timeout(5000).times(1)) + .publishServiceCatalogDeleteNotification(any(ServiceCatalog.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testCompleteServiceCategoryNotificationFlow() { + // Setup event subscription for testing callbacks + EventSubscription subscription = new EventSubscription(); + subscription.setCallback("http://localhost:8080/test-callback"); + subscription.setQuery("servicecategory"); + + when(eventSubscriptionRepoService.findAll()).thenReturn(Arrays.asList(subscription)); + when(restTemplate.exchange(any(String.class), any(), any(), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Test Service Category lifecycle + ServiceCategoryCreate categoryCreate = new ServiceCategoryCreate(); + categoryCreate.setName("End-to-End Test Category"); + categoryCreate.setDescription("A category for end-to-end testing"); + + ServiceCategory createdCategory = categoryRepoService.addCategory(categoryCreate); + + // Verify category create notification flow + verify(serviceCategoryNotificationService, timeout(5000).times(1)) + .publishServiceCategoryCreateNotification(any(ServiceCategory.class)); + verify(callbackService, timeout(5000).times(1)) + .sendServiceCategoryCreateCallback(any()); + + // Delete category + categoryRepoService.deleteById(createdCategory.getUuid()); + + // Verify category delete notification flow + verify(serviceCategoryNotificationService, timeout(5000).times(1)) + .publishServiceCategoryDeleteNotification(any(ServiceCategory.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testCompleteServiceSpecificationNotificationFlow() { + // Setup event subscription for testing callbacks + EventSubscription subscription = new EventSubscription(); + subscription.setCallback("http://localhost:8080/test-callback"); + subscription.setQuery("servicespecification"); + + when(eventSubscriptionRepoService.findAll()).thenReturn(Arrays.asList(subscription)); + when(restTemplate.exchange(any(String.class), any(), any(), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Test Service Specification lifecycle + ServiceSpecificationCreate specCreate = new ServiceSpecificationCreate(); + specCreate.setName("End-to-End Test Specification"); + specCreate.setDescription("A specification for end-to-end testing"); + + ServiceSpecification createdSpec = serviceSpecificationRepoService.addServiceSpecification(specCreate); + + // Verify specification create notification flow + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationCreateNotification(any(ServiceSpecification.class)); + verify(callbackService, timeout(5000).times(1)) + .sendServiceSpecificationCreateCallback(any()); + + // Update specification + ServiceSpecificationUpdate specUpdate = new ServiceSpecificationUpdate(); + specUpdate.setDescription("Updated description for end-to-end testing"); + + ServiceSpecification updatedSpec = serviceSpecificationRepoService.updateServiceSpecification(createdSpec.getUuid(), specUpdate); + + // Verify specification change notification flow + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationChangeNotification(any(ServiceSpecification.class)); + + // Delete specification + serviceSpecificationRepoService.deleteByUuid(createdSpec.getUuid()); + + // Verify specification delete notification flow + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationDeleteNotification(any(ServiceSpecification.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testMultipleSubscriptionsWithDifferentQueries() { + // Setup multiple event subscriptions with different query filters + EventSubscription allEventsSubscription = new EventSubscription(); + allEventsSubscription.setCallback("http://localhost:8080/all-events"); + // No query - should receive all events + + EventSubscription catalogOnlySubscription = new EventSubscription(); + catalogOnlySubscription.setCallback("http://localhost:8080/catalog-only"); + catalogOnlySubscription.setQuery("servicecatalog"); + + EventSubscription categoryOnlySubscription = new EventSubscription(); + categoryOnlySubscription.setCallback("http://localhost:8080/category-only"); + categoryOnlySubscription.setQuery("servicecategory"); + + EventSubscription specOnlySubscription = new EventSubscription(); + specOnlySubscription.setCallback("http://localhost:8080/spec-only"); + specOnlySubscription.setQuery("servicespecification"); + + List subscriptions = Arrays.asList( + allEventsSubscription, catalogOnlySubscription, categoryOnlySubscription, specOnlySubscription + ); + + when(eventSubscriptionRepoService.findAll()).thenReturn(subscriptions); + when(restTemplate.exchange(any(String.class), any(), any(), eq(String.class))) + .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + // Create entities to trigger notifications + ServiceCatalogCreate catalogCreate = new ServiceCatalogCreate(); + catalogCreate.setName("Multi-Subscription Test Catalog"); + ServiceCatalog catalog = catalogRepoService.addCatalog(catalogCreate); + + ServiceCategoryCreate categoryCreate = new ServiceCategoryCreate(); + categoryCreate.setName("Multi-Subscription Test Category"); + ServiceCategory category = categoryRepoService.addCategory(categoryCreate); + + ServiceSpecificationCreate specCreate = new ServiceSpecificationCreate(); + specCreate.setName("Multi-Subscription Test Specification"); + ServiceSpecification spec = serviceSpecificationRepoService.addServiceSpecification(specCreate); + + // Verify that callbacks are sent according to subscription filters + // All events subscription should receive all 3 callbacks + // Each specific subscription should receive only their relevant callback + + verify(callbackService, timeout(5000).times(1)) + .sendServiceCatalogCreateCallback(any()); + verify(callbackService, timeout(5000).times(1)) + .sendServiceCategoryCreateCallback(any()); + verify(callbackService, timeout(5000).times(1)) + .sendServiceSpecificationCreateCallback(any()); + + // Verify multiple HTTP calls are made for different subscriptions + verify(restTemplate, timeout(5000).atLeast(6)) + .exchange(any(String.class), any(), any(), eq(String.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testNotificationSystemWithInvalidCallback() { + // Setup event subscription with invalid callback URL + EventSubscription subscription = new EventSubscription(); + subscription.setCallback("http://invalid-callback-url:9999/callback"); + + when(eventSubscriptionRepoService.findAll()).thenReturn(Arrays.asList(subscription)); + when(restTemplate.exchange(any(String.class), any(), any(), eq(String.class))) + .thenThrow(new RuntimeException("Connection refused")); + + // Create entity to trigger notification + ServiceCatalogCreate catalogCreate = new ServiceCatalogCreate(); + catalogCreate.setName("Invalid Callback Test Catalog"); + ServiceCatalog catalog = catalogRepoService.addCatalog(catalogCreate); + + // Verify notification service still completes successfully even with callback failure + verify(serviceCatalogNotificationService, timeout(5000).times(1)) + .publishServiceCatalogCreateNotification(any(ServiceCatalog.class)); + + // Callback should be attempted but may fail gracefully + verify(callbackService, timeout(5000).times(1)) + .sendServiceCatalogCreateCallback(any()); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryNotificationIntegrationTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryNotificationIntegrationTest.java new file mode 100644 index 00000000..d89f9067 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryNotificationIntegrationTest.java @@ -0,0 +1,150 @@ +package org.etsi.osl.services.api.scm633; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; + +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.scm633.model.ServiceCategory; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreate; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteNotification; +import org.etsi.osl.tmf.scm633.reposervices.CategoryRepoService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceCategoryNotificationService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.WebApplicationContext; + +@RunWith(SpringRunner.class) +@Transactional +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = OpenAPISpringBoot.class) +@AutoConfigureMockMvc +@ActiveProfiles("testing") +@AutoConfigureTestDatabase +public class ServiceCategoryNotificationIntegrationTest { + + @Autowired + private MockMvc mvc; + + @Autowired + private WebApplicationContext context; + + @Autowired + private CategoryRepoService categoryRepoService; + + @SpyBean + private ServiceCategoryNotificationService serviceCategoryNotificationService; + + @Before + public void setup() { + MockitoAnnotations.openMocks(this); + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testServiceCategoryCreateNotificationTriggered() { + // Arrange + ServiceCategoryCreate serviceCategoryCreate = new ServiceCategoryCreate(); + serviceCategoryCreate.setName("Test Integration Category"); + serviceCategoryCreate.setDescription("A test service category for integration testing"); + + // Act + ServiceCategory createdCategory = categoryRepoService.addCategory(serviceCategoryCreate); + + // Assert + verify(serviceCategoryNotificationService, timeout(5000).times(1)) + .publishServiceCategoryCreateNotification(any(ServiceCategory.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testServiceCategoryDeleteNotificationTriggered() { + // Arrange - First create a category + ServiceCategoryCreate serviceCategoryCreate = new ServiceCategoryCreate(); + serviceCategoryCreate.setName("Test Category for Deletion"); + serviceCategoryCreate.setDescription("A test service category to be deleted"); + + ServiceCategory createdCategory = categoryRepoService.addCategory(serviceCategoryCreate); + String categoryId = createdCategory.getUuid(); + + // Act - Delete the category + boolean deleted = categoryRepoService.deleteById(categoryId); + + // Assert - Focus only on delete notification + verify(serviceCategoryNotificationService, timeout(5000).times(1)) + .publishServiceCategoryDeleteNotification(any(ServiceCategory.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testServiceCategoryAddWithDirectObjectNotificationTriggered() { + // Arrange + ServiceCategory serviceCategory = new ServiceCategory(); + serviceCategory.setName("Test Direct Category"); + serviceCategory.setDescription("A test service category added directly"); + + // Act + ServiceCategory createdCategory = categoryRepoService.addCategory(serviceCategory); + + // Assert + verify(serviceCategoryNotificationService, timeout(5000).times(1)) + .publishServiceCategoryCreateNotification(any(ServiceCategory.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testServiceCategoryDeleteWithNonExistentId() { + // Act + boolean deleted = categoryRepoService.deleteById("non-existent-id"); + + // Assert - No notification should be triggered for non-existent categories + verify(serviceCategoryNotificationService, timeout(2000).times(0)) + .publishServiceCategoryDeleteNotification(any(ServiceCategory.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testMultipleServiceCategoryOperationsNotifications() { + // Test multiple operations to ensure notifications are properly triggered + + // Create first category + ServiceCategoryCreate category1 = new ServiceCategoryCreate(); + category1.setName("Test Category 1"); + category1.setDescription("First test category"); + ServiceCategory created1 = categoryRepoService.addCategory(category1); + + // Create second category + ServiceCategoryCreate category2 = new ServiceCategoryCreate(); + category2.setName("Test Category 2"); + category2.setDescription("Second test category"); + ServiceCategory created2 = categoryRepoService.addCategory(category2); + + // Delete first category + boolean deleted1 = categoryRepoService.deleteById(created1.getUuid()); + + // Assert multiple notifications + verify(serviceCategoryNotificationService, timeout(5000).times(2)) + .publishServiceCategoryCreateNotification(any(ServiceCategory.class)); + verify(serviceCategoryNotificationService, timeout(5000).times(1)) + .publishServiceCategoryDeleteNotification(any(ServiceCategory.class)); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryNotificationServiceTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryNotificationServiceTest.java new file mode 100644 index 00000000..e78236b7 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryNotificationServiceTest.java @@ -0,0 +1,102 @@ +package org.etsi.osl.services.api.scm633; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.etsi.osl.tmf.scm633.api.ServiceCatalogApiRouteBuilderEvents; +import org.etsi.osl.tmf.scm633.model.ServiceCategory; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteNotification; +import org.etsi.osl.tmf.scm633.reposervices.ServiceCatalogCallbackService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceCategoryNotificationService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ActiveProfiles("testing") +public class ServiceCategoryNotificationServiceTest { + + @Mock + private ServiceCatalogApiRouteBuilderEvents eventPublisher; + + @Mock + private ServiceCatalogCallbackService serviceCatalogCallbackService; + + @InjectMocks + private ServiceCategoryNotificationService serviceCategoryNotificationService; + + @Before + public void setup() { + MockitoAnnotations.openMocks(this); + } + + @Test + public void testPublishServiceCategoryCreateNotification() { + // Arrange + ServiceCategory serviceCategory = new ServiceCategory(); + serviceCategory.setUuid("test-category-123"); + serviceCategory.setName("Test Service Category"); + serviceCategory.setDescription("A test service category for notifications"); + + // Act + serviceCategoryNotificationService.publishServiceCategoryCreateNotification(serviceCategory); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceCategoryCreateNotification.class), eq("test-category-123")); + verify(serviceCatalogCallbackService, times(1)).sendServiceCategoryCreateCallback(any()); + } + + @Test + public void testPublishServiceCategoryDeleteNotification() { + // Arrange + ServiceCategory serviceCategory = new ServiceCategory(); + serviceCategory.setUuid("test-category-456"); + serviceCategory.setName("Test Service Category to Delete"); + serviceCategory.setDescription("A test service category for deletion notifications"); + + // Act + serviceCategoryNotificationService.publishServiceCategoryDeleteNotification(serviceCategory); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceCategoryDeleteNotification.class), eq("test-category-456")); + verify(serviceCatalogCallbackService, times(1)).sendServiceCategoryDeleteCallback(any()); + } + + @Test + public void testPublishServiceCategoryCreateNotificationWithNullUuid() { + // Arrange + ServiceCategory serviceCategory = new ServiceCategory(); + serviceCategory.setName("Test Service Category with Null UUID"); + serviceCategory.setDescription("A test service category with null UUID"); + + // Act + serviceCategoryNotificationService.publishServiceCategoryCreateNotification(serviceCategory); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceCategoryCreateNotification.class), eq(null)); + verify(serviceCatalogCallbackService, times(1)).sendServiceCategoryCreateCallback(any()); + } + + @Test + public void testPublishServiceCategoryDeleteNotificationWithNullUuid() { + // Arrange + ServiceCategory serviceCategory = new ServiceCategory(); + serviceCategory.setName("Test Service Category with Null UUID"); + serviceCategory.setDescription("A test service category with null UUID"); + + // Act + serviceCategoryNotificationService.publishServiceCategoryDeleteNotification(serviceCategory); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceCategoryDeleteNotification.class), eq(null)); + verify(serviceCatalogCallbackService, times(1)).sendServiceCategoryDeleteCallback(any()); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationNotificationIntegrationTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationNotificationIntegrationTest.java new file mode 100644 index 00000000..2e5944ad --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationNotificationIntegrationTest.java @@ -0,0 +1,199 @@ +package org.etsi.osl.services.api.scm633; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; + +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.scm633.model.ServiceSpecification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreate; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationUpdate; +import org.etsi.osl.tmf.scm633.reposervices.ServiceSpecificationNotificationService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceSpecificationRepoService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.WebApplicationContext; + +@RunWith(SpringRunner.class) +@Transactional +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = OpenAPISpringBoot.class) +@AutoConfigureMockMvc +@ActiveProfiles("testing") +@AutoConfigureTestDatabase +public class ServiceSpecificationNotificationIntegrationTest { + + @Autowired + private MockMvc mvc; + + @Autowired + private WebApplicationContext context; + + @Autowired + private ServiceSpecificationRepoService serviceSpecificationRepoService; + + @SpyBean + private ServiceSpecificationNotificationService serviceSpecificationNotificationService; + + @Before + public void setup() { + MockitoAnnotations.openMocks(this); + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testServiceSpecificationCreateNotificationTriggered() { + // Arrange + ServiceSpecificationCreate serviceSpecificationCreate = new ServiceSpecificationCreate(); + serviceSpecificationCreate.setName("Test Integration Specification"); + serviceSpecificationCreate.setDescription("A test service specification for integration testing"); + + // Act + ServiceSpecification createdSpec = serviceSpecificationRepoService.addServiceSpecification(serviceSpecificationCreate); + + // Assert + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationCreateNotification(any(ServiceSpecification.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testServiceSpecificationUpdateNotificationTriggered() { + // Arrange - First create a specification + ServiceSpecificationCreate serviceSpecificationCreate = new ServiceSpecificationCreate(); + serviceSpecificationCreate.setName("Test Specification for Update"); + serviceSpecificationCreate.setDescription("A test service specification to be updated"); + + ServiceSpecification createdSpec = serviceSpecificationRepoService.addServiceSpecification(serviceSpecificationCreate); + String specId = createdSpec.getUuid(); + + // Act - Update the specification + ServiceSpecificationUpdate serviceSpecificationUpdate = new ServiceSpecificationUpdate(); + serviceSpecificationUpdate.setDescription("Updated description"); + + ServiceSpecification updatedSpec = serviceSpecificationRepoService.updateServiceSpecification(specId, serviceSpecificationUpdate); + + // Assert + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationCreateNotification(any(ServiceSpecification.class)); + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationChangeNotification(any(ServiceSpecification.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testServiceSpecificationDeleteNotificationTriggered() { + // Arrange - First create a specification + ServiceSpecificationCreate serviceSpecificationCreate = new ServiceSpecificationCreate(); + serviceSpecificationCreate.setName("Test Specification for Deletion"); + serviceSpecificationCreate.setDescription("A test service specification to be deleted"); + + ServiceSpecification createdSpec = serviceSpecificationRepoService.addServiceSpecification(serviceSpecificationCreate); + String specId = createdSpec.getUuid(); + + // Act - Delete the specification + serviceSpecificationRepoService.deleteByUuid(specId); + + // Assert - Focus only on delete notification + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationDeleteNotification(any(ServiceSpecification.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testServiceSpecificationUpdateWithNullSpecification() { + // Act - Try to update a non-existent specification + ServiceSpecificationUpdate serviceSpecificationUpdate = new ServiceSpecificationUpdate(); + serviceSpecificationUpdate.setDescription("Updated description"); + + ServiceSpecification result = serviceSpecificationRepoService.updateServiceSpecification("non-existent-id", serviceSpecificationUpdate); + + // Assert - No notification should be triggered for non-existent specifications + verify(serviceSpecificationNotificationService, timeout(2000).times(0)) + .publishServiceSpecificationChangeNotification(any(ServiceSpecification.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testMultipleServiceSpecificationOperationsNotifications() { + // Test multiple operations to ensure notifications are properly triggered + + // Create first specification + ServiceSpecificationCreate spec1 = new ServiceSpecificationCreate(); + spec1.setName("Test Specification 1"); + spec1.setDescription("First test specification"); + ServiceSpecification created1 = serviceSpecificationRepoService.addServiceSpecification(spec1); + + // Create second specification + ServiceSpecificationCreate spec2 = new ServiceSpecificationCreate(); + spec2.setName("Test Specification 2"); + spec2.setDescription("Second test specification"); + ServiceSpecification created2 = serviceSpecificationRepoService.addServiceSpecification(spec2); + + // Update first specification + ServiceSpecificationUpdate spec1Update = new ServiceSpecificationUpdate(); + spec1Update.setDescription("Updated first specification"); + ServiceSpecification updated1 = serviceSpecificationRepoService.updateServiceSpecification(created1.getUuid(), spec1Update); + + // Delete second specification + serviceSpecificationRepoService.deleteByUuid(created2.getUuid()); + + // Assert multiple notifications + verify(serviceSpecificationNotificationService, timeout(5000).times(2)) + .publishServiceSpecificationCreateNotification(any(ServiceSpecification.class)); + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationChangeNotification(any(ServiceSpecification.class)); + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationDeleteNotification(any(ServiceSpecification.class)); + } + + @Test + @WithMockUser(username = "osadmin", roles = {"ADMIN"}) + public void testServiceSpecificationLifecycleNotifications() { + // Test complete lifecycle: Create -> Update -> Delete + + // Create + ServiceSpecificationCreate serviceSpecificationCreate = new ServiceSpecificationCreate(); + serviceSpecificationCreate.setName("Lifecycle Test Specification"); + serviceSpecificationCreate.setDescription("A specification for lifecycle testing"); + + ServiceSpecification createdSpec = serviceSpecificationRepoService.addServiceSpecification(serviceSpecificationCreate); + String specId = createdSpec.getUuid(); + + // Update + ServiceSpecificationUpdate serviceSpecificationUpdate = new ServiceSpecificationUpdate(); + serviceSpecificationUpdate.setName("Updated Lifecycle Test Specification"); + serviceSpecificationUpdate.setDescription("Updated description for lifecycle testing"); + + ServiceSpecification updatedSpec = serviceSpecificationRepoService.updateServiceSpecification(specId, serviceSpecificationUpdate); + + // Delete + serviceSpecificationRepoService.deleteByUuid(specId); + + // Assert complete lifecycle notifications + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationCreateNotification(any(ServiceSpecification.class)); + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationChangeNotification(any(ServiceSpecification.class)); + verify(serviceSpecificationNotificationService, timeout(5000).times(1)) + .publishServiceSpecificationDeleteNotification(any(ServiceSpecification.class)); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationNotificationServiceTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationNotificationServiceTest.java new file mode 100644 index 00000000..ac4338a1 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationNotificationServiceTest.java @@ -0,0 +1,134 @@ +package org.etsi.osl.services.api.scm633; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.etsi.osl.tmf.scm633.api.ServiceCatalogApiRouteBuilderEvents; +import org.etsi.osl.tmf.scm633.model.ServiceSpecification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeNotification; +import org.etsi.osl.tmf.scm633.reposervices.ServiceCatalogCallbackService; +import org.etsi.osl.tmf.scm633.reposervices.ServiceSpecificationNotificationService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ActiveProfiles("testing") +public class ServiceSpecificationNotificationServiceTest { + + @Mock + private ServiceCatalogApiRouteBuilderEvents eventPublisher; + + @Mock + private ServiceCatalogCallbackService serviceCatalogCallbackService; + + @InjectMocks + private ServiceSpecificationNotificationService serviceSpecificationNotificationService; + + @Before + public void setup() { + MockitoAnnotations.openMocks(this); + } + + @Test + public void testPublishServiceSpecificationCreateNotification() { + // Arrange + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setUuid("test-spec-123"); + serviceSpecification.setName("Test Service Specification"); + serviceSpecification.setDescription("A test service specification for notifications"); + + // Act + serviceSpecificationNotificationService.publishServiceSpecificationCreateNotification(serviceSpecification); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceSpecificationCreateNotification.class), eq("test-spec-123")); + verify(serviceCatalogCallbackService, times(1)).sendServiceSpecificationCreateCallback(any()); + } + + @Test + public void testPublishServiceSpecificationDeleteNotification() { + // Arrange + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setUuid("test-spec-456"); + serviceSpecification.setName("Test Service Specification to Delete"); + serviceSpecification.setDescription("A test service specification for deletion notifications"); + + // Act + serviceSpecificationNotificationService.publishServiceSpecificationDeleteNotification(serviceSpecification); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceSpecificationDeleteNotification.class), eq("test-spec-456")); + verify(serviceCatalogCallbackService, times(1)).sendServiceSpecificationDeleteCallback(any()); + } + + @Test + public void testPublishServiceSpecificationChangeNotification() { + // Arrange + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setUuid("test-spec-789"); + serviceSpecification.setName("Test Service Specification to Change"); + serviceSpecification.setDescription("A test service specification for change notifications"); + + // Act + serviceSpecificationNotificationService.publishServiceSpecificationChangeNotification(serviceSpecification); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceSpecificationChangeNotification.class), eq("test-spec-789")); + verify(serviceCatalogCallbackService, times(1)).sendServiceSpecificationChangeCallback(any()); + } + + @Test + public void testPublishServiceSpecificationCreateNotificationWithNullUuid() { + // Arrange + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setName("Test Service Specification with Null UUID"); + serviceSpecification.setDescription("A test service specification with null UUID"); + + // Act + serviceSpecificationNotificationService.publishServiceSpecificationCreateNotification(serviceSpecification); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceSpecificationCreateNotification.class), eq(null)); + verify(serviceCatalogCallbackService, times(1)).sendServiceSpecificationCreateCallback(any()); + } + + @Test + public void testPublishServiceSpecificationDeleteNotificationWithNullUuid() { + // Arrange + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setName("Test Service Specification with Null UUID"); + serviceSpecification.setDescription("A test service specification with null UUID"); + + // Act + serviceSpecificationNotificationService.publishServiceSpecificationDeleteNotification(serviceSpecification); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceSpecificationDeleteNotification.class), eq(null)); + verify(serviceCatalogCallbackService, times(1)).sendServiceSpecificationDeleteCallback(any()); + } + + @Test + public void testPublishServiceSpecificationChangeNotificationWithNullUuid() { + // Arrange + ServiceSpecification serviceSpecification = new ServiceSpecification(); + serviceSpecification.setName("Test Service Specification with Null UUID"); + serviceSpecification.setDescription("A test service specification with null UUID"); + + // Act + serviceSpecificationNotificationService.publishServiceSpecificationChangeNotification(serviceSpecification); + + // Assert + verify(eventPublisher, times(1)).publishEvent(any(ServiceSpecificationChangeNotification.class), eq(null)); + verify(serviceCatalogCallbackService, times(1)).sendServiceSpecificationChangeCallback(any()); + } +} \ No newline at end of file diff --git a/src/test/resources/testEventSubscriptionInput.json b/src/test/resources/testEventSubscriptionInput.json index bccdb0cd..e55a4601 100644 --- a/src/test/resources/testEventSubscriptionInput.json +++ b/src/test/resources/testEventSubscriptionInput.json @@ -1,3 +1,4 @@ { + "callback": "http://localhost:8080/callback", "query": "test" } \ No newline at end of file -- GitLab From 0d03f4daed21ec8ccced75657b11a172546cc60e Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Thu, 14 Aug 2025 00:56:33 +0300 Subject: [PATCH 4/5] fix for #84 --- .../tmf/scm633/api/ListenerApiController.java | 244 ++++++++---------- .../ServiceCatalogCallbackService.java | 213 ++++++++------- .../ServiceCatalogNotificationService.java | 4 +- .../ServiceCategoryNotificationService.java | 4 +- ...rviceSpecificationNotificationService.java | 6 +- .../api/scm633/ListenerApiControllerTest.java | 52 ++-- ...iceCatalogCallbackServiceExtendedTest.java | 35 ++- 7 files changed, 280 insertions(+), 278 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/scm633/api/ListenerApiController.java b/src/main/java/org/etsi/osl/tmf/scm633/api/ListenerApiController.java index 912e48f6..9f19fb8c 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/api/ListenerApiController.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/api/ListenerApiController.java @@ -19,7 +19,7 @@ */ package org.etsi.osl.tmf.scm633.api; -import java.io.IOException; +import java.util.Optional; import com.fasterxml.jackson.databind.ObjectMapper; import org.etsi.osl.tmf.scm633.model.EventSubscription; @@ -64,186 +64,168 @@ public class ListenerApiController implements ListenerApi { this.request = request; } + public Optional getObjectMapper() { + return Optional.ofNullable(objectMapper); + } + + public Optional getRequest() { + return Optional.ofNullable(request); + } + + @Override public ResponseEntity listenToServiceCandidateChangeNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCandidateChangeNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCandidateChangeNotification: {}", data.getEventId()); + log.debug("ServiceCandidateChangeNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCandidateChangeNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceCandidateCreateNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCandidateCreateNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCandidateCreateNotification: {}", data.getEventId()); + log.debug("ServiceCandidateCreateNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCandidateCreateNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceCandidateDeleteNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCandidateDeleteNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCandidateDeleteNotification: {}", data.getEventId()); + log.debug("ServiceCandidateDeleteNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCandidateDeleteNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceCatalogBatchNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCatalogBatchNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCatalogBatchNotification: {}", data.getEventId()); + log.debug("ServiceCatalogBatchNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCatalogBatchNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceCatalogChangeNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCatalogChangeNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCatalogChangeNotification: {}", data.getEventId()); + log.debug("ServiceCatalogChangeNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCatalogChangeNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceCatalogCreateNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCatalogCreateNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCatalogCreateNotification: {}", data.getEventId()); + log.debug("ServiceCatalogCreateNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCatalogCreateNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceCatalogDeleteNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCatalogDeleteNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCatalogDeleteNotification: {}", data.getEventId()); + log.debug("ServiceCatalogDeleteNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCatalogDeleteNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceCategoryChangeNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCategoryChangeNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCategoryChangeNotification: {}", data.getEventId()); + log.debug("ServiceCategoryChangeNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCategoryChangeNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceCategoryCreateNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCategoryCreateNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCategoryCreateNotification: {}", data.getEventId()); + log.debug("ServiceCategoryCreateNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCategoryCreateNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceCategoryDeleteNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceCategoryDeleteNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceCategoryDeleteNotification: {}", data.getEventId()); + log.debug("ServiceCategoryDeleteNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceCategoryDeleteNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceSpecificationChangeNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceSpecificationChangeNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceSpecificationChangeNotification: {}", data.getEventId()); + log.debug("ServiceSpecificationChangeNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceSpecificationChangeNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceSpecificationCreateNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceSpecificationCreateNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceSpecificationCreateNotification: {}", data.getEventId()); + log.debug("ServiceSpecificationCreateNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceSpecificationCreateNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } + @Override public ResponseEntity listenToServiceSpecificationDeleteNotification(@Parameter(description = "The event data" ,required=true ) @Valid @RequestBody ServiceSpecificationDeleteNotification data) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"query\" : \"query\", \"callback\" : \"callback\", \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } + try { + log.info("Received ServiceSpecificationDeleteNotification: {}", data.getEventId()); + log.debug("ServiceSpecificationDeleteNotification details: {}", data); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + log.error("Error processing ServiceSpecificationDeleteNotification", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); } } diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogCallbackService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogCallbackService.java index 592b834b..57d9ea47 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogCallbackService.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogCallbackService.java @@ -20,15 +20,14 @@ package org.etsi.osl.tmf.scm633.reposervices; import java.util.List; - -import org.etsi.osl.tmf.scm633.model.ServiceCatalogCreateEvent; -import org.etsi.osl.tmf.scm633.model.ServiceCatalogDeleteEvent; -import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateEvent; -import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteEvent; -import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateEvent; -import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteEvent; -import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeEvent; import org.etsi.osl.tmf.scm633.model.EventSubscription; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCatalogDeleteNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateNotification; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteNotification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -48,84 +47,84 @@ public class ServiceCatalogCallbackService { @Autowired @Qualifier("scm633EventSubscriptionRepoService") - private EventSubscriptionRepoService eventSubscriptionRepoService; + private EventSubscriptionRepoService notificationSubscriptionRepoService; @Autowired private RestTemplate restTemplate; /** - * Send service catalog create event to all registered callback URLs - * @param serviceCatalogCreateEvent The service catalog create event to send + * Send service catalog create notification to all registered callback URLs + * @param serviceCatalogCreateNotification The service catalog create notification to send */ - public void sendServiceCatalogCreateCallback(ServiceCatalogCreateEvent serviceCatalogCreateEvent) { - List subscriptions = eventSubscriptionRepoService.findAll(); + public void sendServiceCatalogCreateCallback(ServiceCatalogCreateNotification serviceCatalogCreateNotification) { + List subscriptions = notificationSubscriptionRepoService.findAll(); for (EventSubscription subscription : subscriptions) { - if (shouldNotifySubscription(subscription, "serviceCatalogCreateEvent")) { - sendServiceCatalogCreateEventToCallback(subscription.getCallback(), serviceCatalogCreateEvent); + if (shouldNotifySubscription(subscription, "serviceCatalogCreateNotification")) { + sendServiceCatalogCreateNotificationToCallback(subscription.getCallback(), serviceCatalogCreateNotification); } } } /** - * Send service catalog delete event to all registered callback URLs - * @param serviceCatalogDeleteEvent The service catalog delete event to send + * Send service catalog delete notification to all registered callback URLs + * @param serviceCatalogDeleteEvent The service catalog delete notification to send */ - public void sendServiceCatalogDeleteCallback(ServiceCatalogDeleteEvent serviceCatalogDeleteEvent) { - List subscriptions = eventSubscriptionRepoService.findAll(); + public void sendServiceCatalogDeleteCallback(ServiceCatalogDeleteNotification serviceCatalogDeleteNotification) { + List subscriptions = notificationSubscriptionRepoService.findAll(); for (EventSubscription subscription : subscriptions) { - if (shouldNotifySubscription(subscription, "serviceCatalogDeleteEvent")) { - sendServiceCatalogDeleteEventToCallback(subscription.getCallback(), serviceCatalogDeleteEvent); + if (shouldNotifySubscription(subscription, "serviceCatalogDeleteNotification")) { + sendServiceCatalogDeleteNotificationToCallback(subscription.getCallback(), serviceCatalogDeleteNotification); } } } /** - * Send service catalog create event to a specific callback URL + * Send service catalog create notification to a specific callback URL * @param callbackUrl The callback URL to send to - * @param event The service catalog create event + * @param notification The service catalog create notification */ - private void sendServiceCatalogCreateEventToCallback(String callbackUrl, ServiceCatalogCreateEvent event) { + private void sendServiceCatalogCreateNotificationToCallback(String callbackUrl, ServiceCatalogCreateNotification notification) { try { - String url = buildCallbackUrl(callbackUrl, "/listener/serviceCatalogCreateEvent"); + String url = buildCallbackUrl(callbackUrl, "/listener/serviceCatalogCreateNotification"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(event, headers); + HttpEntity entity = new HttpEntity<>(notification, headers); ResponseEntity response = restTemplate.exchange( url, HttpMethod.POST, entity, String.class); - logger.info("Successfully sent service catalog create event to callback URL: {} - Response: {}", + logger.info("Successfully sent service catalog create notification to callback URL: {} - Response: {}", url, response.getStatusCode()); } catch (Exception e) { - logger.error("Failed to send service catalog create event to callback URL: {}", callbackUrl, e); + logger.error("Failed to send service catalog create notification to callback URL: {}", callbackUrl, e); } } /** - * Send service catalog delete event to a specific callback URL + * Send service catalog delete notification to a specific callback URL * @param callbackUrl The callback URL to send to - * @param event The service catalog delete event + * @param notification The service catalog delete notification */ - private void sendServiceCatalogDeleteEventToCallback(String callbackUrl, ServiceCatalogDeleteEvent event) { + private void sendServiceCatalogDeleteNotificationToCallback(String callbackUrl, ServiceCatalogDeleteNotification notification) { try { - String url = buildCallbackUrl(callbackUrl, "/listener/serviceCatalogDeleteEvent"); + String url = buildCallbackUrl(callbackUrl, "/listener/serviceCatalogDeleteNotification"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(event, headers); + HttpEntity entity = new HttpEntity<>(notification, headers); ResponseEntity response = restTemplate.exchange( url, HttpMethod.POST, entity, String.class); - logger.info("Successfully sent service catalog delete event to callback URL: {} - Response: {}", + logger.info("Successfully sent service catalog delete notification to callback URL: {} - Response: {}", url, response.getStatusCode()); } catch (Exception e) { - logger.error("Failed to send service catalog delete event to callback URL: {}", callbackUrl, e); + logger.error("Failed to send service catalog delete notification to callback URL: {}", callbackUrl, e); } } @@ -144,213 +143,213 @@ public class ServiceCatalogCallbackService { } /** - * Send service category create event to all registered callback URLs - * @param serviceCategoryCreateEvent The service category create event to send + * Send service category create notification to all registered callback URLs + * @param serviceCategoryCreateNotification The service category create notification to send */ - public void sendServiceCategoryCreateCallback(ServiceCategoryCreateEvent serviceCategoryCreateEvent) { - List subscriptions = eventSubscriptionRepoService.findAll(); + public void sendServiceCategoryCreateCallback(ServiceCategoryCreateNotification serviceCategoryCreateNotification) { + List subscriptions = notificationSubscriptionRepoService.findAll(); for (EventSubscription subscription : subscriptions) { - if (shouldNotifySubscription(subscription, "serviceCategoryCreateEvent")) { - sendServiceCategoryCreateEventToCallback(subscription.getCallback(), serviceCategoryCreateEvent); + if (shouldNotifySubscription(subscription, "serviceCategoryCreateNotification")) { + sendServiceCategoryCreateNotificationToCallback(subscription.getCallback(), serviceCategoryCreateNotification); } } } /** - * Send service category delete event to all registered callback URLs - * @param serviceCategoryDeleteEvent The service category delete event to send + * Send service category delete notification to all registered callback URLs + * @param serviceCategoryDeleteNotification The service category delete notification to send */ - public void sendServiceCategoryDeleteCallback(ServiceCategoryDeleteEvent serviceCategoryDeleteEvent) { - List subscriptions = eventSubscriptionRepoService.findAll(); + public void sendServiceCategoryDeleteCallback(ServiceCategoryDeleteNotification serviceCategoryDeleteNotification) { + List subscriptions = notificationSubscriptionRepoService.findAll(); for (EventSubscription subscription : subscriptions) { - if (shouldNotifySubscription(subscription, "serviceCategoryDeleteEvent")) { - sendServiceCategoryDeleteEventToCallback(subscription.getCallback(), serviceCategoryDeleteEvent); + if (shouldNotifySubscription(subscription, "serviceCategoryDeleteNotification")) { + sendServiceCategoryDeleteNotificationToCallback(subscription.getCallback(), serviceCategoryDeleteNotification); } } } /** - * Send service specification create event to all registered callback URLs - * @param serviceSpecificationCreateEvent The service specification create event to send + * Send service specification create notification to all registered callback URLs + * @param serviceSpecificationCreateNotification The service specification create notification to send */ - public void sendServiceSpecificationCreateCallback(ServiceSpecificationCreateEvent serviceSpecificationCreateEvent) { - List subscriptions = eventSubscriptionRepoService.findAll(); + public void sendServiceSpecificationCreateCallback(ServiceSpecificationCreateNotification serviceSpecificationCreateNotification) { + List subscriptions = notificationSubscriptionRepoService.findAll(); for (EventSubscription subscription : subscriptions) { - if (shouldNotifySubscription(subscription, "serviceSpecificationCreateEvent")) { - sendServiceSpecificationCreateEventToCallback(subscription.getCallback(), serviceSpecificationCreateEvent); + if (shouldNotifySubscription(subscription, "serviceSpecificationCreateNotification")) { + sendServiceSpecificationCreateNotificationToCallback(subscription.getCallback(), serviceSpecificationCreateNotification); } } } /** - * Send service specification delete event to all registered callback URLs - * @param serviceSpecificationDeleteEvent The service specification delete event to send + * Send service specification delete notification to all registered callback URLs + * @param serviceSpecificationDeleteNotification The service specification delete notification to send */ - public void sendServiceSpecificationDeleteCallback(ServiceSpecificationDeleteEvent serviceSpecificationDeleteEvent) { - List subscriptions = eventSubscriptionRepoService.findAll(); + public void sendServiceSpecificationDeleteCallback(ServiceSpecificationDeleteNotification serviceSpecificationDeleteNotification) { + List subscriptions = notificationSubscriptionRepoService.findAll(); for (EventSubscription subscription : subscriptions) { - if (shouldNotifySubscription(subscription, "serviceSpecificationDeleteEvent")) { - sendServiceSpecificationDeleteEventToCallback(subscription.getCallback(), serviceSpecificationDeleteEvent); + if (shouldNotifySubscription(subscription, "serviceSpecificationDeleteNotification")) { + sendServiceSpecificationDeleteNotificationToCallback(subscription.getCallback(), serviceSpecificationDeleteNotification); } } } /** - * Send service specification change event to all registered callback URLs - * @param serviceSpecificationChangeEvent The service specification change event to send + * Send service specification change notification to all registered callback URLs + * @param serviceSpecificationChangeNotification The service specification change notification to send */ - public void sendServiceSpecificationChangeCallback(ServiceSpecificationChangeEvent serviceSpecificationChangeEvent) { - List subscriptions = eventSubscriptionRepoService.findAll(); + public void sendServiceSpecificationChangeCallback(ServiceSpecificationChangeNotification serviceSpecificationChangeNotification) { + List subscriptions = notificationSubscriptionRepoService.findAll(); for (EventSubscription subscription : subscriptions) { - if (shouldNotifySubscription(subscription, "serviceSpecificationChangeEvent")) { - sendServiceSpecificationChangeEventToCallback(subscription.getCallback(), serviceSpecificationChangeEvent); + if (shouldNotifySubscription(subscription, "serviceSpecificationChangeNotification")) { + sendServiceSpecificationChangeNotificationToCallback(subscription.getCallback(), serviceSpecificationChangeNotification); } } } /** - * Send service category create event to a specific callback URL + * Send service category create notification to a specific callback URL * @param callbackUrl The callback URL to send to - * @param event The service category create event + * @param notification The service category create notification */ - private void sendServiceCategoryCreateEventToCallback(String callbackUrl, ServiceCategoryCreateEvent event) { + private void sendServiceCategoryCreateNotificationToCallback(String callbackUrl, ServiceCategoryCreateNotification notification) { try { - String url = buildCallbackUrl(callbackUrl, "/listener/serviceCategoryCreateEvent"); + String url = buildCallbackUrl(callbackUrl, "/listener/serviceCategoryCreateNotification"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(event, headers); + HttpEntity entity = new HttpEntity<>(notification, headers); ResponseEntity response = restTemplate.exchange( url, HttpMethod.POST, entity, String.class); - logger.info("Successfully sent service category create event to callback URL: {} - Response: {}", + logger.info("Successfully sent service category create notification to callback URL: {} - Response: {}", url, response.getStatusCode()); } catch (Exception e) { - logger.error("Failed to send service category create event to callback URL: {}", callbackUrl, e); + logger.error("Failed to send service category create notification to callback URL: {}", callbackUrl, e); } } /** - * Send service category delete event to a specific callback URL + * Send service category delete notification to a specific callback URL * @param callbackUrl The callback URL to send to - * @param event The service category delete event + * @param notification The service category delete notification */ - private void sendServiceCategoryDeleteEventToCallback(String callbackUrl, ServiceCategoryDeleteEvent event) { + private void sendServiceCategoryDeleteNotificationToCallback(String callbackUrl, ServiceCategoryDeleteNotification notification) { try { - String url = buildCallbackUrl(callbackUrl, "/listener/serviceCategoryDeleteEvent"); + String url = buildCallbackUrl(callbackUrl, "/listener/serviceCategoryDeleteNotification"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(event, headers); + HttpEntity entity = new HttpEntity<>(notification, headers); ResponseEntity response = restTemplate.exchange( url, HttpMethod.POST, entity, String.class); - logger.info("Successfully sent service category delete event to callback URL: {} - Response: {}", + logger.info("Successfully sent service category delete notification to callback URL: {} - Response: {}", url, response.getStatusCode()); } catch (Exception e) { - logger.error("Failed to send service category delete event to callback URL: {}", callbackUrl, e); + logger.error("Failed to send service category delete notification to callback URL: {}", callbackUrl, e); } } /** - * Send service specification create event to a specific callback URL + * Send service specification create notification to a specific callback URL * @param callbackUrl The callback URL to send to - * @param event The service specification create event + * @param notification The service specification create notification */ - private void sendServiceSpecificationCreateEventToCallback(String callbackUrl, ServiceSpecificationCreateEvent event) { + private void sendServiceSpecificationCreateNotificationToCallback(String callbackUrl, ServiceSpecificationCreateNotification notification) { try { - String url = buildCallbackUrl(callbackUrl, "/listener/serviceSpecificationCreateEvent"); + String url = buildCallbackUrl(callbackUrl, "/listener/serviceSpecificationCreateNotification"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(event, headers); + HttpEntity entity = new HttpEntity<>(notification, headers); ResponseEntity response = restTemplate.exchange( url, HttpMethod.POST, entity, String.class); - logger.info("Successfully sent service specification create event to callback URL: {} - Response: {}", + logger.info("Successfully sent service specification create notification to callback URL: {} - Response: {}", url, response.getStatusCode()); } catch (Exception e) { - logger.error("Failed to send service specification create event to callback URL: {}", callbackUrl, e); + logger.error("Failed to send service specification create notification to callback URL: {}", callbackUrl, e); } } /** - * Send service specification delete event to a specific callback URL + * Send service specification delete notification to a specific callback URL * @param callbackUrl The callback URL to send to - * @param event The service specification delete event + * @param notification The service specification delete notification */ - private void sendServiceSpecificationDeleteEventToCallback(String callbackUrl, ServiceSpecificationDeleteEvent event) { + private void sendServiceSpecificationDeleteNotificationToCallback(String callbackUrl, ServiceSpecificationDeleteNotification notification) { try { - String url = buildCallbackUrl(callbackUrl, "/listener/serviceSpecificationDeleteEvent"); + String url = buildCallbackUrl(callbackUrl, "/listener/serviceSpecificationDeleteNotification"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(event, headers); + HttpEntity entity = new HttpEntity<>(notification, headers); ResponseEntity response = restTemplate.exchange( url, HttpMethod.POST, entity, String.class); - logger.info("Successfully sent service specification delete event to callback URL: {} - Response: {}", + logger.info("Successfully sent service specification delete notification to callback URL: {} - Response: {}", url, response.getStatusCode()); } catch (Exception e) { - logger.error("Failed to send service specification delete event to callback URL: {}", callbackUrl, e); + logger.error("Failed to send service specification delete notification to callback URL: {}", callbackUrl, e); } } /** - * Send service specification change event to a specific callback URL + * Send service specification change notification to a specific callback URL * @param callbackUrl The callback URL to send to - * @param event The service specification change event + * @param notification The service specification change notification */ - private void sendServiceSpecificationChangeEventToCallback(String callbackUrl, ServiceSpecificationChangeEvent event) { + private void sendServiceSpecificationChangeNotificationToCallback(String callbackUrl, ServiceSpecificationChangeNotification notification) { try { - String url = buildCallbackUrl(callbackUrl, "/listener/serviceSpecificationChangeEvent"); + String url = buildCallbackUrl(callbackUrl, "/listener/serviceSpecificationChangeNotification"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(event, headers); + HttpEntity entity = new HttpEntity<>(notification, headers); ResponseEntity response = restTemplate.exchange( url, HttpMethod.POST, entity, String.class); - logger.info("Successfully sent service specification change event to callback URL: {} - Response: {}", + logger.info("Successfully sent service specification change notification to callback URL: {} - Response: {}", url, response.getStatusCode()); } catch (Exception e) { - logger.error("Failed to send service specification change event to callback URL: {}", callbackUrl, e); + logger.error("Failed to send service specification change notification to callback URL: {}", callbackUrl, e); } } /** - * Check if a subscription should be notified for a specific event type - * @param subscription The event subscription - * @param eventType The event type to check + * Check if a subscription should be notified for a specific notification type + * @param subscription The notification subscription + * @param notificationType The notification type to check * @return true if the subscription should be notified */ - private boolean shouldNotifySubscription(EventSubscription subscription, String eventType) { - // If no query is specified, notify all events + private boolean shouldNotifySubscription(EventSubscription subscription, String notificationType) { + // If no query is specified, notify all notifications if (subscription.getQuery() == null || subscription.getQuery().trim().isEmpty()) { return true; } - // Check if the query contains the event type + // Check if the query contains the notification type String query = subscription.getQuery().toLowerCase(); return query.contains("servicecatalog") || query.contains("servicecategory") || query.contains("servicespecification") || - query.contains(eventType.toLowerCase()) || + query.contains(notificationType.toLowerCase()) || query.contains("servicecatalog.create") || query.contains("servicecatalog.delete") || query.contains("servicecategory.create") || diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogNotificationService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogNotificationService.java index 74351777..dc33044e 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogNotificationService.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCatalogNotificationService.java @@ -57,7 +57,7 @@ public class ServiceCatalogNotificationService { eventPublisher.publishEvent(notification, serviceCatalog.getUuid()); // Send callbacks to registered subscribers - serviceCatalogCallbackService.sendServiceCatalogCreateCallback(notification.getEvent()); + serviceCatalogCallbackService.sendServiceCatalogCreateCallback(notification); logger.info("Published service catalog create notification for service catalog ID: {}", serviceCatalog.getUuid()); } catch (Exception e) { @@ -75,7 +75,7 @@ public class ServiceCatalogNotificationService { eventPublisher.publishEvent(notification, serviceCatalog.getUuid()); // Send callbacks to registered subscribers - serviceCatalogCallbackService.sendServiceCatalogDeleteCallback(notification.getEvent()); + serviceCatalogCallbackService.sendServiceCatalogDeleteCallback(notification); logger.info("Published service catalog delete notification for service catalog ID: {}", serviceCatalog.getUuid()); } catch (Exception e) { diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCategoryNotificationService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCategoryNotificationService.java index 4d5f6274..9d36b82e 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCategoryNotificationService.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceCategoryNotificationService.java @@ -57,7 +57,7 @@ public class ServiceCategoryNotificationService { eventPublisher.publishEvent(notification, serviceCategory.getUuid()); // Send callbacks to registered subscribers - serviceCatalogCallbackService.sendServiceCategoryCreateCallback(notification.getEvent()); + serviceCatalogCallbackService.sendServiceCategoryCreateCallback(notification); logger.info("Published service category create notification for service category ID: {}", serviceCategory.getUuid()); } catch (Exception e) { @@ -75,7 +75,7 @@ public class ServiceCategoryNotificationService { eventPublisher.publishEvent(notification, serviceCategory.getUuid()); // Send callbacks to registered subscribers - serviceCatalogCallbackService.sendServiceCategoryDeleteCallback(notification.getEvent()); + serviceCatalogCallbackService.sendServiceCategoryDeleteCallback(notification); logger.info("Published service category delete notification for service category ID: {}", serviceCategory.getUuid()); } catch (Exception e) { diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationNotificationService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationNotificationService.java index e694454f..6f5c7db4 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationNotificationService.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationNotificationService.java @@ -59,7 +59,7 @@ public class ServiceSpecificationNotificationService { eventPublisher.publishEvent(notification, serviceSpecification.getUuid()); // Send callbacks to registered subscribers - serviceCatalogCallbackService.sendServiceSpecificationCreateCallback(notification.getEvent()); + serviceCatalogCallbackService.sendServiceSpecificationCreateCallback(notification); logger.info("Published service specification create notification for service specification ID: {}", serviceSpecification.getUuid()); } catch (Exception e) { @@ -77,7 +77,7 @@ public class ServiceSpecificationNotificationService { eventPublisher.publishEvent(notification, serviceSpecification.getUuid()); // Send callbacks to registered subscribers - serviceCatalogCallbackService.sendServiceSpecificationDeleteCallback(notification.getEvent()); + serviceCatalogCallbackService.sendServiceSpecificationDeleteCallback(notification); logger.info("Published service specification delete notification for service specification ID: {}", serviceSpecification.getUuid()); } catch (Exception e) { @@ -95,7 +95,7 @@ public class ServiceSpecificationNotificationService { eventPublisher.publishEvent(notification, serviceSpecification.getUuid()); // Send callbacks to registered subscribers - serviceCatalogCallbackService.sendServiceSpecificationChangeCallback(notification.getEvent()); + serviceCatalogCallbackService.sendServiceSpecificationChangeCallback(notification); logger.info("Published service specification change notification for service specification ID: {}", serviceSpecification.getUuid()); } catch (Exception e) { diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java index 9ed631a1..45edc088 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java @@ -68,14 +68,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCandidateChangeNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCandidateChangeNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCandidateChangeNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -94,14 +94,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCandidateCreateNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCandidateCreateNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCandidateCreateNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -120,14 +120,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCandidateDeleteNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCandidateDeleteNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCandidateDeleteNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -146,14 +146,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCatalogBatchNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogBatchNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCatalogBatchNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -172,14 +172,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCatalogChangeNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogChangeNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCatalogChangeNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -198,14 +198,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCatalogCreateNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogCreateNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCatalogCreateNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -224,14 +224,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCatalogDeleteNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogDeleteNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCatalogDeleteNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -250,14 +250,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCategoryChangeNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCategoryChangeNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCategoryChangeNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -276,14 +276,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCategoryCreateNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCategoryCreateNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCategoryCreateNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -302,14 +302,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCategoryDeleteNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCategoryDeleteNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceCategoryDeleteNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -328,14 +328,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceSpecificationChangeNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceSpecificationChangeNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceSpecificationChangeNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -354,14 +354,14 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceSpecificationCreateNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceSpecificationCreateNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceSpecificationCreateNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } @@ -380,13 +380,13 @@ public class ListenerApiControllerTest { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceSpecificationDeleteNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); // Test when not providing an "Accept" request header mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceSpecificationDeleteNotification") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content( JsonUtils.toJson( serviceSpecificationDeleteNotification ) )) - .andExpect(status().is(501)); + .andExpect(status().is(200)); } } \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogCallbackServiceExtendedTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogCallbackServiceExtendedTest.java index ada8e9c8..11d8bcfc 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogCallbackServiceExtendedTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogCallbackServiceExtendedTest.java @@ -12,11 +12,16 @@ import java.util.List; import org.etsi.osl.tmf.scm633.model.EventSubscription; import org.etsi.osl.tmf.scm633.model.ServiceCategory; import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryCreateNotification; import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceCategoryDeleteNotification; import org.etsi.osl.tmf.scm633.model.ServiceSpecification; import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationCreateNotification; import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationDeleteNotification; import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeEvent; +import org.etsi.osl.tmf.scm633.model.ServiceSpecificationChangeNotification; import org.etsi.osl.tmf.scm633.reposervices.EventSubscriptionRepoService; import org.etsi.osl.tmf.scm633.reposervices.ServiceCatalogCallbackService; import org.junit.Before; @@ -76,8 +81,10 @@ public class ServiceCatalogCallbackServiceExtendedTest { when(restTemplate.exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + ServiceCategoryCreateNotification notif = new ServiceCategoryCreateNotification(); + notif.setEvent(event); // Act - serviceCatalogCallbackService.sendServiceCategoryCreateCallback(event); + serviceCatalogCallbackService.sendServiceCategoryCreateCallback(notif ); // Assert verify(restTemplate, times(2)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); @@ -104,8 +111,11 @@ public class ServiceCatalogCallbackServiceExtendedTest { when(restTemplate.exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); + + ServiceCategoryDeleteNotification notif = new ServiceCategoryDeleteNotification(); + notif.setEvent(event); // Act - serviceCatalogCallbackService.sendServiceCategoryDeleteCallback(event); + serviceCatalogCallbackService.sendServiceCategoryDeleteCallback(notif); // Assert verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); @@ -133,7 +143,10 @@ public class ServiceCatalogCallbackServiceExtendedTest { .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); // Act - serviceCatalogCallbackService.sendServiceSpecificationCreateCallback(event); + + ServiceSpecificationCreateNotification notif = new ServiceSpecificationCreateNotification(); + notif.setEvent(event); + serviceCatalogCallbackService.sendServiceSpecificationCreateCallback(notif); // Assert verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); @@ -160,7 +173,9 @@ public class ServiceCatalogCallbackServiceExtendedTest { .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); // Act - serviceCatalogCallbackService.sendServiceSpecificationDeleteCallback(event); + ServiceSpecificationDeleteNotification notif = new ServiceSpecificationDeleteNotification(); + notif.setEvent(event); + serviceCatalogCallbackService.sendServiceSpecificationDeleteCallback(notif); // Assert verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); @@ -188,7 +203,9 @@ public class ServiceCatalogCallbackServiceExtendedTest { .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); // Act - serviceCatalogCallbackService.sendServiceSpecificationChangeCallback(event); + ServiceSpecificationChangeNotification notif = new ServiceSpecificationChangeNotification(); + notif.setEvent(event); + serviceCatalogCallbackService.sendServiceSpecificationChangeCallback(notif); // Assert verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); @@ -214,7 +231,9 @@ public class ServiceCatalogCallbackServiceExtendedTest { .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); // Act - serviceCatalogCallbackService.sendServiceCategoryCreateCallback(event); + ServiceCategoryCreateNotification notif = new ServiceCategoryCreateNotification(); + notif.setEvent(event); + serviceCatalogCallbackService.sendServiceCategoryCreateCallback(notif); // Assert - should call callback even with no query verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); @@ -240,7 +259,9 @@ public class ServiceCatalogCallbackServiceExtendedTest { .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); // Act - serviceCatalogCallbackService.sendServiceSpecificationCreateCallback(event); + ServiceSpecificationCreateNotification notif = new ServiceSpecificationCreateNotification(); + notif.setEvent(event); + serviceCatalogCallbackService.sendServiceSpecificationCreateCallback(notif); // Assert verify(restTemplate, times(1)).exchange(any(String.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); -- GitLab From a87c4ebd75e04aa656d32f4717ba4a6f798191c7 Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Wed, 20 Aug 2025 10:51:05 +0300 Subject: [PATCH 5/5] removing classes --- .../org/etsi/osl/tmf/pim637/api/HubApi.java | 1 - .../etsi/osl/tmf/pim637/api/ListenerApi.java | 1 - .../etsi/osl/tmf/pim637/api/ProductApi.java | 1 - .../ServiceCatalogApiRouteBuilderEvents.java | 4 +- .../services/api/rcm634/EntityRefTest.java | 143 ---------- .../osl/services/api/rcm634/ErrorTest.java | 179 ------------ .../ExportJobCreateEventPayloadTest.java | 87 ------ .../api/rcm634/ExportJobCreateEventTest.java | 180 ------------ .../api/rcm634/ExportJobCreateTest.java | 231 --------------- .../rcm634/ExportJobStateChangeEventTest.java | 196 ------------- .../services/api/rcm634/ExportJobTest.java | 266 ------------------ .../scm633/ExportJobApiController633Test.java | 130 --------- .../scm633/ImportJobApiControllerTest.java | 130 --------- 13 files changed, 2 insertions(+), 1547 deletions(-) delete mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/EntityRefTest.java delete mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ErrorTest.java delete mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventPayloadTest.java delete mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventTest.java delete mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateTest.java delete mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobStateChangeEventTest.java delete mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobTest.java delete mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java delete mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java diff --git a/src/main/java/org/etsi/osl/tmf/pim637/api/HubApi.java b/src/main/java/org/etsi/osl/tmf/pim637/api/HubApi.java index 7dc3b86a..8a1652a7 100644 --- a/src/main/java/org/etsi/osl/tmf/pim637/api/HubApi.java +++ b/src/main/java/org/etsi/osl/tmf/pim637/api/HubApi.java @@ -5,7 +5,6 @@ */ package org.etsi.osl.tmf.pim637.api; -import org.etsi.osl.tmf.pim637.model.Error; import org.etsi.osl.tmf.pim637.model.EventSubscription; import org.etsi.osl.tmf.pim637.model.EventSubscriptionInput; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/org/etsi/osl/tmf/pim637/api/ListenerApi.java b/src/main/java/org/etsi/osl/tmf/pim637/api/ListenerApi.java index 8ea75df1..5a63d823 100644 --- a/src/main/java/org/etsi/osl/tmf/pim637/api/ListenerApi.java +++ b/src/main/java/org/etsi/osl/tmf/pim637/api/ListenerApi.java @@ -5,7 +5,6 @@ */ package org.etsi.osl.tmf.pim637.api; -import org.etsi.osl.tmf.pim637.model.Error; import org.etsi.osl.tmf.pim637.model.EventSubscription; import org.etsi.osl.tmf.pim637.model.ProductAttributeValueChangeEvent; import org.etsi.osl.tmf.pim637.model.ProductBatchEvent; diff --git a/src/main/java/org/etsi/osl/tmf/pim637/api/ProductApi.java b/src/main/java/org/etsi/osl/tmf/pim637/api/ProductApi.java index c4f9f782..0631e196 100644 --- a/src/main/java/org/etsi/osl/tmf/pim637/api/ProductApi.java +++ b/src/main/java/org/etsi/osl/tmf/pim637/api/ProductApi.java @@ -6,7 +6,6 @@ package org.etsi.osl.tmf.pim637.api; import java.util.List; -import org.etsi.osl.tmf.pim637.model.Error; import org.etsi.osl.tmf.pim637.model.Product; import org.etsi.osl.tmf.pim637.model.ProductCreate; import org.etsi.osl.tmf.pim637.model.ProductUpdate; diff --git a/src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilderEvents.java b/src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilderEvents.java index 7ac8e2be..630ad076 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilderEvents.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilderEvents.java @@ -139,8 +139,8 @@ public class ServiceCatalogApiRouteBuilderEvents extends RouteBuilder { centralLogger.log(CLevel.INFO, msgtxt, compname()); } catch (Exception e) { - e.printStackTrace(); - logger.error("Cannot send Event . " + e.getMessage()); + //e.printStackTrace(); + logger.error("Cannot send Event to message bus. " + e.getMessage()); } } diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/EntityRefTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/EntityRefTest.java deleted file mode 100644 index 156d8c94..00000000 --- a/src/test/java/org/etsi/osl/services/api/rcm634/EntityRefTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.etsi.osl.services.api.rcm634; - -import org.etsi.osl.tmf.rcm634.model.EntityRef; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; -import java.lang.reflect.Method; - -public class EntityRefTest { - - @Test - void testEntityRef() { - EntityRef ref = new EntityRef(); - String id = "testId"; - String href = "testHref"; - String name = "testName"; - String referredType = "testReferredType"; - - ref.id(id); - ref.setUuid(id); - ref.href(href); - ref.name(name); - ref._atReferredType(referredType); - - assertEquals(id, ref.getId()); - assertEquals(href, ref.getHref()); - assertEquals(name, ref.getName()); - assertEquals(referredType, ref.getAtReferredType()); - - ref = new EntityRef(); - ref.setId(id); - ref.setUuid(id); - ref.setHref(href); - ref.setName(name); - ref.setAtReferredType(referredType); - - assertEquals(id, ref.getId()); - assertEquals(href, ref.getHref()); - assertEquals(name, ref.getName()); - assertEquals(referredType, ref.getAtReferredType()); - } - - @Test - void testEquals() { - String id = "testId"; - String href = "testHref"; - String name = "testName"; - String referredType = "testReferredType"; - - EntityRef ref1 = new EntityRef(); - ref1.setUuid(id); - ref1.setHref(href); - ref1.setName(name); - ref1.setAtReferredType(referredType); - - EntityRef ref2 = new EntityRef(); - ref2.setUuid(id); - ref2.setHref(href); - ref2.setName(name); - ref2.setAtReferredType(referredType); - - assertTrue(ref1.equals(ref2)); - - ref1.id("differentId"); - - assertFalse(ref1.equals(ref2)); - } - - @Test - void testHashCode() { - String id = "testId"; - String href = "testHref"; - String name = "testName"; - String referredType = "testReferredType"; - - EntityRef ref1 = new EntityRef(); - ref1.setUuid(id); - ref1.setHref(href); - ref1.setName(name); - ref1.setAtReferredType(referredType); - - EntityRef ref2 = new EntityRef(); - ref2.setUuid(id); - ref2.setHref(href); - ref2.setName(name); - ref2.setAtReferredType(referredType); - - assertEquals(ref1.hashCode(), ref2.hashCode()); - - ref1.id("differentId"); - ref1.setUuid("differentId"); - - assertNotEquals(ref1.hashCode(), ref2.hashCode()); - } - - @Test - void testToString() { - EntityRef ref = new EntityRef(); - - String id = "testId"; - String href = "testHref"; - String name = "testName"; - String baseType = "testBaseType"; - String schemaLocation = "testSchemaLocation"; - String type = "testType"; - String referredType = "testReferredType"; - - ref.id(id); - ref.setUuid(id); - ref.setHref(href); - ref.name(name); - ref.setBaseType(baseType); - ref.setSchemaLocation(schemaLocation); - ref.setType(type); - ref.setAtReferredType(referredType); - - String expectedString = "class EntityRef {\n" + - " id: testId\n" + - " href: testHref\n" + - " name: testName\n" + - " baseType: testBaseType\n" + - " schemaLocation: testSchemaLocation\n" + - " type: testType\n" + - " _atReferredType: testReferredType\n" + - "}"; - - assertEquals(expectedString, ref.toString()); - } - - @Test - void testToIndentedString() throws Exception { - EntityRef ref = new EntityRef(); - - Method method = EntityRef.class.getDeclaredMethod("toIndentedString", Object.class); - method.setAccessible(true); - - String input = "Hello\nWorld"; - String expectedOutput = "Hello\n World"; - - String output = (String) method.invoke(ref, input); - - assertEquals(expectedOutput, output); - } -} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ErrorTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ErrorTest.java deleted file mode 100644 index d567d602..00000000 --- a/src/test/java/org/etsi/osl/services/api/rcm634/ErrorTest.java +++ /dev/null @@ -1,179 +0,0 @@ -package org.etsi.osl.services.api.rcm634; - -import org.etsi.osl.tmf.rcm634.model.Error; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; -import java.lang.reflect.Method; - -public class ErrorTest { - - @Test - void testError() { - Error error = new Error(); - String code = "testCode"; - String reason = "testReason"; - String message = "testMessage"; - String status = "testStatus"; - String referenceError = "testReferenceError"; - - error.code(code); - error.reason(reason); - error.message(message); - error.status(status); - error.referenceError(referenceError); - - assertEquals(code, error.getCode()); - assertEquals(reason, error.getReason()); - assertEquals(message, error.getMessage()); - assertEquals(status, error.getStatus()); - assertEquals(referenceError, error.getReferenceError()); - - error = new Error(); - error.setCode(code); - error.setReason(reason); - error.setMessage(message); - error.setStatus(status); - error.setReferenceError(referenceError); - - assertEquals(code, error.getCode()); - assertEquals(reason, error.getReason()); - assertEquals(message, error.getMessage()); - assertEquals(status, error.getStatus()); - assertEquals(referenceError, error.getReferenceError()); - } - - @Test - void testEquals() { - String code = "testCode"; - String reason = "testReason"; - String message = "testMessage"; - String status = "testStatus"; - String referenceError = "testReferenceError"; - - Error error1 = new Error(); - error1.setReason(reason); - error1.setMessage(message); - error1.setStatus(status); - error1.setReferenceError(referenceError); - - Error error2 = new Error(); - error2.setReason(reason); - error2.setMessage(message); - error2.setStatus(status); - error2.setReferenceError(referenceError); - - assertTrue(error1.equals(error2)); - - error1.code("differentCode"); - - assertFalse(error1.equals(error2)); - } - - @Test - void testHashCode() { - String code = "testCode"; - String reason = "testReason"; - String message = "testMessage"; - String status = "testStatus"; - String referenceError = "testReferenceError"; - - Error error1 = new Error(); - error1.setReason(reason); - error1.setMessage(message); - error1.setStatus(status); - error1.setReferenceError(referenceError); - - Error error2 = new Error(); - error2.setReason(reason); - error2.setMessage(message); - error2.setStatus(status); - error2.setReferenceError(referenceError); - - assertEquals(error1.hashCode(), error2.hashCode()); - - error1.code("differentCode"); - - assertNotEquals(error1.hashCode(), error2.hashCode()); - } - - @Test - void testToString() { - Error error = new Error(); - - String code = "testCode"; - String reason = "testReason"; - String message = "testMessage"; - String status = "testStatus"; - String referenceError = "testReferenceError"; - String baseType = "testBaseType"; - String schemaLocation = "testSchemaLocation"; - String type = "testType"; - - error.code(code); - error.reason(reason); - error.message(message); - error.status(status); - error.referenceError(referenceError); - - String expectedString = "class Error {\n" + - " code: testCode\n" + - " reason: testReason\n" + - " message: testMessage\n" + - " status: testStatus\n" + - " referenceError: testReferenceError\n" + - " _atBaseType: null\n" + - " _atSchemaLocation: null\n" + - " _atType: null\n" + - "}"; - - assertEquals(expectedString, error.toString()); - } - - @Test - void testToIndentedString() throws Exception { - Error error = new Error(); - - Method method = Error.class.getDeclaredMethod("toIndentedString", Object.class); - method.setAccessible(true); - - String input = "Hello\nWorld"; - String expectedOutput = "Hello\n World"; - - String output = (String) method.invoke(error, input); - - assertEquals(expectedOutput, output); - } - - @Test - void testAtBaseType() { - Error error = new Error(); - String baseType = "testBaseType"; - error.setAtBaseType(baseType); - assertEquals(baseType, error.getAtBaseType()); - - Error newError = error._atBaseType("newTestBaseType"); - assertEquals(error, newError); - } - - @Test - void testAtSchemaLocation() { - Error error = new Error(); - String schemaLocation = "testSchemaLocation"; - error.setAtSchemaLocation(schemaLocation); - assertEquals(schemaLocation, error.getAtSchemaLocation()); - - Error newError = error._atSchemaLocation("newTestSchemaLocation"); - assertEquals(error, newError); - } - - @Test - void testAtType() { - Error error = new Error(); - String type = "testType"; - error.setAtType(type); - assertEquals(type, error.getAtType()); - - Error newError = error._atType("newTestType"); - assertEquals(error, newError); - } -} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventPayloadTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventPayloadTest.java deleted file mode 100644 index 87641b19..00000000 --- a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventPayloadTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.etsi.osl.services.api.rcm634; - -import org.etsi.osl.tmf.rcm634.model.ExportJob; -import org.etsi.osl.tmf.rcm634.model.ExportJobCreateEventPayload; -import org.junit.jupiter.api.Test; - -import java.lang.reflect.Method; -import static org.junit.jupiter.api.Assertions.*; - -public class ExportJobCreateEventPayloadTest { - - @Test - void testExportJobCreateEventPayload() { - ExportJobCreateEventPayload payload = new ExportJobCreateEventPayload(); - ExportJob job = new ExportJob(); - job.setId("testId"); - - payload.exportJob(job); - assertEquals(job, payload.getExportJob()); - - payload = new ExportJobCreateEventPayload(); - payload.setExportJob(job); - assertEquals(job, payload.getExportJob()); - } - - @Test - void testEquals() { - ExportJobCreateEventPayload payload1 = new ExportJobCreateEventPayload(); - ExportJob job = new ExportJob(); - job.setId("testId"); - payload1.setExportJob(job); - - ExportJobCreateEventPayload payload2 = new ExportJobCreateEventPayload(); - payload2.setExportJob(job); - - assertTrue(payload1.equals(payload2)); - - payload1.setExportJob(new ExportJob()); - - assertFalse(payload1.equals(payload2)); - } - - @Test - void testHashCode() { - ExportJobCreateEventPayload payload1 = new ExportJobCreateEventPayload(); - ExportJob job = new ExportJob(); - job.setId("testId"); - payload1.setExportJob(job); - - ExportJobCreateEventPayload payload2 = new ExportJobCreateEventPayload(); - payload2.setExportJob(job); - - assertEquals(payload1.hashCode(), payload2.hashCode()); - - payload1.setExportJob(new ExportJob()); - - assertNotEquals(payload1.hashCode(), payload2.hashCode()); - } - - @Test - void testToString() { - ExportJobCreateEventPayload payload = new ExportJobCreateEventPayload(); - ExportJob job = new ExportJob(); - job.setId("testId"); - payload.setExportJob(job); - - String expectedString = "class ExportJobCreateEventPayload {\n" + - " exportJob: class ExportJob {\n" + - " id: testId\n" + - " href: null\n" + - " completionDate: null\n" + - " contentType: null\n" + - " creationDate: null\n" + - " errorLog: null\n" + - " path: null\n" + - " query: null\n" + - " url: null\n" + - " status: null\n" + - " _atBaseType: null\n" + - " _atSchemaLocation: null\n" + - " _atType: null\n" + - " }\n" + - "}"; - - assertEquals(expectedString, payload.toString()); - } -} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventTest.java deleted file mode 100644 index 1c6eb60d..00000000 --- a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventTest.java +++ /dev/null @@ -1,180 +0,0 @@ -package org.etsi.osl.services.api.rcm634; - -import org.etsi.osl.tmf.rcm634.model.ExportJobCreateEvent; -import org.etsi.osl.tmf.rcm634.model.ExportJobCreateEventPayload; -import org.junit.jupiter.api.Test; - -import java.lang.reflect.Method; -import java.time.OffsetDateTime; -import static org.junit.jupiter.api.Assertions.*; - -public class ExportJobCreateEventTest { - - @Test - void testExportJobCreateEvent() { - ExportJobCreateEvent event = new ExportJobCreateEvent(); - String id = "testId"; - String href = "testHref"; - String eventId = "testEventId"; - OffsetDateTime eventTime = OffsetDateTime.now(); - String eventType = "testEventType"; - String correlationId = "testCorrelationId"; - String domain = "testDomain"; - String title = "testTitle"; - String description = "testDescription"; - String priority = "testPriority"; - OffsetDateTime timeOccurred = OffsetDateTime.now(); - ExportJobCreateEventPayload eventPayload = new ExportJobCreateEventPayload(); - - event.id(id); - event.href(href); - event.eventId(eventId); - event.eventTime(eventTime); - event.eventType(eventType); - event.correlationId(correlationId); - event.domain(domain); - event.title(title); - event.description(description); - event.priority(priority); - event.timeOcurred(timeOccurred); - event.event(eventPayload); - - assertEquals(id, event.getId()); - assertEquals(href, event.getHref()); - assertEquals(eventId, event.getEventId()); - assertEquals(eventTime, event.getEventTime()); - assertEquals(eventType, event.getEventType()); - assertEquals(correlationId, event.getCorrelationId()); - assertEquals(domain, event.getDomain()); - assertEquals(title, event.getTitle()); - assertEquals(description, event.getDescription()); - assertEquals(priority, event.getPriority()); - assertEquals(timeOccurred, event.getTimeOcurred()); - assertEquals(eventPayload, event.getEvent()); - } - - @Test - void testEquals() { - ExportJobCreateEvent event1 = new ExportJobCreateEvent(); - event1.setId("testId"); - event1.setHref("testHref"); - event1.setEventId("testEventId"); - event1.setEventTime(OffsetDateTime.now()); - event1.setEventType("testEventType"); - event1.setCorrelationId("testCorrelationId"); - event1.setDomain("testDomain"); - event1.setTitle("testTitle"); - event1.setDescription("testDescription"); - event1.setPriority("testPriority"); - event1.setTimeOcurred(OffsetDateTime.now()); - event1.setEvent(new ExportJobCreateEventPayload()); - - ExportJobCreateEvent event2 = new ExportJobCreateEvent(); - event2.setId("testId"); - event2.setHref("testHref"); - event2.setEventId("testEventId"); - event2.setEventTime(event1.getEventTime()); - event2.setEventType("testEventType"); - event2.setCorrelationId("testCorrelationId"); - event2.setDomain("testDomain"); - event2.setTitle("testTitle"); - event2.setDescription("testDescription"); - event2.setPriority("testPriority"); - event2.setTimeOcurred(event1.getTimeOcurred()); - event2.setEvent(new ExportJobCreateEventPayload()); - - assertTrue(event1.equals(event2)); - - event1.setId("differentId"); - - assertFalse(event1.equals(event2)); - } - - @Test - void testHashCode() { - ExportJobCreateEvent event1 = new ExportJobCreateEvent(); - event1.setId("testId"); - event1.setHref("testHref"); - event1.setEventId("testEventId"); - event1.setEventTime(OffsetDateTime.now()); - event1.setEventType("testEventType"); - event1.setCorrelationId("testCorrelationId"); - event1.setDomain("testDomain"); - event1.setTitle("testTitle"); - event1.setDescription("testDescription"); - event1.setPriority("testPriority"); - event1.setTimeOcurred(OffsetDateTime.now()); - event1.setEvent(new ExportJobCreateEventPayload()); - - ExportJobCreateEvent event2 = new ExportJobCreateEvent(); - event2.setId("testId"); - event2.setHref("testHref"); - event2.setEventId("testEventId"); - event2.setEventTime(event1.getEventTime()); - event2.setEventType("testEventType"); - event2.setCorrelationId("testCorrelationId"); - event2.setDomain("testDomain"); - event2.setTitle("testTitle"); - event2.setDescription("testDescription"); - event2.setPriority("testPriority"); - event2.setTimeOcurred(event1.getTimeOcurred()); - event2.setEvent(new ExportJobCreateEventPayload()); - - assertEquals(event1.hashCode(), event2.hashCode()); - - event1.setId("differentId"); - - assertNotEquals(event1.hashCode(), event2.hashCode()); - } - - @Test - void testToString() { - ExportJobCreateEvent event = new ExportJobCreateEvent(); - event.setId("testId"); - event.setHref("testHref"); - event.setEventId("testEventId"); - event.setEventTime(OffsetDateTime.parse("2024-01-19T17:02:03.289504717+02:00")); - event.setEventType("testEventType"); - event.setCorrelationId("testCorrelationId"); - event.setDomain("testDomain"); - event.setTitle("testTitle"); - event.setDescription("testDescription"); - event.setPriority("testPriority"); - event.setTimeOcurred(OffsetDateTime.parse("2024-01-19T17:02:03.289527665+02:00")); - event.setEvent(new ExportJobCreateEventPayload()); - - String expectedString = "class ExportJobCreateEvent {\n" + - " id: testId\n" + - " href: testHref\n" + - " eventId: testEventId\n" + - " eventTime: 2024-01-19T17:02:03.289504717+02:00\n" + - " eventType: testEventType\n" + - " correlationId: testCorrelationId\n" + - " domain: testDomain\n" + - " title: testTitle\n" + - " description: testDescription\n" + - " priority: testPriority\n" + - " timeOcurred: 2024-01-19T17:02:03.289527665+02:00\n" + - " event: class ExportJobCreateEventPayload {\n" + - " exportJob: null\n" + - " }\n" + - "}"; - - assertEquals(expectedString, event.toString()); - } - - @Test - void testToIndentedString() throws Exception { - ExportJobCreateEvent event = new ExportJobCreateEvent(); - - Method method = ExportJobCreateEvent.class.getDeclaredMethod("toIndentedString", Object.class); - method.setAccessible(true); - - String input = "Hello\nWorld"; - String expectedOutput = "Hello\n World"; - - String output = (String) method.invoke(event, input); - - assertEquals(expectedOutput, output); - } -} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateTest.java deleted file mode 100644 index 8333fe94..00000000 --- a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateTest.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.etsi.osl.services.api.rcm634; - -import org.etsi.osl.tmf.rcm634.model.ExportJobCreate; -import org.etsi.osl.tmf.rcm634.model.JobStateType; -import org.junit.jupiter.api.Test; - -import java.lang.reflect.Method; -import java.time.OffsetDateTime; -import static org.junit.jupiter.api.Assertions.*; - -public class ExportJobCreateTest { - - @Test - void testExportJobCreate() { - ExportJobCreate jobCreate = new ExportJobCreate(); - String query = "testQuery"; - OffsetDateTime completionDate = OffsetDateTime.now(); - OffsetDateTime creationDate = OffsetDateTime.now(); - String contentType = "testContentType"; - String errorLog = "testErrorLog"; - String path = "testPath"; - String url = "testUrl"; - - jobCreate.query(query); - jobCreate.setCompletionDate(completionDate); - jobCreate.setCreationDate(creationDate); - jobCreate.setContentType(contentType); - jobCreate.setErrorLog(errorLog); - jobCreate.setPath(path); - jobCreate.setUrl(url); - - assertEquals(query, jobCreate.getQuery()); - assertEquals(completionDate, jobCreate.getCompletionDate()); - assertEquals(creationDate, jobCreate.getCreationDate()); - assertEquals(contentType, jobCreate.getContentType()); - assertEquals(errorLog, jobCreate.getErrorLog()); - assertEquals(path, jobCreate.getPath()); - assertEquals(url, jobCreate.getUrl()); - - jobCreate = new ExportJobCreate(); - jobCreate.setQuery(query); - jobCreate.setCompletionDate(completionDate); - jobCreate.setCreationDate(creationDate); - jobCreate.setContentType(contentType); - jobCreate.setErrorLog(errorLog); - jobCreate.setPath(path); - jobCreate.setUrl(url); - - assertEquals(query, jobCreate.getQuery()); - assertEquals(completionDate, jobCreate.getCompletionDate()); - assertEquals(creationDate, jobCreate.getCreationDate()); - assertEquals(contentType, jobCreate.getContentType()); - assertEquals(errorLog, jobCreate.getErrorLog()); - assertEquals(path, jobCreate.getPath()); - assertEquals(url, jobCreate.getUrl()); - } - - @Test - void testStatus() { - ExportJobCreate jobCreate = new ExportJobCreate(); - JobStateType status = JobStateType.RUNNING; - jobCreate.setStatus(status); - assertEquals(status, jobCreate.getStatus()); - - ExportJobCreate newJobCreate = jobCreate.status(JobStateType.FAILED); - assertEquals(jobCreate, newJobCreate); - } - - @Test - void testAtBaseType() { - ExportJobCreate jobCreate = new ExportJobCreate(); - String baseType = "testBaseType"; - jobCreate.setAtBaseType(baseType); - assertEquals(baseType, jobCreate.getAtBaseType()); - - ExportJobCreate newJobCreate = jobCreate._atBaseType("newTestBaseType"); - assertEquals(jobCreate, newJobCreate); - } - - @Test - void testAtSchemaLocation() { - ExportJobCreate jobCreate = new ExportJobCreate(); - String schemaLocation = "testSchemaLocation"; - jobCreate.setAtSchemaLocation(schemaLocation); - assertEquals(schemaLocation, jobCreate.getAtSchemaLocation()); - - ExportJobCreate newJobCreate = jobCreate._atSchemaLocation("newTestSchemaLocation"); - assertEquals(jobCreate, newJobCreate); - } - - @Test - void testAtType() { - ExportJobCreate jobCreate = new ExportJobCreate(); - String type = "testType"; - jobCreate.setAtType(type); - assertEquals(type, jobCreate.getAtType()); - - ExportJobCreate newJobCreate = jobCreate._atType("newTestType"); - assertEquals(jobCreate, newJobCreate); - } - - @Test - void testErrorLog() { - ExportJobCreate jobCreate = new ExportJobCreate(); - String errorLog = "testErrorLog"; - jobCreate.setErrorLog(errorLog); - assertEquals(errorLog, jobCreate.getErrorLog()); - - ExportJobCreate newJobCreate = jobCreate.errorLog("newTestErrorLog"); - assertEquals(jobCreate, newJobCreate); - } - - @Test - void testPath() { - ExportJobCreate jobCreate = new ExportJobCreate(); - String path = "testPath"; - jobCreate.setPath(path); - assertEquals(path, jobCreate.getPath()); - - ExportJobCreate newJobCreate = jobCreate.path("newTestPath"); - assertEquals(jobCreate, newJobCreate); - } - - @Test - void testUrl() { - ExportJobCreate jobCreate = new ExportJobCreate(); - String url = "testUrl"; - jobCreate.setUrl(url); - assertEquals(url, jobCreate.getUrl()); - - ExportJobCreate newJobCreate = jobCreate.url("newTestUrl"); - assertEquals(jobCreate, newJobCreate); - } - - @Test - void testEquals() { - ExportJobCreate jobCreate1 = new ExportJobCreate(); - jobCreate1.setQuery("testQuery"); - jobCreate1.setCompletionDate(OffsetDateTime.now()); - jobCreate1.setCreationDate(OffsetDateTime.now()); - jobCreate1.setContentType("testContentType"); - jobCreate1.setErrorLog("testErrorLog"); - jobCreate1.setPath("testPath"); - jobCreate1.setUrl("testUrl"); - - ExportJobCreate jobCreate2 = new ExportJobCreate(); - jobCreate2.setQuery("testQuery"); - jobCreate2.setCompletionDate(jobCreate1.getCompletionDate()); - jobCreate2.setCreationDate(jobCreate1.getCreationDate()); - jobCreate2.setContentType("testContentType"); - jobCreate2.setErrorLog("testErrorLog"); - jobCreate2.setPath("testPath"); - jobCreate2.setUrl("testUrl"); - - assertTrue(jobCreate1.equals(jobCreate2)); - - jobCreate1.setQuery("differentQuery"); - - assertFalse(jobCreate1.equals(jobCreate2)); - } - - @Test - void testHashCode() { - ExportJobCreate jobCreate1 = new ExportJobCreate(); - jobCreate1.setQuery("testQuery"); - jobCreate1.setCompletionDate(OffsetDateTime.now()); - jobCreate1.setCreationDate(OffsetDateTime.now()); - jobCreate1.setContentType("testContentType"); - jobCreate1.setErrorLog("testErrorLog"); - jobCreate1.setPath("testPath"); - jobCreate1.setUrl("testUrl"); - - ExportJobCreate jobCreate2 = new ExportJobCreate(); - jobCreate2.setQuery("testQuery"); - jobCreate2.setCompletionDate(jobCreate1.getCompletionDate()); - jobCreate2.setCreationDate(jobCreate1.getCreationDate()); - jobCreate2.setContentType("testContentType"); - jobCreate2.setErrorLog("testErrorLog"); - jobCreate2.setPath("testPath"); - jobCreate2.setUrl("testUrl"); - - assertEquals(jobCreate1.hashCode(), jobCreate2.hashCode()); - - jobCreate1.setQuery("differentQuery"); - - assertNotEquals(jobCreate1.hashCode(), jobCreate2.hashCode()); - } - - @Test - void testToString() { - ExportJobCreate jobCreate = new ExportJobCreate(); - jobCreate.setQuery("testQuery"); - jobCreate.setCompletionDate(OffsetDateTime.parse("2024-01-19T17:02:03.289504717+02:00")); - jobCreate.setCreationDate(OffsetDateTime.parse("2024-01-19T17:02:03.289527665+02:00")); - jobCreate.setContentType("testContentType"); - jobCreate.setErrorLog("testErrorLog"); - jobCreate.setPath("testPath"); - jobCreate.setUrl("testUrl"); - - String expectedString = "class ExportJobCreate {\n" + - " completionDate: 2024-01-19T17:02:03.289504717+02:00\n" + - " contentType: testContentType\n" + - " creationDate: 2024-01-19T17:02:03.289527665+02:00\n" + - " errorLog: testErrorLog\n" + - " path: testPath\n" + - " query: testQuery\n" + - " url: testUrl\n" + - " status: null\n" + - " _atBaseType: null\n" + - " _atSchemaLocation: null\n" + - " _atType: null\n" + - "}"; - - assertEquals(expectedString, jobCreate.toString()); - } - - @Test - void testToIndentedString() throws Exception { - ExportJobCreate jobCreate = new ExportJobCreate(); - - Method method = ExportJobCreate.class.getDeclaredMethod("toIndentedString", Object.class); - method.setAccessible(true); - - String input = "Hello\nWorld"; - String expectedOutput = "Hello\n World"; - - String output = (String) method.invoke(jobCreate, input); - - assertEquals(expectedOutput, output); - } -} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobStateChangeEventTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobStateChangeEventTest.java deleted file mode 100644 index d8bb2bbd..00000000 --- a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobStateChangeEventTest.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.etsi.osl.services.api.rcm634; - -import org.etsi.osl.tmf.rcm634.model.ExportJob; -import org.etsi.osl.tmf.rcm634.model.ExportJobStateChangeEvent; -import org.etsi.osl.tmf.rcm634.model.ExportJobStateChangeEventPayload; -import org.junit.jupiter.api.Test; - -import java.lang.reflect.Method; -import java.time.OffsetDateTime; -import static org.junit.jupiter.api.Assertions.*; - -public class ExportJobStateChangeEventTest { - - @Test - void testExportJobStateChangeEvent() { - ExportJobStateChangeEvent event = new ExportJobStateChangeEvent(); - String id = "testId"; - String href = "testHref"; - String eventId = "testEventId"; - OffsetDateTime eventTime = OffsetDateTime.now(); - String eventType = "testEventType"; - String correlationId = "testCorrelationId"; - String domain = "testDomain"; - String title = "testTitle"; - String description = "testDescription"; - String priority = "testPriority"; - OffsetDateTime timeOccurred = OffsetDateTime.now(); - ExportJobStateChangeEventPayload eventPayload = new ExportJobStateChangeEventPayload(); - - event.id(id); - event.href(href); - event.eventId(eventId); - event.eventTime(eventTime); - event.eventType(eventType); - event.correlationId(correlationId); - event.domain(domain); - event.title(title); - event.description(description); - event.priority(priority); - event.timeOcurred(timeOccurred); - event.event(eventPayload); - - assertEquals(id, event.getId()); - assertEquals(href, event.getHref()); - assertEquals(eventId, event.getEventId()); - assertEquals(eventTime, event.getEventTime()); - assertEquals(eventType, event.getEventType()); - assertEquals(correlationId, event.getCorrelationId()); - assertEquals(domain, event.getDomain()); - assertEquals(title, event.getTitle()); - assertEquals(description, event.getDescription()); - assertEquals(priority, event.getPriority()); - assertEquals(timeOccurred, event.getTimeOcurred()); - assertEquals(eventPayload, event.getEvent()); - } - - @Test - void testEquals() { - ExportJobStateChangeEvent event1 = new ExportJobStateChangeEvent(); - event1.setId("testId"); - event1.setHref("testHref"); - event1.setEventId("testEventId"); - event1.setEventTime(OffsetDateTime.now()); - event1.setEventType("testEventType"); - event1.setCorrelationId("testCorrelationId"); - event1.setDomain("testDomain"); - event1.setTitle("testTitle"); - event1.setDescription("testDescription"); - event1.setPriority("testPriority"); - event1.setTimeOcurred(OffsetDateTime.now()); - event1.setEvent(new ExportJobStateChangeEventPayload()); - - ExportJobStateChangeEvent event2 = new ExportJobStateChangeEvent(); - event2.setId("testId"); - event2.setHref("testHref"); - event2.setEventId("testEventId"); - event2.setEventTime(event1.getEventTime()); - event2.setEventType("testEventType"); - event2.setCorrelationId("testCorrelationId"); - event2.setDomain("testDomain"); - event2.setTitle("testTitle"); - event2.setDescription("testDescription"); - event2.setPriority("testPriority"); - event2.setTimeOcurred(event1.getTimeOcurred()); - event2.setEvent(new ExportJobStateChangeEventPayload()); - - assertTrue(event1.equals(event2)); - - event1.setId("differentId"); - - assertFalse(event1.equals(event2)); - } - - @Test - void testHashCode() { - ExportJobStateChangeEvent event1 = new ExportJobStateChangeEvent(); - event1.setId("testId"); - event1.setHref("testHref"); - event1.setEventId("testEventId"); - event1.setEventTime(OffsetDateTime.now()); - event1.setEventType("testEventType"); - event1.setCorrelationId("testCorrelationId"); - event1.setDomain("testDomain"); - event1.setTitle("testTitle"); - event1.setDescription("testDescription"); - event1.setPriority("testPriority"); - event1.setTimeOcurred(OffsetDateTime.now()); - event1.setEvent(new ExportJobStateChangeEventPayload()); - - ExportJobStateChangeEvent event2 = new ExportJobStateChangeEvent(); - event2.setId("testId"); - event2.setHref("testHref"); - event2.setEventId("testEventId"); - event2.setEventTime(event1.getEventTime()); - event2.setEventType("testEventType"); - event2.setCorrelationId("testCorrelationId"); - event2.setDomain("testDomain"); - event2.setTitle("testTitle"); - event2.setDescription("testDescription"); - event2.setPriority("testPriority"); - event2.setTimeOcurred(event1.getTimeOcurred()); - event2.setEvent(new ExportJobStateChangeEventPayload()); - - assertEquals(event1.hashCode(), event2.hashCode()); - - event1.setId("differentId"); - - assertNotEquals(event1.hashCode(), event2.hashCode()); - } - - @Test - void testToString() { - ExportJobStateChangeEvent event = new ExportJobStateChangeEvent(); - event.setId("testId"); - event.setHref("testHref"); - event.setEventId("testEventId"); - event.setEventTime(OffsetDateTime.parse("2024-01-19T17:02:03.289504717+02:00")); - event.setEventType("testEventType"); - event.setCorrelationId("testCorrelationId"); - event.setDomain("testDomain"); - event.setTitle("testTitle"); - event.setDescription("testDescription"); - event.setPriority("testPriority"); - event.setTimeOcurred(OffsetDateTime.parse("2024-01-19T17:02:03.289527665+02:00")); - event.setEvent(new ExportJobStateChangeEventPayload()); - - String expectedString = "class ExportJobStateChangeEvent {\n" + - " id: testId\n" + - " href: testHref\n" + - " eventId: testEventId\n" + - " eventTime: 2024-01-19T17:02:03.289504717+02:00\n" + - " eventType: testEventType\n" + - " correlationId: testCorrelationId\n" + - " domain: testDomain\n" + - " title: testTitle\n" + - " description: testDescription\n" + - " priority: testPriority\n" + - " timeOcurred: 2024-01-19T17:02:03.289527665+02:00\n" + - " event: class ExportJobStateChangeEventPayload {\n" + - " exportJob: null\n" + - " }\n" + - "}"; - - assertEquals(expectedString, event.toString()); - } - - @Test - void testToIndentedString() throws Exception { - ExportJobStateChangeEvent event = new ExportJobStateChangeEvent(); - - Method method = ExportJobStateChangeEvent.class.getDeclaredMethod("toIndentedString", Object.class); - method.setAccessible(true); - - String input = "Hello\nWorld"; - String expectedOutput = "Hello\n World"; - - String output = (String) method.invoke(event, input); - - assertEquals(expectedOutput, output); - } - - @Test - void testExportJob() { - ExportJobStateChangeEventPayload payload = new ExportJobStateChangeEventPayload(); - ExportJob job = new ExportJob(); - job.setId("testId"); - payload.setExportJob(job); - assertEquals(job, payload.getExportJob()); - - ExportJob newJob = new ExportJob(); - newJob.setId("newTestId"); - ExportJobStateChangeEventPayload newPayload = payload.exportJob(newJob); - assertEquals(payload, newPayload); - assertEquals(newJob, payload.getExportJob()); - } -} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobTest.java deleted file mode 100644 index 07567d68..00000000 --- a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobTest.java +++ /dev/null @@ -1,266 +0,0 @@ -package org.etsi.osl.services.api.rcm634; - -import org.etsi.osl.tmf.rcm634.model.ExportJob; -import org.etsi.osl.tmf.rcm634.model.JobStateType; -import org.junit.jupiter.api.Test; -import java.time.OffsetDateTime; -import static org.junit.jupiter.api.Assertions.*; - -public class ExportJobTest { - - @Test - void testExportJob() { - ExportJob job = new ExportJob(); - String id = "testId"; - String query = "testQuery"; - OffsetDateTime completionDate = OffsetDateTime.now(); - OffsetDateTime creationDate = OffsetDateTime.now(); - String contentType = "testContentType"; - String errorLog = "testErrorLog"; - String path = "testPath"; - String url = "testUrl"; - - job.id(id); - job.query(query); - job.setCompletionDate(completionDate); - job.setCreationDate(creationDate); - job.setContentType(contentType); - job.setErrorLog(errorLog); - job.setPath(path); - job.setUrl(url); - - assertEquals(id, job.getId()); - assertEquals(query, job.getQuery()); - assertEquals(completionDate, job.getCompletionDate()); - assertEquals(creationDate, job.getCreationDate()); - assertEquals(contentType, job.getContentType()); - assertEquals(errorLog, job.getErrorLog()); - assertEquals(path, job.getPath()); - assertEquals(url, job.getUrl()); - - job = new ExportJob(); - job.setId(id); - job.setQuery(query); - job.setCompletionDate(completionDate); - job.setCreationDate(creationDate); - job.setContentType(contentType); - job.setErrorLog(errorLog); - job.setPath(path); - job.setUrl(url); - - assertEquals(id, job.getId()); - assertEquals(query, job.getQuery()); - assertEquals(completionDate, job.getCompletionDate()); - assertEquals(creationDate, job.getCreationDate()); - assertEquals(contentType, job.getContentType()); - assertEquals(errorLog, job.getErrorLog()); - assertEquals(path, job.getPath()); - assertEquals(url, job.getUrl()); - } - - @Test - void testEquals() { - String id = "testId"; - String callback = "testCallback"; - String query = "testQuery"; - OffsetDateTime completionDate = OffsetDateTime.now(); - OffsetDateTime creationDate = OffsetDateTime.now(); - String contentType = "testContentType"; - String errorLog = "testErrorLog"; - String path = "testPath"; - String url = "testUrl"; - - ExportJob job1 = new ExportJob(); - job1.setId(id); - job1.setQuery(query); - job1.setCompletionDate(completionDate); - job1.setCreationDate(creationDate); - job1.setContentType(contentType); - job1.setErrorLog(errorLog); - job1.setPath(path); - job1.setUrl(url); - - ExportJob job2 = new ExportJob(); - job2.setId(id); - job2.setQuery(query); - job2.setCompletionDate(completionDate); - job2.setCreationDate(creationDate); - job2.setContentType(contentType); - job2.setErrorLog(errorLog); - job2.setPath(path); - job2.setUrl(url); - - assertTrue(job1.equals(job2)); - - job1.id("differentId"); - - assertFalse(job1.equals(job2)); - } - - @Test - void testHashCode() { - String id = "testId"; - String callback = "testCallback"; - String query = "testQuery"; - OffsetDateTime completionDate = OffsetDateTime.now(); - OffsetDateTime creationDate = OffsetDateTime.now(); - String contentType = "testContentType"; - String errorLog = "testErrorLog"; - String path = "testPath"; - String url = "testUrl"; - - ExportJob job1 = new ExportJob(); - job1.setId(id); - job1.setQuery(query); - job1.setCompletionDate(completionDate); - job1.setCreationDate(creationDate); - job1.setContentType(contentType); - job1.setErrorLog(errorLog); - job1.setPath(path); - job1.setUrl(url); - - ExportJob job2 = new ExportJob(); - job2.setId(id); - job2.setQuery(query); - job2.setCompletionDate(completionDate); - job2.setCreationDate(creationDate); - job2.setContentType(contentType); - job2.setErrorLog(errorLog); - job2.setPath(path); - job2.setUrl(url); - - assertEquals(job1.hashCode(), job2.hashCode()); - - job1.id("differentId"); - - assertNotEquals(job1.hashCode(), job2.hashCode()); - } - - @Test - void testToString() { - ExportJob job = new ExportJob(); - - String id = "testId"; - String callback = "testCallback"; - String query = "testQuery"; - OffsetDateTime completionDate = OffsetDateTime.parse("2024-01-19T16:35:07.730526064+02:00"); - OffsetDateTime creationDate = OffsetDateTime.parse("2024-01-19T16:35:07.731493435+02:00"); - String contentType = "testContentType"; - String errorLog = "testErrorLog"; - String path = "testPath"; - String url = "testUrl"; - - job.id(id); - job.query(query); - job.setCompletionDate(completionDate); - job.setCreationDate(creationDate); - job.setContentType(contentType); - job.setErrorLog(errorLog); - job.setPath(path); - job.setUrl(url); - - String expectedString = "class ExportJob {\n" + - " id: testId\n" + - " href: null\n" + - " completionDate: 2024-01-19T16:35:07.730526064+02:00\n" + - " contentType: testContentType\n" + - " creationDate: 2024-01-19T16:35:07.731493435+02:00\n" + - " errorLog: testErrorLog\n" + - " path: testPath\n" + - " query: testQuery\n" + - " url: testUrl\n" + - " status: null\n" + - " _atBaseType: null\n" + - " _atSchemaLocation: null\n" + - " _atType: null\n" + - "}"; - - assertEquals(expectedString, job.toString()); - } - - @Test - void testHref() { - ExportJob job = new ExportJob(); - String href = "testHref"; - job.setHref(href); - assertEquals(href, job.getHref()); - - ExportJob newJob = job.href("newTestHref"); - assertEquals(job, newJob); - } - - @Test - void testCompletionDate() { - ExportJob job = new ExportJob(); - OffsetDateTime completionDate = OffsetDateTime.now(); - job.setCompletionDate(completionDate); - assertEquals(completionDate, job.getCompletionDate()); - - ExportJob newJob = job.completionDate(OffsetDateTime.now()); - assertEquals(job, newJob); - } - - @Test - void testContentType() { - ExportJob job = new ExportJob(); - String contentType = "testContentType"; - job.setContentType(contentType); - assertEquals(contentType, job.getContentType()); - - ExportJob newJob = job.contentType("newTestContentType"); - assertEquals(job, newJob); - } - - @Test - void testCreationDate() { - ExportJob job = new ExportJob(); - OffsetDateTime creationDate = OffsetDateTime.now(); - job.setCreationDate(creationDate); - assertEquals(creationDate, job.getCreationDate()); - } - - @Test - void testStatus() { - ExportJob job = new ExportJob(); - JobStateType status = JobStateType.RUNNING; - job.setStatus(status); - assertEquals(status, job.getStatus()); - - ExportJob newJob = job.status(JobStateType.FAILED); - assertEquals(job, newJob); - } - - @Test - void testAtBaseType() { - ExportJob job = new ExportJob(); - String baseType = "testBaseType"; - job.setAtBaseType(baseType); - assertEquals(baseType, job.getAtBaseType()); - - ExportJob newJob = job._atBaseType("newTestBaseType"); - assertEquals(job, newJob); - } - - @Test - void testAtSchemaLocation() { - ExportJob job = new ExportJob(); - String schemaLocation = "testSchemaLocation"; - job.setAtSchemaLocation(schemaLocation); - assertEquals(schemaLocation, job.getAtSchemaLocation()); - - ExportJob newJob = job._atSchemaLocation("newTestSchemaLocation"); - assertEquals(job, newJob); - } - - @Test - void testAtType() { - ExportJob job = new ExportJob(); - String type = "testType"; - job.setAtType(type); - assertEquals(type, job.getAtType()); - - ExportJob newJob = job._atType("newTestType"); - assertEquals(job, newJob); - } - -} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java b/src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java deleted file mode 100644 index 14a8a40f..00000000 --- a/src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.etsi.osl.services.api.scm633; - -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; - -import org.apache.commons.io.IOUtils; - -import org.etsi.osl.tmf.OpenAPISpringBoot; -import org.etsi.osl.tmf.scm633.model.*; -import org.etsi.osl.tmf.JsonUtils; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.context.WebApplicationContext; - - -@RunWith(SpringRunner.class) -@Transactional -@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) -@AutoConfigureMockMvc -@ActiveProfiles("testing") -public class ExportJobApiController633Test { - - @Autowired - private MockMvc mvc; - - @Autowired - private WebApplicationContext context; - - @Before - public void setup() { - mvc = MockMvcBuilders - .webAppContextSetup(context) - .apply(springSecurity()) - .build(); - } - - - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) - @Test - public void testCreateExportJob() throws Exception { - - File resourceSpecFile = new File("src/test/resources/testExportJob.json"); - InputStream in = new FileInputStream(resourceSpecFile); - String exportJobString = IOUtils.toString(in, "UTF-8"); - ExportJobCreate exportJobCreate = JsonUtils.toJsonObj(exportJobString, ExportJobCreate.class); - - // Test when providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/exportJob") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON) - .content( JsonUtils.toJson( exportJobCreate ) )) - .andExpect(status().is(501)); - - // Test when not providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/exportJob") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .content( JsonUtils.toJson( exportJobCreate ) )) - .andExpect(status().is(501)); - } - - - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) - @Test - public void testDeleteExportJob() throws Exception { - - mvc.perform(MockMvcRequestBuilders.delete("/serviceCatalogManagement/v4/exportJob/testId") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - } - - - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) - @Test - public void testListExportJob() throws Exception { - - // Test when providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/exportJob") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - - // Test when not providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/exportJob") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - } - - - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) - @Test - public void testRetrieveExportJob() throws Exception { - - // Test when providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/exportJob?testId") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - - // Test when not providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/exportJob/testId") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - } -} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java deleted file mode 100644 index 0d376988..00000000 --- a/src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.etsi.osl.services.api.scm633; - -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; - -import org.apache.commons.io.IOUtils; - -import org.etsi.osl.tmf.OpenAPISpringBoot; -import org.etsi.osl.tmf.scm633.model.*; -import org.etsi.osl.tmf.JsonUtils; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.context.WebApplicationContext; - - -@RunWith(SpringRunner.class) -@Transactional -@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) -@AutoConfigureMockMvc -@ActiveProfiles("testing") -public class ImportJobApiControllerTest { - - @Autowired - private MockMvc mvc; - - @Autowired - private WebApplicationContext context; - - @Before - public void setup() { - mvc = MockMvcBuilders - .webAppContextSetup(context) - .apply(springSecurity()) - .build(); - } - - - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) - @Test - public void testCreateImportJob() throws Exception { - - File resourceSpecFile = new File("src/test/resources/testExportJob.json"); - InputStream in = new FileInputStream(resourceSpecFile); - String exportJobString = IOUtils.toString(in, "UTF-8"); - ExportJobCreate exportJobCreate = JsonUtils.toJsonObj(exportJobString, ExportJobCreate.class); - - // Test when providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/importJob") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON) - .content( JsonUtils.toJson( exportJobCreate ) )) - .andExpect(status().is(501)); - - // Test when not providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/importJob") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .content( JsonUtils.toJson( exportJobCreate ) )) - .andExpect(status().is(501)); - } - - - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) - @Test - public void testDeleteImportJob() throws Exception { - - mvc.perform(MockMvcRequestBuilders.delete("/serviceCatalogManagement/v4/importJob/testId") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - } - - - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) - @Test - public void testListImportJob() throws Exception { - - // Test when providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/importJob") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - - // Test when not providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/importJob") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - } - - - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) - @Test - public void testRetrieveImportJob() throws Exception { - - // Test when providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/importJob?testId") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - - // Test when not providing an "Accept" request header - mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/importJob/testId") - .with(SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().is(501)); - } -} \ No newline at end of file -- GitLab