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 / helpers / AAIClientHelperTest.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.helpers;
22
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.urlPathMatching;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.fail;
30 import static org.mockito.ArgumentMatchers.any;
31 import static org.mockito.ArgumentMatchers.anyString;
32 import static org.mockito.Mockito.doNothing;
33 import static org.mockito.Mockito.mock;
34 import static org.mockito.Mockito.times;
35 import static org.mockito.Mockito.verify;
36 import java.util.HashMap;
37 import java.util.Map;
38 import java.util.Optional;
39 import org.apache.http.HttpStatus;
40 import org.junit.Test;
41 import org.onap.aai.domain.yang.OperationalEnvironment;
42 import org.onap.so.apihandlerinfra.BaseTest;
43 import org.onap.so.client.aai.AAIVersion;
44 import org.onap.so.client.aai.entities.AAIResultWrapper;
45 import org.springframework.beans.factory.annotation.Autowired;
46
47
48
49 public class AAIClientHelperTest extends BaseTest {
50
51     @Autowired
52     private AAIClientHelper clientHelper;
53
54     @Test
55     public void testGetAaiOperationalEnvironmentSuccess() throws Exception {
56         wireMockServer.stubFor(
57                 get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
58                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
59                                 .withBodyFile("vnfoperenv/ecompOperationalEnvironment.json")
60                                 .withStatus(HttpStatus.SC_ACCEPTED)));
61
62         AAIResultWrapper wrapper = clientHelper.getAaiOperationalEnvironment("EMOE-001");
63         Optional<OperationalEnvironment> aaiOpEnv = wrapper.asBean(OperationalEnvironment.class);
64         assertEquals("EMOE-001", aaiOpEnv.get().getOperationalEnvironmentId());
65     }
66
67     @Test
68     public void testUpdateSuccess() {
69         wireMockServer.stubFor(
70                 post(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
71                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
72                                 .withStatus(HttpStatus.SC_ACCEPTED)));
73
74         OperationalEnvironment ecompEnv = new OperationalEnvironment();
75         ecompEnv.setTenantContext("Test");
76         ecompEnv.setWorkloadContext("ECOMPL_PSL");
77
78         try {
79             AAIClientHelper clientHelper = mock(AAIClientHelper.class);
80             doNothing().when(clientHelper).updateAaiOperationalEnvironment(any(String.class),
81                     any(OperationalEnvironment.class));
82             clientHelper.updateAaiOperationalEnvironment("EMOE-001", ecompEnv);
83
84             verify(clientHelper, times(1)).updateAaiOperationalEnvironment("EMOE-001", ecompEnv);
85         } catch (Exception e) {
86             fail("shouldn't reach here");
87         }
88     }
89
90     @Test
91     public void testUpdateMapSuccess() {
92         wireMockServer.stubFor(
93                 post(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
94                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
95                                 .withStatus(HttpStatus.SC_ACCEPTED)));
96
97         Map<String, String> payload = new HashMap<String, String>();
98         payload.put("tenant-context", "Test");
99         payload.put("workload-context", "ECOMPL_PSL");
100         payload.put("operational-environment-status", "ACTIVE");
101
102         try {
103             AAIClientHelper clientHelper = mock(AAIClientHelper.class);
104             doNothing().when(clientHelper).updateAaiOperationalEnvironment("EMOE-001", payload);
105             clientHelper.updateAaiOperationalEnvironment("EMOE-001", payload);
106
107             verify(clientHelper, times(1)).updateAaiOperationalEnvironment("EMOE-001", payload);
108         } catch (Exception e) {
109             fail("shouldn't reach here");
110         }
111     }
112
113     @Test
114     public void testCreateSuccess() {
115         wireMockServer.stubFor(
116                 put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
117                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
118                                 .withStatus(HttpStatus.SC_ACCEPTED)));
119
120         OperationalEnvironment ecompEnv = new OperationalEnvironment();
121         ecompEnv.setOperationalEnvironmentId("opeEvnId");
122         ecompEnv.setTenantContext("Test");
123         ecompEnv.setWorkloadContext("ECOMPL_PSL");
124
125         try {
126             AAIClientHelper clientHelper = mock(AAIClientHelper.class);
127             doNothing().when(clientHelper).createOperationalEnvironment(any(OperationalEnvironment.class));
128             clientHelper.createOperationalEnvironment(ecompEnv);
129
130             verify(clientHelper, times(1)).createOperationalEnvironment(ecompEnv);
131         } catch (Exception e) {
132             fail("shouldn't reach here");
133         }
134     }
135
136     @Test
137     public void testcreateRelationshipSuccess() {
138         wireMockServer.stubFor(
139                 put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
140                         .willReturn(aResponse().withHeader("Content-Type", "application/json")
141                                 .withStatus(HttpStatus.SC_ACCEPTED)));
142
143         OperationalEnvironment ecompEnv = new OperationalEnvironment();
144         ecompEnv.setTenantContext("Test");
145         ecompEnv.setWorkloadContext("ECOMPL_PSL");
146
147         try {
148             AAIClientHelper clientHelper = mock(AAIClientHelper.class);
149             doNothing().when(clientHelper).createRelationship(anyString(), anyString());
150             clientHelper.createRelationship("managingEcomp", "vnfOp");
151
152             verify(clientHelper, times(1)).createRelationship("managingEcomp", "vnfOp");
153         } catch (Exception e) {
154             fail("shouldn't reach here");
155         }
156     }
157 }