Merge "Reorder modifiers"
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / openecomp / mso / apihandlerinfra / tenantisolation / process / CreateVnfOperationalEnvironmentTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.mso.apihandlerinfra.tenantisolation.process;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.spy;
25 import static org.mockito.Mockito.when;
26
27 import java.io.File;
28 import java.nio.file.Files;
29 import java.util.List;
30
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;
38
39 import com.fasterxml.jackson.databind.ObjectMapper;
40
41 public class CreateVnfOperationalEnvironmentTest {
42         
43         private ObjectMapper mapper = new ObjectMapper();
44         private CloudOrchestrationRequest request;
45         private ServiceEndPointList serviceEndpoints;
46         private CreateVnfOperationalEnvironment spyProcess;
47         
48         @Before
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);
57         }
58         
59         
60         @Test
61         public void testGetEcompManagingEnvironmentId() throws Exception { 
62                 when(spyProcess.getRequest()).thenReturn(request);
63                 assertEquals("ff305d54-75b4-431b-adb2-eb6b9e5ff000", spyProcess.getEcompManagingEnvironmentId());
64         }
65         
66         @Test
67         public void testGetTenantContext() throws Exception { 
68                 when(spyProcess.getRequest()).thenReturn(request);
69                 assertEquals("Test", spyProcess.getTenantContext());
70         }
71         
72         @Test
73         public void testGetEnvironmentName() throws Exception {
74                 List<Property> props = serviceEndpoints.getServiceEndPointList().get(0).getProperties();
75                 assertEquals("DEV", spyProcess.getEnvironmentName(props));
76         }
77         
78         @Test 
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"));
82         }
83         
84         @Test
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));
90         }
91         
92         public String getFileContentsAsString(String fileName) {
93                 String content = "";
94                 try {
95                         ClassLoader classLoader = this.getClass().getClassLoader();
96                         File file = new File(classLoader.getResource(fileName).getFile());
97                         content = new String(Files.readAllBytes(file.toPath()));
98                 }
99                 catch(Exception e) {
100                         e.printStackTrace();
101                         System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage());
102                 }
103                 return content;
104         }
105         
106 }