aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'workflow-designer-be/src/test')
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/RestPath.java9
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java8
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java47
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java35
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java4
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java365
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java2
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java10
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java28
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java301
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java4
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java10
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java4
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java2
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java2
15 files changed, 740 insertions, 91 deletions
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/RestPath.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/RestPath.java
index 4301feb8..6c825f9d 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/RestPath.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/RestPath.java
@@ -10,8 +10,7 @@ public class RestPath {
//Hiding implicit constructor
}
- private static final String WORKFLOWS_URL = "/workflows";
- public static final String WORKFLOWS_WITH_VERSION_STATE_FILTER_URL = WORKFLOWS_URL + "?versionState=%s";
+ private static final String WORKFLOWS_URL = "/wf/workflows";
private static final String WORKFLOW_URL_FORMATTER = WORKFLOWS_URL + "/%s";
private static final String VERSIONS_URL_FORMATTER = WORKFLOWS_URL + "/%s/versions";
private static final String VERSION_URL_FORMATTER = WORKFLOWS_URL + "/%s/versions/%s";
@@ -21,8 +20,6 @@ public class RestPath {
private static final String WORKFLOW_URL_FORMATTER_QUERY_PARAMS_ALL =
WORKFLOWS_URL + "?" + SORT_QUERY_STRING_FORMATTER+ "&" + LIMIT_QUERY_STRING_FORMATTER + "&" +
OFFSET_QUERY_STRING_FORMATTER;
- private static final String WORKFLOW_URL_FORMATTER_QUERY_PARAMS_NO_SORT =
- WORKFLOWS_URL + "?" + LIMIT_QUERY_STRING_FORMATTER + "&" + OFFSET_QUERY_STRING_FORMATTER;
private static final String WORKFLOW_URL_FORMATTER_QUERY_PARAMS_NO_SORT_AND_LIMIT =
WORKFLOWS_URL + "?" + OFFSET_QUERY_STRING_FORMATTER;
private static final String WORKFLOW_URL_FORMATTER_QUERY_PARAMS_NO_SORT_AND_OFFSET =
@@ -32,10 +29,6 @@ public class RestPath {
return String.format(WORKFLOW_URL_FORMATTER_QUERY_PARAMS_ALL, sort, limit, offset);
}
- public static String getWorkflowsPathNoSort(String limit, String offset){
- return String.format(WORKFLOW_URL_FORMATTER_QUERY_PARAMS_NO_SORT, limit, offset);
- }
-
public static String getWorkflowsPathNoSortAndLimit(String offset){
return String.format(WORKFLOW_URL_FORMATTER_QUERY_PARAMS_NO_SORT_AND_LIMIT, offset);
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java
index e2a566aa..0a8355c9 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java
@@ -1,12 +1,12 @@
package org.onap.sdc.workflow;
-import org.onap.sdc.workflow.persistence.types.Workflow;
+import static org.onap.sdc.workflow.services.impl.ItemType.WORKFLOW;
+
+import org.onap.sdc.workflow.services.types.Workflow;
import org.openecomp.sdc.versioning.types.Item;
public class TestUtil {
- private static final String WORKFLOW_TYPE = "WORKFLOW";
-
public static Workflow createWorkflow(int workflowNum, boolean createId) {
Workflow workflow = new Workflow();
if (createId) {
@@ -26,7 +26,7 @@ public class TestUtil {
item.setName("Workflow_" + itemNum);
item.setDescription("Description_" + itemNum);
if (setType) {
- item.setType(WORKFLOW_TYPE);
+ item.setType(WORKFLOW.name());
}
return item;
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java
index f8d2aec8..3438093d 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java
@@ -32,15 +32,13 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdc.workflow.RestPath;
-import org.onap.sdc.workflow.api.exceptionshandlers.CustomizedResponseEntityExceptionHandler;
-import org.onap.sdc.workflow.persistence.types.Workflow;
+import org.onap.sdc.workflow.services.types.Workflow;
import org.onap.sdc.workflow.services.WorkflowManager;
import org.onap.sdc.workflow.services.types.Page;
import org.onap.sdc.workflow.services.types.PagingRequest;
import org.onap.sdc.workflow.services.types.RequestSpec;
import org.onap.sdc.workflow.services.types.Sort;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
-import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@@ -48,16 +46,14 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@RunWith(MockitoJUnitRunner.class)
public class WorkflowControllerTest {
-
- private static final String MISSING_REQUEST_HEADER_ERRROR_FORMAT =
- "Missing request header '%s' for method parameter of type String";
private static final String USER_ID = "userId";
+ private static final String MISSING_USER_HEADER_ERROR =
+ "Missing request header 'USER_ID' for method parameter of type String";
private static final Gson GSON = new Gson();
private static final String DEFAULT_SORT_VALUE = "name:asc";
private MockMvc mockMvc;
-
@Mock
private WorkflowManager workflowManagerMock;
@Captor
@@ -65,23 +61,19 @@ public class WorkflowControllerTest {
@InjectMocks
private WorkflowController workflowController;
-
@Before
public void setUp() {
mockMvc = MockMvcBuilders.standaloneSetup(workflowController)
.setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver())
- .setControllerAdvice(new CustomizedResponseEntityExceptionHandler()).build();
+ .setControllerAdvice(new ExceptionsHandler()).build();
}
@Test
public void shouldReturnErrorWhenMissingUserIdInGetReqHeader() throws Exception {
Workflow workflowMock = createWorkflow(1, true);
- MockHttpServletResponse response =
- mockMvc.perform(get(RestPath.getWorkflowPath(workflowMock.getId())).contentType(APPLICATION_JSON))
- .andDo(print()).andExpect(status().isBadRequest()).andExpect(status().is(400)).andReturn()
- .getResponse();
- assertEquals(String.format(MISSING_REQUEST_HEADER_ERRROR_FORMAT, USER_ID_HEADER),
- response.getContentAsString());
+ mockMvc.perform(get(RestPath.getWorkflowPath(workflowMock.getId())).contentType(APPLICATION_JSON))
+ .andDo(print()).andExpect(status().isBadRequest())
+ .andExpect(jsonPath("$.message", is(MISSING_USER_HEADER_ERROR)));
}
@Test
@@ -96,11 +88,8 @@ public class WorkflowControllerTest {
@Test
public void shouldReturnErrorWhenMissingUserIdInListReqHeader() throws Exception {
- MockHttpServletResponse response =
- mockMvc.perform(get(RestPath.getWorkflowsPath()).contentType(APPLICATION_JSON)).andDo(print())
- .andExpect(status().isBadRequest()).andExpect(status().is(400)).andReturn().getResponse();
- assertEquals(String.format(MISSING_REQUEST_HEADER_ERRROR_FORMAT, USER_ID_HEADER),
- response.getContentAsString());
+ mockMvc.perform(get(RestPath.getWorkflowsPath()).contentType(APPLICATION_JSON)).andDo(print())
+ .andExpect(status().isBadRequest()).andExpect(jsonPath("$.message", is(MISSING_USER_HEADER_ERROR)));
}
@Test
@@ -205,23 +194,17 @@ public class WorkflowControllerTest {
@Test
public void shouldThrowExceptionWhenWorkflowNameInvalid() throws Exception {
-
Workflow reqWorkflow = new Workflow();
reqWorkflow.setName("Invalid workflow name %");
- MockHttpServletResponse response = mockMvc.perform(
- post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)
- .content(GSON.toJson(reqWorkflow))).andDo(print())
- .andExpect(status().isBadRequest()).andReturn().getResponse();
- assertEquals("Workflow name must contain only letters, digits and underscores", response.getContentAsString());
+ mockMvc.perform(post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)
+ .content(GSON.toJson(reqWorkflow))).andDo(print())
+ .andExpect(status().isBadRequest())
+ .andExpect(jsonPath("$.message", is("Workflow name must contain only letters, digits and underscores")));
}
private void mockManagerList3() {
- doReturn(new Page<>(Arrays.asList(
- createWorkflow(1, true),
- createWorkflow(2, true),
- createWorkflow(3, true)),
- new PagingRequest(DEFAULT_OFFSET, DEFAULT_LIMIT), 3))
- .when(workflowManagerMock).list(any(), any());
+ doReturn(new Page<>(Arrays.asList(createWorkflow(1, true), createWorkflow(2, true), createWorkflow(3, true)),
+ new PagingRequest(DEFAULT_OFFSET, DEFAULT_LIMIT), 3)).when(workflowManagerMock).list(any(), any());
}
private static void assertRequestSpec(RequestSpec actual, int expectedOffset, int expectedLimit,
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
index 65dae726..2b3c49c1 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
@@ -1,5 +1,6 @@
package org.onap.sdc.workflow.api;
+import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
@@ -16,7 +17,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import com.google.gson.Gson;
import java.util.Arrays;
import java.util.Collection;
-import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -26,8 +26,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdc.workflow.RestPath;
import org.onap.sdc.workflow.persistence.types.ParameterEntity;
import org.onap.sdc.workflow.persistence.types.ParameterType;
-import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
+import org.onap.sdc.workflow.services.types.WorkflowVersion;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.springframework.http.HttpStatus;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -58,14 +58,26 @@ public class WorkflowVersionControllerTest {
}
@Test
+ public void shouldReturnWorkflowVersionListWhenCallingVersionGetREST() throws Exception {
+ doReturn(Arrays.asList(new Version(VERSION1_ID), new Version(VERSION2_ID))).when(workflowVersionManagerMock)
+ .list(ITEM1_ID, null);
+ mockMvc.perform(get(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
+ .contentType(APPLICATION_JSON)).andExpect(status().isOk())
+ .andExpect(jsonPath("$.items", hasSize(2))).andExpect(jsonPath("$.items[0].id", is(VERSION1_ID)))
+ .andExpect(jsonPath("$.items[1].id", is(VERSION2_ID)));
+
+ verify(workflowVersionManagerMock, times(1)).list(ITEM1_ID, null);
+ }
+
+
+ @Test
public void shouldCreateWorkflowVersionWhenCallingVersionsPostREST() throws Exception {
WorkflowVersion version = new WorkflowVersion();
version.setDescription("VersionDescription");
mockMvc.perform(post(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
- .contentType(APPLICATION_JSON)
- .content(GSON.toJson(version)))
- .andExpect(status().isCreated());
+ .contentType(APPLICATION_JSON).content(GSON.toJson(version)))
+ .andExpect(status().isCreated());
verify(workflowVersionManagerMock, times(1)).create(ITEM1_ID, null, version);
}
@@ -79,9 +91,8 @@ public class WorkflowVersionControllerTest {
version.setInputs(inputs);
version.setDescription("VersionDescription");
mockMvc.perform(post(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
- .contentType(APPLICATION_JSON)
- .content(GSON.toJson(version)))
- .andExpect(status().isBadRequest());
+ .contentType(APPLICATION_JSON).content(GSON.toJson(version)))
+ .andExpect(status().isBadRequest());
}
@@ -92,8 +103,8 @@ public class WorkflowVersionControllerTest {
doReturn(version).when(workflowVersionManagerMock).get(ITEM1_ID, VERSION1_ID);
mockMvc.perform(
get(RestPath.getWorkflowVersion(ITEM1_ID, VERSION1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
- .contentType(APPLICATION_JSON)).andDo(print())
- .andExpect(status().isOk()).andExpect(jsonPath("$.id", is(version.getId())));
+ .contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isOk())
+ .andExpect(jsonPath("$.id", is(version.getId())));
verify(workflowVersionManagerMock, times(1)).get(ITEM1_ID, VERSION1_ID);
}
@@ -104,9 +115,7 @@ public class WorkflowVersionControllerTest {
MockHttpServletResponse result = mockMvc.perform(
put(RestPath.getWorkflowVersion(ITEM1_ID, VERSION1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
- .contentType(APPLICATION_JSON)
- .content(GSON.toJson(version))).andReturn()
- .getResponse();
+ .contentType(APPLICATION_JSON).content(GSON.toJson(version))).andReturn().getResponse();
assertEquals(HttpStatus.OK.value(), result.getStatus());
version.setId(VERSION1_ID);
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java
index 423c5e6c..c40aef3e 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java
@@ -2,8 +2,8 @@ package org.onap.sdc.workflow.api.types;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.onap.sdc.workflow.persistence.types.WorkflowVersionState.CERTIFIED;
-import static org.onap.sdc.workflow.persistence.types.WorkflowVersionState.DRAFT;
+import static org.onap.sdc.workflow.services.types.WorkflowVersionState.CERTIFIED;
+import static org.onap.sdc.workflow.services.types.WorkflowVersionState.DRAFT;
import java.util.Collections;
import java.util.stream.Collectors;
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java
new file mode 100644
index 00000000..999097c2
--- /dev/null
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java
@@ -0,0 +1,365 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.onap.sdc.workflow.persistence.impl;
+
+import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
+import com.amdocs.zusammen.commons.health.data.HealthInfo;
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.item.Action;
+import com.amdocs.zusammen.datatypes.item.ElementContext;
+import com.amdocs.zusammen.datatypes.item.Info;
+import com.amdocs.zusammen.datatypes.item.Item;
+import com.amdocs.zusammen.datatypes.item.ItemVersion;
+import com.amdocs.zusammen.datatypes.item.ItemVersionData;
+import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
+import com.amdocs.zusammen.datatypes.item.Resolution;
+import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
+import com.amdocs.zusammen.datatypes.itemversion.Tag;
+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.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.sdc.workflow.persistence.impl.ActivitySpecRepositoryImpl.InfoPropertyName;
+import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecData;
+import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecElementType;
+import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
+import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.types.ElementPropertyName;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+public class ActivitySpecRepositoryImplTest {
+
+ private static final Version version = new Version();
+ private static final String versionId = "1234";
+ private static final String itemId = "5678";
+ private static final String tenant = "dox";
+
+ private ZusammenAdaptorMock zusammenAdaptor;
+ private ActivitySpecRepositoryImpl daoImpl;
+ private ActivitySpecEntity entity;
+
+
+ @Before
+ public void setUp() {
+ SessionContextProviderFactory.getInstance().createInterface().create("test", tenant);
+ zusammenAdaptor = new ZusammenAdaptorMock();
+ daoImpl = new ActivitySpecRepositoryImpl(zusammenAdaptor);
+ entity = new ActivitySpecEntity();
+ entity = new ActivitySpecEntity();
+
+ entity.setId(itemId);
+ version.setId(versionId);
+ entity.setVersion(version);
+ entity.setName("activitySpec");
+ List<String> categoryList = new ArrayList<>();
+ categoryList.add("category1");
+ entity.setCategoryList(categoryList);
+ ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", "String", null);
+ inputParams.setValue("localhost");
+ List<ActivitySpecParameter> inputs = new ArrayList<>();
+ inputs.add(inputParams);
+ entity.setInputs(inputs);
+ }
+
+ @After
+ public void tearDown() {
+ SessionContextProviderFactory.getInstance().createInterface().close();
+ }
+
+ @Test
+ public void testCreate() {
+ ItemVersion itemVersionmock = new ItemVersion();
+ itemVersionmock.setId(new Id());
+
+ daoImpl.create(entity);
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId());
+ Optional<ElementInfo> testElementInfo = zusammenAdaptor.getElementInfoByName(context, elementContext, Id.ZERO,
+ ActivitySpecElementType.ACTIVITYSPEC.name());
+ Assert.assertTrue(testElementInfo.isPresent());
+ Assert.assertEquals(testElementInfo.get().getInfo().getName(), ActivitySpecElementType.ACTIVITYSPEC.name());
+ Assert.assertEquals(testElementInfo.get().getInfo()
+ .getProperty(ActivitySpecRepositoryImpl.InfoPropertyName.DESCRIPTION.getValue()),
+ entity.getDescription());
+ Assert.assertEquals(testElementInfo.get().getInfo().getProperty(InfoPropertyName.CATEGORY.getValue()),
+ entity.getCategoryList());
+ Assert.assertEquals(testElementInfo.get().getInfo()
+ .getProperty(ActivitySpecRepositoryImpl.InfoPropertyName.NAME.getValue()),
+ entity.getName());
+
+ final Optional<Element> testElement =
+ zusammenAdaptor.getElement(context, elementContext, zusammenAdaptor.elementId);
+ final InputStream data = testElement.get().getData();
+ final ActivitySpecData activitySpecData = JsonUtil.json2Object(data, ActivitySpecData.class);
+ Assert.assertEquals(activitySpecData.getInputs().get(0).getName(), entity.getInputs().get(0).getName());
+ }
+
+ @Test
+ public void testGet() {
+ final ActivitySpecEntity retrieved = daoImpl.get(entity);
+ Assert.assertEquals(retrieved.getName(), entity.getName());
+ Assert.assertEquals(retrieved.getDescription(), entity.getDescription());
+ Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList());
+ }
+
+ @Test
+ public void testUpdate() {
+ entity.setDescription("Update AS version1");
+ daoImpl.update(entity);
+ final ActivitySpecEntity retrieved = daoImpl.get(entity);
+ Assert.assertEquals(retrieved.getName(), entity.getName());
+ Assert.assertEquals(retrieved.getDescription(), entity.getDescription());
+ Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList());
+ }
+
+ private class ZusammenAdaptorMock implements ZusammenAdaptor {
+
+ private final Map<String, Element> elementMap = new HashMap<>();
+ String elementId;
+ private ItemVersion itemVersion;
+
+ @Override
+ public Collection<Item> listItems(SessionContext context) {
+ return null;
+ }
+
+ @Override
+ public Item getItem(SessionContext context, Id itemId) {
+ return null;
+ }
+
+ @Override
+ public void deleteItem(SessionContext context, Id itemId) {
+
+ }
+
+ @Override
+ public Id createItem(SessionContext context, Info info) {
+ return null;
+ }
+
+ @Override
+ public void updateItem(SessionContext context, Id itemId, Info info) {
+
+ }
+
+ @Override
+ public Optional<ItemVersion> getFirstVersion(SessionContext context, Id itemId) {
+
+ return Optional.ofNullable(itemVersion);
+ }
+
+ @Override
+ public Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId) {
+ return null;
+ }
+
+ @Override
+ public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) {
+ return null;
+ }
+
+ @Override
+ public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData) {
+ return null;
+ }
+
+ @Override
+ public void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData) {
+
+ }
+
+ @Override
+ public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) {
+ return null;
+ }
+
+ @Override
+ public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) {
+ return null;
+ }
+
+ @Override
+ public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) {
+ return null;
+ }
+
+ @Override
+ public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) {
+
+ }
+
+ @Override
+ public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String changeRef) {
+
+ }
+
+ @Override
+ public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) {
+
+ }
+
+ @Override
+ public void syncVersion(SessionContext sessionContext, Id itemId, Id versionId) {
+
+ }
+
+ @Override
+ public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) {
+
+ }
+
+ @Override
+ public void cleanVersion(SessionContext sessionContext, Id itemId, Id versionId) {
+
+ }
+
+ @Override
+ public Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext,
+ Id elementId) {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<Element> getElement(SessionContext context, ElementContext elementContext, String elementId) {
+ return Optional.of(elementMap.get(elementId));
+ }
+
+ @Override
+ public Optional<Element> getElementByName(SessionContext context, ElementContext elementContext,
+ Id parentElementId, String elementName) {
+ //return Optional.empty();
+ ZusammenElement element = new ZusammenElement();
+ Info info = new Info();
+ element.setElementId(Id.ZERO);
+ info.addProperty("name", entity.getName());
+ info.addProperty("description", entity.getDescription());
+ info.addProperty("category", entity.getCategoryList());
+ element.setInfo(info);
+ return Optional.ofNullable(element);
+ }
+
+ @Override
+ public Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext,
+ Id parentElementId) {
+ return null;
+ }
+
+ @Override
+ public Collection<Element> listElementData(SessionContext context, ElementContext elementContext,
+ Id parentElementId) {
+ return elementMap.values();
+ }
+
+ @Override
+ public Collection<ElementInfo> listElementsByName(SessionContext context, ElementContext elementContext,
+ Id parentElementId, String elementName) {
+
+ return elementMap.values().stream().filter(element -> elementName.equals(element.getInfo().getProperty(
+ ElementPropertyName.elementType.name()))).map(element -> {
+ ElementInfo elementInfo = new ElementInfo();
+ elementInfo.setId(element.getElementId());
+ elementInfo.setInfo(element.getInfo());
+ return elementInfo;
+ }).collect(Collectors.toList());
+
+ }
+
+ @Override
+ public Optional<ElementInfo> getElementInfoByName(SessionContext context, ElementContext elementContext,
+ Id parentElementId, String elementName) {
+
+
+ return elementMap.values().stream().filter(element -> elementName.equals(element.getInfo().getProperty(
+ ElementPropertyName.elementType.name()))).map(element -> {
+ ElementInfo elementInfo = new ElementInfo();
+ elementInfo.setId(element.getElementId());
+ elementInfo.setInfo(element.getInfo());
+ return elementInfo;
+ }).findAny();
+
+
+ }
+
+ @Override
+ public Optional<ElementConflict> getElementConflict(SessionContext context, ElementContext elementContext,
+ Id id) {
+ return Optional.empty();
+ }
+
+ @Override
+ public Element saveElement(SessionContext context, ElementContext elementContext, ZusammenElement element,
+ String message) {
+ if (element.getAction().equals(Action.CREATE) || element.getAction().equals(Action.UPDATE)) {
+ element.setElementId(new Id(UUID.randomUUID().toString()));
+ }
+ elementMap.put(element.getElementId().getValue(), element);
+ elementId = element.getElementId().getValue();
+ return element;
+ }
+
+ @Override
+ public void resolveElementConflict(SessionContext context, ElementContext elementContext,
+ ZusammenElement element, Resolution resolution) {
+
+ }
+
+ @Override
+ public void revert(SessionContext sessionContext, Id itemId, Id versionId, Id revisionId) {
+
+ }
+
+ @Override
+ public ItemVersionRevisions listRevisions(SessionContext sessionContext, Id itemId, Id versionId) {
+ return null;
+ }
+
+ @Override
+ public Collection<HealthInfo> checkHealth(SessionContext context) {
+ return null;
+ }
+
+ @Override
+ public String getVersion(SessionContext sessionContext) {
+ return null;
+ }
+
+ }
+
+}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
index b86b14b9..9d202fce 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
@@ -26,7 +26,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
-import org.onap.sdc.workflow.persistence.types.WorkflowElementType;
+import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
index 07a42658..546a3fe6 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
@@ -26,10 +26,10 @@ import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdc.workflow.persistence.types.ParameterEntity;
-import org.onap.sdc.workflow.persistence.types.ParameterPropertyName;
+import org.onap.sdc.workflow.persistence.impl.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.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
@@ -62,7 +62,7 @@ public class ParameterRepositoryTest {
Info info = new Info();
info.setName("testInput");
info.addProperty(ParameterPropertyName.TYPE.name(), ParameterType.FLOAT.name());
- info.addProperty(ParameterPropertyName.mandatory.name(), true);
+ info.addProperty(ParameterPropertyName.MANDATORY.name(), true);
element.setInfo(info);
doReturn(Optional.of(element)).when(zusammenAdaptorMock)
.getElementInfo(any(SessionContext.class), any(ElementContext.class),
@@ -118,14 +118,14 @@ public class ParameterRepositoryTest {
Info info1 = new Info();
info1.setName("input1");
info1.addProperty(ParameterPropertyName.TYPE.name(), "INTEGER");
- info1.addProperty(ParameterPropertyName.mandatory.name(), true);
+ 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);
+ info2.addProperty(ParameterPropertyName.MANDATORY.name(), false);
parameter2.setInfo(info2);
Collection<ElementInfo> parameters = Collections.asSet(parameter1, parameter2);
doReturn(parameters).when(zusammenAdaptorMock)
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java
index 4911060a..5c285c3b 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java
@@ -38,45 +38,45 @@ public class UniqueValueServiceTest {
}
@Test
- public void shouldCallRepositoryInsertIfValueUnique(){
+ public void shouldCallRepositoryInsertIfValueUnique() {
doReturn(Optional.empty()).when(uniqueValueRepositoryMock).findById(any());
- uniqueValueService.createUniqueValue(TYPE, new String[]{DUMMY_COMBINATION});
+ uniqueValueService.createUniqueValue(TYPE, DUMMY_COMBINATION);
verify(uniqueValueRepositoryMock, times(1)).insert(any(UniqueValueEntity.class));
}
@Test
- public void shouldNotCheckValueIfNoUniqueCombination(){
- uniqueValueService.createUniqueValue(TYPE, null);
+ public void shouldNotCheckValueIfNoUniqueCombination() {
+ uniqueValueService.createUniqueValue(TYPE);
verify(uniqueValueRepositoryMock, never()).findById(any(UniqueValueEntity.class));
}
@Test(expected = UniqueValueViolationException.class)
- public void shouldThrowExceptionIfValueIsNotUnique(){
+ public void shouldThrowExceptionIfValueIsNotUnique() {
doReturn(Optional.of("xxx")).when(uniqueValueRepositoryMock).findById(any());
- uniqueValueService.createUniqueValue(TYPE, new String[]{DUMMY_COMBINATION});
+ uniqueValueService.createUniqueValue(TYPE, DUMMY_COMBINATION);
}
@Test
- public void shouldCallRepositoryDeleteIfValueValid(){
- uniqueValueService.deleteUniqueValue(TYPE, new String[]{DUMMY_COMBINATION});
+ public void shouldCallRepositoryDeleteIfValueValid() {
+ uniqueValueService.deleteUniqueValue(TYPE, DUMMY_COMBINATION);
verify(uniqueValueRepositoryMock, times(1)).delete(any(UniqueValueEntity.class));
}
@Test
- public void shouldNotCallRepositoryDeleteIfValueNouniqueCombination(){
- uniqueValueService.deleteUniqueValue(TYPE, new String[]{});
+ public void shouldNotCallRepositoryDeleteIfValueNouniqueCombination() {
+ uniqueValueService.deleteUniqueValue(TYPE);
verify(uniqueValueRepositoryMock, never()).delete(any(UniqueValueEntity.class));
}
@Test
- public void shouldNotUpdateIfNewAndOldValueAreEqualsCaseIgnore(){
+ public void shouldNotUpdateIfNewAndOldValueAreEqualsCaseIgnore() {
String value = "value";
uniqueValueService.updateUniqueValue(TYPE, value, value.toUpperCase());
verify(uniqueValueService, never()).createUniqueValue(anyString(), any());
}
@Test
- public void shouldUpdateIfNewAndOldValueAreNotEqualsCaseIgnore(){
+ public void shouldUpdateIfNewAndOldValueAreNotEqualsCaseIgnore() {
String oldValue = "oldValue";
String newValue = "newValue";
uniqueValueService.updateUniqueValue(TYPE, oldValue, newValue);
@@ -87,12 +87,12 @@ public class UniqueValueServiceTest {
@Test
public void shouldReturnTrueIfValueExist() {
doReturn(Optional.of("xxx")).when(uniqueValueRepositoryMock).findById(any());
- assertTrue(uniqueValueService.isUniqueValueOccupied(TYPE, new String[]{DUMMY_COMBINATION}));
+ assertTrue(uniqueValueService.isUniqueValueOccupied(TYPE, DUMMY_COMBINATION));
}
@Test
public void shouldReturnFalseIfValueNotExist() {
doReturn(Optional.empty()).when(uniqueValueRepositoryMock).findById(any());
- assertFalse(uniqueValueService.isUniqueValueOccupied(TYPE, new String[]{DUMMY_COMBINATION}));
+ assertFalse(uniqueValueService.isUniqueValueOccupied(TYPE, DUMMY_COMBINATION));
}
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java
new file mode 100644
index 00000000..719531bf
--- /dev/null
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java
@@ -0,0 +1,301 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.onap.sdc.workflow.services.impl;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import static org.onap.sdc.workflow.services.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND;
+import static org.onap.sdc.workflow.services.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecAction;
+import org.onap.sdc.workflow.persistence.ActivitySpecRepository;
+import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
+import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter;
+import org.onap.sdc.workflow.services.UniqueValueService;
+import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
+import org.onap.sdc.workflow.services.exceptions.VersionStatusModificationException;
+import org.onap.sdc.workflow.services.impl.mappers.ActivitySpecMapper;
+import org.openecomp.sdc.common.errors.SdcRuntimeException;
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.Item;
+
+public class ActivitySpecManagerImplTest {
+
+ private static final String STRING_TYPE = "String";
+ private static final String TEST_ERROR_MSG = "Test Error";
+ private static final String ID = "ID1";
+ private Version version01 = new Version("12345");
+ private ActivitySpecEntity input;
+
+ @Spy
+ @InjectMocks
+ private ActivitySpecManagerImpl activitySpecManager;
+ @Mock
+ private ItemManager itemManagerMock;
+ @Mock
+ private VersioningManager versionManagerMock;
+ @Mock
+ private ActivitySpecRepository activitySpecRepositoryMock;
+ @Mock
+ private UniqueValueService uniqueValueServiceMock;
+ @Mock
+ private ActivitySpecMapper activitySpecMapperMock;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @After
+ public void tearDown() {
+ activitySpecManager = null;
+ }
+
+ @Test
+ public void testCreate() {
+ ActivitySpecEntity activitySpecToCreate = new ActivitySpecEntity();
+ activitySpecToCreate.setName("startserver");
+ activitySpecToCreate.setDescription("start the server");
+ activitySpecToCreate.setVersion(version01);
+
+ List<String> categoryList = new ArrayList<>();
+ categoryList.add("category1");
+ categoryList.add("category2");
+ activitySpecToCreate.setCategoryList(categoryList);
+
+ ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", STRING_TYPE, null);
+ inputParams.setValue("localhost");
+ ActivitySpecParameter inputParams1 = new ActivitySpecParameter("dbname", STRING_TYPE, null);
+ inputParams.setValue("prod");
+ List<ActivitySpecParameter> inputs = new ArrayList<>();
+ inputs.add(inputParams);
+ inputs.add(inputParams1);
+ activitySpecToCreate.setInputs(inputs);
+
+ ActivitySpecParameter outputParams = new ActivitySpecParameter("status", STRING_TYPE, null);
+ outputParams.setValue("started");
+ List<ActivitySpecParameter> outputs = new ArrayList<>();
+ outputs.add(outputParams);
+ activitySpecToCreate.setOutputs(outputs);
+
+ activitySpecToCreate.setId("ID1");
+ activitySpecToCreate.setVersion(version01);
+
+ Item mappedItem = new Item();
+ doReturn(mappedItem).when(activitySpecMapperMock).activitySpecToItem(activitySpecToCreate);
+ doReturn(new Item()).when(itemManagerMock).create(mappedItem);
+
+ ActivitySpecEntity activitySpec = activitySpecManager.createActivitySpec(activitySpecToCreate);
+
+ Assert.assertNotNull(activitySpec);
+ activitySpec.setId("ID1");
+ activitySpec.setStatus(VersionStatus.Draft.name());
+ assertActivitySpecEquals(activitySpec, activitySpecToCreate);
+ }
+
+ private void assertActivitySpecEquals(ActivitySpecEntity actual, ActivitySpecEntity expected) {
+ Assert.assertEquals(actual.getId(), expected.getId());
+ Assert.assertEquals(actual.getName(), expected.getName());
+ Assert.assertEquals(actual.getDescription(), expected.getDescription());
+ Assert.assertEquals(actual.getCategoryList(), expected.getCategoryList());
+ Assert.assertEquals(actual.getInputs(), expected.getInputs());
+ Assert.assertEquals(actual.getOutputs(), expected.getOutputs());
+ }
+
+ @Test
+ public void testList() {
+ Item item = new Item();
+ item.setId(ID);
+ doReturn(Collections.singletonList(item)).when(itemManagerMock).list(any());
+ doReturn(new ActivitySpecEntity(ID, null)).when(activitySpecMapperMock).itemToActivitySpec(item);
+
+ final Collection<ActivitySpecEntity> activitySpecs = activitySpecManager.list("Certified");
+ Assert.assertEquals(1, activitySpecs.size());
+ Assert.assertEquals(ID, activitySpecs.iterator().next().getId());
+ }
+
+ @Test
+ public void testListInvalidFilter() {
+ final Collection<ActivitySpecEntity> activitySpecs = activitySpecManager.list("invalid_status");
+ Assert.assertEquals(0, activitySpecs.size());
+ }
+
+ @Test
+ public void testListNoFilter() {
+ final Collection<ActivitySpecEntity> activitySpecs = activitySpecManager.list(null);
+ Assert.assertEquals(0, activitySpecs.size());
+ }
+
+ @Test
+ public void testGet() {
+ input = new ActivitySpecEntity();
+ input.setId(ID);
+ input.setVersion(version01);
+
+ mockListVersions();
+ doReturn(input).when(activitySpecRepositoryMock).get(any());
+ version01.setStatus(VersionStatus.Draft);
+ doReturn(version01).when(versionManagerMock).get(any(), any());
+ ActivitySpecEntity retrieved = activitySpecManager.get(input);
+ assertActivitySpecEquals(retrieved, input);
+ Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name());
+
+
+ input.setVersion(new Version(VERSION_ID_DEFAULT_VALUE));
+ retrieved = activitySpecManager.get(input);
+ assertActivitySpecEquals(retrieved, input);
+ Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name());
+ }
+
+ private void mockListVersions() {
+ doReturn(Collections.singletonList(version01)).when(versionManagerMock).list(any());
+ }
+
+ @Test
+ public void testGetActivitySpecDaoFail() {
+ input = new ActivitySpecEntity();
+ input.setId(ID);
+ input.setVersion(version01);
+ mockListVersions();
+ doReturn(input).when(activitySpecRepositoryMock).get(any());
+ Mockito.doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(activitySpecRepositoryMock).get(any());
+ try {
+ activitySpecManager.get(input);
+ Assert.fail();
+ } catch (EntityNotFoundException exception) {
+ Assert.assertEquals(ACTIVITY_SPEC_NOT_FOUND, exception.getMessage());
+ }
+ }
+
+ @Test
+ public void testListVersionFail() {
+ input = new ActivitySpecEntity();
+ input.setId(ID);
+ input.setVersion(version01);
+ input.getVersion().setId(VERSION_ID_DEFAULT_VALUE);
+ Mockito.doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).list(any());
+ try {
+ activitySpecManager.get(input);
+ Assert.fail();
+ } catch (EntityNotFoundException exception) {
+ Assert.assertEquals(ACTIVITY_SPEC_NOT_FOUND, exception.getMessage());
+ }
+ }
+
+ @Test(expected = VersionStatusModificationException.class)
+ public void testInvalidDeprecate() {
+ Version version = new Version(version01.getId());
+ version.setStatus(VersionStatus.Draft);
+ doReturn(version).when(versionManagerMock).get(ID, version01);
+ activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.DEPRECATE);
+ }
+
+ @Test(expected = VersionStatusModificationException.class)
+ public void testInvalidDelete() {
+ mockCertifiedVersion();
+ activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.DELETE);
+ }
+
+ private void mockCertifiedVersion() {
+ Version version = new Version(version01.getId());
+ version.setStatus(VersionStatus.Certified);
+ doReturn(version).when(versionManagerMock).get(ID, version01);
+ }
+
+ @Test(expected = VersionStatusModificationException.class)
+ public void testInvalidCertify() {
+ mockCertifiedVersion();
+ activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.CERTIFY);
+ }
+
+ @Test
+ public void testCertify() {
+ Version retrievedVersion = new Version(version01.getId());
+ retrievedVersion.setStatus(VersionStatus.Draft);
+ doReturn(Collections.singletonList(retrievedVersion)).when(versionManagerMock).list(any());
+ doReturn(retrievedVersion).when(versionManagerMock).get(any(), any());
+
+ activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.CERTIFY);
+
+ verify(versionManagerMock).updateVersion(ID, retrievedVersion);
+ verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Certified, VersionStatus.Draft);
+ verify(versionManagerMock).publish(ID, retrievedVersion, "actionOnActivitySpec :CERTIFY");
+ }
+
+ @Test
+ public void testGetVersionFailOnStatusChangeAction() {
+ mockListVersions();
+ Mockito.doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).get(any(), any());
+ try {
+ activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.CERTIFY);
+ Assert.fail();
+ } catch (EntityNotFoundException exception) {
+ Assert.assertEquals(ACTIVITY_SPEC_NOT_FOUND, exception.getMessage());
+ }
+ }
+
+ @Test
+ public void testDeprecate() {
+ version01.setStatus(VersionStatus.Certified);
+ Version retrivedVersion = new Version("12");
+ retrivedVersion.setStatus(VersionStatus.Certified);
+ mockListVersions();
+ doReturn(retrivedVersion).when(versionManagerMock).get(any(), any());
+ activitySpecManager.actOnAction(new ActivitySpecEntity(ID, new Version(VERSION_ID_DEFAULT_VALUE)), ActivitySpecAction.DEPRECATE);
+
+ verify(versionManagerMock).updateVersion(ID, retrivedVersion);
+ verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deprecated, VersionStatus.Certified);
+ verify(versionManagerMock).publish(any(), any(), any());
+ }
+
+ @Test
+ public void testDelete() {
+ ActivitySpecEntity activitySpec = new ActivitySpecEntity();
+ version01.setStatus(VersionStatus.Deprecated);
+ activitySpec.setName("stopServer");
+ activitySpec.setVersion(version01);
+
+ Version retrivedVersion = new Version("12");
+ retrivedVersion.setStatus(VersionStatus.Deprecated);
+
+ mockListVersions();
+ doReturn(retrivedVersion).when(versionManagerMock).get(any(), any());
+ doReturn(activitySpec).when(activitySpecRepositoryMock).get(any());
+ activitySpecManager.actOnAction(new ActivitySpecEntity(ID, new Version(VERSION_ID_DEFAULT_VALUE)), ActivitySpecAction.DELETE);
+
+ verify(versionManagerMock).updateVersion(ID, version01);
+ verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deleted, VersionStatus.Deprecated);
+ verify(versionManagerMock).publish(any(), any(), any());
+ }
+}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java
index de17a049..2b93075b 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java
@@ -25,8 +25,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.onap.sdc.workflow.persistence.types.Workflow;
-import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.onap.sdc.workflow.services.types.Workflow;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.onap.sdc.workflow.services.UniqueValueService;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
index be6fe04e..9640fa1b 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
@@ -7,15 +7,13 @@ import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.onap.sdc.workflow.persistence.types.WorkflowVersionState.CERTIFIED;
-import static org.onap.sdc.workflow.persistence.types.WorkflowVersionState.DRAFT;
+import static org.onap.sdc.workflow.services.types.WorkflowVersionState.CERTIFIED;
+import static org.onap.sdc.workflow.services.types.WorkflowVersionState.DRAFT;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -32,8 +30,8 @@ import org.onap.sdc.workflow.persistence.ArtifactRepository;
import org.onap.sdc.workflow.persistence.ParameterRepository;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
import org.onap.sdc.workflow.persistence.types.ParameterRole;
-import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
-import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.onap.sdc.workflow.services.types.WorkflowVersion;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.exceptions.VersionCreationException;
import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException;
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java
index d9790355..3ee3c07c 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java
@@ -5,8 +5,8 @@ import static org.junit.Assert.assertEquals;
import java.util.Date;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
-import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.onap.sdc.workflow.services.types.WorkflowVersion;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java
index 070c433e..b69b0f7b 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java
@@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java
index 55802cc0..d6e16d57 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java
@@ -8,7 +8,7 @@ import static org.onap.sdc.workflow.TestUtil.createWorkflow;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.sdc.workflow.persistence.types.Workflow;
+import org.onap.sdc.workflow.services.types.Workflow;
import org.openecomp.sdc.versioning.types.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;