aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorEzekielaRakotoarijaona <ezekiela.rakotoarijaona@orange.com>2019-01-11 14:53:30 +0100
committerEzekielaRakotoarijaona <ezekiela.rakotoarijaona@orange.com>2019-01-18 17:28:05 +0100
commit05733ab5105f440e44eb56dc37e6d14615c36454 (patch)
tree3989eb8552ab271c9d5ba0a37b99960c49b36259 /src/test/java
parent09d6ce6112d61a7fc98c3038afce636b3e494f29 (diff)
Fix unit testing instability
Migration of most of the unit tests from JUnit to Karate Framework Remove of the scheduling tasks for testing. Change-Id: Ic51378443bd6c12f247fa50b2b08ee881264dac4 Issue-ID: EXTAPI-178 Signed-off-by: EzekielaRakotoarijaona <ezekiela.rakotoarijaona@orange.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/joe.jpage10
-rw-r--r--src/test/java/karate-config.js8
-rw-r--r--src/test/java/org/onap/nbi/apis/ApiTest.java1332
-rw-r--r--src/test/java/org/onap/nbi/apis/StatusResourceTest.java64
-rw-r--r--src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java58
-rw-r--r--src/test/java/org/onap/nbi/apis/assertions/ServiceCatalogAssertions.java158
-rw-r--r--src/test/java/org/onap/nbi/apis/assertions/ServiceInventoryAssertions.java122
-rw-r--r--src/test/java/org/onap/nbi/apis/assertions/ServiceOrderExecutionTaskAssertions.java (renamed from src/test/java/org/onap/nbi/apis/assertions/ServiceOrderAssertions.java)2
-rw-r--r--src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java273
-rw-r--r--src/test/java/org/onap/nbi/test/ApiTestWithoutOnap.java (renamed from src/test/java/org/onap/nbi/apis/ApiTestWithoutOnap.java)16
-rw-r--r--src/test/java/org/onap/nbi/test/Context.java98
-rw-r--r--src/test/java/org/onap/nbi/test/ExecutionTaskTest.java548
-rw-r--r--src/test/java/org/onap/nbi/test/KarateApiTest.java30
-rw-r--r--src/test/java/org/onap/nbi/test/ServiceOrderRepositoryTest.java (renamed from src/test/java/org/onap/nbi/apis/ServiceOrderRepositoryTest.java)8
14 files changed, 713 insertions, 2014 deletions
diff --git a/src/test/java/joe.jpage b/src/test/java/joe.jpage
new file mode 100644
index 0000000..0e28672
--- /dev/null
+++ b/src/test/java/joe.jpage
@@ -0,0 +1,10 @@
+java.io.File file = new java.io.File("/home/user/Source/starck-xsl/spec.json");
+String jsonStr = org.apache.commons.io.FileUtils.readFileToString(file);
+
+System.out.println(jsonStr);
+
+org.json.JSONObject json = new org.json.JSONObject(jsonStr);
+String xml = org.json.XML.toString(json);
+
+System.out.println(xml);
+
diff --git a/src/test/java/karate-config.js b/src/test/java/karate-config.js
new file mode 100644
index 0000000..f67e555
--- /dev/null
+++ b/src/test/java/karate-config.js
@@ -0,0 +1,8 @@
+function() {
+ var config = {
+ nbiBaseUrl: 'http://localhost:8080/nbi/api/v3'
+ };
+ karate.configure('connectTimeout', 5000);
+ karate.configure('readTimeout', 5000);
+ return config;
+}
diff --git a/src/test/java/org/onap/nbi/apis/ApiTest.java b/src/test/java/org/onap/nbi/apis/ApiTest.java
deleted file mode 100644
index 696aa57..0000000
--- a/src/test/java/org/onap/nbi/apis/ApiTest.java
+++ /dev/null
@@ -1,1332 +0,0 @@
-/**
- * Copyright (c) 2018 Orange
- *
- * 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.
- */
-package org.onap.nbi.apis;
-
-
-import com.github.tomakehurst.wiremock.WireMockServer;
-import com.github.tomakehurst.wiremock.http.ResponseDefinition;
-import com.github.tomakehurst.wiremock.stubbing.ListStubMappingsResult;
-import com.github.tomakehurst.wiremock.stubbing.StubMapping;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Set;
-import javax.validation.Validation;
-import javax.validation.Validator;
-import javax.validation.ValidatorFactory;
-
-import org.junit.*;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.onap.nbi.apis.assertions.HubAssertions;
-import org.onap.nbi.apis.assertions.ServiceCatalogAssertions;
-import org.onap.nbi.apis.assertions.ServiceInventoryAssertions;
-import org.onap.nbi.apis.assertions.ServiceOrderAssertions;
-import org.onap.nbi.apis.hub.HubResource;
-import org.onap.nbi.apis.hub.model.Subscriber;
-import org.onap.nbi.apis.hub.model.Subscription;
-import org.onap.nbi.apis.hub.service.SubscriptionService;
-import org.onap.nbi.apis.servicecatalog.ServiceSpecificationResource;
-import org.onap.nbi.apis.serviceinventory.ServiceInventoryResource;
-import org.onap.nbi.apis.serviceorder.ServiceOrderResource;
-import org.onap.nbi.apis.serviceorder.model.*;
-import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask;
-import org.onap.nbi.apis.serviceorder.repositories.ExecutionTaskRepository;
-import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
-import org.onap.nbi.apis.serviceorder.workflow.SOTaskProcessor;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.context.embedded.LocalServerPort;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.http.ResponseEntity;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.context.request.RequestAttributes;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@RunWith(SpringRunner.class)
-@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
-public class ApiTest {
-
- @LocalServerPort
- int randomServerPort;
-
- String realServerPort;
-
- static public WireMockServer wireMockServer = new WireMockServer(8091);
-
- @Autowired
- ServiceSpecificationResource serviceSpecificationResource;
-
- @Autowired
- ServiceInventoryResource serviceInventoryResource;
-
- @Autowired
- ServiceOrderResource serviceOrderResource;
-
- @Autowired
- HubResource hubResource;
-
- @Autowired
- SubscriptionService subscriptionService;
-
- @Autowired
- ServiceOrderRepository serviceOrderRepository;
-
- @Autowired
- ExecutionTaskRepository executionTaskRepository;
-
- @Autowired
- SOTaskProcessor SoTaskProcessor;
-
- @Mock
- private RequestAttributes attrs;
-
- static Validator validator;
-
- @Value("${scheduler.pollingDurationInMins}")
- private float pollingDurationInMins;
-
- @Before
- public void before() {
- MockHttpServletRequest request = new MockHttpServletRequest();
- RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
- }
-
- @BeforeClass
- public static void setUp() throws Exception {
- wireMockServer.start();
- ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
- validator = factory.getValidator();
- }
-
- @AfterClass
- public static void tearsDown() throws Exception {
- wireMockServer.stop();
-
- }
-
- @After
- public void tearsDownUpPort() throws Exception {
- executionTaskRepository.deleteAll();
- serviceOrderRepository.deleteAll();
- subscriptionService.deleteAll();
- wireMockServer.resetToDefaultMappings();
-
- }
-
-
- public ExecutionTask getExecutionTask(String orderItemId) {
- for (ExecutionTask executionTask : executionTaskRepository.findAll()) {
- if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) {
- return executionTask;
- }
-
- }
- return null;
- }
-
- private void removeWireMockMapping(String s) {
- ListStubMappingsResult listStubMappingsResult = wireMockServer.listAllStubMappings();
- StubMapping mappingToDelete = null;
- List<StubMapping> mappings = listStubMappingsResult.getMappings();
- for (StubMapping mapping : mappings) {
- if (mapping.getRequest().getUrl().equals(s)) {
- mappingToDelete = mapping;
- }
-
-
- }
-
- wireMockServer.removeStubMapping(mappingToDelete);
- }
-
- private void changeWireMockResponse(String s,int statusCode, String bodyContent) {
- ListStubMappingsResult listStubMappingsResult = wireMockServer.listAllStubMappings();
- ResponseDefinition responseDefinition = new ResponseDefinition(statusCode,bodyContent);
- List<StubMapping> mappings = listStubMappingsResult.getMappings();
- for (StubMapping mapping : mappings) {
- if (mapping.getRequest().getUrl().equals(s)) {
- mapping.setResponse(responseDefinition);
- }
- }
- }
-
-
-
-
- // serviceCatalog
-
-
- @Test
- @Ignore
- public void testServiceResourceGetCatalog() throws Exception {
-
- ResponseEntity<Object> resource =
- serviceSpecificationResource.getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
- ServiceCatalogAssertions.assertGetServiceCatalog(resource);
-
- }
-
- @Test
- public void testServiceCatalogGetResourceWithoutTosca() throws Exception {
-
- ResponseEntity<Object> resource = serviceSpecificationResource
- .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439_withoutTosca", null);
- ServiceCatalogAssertions.assertGetServiceCatalogWithoutTosca(resource);
-
- }
-
- @Test
- public void testServiceCatalogFind() throws Exception {
-
- ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(null);
- ServiceCatalogAssertions.assertFindServiceCatalog(resource);
-
- }
-
-
- @Test
- public void testServiceCatalogFindWithFilter() throws Exception {
-
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- params.add("fields", "name");
- ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(params);
- ServiceCatalogAssertions.assertFindServiceCatalogWIthFilter(resource);
-
- }
-
- // serviceInventory
-
- @Test
- public void testServiceResourceGetInventory() throws Exception {
-
- String serviceName = "vFW";
- String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- params.add("serviceSpecification.name", serviceName);
- params.add("relatedParty.id", "6490");
- ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
- ServiceInventoryAssertions.assertServiceInventoryGet(resource);
-
- }
-
- @Test
- public void testServiceResourceGetInventoryWithStatus() throws Exception {
-
- String serviceName = "AnsibleService";
- String serviceId = "405c8c00-44b9-4303-9f27-6797d22ca096";
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- params.add("serviceSpecification.name", serviceName);
- params.add("relatedParty.id", "6490");
- ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
- LinkedHashMap service = (LinkedHashMap) resource.getBody();
- assertThat(service.get("state")).isEqualTo("Active");
-
-
- }
-
- @Test
- public void testServiceResourceGetInventoryWithoutRelationShipList() throws Exception {
-
- String serviceName = "vFW";
- String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcbWithoutList";
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- params.add("serviceSpecification.name", serviceName);
- params.add("relatedParty.id", "6490");
- ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
- ServiceInventoryAssertions.assertServiceInventoryGetWithoutList(resource);
-
- }
-
-
- @Test
- public void testServiceResourceGetInventoryWithServiceSpecId() throws Exception {
-
- String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- params.add("serviceSpecification.id", "1e3feeb0-8e36-46c6-862c-236d9c626439");
- params.add("relatedParty.id", "6490");
- ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
- ServiceInventoryAssertions.assertServiceInventoryGet(resource);
-
- }
-
-
- @Test
- public void testServiceInventoryFind() throws Exception {
-
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- String serviceName = "vFW";
- params.add("serviceSpecification.name", serviceName);
- params.add("relatedParty.id", "6490");
-
- ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
- ServiceInventoryAssertions.assertServiceInventoryFind(resource);
-
- }
-
-
- @Test
- public void testServiceInventoryFindWithServiceSpecId() throws Exception {
-
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- params.add("serviceSpecification.id", "1e3feeb0-8e36-46c6-862c-236d9c626439");
- params.add("relatedParty.id", "6490");
-
- ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
- ServiceInventoryAssertions.assertServiceInventoryFind(resource);
-
- }
-
-
- @Test
- public void testServiceInventoryFindWithoutParameter() throws Exception {
-
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- params.add("relatedParty.id", "6490");
-
- ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
- ServiceInventoryAssertions.assertServiceInventoryFindWithoutParameter(resource);
-
- }
-
- @Test
- public void testCreateServiceOrderResource() throws Exception {
-
- ResponseEntity<Object> serviceOrder = serviceOrderResource
- .createServiceOrder(ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD), null, null);
- assertThat(serviceOrder.getStatusCodeValue()).isEqualTo(201);
- ServiceOrder body = (ServiceOrder) serviceOrder.getBody();
- assertThat(body.getId()).isNotNull();
- assertThat(body.getState()).isEqualTo(StateType.ACKNOWLEDGED);
-
-
- }
-
- @Test
- public void testCheckServiceOrder() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.ACKNOWLEDGED);
-
- }
-
-
- @Test
- public void testCheckServiceOrderWithUnknownSverviceSpecId() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- serviceOrderItem.getService().getServiceSpecification().setId("toto");
- }
-
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("102");
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("serviceSpecification.id");
- }
- }
-
- @Test
- public void testCheckServiceOrderWithGenericCustomer() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- testServiceOrder.setRelatedParty(new ArrayList<>());
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.ACKNOWLEDGED);
-
- }
-
-
- @Test
- public void testCheckServiceOrderWithoutRelatedParty() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- testServiceOrder.setRelatedParty(null);
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.ACKNOWLEDGED);
-
-
- }
-
- @Test
- public void testCheckServiceOrderWithUnKnownCustomer() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- List<RelatedParty> customers = new ArrayList<>();
- RelatedParty customer = new RelatedParty();
- customer.setId("new");
- customer.setRole("ONAPcustomer");
- customer.setName("romain");
- customers.add(customer);
- testServiceOrder.setRelatedParty(customers);
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.ACKNOWLEDGED);
-
- }
-
- @Test
- public void testCheckServiceOrderInDeleteWithNoServiceId() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.DELETE);
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- serviceOrderItem.getService().setId(null);
- }
-
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("101");
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("service.id");
- }
- }
-
-
- @Test
- public void testCheckServiceOrderInModifyWithNoServiceId() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.MODIFY);
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- serviceOrderItem.getService().setId(null);
- }
-
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("101");
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("service.id");
- }
- }
-
- @Test
- public void testCheckServiceOrderInAddWithServiceId() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- serviceOrderItem.getService().setId("toto");
- }
-
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("103");
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("service.id");
- }
- }
-
- @Test
- public void testCheckServiceOrderWithUnKnownCustomerInChange() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.DELETE);
- List<RelatedParty> customers = new ArrayList<>();
- RelatedParty customer = new RelatedParty();
- customer.setId("new");
- customer.setRole("ONAPcustomer");
- customer.setName("romain");
- customers.add(customer);
- testServiceOrder.setRelatedParty(customers);
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
- assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
- assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("104");
- assertThat(serviceOrderChecked.getOrderMessage().get(0).getField()).isEqualTo("relatedParty.id");
- }
-
-
-
- @Test
- public void testCheckServiceOrderWithCustomerAAINotResponding() throws Exception {
-
- removeWireMockMapping("/aai/v11/business/customers/customer/new");
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- List<RelatedParty> customers = new ArrayList<>();
- RelatedParty customer = new RelatedParty();
- customer.setId("new");
- customer.setRole("ONAPcustomer");
- customer.setName("romain");
- customers.add(customer);
- testServiceOrder.setRelatedParty(customers);
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
-
- assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
- assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("501");
- assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with AAI API");
- }
-
-
- @Test
- public void testCheckServiceOrderWithSDCNotResponding() throws Exception {
-
- removeWireMockMapping("/sdc/v1/catalog/services/1e3feeb0-8e36-46c6-862c-236d9c626439/metadata");
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- List<RelatedParty> customers = new ArrayList<>();
- RelatedParty customer = new RelatedParty();
- customer.setId("new");
- customer.setRole("ONAPcustomer");
- customer.setName("romain");
- customers.add(customer);
- testServiceOrder.setRelatedParty(customers);
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
-
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("102");
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("serviceSpecification.id");
- }
- }
-
-
-
-
- @Test
- public void testCheckServiceOrderWithPutServiceAAINotResponding() throws Exception {
-
- removeWireMockMapping("/aai/v11/business/customers/customer/new/service-subscriptions/service-subscription/vFW");
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- List<RelatedParty> customers = new ArrayList<>();
- RelatedParty customer = new RelatedParty();
- customer.setId("new");
- customer.setRole("ONAPcustomer");
- customer.setName("romain");
- customers.add(customer);
- testServiceOrder.setRelatedParty(customers);
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
- }
-
-
- @Test
- public void testCheckServiceOrderDelete() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.DELETE);
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- serviceOrderItem.setState(StateType.ACKNOWLEDGED);
- }
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.ACKNOWLEDGED);
-
- }
-
- @Test
- public void testCheckServiceOrderDeleteRejected() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.DELETE);
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- serviceOrderItem.getService().setId("no_response");
-
- }
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("106");
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("service.id");
- }
- }
-
- @Test
- public void testCheckServiceOrderNoChange() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.DELETE);
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- serviceOrderItem.setAction(ActionType.NOCHANGE);
- }
-
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
- }
-
- }
-
-
-
- @Test
- public void testCheckServiceOrderNoChangeAndDelete() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.DELETE);
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- serviceOrderItem.setAction(ActionType.NOCHANGE);
- }
- serviceOrderItem.setState(StateType.ACKNOWLEDGED);
- }
-
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A"))
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
- }
- }
-
-
- @Test
- public void testCheckServiceOrderDeleteWithKoServiceSpecId() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.DELETE);
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- serviceOrderItem.getService().getServiceSpecification().setId("undefined");
- }
-
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A"))
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.REJECTED);
- }
- }
-
-
-
-
- @Test
- public void testCheckServiceOrderRejected() throws Exception {
-
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrderRejected();
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
- serviceOrderResource.scheduleCheckServiceOrders();
-
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if(serviceOrderItem.getId().equals("A")) {
- assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("102");
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("serviceSpecification.id");
- }
- }
- }
-
- @Test
- public void validateServiceOrderBeanWithAnnotation() {
- ServiceOrder serviceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- Set violations = validator.validate(serviceOrder);
- assertThat(violations).isEmpty();
-
- ServiceOrderItem item = new ServiceOrderItem();
- item.setAction(ActionType.DELETE);
- item.setService(new Service());
- serviceOrder.addOrderItemItem(item);
-
- violations = validator.validate(serviceOrder);
- assertThat(violations).isNotEmpty();
-
- ServiceOrder serviceOrder2 = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- serviceOrder2.getOrderItem().get(0).getService().getServiceSpecification().setId("");
- serviceOrder2.getOrderItem().get(1).getService().getServiceSpecification().setId(" ");
-
- violations = validator.validate(serviceOrder2);
- assertThat(violations).isNotEmpty();
- assertThat(violations.size()).isEqualTo(2);
-
- }
-
-
-
- @Test
- public void testFindAndGetServiceOrder() throws Exception {
-
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) {
- serviceOrderItem.setState(StateType.ACKNOWLEDGED);
- }
- testServiceOrder.setExternalId("extid1");
- testServiceOrder.setOrderDate(new Date());
- testServiceOrder.setState(StateType.ACKNOWLEDGED);
- testServiceOrder.setDescription("toto");
- testServiceOrder.setId("test");
- serviceOrderRepository.save(testServiceOrder);
-
-
- ServiceOrder testServiceOrder2 = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
- testServiceOrder2.setState(StateType.ACKNOWLEDGED);
- testServiceOrder2.setDescription("toto");
- testServiceOrder2.setId("test2");
- testServiceOrder2.setExternalId("extid2");
- testServiceOrder2.setOrderDate(new Date());
-
- serviceOrderRepository.save(testServiceOrder2);
-
-
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- params.add("fields", "id");
-
- ResponseEntity<Object> serviceOrdersResponse = serviceOrderResource.findServiceOrder(params);
- ArrayList serviceOrders = (ArrayList) serviceOrdersResponse.getBody();
- assertThat(serviceOrders.size()).isEqualTo(2);
-
- params.add("externalId", "extid1");
- params.add("state", "acknowledged");
-
- serviceOrdersResponse = serviceOrderResource.findServiceOrder(params);
- serviceOrders = (ArrayList) serviceOrdersResponse.getBody();
- assertThat(serviceOrders.size()).isEqualTo(1);
-
- MultiValueMap<String, String> paramsDate = new LinkedMultiValueMap<>();
- paramsDate.add("orderDate.gt", "2017-01-01T00:00:00.000Z");
- paramsDate.add("orderDate.lt", "2030-01-01T00:00:00.000Z");
- paramsDate.add("offset", "0");
- paramsDate.add("limit", "2");
-
- serviceOrdersResponse = serviceOrderResource.findServiceOrder(paramsDate);
- serviceOrders = (ArrayList) serviceOrdersResponse.getBody();
- assertThat(serviceOrders.size()).isEqualTo(2);
-
-
- ResponseEntity<Object> serviceOrderResponse =
- serviceOrderResource.getServiceOrder("test2", new LinkedMultiValueMap<>());
- ServiceOrder serviceOrder = (ServiceOrder) serviceOrderResponse.getBody();
- assertThat(serviceOrder).isNotNull();
- }
-
-
-
- @Test
- public void testExecutionTaskSuccess() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.ADD);
- ExecutionTask executionTaskB;
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
- } else {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- }
- }
-
- executionTaskB = getExecutionTask("B");
- assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
- executionTaskA = getExecutionTask("A");
- assertThat(executionTaskA).isNull();
-
- SoTaskProcessor.processOrderItem(executionTaskB);
- serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
-
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
-
-
- }
-
- @Test
- public void testE2EExecutionTaskSuccess() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.ADD);
- ExecutionTask executionTaskB;
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
- } else {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- }
- }
-
- executionTaskB = getExecutionTask("B");
- assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
- executionTaskA = getExecutionTask("A");
- assertThat(executionTaskA).isNull();
-
- SoTaskProcessor.processOrderItem(executionTaskB);
- serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
-
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
-
-
- }
-
- @Test
- public void testExecutionTaskDeleteSuccess() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.DELETE);
- ExecutionTask executionTaskB;
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
- } else {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- }
- }
-
- executionTaskB = getExecutionTask("B");
- assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
- executionTaskA = getExecutionTask("A");
- assertThat(executionTaskA).isNull();
-
- SoTaskProcessor.processOrderItem(executionTaskB);
- serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
-
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
-
-
- }
-
- @Test
- public void testE2EExecutionTaskDeleteSuccess() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.DELETE);
- ExecutionTask executionTaskB;
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
- } else {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- }
- }
-
- executionTaskB = getExecutionTask("B");
- assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
- executionTaskA = getExecutionTask("A");
- assertThat(executionTaskA).isNull();
-
- SoTaskProcessor.processOrderItem(executionTaskB);
- serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
-
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
-
-
- }
-
-
- @Test
- public void testExecutionTaskFailed() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.ADD);
-
- removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId");
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS);
- } else {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- }
- }
- executionTaskA = getExecutionTask("A");
- Date createDate = executionTaskA.getCreateDate();
- assertThat(executionTaskA.getLastAttemptDate().getTime()> createDate.getTime()).isTrue();
-
- changeCreationDate(executionTaskA);
- SoTaskProcessor.processOrderItem(executionTaskA);
-
- serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
-
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
-
- }
-
- private void changeCreationDate(ExecutionTask executionTaskA) {
- Calendar cal = Calendar.getInstance();
- cal.setTime(executionTaskA.getCreateDate());
- cal.add(Calendar.SECOND, -30);
- executionTaskA.setCreateDate(cal.getTime());
- }
-
-
- @Test
- public void testE2EExecutionTaskFailed() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.ADD);
-
- removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3/serviceId/operations/operationId");
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS);
- } else {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- }
- }
- executionTaskA = getExecutionTask("A");
- assertThat(executionTaskA.getLastAttemptDate().getTime()>executionTaskA.getCreateDate().getTime()).isTrue();
- changeCreationDate(executionTaskA);
- SoTaskProcessor.processOrderItem(executionTaskA);
-
- serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
-
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
-
- }
-
- @Test
- public void testExecutionTaskFailedNoSoResponse() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.ADD);
-
- removeWireMockMapping("/onap/so/infra/serviceInstantiation/v7/serviceInstances/");
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
-
-
- }
-
- @Test
- public void testExecutionTaskFailedNoSoAndStatusResponse() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.ADD);
-
- removeWireMockMapping("/onap/so/infra/serviceInstantiation/v7/serviceInstances/");
- removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId");
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
- }
-
- @Test
- public void testE2EExecutionTaskFailedNoSoAndStatusResponse() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.ADD);
-
- removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3");
- removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3/serviceId/operations/operationId");
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
- }
-
-
- @Test
- public void testExecutionTaskFailedBadRequestSo() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.ADD);
-
-
- changeWireMockResponse("/onap/so/infra/serviceInstantiation/v7/serviceInstances/",400,"\"serviceException\": {\n"
- + " \"messageId\": \"SVC0002\",\n"
- + " \"text\": \"Error parsing request. org.openecomp.mso.apihandler.common.ValidationException: serviceInstance already existsd\"\n"
- + " }");
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if(serviceOrderItem.getId().equals("A")) {
- assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("105");
- assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("service.name");
- }
- }
-
- }
-
-
- @Test
- public void testExecutionTaskModifySuccess() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.MODIFY);
- ExecutionTask executionTaskB;
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- //assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS);
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE);
- } else {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- }
- }
- SoTaskProcessor.processOrderItem(executionTaskA);
- serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
- } else {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- }
- }
-
- executionTaskB = getExecutionTask("B");
- assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
- executionTaskA = getExecutionTask("A");
- assertThat(executionTaskA).isNull();
-
- SoTaskProcessor.processOrderItem(executionTaskB);
- SoTaskProcessor.processOrderItem(executionTaskB);
-
- serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
-
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
- }
-
-
-
-
- @Test
- public void testExecutionTaskModifyFailed() throws Exception {
-
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
- executionTaskRepository, ActionType.MODIFY);
- ExecutionTask executionTaskB;
- removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId");
-
-
- SoTaskProcessor.processOrderItem(executionTaskA);
- ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- if (serviceOrderItem.getId().equals("A")) {
- //assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS);
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS_MODIFY_REQUEST_DELETE_SEND);
- } else {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
- }
- }
- executionTaskA = getExecutionTask("A");
- assertThat(executionTaskA.getLastAttemptDate().getTime()>executionTaskA.getCreateDate().getTime()).isTrue();
- changeCreationDate(executionTaskA);
- SoTaskProcessor.processOrderItem(executionTaskA);
-
- serviceOrderChecked = serviceOrderRepository.findOne("test");
- assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
- for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
- assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
-
- }
-
- assertThat(executionTaskRepository.count()).isEqualTo(0);
-
- }
-
- // hub
-
- @Test
- public void testFindWhenNoSubscriber() throws Exception {
- ResponseEntity<Object> findResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
- assertThat(findResponseEntity.getStatusCodeValue()).isEqualTo(200);
- ArrayList subscribers = (ArrayList) findResponseEntity.getBody();
- assertThat(subscribers.size()).isEqualTo(0);
- }
-
- @Test
- public void testSubscriberCreation() throws Exception {
- ResponseEntity<Subscriber> firstCreationResponseEntity = hubResource
- .createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
- assertThat(firstCreationResponseEntity.getStatusCodeValue()).isEqualTo(201);
- assertThat(firstCreationResponseEntity.getHeaders().getLocation()).isNotNull();
- assertThat(subscriptionService.countSubscription()).isEqualTo(1);
- }
-
- @Test
- public void testCreationAndFindSubscriber() throws Exception {
- ResponseEntity<Subscriber> firstCreationResponseEntity = hubResource
- .createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
- ResponseEntity<Object> findResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
- ArrayList subscribers = (ArrayList) findResponseEntity.getBody();
- assertThat(subscribers.size()).isEqualTo(1);
- }
-
- @Test
- public void testCreationAndGetByIdSubscriber() throws Exception {
- ResponseEntity<Subscriber> createResponseEntity = hubResource
- .createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
- String resourceId = createResponseEntity.getHeaders().getLocation().getPath().substring(1);
- ResponseEntity<Subscription> getResponseEntity = hubResource.getSubscription(resourceId);
- assertThat(getResponseEntity.getStatusCodeValue()).isEqualTo(200);
- assertThat(getResponseEntity.getBody()).isInstanceOf(Subscription.class);
- }
-
- @Test
- public void testMultiCreationAndFindSubscriber() throws Exception {
- hubResource.createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
- hubResource.createEventSubscription(HubAssertions.createServiceOrderStateChangeSubscription());
- hubResource.createEventSubscription(HubAssertions.createServiceOrderItemStateChangeSubscription());
-
- ResponseEntity<Object> findAllResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
- ArrayList subscribers = (ArrayList) findAllResponseEntity.getBody();
- assertThat(subscribers.size()).isEqualTo(3);
- }
-
- @Test
- public void testMultiCreationAndFindWithFilteringSubscriber() throws Exception {
- hubResource.createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
- hubResource.createEventSubscription(HubAssertions.createServiceOrderStateChangeSubscription());
- hubResource.createEventSubscription(HubAssertions.createServiceOrderItemStateChangeSubscription());
-
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
- params.add("query.eventType", "ServiceOrderCreationNotification");
- ResponseEntity<Object> findWithFilterResponseEntity = hubResource.findSubscribers(params);
- ArrayList subscribers = (ArrayList) findWithFilterResponseEntity.getBody();
- assertThat(subscribers.size()).isEqualTo(1);
- }
-
- @Test
- public void testSubscriberDeletion() throws Exception {
- ResponseEntity<Subscriber> createResponseEntity = hubResource
- .createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
- String resourceId = createResponseEntity.getHeaders().getLocation().getPath().substring(1);
-
- ResponseEntity<Object> findResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
- ArrayList subscribers = (ArrayList) findResponseEntity.getBody();
- assertThat(subscribers.size()).isEqualTo(1);
-
- hubResource.deleteSubscription(resourceId);
-
- findResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
- subscribers = (ArrayList) findResponseEntity.getBody();
- assertThat(subscribers).isEmpty();
- }
-}
diff --git a/src/test/java/org/onap/nbi/apis/StatusResourceTest.java b/src/test/java/org/onap/nbi/apis/StatusResourceTest.java
deleted file mode 100644
index 9b80745..0000000
--- a/src/test/java/org/onap/nbi/apis/StatusResourceTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Copyright (c) 2018 Orange
- *
- * 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.
- */
-package org.onap.nbi.apis;
-
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.onap.nbi.apis.status.StatusResource;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.test.context.junit4.SpringRunner;
-import static org.assertj.core.api.Assertions.assertThat;
-
-
-@RunWith(SpringRunner.class)
-@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-public class StatusResourceTest {
-
- @Autowired
- StatusResource statusResource;
-
- @Value("${server.contextPath}")
- String contextPath;
-
- @Value("${nbi.version}")
- String version;
-
- private MockHttpServletRequest request;
-
- @Before
- public void setup() {
- request = new MockHttpServletRequest();
- request.setRequestURI(contextPath);
- }
-
- @Test
- public void testHealthCheck() {
- ResponseEntity<Object> response = statusResource.status(request);
- assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
- ObjectNode status = (ObjectNode) response.getBody();
- assertThat(status.get("name").textValue()).isEqualTo("nbi");
- assertThat(status.get("status").toString()).isEqualTo("OK");
- assertThat(status.get("version").textValue()).isEqualTo(version);
- }
-}
diff --git a/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java b/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java
deleted file mode 100644
index f2b72f8..0000000
--- a/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Copyright (c) 2018 Orange
- *
- * 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.
- */
-package org.onap.nbi.apis.assertions;
-
-import org.onap.nbi.apis.hub.model.Event;
-import org.onap.nbi.apis.hub.model.EventType;
-import org.onap.nbi.apis.hub.model.Subscription;
-
-import java.util.Date;
-import java.util.UUID;
-
-public class HubAssertions {
-
- public static Subscription createServiceOrderCreationSubscription(){
- Subscription subscription = new Subscription();
- subscription.setId("id");
- subscription.setCallback("http://localhost:8080/test");
- subscription.setQuery("eventType = ServiceOrderCreationNotification");
- return subscription;
- }
-
- public static Subscription createServiceOrderStateChangeSubscription(){
- Subscription subscription = new Subscription();
- subscription.setId("id");
- subscription.setCallback("http://localhost/test");
- subscription.setQuery("eventType = ServiceOrderStateChangeNotification");
- return subscription;
- }
-
- public static Subscription createServiceOrderItemStateChangeSubscription(){
- Subscription subscription = new Subscription();
- subscription.setId("id");
- subscription.setCallback("http://localhost/test");
- subscription.setQuery("eventType = ServiceOrderItemStateChangeNotification");
- return subscription;
- }
-
- public static Event createFakeEvent() {
- Event event = new Event();
- event.setEventId(UUID.randomUUID().toString());
- event.setEventDate(new Date());
- event.setEventType(EventType.SERVICE_ORDER_CREATION.value());
- return event;
- }
-}
diff --git a/src/test/java/org/onap/nbi/apis/assertions/ServiceCatalogAssertions.java b/src/test/java/org/onap/nbi/apis/assertions/ServiceCatalogAssertions.java
deleted file mode 100644
index 3789c8f..0000000
--- a/src/test/java/org/onap/nbi/apis/assertions/ServiceCatalogAssertions.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- * Copyright (c) 2018 Orange
- *
- * 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.
- */
-package org.onap.nbi.apis.assertions;
-
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import static org.assertj.core.api.Assertions.assertThat;
-
-
-public class ServiceCatalogAssertions {
-
-
- public static void assertGetServiceCatalog(ResponseEntity<Object> resource) {
- assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
- LinkedHashMap service = (LinkedHashMap) resource.getBody();
- assertThat(service.get("id")).isEqualTo("1e3feeb0-8e36-46c6-862c-236d9c626439");
- assertThat(service.get("name")).isEqualTo("vFW");
- assertThat(service.get("invariantUUID")).isEqualTo("b58a118e-eeb9-4f6e-bdca-e292f84d17df");
- assertThat(service.get("toscaModelURL"))
- .isEqualTo("/sdc/v1/catalog/services/1e3feeb0-8e36-46c6-862c-236d9c626439/toscaModel");
- assertThat(service.get("distributionStatus")).isEqualTo("DISTRIBUTED");
- assertThat(service.get("version")).isEqualTo("2.0");
- assertThat(service.get("lifecycleStatus")).isEqualTo("CERTIFIED");
- assertThat(service.get("@type")).isEqualTo("ONAPservice");
- assertThat(((ArrayList) service.get("attachment")).size()).isEqualTo(5);
- LinkedHashMap relatedParty = (LinkedHashMap) service.get("relatedParty");
- assertThat(relatedParty.get("name")).isEqualTo("Joni Mitchell");
- assertThat(relatedParty.get("role")).isEqualTo("lastUpdater");
-
-
- assertThat(((ArrayList) service.get("resourceSpecification")).size()).isEqualTo(2);
- LinkedHashMap resource1 = (LinkedHashMap) ((ArrayList) service.get("resourceSpecification")).get(0);
- assertThat(resource1.get("name")).isEqualTo("vFW-vSINK");
- assertThat(resource1.get("resourceInstanceName")).isEqualTo("vFW-vSINK 0");
- assertThat(resource1.get("resourceType")).isEqualTo("VF");
- assertThat(resource1.get("resourceInvariantUUID")).isEqualTo("18b90934-aa82-456f-938e-e74a07a426f3");
- assertThat(resource1.get("@type")).isEqualTo("ONAPresource");
- assertThat(resource1.get("modelCustomizationName")).isEqualTo("vFW-vSINK 0");
-
- assertThat(((ArrayList) service.get("serviceSpecCharacteristic")).size()).isEqualTo(4);
- ArrayList serviceSPecCharacteristics = (ArrayList) service.get("serviceSpecCharacteristic");
- for (Object serviceSPecCharacteristic : serviceSPecCharacteristics) {
- LinkedHashMap serviceSPecCharacteristicMap = (LinkedHashMap) serviceSPecCharacteristic;
- if (serviceSPecCharacteristicMap.get("name").toString().equals("cpus")) {
- assertThat(serviceSPecCharacteristicMap.get("valueType")).isEqualTo("integer");
- assertThat(serviceSPecCharacteristicMap.get("@type")).isEqualTo("ONAPserviceCharacteristic");
- ArrayList serviceSpecCharacteristicValues =
- (ArrayList) serviceSPecCharacteristicMap.get("serviceSpecCharacteristicValue");
- for (Object serviceSpecCharacteristicValue : serviceSpecCharacteristicValues) {
- LinkedHashMap serviceSpecCharacteristicValueMap = (LinkedHashMap) serviceSpecCharacteristicValue;
- if (serviceSpecCharacteristicValueMap.get("value").toString().equals("2")) {
- assertThat(serviceSpecCharacteristicValueMap.get("isDefault")).isEqualTo(true);
- assertThat(serviceSpecCharacteristicValueMap.get("valueType")).isEqualTo("integer");
- } else {
- assertThat(serviceSpecCharacteristicValueMap.get("isDefault")).isEqualTo(false);
- assertThat(serviceSpecCharacteristicValueMap.get("valueType")).isEqualTo("integer");
- }
- }
- }
- }
-
- }
-
-
-
-
- public static void assertGetServiceCatalogWithoutTosca(ResponseEntity<Object> resource) {
- assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
- LinkedHashMap service = (LinkedHashMap) resource.getBody();
- assertThat(service.get("id")).isEqualTo("1e3feeb0-8e36-46c6-862c-236d9c626439");
- assertThat(service.get("name")).isEqualTo("vFW");
- assertThat(service.get("invariantUUID")).isEqualTo("b58a118e-eeb9-4f6e-bdca-e292f84d17df");
- assertThat(service.get("toscaModelURL"))
- .isEqualTo("/sdc/v1/catalog/services/1e3feeb0-8e36-46c6-862c-236d9c626439toto/toscaModel");
- assertThat(service.get("distributionStatus")).isEqualTo("DISTRIBUTED");
- assertThat(service.get("version")).isEqualTo("2.0");
- assertThat(service.get("lifecycleStatus")).isEqualTo("CERTIFIED");
- assertThat(service.get("@type")).isEqualTo("ONAPservice");
- assertThat(((ArrayList) service.get("attachment")).size()).isEqualTo(5);
- LinkedHashMap relatedParty = (LinkedHashMap) service.get("relatedParty");
- assertThat(relatedParty.get("name")).isEqualTo("Joni Mitchell");
- assertThat(relatedParty.get("role")).isEqualTo("lastUpdater");
-
-
- assertThat(((ArrayList) service.get("resourceSpecification")).size()).isEqualTo(2);
- LinkedHashMap resource1 = (LinkedHashMap) ((ArrayList) service.get("resourceSpecification")).get(0);
- assertThat(resource1.get("name")).isEqualTo("vFW-vSINK");
- assertThat(resource1.get("resourceInstanceName")).isEqualTo("vFW-vSINK 0");
- assertThat(resource1.get("resourceType")).isEqualTo("VF");
- assertThat(resource1.get("resourceInvariantUUID")).isEqualTo("18b90934-aa82-456f-938e-e74a07a426f3");
- assertThat(resource1.get("@type")).isEqualTo("ONAPresource");
- assertThat(resource1.get("modelCustomizationName")).isEqualTo("vFW-vSINK 0");
- assertThat(service.get("serviceSpecCharacteristic")).isNull();
- }
-
-
-
-
-
-
-
-
-
-
- public static void assertFindServiceCatalog(ResponseEntity<Object> resource) {
- assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
- ArrayList body = (ArrayList) resource.getBody();
- assertThat(body.size()).isEqualTo(21);
- LinkedHashMap service1 = (LinkedHashMap) body.get(0);
- assertThat(service1.get("id")).isEqualTo("446afaf6-79b5-420e-aff8-7551b00bb510");
- assertThat(service1.get("name")).isEqualTo("FreeRadius-service");
- assertThat(service1.get("invariantUUID")).isEqualTo("7e4781e8-6c6e-41c5-b889-6a321d5f2490");
- assertThat(service1.get("category")).isEqualTo("Network L4+");
- assertThat(service1.get("distributionStatus")).isEqualTo("DISTRIBUTED");
- assertThat(service1.get("version")).isEqualTo("1.0");
- assertThat(service1.get("lifecycleStatus")).isEqualTo("CERTIFIED");
- LinkedHashMap relatedParty = (LinkedHashMap) service1.get("relatedParty");
- assertThat(relatedParty.get("role")).isEqualTo("lastUpdater");
- }
-
-
-
- public static void assertFindServiceCatalogWIthFilter(ResponseEntity<Object> resource) {
- assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
- ArrayList body = (ArrayList) resource.getBody();
- assertThat(body.size()).isEqualTo(21);
-
-
- ObjectNode service1 = (ObjectNode) body.get(0);
- assertThat(service1.get("id")).isNull();
- assertThat(service1.get("name").asText()).isEqualTo("FreeRadius-service");
- assertThat(service1.get("invariantUUID")).isNull();
- assertThat(service1.get("category")).isNull();
- assertThat(service1.get("distributionStatus")).isNull();
- assertThat(service1.get("version")).isNull();
- assertThat(service1.get("lifecycleStatus")).isNull();
- assertThat(service1.get("relatedParty")).isNull();
- }
-
-}
-
diff --git a/src/test/java/org/onap/nbi/apis/assertions/ServiceInventoryAssertions.java b/src/test/java/org/onap/nbi/apis/assertions/ServiceInventoryAssertions.java
deleted file mode 100644
index f68b82f..0000000
--- a/src/test/java/org/onap/nbi/apis/assertions/ServiceInventoryAssertions.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Copyright (c) 2018 Orange
- *
- * 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.
- */
-package org.onap.nbi.apis.assertions;
-
-
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ServiceInventoryAssertions {
-
-
-
- public static void assertServiceInventoryGet(ResponseEntity<Object> resource) {
- assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
- LinkedHashMap service = (LinkedHashMap) resource.getBody();
- assertThat(service.get("id")).isEqualTo("e4688e5f-61a0-4f8b-ae02-a2fbde623bcb");
- assertThat(service.get("name")).isEqualTo("NewFreeRadius-service-instance-01");
- assertThat(service.get("hasStarted")).isEqualTo("yes");
- assertThat(service.get("type")).isEqualTo("service-instance");
- assertThat(service.get("@type")).isEqualTo("serviceONAP");
- LinkedHashMap relatedParty = (LinkedHashMap) service.get("relatedParty");
- assertThat(relatedParty.get("role")).isEqualTo("ONAPcustomer");
- assertThat(relatedParty.get("id")).isEqualTo("6490");
- LinkedHashMap serviceSpecification = (LinkedHashMap) service.get("serviceSpecification");
- assertThat(serviceSpecification.get("id")).isEqualTo("98d95267-5e0f-4531-abf8-f14b90031dc5");
- assertThat(serviceSpecification.get("invariantUUID")).isEqualTo("709d157b-52fb-4250-976e-7133dff5c347");
- assertThat(serviceSpecification.get("@type")).isEqualTo("ONAPservice");
-
-
- assertThat(((ArrayList) service.get("supportingResource")).size()).isEqualTo(2);
- LinkedHashMap resource1 = (LinkedHashMap) ((ArrayList) service.get("supportingResource")).get(0);
- assertThat(resource1.get("id")).isEqualTo("cb80fbb6-9aa7-4ac5-9541-e14f45de533e");
- assertThat(resource1.get("name")).isEqualTo("NewFreeRadius-VNF-instance-01");
- assertThat(resource1.get("status")).isEqualTo("PREPROV");
- assertThat(resource1.get("modelInvariantId")).isEqualTo("f5993703-977f-4346-a1c9-c1884f8cfd8d");
- assertThat(resource1.get("modelVersionId")).isEqualTo("902438f7-1e4c-492d-b7cc-8650e13b8aeb");
- assertThat(resource1.get("@referredType")).isEqualTo("ONAP resource");
- }
-
-
- public static void assertServiceInventoryGetWithoutList(ResponseEntity<Object> resource) {
- assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
- LinkedHashMap service = (LinkedHashMap) resource.getBody();
- assertThat(service.get("id")).isEqualTo("e4688e5f-61a0-4f8b-ae02-a2fbde623bcb");
- assertThat(service.get("name")).isEqualTo("NewFreeRadius-service-instance-01");
- assertThat(service.get("hasStarted")).isEqualTo("yes");
- assertThat(service.get("type")).isEqualTo("service-instance");
- assertThat(service.get("@type")).isEqualTo("serviceONAP");
- LinkedHashMap relatedParty = (LinkedHashMap) service.get("relatedParty");
- assertThat(relatedParty.get("role")).isEqualTo("ONAPcustomer");
- assertThat(relatedParty.get("id")).isEqualTo("6490");
- LinkedHashMap serviceSpecification = (LinkedHashMap) service.get("serviceSpecification");
- assertThat(serviceSpecification.get("id")).isEqualTo("98d95267-5e0f-4531-abf8-f14b90031dc5");
- assertThat(serviceSpecification.get("invariantUUID")).isEqualTo("709d157b-52fb-4250-976e-7133dff5c347");
- assertThat(serviceSpecification.get("@type")).isEqualTo("ONAPservice");
-
- assertThat(((ArrayList) service.get("supportingResource")).size()).isEqualTo(0);
-
- }
-
-
-
- public static void assertServiceInventoryFind(ResponseEntity<Object> resource) {
- assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
- ArrayList body = (ArrayList) resource.getBody();
- assertThat(body.size()).isEqualTo(1);
- LinkedHashMap service1 = (LinkedHashMap) body.get(0);
- assertThat(service1.get("id")).isEqualTo("e4688e5f-61a0-4f8b-ae02-a2fbde623bcb");
- assertThat(service1.get("name")).isEqualTo("NewFreeRadius-service-instance-01");
- LinkedHashMap relatedParty = (LinkedHashMap) service1.get("relatedParty");
- assertThat(relatedParty.get("role")).isEqualTo("ONAPcustomer");
- assertThat(relatedParty.get("id")).isEqualTo("6490");
- LinkedHashMap serviceSpecification = (LinkedHashMap) service1.get("serviceSpecification");
- assertThat(serviceSpecification.get("name")).isEqualTo("vFW");
- assertThat(serviceSpecification.get("id")).isEqualTo("98d95267-5e0f-4531-abf8-f14b90031dc5");
- }
-
-
- public static void assertServiceInventoryFindWithoutParameter(ResponseEntity<Object> resource) {
- assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
- ArrayList body = (ArrayList) resource.getBody();
- assertThat(body.size()).isEqualTo(2);
- LinkedHashMap service1 = (LinkedHashMap) body.get(0);
- assertThat(service1.get("id")).isEqualTo("vfw-service-id");
- assertThat(service1.get("name")).isEqualTo("vfw-service-name");
- LinkedHashMap relatedParty = (LinkedHashMap) service1.get("relatedParty");
- assertThat(relatedParty.get("role")).isEqualTo("ONAPcustomer");
- assertThat(relatedParty.get("id")).isEqualTo("6490");
- LinkedHashMap serviceSpecification = (LinkedHashMap) service1.get("serviceSpecification");
- assertThat(serviceSpecification.get("name")).isEqualTo("vFW-service-2VF-based");
- assertThat(serviceSpecification.get("id")).isEqualTo("9vfw-service-modek-version-id");
-
-
- LinkedHashMap service2 = (LinkedHashMap) body.get(1);
- assertThat(service2.get("id")).isEqualTo("e4688e5f-61a0-4f8b-ae02-a2fbde623bcb");
- assertThat(service2.get("name")).isEqualTo("NewFreeRadius-service-instance-01");
- relatedParty = (LinkedHashMap) service1.get("relatedParty");
- assertThat(relatedParty.get("role")).isEqualTo("ONAPcustomer");
- assertThat(relatedParty.get("id")).isEqualTo("6490");
- serviceSpecification = (LinkedHashMap) service2.get("serviceSpecification");
- assertThat(serviceSpecification.get("name")).isEqualTo("vFW");
- assertThat(serviceSpecification.get("id")).isEqualTo("98d95267-5e0f-4531-abf8-f14b90031dc5");
-
- }
-
-}
diff --git a/src/test/java/org/onap/nbi/apis/assertions/ServiceOrderAssertions.java b/src/test/java/org/onap/nbi/apis/assertions/ServiceOrderExecutionTaskAssertions.java
index 6bd4bd0..6fea745 100644
--- a/src/test/java/org/onap/nbi/apis/assertions/ServiceOrderAssertions.java
+++ b/src/test/java/org/onap/nbi/apis/assertions/ServiceOrderExecutionTaskAssertions.java
@@ -41,7 +41,7 @@ import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
import org.onap.nbi.apis.serviceorder.utils.JsonEntityConverter;
-public class ServiceOrderAssertions {
+public class ServiceOrderExecutionTaskAssertions {
public static ServiceOrder createTestServiceOrderRejected() {
ServiceOrder serviceOrder = new ServiceOrder();
diff --git a/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java b/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java
deleted file mode 100644
index b2ebe17..0000000
--- a/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/**
- * Copyright (c) 2018 Orange
- *
- * 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.
- */
-package org.onap.nbi.apis.servicecatalog;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertNull;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-
-import org.assertj.core.api.AbstractBooleanAssert;
-import org.junit.Test;
-import org.onap.nbi.exceptions.TechnicalException;
-import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
-
-
-public class ToscaInfosProcessorTest {
-
- final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson databind
-
- ToscaInfosProcessor toscaInfosProcessor = new ToscaInfosProcessor();
-
-
- private LinkedHashMap parseToscaFile(String fileName) {
-
- File toscaFile = new File(fileName);
- if (!toscaFile.exists()) {
- throw new TechnicalException("unable to find file : " + fileName);
- }
- try {
- return (LinkedHashMap) mapper.readValue(toscaFile, Object.class);
- } catch (IOException e) {
- throw new TechnicalException("Unable to parse tosca file : " + fileName);
-
- } catch (NullPointerException e) {
- throw new TechnicalException("unable to find tosca file : " + fileName);
- }
- }
-
-
- @Test
- public void buildResponseWithToscaInfos() {
-
- ClassLoader classLoader = getClass().getClassLoader();
- File file = new File(classLoader.getResource("toscafile/service-TestNetwork-template.yml").getFile());
- List<LinkedHashMap> resources = new ArrayList<>();
- LinkedHashMap resource1 = new LinkedHashMap();
- resource1.put("id", "e2b12ac6-cbb6-4517-9c58-b846d1f68caf");
- resources.add(resource1);
- LinkedHashMap toscaFile = parseToscaFile(file.getPath());
- LinkedHashMap response = new LinkedHashMap();
- response.put("resourceSpecification", resources);
- toscaInfosProcessor.buildResponseWithToscaInfos((LinkedHashMap) toscaFile.get("topology_template"), response);
-
- resources = (List<LinkedHashMap>) response.get("resourceSpecification");
- assertNull(resources.get(0).get("modelCustomizationId"));
- assertNull(resources.get(0).get("modelCustomizationName"));
-
- }
-
- @Test
- public void buildResponseWithSdcToscaParser() {
-
- ClassLoader classLoader = getClass().getClassLoader();
- Path path = new File(classLoader.getResource("toscafile/service-Sdwanvpninfraservice-csar.csar").getFile()).toPath().toAbsolutePath();
- List<LinkedHashMap> resources = new ArrayList<>();
- LinkedHashMap resource1 = new LinkedHashMap();
- resource1.put("id", "7baa7742-3a13-4288-8330-868015adc340");
- resources.add(resource1);
- LinkedHashMap resource2 = new LinkedHashMap();
- resource2.put("id", "81b9430b-8abe-45d6-8bf9-f41a8f5c735f");
- resources.add(resource2);
- LinkedHashMap response = new LinkedHashMap();
- response.put("resourceSpecification", resources);
-
- try {
- toscaInfosProcessor.buildResponseWithSdcToscaParser(path, response);
- }
- catch(SdcToscaParserException e) {
- throw new TechnicalException("unable to build response from tosca csar using sdc-parser : " + path.toString()+" "+e.getMessage());
- }
- resources = (List<LinkedHashMap>) response.get("resourceSpecification");
- List<LinkedHashMap> serviceSpecCharacteristic = new ArrayList<>();
- serviceSpecCharacteristic = (List<LinkedHashMap>) response.get("serviceSpecCharacteristic");
- assertThat(serviceSpecCharacteristic.get(0).get("name")).isEqualTo("sdwanconnectivity0_topology");
- assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string");
- assertThat(serviceSpecCharacteristic.get(0).get("required")).isEqualTo(true);
- assertThat(serviceSpecCharacteristic.get(1).get("name")).isEqualTo("sdwanconnectivity0_name");
- assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string");
- assertThat(serviceSpecCharacteristic.get(1).get("required")).isEqualTo(true);
- assertThat(resources.get(0).get("modelCustomizationId")).isEqualTo("94ec574b-2306-4cbd-8214-09662b040f73");
- assertThat(resources.get(1).get("modelCustomizationId")).isEqualTo("a7baba5d-6ac3-42b5-b47d-070841303ab1");
-
- }
-
- @Test
- public void buildResponseWithSdcToscaParserWithDefaultInputs() {
-
- ClassLoader classLoader = getClass().getClassLoader();
- Path path = new File(classLoader.getResource("toscafile/service-Sotnvpninfraservice-csar.csar").getFile()).toPath().toAbsolutePath();
- List<LinkedHashMap> resources = new ArrayList<>();
- LinkedHashMap resource1 = new LinkedHashMap();
- resource1.put("id", "218df3c3-50dd-4c26-9e36-4771387bb771");
- resources.add(resource1);
- LinkedHashMap resource2 = new LinkedHashMap();
- resource2.put("id", "81b9430b-8abe-45d6-8bf9-f41a8f5c735f");
- resources.add(resource2);
- LinkedHashMap response = new LinkedHashMap();
- response.put("resourceSpecification", resources);
-
- try {
- toscaInfosProcessor.buildResponseWithSdcToscaParser(path, response);
- }
- catch(SdcToscaParserException e) {
- throw new TechnicalException("unable to build response from tosca csar using sdc-parser : " + path.toString()+" "+e.getMessage());
- }
- resources = (List<LinkedHashMap>) response.get("resourceSpecification");
- List<LinkedHashMap> serviceSpecCharacteristic = new ArrayList<>();
- serviceSpecCharacteristic = (List<LinkedHashMap>) response.get("serviceSpecCharacteristic");
- assertThat(resources.get(0).get("modelCustomizationId")).isEqualTo("b44071c8-04fd-4d6b-b6af-772cbfaa1129");
- assertThat(resources.get(1).get("modelCustomizationId")).isEqualTo("c3612284-6c67-4d8c-8b41-b699cc90e76d");
- assertThat(serviceSpecCharacteristic.get(12).get("serviceSpecCharacteristicValue")).isNull();
- assertThat(serviceSpecCharacteristic.get(13).get("serviceSpecCharacteristicValue")).isNotNull();
- }
-
- @Test
- public void buildResponseWithSdcToscaParserwithMetaDataMisMatch() {
-
- ClassLoader classLoader = getClass().getClassLoader();
- Path path = new File(classLoader.getResource("toscafile/service-Sdwanvpninfraservice-csar.csar").getFile()).toPath().toAbsolutePath();
- List<LinkedHashMap> resources = new ArrayList<>();
- LinkedHashMap resource1 = new LinkedHashMap();
- resource1.put("id", "some bad resource id no in TOSCA CSAR");
- resources.add(resource1);
- LinkedHashMap resource2 = new LinkedHashMap();
- resource2.put("id", "some bad resource id no in TOSCA CSAR");
- resources.add(resource2);
- LinkedHashMap response = new LinkedHashMap();
- response.put("resourceSpecification", resources);
-
- try {
- toscaInfosProcessor.buildResponseWithSdcToscaParser(path, response);
- }
- catch(SdcToscaParserException e) {
- throw new TechnicalException("unable to build response from tosca csar using sdc-parser : " + path.toString()+" "+e.getMessage());
- }
- resources = (List<LinkedHashMap>) response.get("resourceSpecification");
- List<LinkedHashMap> serviceSpecCharacteristic = new ArrayList<>();
- serviceSpecCharacteristic = (List<LinkedHashMap>) response.get("serviceSpecCharacteristic");
- assertThat(serviceSpecCharacteristic.get(0).get("name")).isEqualTo("sdwanconnectivity0_topology");
- assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string");
- assertThat(serviceSpecCharacteristic.get(0).get("required")).isEqualTo(true);
- assertThat(serviceSpecCharacteristic.get(1).get("name")).isEqualTo("sdwanconnectivity0_name");
- assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string");
- assertThat(serviceSpecCharacteristic.get(1).get("required")).isEqualTo(true);
- // Check that resources cannot be found in the TOSCA template
- assertThat(resources.get(0).get("modelCustomizationId")).isNull();
- assertThat(resources.get(1).get("modelCustomizationId")).isNull();
-
- }
- @Test
- public void buildResponseWithToscaInfosOk() {
-
- ClassLoader classLoader = getClass().getClassLoader();
- File file = new File(classLoader.getResource("toscafile/service-VfwService2vfBased-template.yml").getFile());
- List<LinkedHashMap> resources = new ArrayList<>();
- LinkedHashMap resource1 = new LinkedHashMap();
- resource1.put("id", "e2b12ac6-cbb6-4517-9c58-b846d1f68caf");
- resources.add(resource1);
- LinkedHashMap toscaFile = parseToscaFile(file.getPath());
- LinkedHashMap response = new LinkedHashMap();
- response.put("resourceSpecification", resources);
- toscaInfosProcessor.buildResponseWithToscaInfos((LinkedHashMap) toscaFile.get("topology_template"), response);
-
- ArrayList toscaInfos = (ArrayList) response.get("serviceSpecCharacteristic");
- assertThat(toscaInfos.size()).isEqualTo(4);
-
- for (Object toscaInfo : toscaInfos) {
- LinkedHashMap info = (LinkedHashMap) toscaInfo;
- if (((String) info.get("name")).equalsIgnoreCase("fortigate_image_url")) {
- assertThat(info.get("name")).isEqualTo("fortigate_image_url");
- assertThat(info.get("description")).isNull();
- assertThat(info.get("valueType")).isEqualTo("string");
- assertThat(info.get("@type")).isEqualTo("ONAPserviceCharacteristic");
- assertThat(info.get("required")).isEqualTo(false);
- assertThat(info.get("status")).isNull();
- assertThat(((ArrayList) info.get("serviceSpecCharacteristicValue")).size()).isEqualTo(0);
-
- }
-
- if (((String) info.get("name")).equalsIgnoreCase("flavor")) {
- assertThat(info.get("name")).isEqualTo("flavor");
- assertThat(info.get("description")).isNull();
- assertThat(info.get("valueType")).isEqualTo("string");
- assertThat(info.get("@type")).isEqualTo("ONAPserviceCharacteristic");
- assertThat(info.get("required")).isNull();
- assertThat(info.get("status")).isNull();
- assertThat(((ArrayList) info.get("serviceSpecCharacteristicValue")).size()).isEqualTo(0);
-
- }
-
- if (((String) info.get("name")).equalsIgnoreCase("external_network_name")) {
- assertThat(info.get("name")).isEqualTo("external_network_name");
- assertThat(info.get("description")).isNull();
- assertThat(info.get("valueType")).isEqualTo("string");
- assertThat(info.get("@type")).isEqualTo("ONAPserviceCharacteristic");
- assertThat(info.get("required")).isNull();
- assertThat(info.get("status")).isEqualTo("inactive");
- ;
- assertThat(((ArrayList) info.get("serviceSpecCharacteristicValue")).size()).isEqualTo(0);
-
- }
-
- if (((String) info.get("name")).equalsIgnoreCase("cpus")) {
- assertThat(info.get("name")).isEqualTo("cpus");
- assertThat(info.get("description")).isEqualTo("Number of CPUs for the server.");
- assertThat(info.get("valueType")).isEqualTo("integer");
- assertThat(info.get("@type")).isEqualTo("ONAPserviceCharacteristic");
- assertThat(info.get("required")).isNull();
- assertThat(info.get("status")).isNull();
- ;
- assertThat(((ArrayList) info.get("serviceSpecCharacteristicValue")).size()).isEqualTo(4);
- ArrayList serviceSpecCharacteristicValues = (ArrayList) info.get("serviceSpecCharacteristicValue");
-
- for (Object serviceSpecCharacteristicValue : serviceSpecCharacteristicValues) {
- LinkedHashMap serviceSpecValue = (LinkedHashMap) serviceSpecCharacteristicValue;
- if (((String) serviceSpecValue.get("value")).equalsIgnoreCase("1")) {
- assertThat(serviceSpecValue.get("isDefault")).isEqualTo(false);
- assertThat(serviceSpecValue.get("value")).isEqualTo("1");
- assertThat(serviceSpecValue.get("valueType")).isEqualTo("integer");
- }
- if (((String) serviceSpecValue.get("value")).equalsIgnoreCase("2")) {
- assertThat(serviceSpecValue.get("isDefault")).isEqualTo(true);
- assertThat(serviceSpecValue.get("value")).isEqualTo("2");
- assertThat(serviceSpecValue.get("valueType")).isEqualTo("integer");
- }
- if (((String) serviceSpecValue.get("value")).equalsIgnoreCase("3")) {
- assertThat(serviceSpecValue.get("isDefault")).isEqualTo(false);
- assertThat(serviceSpecValue.get("value")).isEqualTo("3");
- assertThat(serviceSpecValue.get("valueType")).isEqualTo("integer");
- }
- if (((String) serviceSpecValue.get("value")).equalsIgnoreCase("4")) {
- assertThat(serviceSpecValue.get("isDefault")).isEqualTo(false);
- assertThat(serviceSpecValue.get("value")).isEqualTo("4");
- assertThat(serviceSpecValue.get("valueType")).isEqualTo("integer");
- }
-
- }
-
-
- }
-
- }
-
-
- }
-} \ No newline at end of file
diff --git a/src/test/java/org/onap/nbi/apis/ApiTestWithoutOnap.java b/src/test/java/org/onap/nbi/test/ApiTestWithoutOnap.java
index 782c39a..6e57673 100644
--- a/src/test/java/org/onap/nbi/apis/ApiTestWithoutOnap.java
+++ b/src/test/java/org/onap/nbi/test/ApiTestWithoutOnap.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onap.nbi.apis;
+package org.onap.nbi.test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -22,7 +22,7 @@ import java.util.List;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.nbi.apis.assertions.ServiceOrderAssertions;
+import org.onap.nbi.apis.assertions.ServiceOrderExecutionTaskAssertions;
import org.onap.nbi.apis.servicecatalog.ServiceSpecificationResource;
import org.onap.nbi.apis.serviceinventory.ServiceInventoryResource;
import org.onap.nbi.apis.serviceorder.ServiceOrderResource;
@@ -39,12 +39,17 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
+@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+@DirtiesContext(classMode= ClassMode.AFTER_CLASS)
public class ApiTestWithoutOnap {
@@ -88,7 +93,7 @@ public class ApiTestWithoutOnap {
@Test
public void testExecutionTaskWithoutOnap() throws Exception {
- ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
executionTaskRepository, ActionType.ADD);
SoTaskProcessor.processOrderItem(executionTaskA);
@@ -108,7 +113,7 @@ public class ApiTestWithoutOnap {
@Test
public void testCheckServiceOrderWithSDCNotResponding() throws Exception {
- ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
+ ServiceOrder testServiceOrder = ServiceOrderExecutionTaskAssertions.createTestServiceOrder(ActionType.ADD);
List<RelatedParty> customers = new ArrayList<>();
RelatedParty customer = new RelatedParty();
customer.setId("new");
@@ -120,7 +125,7 @@ public class ApiTestWithoutOnap {
testServiceOrder.setId("test");
serviceOrderRepository.save(testServiceOrder);
- serviceOrderResource.scheduleCheckServiceOrders();
+ serviceOrderResource.checkServiceOrder(testServiceOrder);
ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
@@ -155,6 +160,7 @@ public class ApiTestWithoutOnap {
ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
+
}
diff --git a/src/test/java/org/onap/nbi/test/Context.java b/src/test/java/org/onap/nbi/test/Context.java
new file mode 100644
index 0000000..bc35aa0
--- /dev/null
+++ b/src/test/java/org/onap/nbi/test/Context.java
@@ -0,0 +1,98 @@
+/**
+ * Copyright (c) 2018 Orange
+ *
+ * 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.
+ */
+package org.onap.nbi.test;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import com.github.tomakehurst.wiremock.stubbing.StubMapping;
+import java.util.List;
+import org.onap.nbi.Application;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+public class Context {
+
+
+ public static ConfigurableApplicationContext nbiServer;
+
+ public static WireMockServer wireMockServer;
+
+ public static void startServers() throws Exception {
+ startWiremock();
+
+ // NBI
+ if (nbiServer == null) {
+ String[] args = new String[1];
+ args[0] = "--spring.profiles.active=test";
+ nbiServer = Application.run(args);
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
+ }
+
+ }
+
+ public static void startWiremock() {
+ // Wiremock
+ // If wireMockServer was previously created
+ if (wireMockServer != null) {
+ wireMockServer.stop();
+ wireMockServer.resetToDefaultMappings();
+ } else {
+ wireMockServer =
+ new WireMockServer(
+ WireMockConfiguration.wireMockConfig().port(8091).jettyStopTimeout(1000L));
+ }
+
+ wireMockServer.start();
+ }
+
+ public static void removeWireMockMapping(String mappingToBeRemoved) {
+
+ if (mappingToBeRemoved == null) {
+ return;
+ }
+
+ // Get current mappings
+ List<StubMapping> mappings = wireMockServer.listAllStubMappings().getMappings();
+
+ StubMapping mappingToDelete = null;
+ for (StubMapping mapping : mappings) {
+ if (mapping.getRequest().getUrl().equals(mappingToBeRemoved)) {
+ mappingToDelete = mapping;
+ }
+ }
+
+ if (mappingToDelete != null) {
+ wireMockServer.removeStubMapping(mappingToDelete);
+ }
+ }
+
+ public static void stopServers() throws Exception {
+
+ // NBI
+ if (nbiServer != null) { // keep spring boot side alive for all tests including package
+ // 'mock'
+ nbiServer.close();
+ }
+
+ // Wiremock
+ if (wireMockServer != null) {
+ wireMockServer.stop();
+ }
+
+ }
+
+}
diff --git a/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java b/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java
new file mode 100644
index 0000000..56f2ba0
--- /dev/null
+++ b/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java
@@ -0,0 +1,548 @@
+/**
+ * Copyright (c) 2018 Orange
+ *
+ * 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.
+ */
+package org.onap.nbi.test;
+
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.github.tomakehurst.wiremock.admin.model.ListStubMappingsResult;
+import com.github.tomakehurst.wiremock.http.ResponseDefinition;
+import com.github.tomakehurst.wiremock.stubbing.StubMapping;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.nbi.apis.assertions.ServiceOrderExecutionTaskAssertions;
+import org.onap.nbi.apis.serviceorder.model.ActionType;
+import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
+import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
+import org.onap.nbi.apis.serviceorder.model.StateType;
+import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask;
+import org.onap.nbi.apis.serviceorder.repositories.ExecutionTaskRepository;
+import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
+import org.onap.nbi.apis.serviceorder.workflow.SOTaskProcessor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+@ActiveProfiles("test")
+@DirtiesContext(classMode= ClassMode.AFTER_CLASS)
+public class ExecutionTaskTest {
+
+ @Autowired
+ ServiceOrderRepository serviceOrderRepository;
+
+ @Autowired
+ ExecutionTaskRepository executionTaskRepository;
+
+ @Autowired
+ SOTaskProcessor SoTaskProcessor;
+
+
+ static Validator validator;
+
+ @Before
+ public void before() {
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
+ }
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+ validator = factory.getValidator();
+ Context.startWiremock();
+ }
+
+ @AfterClass
+ public static void tearsDown() throws Exception {
+ Context.stopServers();
+
+ }
+
+ @After
+ public void tearsDownUpPort() throws Exception {
+ executionTaskRepository.deleteAll();
+ serviceOrderRepository.deleteAll();
+ Context.wireMockServer.resetToDefaultMappings();
+
+ }
+
+
+ public ExecutionTask getExecutionTask(String orderItemId) {
+ for (ExecutionTask executionTask : executionTaskRepository.findAll()) {
+ if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) {
+ return executionTask;
+ }
+
+ }
+ return null;
+ }
+
+ private void changeWireMockResponse(String s,int statusCode, String bodyContent) {
+ ListStubMappingsResult listStubMappingsResult = Context.wireMockServer.listAllStubMappings();
+ ResponseDefinition responseDefinition = new ResponseDefinition(statusCode,bodyContent);
+ List<StubMapping> mappings = listStubMappingsResult.getMappings();
+ for (StubMapping mapping : mappings) {
+ if (mapping.getRequest().getUrl().equals(s)) {
+ mapping.setResponse(responseDefinition);
+ }
+ }
+ }
+
+
+
+
+
+
+ @Test
+ public void testExecutionTaskSuccess() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+ ExecutionTask executionTaskB;
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if (serviceOrderItem.getId().equals("A")) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+ } else {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
+ }
+ }
+
+ executionTaskB = getExecutionTask("B");
+ assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
+ executionTaskA = getExecutionTask("A");
+ assertThat(executionTaskA).isNull();
+
+ SoTaskProcessor.processOrderItem(executionTaskB);
+ serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+
+
+ }
+
+ @Test
+ public void testE2EExecutionTaskSuccess() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+ ExecutionTask executionTaskB;
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if (serviceOrderItem.getId().equals("A")) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+ } else {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
+ }
+ }
+
+ executionTaskB = getExecutionTask("B");
+ assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
+ executionTaskA = getExecutionTask("A");
+ assertThat(executionTaskA).isNull();
+
+ SoTaskProcessor.processOrderItem(executionTaskB);
+ serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+
+
+ }
+
+ @Test
+ public void testExecutionTaskDeleteSuccess() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.DELETE);
+ ExecutionTask executionTaskB;
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if (serviceOrderItem.getId().equals("A")) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+ } else {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
+ }
+ }
+
+ executionTaskB = getExecutionTask("B");
+ assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
+ executionTaskA = getExecutionTask("A");
+ assertThat(executionTaskA).isNull();
+
+ SoTaskProcessor.processOrderItem(executionTaskB);
+ serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+
+
+ }
+
+ @Test
+ public void testE2EExecutionTaskDeleteSuccess() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.DELETE);
+ ExecutionTask executionTaskB;
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if (serviceOrderItem.getId().equals("A")) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+ } else {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
+ }
+ }
+
+ executionTaskB = getExecutionTask("B");
+ assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
+ executionTaskA = getExecutionTask("A");
+ assertThat(executionTaskA).isNull();
+
+ SoTaskProcessor.processOrderItem(executionTaskB);
+ serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+
+
+ }
+
+
+ @Test
+ public void testExecutionTaskFailed() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+
+ Context.removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId");
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if (serviceOrderItem.getId().equals("A")) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS);
+ } else {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
+ }
+ }
+ executionTaskA = getExecutionTask("A");
+ Date createDate = executionTaskA.getCreateDate();
+ assertThat(executionTaskA.getLastAttemptDate().getTime()> createDate.getTime()).isTrue();
+
+ changeCreationDate(executionTaskA);
+ SoTaskProcessor.processOrderItem(executionTaskA);
+
+ serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
+
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+
+ }
+
+ private void changeCreationDate(ExecutionTask executionTaskA) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(executionTaskA.getCreateDate());
+ cal.add(Calendar.SECOND, -30);
+ executionTaskA.setCreateDate(cal.getTime());
+ }
+
+
+ @Test
+ public void testE2EExecutionTaskFailed() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+
+ Context.removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3/serviceId/operations/operationId");
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if (serviceOrderItem.getId().equals("A")) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS);
+ } else {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
+ }
+ }
+ executionTaskA = getExecutionTask("A");
+ assertThat(executionTaskA.getLastAttemptDate().getTime()>executionTaskA.getCreateDate().getTime()).isTrue();
+ changeCreationDate(executionTaskA);
+ SoTaskProcessor.processOrderItem(executionTaskA);
+
+ serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
+
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+
+ }
+
+ @Test
+ public void testExecutionTaskFailedNoSoResponse() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+
+ Context.removeWireMockMapping("/onap/so/infra/serviceInstantiation/v7/serviceInstances/");
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+
+
+ }
+
+ @Test
+ public void testExecutionTaskFailedNoSoAndStatusResponse() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+
+ Context.removeWireMockMapping("/onap/so/infra/serviceInstantiation/v7/serviceInstances/");
+ Context.removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId");
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+ }
+
+ @Test
+ public void testE2EExecutionTaskFailedNoSoAndStatusResponse() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+
+ Context.removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3");
+ Context.removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3/serviceId/operations/operationId");
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+ }
+
+
+ @Test
+ public void testExecutionTaskFailedBadRequestSo() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+
+
+ changeWireMockResponse("/onap/so/infra/serviceInstantiation/v7/serviceInstances/",400,"\"serviceException\": {\n"
+ + " \"messageId\": \"SVC0002\",\n"
+ + " \"text\": \"Error parsing request. org.openecomp.mso.apihandler.common.ValidationException: serviceInstance already existsd\"\n"
+ + " }");
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if(serviceOrderItem.getId().equals("A")) {
+ assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
+ assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("105");
+ assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("service.name");
+ }
+ }
+
+ }
+
+
+ @Test
+ public void testExecutionTaskModifySuccess() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.MODIFY);
+ ExecutionTask executionTaskB;
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if (serviceOrderItem.getId().equals("A")) {
+ //assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS);
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE);
+ } else {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
+ }
+ }
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if (serviceOrderItem.getId().equals("A")) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+ } else {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
+ }
+ }
+
+ executionTaskB = getExecutionTask("B");
+ assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty();
+ executionTaskA = getExecutionTask("A");
+ assertThat(executionTaskA).isNull();
+
+ SoTaskProcessor.processOrderItem(executionTaskB);
+ SoTaskProcessor.processOrderItem(executionTaskB);
+
+ serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED);
+
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+ }
+
+
+
+
+ @Test
+ public void testExecutionTaskModifyFailed() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.MODIFY);
+ ExecutionTask executionTaskB;
+ Context.removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId");
+
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if (serviceOrderItem.getId().equals("A")) {
+ //assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS);
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS_MODIFY_REQUEST_DELETE_SEND);
+ } else {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED);
+ }
+ }
+ executionTaskA = getExecutionTask("A");
+ assertThat(executionTaskA.getLastAttemptDate().getTime()>executionTaskA.getCreateDate().getTime()).isTrue();
+ changeCreationDate(executionTaskA);
+ SoTaskProcessor.processOrderItem(executionTaskA);
+
+ serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
+
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+ }
+
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/nbi/test/KarateApiTest.java b/src/test/java/org/onap/nbi/test/KarateApiTest.java
new file mode 100644
index 0000000..e5845f3
--- /dev/null
+++ b/src/test/java/org/onap/nbi/test/KarateApiTest.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2018 Orange
+ *
+ * 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.
+ */
+package org.onap.nbi.test;
+
+import com.intuit.karate.junit4.Karate;
+import cucumber.api.CucumberOptions;
+import org.junit.AfterClass;
+import org.junit.runner.RunWith;
+
+@RunWith(Karate.class)
+@CucumberOptions(features = "src/test/resources/karatetest/features")
+public class KarateApiTest {
+
+ @AfterClass
+ public static void stop() throws Exception {
+ Context.stopServers();
+ }
+
+}
diff --git a/src/test/java/org/onap/nbi/apis/ServiceOrderRepositoryTest.java b/src/test/java/org/onap/nbi/test/ServiceOrderRepositoryTest.java
index 9c030bd..11ed493 100644
--- a/src/test/java/org/onap/nbi/apis/ServiceOrderRepositoryTest.java
+++ b/src/test/java/org/onap/nbi/test/ServiceOrderRepositoryTest.java
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onap.nbi.apis;
+package org.onap.nbi.test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+
import java.util.List;
import org.junit.Before;
import org.junit.Test;
@@ -27,10 +28,15 @@ import org.onap.nbi.apis.serviceorder.model.StateType;
import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@DirtiesContext(classMode= ClassMode.AFTER_CLASS)
+@ActiveProfiles("test")
public class ServiceOrderRepositoryTest {
@Autowired