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.process;
\r
23 import static org.mockito.Matchers.any;
\r
24 import static org.mockito.Mockito.doNothing;
\r
25 import static org.mockito.Mockito.mock;
\r
26 import static org.mockito.Mockito.spy;
\r
27 import static org.mockito.Mockito.times;
\r
28 import static org.mockito.Mockito.verify;
\r
29 import static org.mockito.Mockito.when;
\r
31 import java.util.Optional;
\r
33 import org.junit.Test;
\r
34 import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
\r
35 import org.openecomp.mso.apihandlerinfra.tenantisolation.helpers.AAIClientHelper;
\r
36 import org.openecomp.mso.client.aai.entities.AAIResultWrapper;
\r
37 import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment;
\r
38 import org.openecomp.mso.requestsdb.RequestsDBHelper;
\r
40 public class DeactivateVnfOperationalEnvironmentTest {
\r
43 public void testDeactivateOperationalEnvironment() throws Exception {
\r
44 String operationlEnvironmentId = "ff3514e3-5a33-55df-13ab-12abad84e7ff";
\r
45 CloudOrchestrationRequest request = new CloudOrchestrationRequest();
\r
46 request.setOperationalEnvironmentId(operationlEnvironmentId);
\r
47 request.setRequestDetails(null);
\r
49 DeactivateVnfOperationalEnvironment deactivate = spy(new DeactivateVnfOperationalEnvironment(request, "ff3514e3-5a33-55df-13ab-12abad84e7fe"));
\r
50 RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
\r
51 AAIClientHelper helper = mock(AAIClientHelper.class);
\r
52 AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
\r
53 AAIOperationalEnvironment operationalEnv = new AAIOperationalEnvironment();
\r
54 operationalEnv.setOperationalEnvironmentStatus("ACTIVE");
\r
56 doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
\r
57 when(helper.getAaiOperationalEnvironment(any(String.class))).thenReturn(wrapper);
\r
58 when(wrapper.asBean(AAIOperationalEnvironment.class)).thenReturn(Optional.of((AAIOperationalEnvironment)operationalEnv));
\r
60 deactivate.setRequestsDBHelper(dbUtils);
\r
61 deactivate.setAaiHelper(helper);
\r
62 deactivate.execute();
\r
64 verify(dbUtils, times(1)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
\r
68 public void testDeactivateInvalidStatus() throws Exception {
\r
69 String operationlEnvironmentId = "ff3514e3-5a33-55df-13ab-12abad84e7ff";
\r
70 CloudOrchestrationRequest request = new CloudOrchestrationRequest();
\r
71 request.setOperationalEnvironmentId(operationlEnvironmentId);
\r
72 request.setRequestDetails(null);
\r
74 DeactivateVnfOperationalEnvironment deactivate = spy(new DeactivateVnfOperationalEnvironment(request, "ff3514e3-5a33-55df-13ab-12abad84e7fe"));
\r
75 RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
\r
76 AAIClientHelper helper = mock(AAIClientHelper.class);
\r
77 AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
\r
78 AAIOperationalEnvironment operationalEnv = new AAIOperationalEnvironment();
\r
79 operationalEnv.setOperationalEnvironmentStatus("SUCCESS");
\r
81 doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
\r
82 when(helper.getAaiOperationalEnvironment(any(String.class))).thenReturn(wrapper);
\r
83 when(wrapper.asBean(AAIOperationalEnvironment.class)).thenReturn(Optional.of((AAIOperationalEnvironment)operationalEnv));
\r
85 deactivate.setRequestsDBHelper(dbUtils);
\r
86 deactivate.setAaiHelper(helper);
\r
87 deactivate.execute();
\r
89 verify(dbUtils, times(1)).updateInfraFailureCompletion(any(String.class), any(String.class), any(String.class));
\r