diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation')
17 files changed, 0 insertions, 2655 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/CloudOrchestrationTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/CloudOrchestrationTest.java deleted file mode 100644 index 30db50c9b9..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/CloudOrchestrationTest.java +++ /dev/null @@ -1,209 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-
-import javax.ws.rs.core.Response;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharEncoding;
-import org.junit.Ignore; -import org.junit.Test;
-import org.openecomp.mso.apihandlerinfra.MsoException;
-import org.openecomp.mso.apihandlerinfra.Status;
-import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.Action;
-import org.openecomp.mso.requestsdb.InfraActiveRequests;
-import org.openecomp.mso.requestsdb.RequestsDatabase;
-
-public class CloudOrchestrationTest {
-
- @Test
- public void testCreateOpEnvObjectMapperError() throws IOException {
- CloudOrchestration co = new CloudOrchestration();
- Response response = co.createOperationEnvironment(null, null);
- String body = response.getEntity().toString();
-
- assertTrue(body.contains("Mapping of request to JSON object failed."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testCreateOpEnvError() throws IOException {
- String request = "{\"requestDetails\":{\"requestInfo\":{\"resourceType\":\"operationalEnvironment\",\"instanceName\": \"myOpEnv\",\"source\": \"VID\",\"requestorId\": \"az2017\"},"
- + " \"requestParameters\": {\"tenantContext\": \"Test\",\"workloadContext\": \"ECOMP_E2E-IST\"}}}";
- CloudOrchestration co = new CloudOrchestration();
- Response response = co.createOperationEnvironment(request, null);
- String body = response.getEntity().toString();
-
- assertTrue(body.contains("Error parsing request."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testCreateOpEnvReqRecord() throws IOException {
- CloudOrchestration co = new CloudOrchestration();
- String request = IOUtils.toString(ClassLoader.class.getResourceAsStream ("/ECOMPOperationEnvironmentCreate.json"), CharEncoding.UTF_8);
- Response response = co.createOperationEnvironment(request, null);
- assertEquals(500, response.getStatus());
- }
-
- @Test
- public void testCreateOperationalEnvironment() throws IOException {
- CloudOrchestration co = new CloudOrchestration();
- TenantIsolationRequest tenantIsolationRequest = mock(TenantIsolationRequest.class);
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- co.setRequestsDatabase(reqDB);
- co.setTenantIsolationRequest(tenantIsolationRequest);
- String request = IOUtils.toString(ClassLoader.class.getResourceAsStream ("/ECOMPOperationEnvironmentCreate.json"), CharEncoding.UTF_8);
- when(reqDB.checkInstanceNameDuplicate(new HashMap<String, String>(), "myOpEnv", "create")).thenReturn(null);
- doNothing().when(tenantIsolationRequest).createRequestRecord(Status.IN_PROGRESS, Action.create);
-
- Response response = co.createOperationEnvironment(request, null);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testCreateVNFDuplicateCheck() throws IOException {
- CloudOrchestration co = new CloudOrchestration();
- TenantIsolationRequest tenantIsolationRequest = mock(TenantIsolationRequest.class);
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- Response res = Response.status(409).entity("already has a request being worked with a status of").build();
-
- co.setRequestsDatabase(reqDB);
- co.setTenantIsolationRequest(tenantIsolationRequest);
- String request = IOUtils.toString(ClassLoader.class.getResourceAsStream ("/VNFOperationEnvironmentCreate.json"), CharEncoding.UTF_8);
- when(reqDB.checkInstanceNameDuplicate(null, "myVnfOpEnv", "operationalEnvironment")).thenReturn(new InfraActiveRequests());
- doNothing().when(tenantIsolationRequest).createRequestRecord(Status.FAILED, Action.create);
- when(tenantIsolationRequest.buildServiceErrorResponse(any(Integer.class), any(MsoException.class), any(String.class), any(String.class), any(List.class))).thenReturn(res);
-
- Response response = co.createOperationEnvironment(request, null);
- assertEquals(409, response.getStatus());
- }
-
- @Test
- public void testCreateVNF() throws IOException {
- CloudOrchestration co = new CloudOrchestration();
- TenantIsolationRequest tenantIsolationRequest = mock(TenantIsolationRequest.class);
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- TenantIsolationRunnable thread = mock(TenantIsolationRunnable.class);
-
- co.setRequestsDatabase(reqDB);
- co.setThread(thread);
- co.setTenantIsolationRequest(tenantIsolationRequest);
- String request = IOUtils.toString(ClassLoader.class.getResourceAsStream ("/VNFOperationEnvironmentCreate.json"), CharEncoding.UTF_8);
- when(reqDB.checkInstanceNameDuplicate(null, "myVnfOpEnv", "operationalEnvironment")).thenReturn(null);
- doNothing().when(tenantIsolationRequest).createRequestRecord(Status.IN_PROGRESS, Action.create);
- doNothing().when(thread).run();
-
- Response response = co.createOperationEnvironment(request, null);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testActivate() throws IOException {
- CloudOrchestration co = new CloudOrchestration();
- TenantIsolationRequest tenantIsolationRequest = mock(TenantIsolationRequest.class);
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- TenantIsolationRunnable thread = mock(TenantIsolationRunnable.class);
-
- co.setRequestsDatabase(reqDB);
- co.setThread(thread);
- co.setTenantIsolationRequest(tenantIsolationRequest);
- String request = IOUtils.toString(ClassLoader.class.getResourceAsStream ("/ActivateOperationEnvironment.json"), CharEncoding.UTF_8);
- when(reqDB.checkInstanceNameDuplicate(null, "myVnfOpEnv", "operationalEnvironment")).thenReturn(null);
- doNothing().when(tenantIsolationRequest).createRequestRecord(Status.IN_PROGRESS, Action.activate);
- doNothing().when(thread).run();
-
- Response response = co.activateOperationEnvironment(request, null, "ff3514e3-5a33-55df-13ab-12abad84e7ff");
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testDeactivate() throws IOException {
- CloudOrchestration co = new CloudOrchestration();
- TenantIsolationRequest tenantIsolationRequest = mock(TenantIsolationRequest.class);
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- TenantIsolationRunnable thread = mock(TenantIsolationRunnable.class);
-
- co.setRequestsDatabase(reqDB);
- co.setThread(thread);
- co.setTenantIsolationRequest(tenantIsolationRequest);
- String request = IOUtils.toString(ClassLoader.class.getResourceAsStream ("/DeactivateOperationEnvironment.json"), CharEncoding.UTF_8);
- when(reqDB.checkInstanceNameDuplicate(null, "myVnfOpEnv", "operationalEnvironment")).thenReturn(null);
- doNothing().when(tenantIsolationRequest).createRequestRecord(Status.IN_PROGRESS, Action.deactivate);
- doNothing().when(thread).run();
-
- Response response = co.activateOperationEnvironment(request, null, "ff3514e3-5a33-55df-13ab-12abad84e7ff");
- assertEquals(200, response.getStatus());
- }
-
- @Ignore // 1802 merge - @Test
- public void testDeactivateThreadException() throws IOException {
- CloudOrchestration co = new CloudOrchestration();
- TenantIsolationRequest tenantIsolationRequest = mock(TenantIsolationRequest.class);
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- TenantIsolationRunnable thread = mock(TenantIsolationRunnable.class);
- Response res = Response.status(500).entity("Failed creating a Thread").build();
-
- co.setRequestsDatabase(reqDB);
- co.setThread(thread);
- co.setTenantIsolationRequest(tenantIsolationRequest);
- String request = IOUtils.toString(ClassLoader.class.getResourceAsStream ("/DeactivateOperationEnvironment.json"), CharEncoding.UTF_8);
- when(reqDB.checkInstanceNameDuplicate(null, "myVnfOpEnv", "operationalEnvironment")).thenReturn(null);
- doNothing().when(tenantIsolationRequest).createRequestRecord(Status.IN_PROGRESS, Action.deactivate);
- doThrow(Exception.class).when(thread).run();
- when(tenantIsolationRequest.buildServiceErrorResponse(any(Integer.class), any(MsoException.class), any(String.class), any(String.class), any(List.class))).thenReturn(res);
-
- Response response = co.activateOperationEnvironment(request, null, "ff3514e3-5a33-55df-13ab-12abad84e7ff");
- assertEquals(500, response.getStatus());
- }
-
- @Test
- public void testDeactivateDupCheck() throws IOException {
- CloudOrchestration co = new CloudOrchestration();
- TenantIsolationRequest tenantIsolationRequest = mock(TenantIsolationRequest.class);
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- Response res = Response.status(409).entity("Failed creating a Thread").build();
-
- co.setRequestsDatabase(reqDB);
- co.setTenantIsolationRequest(tenantIsolationRequest);
- String request = IOUtils.toString(ClassLoader.class.getResourceAsStream ("/DeactivateOperationEnvironment.json"), CharEncoding.UTF_8);
- when(reqDB.checkInstanceNameDuplicate(null, "myVnfOpEnv", "operationalEnvironment")).thenReturn(null);
- when(reqDB.checkVnfIdStatus(null)).thenReturn(new InfraActiveRequests());
- when(tenantIsolationRequest.buildServiceErrorResponse(any(Integer.class), any(MsoException.class), any(String.class), any(String.class), any(List.class))).thenReturn(res);
-
- Response response = co.deactivateOperationEnvironment(request, null, "ff3514e3-5a33-55df-13ab-12abad84e7ff");
- assertEquals(409, response.getStatus());
- }
-}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/CloudResourcesOrchestrationTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/CloudResourcesOrchestrationTest.java deleted file mode 100644 index 3e19489f5d..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/CloudResourcesOrchestrationTest.java +++ /dev/null @@ -1,333 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.sql.Timestamp;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.core.Response;
-
-import org.jboss.resteasy.spi.ResteasyUriInfo;
-import org.junit.Ignore; -import org.junit.Test;
-import org.openecomp.mso.requestsdb.InfraActiveRequests;
-import org.openecomp.mso.requestsdb.RequestsDatabase;
-
-public class CloudResourcesOrchestrationTest {
-
- private String requestJSON = "{\"requestDetails\":{\"requestInfo\":{\"source\":\"VID\",\"requestorId\":\"zz9999\" } } }";
-
- @Test
- public void testUnlockFailObjectMapping() {
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- Response response = cor.unlockOrchestrationRequest(null, null, null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Mapping of request to JSON object failed."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testUnlockFailObjectMapping2() {
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- Response response = cor.unlockOrchestrationRequest(null, "requestId", null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Mapping of request to JSON object failed."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testParseOrchestrationError1() {
- String requestJSON = "{\"requestDetails\": null }";
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- Response response = cor.unlockOrchestrationRequest(requestJSON, "requestId", null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Error parsing request."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testParseOrchestrationError2() {
- String requestJSON = "{\"requestDetails\":{\"requestInfo\":{\"source\":\"\",\"requestorId\":\"zz9999\" } } }";
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- Response response = cor.unlockOrchestrationRequest(requestJSON, "requestId", null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Error parsing request."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testParseOrchestrationError3() {
- String requestJSON = "{\"requestDetails\":{\"requestInfo\":{\"source\":\"VID\",\"requestorId\":\"\" } } }";
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- Response response = cor.unlockOrchestrationRequest(requestJSON, "requestId", null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Error parsing request."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testGetInfraActiveRequestNull() {
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- cor.setRequestsDB(reqDB);
- when(reqDB.getRequestFromInfraActive("requestId")).thenReturn(null);
-
- Response response = cor.unlockOrchestrationRequest(requestJSON, "requestId", null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Orchestration RequestId requestId is not found in DB"));
- assertEquals(404, response.getStatus());
- }
-
- @Test
- public void testUnlockError() {
- InfraActiveRequests iar = new InfraActiveRequests();
- iar.setRequestId("requestId");
- iar.setRequestScope("requestScope");
- iar.setRequestType("requestType");
- iar.setOperationalEnvId("operationalEnvironmentId");
- iar.setOperationalEnvName("operationalEnvName");
- iar.setRequestorId("ma920e");
- iar.setRequestBody("");
- iar.setRequestStatus("IN_PROGRESS");
-
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- cor.setRequestsDB(reqDB);
- when(reqDB.getRequestFromInfraActive("requestId")).thenReturn(iar);
- when(reqDB.updateInfraStatus("requestId", "UNLOCKED", "APIH")).thenReturn(1);
-
- Response response = cor.unlockOrchestrationRequest(requestJSON, "requestId", null);
- assertEquals(404, response.getStatus());
- }
-
- @Test
- public void testUnlock() throws ParseException {
- InfraActiveRequests iar = new InfraActiveRequests();
- iar.setRequestId("requestId");
- iar.setRequestScope("requestScope");
- iar.setRequestType("requestType");
- iar.setOperationalEnvId("operationalEnvironmentId");
- iar.setOperationalEnvName("operationalEnvName");
- iar.setRequestorId("ma920e");
- iar.setRequestBody("");
- iar.setRequestStatus("IN_PROGRESS");
-
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateFormat.parse("23/09/2007");
- long time = date.getTime();
- iar.setStartTime(new Timestamp(time));
-
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- cor.setRequestsDB(reqDB);
- when(reqDB.getRequestFromInfraActive("requestId")).thenReturn(iar);
- when(reqDB.updateInfraStatus("requestId", "UNLOCKED", "APIH")).thenReturn(1);
-
- Response response = cor.unlockOrchestrationRequest(requestJSON, "requestId", null);
- assertEquals(204, response.getStatus());
- }
-
- @Test
- public void testUnlockComplete() throws ParseException {
- InfraActiveRequests iar = new InfraActiveRequests();
- iar.setRequestId("requestId");
- iar.setRequestScope("requestScope");
- iar.setRequestType("requestType");
- iar.setOperationalEnvId("operationalEnvironmentId");
- iar.setOperationalEnvName("operationalEnvName");
- iar.setRequestorId("ma920e");
- iar.setRequestBody("");
- iar.setRequestStatus("COMPLETE");
-
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateFormat.parse("23/09/2007");
- long time = date.getTime();
- iar.setStartTime(new Timestamp(time));
-
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- cor.setRequestsDB(reqDB);
- when(reqDB.getRequestFromInfraActive("requestId")).thenReturn(iar);
- when(reqDB.updateInfraStatus("requestId", "UNLOCKED", "APIH")).thenReturn(1);
-
- Response response = cor.unlockOrchestrationRequest(requestJSON, "requestId", null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Orchestration RequestId requestId has a status of COMPLETE and can not be unlocked"));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testGetOperationalEnvFilter() {
- ResteasyUriInfo uriInfo = new ResteasyUriInfo("", "requestId=89c56827-1c78-4827-bc4d-6afcdb37a51f", "");
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- cor.setRequestsDB(reqDB);
- when(reqDB.getRequestFromInfraActive("89c56827-1c78-4827-bc4d-6afcdb37a51f")).thenReturn(null);
-
- Response response = cor.getOperationEnvironmentStatusFilter(uriInfo, null);
- String body = response.getEntity().toString();
-
- assertTrue(body.contains("Orchestration RequestId 89c56827-1c78-4827-bc4d-6afcdb37a51f is not found in DB"));
- assertEquals(204, response.getStatus());
- }
-
- @Test
- public void testGetOperationalEnvFilterException() {
- ResteasyUriInfo uriInfo = new ResteasyUriInfo("", "requestId=89c56827-1c78-4827-bc4d-6afcdb37a51f", "");
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
-
- Response response = cor.getOperationEnvironmentStatusFilter(uriInfo, null);
- assertEquals(404, response.getStatus());
- }
-
- @Test
- public void testGetOperationalEnvSuccess() throws ParseException {
- InfraActiveRequests iar = new InfraActiveRequests();
- iar.setRequestId("requestId");
- iar.setRequestScope("requestScope");
- iar.setRequestType("requestType");
- iar.setOperationalEnvId("operationalEnvironmentId");
- iar.setOperationalEnvName("operationalEnvName");
- iar.setRequestorId("ma920e");
- iar.setRequestBody("");
- iar.setRequestStatus("COMPLETE");
-
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateFormat.parse("23/09/2007");
- long time = date.getTime();
- iar.setStartTime(new Timestamp(time));
-
- ResteasyUriInfo uriInfo = new ResteasyUriInfo("", "requestId=89c56827-1c78-4827-bc4d-6afcdb37a51f", "");
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- cor.setRequestsDB(reqDB);
- when(reqDB.getRequestFromInfraActive("89c56827-1c78-4827-bc4d-6afcdb37a51f")).thenReturn(iar);
-
- Response response = cor.getOperationEnvironmentStatusFilter(uriInfo, null);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testGetOperationalEnvFilterSuccess() throws ParseException {
- InfraActiveRequests iar = new InfraActiveRequests();
- iar.setRequestId("requestId");
- iar.setRequestScope("requestScope");
- iar.setRequestType("requestType");
- iar.setOperationalEnvId("operationalEnvironmentId");
- iar.setOperationalEnvName("operationalEnvName");
- iar.setRequestorId("ma920e");
- iar.setRequestBody("");
- iar.setRequestStatus("COMPLETE");
- iar.setStatusMessage("status Message");
- iar.setProgress(20L);
-
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateFormat.parse("23/09/2007");
- long time = date.getTime();
- iar.setStartTime(new Timestamp(time));
- iar.setEndTime(new Timestamp(time));
-
- List<InfraActiveRequests> requests = new ArrayList<>();
- requests.add(iar);
-
- Map<String, String> map = new HashMap<>();
- map.put("operationalEnvironmentName", "myVnfOpEnv");
-
- ResteasyUriInfo uriInfo = new ResteasyUriInfo("", "operationalEnvironmentName=myVnfOpEnv&requestorId=test", "");
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- cor.setRequestsDB(reqDB);
- when(reqDB.getCloudOrchestrationFiltersFromInfraActive(map)).thenReturn(requests);
-
- Response response = cor.getOperationEnvironmentStatusFilter(uriInfo, null);
- assertEquals(200, response.getStatus());
- }
-
- @Ignore // 1802 merge - @Test
- public void testGetOperationalEnvFilterException1() throws ParseException {
- InfraActiveRequests iar = new InfraActiveRequests();
- iar.setRequestId("requestId");
- iar.setRequestScope("requestScope");
- iar.setRequestType("requestType");
- iar.setOperationalEnvId("operationalEnvironmentId");
- iar.setOperationalEnvName("operationalEnvName");
- iar.setRequestorId("ma920e");
- iar.setRequestBody("");
- iar.setRequestStatus("COMPLETE");
-
- List<InfraActiveRequests> requests = new ArrayList<>();
- requests.add(iar);
-
- Map<String, String> map = new HashMap<>();
- map.put("operationalEnvironmentName", "myVnfOpEnv");
-
- ResteasyUriInfo uriInfo = new ResteasyUriInfo("", "filter=operationalEnvironmentName:EQUALS:myVnfOpEnv", "");
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- cor.setRequestsDB(reqDB);
- when(reqDB.getCloudOrchestrationFiltersFromInfraActive(map)).thenReturn(requests);
-
- Response response = cor.getOperationEnvironmentStatusFilter(uriInfo, null);
- assertEquals(500, response.getStatus());
- }
-
- @Test
- public void testGetOperationalEnvFilterException2() throws ParseException {
- InfraActiveRequests iar = new InfraActiveRequests();
- iar.setRequestId("requestId");
- iar.setRequestScope("requestScope");
- iar.setRequestType("requestType");
- iar.setOperationalEnvId("operationalEnvId");
- iar.setOperationalEnvName("operationalEnvName");
- iar.setRequestorId("ma920e");
- iar.setRequestBody("");
- iar.setRequestStatus("COMPLETE");
-
- List<InfraActiveRequests> requests = new ArrayList<>();
- requests.add(iar);
-
- Map<String, String> map = new HashMap<>();
- map.put("operationalEnvironmentName", "myVnfOpEnv");
-
- ResteasyUriInfo uriInfo = new ResteasyUriInfo("", "operationalEnvironmentName=", "");
- CloudResourcesOrchestration cor = new CloudResourcesOrchestration();
- RequestsDatabase reqDB = mock(RequestsDatabase.class);
- cor.setRequestsDB(reqDB);
- when(reqDB.getCloudOrchestrationFiltersFromInfraActive(map)).thenReturn(requests);
-
- Response response = cor.getOperationEnvironmentStatusFilter(uriInfo, null);
- assertEquals(500, response.getStatus());
- assertTrue(response.getEntity().toString().contains("No valid operationalEnvironmentName value is specified"));
- }
-}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java deleted file mode 100644 index c02557314d..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-
-import javax.ws.rs.core.Response;
-
-import org.apache.http.HttpStatus;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class ModelDistributionRequestTest {
-
- private static final String requestJSON = "{\"status\": \"DISTRIBUTION_COMPLETE_ERROR\", \"errorReason\": \"Distribution failed in AAI\" }";
-
- @Test
- public void testUpdateModelDistributionStatus() {
- final Response okResponse = Response.status(HttpStatus.SC_OK).build();
-
- try {
- ModelDistributionRequest mdr = Mockito.mock(ModelDistributionRequest.class);
- Mockito.when(mdr.updateModelDistributionStatus(requestJSON, "v1", "ff3514e3-5a33-55df-13ab-12abad84e7ff")).thenReturn(okResponse);
- Response resp = mdr.updateModelDistributionStatus(requestJSON, "v1", "ff3514e3-5a33-55df-13ab-12abad84e7ff");
- assertEquals(resp.getStatus(), HttpStatus.SC_OK);
- } catch (Exception e) {
- fail("Exception caught: " + e.getMessage());
- }
- }
-
- @Test
- public void testObjectMapperError() {
- ModelDistributionRequest request = new ModelDistributionRequest();
- Response response = request.updateModelDistributionStatus(null, null, null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Mapping of request to JSON object failed."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testParseError1() {
- String requestErrorJSON = "{\"errorReason\": \"Distribution failed in AAI\" }";
-
- ModelDistributionRequest request = new ModelDistributionRequest();
- Response response = request.updateModelDistributionStatus(requestErrorJSON, null, null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Error parsing request."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testParseError2() {
- String requestErrorJSON = "{\"status\": \"DISTRIBUTION_COMPLETE_ERROR\"}";
-
- ModelDistributionRequest request = new ModelDistributionRequest();
- Response response = request.updateModelDistributionStatus(requestErrorJSON, null, null);
- String body = response.getEntity().toString();
- assertTrue(body.contains("Error parsing request."));
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void testSuccess() {
- ModelDistributionRequest request = new ModelDistributionRequest();
- TenantIsolationRunnable thread = mock(TenantIsolationRunnable.class);
- request.setThread(thread);
-
- Response response = request.updateModelDistributionStatus(requestJSON, null, null);
-
- assertEquals(200, response.getStatus());
- }
-}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/TenantIsolationRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/TenantIsolationRequestTest.java deleted file mode 100644 index d2d7959622..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/TenantIsolationRequestTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import java.util.HashMap; - -import org.apache.commons.io.IOUtils; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; -import org.openecomp.mso.apihandler.common.ValidationException; -import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest; -import org.openecomp.mso.apihandlerinfra.tenantisolation.TenantIsolationRequest; -import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.Action; - -public class TenantIsolationRequestTest { - - @Test - public void testParseCloudResourceECOMP() throws Exception{ - try { - String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/ECOMPOperationEnvironmentCreate.json")); - ObjectMapper mapper = new ObjectMapper(); - HashMap<String, String> instanceIdMap = new HashMap<String,String>(); - CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class); - TenantIsolationRequest request = new TenantIsolationRequest ("1234"); - request.parse(cor, instanceIdMap, Action.create); - assertNotNull(request.getRequestId()); - } catch(ValidationException e) { - fail(e.getMessage()); - } - } - - @Test - public void testParseCloudResourceVNF() throws Exception{ - try { - String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/VNFOperationEnvironmentCreate.json")); - ObjectMapper mapper = new ObjectMapper(); - HashMap<String, String> instanceIdMap = new HashMap<String,String>(); - CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class); - TenantIsolationRequest request = new TenantIsolationRequest ("1234"); - request.parse(cor, instanceIdMap, Action.create); - assertNotNull(request.getRequestId()); - } catch(ValidationException e) { - fail(e.getMessage()); - } - } - - @Test(expected=ValidationException.class) - public void testParseCloudResourceVNFInvalid() throws Exception { - String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/VNFOperationEnvironmentCreateInvalid.json")); - ObjectMapper mapper = new ObjectMapper(); - HashMap<String, String> instanceIdMap = new HashMap<String,String>(); - CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class); - TenantIsolationRequest request = new TenantIsolationRequest ("1234"); - request.parse(cor, instanceIdMap, Action.create); - assertNotNull(request.getRequestId()); - } - - @Test - public void testParseActivateCloudResource() throws Exception{ - try { - String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/ActivateOperationEnvironment.json")); - ObjectMapper mapper = new ObjectMapper(); - HashMap<String, String> instanceIdMap = new HashMap<String,String>(); - CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class); - TenantIsolationRequest request = new TenantIsolationRequest ("1234"); - request.parse(cor, instanceIdMap, Action.activate); - assertNotNull(request.getRequestId()); - } catch(ValidationException e) { - fail(e.getMessage()); - } - } - - @Test(expected = ValidationException.class) - public void testParseActivateCloudResourceInvalid() throws Exception{ - String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/ActivateOperationEnvironmentInvalid.json")); - ObjectMapper mapper = new ObjectMapper(); - HashMap<String, String> instanceIdMap = new HashMap<String,String>(); - CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class); - TenantIsolationRequest request = new TenantIsolationRequest ("1234"); - request.parse(cor, instanceIdMap, Action.activate); - assertNotNull(request.getRequestId()); - } - - @Test - public void testParseDeactivateCloudResource() throws Exception{ - try { - String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/DeactivateOperationEnvironment.json")); - ObjectMapper mapper = new ObjectMapper(); - HashMap<String, String> instanceIdMap = new HashMap<String,String>(); - CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class); - TenantIsolationRequest request = new TenantIsolationRequest ("1234"); - request.parse(cor, instanceIdMap, Action.deactivate); - assertNotNull(request.getRequestId()); - } catch(ValidationException e) { - fail(e.getMessage()); - } - } - - @Test(expected= ValidationException.class) - public void testParseDeactivateCloudResourceInvalid() throws Exception{ - String requestJSON = IOUtils.toString (ClassLoader.class.getResourceAsStream ("/DeactivateOperationEnvironmentInvalid.json")); - ObjectMapper mapper = new ObjectMapper(); - HashMap<String, String> instanceIdMap = new HashMap<String,String>(); - CloudOrchestrationRequest cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class); - TenantIsolationRequest request = new TenantIsolationRequest ("1234"); - request.parse(cor, instanceIdMap, Action.deactivate); - assertNotNull(request.getRequestId()); - } -}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/dmaap/AsdcDmaapClientTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/dmaap/AsdcDmaapClientTest.java deleted file mode 100644 index f62b360071..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/dmaap/AsdcDmaapClientTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.dmaap; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.text.ParseException; - -import org.junit.Test; -import org.openecomp.mso.apihandlerinfra.tenantisolation.dmaap.CreateEcompOperationEnvironmentBean; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class AsdcDmaapClientTest { - - private final String fileLocation = "src/test/resources/org/openecomp/mso/client/asdc/create-ecompoe/"; - - private static final String operationalEnvironmentId = "28122015552391"; - private static final String operationalEnvironmentName = "Operational Environment Name"; - private static final String operationalEnvironmentType = "ECOMP"; - private static final String tenantContext = "TEST"; - private static final String workloadContext = "ECOMP_E2E-IST"; - private static final String action = "Create" ; - - - - @Test - public void verifyasdcCreateoeRequest() throws IOException, ParseException{ - - ObjectMapper mapper = new ObjectMapper(); - - String expected = "{\"operationalEnvironmentId\":\"28122015552391\",\"operationalEnvironmentName\":\"Operational Environment Name\",\"operationalEnvironmentType\":\"ECOMP\",\"tenantContext\":\"TEST\",\"workloadContext\":\"ECOMP_E2E-IST\",\"action\":\"Create\"}"; - - - CreateEcompOperationEnvironmentBean cBean = new CreateEcompOperationEnvironmentBean(); - cBean.setOperationalEnvironmentId(operationalEnvironmentId); - cBean.setoperationalEnvironmentName(operationalEnvironmentName); - cBean.setoperationalEnvironmentType(operationalEnvironmentType); - cBean.settenantContext(tenantContext); - cBean.setworkloadContext(workloadContext); - cBean.setaction(action); - - String actual = mapper.writeValueAsString(cBean); - - assertEquals("payloads are equal", expected, actual); - } - - - -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/dmaap/DmaapOperationalEnvClientTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/dmaap/DmaapOperationalEnvClientTest.java deleted file mode 100644 index 539b1816bd..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/dmaap/DmaapOperationalEnvClientTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.dmaap; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.spy; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.text.ParseException; - -import org.junit.Test; -import org.openecomp.mso.apihandlerinfra.tenantisolation.dmaap.CreateEcompOperationEnvironmentBean; -import org.openecomp.mso.apihandlerinfra.tenantisolation.dmaap.DmaapOperationalEnvClient; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class DmaapOperationalEnvClientTest { - - private final String fileLocation = "src/test/resources/org/openecomp/mso/client/asdc/create-ecompoe/"; - private static final String operationalEnvironmentId = "28122015552391"; - private static final String operationalEnvironmentName = "OpEnv-name"; - private static final String operationalEnvironmentType = "VNF"; - private static final String tenantContext = "Test"; - private static final String workloadContext = "VNF_E2E-IST"; - private static final String action = "Create"; - - - @Test - public void verifyCreateEcompOperationEnvironmentRequest() throws IOException, ParseException{ - String content = this.getJson("ecomp-openv-request.json"); - ObjectMapper mapper = new ObjectMapper(); - CreateEcompOperationEnvironmentBean expected = mapper.readValue(content, CreateEcompOperationEnvironmentBean.class); - DmaapOperationalEnvClient client = new DmaapOperationalEnvClient(); - DmaapOperationalEnvClient spy = spy(client); - - String actual = spy.buildRequest(operationalEnvironmentId, operationalEnvironmentName, operationalEnvironmentType, - tenantContext, workloadContext, action); - - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - } - - - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); - } - -} - diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/dmaap/OperationalEnvironmentPublisherTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/dmaap/OperationalEnvironmentPublisherTest.java deleted file mode 100644 index a9763f1d39..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/dmaap/OperationalEnvironmentPublisherTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.dmaap; - -import static org.junit.Assert.assertEquals; - -import java.io.FileNotFoundException; -import java.io.IOException; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.openecomp.mso.apihandlerinfra.tenantisolation.dmaap.OperationalEnvironmentPublisher; -import org.openecomp.mso.properties.MsoJavaProperties; -import org.openecomp.mso.properties.MsoPropertiesException; -import org.openecomp.mso.properties.MsoPropertiesFactory; - -public class OperationalEnvironmentPublisherTest { - - private static final String APIH_INFRA_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.apihandler-infra.properties").toString().substring(5); - - @BeforeClass - public static void setUp() throws MsoPropertiesException { - MsoPropertiesFactory propertiesFactory = new MsoPropertiesFactory(); - propertiesFactory.removeAllMsoProperties(); - propertiesFactory.initializeMsoProperties("MSO_PROP_APIHANDLER_INFRA", APIH_INFRA_PROP); - } - - @Test - public void getProperties() throws FileNotFoundException, IOException { - OperationalEnvironmentPublisher publisher = new OperationalEnvironmentPublisher(); - - assertEquals("m97898@mso.ecomp.att.com", publisher.getUserName()); - assertEquals("VjR5NDcxSzA=", publisher.getPassword()); - assertEquals("com.att.ecomp.mso.operationalEnvironmentEvent", publisher.getTopic()); - assertEquals("https://dcae-mrtr-ftl3.ecomp.cci.att.com:3905", publisher.getHost().get()); - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientHelperTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientHelperTest.java deleted file mode 100644 index 3b8bf3f19e..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientHelperTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.helpers; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.doThrow; - - -import org.openecomp.mso.apihandlerinfra.tenantisolation.exceptions.AAIClientCallFailed; -import org.openecomp.mso.apihandlerinfra.tenantisolation.mock.MockTest; -import org.openecomp.mso.client.aai.AAIResourcesClient; -import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; -import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment; - - -public class AAIClientHelperTest extends MockTest { - - @Mock private AAIResourcesClient aaiResourceClientMock; - private AAIClientHelper clientHelper; - - @Before - public void testSetUp() { - MockitoAnnotations.initMocks(this); - AAIClientHelper aaiHelper = new AAIClientHelper(); - clientHelper = spy(aaiHelper); - when(clientHelper.getClient()).thenReturn(aaiResourceClientMock); - } - - @Test - public void testGetAaiOperationalEnvironmentSuccess() throws Exception { - clientHelper.getAaiOperationalEnvironment("123"); - verify(aaiResourceClientMock, times(1)).get(any(AAIResourceUri.class)); - } - - @Test(expected = AAIClientCallFailed.class) - public void testGetAaiOperationalEnvironmentRainyDay() throws Exception { - when(aaiResourceClientMock.get(any(AAIResourceUri.class))).thenThrow(new RuntimeException()); - clientHelper.getAaiOperationalEnvironment("123"); - } - - @Test - public void testCreateOperationalEnvironmentSuccess() throws Exception { - AAIOperationalEnvironment env = AAIClientObjectBuilder.createAAIOperationalEnvironment("123", "Test Env", "ECOMP", "ACTIVE", "Test", "PVT"); - clientHelper.createOperationalEnvironment(env); - verify(aaiResourceClientMock, times(1)).create(any(AAIResourceUri.class), eq(env)); - } - - @Test(expected = AAIClientCallFailed.class) - public void testCreateOperationalEnvironmentRainyDay() throws Exception { - AAIOperationalEnvironment env = AAIClientObjectBuilder.createAAIOperationalEnvironment("123", "Test Env", "ECOMP", "ACTIVE", "Test", "PVT"); - doThrow(RuntimeException.class).when(aaiResourceClientMock).create(any(AAIResourceUri.class), eq(env)); - clientHelper.createOperationalEnvironment(env); - } - - @Test - public void testCreateRelationshipSuccess() throws Exception { - clientHelper.createRelationship("VOE-001", "MEOE-002"); - verify(aaiResourceClientMock, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); - } - - @Test(expected = AAIClientCallFailed.class) - public void testCreateRelationshipRainyDay() throws Exception { - doThrow(RuntimeException.class).when(aaiResourceClientMock).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); - clientHelper.createRelationship("VOE-001", "MEOE-002"); - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientObjectBuilderTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientObjectBuilderTest.java deleted file mode 100644 index 12312764c3..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientObjectBuilderTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.helpers; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; -import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest; -import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.OperationalEnvironment; -import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.RequestDetails; -import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.RequestInfo; -import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.RequestParameters; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class AAIClientObjectBuilderTest { - - private String expectedAAIObject = "{\"operational-environment-name\":\"TEST_ECOMP_ENVIRONMENT\",\"operational-environment-type\":\"ECOMP\",\"operational-environment-status\":\"Active\",\"tenant-context\":\"TEST\",\"workload-context\":\"ECOMP_TEST\"}"; - private CloudOrchestrationRequest request; - private ObjectMapper mapper = new ObjectMapper(); - - @Before - public void testSetUp() { - request = getCloudOrchestrationRequest(); - } - - public CloudOrchestrationRequest getCloudOrchestrationRequest() { - CloudOrchestrationRequest cor = new CloudOrchestrationRequest(); - RequestDetails reqDetails = new RequestDetails(); - RequestInfo reqInfo = new RequestInfo(); - RequestParameters reqParams = new RequestParameters(); - reqParams.setTenantContext("TEST"); - reqParams.setWorkloadContext("ECOMP_TEST"); - reqParams.setOperationalEnvironmentType(OperationalEnvironment.ECOMP); - reqInfo.setInstanceName("TEST_ECOMP_ENVIRONMENT"); - reqDetails.setRequestInfo(reqInfo); - reqDetails.setRequestParameters(reqParams); - cor.setRequestDetails(reqDetails); - return cor; - } - - @Test - public void testGetAaiClientObjectBuilder() throws Exception { - AAIClientObjectBuilder builder = new AAIClientObjectBuilder(request); - assertEquals(expectedAAIObject, mapper.writeValueAsString(builder.buildAAIOperationalEnvironment("Active"))); - } - - -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AsdcClientHelperTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AsdcClientHelperTest.java deleted file mode 100644 index fbeb448227..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AsdcClientHelperTest.java +++ /dev/null @@ -1,209 +0,0 @@ -/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.apihandlerinfra.tenantisolation.helpers;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.LinkedHashMap;
-import java.util.List;
-
-import org.json.JSONObject;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.openecomp.mso.apihandlerinfra.Constants;
-import org.openecomp.mso.apihandlerinfra.MsoPropertiesUtils;
-import org.openecomp.mso.properties.MsoJavaProperties;
-import org.openecomp.mso.properties.MsoPropertiesFactory;
-import org.openecomp.mso.rest.RESTClient;
-import org.openecomp.mso.rest.RESTConfig;
-
-import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-
-public class AsdcClientHelperTest {
-
- MsoJavaProperties properties = MsoPropertiesUtils.loadMsoProperties();
- AsdcClientHelper asdcClientUtils = new AsdcClientHelper(properties);
-
- String serviceModelVersionId = "TEST_uuid1";
- String operationalEnvironmentId = "TEST_operationalEnvironmentId";
- String workloadContext = "TEST_workloadContext";
-
- @Rule
- public final WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.wireMockConfig().port(28090)); //.extensions(transformerArray));
-
- @BeforeClass
- public static void setUp() throws Exception {
- MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
- msoPropertiesFactory.removeAllMsoProperties();
- msoPropertiesFactory.initializeMsoProperties(Constants.MSO_PROP_APIHANDLER_INFRA, "src/test/resources/mso.apihandler-infra.properties");
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
- @Test
- public void getPropertiesTest() {
-
- String asdcInstanceId = asdcClientUtils.getAsdcInstanceId();
- Assert.assertEquals("Asdc InstanceId - " , "test", asdcInstanceId);
-
- String asdcEndpoint = asdcClientUtils.getAsdcEndpoint();
- Assert.assertEquals("Asdc Endpoint - " , "http://localhost:28090", asdcEndpoint);
-
- String userid = asdcClientUtils.getAsdcUserId();
- Assert.assertEquals("userid - " , "cs0008", userid);
-
- }
-
- @Test
- public void buildUriBuilderTest() {
-
- try {
- String url = asdcClientUtils.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId);
- assertEquals("http://localhost:28090/sdc/v1/catalog/services/TEST_uuid1/distribution/TEST_operationalEnvironmentId/activate", url);
-
- } catch (Exception e) {
- fail("Exception caught: " + e.getMessage());
-
- }
- }
-
- @Test
- public void buildJsonWorkloadContextTest() {
-
- try {
- String jsonPayload = asdcClientUtils.buildJsonWorkloadContext(workloadContext);
- assertEquals("{\"workloadContext\":\"TEST_workloadContext\"}", jsonPayload);
-
- } catch (Exception e) {
- fail("Exception caught: " + e.getMessage());
-
- }
- }
-
- @Test
- public void setRestClientTest() {
-
- try {
- String url = asdcClientUtils.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId);
- RESTConfig config = new RESTConfig(url);
- RESTClient client = asdcClientUtils.setRestClient(config);
- LinkedHashMap<String, List<String>> headers = client.getHeaders();
- assertEquals("[cs0008]", headers.get("USER_ID").toString());
-
- } catch (Exception e) {
- fail("Exception caught: " + e.getMessage());
-
- }
- }
-
- @Test
- public void enhanceJsonResponseTest_Success() {
-
- try {
- // build success response data
- JSONObject asdcResponseJsonObj = new JSONObject();
- asdcResponseJsonObj.put("distributionId", "TEST_distributionId");
-
- int statusCode = 202;
- asdcResponseJsonObj = asdcClientUtils.enhanceJsonResponse(asdcResponseJsonObj, statusCode);
-
- assertEquals("202", asdcResponseJsonObj.getString("statusCode"));
- assertEquals("", asdcResponseJsonObj.getString("messageId"));
- assertEquals("Success", asdcResponseJsonObj.getString("message"));
- assertEquals("TEST_distributionId", asdcResponseJsonObj.getString("distributionId"));
-
- } catch (Exception e) {
- fail("Exception caught: " + e.getMessage());
-
- }
- }
-
- @Test
- public void enhanceJsonResponseTest_Error() {
-
- try {
-
- // build error response data
- JSONObject jsonMessages = new JSONObject();
- jsonMessages.put("messageId", "SVC4675");
- jsonMessages.put("text", "Error: Service state is invalid for this action.");
- JSONObject jsonServException = new JSONObject();
- jsonServException.put("serviceException", jsonMessages);
- JSONObject jsonErrorRequest = new JSONObject();
- jsonErrorRequest.put("requestError", jsonServException);
-
- String responseData = jsonErrorRequest.toString();
-
- JSONObject asdcResponseJsonObj = new JSONObject(responseData);
- int statusCode = 409;
- asdcResponseJsonObj = asdcClientUtils.enhanceJsonResponse(asdcResponseJsonObj, statusCode);
-
- assertEquals("409", asdcResponseJsonObj.getString("statusCode"));
- assertEquals("SVC4675", asdcResponseJsonObj.getString("messageId"));
- assertEquals("Error: Service state is invalid for this action.", asdcResponseJsonObj.getString("message"));
-
-
- } catch (Exception e) {
- fail("Exception caught: " + e.getMessage());
-
- }
- }
-
- @Test
- public void enhanceJsonResponseTest_Error_policyException() {
-
- try {
-
- // build error response data
- JSONObject jsonMessages = new JSONObject();
- jsonMessages.put("messageId", "POL5003");
- jsonMessages.put("text", "Error: Not authorized to use the API.");
- JSONObject jsonServException = new JSONObject();
- jsonServException.put("policyException", jsonMessages);
- JSONObject jsonErrorRequest = new JSONObject();
- jsonErrorRequest.put("requestError", jsonServException);
-
- String responseData = jsonErrorRequest.toString();
-
- JSONObject asdcResponseJsonObj = new JSONObject(responseData);
- int statusCode = 403;
- asdcResponseJsonObj = asdcClientUtils.enhanceJsonResponse(asdcResponseJsonObj, statusCode);
-
- assertEquals("403", asdcResponseJsonObj.getString("statusCode"));
- assertEquals("POL5003", asdcResponseJsonObj.getString("messageId"));
- assertEquals("Error: Not authorized to use the API.", asdcResponseJsonObj.getString("message"));
-
-
- } catch (Exception e) {
- fail("Exception caught: " + e.getMessage());
-
- }
- }
-
-}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/mock/AaiStubResponse.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/mock/AaiStubResponse.java deleted file mode 100644 index b89da737f7..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/mock/AaiStubResponse.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.mock; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; - -import javax.ws.rs.core.MediaType; - -public class AaiStubResponse { - - public static String DEFAULT_ERROR_RESPONSE = "{ \"requestError\":{ \"serviceException\" : {\"messageId\": \"500\",\"text\": \"Test error message!\"}}}"; - - public static void setupAllMocks() {} - - public static void MockGetRequest(String link, int returnCode, String response) { - stubFor(get(urlPathEqualTo(link)) - .willReturn(aResponse() - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withHeader("Accept", MediaType.APPLICATION_JSON) - .withStatus(returnCode) - .withBody(response))); - } - - public static void MockPutRequest(String link, int returnCode, String response) { - stubFor(put(urlPathEqualTo(link)) - .willReturn(aResponse() - .withStatus(returnCode) - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withBody(response))); - } - - public static void MockPostRequest(String link, int returnCode) { - stubFor(post(urlPathEqualTo(link)) - .willReturn(aResponse() - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withHeader("X-HTTP-Method-Override", "PATCH") - .withStatus(returnCode))); - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/mock/MockTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/mock/MockTest.java deleted file mode 100644 index 36cab4fa61..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/mock/MockTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.mock; - -import java.io.File; -import java.nio.file.Files; - -import org.junit.BeforeClass; -import org.junit.Rule; -import org.openecomp.mso.apihandlerinfra.Constants; -import org.openecomp.mso.properties.MsoPropertiesFactory; - -import com.github.tomakehurst.wiremock.core.WireMockConfiguration; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class MockTest { - - @Rule - public final WireMockRule wireMockRule; - - public MockTest() { - wireMockRule = new WireMockRule(WireMockConfiguration.wireMockConfig().port(28090)); //.extensions(transformerArray)); - } - - @BeforeClass - public static void setUp() throws Exception { - MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - msoPropertiesFactory.removeAllMsoProperties(); - msoPropertiesFactory.initializeMsoProperties(Constants.MSO_PROP_APIHANDLER_INFRA, "src/test/resources/mso.apihandler-infra.properties"); - } - - public String getFileContentsAsString(String fileName) { - - String content = ""; - try { - ClassLoader classLoader = this.getClass().getClassLoader(); - File file = new File(classLoader.getResource(fileName).getFile()); - content = new String(Files.readAllBytes(file.toPath())); - } - catch(Exception e) { - e.printStackTrace(); - System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage() + ". Make sure to specify the correct path."); - } - return content; - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironmentTest.java deleted file mode 100644 index 49fea2a8d9..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironmentTest.java +++ /dev/null @@ -1,249 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.process;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.json.JSONObject;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.openecomp.mso.apihandlerinfra.Constants;
-import org.openecomp.mso.apihandlerinfra.MsoPropertiesUtils;
-import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
-import org.openecomp.mso.apihandlerinfra.tenantisolation.helpers.AAIClientHelper;
-import org.openecomp.mso.apihandlerinfra.tenantisolation.helpers.AsdcClientHelper;
-import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.Manifest;
-import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.RecoveryAction;
-import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.RequestDetails;
-import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.RequestParameters;
-import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.ServiceModelList;
-import org.openecomp.mso.client.aai.entities.AAIResultWrapper;
-import org.openecomp.mso.properties.MsoJavaProperties;
-import org.openecomp.mso.properties.MsoPropertiesFactory;
-import org.openecomp.mso.requestsdb.OperationalEnvDistributionStatusDb;
-import org.openecomp.mso.requestsdb.OperationalEnvServiceModelStatusDb;
-import org.openecomp.mso.requestsdb.RequestsDBHelper;
-import org.openecomp.mso.rest.APIResponse;
-import org.openecomp.mso.rest.RESTClient;
-import org.openecomp.mso.rest.RESTConfig;
-
-public class ActivateVnfOperationalEnvironmentTest {
-
- MsoJavaProperties properties = MsoPropertiesUtils.loadMsoProperties();
- AsdcClientHelper asdcClientUtils = new AsdcClientHelper(properties);
-
- String requestId = "TEST_requestId";
- String operationalEnvironmentId = "TEST_operationalEnvironmentId";
- CloudOrchestrationRequest request = new CloudOrchestrationRequest();
- String workloadContext = "TEST_workloadContext";
- String recoveryAction = "RETRY";
- String serviceModelVersionId = "TEST_serviceModelVersionId";
- int retryCount = 3;
- String distributionId = "TEST_distributionId";
-
- @BeforeClass
- public static void setUp() throws Exception {
- MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
- msoPropertiesFactory.removeAllMsoProperties();
- msoPropertiesFactory.initializeMsoProperties(Constants.MSO_PROP_APIHANDLER_INFRA, "src/test/resources/mso.apihandler-infra.properties");
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
- @Test
- public void getAAIClientHelperTest() throws Exception {
-
- request.setOperationalEnvironmentId(operationalEnvironmentId);
- ActivateVnfOperationalEnvironment activateVnf = new ActivateVnfOperationalEnvironment(request, requestId);
- AAIClientHelper aaiHelper = activateVnf.getAaiHelper();
-
- Assert.assertNotNull(aaiHelper);
-
- }
-
- @Test
- public void getAAIOperationalEnvironmentTest() throws Exception {
-
- // prepare return data
- JSONObject aaiJsonResponse = new JSONObject();
- aaiJsonResponse.put("operational-environment-id", "testASDCDistributionId");
- aaiJsonResponse.put("operational-environment-name", "testASDCDistributionIName");
- aaiJsonResponse.put("operational-environment-type", "VNF");
- aaiJsonResponse.put("operational-environment-status", "ACTIVE");
- aaiJsonResponse.put("tenant-context", "Test");
- aaiJsonResponse.put("workload-context", "PVT");
- aaiJsonResponse.put("resource-version", "1505228226913");
- String mockGetResponseJson = aaiJsonResponse.toString();
-
- AAIResultWrapper aaiREsultWrapperObj = new AAIResultWrapper(mockGetResponseJson);
-
- request.setOperationalEnvironmentId(operationalEnvironmentId);
- AAIClientHelper aaiClientHelperMock = Mockito.mock(AAIClientHelper.class);
-
- ActivateVnfOperationalEnvironment activateVnfMock = Mockito.mock(ActivateVnfOperationalEnvironment.class);
- ActivateVnfOperationalEnvironment activateVnf = new ActivateVnfOperationalEnvironment(request, requestId);
-
- Mockito.when(aaiClientHelperMock.getAaiOperationalEnvironment(operationalEnvironmentId)).thenReturn(aaiREsultWrapperObj);
-
- activateVnfMock = spy(activateVnf);
- activateVnfMock.setAaiHelper(aaiClientHelperMock);
- activateVnfMock.getAAIOperationalEnvironment(operationalEnvironmentId);
-
- verify(activateVnfMock, times(1)).getAaiHelper();
- verify(aaiClientHelperMock, times(1)).getAaiOperationalEnvironment( any(String.class) );
-
- }
-
- @Test
- public void processActivateASDCRequestTest() throws Exception {
-
- String jsonPayload = asdcClientUtils.buildJsonWorkloadContext(workloadContext);
- String distributionId = "TEST_distributionId";
-
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("statusCode", "202");
- jsonObject.put("message", "Success");
- jsonObject.put("distributionId", distributionId);
-
- List<ServiceModelList> serviceModelVersionIdList = new ArrayList<ServiceModelList>();
- ServiceModelList serviceModelList1 = new ServiceModelList();
- serviceModelList1.setRecoveryAction(RecoveryAction.retry);
- serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
- serviceModelVersionIdList.add(serviceModelList1);
-
- ActivateVnfOperationalEnvironment activate = new ActivateVnfOperationalEnvironment(request, requestId);
- ActivateVnfOperationalEnvironment activateVnfMock = spy(activate);
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- AsdcClientHelper asdcClientHelperMock = Mockito.mock(AsdcClientHelper.class);
- RESTConfig configMock = Mockito.mock(RESTConfig.class);
- RESTClient clientMock = Mockito.mock(RESTClient.class);
- APIResponse apiResponseMock = Mockito.mock(APIResponse.class);
-
- activateVnfMock.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfMock.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfMock.setAsdcClientHelper(asdcClientHelperMock);
-
- Mockito.when(asdcClientHelperMock.setRestClient(configMock)).thenReturn(clientMock);
- Mockito.when(asdcClientHelperMock.setHttpPostResponse(clientMock, jsonPayload)).thenReturn(apiResponseMock);
- Mockito.when(asdcClientHelperMock.enhanceJsonResponse(jsonObject, 202)).thenReturn(jsonObject);
- Mockito.when(asdcClientHelperMock.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext)).thenReturn(jsonObject);
-
- activateVnfMock.processActivateASDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext);
-
- verify(serviceModelDb, times(1)).insertOperationalEnvServiceModelStatus(requestId, operationalEnvironmentId, serviceModelVersionId, "SENT", "RETRY", retryCount, workloadContext);
-
- }
-
- @Test
- public void executionTest() throws Exception {
-
- // prepare request detail
- List<ServiceModelList> serviceModelVersionIdList = new ArrayList<ServiceModelList>();
- ServiceModelList serviceModelList1 = new ServiceModelList();
- serviceModelList1.setRecoveryAction(RecoveryAction.retry);
- serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
- serviceModelVersionIdList.add(serviceModelList1);
-
- RequestDetails requestDetails = new RequestDetails();
- RequestParameters requestParameters = new RequestParameters();
- Manifest manifest = new Manifest();
- manifest.setServiceModelList(serviceModelVersionIdList);
- requestParameters.setManifest(manifest);
- requestParameters.setWorkloadContext(workloadContext);
- requestDetails.setRequestParameters(requestParameters);
-
- // prepare aai return data
- JSONObject aaiJsonResponse = new JSONObject();
- aaiJsonResponse.put("operational-environment-id", "testASDCDistributionId");
- aaiJsonResponse.put("operational-environment-name", "testASDCDistributionIName");
- aaiJsonResponse.put("operational-environment-type", "VNF");
- aaiJsonResponse.put("operational-environment-status", "ACTIVE");
- aaiJsonResponse.put("tenant-context", "Test");
- aaiJsonResponse.put("workload-context", workloadContext);
- aaiJsonResponse.put("resource-version", "1505228226913");
- String mockGetResponseJson = aaiJsonResponse.toString();
- AAIResultWrapper aaiREsultWrapperObj = new AAIResultWrapper(mockGetResponseJson);
-
- // prepare asdc return data
- String jsonPayload = asdcClientUtils.buildJsonWorkloadContext(workloadContext);
-
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("statusCode", "202");
- jsonObject.put("message", "Success");
- jsonObject.put("distributionId", distributionId);
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
- AsdcClientHelper asdcClientHelperMock = Mockito.mock(AsdcClientHelper.class);
- RESTConfig configMock = Mockito.mock(RESTConfig.class);
- RESTClient clientMock = Mockito.mock(RESTClient.class);
- APIResponse apiResponseMock = Mockito.mock(APIResponse.class);
-
- Mockito.when(asdcClientHelperMock.setRestClient(configMock)).thenReturn(clientMock);
- Mockito.when(asdcClientHelperMock.setHttpPostResponse(clientMock, jsonPayload)).thenReturn(apiResponseMock);
- Mockito.when(asdcClientHelperMock.enhanceJsonResponse(jsonObject, 202)).thenReturn(jsonObject);
-
- AAIClientHelper aaiClientHelperMock = Mockito.mock(AAIClientHelper.class);
- Mockito.when(aaiClientHelperMock.getAaiOperationalEnvironment(operationalEnvironmentId)).thenReturn(aaiREsultWrapperObj);
- Mockito.when(asdcClientHelperMock.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext)).thenReturn(jsonObject);
-
- doNothing().when(serviceModelDb).insertOperationalEnvServiceModelStatus(requestId, operationalEnvironmentId, serviceModelVersionId, "SENT", recoveryAction, retryCount, workloadContext);
- doNothing().when(distributionDb).insertOperationalEnvDistributionStatus(distributionId, operationalEnvironmentId, serviceModelVersionId, "SENT", requestId);
-
- request.setOperationalEnvironmentId(operationalEnvironmentId);
- request.setRequestDetails(requestDetails);
- ActivateVnfOperationalEnvironment activate = new ActivateVnfOperationalEnvironment(request, requestId);
- ActivateVnfOperationalEnvironment activateVnfMock = spy(activate);
- activateVnfMock.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfMock.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfMock.setRequestsDBHelper(dbUtils);
- activateVnfMock.setAsdcClientHelper(asdcClientHelperMock);
- activateVnfMock.setAaiHelper(aaiClientHelperMock);
-
- activateVnfMock.execute();
-
- verify(serviceModelDb, times(1)).insertOperationalEnvServiceModelStatus(requestId, operationalEnvironmentId, serviceModelVersionId, "SENT", recoveryAction, retryCount, workloadContext);
- verify(distributionDb, times(1)).insertOperationalEnvDistributionStatus(distributionId, operationalEnvironmentId, serviceModelVersionId, "SENT", requestId);
-
-
- }
-
-
-}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java deleted file mode 100644 index 535d67e776..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java +++ /dev/null @@ -1,670 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.process;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.json.JSONObject;
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.junit.Ignore; -import org.junit.Test;
-import org.mockito.Mockito;
-import org.openecomp.mso.apihandlerinfra.Constants;
-import org.openecomp.mso.apihandlerinfra.MsoPropertiesUtils;
-import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
-import org.openecomp.mso.apihandlerinfra.tenantisolation.helpers.AsdcClientHelper;
-import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.Distribution;
-import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.DistributionStatus;
-import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.Status;
-import org.openecomp.mso.properties.MsoJavaProperties;
-import org.openecomp.mso.properties.MsoPropertiesFactory;
-import org.openecomp.mso.requestsdb.OperationalEnvDistributionStatus;
-import org.openecomp.mso.requestsdb.OperationalEnvDistributionStatusDb;
-import org.openecomp.mso.requestsdb.OperationalEnvServiceModelStatus;
-import org.openecomp.mso.requestsdb.OperationalEnvServiceModelStatusDb;
-import org.openecomp.mso.requestsdb.RequestsDBHelper;
-import org.openecomp.mso.rest.APIResponse;
-import org.openecomp.mso.rest.RESTClient;
-import org.openecomp.mso.rest.RESTConfig;
-
-public class ActivateVnfStatusOperationalEnvironmentTest {
-
- MsoJavaProperties properties = MsoPropertiesUtils.loadMsoProperties();
- AsdcClientHelper asdcClientUtils = new AsdcClientHelper(properties);
-
- String requestId = "TEST_requestId";
- String operationalEnvironmentId = "TEST_operationalEnvironmentId";
- CloudOrchestrationRequest request = new CloudOrchestrationRequest();
- String workloadContext = "TEST_workloadContext";
- String recoveryAction = "RETRY";
- String serviceModelVersionId = "TEST_serviceModelVersionId";
- int retryCount = 3;
- String asdcDistributionId = "TEST_distributionId";
-
- @BeforeClass
- public static void setUp() throws Exception {
- MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
- msoPropertiesFactory.removeAllMsoProperties();
- msoPropertiesFactory.initializeMsoProperties(Constants.MSO_PROP_APIHANDLER_INFRA, "src/test/resources/mso.apihandler-infra.properties");
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
-
- @Ignore // 1802 merge - @Test
- public void checkOrUpdateOverallStatusTest_Ok() throws Exception {
-
- int retryCount = 0;
-
- ActivateVnfStatusOperationalEnvironment activateVnfStatus = spy(new ActivateVnfStatusOperationalEnvironment(request, requestId));
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper requestDb = mock(RequestsDBHelper.class);
-
- // Prepare data
- OperationalEnvServiceModelStatus modelStatus = new OperationalEnvServiceModelStatus();
- modelStatus.setWorkloadContext(workloadContext);
- modelStatus.setRecoveryAction(recoveryAction);
- modelStatus.setOperationalEnvId(operationalEnvironmentId);
- modelStatus.setRetryCount(retryCount);
- modelStatus.setServiceModelVersionDistrStatus(DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString());
-
- OperationalEnvServiceModelStatus modelStatus1 = new OperationalEnvServiceModelStatus();
- modelStatus1.setWorkloadContext(workloadContext);
- modelStatus1.setRecoveryAction(recoveryAction);
- modelStatus1.setOperationalEnvId(operationalEnvironmentId);
- modelStatus1.setRetryCount(retryCount);
- modelStatus1.setServiceModelVersionDistrStatus(DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString());
-
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = new ArrayList<OperationalEnvServiceModelStatus>();
- queryServiceModelResponseList.add(modelStatus);
- queryServiceModelResponseList.add(modelStatus1);
-
- Mockito.when(serviceModelDb.getOperationalEnvIdStatus(operationalEnvironmentId, requestId)).thenReturn(queryServiceModelResponseList);
- doNothing().when(requestDb).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- activateVnfStatus.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfStatus.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfStatus.setRequestsDBHelper(requestDb);
- activateVnfStatus.checkOrUpdateOverallStatus(requestId, operationalEnvironmentId);
-
- verify(requestDb, times(0)).updateInfraFailureCompletion(any(String.class), any(String.class), any(String.class));
- verify(requestDb, times(1)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- }
-
- @Test
- public void checkOrUpdateOverallStatusTest_Error() throws Exception {
-
-
- int retryCount = 0; // no more retry
-
- ActivateVnfStatusOperationalEnvironment activateVnfStatus = spy(new ActivateVnfStatusOperationalEnvironment(request, requestId));
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper requestDb = mock(RequestsDBHelper.class);
-
- // Prepare data
- OperationalEnvServiceModelStatus modelStatus = new OperationalEnvServiceModelStatus();
- modelStatus.setWorkloadContext(workloadContext);
- modelStatus.setRecoveryAction(recoveryAction);
- modelStatus.setOperationalEnvId(operationalEnvironmentId);
- modelStatus.setRetryCount(retryCount);
- modelStatus.setServiceModelVersionDistrStatus(DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString());
-
- OperationalEnvServiceModelStatus modelStatus1 = new OperationalEnvServiceModelStatus();
- modelStatus1.setWorkloadContext(workloadContext);
- modelStatus1.setRecoveryAction(recoveryAction);
- modelStatus1.setOperationalEnvId(operationalEnvironmentId);
- modelStatus1.setRetryCount(retryCount);
- modelStatus1.setServiceModelVersionDistrStatus(DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString());
-
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = new ArrayList<OperationalEnvServiceModelStatus>();
- queryServiceModelResponseList.add(modelStatus);
- queryServiceModelResponseList.add(modelStatus1);
-
- Mockito.when(serviceModelDb.getOperationalEnvIdStatus(operationalEnvironmentId, requestId)).thenReturn(queryServiceModelResponseList);
- doNothing().when(requestDb).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- activateVnfStatus.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfStatus.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfStatus.setRequestsDBHelper(requestDb);
- activateVnfStatus.checkOrUpdateOverallStatus(requestId, operationalEnvironmentId);
-
- verify(requestDb, times(0)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
- verify(requestDb, times(1)).updateInfraFailureCompletion(any(String.class), any(String.class), any(String.class));
-
- }
-
- @Test
- public void checkOrUpdateOverallStatusTest_Waiting() throws Exception {
-
- int retryCount = 2; // 2 more retry
-
- ActivateVnfStatusOperationalEnvironment activateVnfStatus = spy(new ActivateVnfStatusOperationalEnvironment(request, requestId));
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper requestDb = mock(RequestsDBHelper.class);
-
- OperationalEnvServiceModelStatus modelStatus1 = spy(new OperationalEnvServiceModelStatus());
- modelStatus1.setWorkloadContext(workloadContext);
- modelStatus1.setRecoveryAction(recoveryAction);
- modelStatus1.setOperationalEnvId(operationalEnvironmentId);
- modelStatus1.setRetryCount(0);
- modelStatus1.setServiceModelVersionDistrStatus(DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString());
-
- OperationalEnvServiceModelStatus modelStatus2 = spy(new OperationalEnvServiceModelStatus());
- modelStatus2.setWorkloadContext(workloadContext);
- modelStatus2.setRecoveryAction(recoveryAction);
- modelStatus2.setOperationalEnvId(operationalEnvironmentId);
- modelStatus2.setRetryCount(retryCount);
- modelStatus2.setServiceModelVersionDistrStatus(DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString());
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = new ArrayList<OperationalEnvServiceModelStatus>();
- queryServiceModelResponseList.add(modelStatus1);
- queryServiceModelResponseList.add(modelStatus2);
-
- Mockito.when(serviceModelDb.getOperationalEnvIdStatus(operationalEnvironmentId, requestId)).thenReturn(queryServiceModelResponseList);
- doNothing().when(requestDb).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- activateVnfStatus.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfStatus.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfStatus.setRequestsDBHelper(requestDb);
- activateVnfStatus.checkOrUpdateOverallStatus(requestId, operationalEnvironmentId);
-
- verify(requestDb, times(0)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
- verify(requestDb, times(0)).updateInfraFailureCompletion(any(String.class), any(String.class), any(String.class));
-
- }
-
- @Test
- public void executionTest() throws Exception {
-
- // Prepare db query mock response data
- OperationalEnvDistributionStatus operEnvDistStatusObj = new OperationalEnvDistributionStatus();
- operEnvDistStatusObj.setServiceModelVersionId(serviceModelVersionId);
- operEnvDistStatusObj.setDistributionId(asdcDistributionId);
- operEnvDistStatusObj.setOperationalEnvId( operationalEnvironmentId);
- operEnvDistStatusObj.setDistributionIdStatus(DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString());
- operEnvDistStatusObj.setRequestId(requestId);
-
- // ServiceModelStatus - getOperationalEnvServiceModelStatus
- OperationalEnvServiceModelStatus operEnvServiceModelStatusObj = new OperationalEnvServiceModelStatus();
- operEnvServiceModelStatusObj.setRequestId(requestId);
- operEnvServiceModelStatusObj.setOperationalEnvId(operationalEnvironmentId);
- operEnvServiceModelStatusObj.setServiceModelVersionDistrStatus(DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString());
- operEnvServiceModelStatusObj.setRecoveryAction(recoveryAction);
- operEnvServiceModelStatusObj.setRetryCount(retryCount);
- operEnvServiceModelStatusObj.setWorkloadContext(workloadContext);
- operEnvServiceModelStatusObj.setServiceModelVersionId(serviceModelVersionId);
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = new ArrayList<OperationalEnvServiceModelStatus>();
- queryServiceModelResponseList.add(operEnvServiceModelStatusObj);
-
- // prepare distribution obj
- Distribution distribution = new Distribution();
- distribution.setStatus(Status.DISTRIBUTION_COMPLETE_OK);
- request.setDistribution(distribution);
- request.setDistributionId(asdcDistributionId);
-
- // prepare asdc return data
- String jsonPayload = asdcClientUtils.buildJsonWorkloadContext(workloadContext);
-
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("statusCode", "202");
- jsonObject.put("message", "Success");
- jsonObject.put("distributionId", asdcDistributionId);
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
- AsdcClientHelper asdcClientHelperMock = Mockito.mock(AsdcClientHelper.class);
- RESTConfig configMock = Mockito.mock(RESTConfig.class);
- RESTClient clientMock = Mockito.mock(RESTClient.class);
- APIResponse apiResponseMock = Mockito.mock(APIResponse.class);
-
- Mockito.when(asdcClientHelperMock.setRestClient(configMock)).thenReturn(clientMock);
- Mockito.when(asdcClientHelperMock.setHttpPostResponse(clientMock, jsonPayload)).thenReturn(apiResponseMock);
- Mockito.when(asdcClientHelperMock.enhanceJsonResponse(jsonObject, 202)).thenReturn(jsonObject);
- Mockito.when(asdcClientHelperMock.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext)).thenReturn(jsonObject);
-
- Mockito.when(distributionDb.getOperationalEnvDistributionStatus(asdcDistributionId)).thenReturn(operEnvDistStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvServiceModelStatus(operationalEnvironmentId, serviceModelVersionId)).thenReturn(operEnvServiceModelStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvIdStatus(operationalEnvironmentId, requestId)).thenReturn(queryServiceModelResponseList);
-
- int row = 1;
- Mockito.when(distributionDb.updateOperationalEnvDistributionStatus(distribution.getStatus().toString(), asdcDistributionId, operationalEnvironmentId, serviceModelVersionId)).thenReturn(row);
- Mockito.when(serviceModelDb.updateOperationalEnvRetryCountStatus(operationalEnvironmentId, serviceModelVersionId, distribution.getStatus().toString(), 0)).thenReturn(row);
-
- doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- request.setOperationalEnvironmentId(operationalEnvironmentId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatus = new ActivateVnfStatusOperationalEnvironment(request, requestId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatusMock = spy(activateVnfStatus);
- activateVnfStatusMock.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfStatusMock.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfStatusMock.setRequestsDBHelper(dbUtils);
- activateVnfStatusMock.setAsdcClientHelper(asdcClientHelperMock);
-
- activateVnfStatusMock.execute();
-
- verify(distributionDb, times(1)).updateOperationalEnvDistributionStatus(distribution.getStatus().toString(), asdcDistributionId, operationalEnvironmentId, serviceModelVersionId);
- verify(serviceModelDb, times(1)).updateOperationalEnvRetryCountStatus(operationalEnvironmentId, serviceModelVersionId, distribution.getStatus().toString(), 0);
-
-
- }
-
- @Test
- public void executionTest_ERROR_Status_And_RETRY() throws Exception {
-
- int retryCnt = 3;
- String distributionStatus = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString();
- String recoverAction = "RETRY";
-
- // Prepare db query mock response data
- OperationalEnvDistributionStatus operEnvDistStatusObj = new OperationalEnvDistributionStatus();
- operEnvDistStatusObj.setServiceModelVersionId(serviceModelVersionId);
- operEnvDistStatusObj.setDistributionId(asdcDistributionId);
- operEnvDistStatusObj.setOperationalEnvId(operationalEnvironmentId);
- operEnvDistStatusObj.setDistributionIdStatus(distributionStatus);
- operEnvDistStatusObj.setRequestId(requestId);
-
- // ServiceModelStatus - getOperationalEnvServiceModelStatus
- OperationalEnvServiceModelStatus operEnvServiceModelStatusObj = new OperationalEnvServiceModelStatus();
- operEnvServiceModelStatusObj.setRequestId(requestId);
- operEnvServiceModelStatusObj.setOperationalEnvId(operationalEnvironmentId);
- operEnvServiceModelStatusObj.setServiceModelVersionDistrStatus(distributionStatus);
- operEnvServiceModelStatusObj.setRecoveryAction(recoverAction);
- operEnvServiceModelStatusObj.setRetryCount(retryCnt);
- operEnvServiceModelStatusObj.setWorkloadContext(workloadContext);
- operEnvServiceModelStatusObj.setServiceModelVersionId(serviceModelVersionId);
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = new ArrayList<OperationalEnvServiceModelStatus>();
- queryServiceModelResponseList.add(operEnvServiceModelStatusObj);
-
- // prepare distribution obj
- Distribution distribution = new Distribution();
- distribution.setStatus(Status.DISTRIBUTION_COMPLETE_ERROR);
- request.setDistribution(distribution);
- request.setDistributionId(asdcDistributionId);
-
- // prepare asdc return data
- String jsonPayload = asdcClientUtils.buildJsonWorkloadContext(workloadContext);
-
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("statusCode", "202");
- jsonObject.put("message", "Success");
- jsonObject.put("distributionId", asdcDistributionId);
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
- AsdcClientHelper asdcClientHelperMock = Mockito.mock(AsdcClientHelper.class);
- RESTConfig configMock = Mockito.mock(RESTConfig.class);
- RESTClient clientMock = Mockito.mock(RESTClient.class);
- APIResponse apiResponseMock = Mockito.mock(APIResponse.class);
-
- Mockito.when(asdcClientHelperMock.setRestClient(configMock)).thenReturn(clientMock);
- Mockito.when(asdcClientHelperMock.setHttpPostResponse(clientMock, jsonPayload)).thenReturn(apiResponseMock);
- Mockito.when(asdcClientHelperMock.enhanceJsonResponse(jsonObject, 202)).thenReturn(jsonObject);
- Mockito.when(asdcClientHelperMock.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext)).thenReturn(jsonObject);
-
- Mockito.when(distributionDb.getOperationalEnvDistributionStatus(asdcDistributionId)).thenReturn(operEnvDistStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvServiceModelStatus(operationalEnvironmentId, serviceModelVersionId)).thenReturn(operEnvServiceModelStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvIdStatus(operationalEnvironmentId, requestId)).thenReturn(queryServiceModelResponseList);
-
- int row = 1;
- Mockito.when(distributionDb.updateOperationalEnvDistributionStatus(distribution.getStatus().toString(), asdcDistributionId, operationalEnvironmentId, serviceModelVersionId)).thenReturn(row);
- Mockito.when(serviceModelDb.updateOperationalEnvRetryCountStatus(operationalEnvironmentId, serviceModelVersionId, distribution.getStatus().toString(), 0)).thenReturn(row);
-
- doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- request.setOperationalEnvironmentId(operationalEnvironmentId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatus = new ActivateVnfStatusOperationalEnvironment(request, requestId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatusMock = spy(activateVnfStatus);
- activateVnfStatusMock.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfStatusMock.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfStatusMock.setRequestsDBHelper(dbUtils);
- activateVnfStatusMock.setAsdcClientHelper(asdcClientHelperMock);
-
- activateVnfStatusMock.execute();
-
- // waiting
- verify(dbUtils, times(0)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
- verify(dbUtils, times(0)).updateInfraFailureCompletion(any(String.class), any(String.class), any(String.class));
- assertEquals(false, activateVnfStatusMock.isSuccess());
-
- }
-
- @Test
- public void executionTest_ERROR_Status_And_RETRY_And_RetryZero() throws Exception {
-
- int retryCnt = 0;
- String distributionStatus = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString();
- String recoverAction = "RETRY";
-
- // Prepare db query mock response data
- OperationalEnvDistributionStatus operEnvDistStatusObj = new OperationalEnvDistributionStatus();
- operEnvDistStatusObj.setServiceModelVersionId(serviceModelVersionId);
- operEnvDistStatusObj.setDistributionId(asdcDistributionId);
- operEnvDistStatusObj.setOperationalEnvId(operationalEnvironmentId);
- operEnvDistStatusObj.setDistributionIdStatus(distributionStatus);
- operEnvDistStatusObj.setRequestId(requestId);
-
- // ServiceModelStatus - getOperationalEnvServiceModelStatus
- OperationalEnvServiceModelStatus operEnvServiceModelStatusObj = new OperationalEnvServiceModelStatus();
- operEnvServiceModelStatusObj.setRequestId(requestId);
- operEnvServiceModelStatusObj.setOperationalEnvId(operationalEnvironmentId);
- operEnvServiceModelStatusObj.setServiceModelVersionDistrStatus(distributionStatus);
- operEnvServiceModelStatusObj.setRecoveryAction(recoverAction);
- operEnvServiceModelStatusObj.setRetryCount(retryCnt);
- operEnvServiceModelStatusObj.setWorkloadContext(workloadContext);
- operEnvServiceModelStatusObj.setServiceModelVersionId(serviceModelVersionId);
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = new ArrayList<OperationalEnvServiceModelStatus>();
- queryServiceModelResponseList.add(operEnvServiceModelStatusObj);
-
- // prepare distribution obj
- Distribution distribution = new Distribution();
- distribution.setStatus(Status.DISTRIBUTION_COMPLETE_ERROR);
- request.setDistribution(distribution);
- request.setDistributionId(asdcDistributionId);
-
- // prepare asdc return data
- String jsonPayload = asdcClientUtils.buildJsonWorkloadContext(workloadContext);
-
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("statusCode", "202");
- jsonObject.put("message", "Success");
- jsonObject.put("distributionId", asdcDistributionId);
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
- AsdcClientHelper asdcClientHelperMock = Mockito.mock(AsdcClientHelper.class);
- RESTConfig configMock = Mockito.mock(RESTConfig.class);
- RESTClient clientMock = Mockito.mock(RESTClient.class);
- APIResponse apiResponseMock = Mockito.mock(APIResponse.class);
-
- Mockito.when(asdcClientHelperMock.setRestClient(configMock)).thenReturn(clientMock);
- Mockito.when(asdcClientHelperMock.setHttpPostResponse(clientMock, jsonPayload)).thenReturn(apiResponseMock);
- Mockito.when(asdcClientHelperMock.enhanceJsonResponse(jsonObject, 202)).thenReturn(jsonObject);
- Mockito.when(asdcClientHelperMock.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext)).thenReturn(jsonObject);
-
- Mockito.when(distributionDb.getOperationalEnvDistributionStatus(asdcDistributionId)).thenReturn(operEnvDistStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvServiceModelStatus(operationalEnvironmentId, serviceModelVersionId)).thenReturn(operEnvServiceModelStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvIdStatus(operationalEnvironmentId, requestId)).thenReturn(queryServiceModelResponseList);
-
- int row = 1;
- Mockito.when(distributionDb.updateOperationalEnvDistributionStatus(distribution.getStatus().toString(), asdcDistributionId, operationalEnvironmentId, serviceModelVersionId)).thenReturn(row);
- Mockito.when(serviceModelDb.updateOperationalEnvRetryCountStatus(operationalEnvironmentId, serviceModelVersionId, distribution.getStatus().toString(), 0)).thenReturn(row);
-
- doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- request.setOperationalEnvironmentId(operationalEnvironmentId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatus = new ActivateVnfStatusOperationalEnvironment(request, requestId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatusMock = spy(activateVnfStatus);
- activateVnfStatusMock.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfStatusMock.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfStatusMock.setRequestsDBHelper(dbUtils);
- activateVnfStatusMock.setAsdcClientHelper(asdcClientHelperMock);
-
- activateVnfStatusMock.execute();
-
- // waiting
- verify(dbUtils, times(0)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
- verify(dbUtils, times(1)).updateInfraFailureCompletion(any(String.class), any(String.class), any(String.class));
- assertEquals(false, activateVnfStatusMock.isSuccess());
-
- }
-
- @Test
- public void executionTest_ERROR_Status_And_RETRY_And_ErrorAsdc() throws Exception {
-
- int retryCnt = 3;
- String distributionStatus = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString();
- String recoverAction = "RETRY";
-
- // Prepare db query mock response data
- OperationalEnvDistributionStatus operEnvDistStatusObj = new OperationalEnvDistributionStatus();
- operEnvDistStatusObj.setServiceModelVersionId(serviceModelVersionId);
- operEnvDistStatusObj.setDistributionId(asdcDistributionId);
- operEnvDistStatusObj.setOperationalEnvId(operationalEnvironmentId);
- operEnvDistStatusObj.setDistributionIdStatus(distributionStatus);
- operEnvDistStatusObj.setRequestId(requestId);
-
- // ServiceModelStatus - getOperationalEnvServiceModelStatus
- OperationalEnvServiceModelStatus operEnvServiceModelStatusObj = new OperationalEnvServiceModelStatus();
- operEnvServiceModelStatusObj.setRequestId(requestId);
- operEnvServiceModelStatusObj.setOperationalEnvId(operationalEnvironmentId);
- operEnvServiceModelStatusObj.setServiceModelVersionDistrStatus(distributionStatus);
- operEnvServiceModelStatusObj.setRecoveryAction(recoverAction);
- operEnvServiceModelStatusObj.setRetryCount(retryCnt);
- operEnvServiceModelStatusObj.setWorkloadContext(workloadContext);
- operEnvServiceModelStatusObj.setServiceModelVersionId(serviceModelVersionId);
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = new ArrayList<OperationalEnvServiceModelStatus>();
- queryServiceModelResponseList.add(operEnvServiceModelStatusObj);
-
- // prepare distribution obj
- Distribution distribution = new Distribution();
- distribution.setStatus(Status.DISTRIBUTION_COMPLETE_ERROR);
- request.setDistribution(distribution);
- request.setDistributionId(asdcDistributionId);
-
- // prepare asdc return data
- String jsonPayload = asdcClientUtils.buildJsonWorkloadContext(workloadContext);
-
- // ERROR in asdc
- JSONObject jsonMessages = new JSONObject();
- jsonMessages.put("statusCode", "409");
- jsonMessages.put("message", "Undefined Error Message!");
- jsonMessages.put("messageId", "SVC4675");
- jsonMessages.put("text", "Error: Service state is invalid for this action.");
- JSONObject jsonServException = new JSONObject();
- jsonServException.put("serviceException", jsonMessages);
- JSONObject jsonErrorRequest = new JSONObject();
- jsonErrorRequest.put("requestError", jsonServException);
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
- AsdcClientHelper asdcClientHelperMock = Mockito.mock(AsdcClientHelper.class);
- RESTConfig configMock = Mockito.mock(RESTConfig.class);
- RESTClient clientMock = Mockito.mock(RESTClient.class);
- APIResponse apiResponseMock = Mockito.mock(APIResponse.class);
-
- Mockito.when(asdcClientHelperMock.setRestClient(configMock)).thenReturn(clientMock);
- Mockito.when(asdcClientHelperMock.setHttpPostResponse(clientMock, jsonPayload)).thenReturn(apiResponseMock);
- Mockito.when(asdcClientHelperMock.enhanceJsonResponse(jsonMessages, 202)).thenReturn(jsonMessages);
- Mockito.when(asdcClientHelperMock.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext)).thenReturn(jsonMessages);
-
- Mockito.when(distributionDb.getOperationalEnvDistributionStatus(asdcDistributionId)).thenReturn(operEnvDistStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvServiceModelStatus(operationalEnvironmentId, serviceModelVersionId)).thenReturn(operEnvServiceModelStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvIdStatus(operationalEnvironmentId, requestId)).thenReturn(queryServiceModelResponseList);
-
- int row = 1;
- Mockito.when(distributionDb.updateOperationalEnvDistributionStatus(distribution.getStatus().toString(), asdcDistributionId, operationalEnvironmentId, serviceModelVersionId)).thenReturn(row);
- Mockito.when(serviceModelDb.updateOperationalEnvRetryCountStatus(operationalEnvironmentId, serviceModelVersionId, distribution.getStatus().toString(), 0)).thenReturn(row);
-
- doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- request.setOperationalEnvironmentId(operationalEnvironmentId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatus = new ActivateVnfStatusOperationalEnvironment(request, requestId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatusMock = spy(activateVnfStatus);
- activateVnfStatusMock.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfStatusMock.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfStatusMock.setRequestsDBHelper(dbUtils);
- activateVnfStatusMock.setAsdcClientHelper(asdcClientHelperMock);
-
- activateVnfStatusMock.execute();
-
- // waiting
- verify(dbUtils, times(0)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
- verify(dbUtils, times(1)).updateInfraFailureCompletion(any(String.class), any(String.class), any(String.class));
- assertEquals(false, activateVnfStatusMock.isSuccess());
-
- }
-
- @Test
- public void executionTest_ERROR_Status_And_SKIP() throws Exception {
-
- int retryCnt = 3;
- String distributionStatus = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString();
- String recoverAction = "SKIP";
-
- // Prepare db query mock response data
- OperationalEnvDistributionStatus operEnvDistStatusObj = new OperationalEnvDistributionStatus();
- operEnvDistStatusObj.setServiceModelVersionId(serviceModelVersionId);
- operEnvDistStatusObj.setDistributionId(asdcDistributionId);
- operEnvDistStatusObj.setOperationalEnvId( operationalEnvironmentId);
- operEnvDistStatusObj.setDistributionIdStatus(distributionStatus);
- operEnvDistStatusObj.setRequestId(requestId);
-
- // ServiceModelStatus - getOperationalEnvServiceModelStatus
- OperationalEnvServiceModelStatus operEnvServiceModelStatusObj = new OperationalEnvServiceModelStatus();
- operEnvServiceModelStatusObj.setRequestId(requestId);
- operEnvServiceModelStatusObj.setOperationalEnvId(operationalEnvironmentId);
- operEnvServiceModelStatusObj.setServiceModelVersionDistrStatus(distributionStatus);
- operEnvServiceModelStatusObj.setRecoveryAction(recoverAction);
- operEnvServiceModelStatusObj.setRetryCount(retryCnt);
- operEnvServiceModelStatusObj.setWorkloadContext(workloadContext);
- operEnvServiceModelStatusObj.setServiceModelVersionId(serviceModelVersionId);
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = new ArrayList<OperationalEnvServiceModelStatus>();
- queryServiceModelResponseList.add(operEnvServiceModelStatusObj);
-
- // prepare distribution obj
- Distribution distribution = new Distribution();
- distribution.setStatus(Status.DISTRIBUTION_COMPLETE_ERROR);
- request.setDistribution(distribution);
- request.setDistributionId(asdcDistributionId);
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
-
- Mockito.when(distributionDb.getOperationalEnvDistributionStatus(asdcDistributionId)).thenReturn(operEnvDistStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvServiceModelStatus(operationalEnvironmentId, serviceModelVersionId)).thenReturn(operEnvServiceModelStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvIdStatus(operationalEnvironmentId, requestId)).thenReturn(queryServiceModelResponseList);
-
- int row = 1;
- Mockito.when(distributionDb.updateOperationalEnvDistributionStatus(distribution.getStatus().toString(), asdcDistributionId, operationalEnvironmentId, serviceModelVersionId)).thenReturn(row);
- Mockito.when(serviceModelDb.updateOperationalEnvRetryCountStatus(operationalEnvironmentId, serviceModelVersionId, distribution.getStatus().toString(), 0)).thenReturn(row);
-
- doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- request.setOperationalEnvironmentId(operationalEnvironmentId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatus = new ActivateVnfStatusOperationalEnvironment(request, requestId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatusMock = spy(activateVnfStatus);
- activateVnfStatusMock.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfStatusMock.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfStatusMock.setRequestsDBHelper(dbUtils);
-
- activateVnfStatusMock.execute();
-
- // waiting
- verify(dbUtils, times(0)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
- verify(dbUtils, times(0)).updateInfraFailureCompletion(any(String.class), any(String.class), any(String.class));
- assertEquals(false, activateVnfStatusMock.isSuccess());
-
- }
-
- @Test
- public void executionTest_ERROR_Status_And_ABORT() throws Exception {
-
- int retryCnt = 3;
- String distributionStatus = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString();
- String recoverAction = "ABORT";
-
- // Prepare db query mock response data
- OperationalEnvDistributionStatus operEnvDistStatusObj = new OperationalEnvDistributionStatus();
- operEnvDistStatusObj.setServiceModelVersionId(serviceModelVersionId);
- operEnvDistStatusObj.setDistributionId(asdcDistributionId);
- operEnvDistStatusObj.setOperationalEnvId( operationalEnvironmentId);
- operEnvDistStatusObj.setDistributionIdStatus(distributionStatus);
- operEnvDistStatusObj.setRequestId(requestId);
-
- // ServiceModelStatus - getOperationalEnvServiceModelStatus
- OperationalEnvServiceModelStatus operEnvServiceModelStatusObj = new OperationalEnvServiceModelStatus();
- operEnvServiceModelStatusObj.setRequestId(requestId);
- operEnvServiceModelStatusObj.setOperationalEnvId(operationalEnvironmentId);
- operEnvServiceModelStatusObj.setServiceModelVersionDistrStatus(distributionStatus);
- operEnvServiceModelStatusObj.setRecoveryAction(recoverAction);
- operEnvServiceModelStatusObj.setRetryCount(retryCnt);
- operEnvServiceModelStatusObj.setWorkloadContext(workloadContext);
- operEnvServiceModelStatusObj.setServiceModelVersionId(serviceModelVersionId);
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = new ArrayList<OperationalEnvServiceModelStatus>();
- queryServiceModelResponseList.add(operEnvServiceModelStatusObj);
-
- // prepare distribution obj
- Distribution distribution = new Distribution();
- distribution.setStatus(Status.DISTRIBUTION_COMPLETE_ERROR);
- request.setDistribution(distribution);
- request.setDistributionId(asdcDistributionId);
-
- // Mockito mock
- OperationalEnvDistributionStatusDb distributionDb = Mockito.mock(OperationalEnvDistributionStatusDb.class);
- OperationalEnvServiceModelStatusDb serviceModelDb = Mockito.mock(OperationalEnvServiceModelStatusDb.class);
- RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
-
- Mockito.when(distributionDb.getOperationalEnvDistributionStatus(asdcDistributionId)).thenReturn(operEnvDistStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvServiceModelStatus(operationalEnvironmentId, serviceModelVersionId)).thenReturn(operEnvServiceModelStatusObj);
- Mockito.when(serviceModelDb.getOperationalEnvIdStatus(operationalEnvironmentId, requestId)).thenReturn(queryServiceModelResponseList);
-
- int row = 1;
- Mockito.when(distributionDb.updateOperationalEnvDistributionStatus(distribution.getStatus().toString(), asdcDistributionId, operationalEnvironmentId, serviceModelVersionId)).thenReturn(row);
- Mockito.when(serviceModelDb.updateOperationalEnvRetryCountStatus(operationalEnvironmentId, serviceModelVersionId, distribution.getStatus().toString(), 0)).thenReturn(row);
-
- doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
-
- request.setOperationalEnvironmentId(operationalEnvironmentId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatus = new ActivateVnfStatusOperationalEnvironment(request, requestId);
- ActivateVnfStatusOperationalEnvironment activateVnfStatusMock = spy(activateVnfStatus);
- activateVnfStatusMock.setOperationalEnvDistributionStatusDb(distributionDb);
- activateVnfStatusMock.setOperationalEnvServiceModelStatusDb(serviceModelDb);
- activateVnfStatusMock.setRequestsDBHelper(dbUtils);
- activateVnfStatusMock.execute();
-
- assertEquals(false, activateVnfStatusMock.isSuccess());
-
- }
-
-}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java deleted file mode 100644 index e7b9db0657..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.process; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest; -import org.openecomp.mso.apihandlerinfra.tenantisolation.dmaap.DmaapOperationalEnvClient; -import org.openecomp.mso.apihandlerinfra.tenantisolation.helpers.AAIClientHelper; -import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.OperationalEnvironment; -import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.RequestDetails; -import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.RequestInfo; -import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.RequestParameters; -import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment; -import org.openecomp.mso.requestsdb.RequestsDBHelper; - -public class CreateEcompOperationalEnvironmentTest { - - @Mock private AAIClientHelper mockAaiClientHelper; - @Mock private DmaapOperationalEnvClient mockDmaapClient; - @Mock private RequestsDBHelper mockRequestsDBHelper; - - private CloudOrchestrationRequest request; - private CreateEcompOperationalEnvironment spyProcess; - - public CreateEcompOperationalEnvironmentTest() { - super(); - } - - @Before - public void testSetUp() { - MockitoAnnotations.initMocks(this); - request = getCloudOrchestrationRequest(); - CreateEcompOperationalEnvironment process = new CreateEcompOperationalEnvironment(request, "123"); - spyProcess = spy(process); - when(spyProcess.getAaiHelper()).thenReturn(mockAaiClientHelper); - when(spyProcess.getDmaapClient()).thenReturn(mockDmaapClient); - when(spyProcess.getRequestDb()).thenReturn(mockRequestsDBHelper); - } - - public CloudOrchestrationRequest getCloudOrchestrationRequest() { - CloudOrchestrationRequest cor = new CloudOrchestrationRequest(); - RequestDetails reqDetails = new RequestDetails(); - RequestInfo reqInfo = new RequestInfo(); - RequestParameters reqParams = new RequestParameters(); - reqParams.setTenantContext("TEST"); - reqParams.setWorkloadContext("ECOMP_TEST"); - reqParams.setOperationalEnvironmentType(OperationalEnvironment.ECOMP); - reqInfo.setInstanceName("TEST_ECOMP_ENVIRONMENT"); - reqDetails.setRequestInfo(reqInfo); - reqDetails.setRequestParameters(reqParams); - cor.setRequestDetails(reqDetails); - return cor; - } - - @Test - public void testProcess() throws Exception { - spyProcess.execute(); - verify(mockAaiClientHelper, times(1)).createOperationalEnvironment(any(AAIOperationalEnvironment.class)); - verify(mockDmaapClient, times(1)).dmaapPublishOperationalEnvRequest(any(String.class), any(String.class), any(String.class), any(String.class), any(String.class), any(String.class) ); - verify(mockRequestsDBHelper, times(1)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class)); - } - -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java deleted file mode 100644 index ad8a5ba245..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.process; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.nio.file.Files; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.MockitoAnnotations; -import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest; -import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment; -import org.openecomp.mso.client.grm.beans.Property; -import org.openecomp.mso.client.grm.beans.ServiceEndPointList; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class CreateVnfOperationalEnvironmentTest { - - private ObjectMapper mapper = new ObjectMapper(); - private CloudOrchestrationRequest request; - private ServiceEndPointList serviceEndpoints; - private CreateVnfOperationalEnvironment spyProcess; - - @Before - public void testSetUp() throws Exception { - MockitoAnnotations.initMocks(this); - String jsonRequest = getFileContentsAsString("__files/vnfoperenv/createVnfOperationalEnvironmentRequest.json"); - request = mapper.readValue(jsonRequest, CloudOrchestrationRequest.class); - String jsonServiceEndpoints = getFileContentsAsString("__files/vnfoperenv/endpoints.json"); - serviceEndpoints = mapper.readValue(jsonServiceEndpoints, ServiceEndPointList.class); - CreateVnfOperationalEnvironment process = new CreateVnfOperationalEnvironment(request, "9876543210"); - spyProcess = spy(process); - } - - - @Test - public void testGetEcompManagingEnvironmentId() throws Exception { - when(spyProcess.getRequest()).thenReturn(request); - assertEquals("ff305d54-75b4-431b-adb2-eb6b9e5ff000", spyProcess.getEcompManagingEnvironmentId()); - } - - @Test - public void testGetTenantContext() throws Exception { - when(spyProcess.getRequest()).thenReturn(request); - assertEquals("Test", spyProcess.getTenantContext()); - } - - @Test - public void testGetEnvironmentName() throws Exception { - List<Property> props = serviceEndpoints.getServiceEndPointList().get(0).getProperties(); - assertEquals("DEV", spyProcess.getEnvironmentName(props)); - } - - @Test - public void testBuildServiceNameForVnf() throws Exception { - when(spyProcess.getRequest()).thenReturn(request); - assertEquals("Test.VNF_E2E-IST.Inventory", spyProcess.buildServiceNameForVnf("TEST.ECOMP_PSL.Inventory")); - } - - @Test - public void testGetSearchKey() { - AAIOperationalEnvironment ecompEnv = new AAIOperationalEnvironment(); - ecompEnv.setTenantContext("Test"); - ecompEnv.setWorkloadContext("ECOMPL_PSL"); - assertEquals("Test.ECOMPL_PSL.*", spyProcess.getSearchKey(ecompEnv)); - } - - public String getFileContentsAsString(String fileName) { - String content = ""; - try { - ClassLoader classLoader = this.getClass().getClassLoader(); - File file = new File(classLoader.getResource(fileName).getFile()); - content = new String(Files.readAllBytes(file.toPath())); - } - catch(Exception e) { - e.printStackTrace(); - System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage()); - } - return content; - } - -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java deleted file mode 100644 index ee07a53f74..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.apihandlerinfra.tenantisolation.process;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Optional;
-
-import org.junit.Test;
-import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
-import org.openecomp.mso.apihandlerinfra.tenantisolation.helpers.AAIClientHelper;
-import org.openecomp.mso.client.aai.entities.AAIResultWrapper;
-import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment;
-import org.openecomp.mso.requestsdb.RequestsDBHelper;
-
-public class DeactivateVnfOperationalEnvironmentTest {
-
- @Test
- public void testDeactivateOperationalEnvironment() throws Exception {
- String operationlEnvironmentId = "ff3514e3-5a33-55df-13ab-12abad84e7ff";
- CloudOrchestrationRequest request = new CloudOrchestrationRequest();
- request.setOperationalEnvironmentId(operationlEnvironmentId);
- request.setRequestDetails(null);
-
- DeactivateVnfOperationalEnvironment deactivate = spy(new DeactivateVnfOperationalEnvironment(request, "ff3514e3-5a33-55df-13ab-12abad84e7fe"));
- RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
- AAIClientHelper helper = mock(AAIClientHelper.class);
- AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
- AAIOperationalEnvironment operationalEnv = new AAIOperationalEnvironment();
- operationalEnv.setOperationalEnvironmentStatus("ACTIVE");
-
- doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
- when(helper.getAaiOperationalEnvironment(any(String.class))).thenReturn(wrapper);
- when(wrapper.asBean(AAIOperationalEnvironment.class)).thenReturn(Optional.of((AAIOperationalEnvironment)operationalEnv));
-
- deactivate.setRequestsDBHelper(dbUtils);
- deactivate.setAaiHelper(helper);
- deactivate.execute();
-
- verify(dbUtils, times(1)).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
- }
-
- @Test
- public void testDeactivateInvalidStatus() throws Exception {
- String operationlEnvironmentId = "ff3514e3-5a33-55df-13ab-12abad84e7ff";
- CloudOrchestrationRequest request = new CloudOrchestrationRequest();
- request.setOperationalEnvironmentId(operationlEnvironmentId);
- request.setRequestDetails(null);
-
- DeactivateVnfOperationalEnvironment deactivate = spy(new DeactivateVnfOperationalEnvironment(request, "ff3514e3-5a33-55df-13ab-12abad84e7fe"));
- RequestsDBHelper dbUtils = mock(RequestsDBHelper.class);
- AAIClientHelper helper = mock(AAIClientHelper.class);
- AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
- AAIOperationalEnvironment operationalEnv = new AAIOperationalEnvironment();
- operationalEnv.setOperationalEnvironmentStatus("SUCCESS");
-
- doNothing().when(dbUtils).updateInfraSuccessCompletion(any(String.class), any(String.class), any(String.class));
- when(helper.getAaiOperationalEnvironment(any(String.class))).thenReturn(wrapper);
- when(wrapper.asBean(AAIOperationalEnvironment.class)).thenReturn(Optional.of((AAIOperationalEnvironment)operationalEnv));
-
- deactivate.setRequestsDBHelper(dbUtils);
- deactivate.setAaiHelper(helper);
- deactivate.execute();
-
- verify(dbUtils, times(1)).updateInfraFailureCompletion(any(String.class), any(String.class), any(String.class));
- }
-}
\ No newline at end of file |