2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.nbi.test;
18 import static org.assertj.core.api.Assertions.assertThat;
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.junit.After;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.onap.nbi.apis.assertions.ServiceOrderExecutionTaskAssertions;
26 import org.onap.nbi.apis.servicecatalog.ServiceSpecificationResource;
27 import org.onap.nbi.apis.serviceinventory.ServiceInventoryResource;
28 import org.onap.nbi.apis.serviceorder.ServiceOrderResource;
29 import org.onap.nbi.apis.serviceorder.model.ActionType;
30 import org.onap.nbi.apis.serviceorder.model.RelatedParty;
31 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
32 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
33 import org.onap.nbi.apis.serviceorder.model.StateType;
34 import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask;
35 import org.onap.nbi.apis.serviceorder.repositories.ExecutionTaskRepository;
36 import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
37 import org.onap.nbi.apis.serviceorder.workflow.SOTaskProcessor;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.boot.test.context.SpringBootTest;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.http.ResponseEntity;
42 import org.springframework.test.annotation.DirtiesContext;
43 import org.springframework.test.annotation.DirtiesContext.ClassMode;
44 import org.springframework.test.context.ActiveProfiles;
45 import org.springframework.test.context.junit4.SpringRunner;
46 import org.springframework.util.LinkedMultiValueMap;
47 import org.springframework.util.MultiValueMap;
49 @ActiveProfiles("test")
50 @RunWith(SpringRunner.class)
51 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
52 @DirtiesContext(classMode= ClassMode.AFTER_CLASS)
53 public class ApiTestWithoutOnap {
57 ServiceOrderRepository serviceOrderRepository;
60 ExecutionTaskRepository executionTaskRepository;
63 SOTaskProcessor SoTaskProcessor;
66 ServiceSpecificationResource serviceSpecificationResource;
69 ServiceInventoryResource serviceInventoryResource;
72 ServiceOrderResource serviceOrderResource;
75 public void tearsDownUpPort() throws Exception {
76 executionTaskRepository.deleteAll();
77 serviceOrderRepository.deleteAll();
81 public ExecutionTask getExecutionTask(String orderItemId) {
82 for (ExecutionTask executionTask : executionTaskRepository.findAll()) {
83 if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) {
94 public void testExecutionTaskWithoutOnap() throws Exception {
96 ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
97 executionTaskRepository, ActionType.ADD);
99 SoTaskProcessor.processOrderItem(executionTaskA);
100 ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
101 assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
102 for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
103 assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
105 assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
106 assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("502");
107 assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SO API");
109 assertThat(executionTaskRepository.count()).isEqualTo(0);
114 public void testCheckServiceOrderWithSDCNotResponding() throws Exception {
116 ServiceOrder testServiceOrder = ServiceOrderExecutionTaskAssertions.createTestServiceOrder(ActionType.ADD);
117 List<RelatedParty> customers = new ArrayList<>();
118 RelatedParty customer = new RelatedParty();
119 customer.setId("new");
120 customer.setRole("ONAPcustomer");
121 customer.setName("romain");
122 customers.add(customer);
123 testServiceOrder.setRelatedParty(customers);
124 testServiceOrder.setState(StateType.ACKNOWLEDGED);
125 testServiceOrder.setId("test");
126 serviceOrderRepository.save(testServiceOrder);
128 serviceOrderResource.checkServiceOrder(testServiceOrder);
130 ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
131 assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
133 assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
134 assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("500");
135 assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SDC API");
141 public void testServiceCatalogGetResource() throws Exception {
143 ResponseEntity<Object> resource = serviceSpecificationResource
144 .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
145 assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
153 public void testServiceResourceGetInventory() throws Exception {
155 String serviceName = "vFW";
156 String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
157 MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
158 params.add("serviceSpecification.name", serviceName);
159 params.add("relatedParty.id", "6490");
160 ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
161 assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);