fix nbi test 03/77503/11
authorromaingimbert <romain.gimbert@orange.com>
Tue, 29 Jan 2019 09:59:54 +0000 (10:59 +0100)
committerromaingimbert <romain.gimbert@orange.com>
Wed, 30 Jan 2019 10:52:59 +0000 (11:52 +0100)
-add karate test
-fix listener resource

Change-Id: I4904c40d65686c29404cfafd17ae6a5084cc4870
Issue-ID: EXTAPI-196
Signed-off-by: romaingimbert <romain.gimbert@orange.com>
pom.xml
src/test/java/org/onap/nbi/api/listener/ListenerResource.java
src/test/java/org/onap/nbi/test/ApiTestWithoutOnap.java [deleted file]
src/test/java/org/onap/nbi/test/Context.java
src/test/java/org/onap/nbi/test/ExecutionTaskTest.java
src/test/resources/karatetest/features/00--ServiceCatalog.feature
src/test/resources/karatetest/features/01--ServiceInventory.feature
src/test/resources/karatetest/features/02--ServiceOrder.feature
src/test/resources/karatetest/features/03--Subscriber.feature
src/test/resources/toscafile/service-Sdwanvpninfraservice-csar.csar
src/test/resources/toscafile/service-Sotnvpninfraservice-csar.csar

diff --git a/pom.xml b/pom.xml
index a733f32..a778cf7 100644 (file)
--- a/pom.xml
+++ b/pom.xml
           <exclude>**/*.java</exclude>
         </excludes>
       </testResource>
+      <testResource>
+        <directory>src/test/resources</directory>
+      </testResource>
     </testResources>
     <plugins>
       <plugin>
             <include>org/onap/nbi/test/KarateApiTest.java</include>
              <include>org/onap/nbi/test/ExecutionTaskTest.java</include>
             <include>org/onap/nbi/test/ServiceOrderRepositoryTest.java</include>
-            <!--<include>org/onap/nbi/test/ApiTestWithoutOnap.java</include>-->
+            <include>org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java</include>
           </includes>
         </configuration>
       </plugin>
index aa9efac..1b60109 100644 (file)
@@ -16,8 +16,8 @@ import com.fasterxml.jackson.databind.JsonNode;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import org.apache.commons.lang3.StringUtils;
 import org.onap.nbi.commons.ResourceManagement;
 import org.slf4j.Logger;
@@ -41,7 +41,7 @@ public class ListenerResource extends ResourceManagement {
 
     Logger logger = LoggerFactory.getLogger(ListenerResource.class);
 
-    Map<String, JsonNode> events = new HashMap<>();
+    static Map<String, JsonNode> events = new ConcurrentHashMap<>();
 
     /*
         listener resource test for hub resource
@@ -71,6 +71,7 @@ public class ListenerResource extends ResourceManagement {
         if(StringUtils.isNotEmpty(serviceOrderId)) {
             for (JsonNode jsonNode : events.values()) {
                 String id = jsonNode.get("event").get("id").asText();
+                logger.info("found event with service order id : "+id);
                 if(id.equals(serviceOrderId)) {
                     values.add(jsonNode);
                 }
@@ -78,6 +79,7 @@ public class ListenerResource extends ResourceManagement {
             if(!values.isEmpty()) {
                 return ResponseEntity.ok(values);
             } else {
+                logger.error("cannot found events with service order id : "+serviceOrderId);
                 return ResponseEntity.notFound().build();
             }
         } else {
diff --git a/src/test/java/org/onap/nbi/test/ApiTestWithoutOnap.java b/src/test/java/org/onap/nbi/test/ApiTestWithoutOnap.java
deleted file mode 100644 (file)
index 6e57673..0000000
+++ /dev/null
@@ -1,169 +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.test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.junit.After;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-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;
-import org.onap.nbi.apis.serviceorder.model.ActionType;
-import org.onap.nbi.apis.serviceorder.model.RelatedParty;
-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.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 {
-
-
-    @Autowired
-    ServiceOrderRepository serviceOrderRepository;
-
-    @Autowired
-    ExecutionTaskRepository executionTaskRepository;
-
-    @Autowired
-    SOTaskProcessor SoTaskProcessor;
-
-    @Autowired
-    ServiceSpecificationResource serviceSpecificationResource;
-
-    @Autowired
-    ServiceInventoryResource serviceInventoryResource;
-
-    @Autowired
-    ServiceOrderResource serviceOrderResource;
-
-    @After
-    public void tearsDownUpPort() throws Exception {
-        executionTaskRepository.deleteAll();
-        serviceOrderRepository.deleteAll();
-    }
-
-
-    public ExecutionTask getExecutionTask(String orderItemId) {
-        for (ExecutionTask executionTask : executionTaskRepository.findAll()) {
-            if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) {
-                return executionTask;
-            }
-
-        }
-        return null;
-    }
-
-
-
-    @Test
-    public void testExecutionTaskWithoutOnap() throws Exception {
-
-        ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
-            executionTaskRepository, ActionType.ADD);
-
-        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(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
-        assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("502");
-        assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SO API");
-
-        assertThat(executionTaskRepository.count()).isEqualTo(0);
-    }
-
-
-    @Test
-    public void testCheckServiceOrderWithSDCNotResponding() throws Exception {
-
-        ServiceOrder testServiceOrder = ServiceOrderExecutionTaskAssertions.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.checkServiceOrder(testServiceOrder);
-
-        ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
-        assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
-
-        assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
-        assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("500");
-        assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SDC API");
-    }
-
-
-
-    @Test
-    public void testServiceCatalogGetResource() throws Exception {
-
-        ResponseEntity<Object> resource = serviceSpecificationResource
-            .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
-        assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
-
-
-    }
-
-
-
-    @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);
-        assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
-
-
-    }
-
-
-
-
-}
index bc35aa0..10ad2c2 100644 (file)
@@ -94,5 +94,12 @@ public class Context {
     }
 
   }
+  public static void stopWiremock() throws Exception {
 
+    // Wiremock
+    if (wireMockServer != null) {
+      wireMockServer.stop();
+    }
+
+  }
 }
index 56f2ba0..bc51541 100644 (file)
@@ -545,4 +545,25 @@ public class ExecutionTaskTest {
 
     }
 
+    @Test
+    public void testExecutionTaskWithoutOnap() throws Exception {
+        Context.stopWiremock();
+        ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+            executionTaskRepository, ActionType.ADD);
+
+        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(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
+        assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("502");
+        assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SO API");
+
+        assertThat(executionTaskRepository.count()).isEqualTo(0);
+        Context.startWiremock();
+
+    }
+
 }
\ No newline at end of file
index 2edd420..31fd148 100644 (file)
@@ -36,3 +36,11 @@ Then status 200
 And assert response.length == 21
 And match $[0] contains { name : 'FreeRadius-service' }
 
+Scenario: findServiceCatalogWithoutWiremock
+* call Context.stopWiremock();
+Given path 'serviceSpecification','1e3feeb0-8e36-46c6-862c-236d9c626439'
+When method get
+Then status 500
+* call Context.startServers();
+
+
index 2b657be..2065f8c 100644 (file)
@@ -82,6 +82,14 @@ And match $[1].relatedParty  contains { role : 'ONAPcustomer' , id : '6490' }
 And match $[1].serviceSpecification contains { name : 'vFW' , id : '98d95267-5e0f-4531-abf8-f14b90031dc5' }
 
 
+Scenario: testServiceResourceGetInventoryWithoutWiremock
+* call Context.stopWiremock();
+Given path 'service','e4688e5f-61a0-4f8b-ae02-a2fbde623bcb'
+And params {serviceSpecification.name : 'vFW' , relatedParty.id : '6490'}
+When method get
+Then status 500
+* call Context.startServers();
+
 
 
 
index 4ced372..c621709 100644 (file)
@@ -416,4 +416,23 @@ And match $.orderItem[0].orderMessage[0] contains { code : '102'  , field : 'ser
 Given path 'serviceOrder',serviceOrderId
 When method get
 Then status 200
+* call Context.startServers();
+
+Scenario: testCheckServiceOrderWithSDCNotRespondingWithoutWiremock
+* call Context.stopWiremock();
+Given path 'serviceOrder'
+And request data[4]
+When method post
+Then status 201
+And def serviceOrderId = $.id
+Given path 'serviceOrder','test',serviceOrderId
+And request $
+When method put
+Then status 201
+And match $.id == serviceOrderId
+And match $.state == 'rejected'
+And match $.orderMessage[0] contains { code : '500'  , messageInformation : 'Problem with SDC API' }
+Given path 'serviceOrder',serviceOrderId
+When method get
+Then status 200
 * call Context.startServers();
\ No newline at end of file
index 3a41c34..0d21ccb 100644 (file)
@@ -9,6 +9,7 @@ Background:
 * call Context.startServers();
 * def data = read('../data/subscriber.json')
 * def serviceOrderData = read('../data/serviceOrder.json')
+* configure retry = { count: 10, interval: 500 }
 * def checkDateFormat =
 """
 function(s) {
@@ -29,38 +30,65 @@ Given path 'hub'
 And request data[0]
 When method post
 Then status 201
-Given url 'http://localhost:8080/nbi/api/v3/hub/'
+And def location = responseHeaders['Location'][0]
+Given path 'hub'
 When method get
 And match $ == '#[1]'
+Given url location
+When method delete
+Then status 204
 
 Scenario: testGetByIdSubscriber
 Given path 'hub'
+And request data[0]
+When method post
+Then status 201
+Given path 'hub'
 When method get
 And def Id = $[0].id
 Given path 'hub',Id
 When method get
 And match $ contains { callback : 'http://localhost:8080/test' , query : 'eventType=ServiceOrderCreationNotification' }
+Given path 'hub',Id
+When method delete
+Then status 204
 
 Scenario: testFindSubscriber
 Given path 'hub'
 And request data[1]
 When method post
 Then status 201
+And def location1 = responseHeaders['Location'][0]
 Given path 'hub'
 And request data[2]
 When method post
 Then status 201
+And def location2 = responseHeaders['Location'][0]
 Given path 'hub'
 When method get
 Then status 200
 And match $ == '#notnull'
+Given url location1
+When method delete
+Then status 204
+Given url location2
+When method delete
+Then status 204
 
 Scenario: testFindWithFilteringSubscriber
 Given path 'hub'
+And request data[0]
+When method post
+Then status 201
+And def location = responseHeaders['Location'][0]
+Given path 'hub'
 And params { query.eventType : 'ServiceOrderCreationNotification' }
 When method get
 Then status 200
 And match $ == '#[1]'
+Given url location
+When method delete
+Then status 204
 
 Scenario: testSubscriberDeletion
 Given path 'hub'
@@ -93,8 +121,8 @@ Then status 201
 And def serviceOrderId = $.id
 Given path 'test/listener'
 And params {serviceOrderId : '#(serviceOrderId)'}
+And retry until responseStatus == 200
 When method get
-Then status 200
 And assert response.length == 1
 And match $[0] contains { eventId : '#notnull' , eventType : 'ServiceOrderCreationNotification' , eventDate : '#notnull' , event :'#notnull'}
 And def eventId = $[0].eventId
index e69de29..52bdfe2 100644 (file)
Binary files a/src/test/resources/toscafile/service-Sdwanvpninfraservice-csar.csar and b/src/test/resources/toscafile/service-Sdwanvpninfraservice-csar.csar differ
index e69de29..b4f9693 100644 (file)
Binary files a/src/test/resources/toscafile/service-Sotnvpninfraservice-csar.csar and b/src/test/resources/toscafile/service-Sotnvpninfraservice-csar.csar differ