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.helpers;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.put;
27 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.fail;
31 import static org.mockito.ArgumentMatchers.any;
32 import static org.mockito.Matchers.anyString;
33 import static org.mockito.Mockito.doNothing;
34 import static org.mockito.Mockito.mock;
35 import static org.mockito.Mockito.times;
36 import static org.mockito.Mockito.verify;
38 import java.util.HashMap;
40 import java.util.Optional;
42 import org.apache.http.HttpStatus;
43 import org.junit.Test;
44 import org.onap.so.apihandlerinfra.BaseTest;
45 import org.onap.so.client.aai.AAIVersion;
46 import org.onap.so.client.aai.entities.AAIResultWrapper;
47 import org.onap.so.client.aai.objects.AAIOperationalEnvironment;
48 import org.springframework.beans.factory.annotation.Autowired;
52 public class AAIClientHelperTest extends BaseTest{
55 private AAIClientHelper clientHelper;
58 public void testGetAaiOperationalEnvironmentSuccess() throws Exception {
59 stubFor(get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
60 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("vnfoperenv/ecompOperationalEnvironment.json").withStatus(HttpStatus.SC_ACCEPTED)));
62 AAIResultWrapper wrapper = clientHelper.getAaiOperationalEnvironment("EMOE-001");
63 Optional<AAIOperationalEnvironment> aaiOpEnv = wrapper.asBean(AAIOperationalEnvironment.class);
64 assertEquals("EMOE-001", aaiOpEnv.get().getOperationalEnvironmentId());
68 public void testUpdateSuccess() {
69 stubFor(post(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
70 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
72 AAIOperationalEnvironment ecompEnv = new AAIOperationalEnvironment();
73 ecompEnv.setTenantContext("Test");
74 ecompEnv.setWorkloadContext("ECOMPL_PSL");
77 AAIClientHelper clientHelper = mock(AAIClientHelper.class);
78 doNothing().when(clientHelper).updateAaiOperationalEnvironment(any(String.class), any(AAIOperationalEnvironment.class));
79 clientHelper.updateAaiOperationalEnvironment("EMOE-001", ecompEnv);
81 verify(clientHelper, times(1)).updateAaiOperationalEnvironment("EMOE-001", ecompEnv);
82 } catch(Exception e) {
83 fail("shouldn't reach here");
88 public void testUpdateMapSuccess() {
89 stubFor(post(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
90 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
92 Map<String, String> payload = new HashMap<String, String>();
93 payload.put("tenant-context", "Test");
94 payload.put("workload-context", "ECOMPL_PSL");
97 AAIClientHelper clientHelper = mock(AAIClientHelper.class);
98 doNothing().when(clientHelper).updateAaiOperationalEnvironment("EMOE-001", payload);
99 clientHelper.updateAaiOperationalEnvironment("EMOE-001", payload);
101 verify(clientHelper, times(1)).updateAaiOperationalEnvironment("EMOE-001", payload);
102 } catch(Exception e) {
103 fail("shouldn't reach here");
108 public void testCreateSuccess() {
109 stubFor(put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
110 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
112 AAIOperationalEnvironment ecompEnv = new AAIOperationalEnvironment();
113 ecompEnv.setOperationalEnvironmentId("opeEvnId");
114 ecompEnv.setTenantContext("Test");
115 ecompEnv.setWorkloadContext("ECOMPL_PSL");
118 AAIClientHelper clientHelper = mock(AAIClientHelper.class);
119 doNothing().when(clientHelper).createOperationalEnvironment(any(AAIOperationalEnvironment.class));
120 clientHelper.createOperationalEnvironment(ecompEnv);
122 verify(clientHelper, times(1)).createOperationalEnvironment(ecompEnv);
123 } catch(Exception e) {
124 fail("shouldn't reach here");
129 public void testcreateRelationshipSuccess() {
130 stubFor(put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
131 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
133 AAIOperationalEnvironment ecompEnv = new AAIOperationalEnvironment();
134 ecompEnv.setTenantContext("Test");
135 ecompEnv.setWorkloadContext("ECOMPL_PSL");
138 AAIClientHelper clientHelper = mock(AAIClientHelper.class);
139 doNothing().when(clientHelper).createRelationship(anyString(), anyString());
140 clientHelper.createRelationship("managingEcomp", "vnfOp");
142 verify(clientHelper, times(1)).createRelationship("managingEcomp", "vnfOp");
143 } catch(Exception e) {
144 fail("shouldn't reach here");