aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorayalaben <ayala.benzvi@amdocs.com>2018-07-22 12:26:27 +0300
committerayalaben <ayala.benzvi@amdocs.com>2018-07-22 14:12:45 +0300
commit2b995d1eeb30216170afc41c279269d1344c7205 (patch)
treef9e33a06c8928ed33fa462d554448fc446003968
parent7b29a376f0b211dccc35cb1d7f73e011bcad016b (diff)
Unit tests
Change-Id: I5314d3e8e7ae720a2b85decd72f24c07db2543b3 Issue-ID: SDC-1518 Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
-rw-r--r--workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java17
-rw-r--r--workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java83
-rw-r--r--workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java7
3 files changed, 86 insertions, 21 deletions
diff --git a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java
index c9400224..b73427e8 100644
--- a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java
+++ b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java
@@ -5,6 +5,8 @@ import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.onap.sdc.workflow.TestUtil.createWorkflow;
import static org.onap.sdc.workflow.api.RestConstants.PAGE_DEFAULT;
import static org.onap.sdc.workflow.api.RestConstants.SIZE_DEFAULT;
@@ -13,10 +15,13 @@ import static org.onap.sdc.workflow.api.RestConstants.SORT_PARAM;
import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.item.Item;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
@@ -35,8 +40,10 @@ import org.onap.sdc.workflow.api.types.CollectionWrapper;
import org.onap.sdc.workflow.persistence.types.Workflow;
import org.onap.sdc.workflow.services.WorkflowManager;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
+import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@RunWith(MockitoJUnitRunner.class)
@@ -218,17 +225,17 @@ public class WorkflowControllerTest {
.andExpect(status().isOk()).andExpect(jsonPath("$.results", hasSize(1)));
}
- /* @Test
+ @Test
public void shouldCreateWorkflowWhenCallingPostRESTRequest() throws Exception {
Item item = new Item();
- item.setId("abc");
+ item.setId(new Id("abc"));
Workflow reqWorkflow = createWorkflow(1, false);
mockMvc.perform(
post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON)
- .content(GSON.toJson(reqWorkflow))).andDo(print()).andExpect(status().isCreated())
- .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
+ .content(GSON.toJson(reqWorkflow))).andDo(print())
+ .andExpect(status().isCreated());
verify(workflowManagerMock, times(1)).create(reqWorkflow);
- }*/
+ }
private List<Workflow> createWorkflows(int numOfWorkflows) {
List<Workflow> workflowList = new ArrayList<>(numOfWorkflows);
diff --git a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
index 4ddd8d48..63d2e560 100644
--- a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
+++ b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
@@ -1,21 +1,27 @@
package org.onap.sdc.workflow.persistence.impl;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.verify;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.datatypes.item.Info;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mapstruct.ap.internal.util.Collections;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
@@ -24,6 +30,7 @@ import org.onap.sdc.workflow.persistence.types.ParameterEntity;
import org.onap.sdc.workflow.persistence.types.ParameterPropertyName;
import org.onap.sdc.workflow.persistence.types.ParameterRole;
import org.onap.sdc.workflow.persistence.types.ParameterType;
+import org.onap.sdc.workflow.persistence.types.WorkflowElementType;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
@@ -33,6 +40,9 @@ public class ParameterRepositoryTest {
private static final String ITEM1_ID = "item_id_1";
private static final String VERSION1_ID = "version_id_1";
private static final String PARAMETER1_ID = "parameter_id_1";
+ private static final String PARAMETER2_ID = "parameter_id_2";
+ private static final String PARAMETERS_PARENT_ID = "parameters_id";
+
@Mock
private ZusammenAdaptor zusammenAdaptorMock;
@@ -45,25 +55,25 @@ public class ParameterRepositoryTest {
SessionContextProviderFactory.getInstance().createInterface().create("test_user", "workflow");
}
- /*@Test
+ @Test
public void shouldGetParameterById() {
- ZusammenElement element = new ZusammenElement();
- element.setElementId(new Id(PARAMETER1_ID));
+ ElementInfo element = new ElementInfo();
+ element.setId(new Id(PARAMETER1_ID));
Info info = new Info();
info.setName("testInput");
info.addProperty(ParameterPropertyName.TYPE.name(),ParameterType.FLOAT.name());
info.addProperty(ParameterPropertyName.mandatory.name(),true);
element.setInfo(info);
doReturn(Optional.of(element)).when(zusammenAdaptorMock)
- .getElement(any(SessionContext.class), any(ElementContext.class),
- eq(PARAMETER1_ID));
+ .getElementInfo(any(SessionContext.class), any(ElementContext.class),
+ eq(new Id(PARAMETER1_ID)));
ParameterEntity result = parameterRepository.get(ITEM1_ID, VERSION1_ID, PARAMETER1_ID);
- verify(parameterRepository,times(1)).elementToParameterEntity(element);
- verify(zusammenAdaptorMock).getElement(any(SessionContext.class), any(ElementContext.class),eq(PARAMETER1_ID));
- assertEquals("testInput",result.getName());
+ verify(zusammenAdaptorMock)
+ .getElementInfo(any(SessionContext.class), any(ElementContext.class), eq(new Id(PARAMETER1_ID)));
+ assertEquals("testInput", result.getName());
- }*/
+ }
@Test
@@ -101,9 +111,56 @@ public class ParameterRepositoryTest {
}
+ @Test
+ public void shouldListParametersByType() {
+
+ ElementInfo parameter1 = new ElementInfo();
+ parameter1.setId(new Id(PARAMETER1_ID));
+ Info info1 = new Info();
+ info1.setName("input1");
+ info1.addProperty(ParameterPropertyName.TYPE.name(),"INTEGER");
+ info1.addProperty(ParameterPropertyName.mandatory.name(),true);
+ parameter1.setInfo(info1);
+ ElementInfo parameter2 = new ElementInfo();
+ parameter2.setId(new Id(PARAMETER2_ID));
+ Info info2 = new Info();
+ info2.setName("input2");
+ info2.addProperty(ParameterPropertyName.TYPE.name(),"STRING");
+ info2.addProperty(ParameterPropertyName.mandatory.name(),false);
+ parameter2.setInfo(info2);
+ Collection<ElementInfo> parameters = Collections.asSet(parameter1, parameter2);
+ doReturn(parameters).when(zusammenAdaptorMock)
+ .listElementsByName(any(SessionContext.class), any(ElementContext.class),isNull(Id.class),eq(ParameterRole.INPUT.name()));
+ Collection<ParameterEntity> results = parameterRepository.list(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT);
+
+ verify(zusammenAdaptorMock).listElementsByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class),
+ eq(WorkflowElementType.INPUT.name()));
+ assertTrue(results.stream().anyMatch(parameterEntity -> parameterEntity.getId().equals(PARAMETER1_ID)));
+ assertTrue(results.stream().anyMatch(parameterEntity -> parameterEntity.getId().equals(PARAMETER2_ID)));
+ }
-
-
-
+ @Test
+ public void shouldDeleteAllParametersByType() {
+ ElementInfo parameterParentElement = new ElementInfo();
+ parameterParentElement.setId(new Id(PARAMETERS_PARENT_ID));
+ ElementInfo parameter1 = new ElementInfo();
+ parameter1.setId(new Id(PARAMETER1_ID));
+ ElementInfo parameter2 = new ElementInfo();
+ parameter2.setId(new Id(PARAMETER2_ID));
+ parameterParentElement.setSubElements(new ArrayList<>());
+ parameterParentElement.getSubElements().add(parameter1);
+ parameterParentElement.getSubElements().add(parameter2);
+
+ Optional<ElementInfo> elementOptional = Optional.of(parameterParentElement);
+
+ doReturn(elementOptional).when(zusammenAdaptorMock)
+ .getElementInfoByName(any(SessionContext.class), any(ElementContext.class),
+ isNull(Id.class), eq(WorkflowElementType.INPUTS.name()));
+
+ parameterRepository.deleteAll(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT);
+ verify(zusammenAdaptorMock)
+ .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ eq("Delete all INPUT"));
+ }
}
diff --git a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
index 53a3cff4..4c511de0 100644
--- a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
+++ b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
@@ -127,20 +127,21 @@ public class WorkflowVersionManagerImplTest {
}
- /*@Test
+ @Test
public void shouldCreateWorkflowVersion(){
Version version = new Version(VERSION1_ID);
version.setDescription("version desc");
doReturn(version).when(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major);
VersionRequestDto versionRequest = new VersionRequestDto();
versionRequest.setDescription("version desc");
+ versionRequest.setInputs(new ArrayList<>());
+ versionRequest.setOutputs(new ArrayList<>());
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
doReturn(workflowVersion).when(workflowVersionManager).get(ITEM1_ID,VERSION1_ID);
workflowVersionManager.create(ITEM1_ID,versionRequest);
verify(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major);
-
}
-*/
+
@Test(expected = VersionCreationException.class)
public void shouldTrowExceptionWhenDraftVersionExists() {
VersionRequestDto versionRequestDto = new VersionRequestDto();