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