aboutsummaryrefslogtreecommitdiffstats
path: root/ccsdk-app-common/src/test/java/org
diff options
context:
space:
mode:
authorKotagiri, Ramprasad (rp5662) <rp5662@att.com>2019-03-21 17:37:42 -0400
committerKotagiri, Ramprasad (rp5662) <rp5662@att.com>2019-03-21 18:19:12 -0400
commitf4231f30d53e192e15906245a8dd0e6ef42198e1 (patch)
tree34ae86589199c2b1056efb5b2049011d5b65fd75 /ccsdk-app-common/src/test/java/org
parentb46d863e9e5db30291034e8740291c70875f1f5f (diff)
Java unit test code
This change contains the following: 1) Added Junit classes for java unit testing and code coverage 2) Refactored code to use Spring autowiring of service class instances 3) Updated icons to match the available font icons library 4) Added back ccsdk-app-os module in the parent POM Change-Id: I545202357eb1c8257ee29e0f5a02aa37991b2673 Issue-ID: CCSDK-1011 Signed-off-by: ramprasad kotagiri <rp5662@att.com>
Diffstat (limited to 'ccsdk-app-common/src/test/java/org')
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java578
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CommonApiControllerTest.java791
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ConsulControllerTest.java315
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerControllerTest.java184
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnControllerTest.java57
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/HealthCheckControllerTest.java69
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/InventoryControllerTest.java788
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockUser.java133
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockitoTestSuite.java122
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java520
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImplTest.java212
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImplTest.java366
-rw-r--r--ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImplTest.java361
13 files changed, 4214 insertions, 282 deletions
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java
index 0a5fe93..d6e1fb0 100644
--- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java
@@ -2,110 +2,526 @@
* =============LICENSE_START=========================================================
*
* =================================================================================
- * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2019 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.
+ * 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=========================================================
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*******************************************************************************/
+
package org.onap.ccsdk.dashboard.controller;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
+import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.ccsdk.dashboard.core.MockUser;
+import org.onap.ccsdk.dashboard.core.MockitoTestSuite;
+import org.onap.ccsdk.dashboard.model.CloudifyBlueprint;
+import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenant;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployment;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateRequest;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateResponse;
+import org.onap.ccsdk.dashboard.model.CloudifyEvent;
+import org.onap.ccsdk.dashboard.model.CloudifyEventList;
+import org.onap.ccsdk.dashboard.model.CloudifyExecution;
+import org.onap.ccsdk.dashboard.model.CloudifyExecutionList;
+import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstance;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceId;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceIdList;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceList;
+import org.onap.ccsdk.dashboard.model.CloudifyTenant;
import org.onap.ccsdk.dashboard.model.CloudifyTenantList;
import org.onap.ccsdk.dashboard.rest.CloudifyClient;
-import org.onap.ccsdk.dashboard.core.MockitoTestSuite;
import org.onap.portalsdk.core.domain.User;
import org.onap.portalsdk.core.web.support.UserUtils;
-import org.springframework.test.web.servlet.RequestBuilder;
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.client.HttpClientErrorException;
+
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.springframework.http.MediaType;
+public class CloudifyControllerTest extends MockitoTestSuite {
+ @Mock
+ private CloudifyClient restClient;
-public class CloudifyControllerTest extends MockitoTestSuite {
+ @InjectMocks
+ private CloudifyController subject = new CloudifyController();
+
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+
+ @Mock
+ UserUtils userUtils = new UserUtils();
+
+ @Mock
+ User epuser;
+
+ MockUser mockUser = new MockUser();
+
+ HttpClientErrorException httpException;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ objectMapper.registerModule(new Jdk8Module());
+ httpException = new HttpClientErrorException(HttpStatus.BAD_REQUEST, "statusText");
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetTenants() throws Exception {
+ String tenantsList =
+ "{\"items\": [{\"id\": 1, \"name\": \"default_tenant\", \"dName\": \"default_tenant\" }, "
+ + "{\"id\": 2, \"name\": \"dyh1b1902\", \"dName\": \"dyh1b1902\"}], "
+ + "\"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}";
+ CloudifyTenantList sampleData = null;
+ try {
+ sampleData = objectMapper.readValue(tenantsList, CloudifyTenantList.class);
+ } catch (Exception e) {
+ }
+
+ User user = mockUser.mockUser();
+ user.setLoginId("tester");
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(restClient.getTenants()).thenReturn(sampleData).thenThrow(Exception.class);
+ /*
+ * RequestBuilder request = MockMvcRequestBuilders. get("/tenants").
+ * accept(MediaType.APPLICATION_JSON);
+ */
+ String tenantStr = subject.getTenants(mockedRequest);
+ assertTrue(tenantStr.contains("dyh1b"));
+
+ tenantStr = subject.getTenants(mockedRequest);
+ assertTrue(tenantStr.contains("error"));
+ }
+
+ @SuppressWarnings({"unchecked", "unchecked"})
+ @Test
+ public final void testGetBlueprintById() throws Exception {
+
+ CloudifyBlueprint cldBp =
+ new CloudifyBlueprint("file1", "description1", "343242", "3423423", "id1", null);
+
+ List<CloudifyBlueprint> items = new ArrayList<CloudifyBlueprint>();
+ items.add(cldBp);
+
+ CloudifyBlueprintList.Metadata.Pagination pageObj =
+ new CloudifyBlueprintList.Metadata.Pagination(1, 0, 1);
+
+ CloudifyBlueprintList.Metadata metadata = new CloudifyBlueprintList.Metadata(pageObj);
+
+ CloudifyBlueprintList cldBpList = new CloudifyBlueprintList(items, metadata);
+
+ when(restClient.getBlueprint(Mockito.any(), Mockito.any())).thenReturn(cldBpList)
+ .thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult = subject.getBlueprintById("id1", "tenant1", mockedRequest);
+ assertTrue(actualResult.contains("id1"));
+
+ actualResult = subject.getBlueprintById("id1", "tenant1", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getBlueprintById("id1", "tenant1", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetDeploymentById() throws Exception {
+
+ CloudifyDeployment cldDepl = new CloudifyDeployment("description", "blueprint_id",
+ "created_at", "updated_at", "id1", null, null, null, null, null, null, null, "tenant1");
+
+ List<CloudifyDeployment> items = new ArrayList<CloudifyDeployment>();
+ items.add(cldDepl);
+
+ CloudifyDeploymentList.Metadata.Pagination pageObj =
+ new CloudifyDeploymentList.Metadata.Pagination(1, 0, 1);
+
+ CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj);
+
+ CloudifyDeploymentList cldDeplList = new CloudifyDeploymentList(items, metadata);
+
+ when(restClient.getDeployment(Mockito.any(), Mockito.any())).thenReturn(cldDeplList)
+ .thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult = subject.getDeploymentById("id1", "tenant1", mockedRequest);
+ assertTrue(actualResult.contains("id1"));
+
+ actualResult = subject.getDeploymentById("id1", "tenant1", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getDeploymentById("id1", "tenant1", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+
+ when(restClient.getDeployment(Mockito.any())).thenReturn(cldDeplList)
+ .thenThrow(Exception.class).thenThrow(httpException);
+
+ actualResult = subject.getDeploymentById("id1", "", mockedRequest);
+ assertTrue(actualResult.contains("id1"));
+
+ actualResult = subject.getDeploymentById("id1", null, mockedRequest);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getDeploymentById("id1", null, mockedRequest);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetTenantStatusForService() throws Exception {
+
+ String[] deplIds = {"id1", "id2"};
+
+ CloudifyDeployedTenant cldDeplTenant = new CloudifyDeployedTenant("id1", "bp1", "tenant1");
+
+ List<CloudifyDeployedTenant> cldDeplTenantList = new ArrayList<CloudifyDeployedTenant>();
+
+ cldDeplTenantList.add(cldDeplTenant);
+
+ CloudifyDeployedTenantList cldDeployedTenantList =
+ new CloudifyDeployedTenantList(cldDeplTenantList, null);
+
+ CloudifyTenant cldTenant = new CloudifyTenant("tenant1", "tenant1", "tenant_id1");
+
+ List<CloudifyTenant> cldfyTenantList = new ArrayList<CloudifyTenant>();
+ cldfyTenantList.add(cldTenant);
+
+ CloudifyTenantList cloudifyTenantList = new CloudifyTenantList(cldfyTenantList, null);
+
+ CloudifyExecution cldExecution =
+ new CloudifyExecution("successful", "created_at", "install", false, "bp1", "id1",
+ "tenant1", "error", "execution_id1", null, false, false);
+
+ List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>();
+
+ cldExecutionList.add(cldExecution);
+
+ CloudifyExecutionList cloudifyExecutionList =
+ new CloudifyExecutionList(cldExecutionList, null);
+
+ Map<String, Object> plan = new HashMap<String, Object>();
+ HashMap<String, String> plugins_to_install = new HashMap<String, String>();
+ plugins_to_install.put("name", "helm-plugin");
+ ArrayList<HashMap<String, String>> deployment_plugins_to_install =
+ new ArrayList<HashMap<String, String>>();
+
+ deployment_plugins_to_install.add(plugins_to_install);
+ plan.put("deployment_plugins_to_install", deployment_plugins_to_install);
+
+ Map<String, String> workflows = new HashMap<String, String>();
+ workflows.put("status", "workflowshelm");
+ plan.put("workflows", workflows);
+
+ CloudifyBlueprint cldBp =
+ new CloudifyBlueprint("file1", "description1", "343242", "3423423", "id1", plan);
+
+ List<CloudifyBlueprint> items = new ArrayList<CloudifyBlueprint>();
+ items.add(cldBp);
+
+ CloudifyBlueprintList.Metadata.Pagination pageObj =
+ new CloudifyBlueprintList.Metadata.Pagination(1, 0, 1);
+
+ CloudifyBlueprintList.Metadata metadata = new CloudifyBlueprintList.Metadata(pageObj);
+
+ CloudifyBlueprintList cldBpList = new CloudifyBlueprintList(items, metadata);
+
+ when(restClient.getTenants()).thenReturn(cloudifyTenantList);
+
+ when(restClient.getTenantInfoFromDeploy(Mockito.any())).thenReturn(cldDeployedTenantList);
+
+ when(restClient.getExecutionsSummary(Mockito.any(), Mockito.any()))
+ .thenReturn(cloudifyExecutionList);
+
+ when(restClient.getBlueprint(Mockito.any(), Mockito.any())).thenReturn(cldBpList)
+ .thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult = subject.getTenantStatusForService(mockedRequest, deplIds);
+ assertTrue(actualResult.contains("successful"));
+
+ actualResult = subject.getTenantStatusForService(mockedRequest, deplIds);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getTenantStatusForService(mockedRequest, deplIds);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetExecutionsByPage() throws Exception {
+ CloudifyExecution cldExecution =
+ new CloudifyExecution("successful", "created_at", "install", false, "bp1", "id1",
+ "tenant1", "error", "execution_id1", null, false, false);
+
+ List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>();
+
+ cldExecutionList.add(cldExecution);
+
+ CloudifyExecutionList cloudifyExecutionList =
+ new CloudifyExecutionList(cldExecutionList, null);
+
+ CloudifyDeployment cldDeployment = new CloudifyDeployment("description", "blueprint_id",
+ "created_at", "updated_at", "id", null, null, null, null, null, null, null, "tenant");
+
+ List<CloudifyDeployment> cfyDeployItems = new ArrayList<CloudifyDeployment>();
+ cfyDeployItems.add(cldDeployment);
+
+ CloudifyDeploymentList.Metadata.Pagination pageObj =
+ new CloudifyDeploymentList.Metadata.Pagination(1, 0, 1);
+ CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj);
+
+ CloudifyDeploymentList cldDeployList = new CloudifyDeploymentList(cfyDeployItems, metadata);
+
+ when(restClient.getDeployments()).thenReturn(cldDeployList);
+ when(restClient.getExecutions(Mockito.any(), Mockito.any()))
+ .thenReturn(cloudifyExecutionList).thenThrow(Exception.class)
+ .thenReturn(cloudifyExecutionList);
+
+ String actualResult =
+ subject.getExecutionsByPage(mockedRequest, "id1", "successful", "tenant1");
+ assertTrue(actualResult.contains("successful"));
+
+ actualResult = subject.getExecutionsByPage(mockedRequest, "id1", "successful", "tenant1");
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getExecutionsByPage(mockedRequest, null, "successful", "tenant1");
+ assertTrue(actualResult.contains("successful"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetExecutionByIdAndDeploymentId() throws Exception {
+ CloudifyExecution cldExecution =
+ new CloudifyExecution("successful", "created_at", "install", false, "bp1", "id1",
+ "tenant1", "error", "execution_id1", null, false, false);
+
+ List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>();
+
+ cldExecutionList.add(cldExecution);
+
+ CloudifyExecutionList cloudifyExecutionList =
+ new CloudifyExecutionList(cldExecutionList, null);
+
+ when(restClient.getExecutions(Mockito.any(), Mockito.any()))
+ .thenReturn(cloudifyExecutionList).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult = subject.getExecutionByIdAndDeploymentId("execution_id",
+ "deployment_id", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("successful"));
+
+ actualResult = subject.getExecutionByIdAndDeploymentId("execution_id", "deployment_id",
+ "tenant", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getExecutionByIdAndDeploymentId("execution_id", "deployment_id",
+ "tenant", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetExecutionEventsById() throws Exception {
+
+ CloudifyEvent cfyEvent1 = new CloudifyEvent("blueprint_id", "deployment_id", null, "log",
+ "execution_id", "debug", "logger", "message", "node_instance_id", "node_name",
+ "operation", "reported_timestamp", "timestamp", "cloudify_log", "workflow_id");
+ CloudifyEvent cfyEvent2 = new CloudifyEvent("blueprint_id", "deployment_id", null, "log",
+ "execution_id", "debug", "logger", "message", "node_instance_id", "node_name",
+ "operation", "reported_timestamp", "timestamp", "type2", "workflow_id");
+
+ List<CloudifyEvent> cfyEventItems = new ArrayList<CloudifyEvent>();
+ cfyEventItems.add(cfyEvent1);
+ cfyEventItems.add(cfyEvent2);
+
+ CloudifyEventList cfyEventsList = new CloudifyEventList(cfyEventItems, null);
+
+ when(restClient.getEventlogs(Mockito.any(), Mockito.any())).thenReturn(cfyEventsList)
+ .thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult =
+ subject.getExecutionEventsById("execution1", "false", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("execution_id"));
+
+ actualResult =
+ subject.getExecutionEventsById("execution1", "false", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult =
+ subject.getExecutionEventsById("execution1", "false", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testStartExecution() throws Exception {
+ CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "install",
+ false, "bp1", "id1", "tenant1", "error", "execution_id1", null, false, false);
+
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("key1", "value1");
+
+ CloudifyExecutionRequest cfyExecReq = new CloudifyExecutionRequest("deployment_id",
+ "upgrade", false, false, "tenant1", params);
+
+ CloudifyNodeInstanceId cfyNodeInst = new CloudifyNodeInstanceId("node_instance_id1");
+
+ List<CloudifyNodeInstanceId> cfyNodeInstItems = new ArrayList<CloudifyNodeInstanceId>();
+
+ cfyNodeInstItems.add(cfyNodeInst);
+
+ CloudifyNodeInstanceIdList cfyNodeInstList =
+ new CloudifyNodeInstanceIdList(cfyNodeInstItems, null);
+
+ when(restClient.getNodeInstanceId(Mockito.any(), Mockito.any()))
+ .thenReturn(cfyNodeInstList);
+
+ when(restClient.startExecution(Matchers.<CloudifyExecutionRequest>any()))
+ .thenReturn(cfyExecObj).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult = subject.startExecution(mockedRequest, cfyExecReq);
+ assertTrue(actualResult.contains("execution_id1"));
+
+ actualResult = subject.startExecution(mockedRequest, cfyExecReq);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.startExecution(mockedRequest, cfyExecReq);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testUpdateDeployment() throws Exception {
+
+ CloudifyDeploymentUpdateRequest cfyDeployUpdateReq =
+ new CloudifyDeploymentUpdateRequest("deployment_id", "update", false, false,
+ "node_instance_id1", "4", "1000", "image", 2, "my_container");
+
+ CloudifyDeploymentUpdateResponse cfyDeployUpdateResp = new CloudifyDeploymentUpdateResponse(
+ "terminated", "created_at", "update", false, "blueprint_id", "deployment_id", "", "id1",
+ null, "tenant1", "junit", false, "resource_availability");
+
+ when(restClient.updateDeployment(Matchers.<CloudifyDeploymentUpdateRequest>any()))
+ .thenReturn(cfyDeployUpdateResp).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult = subject.updateDeployment(mockedRequest, cfyDeployUpdateReq);
+ assertTrue(actualResult.contains("terminated"));
+
+ actualResult = subject.updateDeployment(mockedRequest, cfyDeployUpdateReq);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.updateDeployment(mockedRequest, cfyDeployUpdateReq);
+ assertTrue(actualResult.contains("error"));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetNodeInstanceId() throws Exception {
+
+ CloudifyNodeInstanceId cfyNodeInst = new CloudifyNodeInstanceId("node_instance_id1");
+
+ List<CloudifyNodeInstanceId> cfyNodeInstItems = new ArrayList<CloudifyNodeInstanceId>();
+
+ cfyNodeInstItems.add(cfyNodeInst);
+
+ CloudifyNodeInstanceIdList cfyNodeInstList =
+ new CloudifyNodeInstanceIdList(cfyNodeInstItems, null);
+
+ when(restClient.getNodeInstanceId(Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(cfyNodeInstList).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult =
+ subject.getNodeInstanceId("deploymentId", "tenant", "nodeId", mockedRequest);
+ assertTrue(actualResult.contains("node_instance_id1"));
+
+ actualResult = subject.getNodeInstanceId("deploymentId", "tenant", "nodeId", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getNodeInstanceId("deploymentId", "tenant", "nodeId", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetDeploymentRevisions() throws Exception {
+
+ CloudifyNodeInstance cfyNodeInstance = new CloudifyNodeInstance("id1", null);
+
+ List<CloudifyNodeInstance> cfyNodeInstanceItems = new ArrayList<CloudifyNodeInstance>();
+ cfyNodeInstanceItems.add(cfyNodeInstance);
+
+ CloudifyNodeInstanceList cfyNodeInstList =
+ new CloudifyNodeInstanceList(cfyNodeInstanceItems, null);
+
+ when(restClient.getNodeInstanceVersion(Mockito.any(), Mockito.any()))
+ .thenReturn(cfyNodeInstList).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult =
+ subject.getDeploymentRevisions("deploymentId", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("id1"));
+
+ actualResult = subject.getDeploymentRevisions("deploymentId", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getDeploymentRevisions("deploymentId", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCancelExecution() throws Exception {
+ List<String> tenants = new ArrayList<String>();
+ tenants.add("tenant1");
+
+ HttpHeaders httpHeader = new HttpHeaders();
+ httpHeader.put("tenant", tenants);
+
+ CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "cancel",
+ false, "bp1", "id1", "tenant1", "error", "execution_id1", null, false, false);
+
+ when(restClient.cancelExecution(Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(cfyExecObj).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult =
+ subject.cancelExecution(httpHeader, "id1", null, mockedRequest, mockedResponse);
+ assertTrue(actualResult.contains("execution_id1"));
- @Mock
- private CloudifyClient restClient;
-
- @InjectMocks
- private CloudifyController subject = new CloudifyController();
-
- protected final ObjectMapper objectMapper = new ObjectMapper();
-
- @Mock
- UserUtils userUtils = new UserUtils();
-
- @Mock
- User epuser;
-
- MockUser mockUser = new MockUser();
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- objectMapper.registerModule(new Jdk8Module());
- }
-
- @Test
- public final void testGetControllerEndpoints_stubbed() {
-
- }
-
- @Test
- public final void testGetTenants_stubbed() throws Exception {
-
- String tenantsList =
- "{\"items\": [{\"id\": 1, \"name\": \"default_tenant\", \"dName\": \"default_tenant\" }, "
- + "{\"id\": 2, \"name\": \"dyh1b1902\", \"dName\": \"dyh1b1902\"}], "
- + "\"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}";
- CloudifyTenantList sampleData = null;
- try {
- sampleData = objectMapper.readValue(tenantsList, CloudifyTenantList.class);
- } catch (Exception e) {
- }
-
- User user = mockUser.mockUser();
- user.setLoginId("tester");
- MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
-
- Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
- Mockito.when(restClient.getTenants()).thenReturn(sampleData);
-
- RequestBuilder request = MockMvcRequestBuilders.
- get("/tenants").
- accept(MediaType.APPLICATION_JSON);
-
- String tenantStr =
- subject.getTenants(mockedRequest);
-
- assertNotNull(tenantStr);
- assertTrue(tenantStr.contains("dyh1b"));
-
-
- }
+ actualResult =
+ subject.cancelExecution(httpHeader, "id1", null, mockedRequest, mockedResponse);
+ assertTrue(actualResult.contains("error"));
+ actualResult =
+ subject.cancelExecution(httpHeader, "id1", null, mockedRequest, mockedResponse);
+ assertTrue(actualResult.contains("error"));
+ }
}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CommonApiControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CommonApiControllerTest.java
new file mode 100644
index 0000000..7097275
--- /dev/null
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CommonApiControllerTest.java
@@ -0,0 +1,791 @@
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+
+package org.onap.ccsdk.dashboard.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.ccsdk.dashboard.core.MockUser;
+import org.onap.ccsdk.dashboard.core.MockitoTestSuite;
+import org.onap.ccsdk.dashboard.domain.EcdComponent;
+import org.onap.ccsdk.dashboard.exceptions.BadRequestException;
+import org.onap.ccsdk.dashboard.exceptions.DeploymentNotFoundException;
+import org.onap.ccsdk.dashboard.exceptions.DownstreamException;
+import org.onap.ccsdk.dashboard.exceptions.ServerErrorException;
+import org.onap.ccsdk.dashboard.exceptions.ServiceAlreadyExistsException;
+import org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException;
+import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeNotFoundException;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenant;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployment;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList;
+import org.onap.ccsdk.dashboard.model.CloudifyExecution;
+import org.onap.ccsdk.dashboard.model.CloudifyExecutionList;
+import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstance;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceId;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceIdList;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceList;
+import org.onap.ccsdk.dashboard.model.CloudifyTenant;
+import org.onap.ccsdk.dashboard.model.CloudifyTenantList;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentInput;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequest;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponse;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponseLinks;
+import org.onap.ccsdk.dashboard.model.inventory.Service;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceList;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceRef;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceType;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeList;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeUploadRequest;
+import org.onap.ccsdk.dashboard.rest.CloudifyClient;
+import org.onap.ccsdk.dashboard.rest.DeploymentHandlerClient;
+import org.onap.ccsdk.dashboard.rest.InventoryClient;
+import org.onap.ccsdk.dashboard.service.ControllerEndpointService;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.client.HttpServerErrorException;
+import org.springframework.web.client.HttpStatusCodeException;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+
+public class CommonApiControllerTest extends MockitoTestSuite {
+
+ @Mock
+ private CloudifyClient cfyClient;
+
+ @Mock
+ private InventoryClient inventoryClient;
+
+ @Mock
+ DeploymentHandlerClient deploymentHandlerClient;
+
+ @Mock
+ ControllerEndpointService controllerEndpointService;
+
+ @InjectMocks
+ CommonApiController subject = new CommonApiController();
+
+ private HttpStatusCodeException httpException =
+ new HttpServerErrorException(HttpStatus.BAD_GATEWAY);
+
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+
+ HttpServletRequest mockedRequest;
+ HttpServletResponse mockedResponse;
+
+ MockUser mockUser = new MockUser();
+ ServiceList deplList = null;
+ Service deplItem = null;
+
+ ServiceType bpItem = null;
+ ServiceType bpItem2 = null;
+ ServiceTypeList bpList = null;
+ ServiceTypeList bpList2 = null;
+
+ ServiceTypeRequest bpUploadItem = null;
+
+ BadRequestException badReqError;
+ ServiceAlreadyExistsException srvcExistError;
+ ServerErrorException serverError;
+ DownstreamException downStrmError;
+ JsonProcessingException jsonError;
+ DeploymentNotFoundException notFoundError;
+ private ServiceTypeNotFoundException serviceTypeException =
+ new ServiceTypeNotFoundException("Invalid blueprint");
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ objectMapper.registerModule(new Jdk8Module());
+ getExpectedDeployments();
+ getExpectedBueprints();
+ createBpUploadItem();
+ mockedRequest = getMockedRequest();
+ mockedResponse = getMockedResponse();
+ badReqError = new BadRequestException("bad request");
+ srvcExistError = new ServiceAlreadyExistsException("service already exists");
+ serverError = new ServerErrorException("Error occured in server");
+ downStrmError = new DownstreamException("error occured in downstream");
+ notFoundError = new DeploymentNotFoundException("item not found");
+ }
+
+ public void getExpectedDeployments()
+ throws JsonParseException, JsonMappingException, IOException {
+
+ deplItem = new Service("dcae_dtiapi_1902", null, "1552335532348", "1552335532348", null,
+ "dummyVnfId", null, "dummyVnfType", "dummyLocation", "dcae_dtiapi_1902", null);
+ Collection<Service> items = new ArrayList<Service>();
+ items.add(deplItem);
+
+ String pageLinks =
+ "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-services/?offset=25\"}}";
+ ServiceList.PaginationLinks paginationLinks =
+ objectMapper.readValue(pageLinks, ServiceList.PaginationLinks.class);
+ int totalCount = 1;
+ deplList = new ServiceList(items, totalCount, paginationLinks);
+
+ }
+
+ public void getExpectedBueprints()
+ throws JsonParseException, JsonMappingException, IOException {
+ bpItem = new ServiceType.Builder("xyz1731", "xyz1731-helm-1906", 1906,
+ "tosca_definitions_version: cloudify_dsl_1_3", "", "app1", "comp1").build();
+
+ Collection<ServiceType> items = new ArrayList<ServiceType>();
+ items.add(bpItem);
+
+ String pageLinks2 =
+ "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-services/?offset=25\"}}";
+ ServiceTypeList.PaginationLinks paginationLinks =
+ objectMapper.readValue(pageLinks2, ServiceTypeList.PaginationLinks.class);
+ int totalCount = 1;
+ bpList = new ServiceTypeList(items, totalCount, paginationLinks);
+
+ bpItem2 = new ServiceType("xyz1731", "xyz1731-helm-1907", 1906,
+ "tosca_definitions_version: cloudify_dsl_1_3\\r\\nimports:\\r\\n - http://www.getcloudify.org/spec/cloudify/4.2/types.yaml\\r\\n",
+ "app1", "comp1", null, null, null, null, null, null, "typeId", null, "created", null,
+ true);
+
+ Collection<ServiceType> items2 = new ArrayList<ServiceType>();
+ items2.add(bpItem2);
+
+ bpList2 = new ServiceTypeList(items2, totalCount, paginationLinks);
+ }
+
+ public void createBpUploadItem() {
+ bpUploadItem = ServiceTypeRequest.from(bpItem);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testInsertComponent() throws Exception {
+ EcdComponent component1 = new EcdComponent();
+
+ component1.setCname("comp1");
+ component1.setCompId(100L);
+ component1.setDname("COMP1");
+
+ doNothing().when(controllerEndpointService).insertComponent(component1);
+
+ String actualResult = subject.insertComponent(mockedRequest, component1);
+ assertTrue(actualResult.contains("Inserted"));
+ }
+
+ @Test
+ public final void testGetComponents() throws Exception {
+ EcdComponent component1 = new EcdComponent();
+ EcdComponent component2 = new EcdComponent();
+
+ component1.setCname("comp1");
+ component1.setCompId(100L);
+ component1.setDname("COMP1");
+
+ component2.setCname("comp2");
+ component2.setCompId(200L);
+ component2.setDname("COMP2");
+
+ List<EcdComponent> compsList = new ArrayList<EcdComponent>();
+ compsList.add(component1);
+ compsList.add(component2);
+
+ when(controllerEndpointService.getComponents()).thenReturn(compsList);
+
+ String actualResult = subject.getComponents(mockedRequest);
+ assertTrue(actualResult.contains("comp1"));
+ }
+
+ @Test
+ public final void testGetTenants() throws Exception {
+ String tenantsList =
+ "{\"items\": [{\"id\": 1, \"name\": \"default_tenant\", \"dName\": \"default_tenant\" }, "
+ + "{\"id\": 2, \"name\": \"dyh1b1902\", \"dName\": \"dyh1b1902\"}], "
+ + "\"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}";
+ CloudifyTenantList sampleData = null;
+ try {
+ sampleData = objectMapper.readValue(tenantsList, CloudifyTenantList.class);
+ } catch (Exception e) {
+ }
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+
+ Mockito.when(cfyClient.getTenants()).thenReturn(sampleData);
+
+ String tenantStr = subject.getTenants(mockedRequest);
+ assertTrue(tenantStr.contains("dyh1b"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetTenantStatusForService() throws Exception {
+ String[] deplIds = {"id1", "id2"};
+
+ CloudifyDeployedTenant cldDeplTenant = new CloudifyDeployedTenant("id1", "bp1", "tenant1");
+
+ List<CloudifyDeployedTenant> cldDeplTenantList = new ArrayList<CloudifyDeployedTenant>();
+
+ cldDeplTenantList.add(cldDeplTenant);
+
+ CloudifyDeployedTenantList cldDeployedTenantList =
+ new CloudifyDeployedTenantList(cldDeplTenantList, null);
+
+ CloudifyTenant cldTenant = new CloudifyTenant("tenant1", "tenant1", "tenant_id1");
+
+ List<CloudifyTenant> cldfyTenantList = new ArrayList<CloudifyTenant>();
+ cldfyTenantList.add(cldTenant);
+
+ CloudifyTenantList cloudifyTenantList = new CloudifyTenantList(cldfyTenantList, null);
+
+ CloudifyExecution cldExecution =
+ new CloudifyExecution("successful", "created_at", "install", false, "bp1", "id1",
+ "tenant1", "error", "execution_id1", null, false, false);
+
+ List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>();
+
+ cldExecutionList.add(cldExecution);
+
+ CloudifyExecutionList cloudifyExecutionList =
+ new CloudifyExecutionList(cldExecutionList, null);
+
+ when(cfyClient.getTenants()).thenReturn(cloudifyTenantList);
+
+ when(cfyClient.getTenantInfoFromDeploy(Mockito.any())).thenReturn(cldDeployedTenantList);
+
+ when(cfyClient.getExecutionsSummary(Mockito.any(), Mockito.any()))
+ .thenReturn(cloudifyExecutionList).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult = subject.getTenantStatusForService(mockedRequest, deplIds);
+ assertTrue(actualResult.contains("successful"));
+
+ actualResult = subject.getTenantStatusForService(mockedRequest, deplIds);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getTenantStatusForService(mockedRequest, deplIds);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testCreateBlueprint() throws Exception {
+ ServiceTypeUploadRequest bpUploadReq = ServiceTypeUploadRequest.from(bpItem);
+
+ when(inventoryClient.addServiceType(Matchers.<ServiceTypeRequest>any()))
+ .thenThrow(BlueprintParseException.class).thenThrow(httpException)
+ .thenThrow(Exception.class).thenReturn(bpItem);
+
+ String actual1 = subject.createBlueprint(mockedRequest, bpUploadReq);
+ assertTrue(actual1.contains("error"));
+
+ String actual2 = subject.createBlueprint(mockedRequest, bpUploadReq);
+ assertTrue(actual2.contains("error"));
+
+ String actual3 = subject.createBlueprint(mockedRequest, bpUploadReq);
+ assertTrue(actual3.contains("error"));
+
+ String actual = subject.createBlueprint(mockedRequest, bpUploadReq);
+ assertTrue(actual.contains("app1"));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetBlueprintsByPage() {
+ MockHttpServletRequestWrapper mockedRequest1 = getMockedRequest();
+ mockedRequest1.addParameter("_include", "typeName,typeId,typeVersion");
+ mockedRequest1.addParameter("name", "xyz");
+
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream1).thenThrow(Exception.class).thenThrow(httpException);
+
+ String result = subject.getBlueprintsByPage(mockedRequest1);
+ assertTrue(result.contains("xyz"));
+
+ result = subject.getBlueprintsByPage(mockedRequest1);
+ assertTrue(result.contains("error"));
+
+ result = subject.getBlueprintsByPage(mockedRequest1);
+ assertTrue(result.contains("error"));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testQueryBlueprintFilter() {
+ MockHttpServletRequestWrapper mockedRequest1 = getMockedRequest();
+ mockedRequest1.addParameter("_include", "typeName,typeId,typeVersion");
+ mockedRequest1.addParameter("name", "xyz");
+
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream1).thenThrow(Exception.class).thenThrow(httpException);
+
+ String result = subject.queryBlueprintFilter(mockedRequest1);
+ assertTrue(result.contains("xyz"));
+
+ result = subject.queryBlueprintFilter(mockedRequest1);
+ assertTrue(result.contains("error"));
+
+ result = subject.queryBlueprintFilter(mockedRequest1);
+ assertTrue(result.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetDeploymentsByPage() {
+ CloudifyDeployedTenant cldDeplTenant =
+ new CloudifyDeployedTenant("dcae_dtiapi_1902", "dcae_dtiapi_1902", "tenant1");
+
+ List<CloudifyDeployedTenant> cldDeplTenantList = new ArrayList<CloudifyDeployedTenant>();
+
+ cldDeplTenantList.add(cldDeplTenant);
+
+ CloudifyDeployedTenantList cldDeployedTenantList =
+ new CloudifyDeployedTenantList(cldDeplTenantList, null);
+
+ CloudifyTenant cldTenant = new CloudifyTenant("tenant1", "tenant1", "tenant_id1");
+
+ List<CloudifyTenant> cldfyTenantList = new ArrayList<CloudifyTenant>();
+ cldfyTenantList.add(cldTenant);
+
+ CloudifyTenantList cloudifyTenantList = new CloudifyTenantList(cldfyTenantList, null);
+
+ MockHttpServletRequestWrapper mockedRequest1 = getMockedRequest();
+ mockedRequest1.addParameter("_include", "id");
+ mockedRequest1.addParameter("searchBy", "dti");
+
+ Collection<Service> items = deplList.items;
+
+ when(cfyClient.getTenants()).thenReturn(cloudifyTenantList);
+
+ when(cfyClient.getTenantInfoFromDeploy(Mockito.any())).thenReturn(cldDeployedTenantList)
+ .thenThrow(Exception.class).thenThrow(httpException).thenReturn(cldDeployedTenantList)
+ .thenReturn(cldDeployedTenantList);
+
+ Stream<Service> sampleStream1 = items.stream();
+ Stream<Service> sampleStream2 = items.stream();
+ Stream<Service> sampleStream3 = items.stream();
+
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream1)
+ .thenReturn(sampleStream2).thenReturn(sampleStream3).thenThrow(Exception.class)
+ .thenThrow(httpException);
+
+ String result = subject.getDeploymentsByPage("dcae_dtiapi_1902", mockedRequest1);
+ assertTrue(result.contains("dti"));
+
+ result = subject.getDeploymentsByPage("dcae_dtiapi_1902", mockedRequest1);
+ assertTrue(result.contains("dti"));
+
+ result = subject.getDeploymentsByPage("dcae_dtiapi_1902", mockedRequest1);
+ assertTrue(result.contains("dti"));
+
+ result = subject.getDeploymentsByPage("dcae_dtiapi_1902", mockedRequest1);
+ assertTrue(result.contains("error"));
+
+ result = subject.getDeploymentsByPage("dcae_dtiapi_1902", mockedRequest1);
+ assertTrue(result.contains("error"));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetAllDeploymentsByPage() {
+ CloudifyDeployedTenant cldDeplTenant =
+ new CloudifyDeployedTenant("dcae_dtiapi_1902", "dcae_dtiapi_1902", "tenant1");
+
+ List<CloudifyDeployedTenant> cldDeplTenantList = new ArrayList<CloudifyDeployedTenant>();
+
+ cldDeplTenantList.add(cldDeplTenant);
+
+ CloudifyDeployedTenantList cldDeployedTenantList =
+ new CloudifyDeployedTenantList(cldDeplTenantList, null);
+
+ CloudifyTenant cldTenant = new CloudifyTenant("tenant1", "tenant1", "tenant_id1");
+
+ List<CloudifyTenant> cldfyTenantList = new ArrayList<CloudifyTenant>();
+ cldfyTenantList.add(cldTenant);
+
+ CloudifyTenantList cloudifyTenantList = new CloudifyTenantList(cldfyTenantList, null);
+
+ MockHttpServletRequestWrapper mockedRequest1 = getMockedRequest();
+ mockedRequest1.addParameter("_include", "id");
+ mockedRequest1.addParameter("searchBy", "dti");
+
+ Collection<Service> items = deplList.items;
+
+ when(cfyClient.getTenants()).thenReturn(cloudifyTenantList);
+
+ when(cfyClient.getTenantInfoFromDeploy(Mockito.any())).thenReturn(cldDeployedTenantList)
+ .thenThrow(Exception.class).thenThrow(httpException).thenReturn(cldDeployedTenantList)
+ .thenReturn(cldDeployedTenantList);
+
+ Stream<Service> sampleStream1 = items.stream();
+ Stream<Service> sampleStream2 = items.stream();
+ Stream<Service> sampleStream3 = items.stream();
+
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream1)
+ .thenReturn(sampleStream2).thenReturn(sampleStream3).thenThrow(Exception.class)
+ .thenThrow(httpException);
+
+ String result = subject.getAllDeploymentsByPage(mockedRequest1);
+ assertTrue(result.contains("dti"));
+
+ result = subject.getAllDeploymentsByPage(mockedRequest1);
+ assertTrue(result.contains("dti"));
+
+ result = subject.getAllDeploymentsByPage(mockedRequest1);
+ assertTrue(result.contains("dti"));
+
+ result = subject.getAllDeploymentsByPage(mockedRequest1);
+ assertTrue(result.contains("error"));
+
+ result = subject.getAllDeploymentsByPage(mockedRequest1);
+ assertTrue(result.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetDeploymentRevisions() throws Exception {
+ CloudifyNodeInstance cfyNodeInstance = new CloudifyNodeInstance("id1", null);
+
+ List<CloudifyNodeInstance> cfyNodeInstanceItems = new ArrayList<CloudifyNodeInstance>();
+ cfyNodeInstanceItems.add(cfyNodeInstance);
+
+ CloudifyNodeInstanceList cfyNodeInstList =
+ new CloudifyNodeInstanceList(cfyNodeInstanceItems, null);
+
+ when(cfyClient.getNodeInstanceVersion(Mockito.any(), Mockito.any()))
+ .thenReturn(cfyNodeInstList).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult =
+ subject.getDeploymentRevisions("deploymentId", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("id1"));
+
+ actualResult = subject.getDeploymentRevisions("deploymentId", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.getDeploymentRevisions("deploymentId", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @Test
+ public final void testGetDeploymentInputs() throws Exception {
+
+ Map<String, Object> inputHash = new HashMap<String, Object>();
+ inputHash.put("key1", "value1");
+
+ CloudifyDeployment cldDeployment =
+ new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id",
+ inputHash, null, null, null, null, null, null, "tenant");
+
+ List<CloudifyDeployment> cfyDeployItems = new ArrayList<CloudifyDeployment>();
+ cfyDeployItems.add(cldDeployment);
+
+ CloudifyDeploymentList.Metadata.Pagination pageObj =
+ new CloudifyDeploymentList.Metadata.Pagination(1, 0, 1);
+ CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj);
+
+ CloudifyDeploymentList cldDeployList = new CloudifyDeploymentList(cfyDeployItems, metadata);
+
+ when(cfyClient.getDeploymentInputs(Matchers.any(), Matchers.any()))
+ .thenReturn(cldDeployList);
+
+ String actualResult = subject.getDeploymentInputs("deploymentId", "tenant", mockedRequest);
+ assertTrue(actualResult.contains("blueprint_id"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testModifyDeployment() throws Exception {
+ CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "install",
+ false, "bp1", "id1", "tenant1", "error", "execution_id1", null, false, false);
+
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("tenant", "tenant1");
+ params.put("workflow", "upgrade");
+
+ CloudifyExecutionRequest cfyExecReq = new CloudifyExecutionRequest("deployment_id",
+ "upgrade", false, false, "tenant1", params);
+
+ CloudifyNodeInstanceId cfyNodeInst = new CloudifyNodeInstanceId("node_instance_id1");
+
+ List<CloudifyNodeInstanceId> cfyNodeInstItems = new ArrayList<CloudifyNodeInstanceId>();
+
+ cfyNodeInstItems.add(cfyNodeInst);
+
+ CloudifyNodeInstanceIdList cfyNodeInstList =
+ new CloudifyNodeInstanceIdList(cfyNodeInstItems, null);
+
+ when(cfyClient.getNodeInstanceId(Mockito.any(), Mockito.any())).thenReturn(cfyNodeInstList);
+
+ when(cfyClient.startExecution(Matchers.<CloudifyExecutionRequest>any()))
+ .thenReturn(cfyExecObj).thenThrow(Exception.class).thenThrow(httpException);
+
+ String inputParamStr = "{\"tenant\": \"tenant1\", \"workflow\":\"upgrade\"}";
+
+ InputStream is = new ByteArrayInputStream(inputParamStr.getBytes());
+
+ String actualResult = subject.modifyDeployment("depId", mockedRequest, is);
+ assertTrue(actualResult.contains("execution_id1"));
+
+ actualResult = subject.modifyDeployment("depId", mockedRequest, is);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.modifyDeployment("depId", mockedRequest, is);
+ assertTrue(actualResult.contains("error"));
+
+ }
+
+ @Test
+ public final void testGetServicesForType() throws Exception {
+ ServiceRef expectedSrvc = new ServiceRef("dcae_dtiapi_1902", "432423", "433434");
+ Collection<ServiceRef> expectedSrvcIds = new ArrayList<ServiceRef>();
+ expectedSrvcIds.add(expectedSrvc);
+ ServiceRefList expectedSrvcRefList = new ServiceRefList(expectedSrvcIds, 1);
+
+ when(inventoryClient.getServicesForType(Matchers.<ServiceQueryParams>any()))
+ .thenReturn(expectedSrvcRefList);
+ String actual = subject.getServicesForType(mockedRequest, "typeId1");
+ assertTrue(actual.contains("typeId1"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testCreateDeployment() throws Exception {
+ DeploymentInput deployInput1 = new DeploymentInput("component1", "tag1",
+ "xyz1731-helm-1906", 1906, "blueprintId", null, "tenant1");
+
+ DeploymentInput deployInput2 = new DeploymentInput("component1", "tag1",
+ "xyz1731-helm-1906", 1906, null, null, "tenant1");
+
+ DeploymentResponseLinks expectLink = new DeploymentResponseLinks("self", "status");
+ DeploymentResponse expectResp = new DeploymentResponse("req1", expectLink);
+
+ Collection<ServiceType> items = bpList2.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream1);
+
+ String actualResp0 = subject.createDeployment(mockedRequest, deployInput2);
+ assertTrue(actualResp0.contains("error"));
+
+ StringBuffer expectedStrBuff = new StringBuffer();
+ expectedStrBuff.append("http://oom.s2.com");
+ when(mockedRequest.getRequestURL()).thenReturn(expectedStrBuff);
+
+ when(deploymentHandlerClient.putDeployment(Matchers.anyString(), Matchers.anyString(),
+ Matchers.<DeploymentRequest>any())).thenReturn(expectResp).thenThrow(badReqError)
+ .thenThrow(srvcExistError).thenThrow(serverError).thenThrow(downStrmError)
+ .thenThrow(Exception.class);
+
+ String actualResp = subject.createDeployment(mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("component1"));
+
+ actualResp = subject.createDeployment(mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.createDeployment(mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.createDeployment(mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.createDeployment(mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.createDeployment(mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testUpdateDeployment() throws Exception {
+
+ DeploymentInput deployInput1 = new DeploymentInput("component1", "tag1",
+ "xyz1731-helm-1906", 1906, "blueprintId", null, "tenant1");
+
+ DeploymentResponseLinks expectLink = new DeploymentResponseLinks("self", "status");
+ DeploymentResponse expectResp = new DeploymentResponse("req1", expectLink);
+
+ Collection<ServiceType> items = bpList2.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream1);
+
+ when(deploymentHandlerClient.updateDeployment(Matchers.anyString(), Matchers.anyString(),
+ Matchers.<DeploymentRequest>any())).thenReturn(expectResp).thenThrow(badReqError)
+ .thenThrow(srvcExistError).thenThrow(serverError).thenThrow(downStrmError)
+ .thenThrow(Exception.class);
+
+ String actualResp = subject.updateDeployment("id1", mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("req1"));
+
+ actualResp = subject.updateDeployment("id1", mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.updateDeployment("id1", mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.updateDeployment("id1", mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.updateDeployment("id1", mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.updateDeployment("id1", mockedRequest, deployInput1);
+ assertTrue(actualResp.contains("error"));
+ }
+
+ @Test
+ public final void testGetExecutionByDeploymentId() throws Exception {
+
+ CloudifyExecution cldExecution =
+ new CloudifyExecution("successful", "created_at", "install", false, "bp1", "id1",
+ "tenant1", "error", "execution_id1", null, false, false);
+
+ List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>();
+
+ cldExecutionList.add(cldExecution);
+
+ CloudifyExecutionList cloudifyExecutionList =
+ new CloudifyExecutionList(cldExecutionList, null);
+
+ when(cfyClient.getExecutionsSummary(Mockito.any(), Mockito.any()))
+ .thenReturn(cloudifyExecutionList);
+
+ String actualResult =
+ subject.getExecutionByDeploymentId("dep_id", "tenant1", mockedRequest);
+ assertTrue(actualResult.contains("execution_id1"));
+ }
+
+ @Test
+ public final void testDeleteBlueprint() throws Exception {
+ String expected = "{\"202\": \"OK\"}";
+ doNothing().doThrow(serviceTypeException).doThrow(Exception.class).when(inventoryClient)
+ .deleteServiceType(Matchers.anyString());
+
+ String actual = subject.deleteBlueprint("srvcId", mockedRequest, mockedResponse);
+ assertEquals(expected, actual);
+
+ actual = subject.deleteBlueprint("srvcId", mockedRequest, mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteBlueprint("srvcId", mockedRequest, mockedResponse);
+ assertTrue(actual.contains("error"));
+ }
+
+ @Test
+ public final void testDeleteDeployment() throws Exception {
+ doNothing().doThrow(badReqError).doThrow(serverError).doThrow(downStrmError)
+ .doThrow(notFoundError).doThrow(Exception.class).when(deploymentHandlerClient)
+ .deleteDeployment(Matchers.anyString(), Matchers.anyString());
+
+ StringBuffer expectedStrBuff = new StringBuffer();
+ expectedStrBuff.append("http://oom.s2.com");
+ when(mockedRequest.getRequestURL()).thenReturn(expectedStrBuff);
+
+ String actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertFalse(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testCancelExecution() throws Exception {
+ List<String> tenants = new ArrayList<String>();
+ tenants.add("tenant1");
+
+ HttpHeaders httpHeader = new HttpHeaders();
+ httpHeader.put("tenant", tenants);
+
+ CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "cancel",
+ false, "bp1", "id1", "tenant1", "error", "execution_id1", null, false, false);
+
+ when(cfyClient.cancelExecution(Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(cfyExecObj).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult =
+ subject.cancelExecution(httpHeader, "id1", null, mockedRequest, mockedResponse);
+ assertTrue(actualResult.contains("execution_id1"));
+
+ actualResult =
+ subject.cancelExecution(httpHeader, "id1", null, mockedRequest, mockedResponse);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult =
+ subject.cancelExecution(httpHeader, "id1", null, mockedRequest, mockedResponse);
+ assertTrue(actualResult.contains("error"));
+ }
+
+}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ConsulControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ConsulControllerTest.java
new file mode 100644
index 0000000..3d71a2e
--- /dev/null
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ConsulControllerTest.java
@@ -0,0 +1,315 @@
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+
+package org.onap.ccsdk.dashboard.controller;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.ccsdk.dashboard.core.MockUser;
+import org.onap.ccsdk.dashboard.core.MockitoTestSuite;
+import org.onap.ccsdk.dashboard.model.ConsulDatacenter;
+import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration;
+import org.onap.ccsdk.dashboard.model.ConsulNodeInfo;
+import org.onap.ccsdk.dashboard.model.ConsulServiceHealth;
+import org.onap.ccsdk.dashboard.model.ConsulServiceInfo;
+import org.onap.ccsdk.dashboard.model.RestResponseSuccess;
+import org.onap.ccsdk.dashboard.rest.ConsulClient;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.client.HttpClientErrorException;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+
+public class ConsulControllerTest extends MockitoTestSuite {
+
+ @Mock
+ ConsulClient consulClient;
+
+ @InjectMocks
+ ConsulController subject = new ConsulController();
+
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+
+ MockUser mockUser = new MockUser();
+ HttpClientErrorException httpException;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ objectMapper.registerModule(new Jdk8Module());
+ mockedRequest = getMockedRequest();
+ mockedResponse = getMockedResponse();
+ httpException = new HttpClientErrorException(HttpStatus.BAD_REQUEST, "statusText");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetServiceHealthDetails() throws Exception {
+ ConsulServiceHealth consulSrvcHlth = new ConsulServiceHealth("cjlvmcnsl00",
+ "service:pgaas1_Service_ID", "Service 'pgaasServer1' check", "passing",
+ "This is a pgaas1_Service_ID health check",
+ "HTTP GET http://srvc.com:8000/healthcheck/status: 200 OK Output: { \"output\": \"Thu Apr 20 19:53:01 UTC 2017|INFO|masters=1 pgaas1.com|secondaries=0 |maintenance= |down=1 pgaas2.com| \" }\n",
+ "pgaas1_Service_ID", "pgaasServer1", 190199, 199395);
+
+ List<ConsulServiceHealth> expectedCnslSrvcHlth = new ArrayList<ConsulServiceHealth>();
+ expectedCnslSrvcHlth.add(consulSrvcHlth);
+
+ when(consulClient.getServiceHealth(Matchers.anyString(), Matchers.anyString()))
+ .thenReturn(expectedCnslSrvcHlth).thenThrow(Exception.class);
+
+ String actualResult = subject.getServiceHealthDetails(mockedRequest, "dc1", "srvc1");
+ assertTrue(actualResult.contains("pgaasServer1"));
+
+ actualResult = subject.getServiceHealthDetails(mockedRequest, "dc1", "srvc1");
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetServicesHealth() throws Exception {
+
+ List<String> srvcIps = new ArrayList<String>();
+ srvcIps.add("135.91.224.136");
+ srvcIps.add("135.91.224.138");
+ ConsulServiceInfo consulSrvcInfo = new ConsulServiceInfo("pgaasServer1", srvcIps);
+
+ List<ConsulServiceInfo> expectedCnslSrvcs = new ArrayList<ConsulServiceInfo>();
+ expectedCnslSrvcs.add(consulSrvcInfo);
+
+ ConsulServiceHealth consulSrvcHlth = new ConsulServiceHealth("cjlvmcnsl00",
+ "service:pgaas1_Service_ID", "Service 'pgaasServer1' check", "passing",
+ "This is a pgaas1_Service_ID health check",
+ "HTTP GET http://srvc.com:8000/healthcheck/status: 200 OK Output: { \"output\": \"Thu Apr 20 19:53:01 UTC 2017|INFO|masters=1 pgaas1.com|secondaries=0 |maintenance= |down=1 pgaas2.com| \" }\n",
+ "pgaas1_Service_ID", "pgaasServer1", 190199, 199395);
+
+ List<ConsulServiceHealth> expectedCnslSrvcHlth = new ArrayList<ConsulServiceHealth>();
+ expectedCnslSrvcHlth.add(consulSrvcHlth);
+
+ when(consulClient.getServices(Matchers.anyString())).thenReturn(expectedCnslSrvcs);
+ when(consulClient.getServiceHealth(Matchers.anyString(), Matchers.anyString()))
+ .thenReturn(expectedCnslSrvcHlth).thenThrow(Exception.class);
+
+ String actualResult = subject.getServicesHealth(mockedRequest, "dc1");
+ assertTrue(actualResult.contains("pgaasServer1"));
+
+ actualResult = subject.getServicesHealth(mockedRequest, "dc1");
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @Test
+ public final void testGetNodesInfo() {
+ User user = mockUser.mockUser();
+ user.setLoginId("tester");
+ user.setId(1000L);
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ ConsulNodeInfo cnslNode = new ConsulNodeInfo("a2788806-6e2e-423e-8ee7-6cad6f3d3de6",
+ "cjlvmcnsl00", "10.170.8.13", null, null, 6, 17980);
+
+ List<ConsulNodeInfo> cnslNodeList = new ArrayList<ConsulNodeInfo>();
+ cnslNodeList.add(cnslNode);
+
+ when(consulClient.getNodes(Matchers.anyString())).thenReturn(cnslNodeList);
+
+ String actualResult = subject.getNodesInfo(mockedRequest, "dc1");
+ assertTrue(actualResult.contains("cjlvmcnsl00"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetNodeServicesHealth() throws Exception {
+ ConsulServiceHealth consulSrvcHlth = new ConsulServiceHealth("cjlvmcnsl00",
+ "service:pgaas1_Service_ID", "Service 'pgaasServer1' check", "passing",
+ "This is a pgaas1_Service_ID health check",
+ "HTTP GET http://srvc.com:8000/healthcheck/status: 200 OK Output: { \"output\": \"Thu Apr 20 19:53:01 UTC 2017|INFO|masters=1 pgaas1.com|secondaries=0 |maintenance= |down=1 pgaas2.com| \" }\n",
+ "pgaas1_Service_ID", "pgaasServer1", 190199, 199395);
+
+ List<ConsulServiceHealth> expectedCnslSrvcHlth = new ArrayList<ConsulServiceHealth>();
+ expectedCnslSrvcHlth.add(consulSrvcHlth);
+
+ when(consulClient.getNodeServicesHealth(Matchers.anyString(), Matchers.anyString()))
+ .thenReturn(expectedCnslSrvcHlth).thenThrow(Exception.class);
+
+ String actualResult = subject.getNodeServicesHealth(mockedRequest, "dc1", "node1");
+ assertTrue(actualResult.contains("pgaasServer1"));
+
+ actualResult = subject.getNodeServicesHealth(mockedRequest, "dc1", "node1");
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @Test
+ public final void testGetDatacentersHealth() {
+ User user = mockUser.mockUser();
+ user.setLoginId("tester");
+ user.setId(1000L);
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ ConsulDatacenter cnslDc = new ConsulDatacenter("dc1");
+
+ List<ConsulDatacenter> cnslDcList = new ArrayList<ConsulDatacenter>();
+ cnslDcList.add(cnslDc);
+
+ when(consulClient.getDatacenters()).thenReturn(cnslDcList);
+
+ String actualResult = subject.getDatacentersHealth(mockedRequest);
+ assertTrue(actualResult.contains("dc1"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testRegisterService() throws Exception {
+ ConsulHealthServiceRegistration.EndpointCheck endPoint =
+ new ConsulHealthServiceRegistration.EndpointCheck("endpoint1", "interval1",
+ "description1", "name1");
+ List<ConsulHealthServiceRegistration.EndpointCheck> endPointList =
+ new ArrayList<ConsulHealthServiceRegistration.EndpointCheck>();
+ endPointList.add(endPoint);
+
+ List<String> tagList = new ArrayList<String>();
+ tagList.add("tag1");
+ tagList.add("tag2");
+
+ ConsulHealthServiceRegistration.ConsulServiceRegistration servcReg =
+ new ConsulHealthServiceRegistration.ConsulServiceRegistration("id1", "name1",
+ "address1", "port1", tagList, endPointList);
+ List<ConsulHealthServiceRegistration.ConsulServiceRegistration> servcRegList =
+ new ArrayList<ConsulHealthServiceRegistration.ConsulServiceRegistration>();
+ servcRegList.add(servcReg);
+
+ ConsulHealthServiceRegistration chsrObj = new ConsulHealthServiceRegistration(servcRegList);
+
+ RestResponseSuccess expectedResp = new RestResponseSuccess("Registration yielded code 0");
+ String expectedResult = objectMapper.writeValueAsString(expectedResp);
+
+ String expectedStr = "Registration yielded code 0";
+ when(consulClient.registerService(Matchers.<ConsulHealthServiceRegistration>any()))
+ .thenReturn(expectedStr).thenThrow(Exception.class).thenThrow(httpException);
+
+ String actualResult = subject.registerService(mockedRequest, chsrObj);
+ assertTrue(actualResult.equals(expectedResult));
+
+ actualResult = subject.registerService(mockedRequest, chsrObj);
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.registerService(mockedRequest, chsrObj);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @Test
+ public final void testRegisterService_SrvcError() throws Exception {
+ ConsulHealthServiceRegistration chsrObj = new ConsulHealthServiceRegistration(null);
+
+ String actualResult = subject.registerService(mockedRequest, chsrObj);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @Test
+ @Ignore
+ public final void testRegisterService_invalidSrvcError() throws Exception {
+ ConsulHealthServiceRegistration.EndpointCheck endPoint =
+ new ConsulHealthServiceRegistration.EndpointCheck("endpoint1", "interval1",
+ "description1", "name1");
+ List<ConsulHealthServiceRegistration.EndpointCheck> endPointList =
+ new ArrayList<ConsulHealthServiceRegistration.EndpointCheck>();
+ endPointList.add(endPoint);
+
+ List<String> tagList = new ArrayList<String>();
+ tagList.add("tag1");
+ tagList.add("tag2");
+
+ ConsulHealthServiceRegistration.ConsulServiceRegistration servcReg =
+ new ConsulHealthServiceRegistration.ConsulServiceRegistration("id1", "name2",
+ "address2", "port1", tagList, endPointList);
+ List<ConsulHealthServiceRegistration.ConsulServiceRegistration> servcRegList =
+ new ArrayList<ConsulHealthServiceRegistration.ConsulServiceRegistration>();
+ servcRegList.add(servcReg);
+
+ ConsulHealthServiceRegistration chsrObj = new ConsulHealthServiceRegistration(servcRegList);
+
+ String actualResult = subject.registerService(mockedRequest, chsrObj);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @Test
+ public final void testRegisterService_invalidEndptError() throws Exception {
+ ConsulHealthServiceRegistration.EndpointCheck endPoint =
+ new ConsulHealthServiceRegistration.EndpointCheck("", "", "description1", "name1");
+ List<ConsulHealthServiceRegistration.EndpointCheck> endPointList =
+ new ArrayList<ConsulHealthServiceRegistration.EndpointCheck>();
+ endPointList.add(endPoint);
+
+ List<String> tagList = new ArrayList<String>();
+ tagList.add("tag1");
+ tagList.add("tag2");
+
+ ConsulHealthServiceRegistration.ConsulServiceRegistration servcReg =
+ new ConsulHealthServiceRegistration.ConsulServiceRegistration("id1", "", "", "port1",
+ tagList, endPointList);
+ List<ConsulHealthServiceRegistration.ConsulServiceRegistration> servcRegList =
+ new ArrayList<ConsulHealthServiceRegistration.ConsulServiceRegistration>();
+ servcRegList.add(servcReg);
+
+ ConsulHealthServiceRegistration chsrObj = new ConsulHealthServiceRegistration(servcRegList);
+
+ String actualResult = subject.registerService(mockedRequest, chsrObj);
+ assertTrue(actualResult.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testDeregisterService() throws Exception {
+ RestResponseSuccess expectedResp = new RestResponseSuccess("Deregistration yielded code 0");
+ String expectedResult = objectMapper.writeValueAsString(expectedResp);
+
+ when(consulClient.deregisterService(Mockito.any())).thenReturn(0).thenThrow(Exception.class)
+ .thenThrow(httpException);
+
+ String actualResult = subject.deregisterService(mockedRequest, "srvc1");
+ assertTrue(actualResult.equals(expectedResult));
+
+ actualResult = subject.deregisterService(mockedRequest, "srvc1");
+ assertTrue(actualResult.contains("error"));
+
+ actualResult = subject.deregisterService(mockedRequest, "srvc1");
+ assertTrue(actualResult.contains("error"));
+ }
+
+}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerControllerTest.java
new file mode 100644
index 0000000..6517b68
--- /dev/null
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerControllerTest.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+
+package org.onap.ccsdk.dashboard.controller;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.ccsdk.dashboard.core.MockitoTestSuite;
+import org.onap.ccsdk.dashboard.exceptions.BadRequestException;
+import org.onap.ccsdk.dashboard.exceptions.DeploymentNotFoundException;
+import org.onap.ccsdk.dashboard.exceptions.DownstreamException;
+import org.onap.ccsdk.dashboard.exceptions.ServerErrorException;
+import org.onap.ccsdk.dashboard.exceptions.ServiceAlreadyExistsException;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequest;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequestObject;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponse;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponseLinks;
+import org.onap.ccsdk.dashboard.rest.DeploymentHandlerClient;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+
+public class DeploymentHandlerControllerTest extends MockitoTestSuite {
+
+ @Mock
+ DeploymentHandlerClient restClient;
+
+ @InjectMocks
+ DeploymentHandlerController subject = new DeploymentHandlerController();
+
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+
+ BadRequestException badReqError;
+ ServiceAlreadyExistsException srvcExistError;
+ ServerErrorException serverError;
+ DownstreamException downStrmError;
+ JsonProcessingException jsonError;
+ DeploymentNotFoundException notFoundError;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ objectMapper.registerModule(new Jdk8Module());
+ mockedRequest = getMockedRequest();
+ mockedResponse = getMockedResponse();
+ badReqError = new BadRequestException("bad request");
+ srvcExistError = new ServiceAlreadyExistsException("service already exists");
+ serverError = new ServerErrorException("Error occured in server");
+ downStrmError = new DownstreamException("error occured in downstream");
+ notFoundError = new DeploymentNotFoundException("item not found");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testPutDeployment_create() throws Exception {
+ DeploymentRequestObject expectReq =
+ new DeploymentRequestObject("dep1", "dep1", null, "tenant1", "create");
+
+ DeploymentResponseLinks expectLink = new DeploymentResponseLinks("self", "status");
+ DeploymentResponse expectResp = new DeploymentResponse("req1", expectLink);
+
+ when(restClient.putDeployment(Matchers.anyString(), Matchers.anyString(),
+ Matchers.<DeploymentRequest>any())).thenReturn(expectResp).thenThrow(badReqError)
+ .thenThrow(srvcExistError).thenThrow(serverError).thenThrow(downStrmError)
+ .thenThrow(Exception.class);
+
+ String actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("req1"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testPutDeployment_update() throws Exception {
+ DeploymentRequestObject expectReq =
+ new DeploymentRequestObject("dep1", "dep1", null, "tenant1", "update");
+
+ DeploymentResponseLinks expectLink = new DeploymentResponseLinks("self", "status");
+ DeploymentResponse expectResp = new DeploymentResponse("req1", expectLink);
+
+ when(restClient.updateDeployment(Matchers.anyString(), Matchers.anyString(),
+ Matchers.<DeploymentRequest>any())).thenReturn(expectResp).thenThrow(badReqError)
+ .thenThrow(srvcExistError).thenThrow(serverError).thenThrow(downStrmError)
+ .thenThrow(Exception.class);
+
+ String actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("req1"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+
+ actualResp = subject.putDeployment(mockedRequest, expectReq);
+ assertTrue(actualResp.contains("error"));
+ }
+
+ @Test
+ public final void testDeleteDeployment() throws Exception {
+
+ doNothing().doThrow(badReqError).doThrow(serverError).doThrow(downStrmError)
+ .doThrow(notFoundError).doThrow(Exception.class).when(restClient)
+ .deleteDeployment(Matchers.anyString(), Matchers.anyString());
+
+ StringBuffer expectedStrBuff = new StringBuffer();
+ expectedStrBuff.append("http://oom.s2.com");
+ when(mockedRequest.getRequestURL()).thenReturn(expectedStrBuff);
+
+ String actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertFalse(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteDeployment("dep1", mockedRequest, "tenant1", mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ }
+
+}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnControllerTest.java
new file mode 100644
index 0000000..771c085
--- /dev/null
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnControllerTest.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+
+package org.onap.ccsdk.dashboard.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.onap.ccsdk.dashboard.core.MockitoTestSuite;
+import org.springframework.web.servlet.ModelAndView;
+
+public class ECDSingleSignOnControllerTest extends MockitoTestSuite {
+
+ @InjectMocks
+ ECDSingleSignOnController subject = new ECDSingleSignOnController();
+
+ @Before
+ public void setUp() throws Exception {
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testSingleSignOnLogin() throws Exception {
+
+ mockedRequest.addParameter("forwardURL", "ecd#");
+ ModelAndView actualResult = subject.singleSignOnLogin(mockedRequest, mockedResponse);
+ assertTrue(actualResult.getViewName().contains("login"));
+
+ }
+
+}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/HealthCheckControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/HealthCheckControllerTest.java
new file mode 100644
index 0000000..4e44c39
--- /dev/null
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/HealthCheckControllerTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+
+package org.onap.ccsdk.dashboard.controller;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.onap.ccsdk.dashboard.core.MockitoTestSuite;
+import org.onap.ccsdk.dashboard.model.HealthStatus;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({SystemProperties.class})
+public class HealthCheckControllerTest extends MockitoTestSuite {
+
+ @InjectMocks
+ HealthCheckController subject = new HealthCheckController();
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mockedRequest = getMockedRequest();
+ mockedResponse = getMockedResponse();
+ PowerMockito.mockStatic(SystemProperties.class);
+ when(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME))
+ .thenReturn("oom-dash");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testHealthCheck() {
+ String messg = "oom-dash health check passed";
+ HealthStatus actualResult = subject.healthCheck(mockedRequest, mockedResponse);
+ assertTrue(actualResult.statusCode == 200);
+ }
+
+}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/InventoryControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/InventoryControllerTest.java
new file mode 100644
index 0000000..01858ed
--- /dev/null
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/InventoryControllerTest.java
@@ -0,0 +1,788 @@
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+
+package org.onap.ccsdk.dashboard.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Optional;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.stream.Stream;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.ccsdk.dashboard.core.MockUser;
+import org.onap.ccsdk.dashboard.core.MockitoTestSuite;
+import org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException;
+import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceNotFoundException;
+import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeNotFoundException;
+import org.onap.ccsdk.dashboard.model.inventory.Service;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceList;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceRef;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceType;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeList;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest;
+import org.onap.ccsdk.dashboard.rest.CloudifyClient;
+import org.onap.ccsdk.dashboard.rest.InventoryClient;
+import org.onap.ccsdk.dashboard.util.DashboardProperties;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.web.support.AppUtils;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.client.HttpServerErrorException;
+import org.springframework.web.client.RestClientException;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DashboardProperties.class})
+public class InventoryControllerTest extends MockitoTestSuite {
+
+ @Mock
+ private CloudifyClient restClient;
+
+ @Mock
+ private InventoryClient inventoryClient;
+
+ @InjectMocks
+ private InventoryController subject = new InventoryController();
+
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+
+ private HttpServerErrorException httpException =
+ new HttpServerErrorException(HttpStatus.BAD_GATEWAY);
+
+ private ServiceNotFoundException serviceException =
+ new ServiceNotFoundException("Invalid deployment");
+
+ private ServiceTypeNotFoundException serviceTypeException =
+ new ServiceTypeNotFoundException("Invalid blueprint");
+
+ @Mock
+ UserUtils userUtils = new UserUtils();
+
+ @Mock
+ User epuser;
+
+ @Mock
+ AppUtils appUtils = new AppUtils();
+
+ HttpServletRequest mockedRequest;
+ HttpServletResponse mockedResponse;
+
+ MockUser mockUser = new MockUser();
+ ServiceList deplList = null;
+ Service deplItem = null;
+
+ ServiceType bpItem = null;
+ ServiceTypeList bpList = null;
+
+ ServiceTypeRequest bpUploadItem = null;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ objectMapper.registerModule(new Jdk8Module());
+ getExpectedDeployments();
+ getExpectedBueprints();
+ createBpUploadItem();
+ mockedRequest = getMockedRequest();
+ mockedResponse = getMockedResponse();
+ }
+
+ public void getExpectedDeployments()
+ throws JsonParseException, JsonMappingException, IOException {
+
+ deplItem = new Service("dcae_dtiapi_1902", null, "1552335532348", "1552335532348", null,
+ "dummyVnfId", null, "dummyVnfType", "dummyLocation", "dcae_dtiapi_1902", null);
+ Collection<Service> items = new ArrayList<Service>();
+ items.add(deplItem);
+
+ String pageLinks =
+ "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-services/?offset=25\"}}";
+ ServiceList.PaginationLinks paginationLinks =
+ objectMapper.readValue(pageLinks, ServiceList.PaginationLinks.class);
+ int totalCount = 1;
+ deplList = new ServiceList(items, totalCount, paginationLinks);
+
+ }
+
+ public void getExpectedBueprints()
+ throws JsonParseException, JsonMappingException, IOException {
+ bpItem = new ServiceType.Builder("xyz1731", "xyz1731-helm-1906", 1906,
+ "tosca_definitions_version: cloudify_dsl_1_3", "", "app1", "comp1").build();
+ Collection<ServiceType> items = new ArrayList<ServiceType>();
+ items.add(bpItem);
+
+ String pageLinks2 =
+ "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-services/?offset=25\"}}";
+ ServiceTypeList.PaginationLinks paginationLinks =
+ objectMapper.readValue(pageLinks2, ServiceTypeList.PaginationLinks.class);
+ int totalCount = 1;
+ bpList = new ServiceTypeList(items, totalCount, paginationLinks);
+ }
+
+ public void createBpUploadItem() {
+ bpUploadItem = ServiceTypeRequest.from(bpItem);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testGetServiceTypesByPage() {
+ User user = mockUser.mockUser();
+ user.setLoginId("tester");
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("searchBy", "xyz");
+ mockedRequest.addParameter("sortBy", "owner");
+
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Collection<ServiceType> items = bpList.items;
+
+ Stream<ServiceType> sampleStream1 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1);
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ HttpSession session = mockedRequest.getSession();
+ HashMap<String, Boolean> comp_deploy_tab = new HashMap<String, Boolean>();
+ comp_deploy_tab.put("comp1", true);
+
+ Set<String> userApps = new TreeSet<String>();
+ userApps.add("comp1");
+
+ when(session.getAttribute("comp_access")).thenReturn(comp_deploy_tab);
+ when(session.getAttribute("role_level")).thenReturn("app");
+ when(session.getAttribute("authComponents")).thenReturn(userApps);
+
+ Stream<ServiceType> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream2);
+ String result2 = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result2.contains("xyz"));
+ }
+
+ @Test
+ public final void testGetServiceTypesByPage_appl() {
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("sortBy", "application");
+
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1);
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Stream<ServiceType> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream2);
+ String result2 = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result2.contains("xyz"));
+ }
+
+ @Test
+ public final void testGetServiceTypesByPage_comp() {
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("sortBy", "component");
+
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1);
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Stream<ServiceType> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream2);
+ String result2 = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result2.contains("xyz"));
+ }
+
+ @Test
+ public final void testGetServiceTypesByPage_typeId() {
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("sortBy", "typeId");
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1);
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Stream<ServiceType> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream2);
+ String result2 = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result2.contains("xyz"));
+ }
+
+ @Test
+ public final void testGetServiceTypesByPage_typeName() {
+
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("sortBy", "typeName");
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1);
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Stream<ServiceType> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream2);
+ String result2 = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result2.contains("xyz"));
+
+ }
+
+ @Test
+ public final void testGetServiceTypesByPage_typeVer() {
+
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("sortBy", "typeVersion");
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1);
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Stream<ServiceType> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream2);
+ String result2 = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result2.contains("xyz"));
+
+ }
+
+ @Test
+ public final void testGetServiceTypesByPage_created() {
+
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("sortBy", "created");
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream1 = items.stream();
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1);
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Stream<ServiceType> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream2);
+ String result2 = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result2.contains("xyz"));
+ }
+
+ @Test
+ public final void testGetServiceTypesByPage_Auth() {
+
+ User user = mockUser.mockUser();
+ user.setLoginId("tester");
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("searchBy", "xyz");
+
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream = items.stream();
+
+ HttpSession session = mockedRequest.getSession();
+ HashMap<String, Boolean> comp_deploy_tab = new HashMap<String, Boolean>();
+ comp_deploy_tab.put("comp1", true);
+
+ Set<String> userApps = new TreeSet<String>();
+ userApps.add("comp1");
+
+ when(session.getAttribute("comp_access")).thenReturn(comp_deploy_tab);
+ when(session.getAttribute("role_level")).thenReturn("ops");
+ when(session.getAttribute("authComponents")).thenReturn(userApps);
+
+ Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any()))
+ .thenReturn(sampleStream);
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testGetServiceTypesByPage_Exception() {
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream = items.stream();
+ when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+ when(inventoryClient.getServiceTypes()).thenThrow(RestClientException.class)
+ .thenThrow(httpException).thenReturn(sampleStream);
+
+ String errResp = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(errResp.contains("error"));
+
+ errResp = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(errResp.contains("error"));
+
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+ }
+
+ @Test
+ public final void testGetServiceTypesByPage_Filter() {
+ User user = mockUser.mockUser();
+ user.setLoginId("tester");
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("searchBy", "xyz");
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> sampleStream = items.stream();
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+ Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream);
+
+ String result = subject.getServiceTypesByPage(mockedRequest);
+ assertTrue(result.contains("xyz"));
+ }
+
+ @Test
+ public final void testGetServicesByPage_auth() throws IOException {
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+ MockHttpServletRequestWrapper mockedRequest1 = getMockedRequest();
+ mockedRequest1.addParameter("searchBy", "dti");
+
+ Collection<Service> items = deplList.items;
+
+ HttpSession session = mockedRequest1.getSession();
+ HashMap<String, Boolean> comp_deploy_tab = new HashMap<String, Boolean>();
+ comp_deploy_tab.put("dcae", true);
+
+ Set<String> userApps = new TreeSet<String>();
+ userApps.add("dcae");
+
+ when(session.getAttribute("comp_access")).thenReturn(comp_deploy_tab);
+ when(session.getAttribute("role_level")).thenReturn("app");
+ when(session.getAttribute("authComponents")).thenReturn(userApps);
+
+ Stream<Service> sampleStream1 = items.stream();
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream1);
+
+ String result1 = subject.getServicesByPage(mockedRequest1);
+ assertTrue(result1.contains("dti"));
+
+ }
+
+ @Test
+ public final void testGetServicesByPage_auth_ops() throws IOException {
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+ MockHttpServletRequestWrapper mockedRequest1 = getMockedRequest();
+ mockedRequest1.addParameter("searchBy", "dti");
+
+ Collection<Service> items = deplList.items;
+
+ HttpSession session = mockedRequest1.getSession();
+ HashMap<String, Boolean> comp_deploy_tab = new HashMap<String, Boolean>();
+ comp_deploy_tab.put("dcae", true);
+
+ Set<String> userApps = new TreeSet<String>();
+ userApps.add("dcae");
+
+ when(session.getAttribute("comp_access")).thenReturn(comp_deploy_tab);
+ when(session.getAttribute("role_level")).thenReturn("ops");
+ when(session.getAttribute("authComponents")).thenReturn(userApps);
+
+ Stream<Service> sampleStream1 = items.stream();
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream1);
+
+ String result1 = subject.getServicesByPage(mockedRequest1);
+ assertTrue(result1.contains("dti"));
+
+ }
+
+ @Test
+ public final void testGetServicesByPage() throws IOException {
+ /*
+ * User user = mockUser.mockUser(); user.setLoginId("tester");
+ */
+ MockHttpServletRequestWrapper mockedRequest1 = getMockedRequest();
+ mockedRequest1.addParameter("searchBy", "dti");
+ mockedRequest1.addParameter("sortBy", "deploymentRef");
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Collection<Service> items = deplList.items;
+
+ Stream<Service> sampleStream1 = items.stream();
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream1);
+
+ String result1 = subject.getServicesByPage(mockedRequest1);
+ assertTrue(result1.contains("dti"));
+ }
+
+ @Test
+ public final void testGetServicesByPage_sort_serviceId() throws IOException {
+
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("sortBy", "serviceId");
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Collection<Service> items = deplList.items;
+
+ Stream<Service> sampleStream1 = items.stream();
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream1);
+
+ String result = subject.getServicesByPage(mockedRequest);
+ assertTrue(result.contains("dti"));
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Stream<Service> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream2);
+
+ String result2 = subject.getServicesByPage(mockedRequest);
+ assertTrue(result2.contains("dti"));
+ }
+
+ @Test
+ public final void testGetServicesByPage_sort_created() throws IOException {
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("sortBy", "created");
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Collection<Service> items = deplList.items;
+
+ Stream<Service> sampleStream = items.stream();
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream);
+
+ String result = subject.getServicesByPage(mockedRequest);
+ assertTrue(result.contains("dti"));
+
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Stream<Service> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream2);
+
+ String result2 = subject.getServicesByPage(mockedRequest);
+ assertTrue(result2.contains("dti"));
+
+ }
+
+ @Test
+ public final void testGetServicesByPage_sort_modified() throws IOException {
+
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ mockedRequest.addParameter("sortBy", "modified");
+
+ PowerMockito.mockStatic(DashboardProperties.class);
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("os");
+
+ Collection<Service> items = deplList.items;
+
+ Stream<Service> sampleStream = items.stream();
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream);
+
+ String result = subject.getServicesByPage(mockedRequest);
+ assertTrue(result.contains("dti"));
+
+ Mockito
+ .when(DashboardProperties.getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "auth"))
+ .thenReturn("auth");
+
+ Stream<Service> sampleStream2 = items.stream();
+ Mockito.when(inventoryClient.getServices()).thenReturn(sampleStream2);
+
+ String result2 = subject.getServicesByPage(mockedRequest);
+ assertTrue(result2.contains("dti"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testUploadServiceTypeBlueprint() throws Exception {
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ String expected = "{\"201\": \"OK\"}";
+ when(inventoryClient.addServiceType(Matchers.<ServiceTypeRequest>any()))
+ .thenThrow(BlueprintParseException.class).thenThrow(httpException)
+ .thenThrow(Exception.class).thenReturn(null);
+
+ String actual1 = subject.uploadServiceTypeBlueprint(mockedRequest, bpUploadItem);
+ assertTrue(actual1.contains("error"));
+
+ String actual2 = subject.uploadServiceTypeBlueprint(mockedRequest, bpUploadItem);
+ assertTrue(actual2.contains("error"));
+
+ String actual3 = subject.uploadServiceTypeBlueprint(mockedRequest, bpUploadItem);
+ assertTrue(actual3.contains("error"));
+
+ String actual = subject.uploadServiceTypeBlueprint(mockedRequest, bpUploadItem);
+ assertEquals(expected, actual);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testUpdateServiceTypeBlueprint() throws Exception {
+ MockHttpServletRequestWrapper mockedRequest = getMockedRequest();
+ String expected = "{\"201\": \"OK\"}";
+ Mockito.when(inventoryClient.addServiceType(Matchers.<ServiceType>any()))
+ .thenThrow(BlueprintParseException.class).thenThrow(httpException)
+ .thenThrow(Exception.class).thenReturn(null);
+
+ String actual1 = subject.updateServiceTypeBlueprint(mockedRequest, bpItem);
+ assertTrue(actual1.contains("error"));
+
+ String actual2 = subject.updateServiceTypeBlueprint(mockedRequest, bpItem);
+ assertTrue(actual2.contains("error"));
+
+ String actual3 = subject.updateServiceTypeBlueprint(mockedRequest, bpItem);
+ assertTrue(actual3.contains("error"));
+
+ String actual = subject.updateServiceTypeBlueprint(mockedRequest, bpItem);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public final void testDeleteService() throws Exception {
+ String expected = "{\"202\": \"OK\"}";
+ doNothing().doThrow(serviceException).doThrow(Exception.class).when(inventoryClient)
+ .deleteService(Matchers.anyString());
+
+ String actual = subject.deleteService("srvcId", mockedRequest, mockedResponse);
+ assertEquals(expected, actual);
+
+ actual = subject.deleteService("srvcId", mockedRequest, mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteService("srvcId", mockedRequest, mockedResponse);
+ assertTrue(actual.contains("error"));
+ }
+
+ @Test
+ public final void testDeleteServiceType() throws Exception {
+ String expected = "{\"202\": \"OK\"}";
+ doNothing().doThrow(serviceTypeException).doThrow(Exception.class).when(inventoryClient)
+ .deleteServiceType(Matchers.anyString());
+
+ String actual = subject.deleteServiceType("srvcId", mockedRequest, mockedResponse);
+ assertEquals(expected, actual);
+
+ actual = subject.deleteServiceType("srvcId", mockedRequest, mockedResponse);
+ assertTrue(actual.contains("error"));
+
+ actual = subject.deleteServiceType("srvcId", mockedRequest, mockedResponse);
+ assertTrue(actual.contains("error"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public final void testViewServiceTypeBlueprintContentById() throws Exception {
+ Optional<ServiceType> expected = Optional.of(bpItem);
+ when(inventoryClient.getServiceType(Matchers.anyString())).thenReturn(expected)
+ .thenThrow(httpException).thenThrow(Exception.class);
+
+ String result = subject.viewServiceTypeBlueprintContentById("typeId", mockedRequest);
+ assertTrue(result.contains("xyz"));
+
+ result = subject.viewServiceTypeBlueprintContentById("typeId", mockedRequest);
+ assertTrue(result.contains("error"));
+
+ result = subject.viewServiceTypeBlueprintContentById("typeId", mockedRequest);
+ assertTrue(result.contains("error"));
+ }
+
+ @Test
+ public final void testGetServicesForType() throws Exception {
+ String[] testTypeIds = {"44234234"};
+ ServiceRef expectedSrvc = new ServiceRef("dcae_dtiapi_1902", "432423", "433434");
+ Collection<ServiceRef> expectedSrvcIds = new ArrayList<ServiceRef>();
+ expectedSrvcIds.add(expectedSrvc);
+ ServiceRefList expectedSrvcRefList = new ServiceRefList(expectedSrvcIds, 1);
+
+ when(inventoryClient.getServicesForType(Matchers.<ServiceQueryParams>any()))
+ .thenReturn(expectedSrvcRefList);
+ String actual = subject.getServicesForType(mockedRequest, testTypeIds);
+ assertTrue(actual.contains(testTypeIds[0]));
+ }
+
+ /*
+ * @Test public final void testGetItemListForPageWrapper() {
+ * fail("Not yet implemented"); // TODO }
+ *
+ * @Test public final void testGetServicesForType() {
+ * fail("Not yet implemented"); // TODO }
+ *
+ *
+ *
+ * @Test public final void testViewServiceTypeBlueprintContentById() {
+ * fail("Not yet implemented"); // TODO }
+ *
+ * @Test public final void testDeleteServiceType() {
+ * fail("Not yet implemented"); // TODO }
+ *
+ * @Test public final void testDeleteService() { fail("Not yet implemented"); //
+ * TODO }
+ *
+ * @Test public final void testUpdateServiceTypeBlueprint() {
+ * fail("Not yet implemented"); // TODO }
+ *
+ * @Test public final void testUploadServiceTypeBlueprint() {
+ * fail("Not yet implemented"); // TODO }
+ *
+ * @Test public final void testGetAppProperties() { fail("Not yet implemented");
+ * // TODO }
+ *
+ * @Test public final void testGetOrSetControllerEndpointSelectionLong() {
+ * fail("Not yet implemented"); // TODO }
+ *
+ * @Test public final void testGetOrSetControllerEndpointSelection() {
+ * fail("Not yet implemented"); // TODO }
+ *
+ * @Test public final void testGetInventoryClientHttpServletRequest() {
+ * fail("Not yet implemented"); // TODO }
+ *
+ * @Test public final void testGetInventoryClientLong() {
+ * fail("Not yet implemented"); // TODO }
+ */
+}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockUser.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockUser.java
index 0a331e0..050e3eb 100644
--- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockUser.java
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockUser.java
@@ -2,23 +2,24 @@
* =============LICENSE_START=========================================================
*
* =================================================================================
- * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2019 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.
+ * 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=========================================================
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*******************************************************************************/
+
package org.onap.ccsdk.dashboard.core;
import java.util.Date;
@@ -27,60 +28,60 @@ import org.onap.portalsdk.core.domain.User;
public class MockUser {
- public User mockUser() {
+ public User mockUser() {
- User ePUser = new User();
- ePUser.setOrgId(null);
- ePUser.setManagerId(null);
- ePUser.setFirstName("test");
- ePUser.setLastName("test");
- ePUser.setMiddleInitial(null);
- ePUser.setPhone(null);
- ePUser.setFax(null);
- ePUser.setCellular(null);
- ePUser.setEmail(null);
- ePUser.setAddressId(null);
- ePUser.setAlertMethodCd(null);
- ePUser.setHrid(null);
- ePUser.setOrgUserId("guestT");
- ePUser.setOrgCode(null);
- ePUser.setAddress1(null);
- ePUser.setAddress2(null);
- ePUser.setCity(null);
- ePUser.setState(null);
- ePUser.setZipCode(null);
- ePUser.setCountry(null);
- ePUser.setOrgManagerUserId(null);
- ePUser.setLocationClli(null);
- ePUser.setBusinessCountryCode(null);
- ePUser.setBusinessCountryName(null);
- ePUser.setBusinessUnit(null);
- ePUser.setBusinessUnitName(null);
- ePUser.setDepartment(null);
- ePUser.setDepartmentName(null);
- ePUser.setCompanyCode(null);
- ePUser.setCompany(null);
- ePUser.setZipCodeSuffix(null);
- ePUser.setJobTitle(null);
- ePUser.setCommandChain(null);
- ePUser.setSiloStatus(null);
- ePUser.setCostCenter(null);
- ePUser.setFinancialLocCode(null);
+ User ePUser = new User();
+ ePUser.setOrgId(null);
+ ePUser.setManagerId(null);
+ ePUser.setFirstName("test");
+ ePUser.setLastName("test");
+ ePUser.setMiddleInitial(null);
+ ePUser.setPhone(null);
+ ePUser.setFax(null);
+ ePUser.setCellular(null);
+ ePUser.setEmail(null);
+ ePUser.setAddressId(null);
+ ePUser.setAlertMethodCd(null);
+ ePUser.setHrid(null);
+ ePUser.setOrgUserId("guestT");
+ ePUser.setOrgCode(null);
+ ePUser.setAddress1(null);
+ ePUser.setAddress2(null);
+ ePUser.setCity(null);
+ ePUser.setState(null);
+ ePUser.setZipCode(null);
+ ePUser.setCountry(null);
+ ePUser.setOrgManagerUserId(null);
+ ePUser.setLocationClli(null);
+ ePUser.setBusinessCountryCode(null);
+ ePUser.setBusinessCountryName(null);
+ ePUser.setBusinessUnit(null);
+ ePUser.setBusinessUnitName(null);
+ ePUser.setDepartment(null);
+ ePUser.setDepartmentName(null);
+ ePUser.setCompanyCode(null);
+ ePUser.setCompany(null);
+ ePUser.setZipCodeSuffix(null);
+ ePUser.setJobTitle(null);
+ ePUser.setCommandChain(null);
+ ePUser.setSiloStatus(null);
+ ePUser.setCostCenter(null);
+ ePUser.setFinancialLocCode(null);
- ePUser.setLoginId(null);
- ePUser.setLoginPwd(null);
- Date date = new Date();
- ePUser.setLastLoginDate(date);
- ePUser.setActive(true);
- ePUser.setInternal(false);
- ePUser.setSelectedProfileId(null);
- ePUser.setTimeZoneId(null);
- ePUser.setOnline(true);
- ePUser.setChatId(null);
- ePUser.setUserApps(null);
- ePUser.setPseudoRoles(null);
+ ePUser.setLoginId(null);
+ ePUser.setLoginPwd(null);
+ Date date = new Date();
+ ePUser.setLastLoginDate(date);
+ ePUser.setActive(true);
+ ePUser.setInternal(false);
+ ePUser.setSelectedProfileId(null);
+ ePUser.setTimeZoneId(null);
+ ePUser.setOnline(true);
+ ePUser.setChatId(null);
+ ePUser.setUserApps(null);
+ ePUser.setPseudoRoles(null);
- ePUser.setId((long) -1);
- return ePUser;
- }
+ ePUser.setId((long) -1);
+ return ePUser;
+ }
}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockitoTestSuite.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockitoTestSuite.java
index c251a5c..e211b35 100644
--- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockitoTestSuite.java
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockitoTestSuite.java
@@ -3,7 +3,7 @@
* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
@@ -38,6 +38,10 @@
*/
package org.onap.ccsdk.dashboard.core;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
@@ -51,45 +55,77 @@ import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MockitoTestSuite {
-
- public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper(
- Mockito.mock(HttpServletRequest.class));
- public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class);
-
- public MockHttpServletRequestWrapper getMockedRequest() {
- return mockedRequest;
- }
-
- public HttpServletResponse getMockedResponse() {
- return mockedResponse;
- }
-
- public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper {
-
- HttpSession session = Mockito.mock(HttpSession.class);
-
- public MockHttpServletRequestWrapper(HttpServletRequest request) {
- super(request);
-
- }
-
- @Override
- public HttpSession getSession() {
-
- return session;
- }
-
- @Override
- public HttpSession getSession(boolean create) {
-
- return session;
- }
-
- }
-
- @Test
- public void test()
- {
- assert(true);
- }
-} \ No newline at end of file
+ public MockHttpServletRequestWrapper mockedRequest =
+ new MockHttpServletRequestWrapper(Mockito.mock(HttpServletRequest.class));
+ public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class);
+
+ public MockHttpServletRequestWrapper getMockedRequest() {
+ return mockedRequest;
+ }
+
+ public HttpServletResponse getMockedResponse() {
+ return mockedResponse;
+ }
+
+ public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper {
+
+ HashMap<String, String> params = new HashMap<>();
+
+ HttpSession session = Mockito.mock(HttpSession.class);
+
+ public MockHttpServletRequestWrapper(HttpServletRequest request) {
+ super(request);
+
+ }
+
+ @Override
+ public HttpSession getSession() {
+ return session;
+ }
+
+ @Override
+ public HttpSession getSession(boolean create) {
+
+ return session;
+ }
+
+ @Override
+ public String getParameter(final String name) {
+ // if we added one with the given name, return that one
+ if (params.get(name) != null) {
+ return (String) params.get(name);
+ } else {
+ // otherwise return what's in the original request
+ return super.getParameter(name);
+ }
+ }
+
+ public void addParameter(String name, String value) {
+ params.put(name, value);
+ }
+
+ @Override
+ public Map<String, String[]> getParameterMap() {
+ return super.getParameterMap();
+ }
+
+ @Override
+ public Enumeration<String> getParameterNames() {
+ // defaulf impl, should be overridden for an approprivate map of request params
+ // names
+ return super.getParameterNames();
+ }
+
+ @Override
+ public String[] getParameterValues(final String name) {
+ // defaulf impl, should be overridden for an approprivate map of request params
+ // values
+ return super.getParameterValues(name);
+ }
+ }
+
+ @Test
+ public void test() {
+ assert (true);
+ }
+}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java
index 5f4f737..a5c5cf8 100644
--- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java
@@ -2,38 +2,39 @@
* =============LICENSE_START=========================================================
*
* =================================================================================
- * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2019 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.
+ * 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=========================================================
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*******************************************************************************/
package org.onap.ccsdk.dashboard.rest;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -42,11 +43,31 @@ import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.onap.ccsdk.dashboard.model.CloudifyErrorCause;
+import org.onap.ccsdk.dashboard.model.CloudifyBlueprint;
+import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenant;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployment;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateRequest;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateResponse;
import org.onap.ccsdk.dashboard.model.CloudifyEvent;
import org.onap.ccsdk.dashboard.model.CloudifyEventList;
import org.onap.ccsdk.dashboard.model.CloudifyEventList.Metadata;
+import org.onap.ccsdk.dashboard.model.CloudifyExecution;
+import org.onap.ccsdk.dashboard.model.CloudifyExecutionList;
+import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeId;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeIdList;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstance;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceId;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceIdList;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceList;
import org.onap.ccsdk.dashboard.model.CloudifyTenantList;
+import org.onap.ccsdk.dashboard.util.DashboardProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
@@ -60,81 +81,396 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DashboardProperties.class})
public class CloudifyRestClientImplTest {
- @Mock
- RestTemplate mockRest;
-
- @InjectMocks
- CloudifyRestClientImpl subject =
- new CloudifyRestClientImpl("https://www.orcl.com/v3.1", "", "");
-
- protected final ObjectMapper objectMapper = new ObjectMapper();
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- objectMapper.registerModule(new Jdk8Module());
- }
-
- @Test
- public final void getEventlogsTest() throws JsonParseException, JsonMappingException, IOException {
- String executionId = "123a123a";
- String tenant = "thisTenant";
- List<CloudifyEvent> items = new ArrayList<CloudifyEvent>();
- CloudifyEvent aMockEvent = new CloudifyEvent("dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02", "dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02",
- null, "workflow_succeeded", "5f8a2e05-e187-4925-90de-ece9160aa517", "warning", "ctx.7a10e191-f12b-4142-aa5d-6e5766ebb1d4",
- "install workflow execution succeeded", "publish_l36bhr", "publish", "cloudify.interfaces.lifecycle.create",
- "2019-02-28T23:17:49.228Z", "2019-02-28T23:17:49.700Z", "cloudify_event", "install");
- items.add(aMockEvent);
- items.add(
- new CloudifyEvent("dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02", "dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02",
- null, "workflow_node_event", "5f8a2e05-e187-4925-90de-ece9160aa517", "warning", "ctx.7a10e191-f12b-4142-aa5d-6e5766ebb1d4",
- "Starting node", "publish_l36bhr", "publish", "cloudify.interfaces.lifecycle.create",
- "2019-02-28T23:17:48.391Z", "2019-02-28T23:17:48.516Z", "cloudify_event", "install"));
-
- String metaInfo = "metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}";
- Metadata metadata = null;
- //metadata = objectMapper.readValue(metaInfo, Metadata.class);
-
- CloudifyEventList expected = new CloudifyEventList(items, metadata);
-
- ResponseEntity<CloudifyEventList> response = new ResponseEntity<CloudifyEventList>(expected, HttpStatus.OK);
- Mockito.when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
- Matchers.<ParameterizedTypeReference<CloudifyEventList>>any())).thenReturn(response);
- CloudifyEventList actual = subject.getEventlogs(executionId, tenant);
-
- assertTrue(actual.items.size() == 2);
-
- }
- @Test
- public final void testGetTenants_GetData() {
- // define the entity you want the exchange to return
- String tenantsList = "{\"items\": [{\"id\": 1, \"dName\": null, \"name\": \"default_tenant\"}, {\"id\": 2, \"dName\": null, \"name\": \"dyh1b1902\"}], \"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}";
- CloudifyTenantList sampleData = null;
- try {
- sampleData = objectMapper.readValue(tenantsList, CloudifyTenantList.class);
- } catch (Exception e) {
- }
-
- ResponseEntity<CloudifyTenantList> response = new ResponseEntity<CloudifyTenantList>(sampleData, HttpStatus.OK);
- Mockito.when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
- Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any())).thenReturn(response);
-
- CloudifyTenantList res = subject.getTenants();
- assertNotNull(res);
- assertThat(res.items.get(1).name, is("dyh1b1902"));
- // Assert.assertEquals(myobjectA, res.get(0));
- }
-
- @Test(expected = RestClientException.class)
- public final void testGetTenants_withException() {
- // define the entity you want the exchange to return
- Mockito.when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
- Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any())).thenThrow(RestClientException.class);
-
- subject.getTenants();
-
-
- }
+ @Mock
+ RestTemplate mockRest;
+
+ @InjectMocks
+ CloudifyRestClientImpl subject = new CloudifyRestClientImpl();
+
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ objectMapper.registerModule(new Jdk8Module());
+ PowerMockito.mockStatic(DashboardProperties.class);
+ when(DashboardProperties.getControllerProperty("dev",
+ DashboardProperties.CONTROLLER_SUBKEY_URL)).thenReturn("https://orcl.com");
+ this.subject.init();
+ }
+
+ @Test
+ public final void getEventlogsTest()
+ throws JsonParseException, JsonMappingException, IOException {
+ String executionId = "123a123a";
+ String tenant = "thisTenant";
+ List<CloudifyEvent> items = new ArrayList<CloudifyEvent>();
+ CloudifyEvent aMockEvent = new CloudifyEvent(
+ "dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02",
+ "dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02", null, "workflow_succeeded",
+ "5f8a2e05-e187-4925-90de-ece9160aa517", "warning",
+ "ctx.7a10e191-f12b-4142-aa5d-6e5766ebb1d4", "install workflow execution succeeded",
+ "publish_l36bhr", "publish", "cloudify.interfaces.lifecycle.create",
+ "2019-02-28T23:17:49.228Z", "2019-02-28T23:17:49.700Z", "cloudify_event", "install");
+ items.add(aMockEvent);
+ items.add(new CloudifyEvent("dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02",
+ "dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02", null, "workflow_node_event",
+ "5f8a2e05-e187-4925-90de-ece9160aa517", "warning",
+ "ctx.7a10e191-f12b-4142-aa5d-6e5766ebb1d4", "Starting node", "publish_l36bhr",
+ "publish", "cloudify.interfaces.lifecycle.create", "2019-02-28T23:17:48.391Z",
+ "2019-02-28T23:17:48.516Z", "cloudify_event", "install"));
+
+ String metaInfo =
+ "metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}";
+ Metadata metadata = null;
+
+ CloudifyEventList expected = new CloudifyEventList(items, metadata);
+
+ ResponseEntity<CloudifyEventList> response =
+ new ResponseEntity<CloudifyEventList>(expected, HttpStatus.OK);
+ Mockito
+ .when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyEventList>>any()))
+ .thenReturn(response);
+ CloudifyEventList actual = subject.getEventlogs(executionId, tenant);
+ assertTrue(actual.items.size() == 2);
+
+ }
+
+ @Test
+ public final void testGetTenants_GetData() {
+ // define the entity you want the exchange to return
+ String tenantsList =
+ "{\"items\": [{\"id\": 1, \"dName\": null, \"name\": \"default_tenant\"}, {\"id\": 2, \"dName\": null, \"name\": \"dyh1b1902\"}], \"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}";
+ CloudifyTenantList sampleData = null;
+ try {
+ sampleData = objectMapper.readValue(tenantsList, CloudifyTenantList.class);
+ } catch (Exception e) {
+ }
+
+ ResponseEntity<CloudifyTenantList> response =
+ new ResponseEntity<CloudifyTenantList>(sampleData, HttpStatus.OK);
+ Mockito
+ .when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any()))
+ .thenReturn(response);
+
+ CloudifyTenantList res = subject.getTenants();
+ assertNotNull(res);
+ assertThat(res.items.get(1).name, is("dyh1b1902"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test(expected = RestClientException.class)
+ public final void testGetTenants_withException() {
+ // define the entity you want the exchange to return
+ Mockito
+ .when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any()))
+ .thenThrow(RestClientException.class);
+ subject.getTenants();
+ }
+
+ @Test
+ public final void testGetNodeInstanceId() {
+ CloudifyNodeInstanceId cfyNodeInst = new CloudifyNodeInstanceId("node_instance_id1");
+ List<CloudifyNodeInstanceId> cfyNodeInstItems = new ArrayList<CloudifyNodeInstanceId>();
+ cfyNodeInstItems.add(cfyNodeInst);
+ CloudifyNodeInstanceIdList cfyNodeInstList =
+ new CloudifyNodeInstanceIdList(cfyNodeInstItems, null);
+
+ ResponseEntity<CloudifyNodeInstanceIdList> response =
+ new ResponseEntity<CloudifyNodeInstanceIdList>(cfyNodeInstList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceIdList>>any()))
+ .thenReturn(response);
+
+ CloudifyNodeInstanceIdList actualResult =
+ subject.getNodeInstanceId("deploymentId", "nodeId", "tenant");
+ assertTrue(actualResult.items.get(0).id.equals("node_instance_id1"));
+ }
+
+ @Test
+ public final void testGetNodeInstanceVersion() {
+ CloudifyNodeInstance cfyNodeInstance = new CloudifyNodeInstance("id1", null);
+
+ List<CloudifyNodeInstance> cfyNodeInstanceItems = new ArrayList<CloudifyNodeInstance>();
+ cfyNodeInstanceItems.add(cfyNodeInstance);
+
+ CloudifyNodeInstanceList cfyNodeInstList =
+ new CloudifyNodeInstanceList(cfyNodeInstanceItems, null);
+
+ ResponseEntity<CloudifyNodeInstanceList> response =
+ new ResponseEntity<CloudifyNodeInstanceList>(cfyNodeInstList, HttpStatus.OK);
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceList>>any()))
+ .thenReturn(response);
+
+ CloudifyNodeInstanceList actualResult =
+ subject.getNodeInstanceVersion("deploymentId", "nodeId", "tenant");
+ assertTrue(actualResult.items.get(0).id.equals("id1"));
+ }
+
+ @Test
+ public final void testGetNodeInstanceVersion_blueprint() {
+ CloudifyNodeId cfyNodeId = new CloudifyNodeId("node_id");
+ List<CloudifyNodeId> cfyNodeIdItems = new ArrayList<CloudifyNodeId>();
+ cfyNodeIdItems.add(cfyNodeId);
+ CloudifyNodeIdList cfyNodeIdList = new CloudifyNodeIdList(cfyNodeIdItems, null);
+
+ ResponseEntity<CloudifyNodeIdList> response1 =
+ new ResponseEntity<CloudifyNodeIdList>(cfyNodeIdList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.contains("nodes"), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyNodeIdList>>any())).thenReturn(response1);
+
+ CloudifyNodeInstance cfyNodeInstance = new CloudifyNodeInstance("id1", null);
+
+ List<CloudifyNodeInstance> cfyNodeInstanceItems = new ArrayList<CloudifyNodeInstance>();
+ cfyNodeInstanceItems.add(cfyNodeInstance);
+
+ CloudifyNodeInstanceList cfyNodeInstList =
+ new CloudifyNodeInstanceList(cfyNodeInstanceItems, null);
+
+ ResponseEntity<CloudifyNodeInstanceList> response2 =
+ new ResponseEntity<CloudifyNodeInstanceList>(cfyNodeInstList, HttpStatus.OK);
+ when(mockRest.exchange(Matchers.contains("node-instances"), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceList>>any()))
+ .thenReturn(response2);
+
+ CloudifyNodeInstanceList actualResult =
+ subject.getNodeInstanceVersion("blueprintId", "tenant");
+ assertTrue(actualResult.items.get(0).id.equals("id1"));
+ }
+
+ @Test
+ public final void testGetNodeInstanceId_blueprint() {
+ CloudifyNodeId cfyNodeId = new CloudifyNodeId("node_id");
+ List<CloudifyNodeId> cfyNodeIdItems = new ArrayList<CloudifyNodeId>();
+ cfyNodeIdItems.add(cfyNodeId);
+ CloudifyNodeIdList cfyNodeIdList = new CloudifyNodeIdList(cfyNodeIdItems, null);
+
+ ResponseEntity<CloudifyNodeIdList> response1 =
+ new ResponseEntity<CloudifyNodeIdList>(cfyNodeIdList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.contains("nodes"), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyNodeIdList>>any())).thenReturn(response1);
+
+ CloudifyNodeInstanceId cfyNodeInst = new CloudifyNodeInstanceId("node_instance_id1");
+ List<CloudifyNodeInstanceId> cfyNodeInstItems = new ArrayList<CloudifyNodeInstanceId>();
+ cfyNodeInstItems.add(cfyNodeInst);
+ CloudifyNodeInstanceIdList cfyNodeInstList =
+ new CloudifyNodeInstanceIdList(cfyNodeInstItems, null);
+
+ ResponseEntity<CloudifyNodeInstanceIdList> response =
+ new ResponseEntity<CloudifyNodeInstanceIdList>(cfyNodeInstList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.contains("node-instances"), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceIdList>>any()))
+ .thenReturn(response);
+
+ CloudifyNodeInstanceIdList actualResult = subject.getNodeInstanceId("bpId", "tenant");
+ assertTrue(actualResult.items.get(0).id.equals("node_instance_id1"));
+ }
+
+ @Test
+ public final void testGetTenantInfoFromDeploy() {
+
+ CloudifyDeployedTenant cldDeplTenant = new CloudifyDeployedTenant("id1", "bp1", "tenant1");
+ List<CloudifyDeployedTenant> cldDeplTenantItems = new ArrayList<CloudifyDeployedTenant>();
+ cldDeplTenantItems.add(cldDeplTenant);
+ CloudifyDeployedTenantList cldDeployedTenantList =
+ new CloudifyDeployedTenantList(cldDeplTenantItems, null);
+
+ ResponseEntity<CloudifyDeployedTenantList> response =
+ new ResponseEntity<CloudifyDeployedTenantList>(cldDeployedTenantList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.contains("deployments"), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyDeployedTenantList>>any()))
+ .thenReturn(response);
+
+ CloudifyDeployedTenantList actualResults = subject.getTenantInfoFromDeploy("tenant1");
+ assertTrue(actualResults.items.get(0).blueprint_id.equals("bp1"));
+ }
+
+ @Test
+ public void testGetExecutions() {
+ CloudifyExecution cldExecution =
+ new CloudifyExecution("successful", "created_at", "install", false, "bp1", "id1",
+ "tenant1", "error", "execution_id1", null, false, false);
+
+ List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>();
+
+ cldExecutionList.add(cldExecution);
+
+ CloudifyExecutionList cloudifyExecutionList =
+ new CloudifyExecutionList(cldExecutionList, null);
+
+ ResponseEntity<CloudifyExecutionList> response =
+ new ResponseEntity<CloudifyExecutionList>(cloudifyExecutionList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.contains("deployment_id"), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyExecutionList>>any()))
+ .thenReturn(response);
+
+ CloudifyExecutionList actualResult = subject.getExecutions("deploymentId1", "tenant1");
+ assertTrue(actualResult.items.get(0).id.contains("id1"));
+ }
+
+ @Test
+ public void testGetExecutionsSummary() {
+ CloudifyExecution cldExecution =
+ new CloudifyExecution("successful", "created_at", "install", false, "bp1", "id1",
+ "tenant1", "error", "execution_id1", null, false, false);
+
+ List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>();
+
+ cldExecutionList.add(cldExecution);
+
+ CloudifyExecutionList cloudifyExecutionList =
+ new CloudifyExecutionList(cldExecutionList, null);
+
+ ResponseEntity<CloudifyExecutionList> response =
+ new ResponseEntity<CloudifyExecutionList>(cloudifyExecutionList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.contains("include"), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<CloudifyExecutionList>>any()))
+ .thenReturn(response);
+
+ CloudifyExecutionList actualResult =
+ subject.getExecutionsSummary("deploymentId1", "tenant1");
+ assertTrue(actualResult.items.get(0).id.contains("id1"));
+ }
+
+ @Test
+ public void testStartExecution() {
+ CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "install",
+ false, "bp1", "id1", "tenant1", "error", "execution_id1", null, false, false);
+
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("key1", "value1");
+
+ CloudifyExecutionRequest cfyExecReq = new CloudifyExecutionRequest("deployment_id",
+ "upgrade", false, false, "tenant1", params);
+
+ when(mockRest.postForObject(Matchers.anyString(), Matchers.<HttpEntity<?>>any(),
+ Matchers.<Class<CloudifyExecution>>any())).thenReturn(cfyExecObj);
+
+ CloudifyExecution actualResult = subject.startExecution(cfyExecReq);
+ assertTrue(actualResult.status.equals("successful"));
+ }
+
+ @Test
+ public void testUpdateDeployment() {
+ CloudifyDeploymentUpdateRequest cfyDeployUpdateReq =
+ new CloudifyDeploymentUpdateRequest("deployment_id", "update", false, false,
+ "node_instance_id1", "4", "1000", "image", 2, "my_container");
+
+ CloudifyDeploymentUpdateResponse cfyDeployUpdateResp = new CloudifyDeploymentUpdateResponse(
+ "terminated", "created_at", "update", false, "blueprint_id", "deployment_id", "", "id1",
+ null, "tenant1", "junit", false, "resource_availability");
+
+ when(mockRest.postForObject(Matchers.anyString(), Matchers.<HttpEntity<?>>any(),
+ Matchers.<Class<CloudifyDeploymentUpdateResponse>>any()))
+ .thenReturn(cfyDeployUpdateResp);
+
+ CloudifyDeploymentUpdateResponse actualResult =
+ subject.updateDeployment(cfyDeployUpdateReq);
+ assertTrue(actualResult.status.equals("terminated"));
+ }
+
+ @Test
+ @Ignore
+ public void testCancelExecution() {
+ CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "install",
+ false, "bp1", "id1", "tenant1", "error", "execution_id1", null, false, false);
+
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("key1", "value1");
+
+ ResponseEntity<CloudifyExecution> response =
+ new ResponseEntity<CloudifyExecution>(cfyExecObj, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.contains("executions"), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<?>>any(), Matchers.<Class<CloudifyExecution>>any()))
+ .thenReturn(response);
+
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("key1", "value1");
+
+ CloudifyExecution actualResult =
+ subject.cancelExecution("executionId", parameters, "tenant");
+ assertTrue(actualResult.id.equals("execution_id1"));
+ }
+
+ @Test
+ @Ignore
+ public void testGetBlueprint() {
+ CloudifyBlueprint cldBp =
+ new CloudifyBlueprint("file1", "description1", "343242", "3423423", "id1", null);
+
+ List<CloudifyBlueprint> items = new ArrayList<CloudifyBlueprint>();
+ items.add(cldBp);
+
+ CloudifyBlueprintList.Metadata.Pagination pageObj =
+ new CloudifyBlueprintList.Metadata.Pagination(1, 0, 1);
+
+ CloudifyBlueprintList.Metadata metadata = new CloudifyBlueprintList.Metadata(pageObj);
+
+ CloudifyBlueprintList cldBpList = new CloudifyBlueprintList(items, metadata);
+
+ ResponseEntity<CloudifyBlueprintList> response =
+ new ResponseEntity<CloudifyBlueprintList>(cldBpList, HttpStatus.OK);
+
+ doReturn(response).when(mockRest).exchange(Matchers.anyString(),
+ Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
+ Matchers.<Class<CloudifyBlueprintList>>any());
+
+ CloudifyBlueprintList actualResult = subject.getBlueprint("id1", "tenant1");
+ assertTrue(actualResult.items.get(0).id.equals("id1"));
+ }
+
+ @Test
+ @Ignore
+ public void testGetDeployments() {
+
+ CloudifyDeployment cldDeployment = new CloudifyDeployment("description", "blueprint_id",
+ "created_at", "updated_at", "id", null, null, null, null, null, null, null, "tenant");
+
+ List<CloudifyDeployment> cfyDeployItems = new ArrayList<CloudifyDeployment>();
+ cfyDeployItems.add(cldDeployment);
+
+ CloudifyDeploymentList.Metadata.Pagination pageObj =
+ new CloudifyDeploymentList.Metadata.Pagination(1, 0, 1);
+ CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj);
+
+ CloudifyDeploymentList cldDeployList = new CloudifyDeploymentList(cfyDeployItems, metadata);
+
+ ResponseEntity<CloudifyDeploymentList> response =
+ new ResponseEntity<CloudifyDeploymentList>(cldDeployList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.contains("deploy"), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(), Matchers.<Class<CloudifyDeploymentList>>any()))
+ .thenReturn(response);
+
+ CloudifyDeploymentList actualResult = subject.getDeployments();
+ assertTrue(actualResult.items.get(0).id.equals("id"));
+ }
}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImplTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImplTest.java
new file mode 100644
index 0000000..f90afa9
--- /dev/null
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImplTest.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+
+package org.onap.ccsdk.dashboard.rest;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.ccsdk.dashboard.model.ConsulDatacenter;
+import org.onap.ccsdk.dashboard.model.ConsulNodeInfo;
+import org.onap.ccsdk.dashboard.model.ConsulServiceHealth;
+import org.onap.ccsdk.dashboard.model.ConsulServiceInfo;
+import org.onap.ccsdk.dashboard.util.DashboardProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestTemplate;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DashboardProperties.class})
+public class ConsulRestClientImplTest {
+
+ @Mock
+ RestTemplate mockRest;
+
+ @InjectMocks
+ ConsulRestClientImpl subject = new ConsulRestClientImpl();
+
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+ HttpClientErrorException httpException;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ objectMapper.registerModule(new Jdk8Module());
+ httpException = new HttpClientErrorException(HttpStatus.BAD_REQUEST, "statusText");
+ PowerMockito.mockStatic(DashboardProperties.class);
+ when(DashboardProperties.getControllerProperty("dev",
+ DashboardProperties.CONTROLLER_SUBKEY_CONSUL_URL)).thenReturn("https://invt.com");
+ this.subject.init();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testGetServiceHealth() {
+ ConsulServiceHealth consulSrvcHlth = new ConsulServiceHealth("cjlvmcnsl00",
+ "service:pgaas1_Service_ID", "Service 'pgaasServer1' check", "passing",
+ "This is a pgaas1_Service_ID health check",
+ "HTTP GET http://srvc.com:8000/healthcheck/status: 200 OK Output: { \"output\": \"Thu Apr 20 19:53:01 UTC 2017|INFO|masters=1 pgaas1.com|secondaries=0 |maintenance= |down=1 pgaas2.com| \" }\n",
+ "pgaas1_Service_ID", "pgaasServer1", 190199, 199395);
+
+ List<ConsulServiceHealth> expectedCnslSrvcHlth = new ArrayList<ConsulServiceHealth>();
+ expectedCnslSrvcHlth.add(consulSrvcHlth);
+
+ ResponseEntity<List<ConsulServiceHealth>> response =
+ new ResponseEntity<List<ConsulServiceHealth>>(expectedCnslSrvcHlth, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<List<ConsulServiceHealth>>>any()))
+ .thenReturn(response);
+
+ List<ConsulServiceHealth> actualCnslSrvcHlth = subject.getServiceHealth("dc1", "srvc1");
+ assertTrue(actualCnslSrvcHlth.get(0).node.equals("cjlvmcnsl00"));
+ }
+
+ @Test
+ @Ignore
+ public final void testGetServices() {
+ List<String> srvcIps = new ArrayList<String>();
+ srvcIps.add("135.91.224.136");
+ srvcIps.add("135.91.224.138");
+ ConsulServiceInfo consulSrvcInfo = new ConsulServiceInfo("pgaasServer1", srvcIps);
+
+ List<ConsulServiceInfo> expectedCnslSrvcs = new ArrayList<ConsulServiceInfo>();
+ expectedCnslSrvcs.add(consulSrvcInfo);
+
+ // ResponseEntity<Map<String, Object>> response = new ResponseEntity<Map<String,
+ // Object>>(consulSrvcInfo);
+
+ subject.getServices("dc1");
+ }
+
+ @Test
+ public final void testGetNodes() {
+ ConsulNodeInfo cnslNode = new ConsulNodeInfo("a2788806-6e2e-423e-8ee7-6cad6f3d3de6",
+ "cjlvmcnsl00", "10.170.8.13", null, null, 6, 17980);
+
+ List<ConsulNodeInfo> cnslNodeList = new ArrayList<ConsulNodeInfo>();
+ cnslNodeList.add(cnslNode);
+
+ ResponseEntity<List<ConsulNodeInfo>> response =
+ new ResponseEntity<List<ConsulNodeInfo>>(cnslNodeList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<List<ConsulNodeInfo>>>any())).thenReturn(response);
+
+ List<ConsulNodeInfo> actualNodeList = subject.getNodes("dc1");
+ assertTrue(actualNodeList.get(0).node.equals("cjlvmcnsl00"));
+
+ }
+
+ @Test
+ public final void testGetNodeServicesHealth() {
+ ConsulServiceHealth consulSrvcHlth = new ConsulServiceHealth("cjlvmcnsl00",
+ "service:pgaas1_Service_ID", "Service 'pgaasServer1' check", "passing",
+ "This is a pgaas1_Service_ID health check",
+ "HTTP GET http://srvc.com:8000/healthcheck/status: 200 OK Output: { \"output\": \"Thu Apr 20 19:53:01 UTC 2017|INFO|masters=1 pgaas1.com|secondaries=0 |maintenance= |down=1 pgaas2.com| \" }\n",
+ "pgaas1_Service_ID", "pgaasServer1", 190199, 199395);
+
+ List<ConsulServiceHealth> expectedCnslSrvcHlth = new ArrayList<ConsulServiceHealth>();
+ expectedCnslSrvcHlth.add(consulSrvcHlth);
+
+ ResponseEntity<List<ConsulServiceHealth>> response =
+ new ResponseEntity<List<ConsulServiceHealth>>(expectedCnslSrvcHlth, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<List<ConsulServiceHealth>>>any()))
+ .thenReturn(response);
+
+ List<ConsulServiceHealth> actualNodeHlthList =
+ subject.getNodeServicesHealth("dc1", "nodeId1");
+ assertTrue(actualNodeHlthList.get(0).node.equals("cjlvmcnsl00"));
+ }
+
+ @Test
+ public final void testGetDatacenters() {
+ ConsulDatacenter cnslDc = new ConsulDatacenter("dc1");
+
+ List<ConsulDatacenter> cnslDcList = new ArrayList<ConsulDatacenter>();
+ cnslDcList.add(cnslDc);
+ List<String> dcItems = new ArrayList<String>();
+ dcItems.add("dc1");
+
+ ResponseEntity<List<String>> response =
+ new ResponseEntity<List<String>>(dcItems, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<List<String>>>any())).thenReturn(response);
+ List<ConsulDatacenter> actualDcList = subject.getDatacenters();
+ assertTrue(actualDcList.get(0).name.equals("dc1"));
+ }
+
+ @Test
+ @Ignore
+ public final void testRegisterService() {
+ fail("Not yet implemented"); // TODO
+ }
+
+ @Test
+ public final void testDeregisterService() {
+
+ JSONObject jsonResp = new JSONObject();
+
+ ResponseEntity<JSONObject> result = new ResponseEntity<JSONObject>(jsonResp, HttpStatus.OK);
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<JSONObject>>any()))
+ .thenReturn(result);
+
+ int actualCode = subject.deregisterService("service1");
+ assertTrue(actualCode == 200);
+ }
+
+}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImplTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImplTest.java
new file mode 100644
index 0000000..7bd085b
--- /dev/null
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImplTest.java
@@ -0,0 +1,366 @@
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+
+package org.onap.ccsdk.dashboard.rest;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.stream.Stream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.onap.ccsdk.dashboard.exceptions.BadRequestException;
+import org.onap.ccsdk.dashboard.exceptions.DeploymentNotFoundException;
+import org.onap.ccsdk.dashboard.exceptions.DownstreamException;
+import org.onap.ccsdk.dashboard.exceptions.ServerErrorException;
+import org.onap.ccsdk.dashboard.exceptions.ServiceAlreadyExistsException;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentLink;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequest;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponse;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponseLinks;
+import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentsListResponse;
+import org.onap.ccsdk.dashboard.util.DashboardProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DashboardProperties.class})
+public class DeploymentHandlerClientImplTest {
+
+ @Mock
+ RestTemplate mockRest;
+
+ @InjectMocks
+ DeploymentHandlerClientImpl subject;
+
+ @Before
+ public void setUp() throws Exception {
+ PowerMockito.mockStatic(DashboardProperties.class);
+ when(DashboardProperties.getControllerProperty("dev",
+ DashboardProperties.CONTROLLER_SUBKEY_DHANDLER_URL)).thenReturn("https://dplh.com");
+ this.subject.init();
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public final void testGetDeployments() {
+ Collection<DeploymentLink> expectedDeplRefs = new ArrayList<DeploymentLink>();
+ expectedDeplRefs.add(new DeploymentLink("http://dplh.com/dpl1"));
+ expectedDeplRefs.add(new DeploymentLink("http://dplh.com/dpl11"));
+
+ DeploymentsListResponse expectedDeplList =
+ new DeploymentsListResponse("req1", expectedDeplRefs);
+
+ ResponseEntity<DeploymentsListResponse> response =
+ new ResponseEntity<DeploymentsListResponse>(expectedDeplList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentsListResponse>>any()))
+ .thenReturn(response);
+
+ Stream<DeploymentLink> actualResult = subject.getDeployments();
+ assertTrue(actualResult.findFirst().get().getHref().contains("dpl1"));
+ }
+
+ @Test
+ public final void testGetDeploymentsString() {
+ Collection<DeploymentLink> expectedDeplRefs = new ArrayList<DeploymentLink>();
+ expectedDeplRefs.add(new DeploymentLink("http://dplh.com/dpl1"));
+ expectedDeplRefs.add(new DeploymentLink("http://dplh.com/dpl11"));
+
+ DeploymentsListResponse expectedDeplList =
+ new DeploymentsListResponse("req1", expectedDeplRefs);
+
+ ResponseEntity<DeploymentsListResponse> response =
+ new ResponseEntity<DeploymentsListResponse>(expectedDeplList, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentsListResponse>>any()))
+ .thenReturn(response);
+
+ Stream<DeploymentLink> actualResult = subject.getDeployments("serviceTypeId");
+ assertTrue(actualResult.findFirst().get().getHref().contains("dpl1"));
+ }
+
+ @Test
+ public final void testPutDeployment() throws Exception {
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ DeploymentResponseLinks newDeplItemLink =
+ new DeploymentResponseLinks("selfUrl", "statusUrl");
+ DeploymentResponse expectedDeplItem = new DeploymentResponse("req1", newDeplItemLink);
+
+ ResponseEntity<DeploymentResponse> response =
+ new ResponseEntity<DeploymentResponse>(expectedDeplItem, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any())).thenReturn(response);
+
+ DeploymentResponse actualResponse = subject.putDeployment("dpl12", "tenant12", deplReq);
+ assertTrue(actualResponse.getRequestId().equals("req1"));
+ }
+
+ @Test(expected = DownstreamException.class)
+ public final void testPutDeployment_downstreamError() throws Exception {
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ HttpServerErrorException httpException =
+ new HttpServerErrorException(HttpStatus.BAD_GATEWAY, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.putDeployment("dpl12", "tenant12", deplReq);
+ }
+
+ @Test(expected = BadRequestException.class)
+ public final void testPutDeployment_badReqError() throws Exception {
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ HttpClientErrorException httpException =
+ new HttpClientErrorException(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.putDeployment("dpl12", "tenant12", deplReq);
+ }
+
+ @Test(expected = ServiceAlreadyExistsException.class)
+ public final void testPutDeployment_srvcExistError() throws Exception {
+
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ HttpClientErrorException httpException =
+ new HttpClientErrorException(HttpStatus.CONFLICT, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.putDeployment("dpl12", "tenant12", deplReq);
+ }
+
+ @Test(expected = ServerErrorException.class)
+ public final void testPutDeployment_srvcError() throws Exception {
+
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ HttpServerErrorException httpException =
+ new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.putDeployment("dpl12", "tenant12", deplReq);
+ }
+
+ @Test
+ public final void testUpdateDeployment() throws Exception {
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ DeploymentResponseLinks newDeplItemLink =
+ new DeploymentResponseLinks("selfUrl", "statusUrl");
+ DeploymentResponse expectedDeplItem = new DeploymentResponse("req1", newDeplItemLink);
+
+ ResponseEntity<DeploymentResponse> response =
+ new ResponseEntity<DeploymentResponse>(expectedDeplItem, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any())).thenReturn(response);
+
+ DeploymentResponse actualResponse = subject.updateDeployment("dpl12", "tenant12", deplReq);
+ assertTrue(actualResponse.getRequestId().equals("req1"));
+ }
+
+ @Test(expected = DownstreamException.class)
+ public final void testUpdateDeployment_downstreamError() throws Exception {
+
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ HttpServerErrorException httpException =
+ new HttpServerErrorException(HttpStatus.BAD_GATEWAY, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.updateDeployment("dpl12", "tenant12", deplReq);
+
+ }
+
+ @Test(expected = BadRequestException.class)
+ public final void testUpdateDeployment_badReqError() throws Exception {
+
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ HttpClientErrorException httpException =
+ new HttpClientErrorException(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.updateDeployment("dpl12", "tenant12", deplReq);
+
+ }
+
+ @Test(expected = ServiceAlreadyExistsException.class)
+ public final void testUpdateDeployment_srvcExistError() throws Exception {
+
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ HttpClientErrorException httpException =
+ new HttpClientErrorException(HttpStatus.CONFLICT, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.updateDeployment("dpl12", "tenant12", deplReq);
+
+ }
+
+ @Test(expected = ServerErrorException.class)
+ public final void testUpdateDeployment_srvcError() throws Exception {
+
+ DeploymentRequest deplReq = new DeploymentRequest("serviceTypeId", null);
+
+ HttpServerErrorException httpException =
+ new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.updateDeployment("dpl12", "tenant12", deplReq);
+
+ }
+
+ @Test
+ public final void testDeleteDeployment() throws Exception {
+ DeploymentResponseLinks newDeplItemLink =
+ new DeploymentResponseLinks("selfUrl", "statusUrl");
+ DeploymentResponse expectedDeplItem = new DeploymentResponse("req1", newDeplItemLink);
+
+ ResponseEntity<DeploymentResponse> response =
+ new ResponseEntity<DeploymentResponse>(expectedDeplItem, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any())).thenReturn(response);
+
+ subject.deleteDeployment("deploymentId", "tenant");
+ }
+
+ @Test(expected = ServerErrorException.class)
+ public final void testDeleteDeployment_serverError() throws Exception {
+ HttpServerErrorException httpException =
+ new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.deleteDeployment("deploymentId", "tenant");
+ }
+
+ @Test(expected = DeploymentNotFoundException.class)
+ public final void testDeleteDeployment_notFoundError() throws Exception {
+
+ HttpServerErrorException httpException =
+ new HttpServerErrorException(HttpStatus.NOT_FOUND, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.deleteDeployment("deploymentId", "tenant");
+ }
+
+ @Test(expected = BadRequestException.class)
+ public final void testDeleteDeployment_badReqError() throws Exception {
+
+ HttpClientErrorException httpException =
+ new HttpClientErrorException(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.deleteDeployment("deploymentId", "tenant");
+ }
+
+ @Test(expected = DownstreamException.class)
+ public final void testDeleteDeployment_downstreamError() throws Exception {
+
+ HttpServerErrorException httpException =
+ new HttpServerErrorException(HttpStatus.BAD_GATEWAY, "statusText");
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<DeploymentResponse>>any()))
+ .thenThrow(httpException);
+
+ subject.deleteDeployment("deploymentId", "tenant");
+ }
+
+}
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImplTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImplTest.java
new file mode 100644
index 0000000..d4c5e14
--- /dev/null
+++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImplTest.java
@@ -0,0 +1,361 @@
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+
+package org.onap.ccsdk.dashboard.rest;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.ccsdk.dashboard.model.inventory.ApiResponseMessage;
+import org.onap.ccsdk.dashboard.model.inventory.Service;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceList;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceRef;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceType;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeList;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams;
+import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest;
+import org.onap.ccsdk.dashboard.util.DashboardProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DashboardProperties.class})
+public class RestInventoryClientImplTest {
+
+ @Mock
+ RestTemplate mockRest;
+
+ @InjectMocks
+ RestInventoryClientImpl subject = new RestInventoryClientImpl();
+
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+
+ ServiceList deplList = null;
+ ServiceList deplListNext = null;
+ Service deplItem = null;
+
+ ServiceType bpItem = null;
+ ServiceTypeList bpList = null;
+ ServiceTypeList bpListNext = null;
+
+ ServiceTypeRequest bpUploadItem = null;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ objectMapper.registerModule(new Jdk8Module());
+ getExpectedBueprints();
+ getExpectedDeployments();
+ PowerMockito.mockStatic(DashboardProperties.class);
+ when(DashboardProperties.getControllerProperty("dev",
+ DashboardProperties.CONTROLLER_SUBKEY_INVENTORY_URL)).thenReturn("https://invt.com");
+ this.subject.init();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ public void getExpectedDeployments()
+ throws JsonParseException, JsonMappingException, IOException {
+ deplItem = new Service("dcae_dtiapi_1902", null, "1552335532348", "1552335532348", null,
+ "dummyVnfId", null, "dummyVnfType", "dummyLocation", "dcae_dtiapi_1902", null);
+ Collection<Service> items = new ArrayList<Service>();
+ items.add(deplItem);
+
+ String pageLinks =
+ "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-services/?offset=25\"}}";
+ String pageLinks2 = "{\"previousLink\":null,\"nextLink\":null}";
+
+ ServiceList.PaginationLinks paginationLinks =
+ objectMapper.readValue(pageLinks, ServiceList.PaginationLinks.class);
+ ServiceList.PaginationLinks paginationLinks2 =
+ objectMapper.readValue(pageLinks2, ServiceList.PaginationLinks.class);
+
+ int totalCount = 2;
+ deplList = new ServiceList(items, totalCount, paginationLinks);
+ deplListNext = new ServiceList(items, totalCount, paginationLinks2);
+ }
+
+ public void getExpectedBueprints()
+ throws JsonParseException, JsonMappingException, IOException {
+ bpItem = new ServiceType.Builder("xyz1731", "xyz1731-helm-1906", 1906,
+ "tosca_definitions_version: cloudify_dsl_1_3", "", "app1", "comp1").build();
+ Collection<ServiceType> items = new ArrayList<ServiceType>();
+ items.add(bpItem);
+
+ String pageLinks =
+ "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-services/?offset=25\"}}";
+ String pageLinks2 = "{\"previousLink\":null,\"nextLink\":null}";
+ ServiceTypeList.PaginationLinks paginationLinks =
+ objectMapper.readValue(pageLinks, ServiceTypeList.PaginationLinks.class);
+ ServiceTypeList.PaginationLinks paginationLinks2 =
+ objectMapper.readValue(pageLinks2, ServiceTypeList.PaginationLinks.class);
+
+ int totalCount = 2;
+ bpList = new ServiceTypeList(items, totalCount, paginationLinks);
+ bpListNext = new ServiceTypeList(items, totalCount, paginationLinks2);
+ }
+
+ @Test
+ @Ignore
+ public final void testInit() {
+ fail("Not yet implemented"); // TODO
+ }
+
+ @Test
+ public final void testGetServiceTypes() {
+ /*
+ * String serviceTypeStr =
+ * "{\"paginationLinks\":{\"previousLink\":null,\"nextLink\":null}},\"totalCount\":32,\"items\":[{\"owner\":\"xyz1731\",\"typeName\":\"xyz1731-helm-1906\",\"typeVersion\":1906,\"blueprintTemplate\":\"tosca_definitions_version: cloudify_dsl_1_3\\nimports:\\n - http://www.getcloudify.org/spec/cloudify/4.2/types.yaml\\n - http://dockercentral.it.att.com:8093/nexus/repository/rawcentral/com.att.dcae.controller/type_files/helm/3.0.1/helm-type.yaml\\ninputs:\\n deployment-description:\\n default: ''\\n chart-name:\\n default: ''\\n tiller-server:\\n default: ''\\n tiller-server-port:\\n default: ''\\n namespace:\\n default: ''\\n chart-repo-url:\\n default: http://32.68.14.161/charts\\n chart-version :\\n default: ''\\n config-url:\\n default: ''\\n config-format:\\n default: ''\\n tls-enable:\\n description: enable helm TSL\\n type: boolean\\n default: false\\n config-dir:\\n description: config dir\\n type: string\\n default: '/opt/manager/resources/'\\n stable-repo-url:\\n description: URL for stable repository\\n type: string\\n default: 'http://32.68.14.161/stable'\\nnode_templates:\\n ecompcomponent:\\n type: onap.nodes.component\\n properties:\\n tiller-server-ip: { get_input: tiller-server }\\n tiller-server-port: { get_input: tiller-server-port }\\n component-name: { get_input: chart-name }\\n chart-repo-url: { concat: [ 'http://', { get_secret: controller_helm_user }, ':', { get_secret: controller_helm_password }, '@', { get_input: chart-repo-url } ] }\\n chart-version: { get_input: chart-version }\\n namespace: { get_input: namespace }\\n config-url: { concat: [ 'http://', { get_secret: controller_helm_user }, ':', { get_secret: controller_helm_password }, '@', { get_input: config-url } ] }\\n config-format: { get_input: config-format}\\n tls-enable: { get_input: tls-enable}\\n ca: { get_secret: ca_value}\\n cert: { get_secret: cert_value}\\n key: { get_secret: key_value}\\n config-dir: { get_input: config-dir}\\n stable-repo-url: { concat: [ 'http://', { get_secret: controller_helm_user }, ':', { get_secret: controller_helm_password }, '@', { get_input: stable-repo-url } ] }\\noutputs:\\n ecompcomponent-helm-output:\\n description: helm value and helm history\\n value:\\n helm-value: { get_attribute: [ecompcomponent, current-helm-value] }\\n helm-history: { get_attribute: [ecompcomponent, helm-history] }\",\"serviceIds\":[],\"vnfTypes\":[],\"serviceLocations\":[],\"asdcServiceId\":\"\",\"asdcResourceId\":\"\",\"asdcServiceURL\":null,\"application\":\"ECOMP\",\"component\":\"controller\",\"typeId\":\"72b8577a-5043-43ab-9aa5-6808b8f53967\",\"selfLink\":{\"rel\":\"self\",\"href\":\"https://ecompc-invt-dev-s5.ecomp.idns.cip.att.com:30123/dcae-service-types/72b8577a-5043-43ab-9aa5-6808b8f53967\"},\"created\":1551214264536,\"deactivated\":null}]"
+ * ; ServiceTypeList sampleData = null; try { sampleData =
+ * objectMapper.readValue(serviceTypeStr, ServiceTypeList.class); } catch
+ * (Exception e) { }
+ */
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> expectedResult = items.stream();
+
+ ResponseEntity<ServiceTypeList> response =
+ new ResponseEntity<ServiceTypeList>(bpList, HttpStatus.OK);
+
+ ResponseEntity<ServiceTypeList> response2 =
+ new ResponseEntity<ServiceTypeList>(bpListNext, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<ServiceTypeList>>any())).thenReturn(response)
+ .thenReturn(response2);
+
+ Stream<ServiceType> actualResult = subject.getServiceTypes();
+ assertNotNull(actualResult);
+ assertTrue(expectedResult.count() == actualResult.count());
+ }
+
+ @Test
+ public final void testGetServiceTypesServiceTypeQueryParams() {
+ ServiceTypeQueryParams qryParms = new ServiceTypeQueryParams.Builder()
+ .asdcResourceId("asdcResourceId").asdcServiceId("asdcServiceId").onlyActive(true)
+ .onlyLatest(false).serviceId("serviceId").serviceLocation("serviceLocation")
+ .typeName("typeName").vnfType("vnfType").build();
+ Collection<ServiceType> items = bpList.items;
+ Stream<ServiceType> expectedResult = items.stream();
+
+ ResponseEntity<ServiceTypeList> response =
+ new ResponseEntity<ServiceTypeList>(bpList, HttpStatus.OK);
+
+ ResponseEntity<ServiceTypeList> response2 =
+ new ResponseEntity<ServiceTypeList>(bpListNext, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<ServiceTypeList>>any())).thenReturn(response)
+ .thenReturn(response2);
+
+ Stream<ServiceType> actualResult = subject.getServiceTypes(qryParms);
+ assertNotNull(actualResult);
+ assertTrue(expectedResult.count() == actualResult.count());
+ }
+
+ @Test
+ public final void testGetServiceType() {
+ Optional<ServiceType> expectedResult = Optional.of(bpItem);
+
+ ResponseEntity<ServiceType> response =
+ new ResponseEntity<ServiceType>(bpItem, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<ServiceType>>any()))
+ .thenReturn(response);
+
+ Optional<ServiceType> actualResult = subject.getServiceType("432432423");
+ assertTrue(expectedResult.get().getTypeName().equals(actualResult.get().getTypeName()));
+ }
+
+ @Test
+ public final void testAddServiceTypeServiceType() {
+
+ when(mockRest.postForObject(Matchers.anyString(), Matchers.<HttpEntity<?>>any(),
+ Matchers.<Class<ServiceType>>any())).thenReturn(bpItem);
+
+ ServiceType actualResult = subject.addServiceType(bpItem);
+ assertTrue(actualResult.getTypeName().contains("xyz"));
+ }
+
+ @Test
+ public final void testAddServiceTypeServiceTypeRequest() {
+ ServiceTypeRequest srvcReq = ServiceTypeRequest.from(bpItem);
+
+ when(mockRest.postForObject(Matchers.anyString(), Matchers.<HttpEntity<?>>any(),
+ Matchers.<Class<ServiceType>>any())).thenReturn(bpItem);
+
+ ServiceType actualResult = subject.addServiceType(srvcReq);
+ assertTrue(actualResult.getTypeName().contains("xyz"));
+ }
+
+ @Test
+ public final void testDeleteServiceType() throws Exception {
+ ResponseEntity<ApiResponseMessage> response =
+ new ResponseEntity<ApiResponseMessage>(HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<ApiResponseMessage>>any())).thenReturn(response);
+
+ subject.deleteServiceType("4243234");
+ }
+
+ @Test
+ public final void testGetServices() {
+
+ Collection<Service> items = deplList.items;
+ Stream<Service> expectedResult = items.stream();
+
+ ResponseEntity<ServiceList> response =
+ new ResponseEntity<ServiceList>(deplList, HttpStatus.OK);
+
+ ResponseEntity<ServiceList> response2 =
+ new ResponseEntity<ServiceList>(deplListNext, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<ServiceList>>any()))
+ .thenReturn(response).thenReturn(response2);
+
+ Stream<Service> actualResult = subject.getServices();
+ assertNotNull(actualResult);
+ assertTrue(expectedResult.count() == actualResult.count());
+
+ }
+
+ @Test
+ public final void testGetServicesForType() {
+ ResponseEntity<ServiceList> response =
+ new ResponseEntity<ServiceList>(deplList, HttpStatus.OK);
+
+ ResponseEntity<ServiceList> response2 =
+ new ResponseEntity<ServiceList>(deplListNext, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<ServiceList>>any()))
+ .thenReturn(response).thenReturn(response2);
+ ServiceQueryParams qryParms = new ServiceQueryParams.Builder().typeId("typeId").build();
+
+ ServiceRefList actualResult = subject.getServicesForType(qryParms);
+ assertTrue(actualResult.items.size() == 2);
+ ServiceRef actualSrvcItem = (ServiceRef) actualResult.items.toArray()[0];
+ assertTrue(actualSrvcItem.getServiceId().contains("dtiapi"));
+
+ }
+
+ @Test
+ public final void testGetServicesServiceQueryParams() {
+ ServiceQueryParams qryParms = new ServiceQueryParams.Builder().typeId("typeId")
+ .vnfId("vnfId").vnfLocation("vnfLocation").vnfType("vnfType")
+ .componentType("componentType").shareable(false).created("43443423").build();
+
+ Collection<Service> items = deplList.items;
+ Stream<Service> expectedResult = items.stream();
+
+ ResponseEntity<ServiceList> response =
+ new ResponseEntity<ServiceList>(deplList, HttpStatus.OK);
+
+ ResponseEntity<ServiceList> response2 =
+ new ResponseEntity<ServiceList>(deplListNext, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<ServiceList>>any()))
+ .thenReturn(response).thenReturn(response2);
+
+ Stream<Service> actualResult = subject.getServices(qryParms);
+ assertTrue(expectedResult.count() == actualResult.count());
+ }
+
+ @Test
+ public final void testGetService() {
+ Optional<Service> expectedResult = Optional.of(deplItem);
+
+ ResponseEntity<Service> response = new ResponseEntity<Service>(deplItem, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<Service>>any()))
+ .thenReturn(response);
+
+ Optional<Service> actualResult = subject.getService("432432423");
+ assertTrue(
+ expectedResult.get().getDeploymentRef().equals(actualResult.get().getDeploymentRef()));
+ }
+
+ @Test
+ public final void testPutService() {
+
+ ResponseEntity<Service> response = new ResponseEntity<Service>(deplItem, HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<Service>>any()))
+ .thenReturn(response);
+
+ subject.putService("423423", deplItem);
+ }
+
+ @Test
+ public final void testDeleteService() throws Exception {
+ ResponseEntity<ApiResponseMessage> response =
+ new ResponseEntity<ApiResponseMessage>(HttpStatus.OK);
+
+ when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<?>>any(),
+ Matchers.<ParameterizedTypeReference<ApiResponseMessage>>any())).thenReturn(response);
+
+ subject.deleteService("4243234");
+ }
+
+}