2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.apihandlerinfra.infra.rest;
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.spy;
28 import java.util.Optional;
29 import org.junit.Before;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.rules.ExpectedException;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.junit.MockitoJUnitRunner;
37 import org.onap.aai.domain.yang.GenericVnf;
38 import org.onap.aai.domain.yang.ServiceInstance;
39 import org.onap.aai.domain.yang.VfModule;
40 import org.onap.aai.domain.yang.VolumeGroup;
41 import org.onap.so.client.aai.AAIObjectType;
42 import org.onap.so.client.aai.AAIResourcesClient;
43 import org.onap.so.client.aai.entities.AAIResultWrapper;
44 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
45 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
46 import org.onap.so.db.request.client.RequestsDbClient;
47 import org.onap.so.serviceinstancebeans.ModelType;
48 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
49 import com.fasterxml.jackson.databind.ObjectMapper;
51 @RunWith(MockitoJUnitRunner.class)
52 public class BpmnRequestBuilderTest {
54 private static final String RESOURCE_PATH = "src/test/resources/__files/infra/";
57 public ExpectedException exceptionRule = ExpectedException.none();
61 private AAIResourcesClient aaiResourcesClient;
64 private AAIDataRetrieval aaiData = spy(AAIDataRetrieval.class);
67 private RequestsDbClient requestDBClient;
70 private BpmnRequestBuilder reqBuilder = spy(BpmnRequestBuilder.class);
73 private ObjectMapper mapper = new ObjectMapper();
75 private GraphInventoryCommonObjectMapperProvider provider = new GraphInventoryCommonObjectMapperProvider();
79 // aaiData.setAaiResourcesClient(aaiResourcesClient);
83 public void test_buildServiceInstanceDeleteRequest() throws Exception {
84 ServiceInstance service =
85 provider.getMapper().readValue(new File(RESOURCE_PATH + "ServiceInstance.json"), ServiceInstance.class);
87 doReturn(service).when(aaiData).getServiceInstance("serviceId");
88 ServiceInstancesRequest expectedRequest = mapper
89 .readValue(new File(RESOURCE_PATH + "ExpectedServiceRequest.json"), ServiceInstancesRequest.class);
90 expectedRequest.getRequestDetails().getModelInfo().setModelId(null); // bad getter/setter setting multiple
92 ServiceInstancesRequest actualRequest = reqBuilder.buildServiceDeleteRequest("serviceId");
93 assertThat(actualRequest, sameBeanAs(expectedRequest));
97 public void test_buildVnfDeleteRequest() throws Exception {
98 GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class);
100 doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class,
101 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId"));
103 ServiceInstancesRequest expectedRequest =
104 mapper.readValue(new File(RESOURCE_PATH + "ExpectedVnfRequest.json"), ServiceInstancesRequest.class);
105 ServiceInstancesRequest actualRequest = reqBuilder.buildVnfDeleteRequest("vnfId");
106 assertThat(actualRequest, sameBeanAs(expectedRequest));
110 public void test_buildVFModuleDeleteRequest() throws Exception {
111 GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class);
113 doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class,
114 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId"));
115 VfModule vfModule = provider.getMapper().readValue(new File(RESOURCE_PATH + "VfModule.json"), VfModule.class);
117 doReturn(Optional.of(vfModule)).when(aaiResourcesClient).get(VfModule.class,
118 AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, "vnfId", "vfModuleId"));
120 ServiceInstancesRequest expectedRequest = mapper
121 .readValue(new File(RESOURCE_PATH + "ExpectedVfModuleRequest.json"), ServiceInstancesRequest.class);
122 ServiceInstancesRequest actualRequest =
123 reqBuilder.buildVFModuleDeleteRequest("vnfId", "vfModuleId", ModelType.vfModule);
124 assertThat(actualRequest, sameBeanAs(expectedRequest));
128 public void test_buildVolumeGroupDeleteRequest() throws Exception {
129 GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class);
131 doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class,
132 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId"));
133 VolumeGroup volumeGroup =
134 provider.getMapper().readValue(new File(RESOURCE_PATH + "VolumeGroup.json"), VolumeGroup.class);
135 AAIResultWrapper wrapper = new AAIResultWrapper(volumeGroup);
136 doReturn(wrapper).when(aaiResourcesClient)
137 .get(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId")
138 .relatedTo(AAIObjectType.VOLUME_GROUP, "volumeGroupId"));
140 ServiceInstancesRequest expectedRequest = mapper
141 .readValue(new File(RESOURCE_PATH + "ExpectedVolumeGroupRequest.json"), ServiceInstancesRequest.class);
142 ServiceInstancesRequest actualRequest = reqBuilder.buildVolumeGroupDeleteRequest("vnfId", "volumeGroupId");
143 assertThat(actualRequest, sameBeanAs(expectedRequest));