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;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.fail;
26 import java.util.HashMap;
28 import org.apache.commons.io.IOUtils;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import org.junit.Test;
31 import org.openecomp.mso.apihandler.common.ValidationException;
32 import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
33 import org.openecomp.mso.apihandlerinfra.tenantisolation.TenantIsolationRequest;
34 import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.Action;
36 public class TenantIsolationRequestTest {
39 public void testParseCloudResourceECOMP() throws Exception{
41 String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/ECOMPOperationEnvironmentCreate.json"));
42 ObjectMapper mapper = new ObjectMapper();
43 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
44 CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
45 TenantIsolationRequest request = new TenantIsolationRequest ("1234");
46 request.parse(cor, instanceIdMap, Action.create);
47 assertNotNull(request.getRequestId());
48 } catch(ValidationException e) {
54 public void testParseCloudResourceVNF() throws Exception{
56 String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/VNFOperationEnvironmentCreate.json"));
57 ObjectMapper mapper = new ObjectMapper();
58 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
59 CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
60 TenantIsolationRequest request = new TenantIsolationRequest ("1234");
61 request.parse(cor, instanceIdMap, Action.create);
62 assertNotNull(request.getRequestId());
63 } catch(ValidationException e) {
68 @Test(expected=ValidationException.class)
69 public void testParseCloudResourceVNFInvalid() throws Exception {
70 String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/VNFOperationEnvironmentCreateInvalid.json"));
71 ObjectMapper mapper = new ObjectMapper();
72 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
73 CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
74 TenantIsolationRequest request = new TenantIsolationRequest ("1234");
75 request.parse(cor, instanceIdMap, Action.create);
76 assertNotNull(request.getRequestId());
80 public void testParseActivateCloudResource() throws Exception{
82 String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/ActivateOperationEnvironment.json"));
83 ObjectMapper mapper = new ObjectMapper();
84 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
85 CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
86 TenantIsolationRequest request = new TenantIsolationRequest ("1234");
87 request.parse(cor, instanceIdMap, Action.activate);
88 assertNotNull(request.getRequestId());
89 } catch(ValidationException e) {
94 @Test(expected = ValidationException.class)
95 public void testParseActivateCloudResourceInvalid() throws Exception{
96 String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/ActivateOperationEnvironmentInvalid.json"));
97 ObjectMapper mapper = new ObjectMapper();
98 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
99 CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
100 TenantIsolationRequest request = new TenantIsolationRequest ("1234");
101 request.parse(cor, instanceIdMap, Action.activate);
102 assertNotNull(request.getRequestId());
106 public void testParseDeactivateCloudResource() throws Exception{
108 String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/DeactivateOperationEnvironment.json"));
109 ObjectMapper mapper = new ObjectMapper();
110 HashMap<String, String> instanceIdMap = new HashMap<String,String>();
111 CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
112 TenantIsolationRequest request = new TenantIsolationRequest ("1234");
113 request.parse(cor, instanceIdMap, Action.deactivate);
114 assertNotNull(request.getRequestId());
115 } catch(ValidationException e) {
116 fail(e.getMessage());
120 @Test(expected= ValidationException.class)
121 public void testParseDeactivateCloudResourceInvalid() throws Exception{
122 String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/DeactivateOperationEnvironmentInvalid.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());