From 172be7073ec345f65e7a40cd95da3a97bdbc0f57 Mon Sep 17 00:00:00 2001 From: "k.kazak" Date: Tue, 12 Feb 2019 15:22:29 +0100 Subject: fix major sonar bug Removed useless 'instanceof' operator as it always resolves as true Replaced it with checking for null Removed unused imports Added information about modifications on the top Added junit tests for the method Change-Id: I7a902ad2852e0ed0d507a6309857a1bab74921de Issue-ID: SO-1491 Signed-off-by: k.kazak --- .../workflow/tasks/WorkflowActionTest.java | 48 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'bpmn/so-bpmn-tasks/src/test/java/org') diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 24b87277c4..c74f590e6b 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * 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 @@ -23,6 +25,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.mockito.ArgumentMatchers.anyObject; @@ -31,6 +34,7 @@ import static org.mockito.Matchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.MalformedURLException; import java.nio.file.Files; @@ -40,9 +44,8 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Optional; -import java.util.UUID; import java.util.Set; - +import java.util.UUID; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; @@ -90,8 +93,6 @@ import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.onap.so.serviceinstancebeans.SubscriberInfo; import org.springframework.core.env.Environment; -import com.fasterxml.jackson.databind.ObjectMapper; - public class WorkflowActionTest extends BaseTaskTest { @@ -1290,7 +1291,44 @@ public class WorkflowActionTest extends BaseTaskTest { assertEquals("222",result.get(1).getResourceId()); assertEquals("111",result.get(2).getResourceId()); } - + + @Test + public void findCatalogNetworkCollectionTest() { + Service service = new Service(); + NetworkCollectionResourceCustomization networkCustomization = new NetworkCollectionResourceCustomization(); + networkCustomization.setModelCustomizationUUID("123"); + service.getCollectionResourceCustomizations().add(networkCustomization); + doReturn(networkCustomization).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); + CollectionResourceCustomization customization = workflowAction.findCatalogNetworkCollection(execution, service); + assertNotNull(customization); + } + + @Test + public void findCatalogNetworkCollectionEmptyTest() { + Service service = new Service(); + NetworkCollectionResourceCustomization networkCustomization = new NetworkCollectionResourceCustomization(); + networkCustomization.setModelCustomizationUUID("123"); + service.getCollectionResourceCustomizations().add(networkCustomization); + CollectionResourceCustomization customization = workflowAction.findCatalogNetworkCollection(execution, service); + assertNull(customization); + } + + @Test + public void findCatalogNetworkCollectionMoreThanOneTest() { + Service service = new Service(); + NetworkCollectionResourceCustomization networkCustomization1 = new NetworkCollectionResourceCustomization(); + networkCustomization1.setModelCustomizationUUID("123"); + NetworkCollectionResourceCustomization networkCustomization2 = new NetworkCollectionResourceCustomization(); + networkCustomization2.setModelCustomizationUUID("321"); + service.getCollectionResourceCustomizations().add(networkCustomization1); + service.getCollectionResourceCustomizations().add(networkCustomization2); + doReturn(networkCustomization1).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); + doReturn(networkCustomization2).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("321"); + workflowAction.findCatalogNetworkCollection(execution, service); + assertEquals("Found multiple Network Collections in the Service model, only one per Service is supported.", + execution.getVariable("WorkflowActionErrorMessage")); + } + private List createFlowList (String... flowNames){ List result = new ArrayList<>(); for(String flowName : flowNames){ -- cgit 1.2.3-korg