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;
27 import java.util.Optional;
28 import org.junit.Before;
29 import org.junit.Rule;
30 import org.junit.Test;
31 import org.junit.rules.ExpectedException;
32 import org.junit.runner.RunWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.Spy;
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.uri.AAIUriFactory;
44 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
45 import org.onap.so.db.request.client.RequestsDbClient;
46 import org.onap.so.serviceinstancebeans.ModelType;
47 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
48 import com.fasterxml.jackson.databind.ObjectMapper;
50 @RunWith(MockitoJUnitRunner.class)
51 public class BpmnRequestBuilderTest {
53 private static final String RESOURCE_PATH = "src/test/resources/__files/infra/";
56 public ExpectedException exceptionRule = ExpectedException.none();
60 BpmnRequestBuilder reqBuilder;
63 private RequestsDbClient requestDBClient;
66 private AAIResourcesClient aaiResourcesClient;
68 private ObjectMapper mapper = new ObjectMapper();
70 private GraphInventoryCommonObjectMapperProvider provider = new GraphInventoryCommonObjectMapperProvider();
74 reqBuilder.setAaiResourcesClient(aaiResourcesClient);
79 public void test_buildServiceInstanceDeleteRequest() throws Exception {
80 ServiceInstance service =
81 provider.getMapper().readValue(new File(RESOURCE_PATH + "ServiceInstance.json"), ServiceInstance.class);
83 doReturn(service).when(reqBuilder).getServiceInstance("serviceId");
84 ServiceInstancesRequest expectedRequest = mapper
85 .readValue(new File(RESOURCE_PATH + "ExpectedServiceRequest.json"), ServiceInstancesRequest.class);
86 expectedRequest.getRequestDetails().getModelInfo().setModelId(null);
87 // bad getter/setter setting multiple fields
88 ServiceInstancesRequest actualRequest = reqBuilder.buildServiceDeleteRequest("serviceId");
89 assertThat(actualRequest, sameBeanAs(expectedRequest));
93 public void test_buildVnfDeleteRequest() throws Exception {
94 GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class);
96 doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class,
97 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId"));
99 ServiceInstancesRequest expectedRequest =
100 mapper.readValue(new File(RESOURCE_PATH + "ExpectedVnfRequest.json"), ServiceInstancesRequest.class);
101 ServiceInstancesRequest actualRequest = reqBuilder.buildVnfDeleteRequest("vnfId");
102 assertThat(actualRequest, sameBeanAs(expectedRequest));
106 public void test_buildVFModuleDeleteRequest() throws Exception {
107 GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class);
109 doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class,
110 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId"));
111 VfModule vfModule = provider.getMapper().readValue(new File(RESOURCE_PATH + "VfModule.json"), VfModule.class);
113 doReturn(Optional.of(vfModule)).when(aaiResourcesClient).get(VfModule.class,
114 AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, "vnfId", "vfModuleId"));
116 ServiceInstancesRequest expectedRequest = mapper
117 .readValue(new File(RESOURCE_PATH + "ExpectedVfModuleRequest.json"), ServiceInstancesRequest.class);
118 ServiceInstancesRequest actualRequest =
119 reqBuilder.buildVFModuleDeleteRequest("vnfId", "vfModuleId", ModelType.vfModule);
120 assertThat(actualRequest, sameBeanAs(expectedRequest));
124 public void test_buildVolumeGroupDeleteRequest() throws Exception {
125 GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class);
127 doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class,
128 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId"));
129 VolumeGroup volumeGroup =
130 provider.getMapper().readValue(new File(RESOURCE_PATH + "VolumeGroup.json"), VolumeGroup.class);
132 doReturn(Optional.of(volumeGroup)).when(aaiResourcesClient).get(VolumeGroup.class, AAIUriFactory
133 .createResourceUri(AAIObjectType.VOLUME_GROUP, "cloudOwner", "regionOne", "volumeGroupId"));
135 ServiceInstancesRequest expectedRequest = mapper
136 .readValue(new File(RESOURCE_PATH + "ExpectedVolumeGroupRequest.json"), ServiceInstancesRequest.class);
137 ServiceInstancesRequest actualRequest = reqBuilder.buildVolumeGroupDeleteRequest("vnfId", "volumeGroupId");
138 assertThat(actualRequest, sameBeanAs(expectedRequest));