summaryrefslogtreecommitdiffstats
path: root/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'services/activity-spec/activity-spec-web/activity-spec-service/src/test/java')
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java400
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java245
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/ActivitySpecDaoMock.java39
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/ItemManagerMock.java81
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/UniqueValueDaoMock.java49
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/VersionManagerMock.java105
6 files changed, 919 insertions, 0 deletions
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java
new file mode 100644
index 0000000000..e6b8123823
--- /dev/null
+++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java
@@ -0,0 +1,400 @@
+/*
+ * 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.openecomp.activityspec.be.dao.impl;
+
+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 org.openecomp.activityspec.be.dao.impl.ActivitySpecDaoZusammenImpl.InfoPropertyName;
+import org.openecomp.activityspec.be.datatypes.ActivitySpecData;
+import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
+import org.openecomp.activityspec.be.datatypes.ElementType;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.types.ElementPropertyName;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+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 static org.mockito.Mockito.verify;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+
+public class ActivitySpecZusammenDaoImplTest {
+
+ 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";
+
+ ZusammenAdaptorMock zusammenAdaptor;
+ ActivitySpecDaoZusammenImpl daoImpl;
+ ActivitySpecEntity entity;
+
+
+ @BeforeMethod
+ public void setUp(){
+ SessionContextProviderFactory.getInstance().createInterface().create("test",
+ tenant);
+ zusammenAdaptor = new ZusammenAdaptorMock();
+ daoImpl = new ActivitySpecDaoZusammenImpl(zusammenAdaptor);
+ entity = new ActivitySpecEntity();
+ entity = new ActivitySpecEntity();
+
+ entity.setId(itemId);
+ version.setId(versionId);
+ entity.setVersion(version);
+ entity.setName("activitySpec");
+ List<String> categoryList = new ArrayList<String>();
+ categoryList.add("category1");
+ entity.setCategoryList(categoryList);
+ ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", "String");
+ inputParams.setValue("localhost");
+ List<ActivitySpecParameter> inputs = new ArrayList<>();
+ inputs.add(inputParams);
+ entity.setInputParameters(inputs);
+ }
+
+ @AfterMethod
+ 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,
+ ElementType.ACTIVITYSPEC.name() );
+ Assert.assertTrue(testElementInfo.isPresent());
+ Assert.assertEquals(testElementInfo.get().getInfo().getName(), ElementType.ACTIVITYSPEC.name());
+ Assert.assertEquals(testElementInfo.get().getInfo().getProperty(
+ ActivitySpecDaoZusammenImpl.InfoPropertyName.DESCRIPTION.getValue()),
+ entity.getDescription());
+ Assert.assertEquals(testElementInfo.get().getInfo().getProperty(
+ InfoPropertyName.CATEGORY.getValue()),
+ entity.getCategoryList());
+ Assert.assertEquals(testElementInfo.get().getInfo().getProperty(
+ ActivitySpecDaoZusammenImpl.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.getInputParameters().get(0).getName(),
+ entity.getInputParameters().get(0).getName());
+ }
+
+ @Test
+ public void testGet () {
+ SessionContext context = createSessionContext();
+ ElementContext elementContext =
+ new ElementContext(entity.getId(), entity.getVersion().getId());
+ 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 () {
+ SessionContext context = createSessionContext();
+ ElementContext elementContext =
+ new ElementContext(entity.getId(), entity.getVersion().getId());
+ 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 ItemVersion itemVersion;
+ private Map<String,Element> elementMap = new HashMap<>();
+ String elementId;
+
+ /* private void setItemVersion(ItemVersion itemVersion) {
+ this.itemVersion = itemVersion;
+ }
+
+ private void addElementInfo(String key, ElementInfo elementInfo) {
+ elementInfoMap.put(key, elementInfo);
+ }
+
+ private void addElement(Element element) {
+ elements.add(element);
+ }*/
+
+ @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 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 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 Collection<HealthInfo> checkHealth(SessionContext context) {
+ return null;
+ }
+
+ @Override
+ public Id createItem(SessionContext context, Info info) {
+ return null;
+ }
+
+ @Override
+ public void updateItem(SessionContext context, Id itemId, Info info) {
+
+ }
+
+ @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 Optional<ElementInfo> getElementInfo(SessionContext context,
+ ElementContext elementContext,
+ Id elementId) {
+ return Optional.empty();
+ }
+
+ @Override
+ public String getVersion(SessionContext sessionContext) {
+ return null;
+ }
+
+ @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 Optional<ElementConflict> getElementConflict(SessionContext context,
+ ElementContext elementContext,
+ Id id) {
+ return Optional.empty();
+ }
+
+ @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) {
+
+ }
+
+ }
+
+}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java
new file mode 100644
index 0000000000..ce0f2883fa
--- /dev/null
+++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java
@@ -0,0 +1,245 @@
+/*
+ * 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.openecomp.activityspec.be.impl;
+
+import java.util.Collection;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.openecomp.activityspec.api.rest.types.ActivitySpecAction;
+import org.openecomp.activityspec.be.dao.ActivitySpecDao;
+import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
+import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter;
+import org.openecomp.core.dao.UniqueValueDao;
+import org.openecomp.activityspec.mocks.ActivitySpecDaoMock;
+import org.openecomp.activityspec.mocks.ItemManagerMock;
+import org.openecomp.activityspec.mocks.UniqueValueDaoMock;
+import org.openecomp.activityspec.mocks.VersionManagerMock;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+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;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ActivitySpecManagerImplTest {
+
+ private static final String STRING_TYPE = "String";
+ ActivitySpecEntity activitySpec;
+ private ActivitySpecEntity retrieved;
+ private ActivitySpecEntity input;
+ private ActivitySpecEntity activitySpecToCreate;
+
+ @Spy
+ @InjectMocks
+ private ActivitySpecManagerImpl activitySpecManager;
+
+
+ private ActivitySpecDao activitySpecDaoMock = new ActivitySpecDaoMock();
+
+
+ private ItemManager itemManagerMock = new ItemManagerMock();
+
+
+ private VersioningManager versionManagerMock = new VersionManagerMock() {
+ };
+
+ private UniqueValueDao uniqueValueDaoMock = new UniqueValueDaoMock();
+ private ActivitySpecEntity retrivedAfterNameUpdate;
+
+ @BeforeMethod
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ activitySpecManager = new ActivitySpecManagerImpl(itemManagerMock, versionManagerMock,
+ activitySpecDaoMock, uniqueValueDaoMock);
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ activitySpecManager = null;
+ }
+
+
+ public static final Version VERSION01 = new Version("12345");
+
+ @Test
+ public void testCreate() {
+
+ SessionContextProviderFactory.getInstance().createInterface().create("testUser", "testTenant");
+
+ 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);
+ inputParams.setValue("localhost");
+ ActivitySpecParameter inputParams1 = new ActivitySpecParameter("dbname", STRING_TYPE);
+ inputParams.setValue("prod");
+ List<ActivitySpecParameter> inputs = new ArrayList<>();
+ inputs.add(inputParams);
+ inputs.add(inputParams1);
+ activitySpecToCreate.setInputParameters(inputs);
+
+ ActivitySpecParameter outputParams = new ActivitySpecParameter("status", STRING_TYPE);
+ outputParams.setValue("started");
+ List<ActivitySpecParameter> outputs = new ArrayList<>();
+ outputs.add(outputParams);
+ activitySpecToCreate.setOutputParameters(outputs);
+
+ activitySpec = activitySpecManager.createActivitySpec
+ (activitySpecToCreate);
+
+ Assert.assertNotNull(activitySpec);
+ activitySpecToCreate.setId(activitySpec.getId());
+ activitySpecToCreate.setVersion(VERSION01);
+ assertActivitySpecEquals(activitySpec, activitySpecToCreate);
+ }
+
+ @Test(dependsOnMethods = "testCreate")
+ public void testList () {
+ //List
+ final Collection<Item> activitySpecs = activitySpecManager.list("Certified");
+ Assert.assertEquals(activitySpecs.size(), 1);
+ }
+
+ @Test(dependsOnMethods = "testCreate")
+ public void testGet () {
+ //Get
+ input = new ActivitySpecEntity();
+ input.setId(activitySpec.getId());
+ input.setVersion(activitySpec.getVersion());
+ retrieved = activitySpecManager.get(input);
+ assertActivitySpecEquals(retrieved, activitySpec);
+ Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name());
+
+ input.setVersion(new Version("LATEST"));
+ retrieved = activitySpecManager.get(input);
+ assertActivitySpecEquals(retrieved, activitySpec);
+ Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name());
+ }
+
+ @Test(dependsOnMethods = "testGet")
+ public void testInvalidDeprecate () {
+ try {
+ activitySpecManager.actOnAction(retrieved.getId(),
+ VERSION01.getId(), ActivitySpecAction.DEPRECATE);
+ }
+ catch (CoreException exception) {
+ Assert.assertEquals(exception.code().id(), "STATUS_NOT_"+VersionStatus.Certified.name()
+ .toUpperCase());
+ }
+ }
+
+ @Test(dependsOnMethods = "testGet")
+ public void testInvalidDelete () {
+ try {
+ activitySpecManager.actOnAction(retrieved.getId(),
+ VERSION01.getId(), ActivitySpecAction.DELETE);
+ }
+ catch (CoreException exception) {
+ Assert.assertEquals(exception.code().id(), "STATUS_NOT_"+VersionStatus.Deprecated.name()
+ .toUpperCase());
+ }
+ }
+
+ @Test(dependsOnMethods = "testGet")
+ public void testUpdate () {
+ //Update
+ retrieved.setDescription("Updated_install");
+ activitySpecManager.update(retrieved);
+
+ final ActivitySpecEntity retrivedAfterUpdate = activitySpecManager.get(input);
+ assertActivitySpecEquals(retrivedAfterUpdate, activitySpecToCreate);
+
+ //Update Name
+ ActivitySpecEntity activitySpecToUpdate = new ActivitySpecEntity();
+ activitySpecToUpdate.setId(activitySpec.getId());
+ activitySpecToUpdate.setName("Updated_start_server");
+ activitySpecToUpdate.setVersion(activitySpec.getVersion());
+
+ activitySpecManager.update(activitySpecToUpdate);
+
+ retrivedAfterNameUpdate = activitySpecManager.get(input);
+ assertActivitySpecEquals(retrivedAfterNameUpdate, activitySpecToUpdate);
+ Assert.assertEquals(retrivedAfterNameUpdate.getStatus(), VersionStatus.Draft.name());
+ }
+
+ @Test(dependsOnMethods = "testUpdate")
+ public void testCertify () {
+ activitySpecManager.actOnAction(retrivedAfterNameUpdate.getId(),
+ VERSION01.getId(), ActivitySpecAction.CERTIFY);
+
+ final ActivitySpecEntity retrivedAfterCertify = activitySpecManager.get(retrivedAfterNameUpdate);
+ assertActivitySpecEquals(retrivedAfterCertify, retrivedAfterNameUpdate );
+ Assert.assertEquals(retrivedAfterCertify.getStatus(), VersionStatus.Certified.name());
+ }
+
+ @Test(dependsOnMethods = "testCertify")
+ public void testInvalidCertify () {
+ try {
+ activitySpecManager.actOnAction(retrieved.getId(),
+ VERSION01.getId(), ActivitySpecAction.CERTIFY);
+ }
+ catch (CoreException exception) {
+ Assert.assertEquals(exception.code().id(), "STATUS_NOT_"+VersionStatus.Draft.name()
+ .toUpperCase());
+ }
+ }
+
+ @Test(dependsOnMethods = "testCertify")
+ public void testDeprecate () {
+ activitySpecManager.actOnAction(retrivedAfterNameUpdate.getId(),
+ retrivedAfterNameUpdate.getVersion().getId(), ActivitySpecAction.DEPRECATE);
+
+ final ActivitySpecEntity retrivedAfterDeprecate = activitySpecManager.get(retrivedAfterNameUpdate);
+ assertActivitySpecEquals(retrivedAfterDeprecate, retrivedAfterNameUpdate );
+ Assert.assertEquals(retrivedAfterDeprecate.getStatus(), VersionStatus.Deprecated.name());
+ }
+
+ @Test(dependsOnMethods = "testDeprecate")
+ public void testDelete () {
+ activitySpecManager.actOnAction(retrivedAfterNameUpdate.getId(),
+ retrivedAfterNameUpdate.getVersion().getId(), ActivitySpecAction.DELETE);
+
+ final ActivitySpecEntity retrivedAfterDelete = activitySpecManager.get(retrivedAfterNameUpdate);
+ assertActivitySpecEquals(retrivedAfterDelete, retrivedAfterNameUpdate );
+ Assert.assertEquals(retrivedAfterDelete.getStatus(), VersionStatus.Deleted.name());
+ }
+
+ 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.getInputParameters(), expected.getInputParameters());
+ Assert.assertEquals(actual.getOutputParameters(), expected.getOutputParameters());
+ }
+}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/ActivitySpecDaoMock.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/ActivitySpecDaoMock.java
new file mode 100644
index 0000000000..4e21435900
--- /dev/null
+++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/ActivitySpecDaoMock.java
@@ -0,0 +1,39 @@
+/*
+ * 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.openecomp.activityspec.mocks;
+
+import org.openecomp.activityspec.be.dao.ActivitySpecDao;
+import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
+
+public class ActivitySpecDaoMock implements ActivitySpecDao {
+ public ActivitySpecEntity activitySpec;
+
+ @Override
+ public void create(ActivitySpecEntity activitySpecEntity) {
+ activitySpec = activitySpecEntity;
+ }
+
+ @Override
+ public ActivitySpecEntity get(ActivitySpecEntity activitySpecEntity) {
+ return activitySpec;
+ }
+
+ @Override
+ public void update(ActivitySpecEntity activitySpecEntity) {
+ activitySpec = activitySpecEntity;
+ }
+}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/ItemManagerMock.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/ItemManagerMock.java
new file mode 100644
index 0000000000..667a97b3a4
--- /dev/null
+++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/ItemManagerMock.java
@@ -0,0 +1,81 @@
+/*
+ * 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.openecomp.activityspec.mocks;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.Item;
+import org.openecomp.sdc.versioning.ItemManager;
+import java.util.Collection;
+import java.util.UUID;
+import java.util.function.Predicate;
+
+public class ItemManagerMock implements ItemManager {
+
+ public String id;
+ public Item item;
+
+
+ @Override
+ public Collection<Item> list(Predicate<Item> predicate) {
+ List<Item> items = new ArrayList<>();
+ items.add(item);
+ Collection<Item> collection = items;
+ return items;
+ }
+
+ @Override
+ public Item get(String itemId) {
+ return null;
+ }
+
+ @Override
+ public Item create(Item item) {
+ this.id = UUID.randomUUID().toString();
+ item.setId(this.id);
+ this.item = item;
+ return item;
+ }
+
+ @Override
+ public void updateVersionStatus(String itemId, VersionStatus addedVersionStatus,
+ VersionStatus removedVersionStatus) {
+
+ }
+
+
+
+ @Override
+ public void updateName(String itemId, String name) {
+
+ }
+
+ @Override
+ public void update(Item item) {
+
+ }
+
+ @Override
+ public void delete(Item item) {
+
+ }
+
+}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/UniqueValueDaoMock.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/UniqueValueDaoMock.java
new file mode 100644
index 0000000000..675c3b1878
--- /dev/null
+++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/UniqueValueDaoMock.java
@@ -0,0 +1,49 @@
+/*
+ * 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.openecomp.activityspec.mocks;
+
+import org.openecomp.core.dao.UniqueValueDao;
+import org.openecomp.core.dao.types.UniqueValueEntity;
+
+import java.util.Collection;
+
+public class UniqueValueDaoMock implements UniqueValueDao {
+ @Override
+ public Collection<UniqueValueEntity> list(UniqueValueEntity entity) {
+ return null;
+ }
+
+ @Override
+ public void create(UniqueValueEntity entity) {
+
+ }
+
+ @Override
+ public void update(UniqueValueEntity entity) {
+
+ }
+
+ @Override
+ public UniqueValueEntity get(UniqueValueEntity entity) {
+ return null;
+ }
+
+ @Override
+ public void delete(UniqueValueEntity entity) {
+
+ }
+}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/VersionManagerMock.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/VersionManagerMock.java
new file mode 100644
index 0000000000..4b1deb3741
--- /dev/null
+++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/mocks/VersionManagerMock.java
@@ -0,0 +1,105 @@
+/*
+ * 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.openecomp.activityspec.mocks;
+
+import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.dao.types.Revision;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deprecated;
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deleted;
+
+public class VersionManagerMock implements VersioningManager {
+
+ private String id;
+ private Version version;
+
+
+ @Override
+ public List<Version> list(String itemId) {
+ List<Version> versions = new ArrayList<Version>();
+ versions.add(version);
+ return versions;
+ }
+
+
+ @Override
+ public Version get(String itemId, Version version) {
+ return this.version;
+ }
+
+ @Override
+ public Version create(String itemId, Version version, VersionCreationMethod creationMethod) {
+ this.id = UUID.randomUUID().toString();
+ version.setId(this.id);
+ version.setStatus(VersionStatus.Draft);
+ this.version = version;
+
+ return version;
+ }
+
+ @Override
+ public void submit(String itemId, Version version, String submitDescription) {
+
+ }
+
+
+ @Override
+ public void publish(String itemId, Version version, String message) {
+
+ }
+
+ @Override
+ public void sync(String itemId, Version version) {
+
+ }
+
+ @Override
+ public void forceSync(String itemId, Version version) {
+
+ }
+
+ @Override
+ public void revert(String itemId, Version version, String revisionId) {
+
+ }
+
+ @Override
+ public List<Revision> listRevisions(String itemId, Version version) {
+ return null;
+ }
+
+ @Override
+ public void updateVersion(String itemId, Version version) {
+ if (version.getStatus() == Certified) {
+ this.version.setStatus(Certified);
+ }
+ if (version.getStatus() == Deprecated) {
+ this.version.setStatus(Deprecated);
+ }
+ if (version.getStatus() == Deleted) {
+ this.version.setStatus(Deleted);
+ }
+ }
+}