426be984867de3daf7a83d06e9516e5005dde506
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / tenantisolation / TenantIsolationRequestTest.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.onap.so.apihandlerinfra.tenantisolation;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.fail;
25
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.HashMap;
29
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.rules.ExpectedException;
33 import org.onap.so.apihandlerinfra.BaseTest;
34 import org.onap.so.apihandlerinfra.tenantisolationbeans.Action;
35 import org.onap.so.exceptions.ValidationException;
36 import org.springframework.test.context.ActiveProfiles;
37
38 import com.fasterxml.jackson.databind.ObjectMapper;
39
40 public class TenantIsolationRequestTest extends BaseTest{
41
42         @Rule
43         public ExpectedException expectedException = ExpectedException.none();
44         
45         @Test
46         public void testParseCloudResourceECOMP() throws Exception{
47                 try {
48                         String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/TenantIsolation/ECOMPOperationEnvironmentCreate.json")));
49                         ObjectMapper mapper = new ObjectMapper();
50                         HashMap<String, String> instanceIdMap = new HashMap<String,String>();
51                         CloudOrchestrationRequest cor  = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
52                         TenantIsolationRequest request = new TenantIsolationRequest ("1234");
53                         request.parse(cor, instanceIdMap, Action.create);
54                         assertNotNull(request.getRequestId());
55                 } catch(ValidationException e) {
56                         fail(e.getMessage());
57                 }
58         }
59         
60         @Test
61         public void testParseCloudResourceVNF() throws Exception{
62                 try {
63                         String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/TenantIsolation/VNFOperationEnvironmentCreate.json")));
64                         ObjectMapper mapper = new ObjectMapper();
65                         HashMap<String, String> instanceIdMap = new HashMap<String,String>();
66                         CloudOrchestrationRequest cor  = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
67                         TenantIsolationRequest request = new TenantIsolationRequest ("1234");
68                         request.parse(cor, instanceIdMap, Action.create);
69                         assertNotNull(request.getRequestId());
70                 } catch(ValidationException e) {
71                         fail(e.getMessage());
72                 }
73         }
74         
75         @Test
76         public void testParseCloudResourceVNFInvalid() throws Exception {
77                 expectedException.expect(ValidationException.class);
78                 
79                 String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/TenantIsolation/VNFOperationEnvironmentCreateInvalid.json")));
80                 ObjectMapper mapper = new ObjectMapper();
81                 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
82                 CloudOrchestrationRequest cor  = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
83                 TenantIsolationRequest request = new TenantIsolationRequest ("1234");
84                 request.parse(cor, instanceIdMap, Action.create);
85                 assertNotNull(request.getRequestId());
86         }
87         
88         @Test
89         public void testParseActivateCloudResource() throws Exception{
90                 try {
91                         String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/TenantIsolation/ActivateOperationEnvironment.json")));
92                         ObjectMapper mapper = new ObjectMapper();
93                         HashMap<String, String> instanceIdMap = new HashMap<String,String>();
94                         CloudOrchestrationRequest cor  = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
95                         TenantIsolationRequest request = new TenantIsolationRequest ("1234");
96                         request.parse(cor, instanceIdMap, Action.activate);
97                         assertNotNull(request.getRequestId());
98                 } catch(ValidationException e) {
99                         fail(e.getMessage());
100                 }
101         }
102         
103         @Test
104         public void testParseActivateCloudResourceInvalid() throws Exception{
105                 expectedException.expect(ValidationException.class);
106                 
107                 String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/TenantIsolation/ActivateOperationEnvironmentInvalid.json")));
108                 ObjectMapper mapper = new ObjectMapper();
109                 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
110                 CloudOrchestrationRequest cor  = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
111                 TenantIsolationRequest request = new TenantIsolationRequest ("1234");
112                 request.parse(cor, instanceIdMap, Action.activate);
113                 assertNotNull(request.getRequestId());
114         }
115         
116         @Test
117         public void testParseDeactivateCloudResource() throws Exception{
118                 try {
119                         String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/TenantIsolation/DeactivateOperationEnvironment.json")));
120                         ObjectMapper mapper = new ObjectMapper();
121                         HashMap<String, String> instanceIdMap = new HashMap<String,String>();
122                         CloudOrchestrationRequest cor  = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
123                         TenantIsolationRequest request = new TenantIsolationRequest ("1234");
124                         request.parse(cor, instanceIdMap, Action.deactivate);
125                         assertNotNull(request.getRequestId());
126                 } catch(ValidationException e) {
127                         fail(e.getMessage());
128                 }
129         }
130         
131         @Test
132         public void testParseDeactivateCloudResourceInvalid() throws Exception{
133                 expectedException.expect(ValidationException.class);
134                 
135                 String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/TenantIsolation/DeactivateOperationEnvironmentInvalid.json")));
136                 ObjectMapper mapper = new ObjectMapper();
137                 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
138                 CloudOrchestrationRequest cor  = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
139                 TenantIsolationRequest request = new TenantIsolationRequest ("1234");
140                 request.parse(cor, instanceIdMap, Action.deactivate);
141                 assertNotNull(request.getRequestId());
142         }
143 }