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.onap.so.apihandlerinfra.tenantisolation;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.fail;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.HashMap;
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;
38 import com.fasterxml.jackson.databind.ObjectMapper;
40 public class TenantIsolationRequestTest extends BaseTest{
43 public ExpectedException expectedException = ExpectedException.none();
46 public void testParseCloudResourceECOMP() throws Exception{
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) {
61 public void testParseCloudResourceVNF() throws Exception{
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) {
76 public void testParseCloudResourceVNFInvalid() throws Exception {
77 expectedException.expect(ValidationException.class);
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());
89 public void testParseActivateCloudResource() throws Exception{
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) {
104 public void testParseActivateCloudResourceInvalid() throws Exception{
105 expectedException.expect(ValidationException.class);
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());
117 public void testParseDeactivateCloudResource() throws Exception{
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());
132 public void testParseDeactivateCloudResourceInvalid() throws Exception{
133 expectedException.expect(ValidationException.class);
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());