2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.mso.apihandlerinfra.tenantisolation.process;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.spy;
25 import static org.mockito.Mockito.when;
28 import java.nio.file.Files;
29 import java.util.List;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.mockito.MockitoAnnotations;
34 import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
35 import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment;
36 import org.openecomp.mso.client.grm.beans.Property;
37 import org.openecomp.mso.client.grm.beans.ServiceEndPointList;
39 import com.fasterxml.jackson.databind.ObjectMapper;
41 public class CreateVnfOperationalEnvironmentTest {
43 private ObjectMapper mapper = new ObjectMapper();
44 private CloudOrchestrationRequest request;
45 private ServiceEndPointList serviceEndpoints;
46 private CreateVnfOperationalEnvironment spyProcess;
49 public void testSetUp() throws Exception {
50 MockitoAnnotations.initMocks(this);
51 String jsonRequest = getFileContentsAsString("__files/vnfoperenv/createVnfOperationalEnvironmentRequest.json");
52 request = mapper.readValue(jsonRequest, CloudOrchestrationRequest.class);
53 String jsonServiceEndpoints = getFileContentsAsString("__files/vnfoperenv/endpoints.json");
54 serviceEndpoints = mapper.readValue(jsonServiceEndpoints, ServiceEndPointList.class);
55 CreateVnfOperationalEnvironment process = new CreateVnfOperationalEnvironment(request, "9876543210");
56 spyProcess = spy(process);
61 public void testGetEcompManagingEnvironmentId() throws Exception {
62 when(spyProcess.getRequest()).thenReturn(request);
63 assertEquals("ff305d54-75b4-431b-adb2-eb6b9e5ff000", spyProcess.getEcompManagingEnvironmentId());
67 public void testGetTenantContext() throws Exception {
68 when(spyProcess.getRequest()).thenReturn(request);
69 assertEquals("Test", spyProcess.getTenantContext());
73 public void testGetEnvironmentName() throws Exception {
74 List<Property> props = serviceEndpoints.getServiceEndPointList().get(0).getProperties();
75 assertEquals("DEV", spyProcess.getEnvironmentName(props));
79 public void testBuildServiceNameForVnf() throws Exception {
80 when(spyProcess.getRequest()).thenReturn(request);
81 assertEquals("Test.VNF_E2E-IST.Inventory", spyProcess.buildServiceNameForVnf("TEST.ECOMP_PSL.Inventory"));
85 public void testGetSearchKey() {
86 AAIOperationalEnvironment ecompEnv = new AAIOperationalEnvironment();
87 ecompEnv.setTenantContext("Test");
88 ecompEnv.setWorkloadContext("ECOMPL_PSL");
89 assertEquals("Test.ECOMPL_PSL.*", spyProcess.getSearchKey(ecompEnv));
92 public String getFileContentsAsString(String fileName) {
95 ClassLoader classLoader = this.getClass().getClassLoader();
96 File file = new File(classLoader.getResource(fileName).getFile());
97 content = new String(Files.readAllBytes(file.toPath()));
101 System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage());