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.apis;
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.ServiceOrderAssertions;
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.context.junit4.SpringRunner;
43 import org.springframework.util.LinkedMultiValueMap;
44 import org.springframework.util.MultiValueMap;
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
48 public class ApiTestWithoutOnap {
52 ServiceOrderRepository serviceOrderRepository;
55 ExecutionTaskRepository executionTaskRepository;
58 SOTaskProcessor SoTaskProcessor;
61 ServiceSpecificationResource serviceSpecificationResource;
64 ServiceInventoryResource serviceInventoryResource;
67 ServiceOrderResource serviceOrderResource;
70 public void tearsDownUpPort() throws Exception {
71 executionTaskRepository.deleteAll();
72 serviceOrderRepository.deleteAll();
76 public ExecutionTask getExecutionTask(String orderItemId) {
77 for (ExecutionTask executionTask : executionTaskRepository.findAll()) {
78 if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) {
89 public void testExecutionTaskWithoutOnap() throws Exception {
91 ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
92 executionTaskRepository, ActionType.ADD);
94 SoTaskProcessor.processOrderItem(executionTaskA);
95 ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
96 assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
97 for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
98 assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
100 assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
101 assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("502");
102 assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SO API");
104 assertThat(executionTaskRepository.count()).isEqualTo(0);
109 public void testCheckServiceOrderWithSDCNotResponding() throws Exception {
111 ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
112 List<RelatedParty> customers = new ArrayList<>();
113 RelatedParty customer = new RelatedParty();
114 customer.setId("new");
115 customer.setRole("ONAPcustomer");
116 customer.setName("romain");
117 customers.add(customer);
118 testServiceOrder.setRelatedParty(customers);
119 testServiceOrder.setState(StateType.ACKNOWLEDGED);
120 testServiceOrder.setId("test");
121 serviceOrderRepository.save(testServiceOrder);
123 serviceOrderResource.scheduleCheckServiceOrders();
125 ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
126 assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
128 assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
129 assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("500");
130 assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SDC API");
136 public void testServiceCatalogGetResource() throws Exception {
138 ResponseEntity<Object> resource = serviceSpecificationResource
139 .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
140 assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
148 public void testServiceResourceGetInventory() throws Exception {
150 String serviceName = "vFW";
151 String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
152 MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
153 params.add("serviceSpecification.name", serviceName);
154 params.add("relatedParty.id", "6490");
155 ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
156 assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);