diff options
author | romaingimbert <romain.gimbert@orange.com> | 2019-01-29 10:59:54 +0100 |
---|---|---|
committer | romaingimbert <romain.gimbert@orange.com> | 2019-01-30 11:52:59 +0100 |
commit | cf9e2869aaff92b58fb1806b2403a6790d62a709 (patch) | |
tree | 455f22133ce3276ba203992eb3443c044ddf90b2 /src/test/java/org | |
parent | ef8fea9dac61407f29850a34c19a1effd1d4a5b9 (diff) |
fix nbi test
-add karate test
-fix listener resource
Change-Id: I4904c40d65686c29404cfafd17ae6a5084cc4870
Issue-ID: EXTAPI-196
Signed-off-by: romaingimbert <romain.gimbert@orange.com>
Diffstat (limited to 'src/test/java/org')
4 files changed, 32 insertions, 171 deletions
diff --git a/src/test/java/org/onap/nbi/api/listener/ListenerResource.java b/src/test/java/org/onap/nbi/api/listener/ListenerResource.java index aa9efac..1b60109 100644 --- a/src/test/java/org/onap/nbi/api/listener/ListenerResource.java +++ b/src/test/java/org/onap/nbi/api/listener/ListenerResource.java @@ -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 index 6e57673..0000000 --- a/src/test/java/org/onap/nbi/test/ApiTestWithoutOnap.java +++ /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); - - - } - - - - -} diff --git a/src/test/java/org/onap/nbi/test/Context.java b/src/test/java/org/onap/nbi/test/Context.java index bc35aa0..10ad2c2 100644 --- a/src/test/java/org/onap/nbi/test/Context.java +++ b/src/test/java/org/onap/nbi/test/Context.java @@ -94,5 +94,12 @@ public class Context { } } + public static void stopWiremock() throws Exception { + // 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 index 56f2ba0..bc51541 100644 --- a/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java +++ b/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java @@ -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 |