summaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java22
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperationTest.java117
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java213
3 files changed, 75 insertions, 277 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java
index 5c5bf8939a..87f01cd97e 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java
@@ -123,21 +123,16 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
}
private Either<InterfaceData, JanusGraphOperationStatus> addInterfaceToGraph(InterfaceDefinition interfaceInfo, String interfaceName, String resourceId) {
-
InterfaceData interfaceData = new InterfaceData(interfaceInfo);
-
ResourceMetadataData resourceData = new ResourceMetadataData();
resourceData.getMetadataDataDefinition().setUniqueId(resourceId);
String interfaceNameSplitted = getShortInterfaceName(interfaceInfo);
-
interfaceInfo.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, interfaceNameSplitted));
Either<InterfaceData, JanusGraphOperationStatus> existInterface = janusGraphGenericDao
.getNode(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), InterfaceData.class);
-
if (existInterface.isRight()) {
-
return createInterfaceNodeAndRelation(interfaceNameSplitted, resourceId, interfaceData, resourceData);
} else {
log.debug("Interface {} already exist", interfaceData.getUniqueId());
@@ -205,7 +200,6 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
@Override
public Either<Map<String, InterfaceDefinition>, StorageOperationStatus> getAllInterfacesOfResource(String resourceId, boolean recursively, boolean inTransaction) {
-
Either<Map<String, InterfaceDefinition>, StorageOperationStatus> result = null;
Map<String, InterfaceDefinition> interfaces = new HashMap<>();
try {
@@ -242,7 +236,6 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
}
private JanusGraphOperationStatus findAllInterfacesNotRecursively(String resourceId, Map<String, InterfaceDefinition> interfaces) {
-
Either<List<ImmutablePair<InterfaceData, GraphEdge>>, JanusGraphOperationStatus> interfaceNodes = janusGraphGenericDao
.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), resourceId, GraphEdgeLabels.INTERFACE,
NodeTypeEnum.Interface, InterfaceData.class);
@@ -286,7 +279,6 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
}
public JanusGraphOperationStatus findAllInterfacesRecursively(String resourceId, Map<String, InterfaceDefinition> interfaces) {
-
JanusGraphOperationStatus
findAllInterfacesNotRecursively = findAllInterfacesNotRecursively(resourceId, interfaces);
if (!findAllInterfacesNotRecursively.equals(JanusGraphOperationStatus.OK)) {
@@ -307,10 +299,9 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
return parentNodesStatus;
}
}
- ImmutablePair<ResourceMetadataData, GraphEdge> parnetNodePair = parentNodes.left().value();
- String parentUniqueId = parnetNodePair.getKey().getMetadataDataDefinition().getUniqueId();
- JanusGraphOperationStatus
- addParentIntStatus = findAllInterfacesRecursively(parentUniqueId, interfaces);
+ ImmutablePair<ResourceMetadataData, GraphEdge> parentNodePair = parentNodes.left().value();
+ String parentUniqueId = parentNodePair.getKey().getMetadataDataDefinition().getUniqueId();
+ JanusGraphOperationStatus addParentIntStatus = findAllInterfacesRecursively(parentUniqueId, interfaces);
if (addParentIntStatus != JanusGraphOperationStatus.OK) {
log.error("Failed to fetch all interfaces of resource {}", parentUniqueId);
@@ -642,9 +633,7 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
@Override
public Either<InterfaceDefinition, StorageOperationStatus> createInterfaceOnResource(InterfaceDefinition interf, String resourceId, String interfaceName, boolean failIfExist, boolean inTransaction) {
-
Either<InterfaceData, JanusGraphOperationStatus> status = addInterfaceToGraph(interf, interfaceName, resourceId);
-
if (status.isRight()) {
janusGraphGenericDao.rollback();
log.error("Failed to add interface {} to resource {}", interfaceName, resourceId);
@@ -711,7 +700,7 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
janusGraphGenericDao.commit();
}
- Operation opDefResult = status.left().value();// convertOperationDataToOperation(operationData);
+ Operation opDefResult = status.left().value();
log.debug("The returned Operation is {}", opDefResult);
return Either.left(opDefResult);
}
@@ -916,9 +905,6 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
return interfaceName.toLowerCase();
}
- /**
- *
- */
public Either<InterfaceDefinition, StorageOperationStatus> createInterfaceType(InterfaceDefinition interf) {
return createInterfaceType(interf, false);
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperationTest.java
index 7c8dc3c805..d6414c5f25 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperationTest.java
@@ -32,14 +32,10 @@ import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.*;
-import org.openecomp.sdc.be.model.category.CategoryDefinition;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil;
import org.openecomp.sdc.be.resources.data.*;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -59,35 +55,28 @@ public class ArtifactOperationTest extends ModelTestBase {
@javax.annotation.Resource(name = "janusgraph-generic-dao")
private JanusGraphGenericDao janusGraphDao;
- @javax.annotation.Resource(name = "tosca-operation-facade")
- private ToscaOperationFacade toscaOperationFacade;
-
@javax.annotation.Resource
private ArtifactOperation artifactOperation;
- private static final Logger log = LoggerFactory.getLogger(ToscaOperationFacade.class);
-
- private static String RESOURCE_ID = "resourceId";
- private static String RESOURCE_ID_2 = "resourceId2";
+ private static final String RESOURCE_ID = "resourceId";
+ private static final String RESOURCE_ID_2 = "resourceId2";
- private static String USER_ID = "muUserId";
- private static String CATEGORY_NAME = "category/mycategory";
+ private static final String USER_ID = "muUserId";
@BeforeClass
public static void setupBeforeClass() {
-
ModelTestBase.init();
}
@Before
public void createUserAndCategory() {
+ String CATEGORY_NAME = "category/mycategory";
deleteAndCreateCategory(CATEGORY_NAME);
- deleteAndCreateUser(USER_ID, "first_" + USER_ID, "last_" + USER_ID, null);
+ deleteAndCreateUser();
}
@Test
public void testCreateDeleteArtifactWithHeatParams() {
-
ArtifactDefinition artifactWithHeat = createResourceWithHeat();
List<HeatParameterDefinition> heatParameters = artifactWithHeat.getListHeatParameters();
@@ -113,7 +102,6 @@ public class ArtifactOperationTest extends ModelTestBase {
@Test
public void testUpdateArtifactWithHeatParams() {
-
ArtifactDefinition artifactWithHeat = createResourceWithHeat();
List<HeatParameterDefinition> heatParameters = artifactWithHeat.getListHeatParameters();
@@ -125,7 +113,7 @@ public class ArtifactOperationTest extends ModelTestBase {
assertTrue(parameterNode.isLeft());
// update to artifact without params
- ArtifactDefinition artifactNoParams = createArtifactDefinition(USER_ID, RESOURCE_ID, ARTIFACT_NAME);
+ ArtifactDefinition artifactNoParams = createArtifactDefinition();
artifactNoParams.setUniqueId(artifactWithHeat.getUniqueId());
artifactNoParams.setArtifactType("HEAT");
artifactNoParams.setArtifactVersion("2");
@@ -180,11 +168,10 @@ public class ArtifactOperationTest extends ModelTestBase {
Either<HeatParameterData, JanusGraphOperationStatus> parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class);
assertTrue(parameterNodeAfterDelete.isLeft());
- Either<ArtifactDefinition, StorageOperationStatus> removeArifact = artifactOperation.removeArifactFromResource(RESOURCE_ID_2, (String) artifactAfterUpdateValue.getUniqueId(), NodeTypeEnum.Resource, true, false);
- removeArifact = artifactOperation.removeArifactFromResource(RESOURCE_ID, artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, true, false);
+ artifactOperation.removeArifactFromResource(RESOURCE_ID_2, artifactAfterUpdateValue.getUniqueId(), NodeTypeEnum.Resource, true, false);
+ artifactOperation.removeArifactFromResource(RESOURCE_ID, artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, true, false);
janusGraphDao.deleteNode(new UniqueIdData(NodeTypeEnum.Resource, RESOURCE_ID), ResourceMetadataData.class);
janusGraphDao.deleteNode(new UniqueIdData(NodeTypeEnum.Resource, RESOURCE_ID_2), ResourceMetadataData.class);
-
}
@Test
@@ -240,13 +227,13 @@ public class ArtifactOperationTest extends ModelTestBase {
ArtifactData updatedArtifactData = updatedArtifact.left().value();
assertEquals(atifactToUpdate.getArtifactVersion(), updatedArtifactData.getArtifactDataDefinition()
.getArtifactVersion());
- assertFalse(((String) updatedArtifactData.getUniqueId()).equalsIgnoreCase((String) origArtifactData.getUniqueId()));
+ assertFalse(updatedArtifactData.getUniqueId().equalsIgnoreCase(origArtifactData.getUniqueId()));
List<HeatParameterDefinition> heatParametersAfterUpdate = artifactDefinitionUpdated.getListHeatParameters();
assertNotNull(heatParametersAfterUpdate);
assertEquals(1, heatParametersAfterUpdate.size());
HeatParameterDefinition UpdatedHeatParameter = heatParametersAfterUpdate.get(0);
- assertFalse(UpdatedHeatParameter.getUniqueId().equalsIgnoreCase((String) parameterData.getUniqueId()));
+ assertFalse(UpdatedHeatParameter.getUniqueId().equalsIgnoreCase(parameterData.getUniqueId()));
Either<HeatParameterData, JanusGraphOperationStatus> parameterNodeAfterUpdate = janusGraphDao.getNode(new HeatParameterData(UpdatedHeatParameter).getUniqueIdKey(), UpdatedHeatParameter.getUniqueId(), HeatParameterData.class);
assertTrue(parameterNodeAfterUpdate.isLeft());
@@ -277,8 +264,8 @@ public class ArtifactOperationTest extends ModelTestBase {
}
private ArtifactDefinition createResourceWithHeat() {
- ResourceMetadataData resource = createResource(RESOURCE_ID);
- ArtifactDefinition artifactDefinition = createArtifactDefinition(USER_ID, RESOURCE_ID, ARTIFACT_NAME);
+ createResource(RESOURCE_ID);
+ ArtifactDefinition artifactDefinition = createArtifactDefinition();
artifactDefinition.setArtifactType("HEAT");
artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
@@ -297,97 +284,43 @@ public class ArtifactOperationTest extends ModelTestBase {
return artifact.left().value();
}
- private ArtifactDefinition addArtifactToService(String userId, String serviceId, String artifactName) {
- ArtifactDefinition artifactInfo = createArtifactDefinition(userId, serviceId, artifactName);
-
- Either<ArtifactDefinition, StorageOperationStatus> artifact = artifactOperation.addArifactToComponent(artifactInfo, serviceId, NodeTypeEnum.Service, true, true);
- assertTrue(artifact.isLeft());
- return artifact.left().value();
- }
-
- private ArtifactDefinition createArtifactDefinition(String userId, String serviceId, String artifactName) {
+ private ArtifactDefinition createArtifactDefinition() {
ArtifactDefinition artifactInfo = new ArtifactDefinition();
- artifactInfo.setArtifactName(artifactName + ".sh");
+ artifactInfo.setArtifactName(ArtifactOperationTest.ARTIFACT_NAME + ".sh");
artifactInfo.setArtifactType("SHELL");
artifactInfo.setDescription("hdkfhskdfgh");
artifactInfo.setArtifactChecksum("UEsDBAoAAAAIAAeLb0bDQz");
- artifactInfo.setUserIdCreator(userId);
+ artifactInfo.setUserIdCreator(ArtifactOperationTest.USER_ID);
String fullName = "Jim H";
artifactInfo.setUpdaterFullName(fullName);
long time = System.currentTimeMillis();
artifactInfo.setCreatorFullName(fullName);
artifactInfo.setCreationDate(time);
artifactInfo.setLastUpdateDate(time);
- artifactInfo.setUserIdLastUpdater(userId);
- artifactInfo.setArtifactLabel(artifactName);
- artifactInfo.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(serviceId, artifactInfo.getArtifactLabel()));
+ artifactInfo.setUserIdLastUpdater(ArtifactOperationTest.USER_ID);
+ artifactInfo.setArtifactLabel(ArtifactOperationTest.ARTIFACT_NAME);
+ artifactInfo.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(ArtifactOperationTest.RESOURCE_ID, artifactInfo.getArtifactLabel()));
return artifactInfo;
}
- public Service createService(String userId, CategoryDefinition category, String serviceName, String serviceVersion, boolean isHighestVersion) {
-
- Service service = buildServiceMetadata(userId, category, serviceName, serviceVersion);
-
- service.setHighestVersion(isHighestVersion);
-
- Either<Service, StorageOperationStatus> result = toscaOperationFacade.createToscaComponent(service);
-
- log.info(result.toString());
- assertTrue(result.isLeft());
- Service resultService = result.left().value();
-
- // assertEquals("check resource unique id",
- // UniqueIdBuilder.buildServiceUniqueId(serviceName, serviceVersion),
- // resultService.getUniqueId());
- assertEquals("check resource state", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, resultService.getLifecycleState());
-
- return resultService;
- }
-
- private Service buildServiceMetadata(String userId, CategoryDefinition category, String serviceName, String serviceVersion) {
-
- Service service = new Service();
- service.setName(serviceName);
- service.setVersion(serviceVersion);
- service.setDescription("description 1");
-
- service.setCreatorUserId(userId);
- service.setContactId("contactId@sdc.com");
- List<CategoryDefinition> categories = new ArrayList<>();
- categories.add(category);
- service.setCategories(categories);
- service.setIcon("images/my.png");
- List<String> tags = new ArrayList<>();
- tags.add("TAG1");
- tags.add("TAG2");
- service.setTags(tags);
- return service;
- }
-
private void deleteAndCreateCategory(String category) {
String[] names = category.split("/");
OperationTestsUtil.deleteAndCreateServiceCategory(category, janusGraphDao);
OperationTestsUtil.deleteAndCreateResourceCategory(names[0], names[1], janusGraphDao);
}
- private UserData deleteAndCreateUser(String userId, String firstName, String lastName, String role) {
+ private void deleteAndCreateUser() {
UserData userData = new UserData();
- userData.setUserId(userId);
- userData.setFirstName(firstName);
- userData.setLastName(lastName);
- if (role != null && !role.isEmpty()) {
- userData.setRole(role);
- } else {
- userData.setRole("ADMIN");
- }
-
- janusGraphDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.User), userId, UserData.class);
+ userData.setUserId(ArtifactOperationTest.USER_ID);
+ userData.setFirstName("first_muUserId");
+ userData.setLastName("last_muUserId");
+ userData.setRole("ADMIN");
+
+ janusGraphDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.User), ArtifactOperationTest.USER_ID, UserData.class);
janusGraphDao.createNode(userData, UserData.class);
janusGraphDao.commit();
-
- return userData;
}
public ResourceMetadataData createResource(String resourceName) {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java
index 975181d471..8262d54bc4 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java
@@ -20,10 +20,9 @@
package org.openecomp.sdc.be.model.operations.impl;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -32,42 +31,38 @@ import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
+import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.ModelTestBase;
-import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil;
-import org.openecomp.sdc.be.resources.data.category.CategoryData;
import org.openecomp.sdc.be.resources.data.InterfaceData;
import org.openecomp.sdc.be.resources.data.OperationData;
+import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
import org.openecomp.sdc.be.resources.data.UserData;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.openecomp.sdc.be.resources.data.category.CategoryData;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
-import org.junit.Assert;
-
-import static org.junit.Assert.assertNotNull;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
public class InterfaceLifecycleOperationTest {
- private static final Logger log = LoggerFactory.getLogger(InterfaceLifecycleOperationTest.class);
- private Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
private static String USER_ID = "muUserId";
private static String CATEGORY_NAME = "category/mycategory";
@@ -75,16 +70,9 @@ public class InterfaceLifecycleOperationTest {
@InjectMocks
private InterfaceLifecycleOperation interfaceLifecycleOperation = new InterfaceLifecycleOperation();
- @javax.annotation.Resource(name = "property-operation")
- private PropertyOperation propertyOperation;
-
- // @Resource(name = "artifact-operation")
- // private ArtifactOperation artifactOperation;
-
@Before
public void createUserAndCategory() {
MockitoAnnotations.initMocks(this);
- final String UNIQUE_ID = "UNIQUE_ID";
CategoryData categoryData = new CategoryData(NodeTypeEnum.ResourceCategory);
when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.left(categoryData));
deleteAndCreateCategory(CATEGORY_NAME);
@@ -93,167 +81,25 @@ public class InterfaceLifecycleOperationTest {
@BeforeClass
public static void setupBeforeClass() {
- // ExternalConfiguration.setAppName("catalog-model");
- // String appConfigDir = "src/test/resources/config/catalog-model";
- // ConfigurationSource configurationSource = new
- // FSConfigurationSource(ExternalConfiguration.getChangeListener(),
- // appConfigDir);
-
ModelTestBase.init();
-
}
@Test
public void testDummy() {
-
assertNotNull(interfaceLifecycleOperation);
-
- }
-
-/* @Test
- public void addInterfaceToResourceTest() {
-
- String capabilityTypeName = "mycapability1";
- String reqName = "host";
- String reqNodeName = "tosca.nodes.Compute1";
- String rootName = "Root100";
- String softwareCompName = "tosca.nodes.SoftwareComponent";
- String computeNodeName = "tosca.nodes.Compute";
- String myResourceVersion = "300.0";
- String reqRelationship = "myrelationship";
-
- ResourceOperationTest resourceOperationTest = new ResourceOperationTest();
- resourceOperationTest.setOperations(janusGraphDao, resourceOperation, propertyOperation);
-
- Resource rootResource = resourceOperationTest.createResource(USER_ID, CATEGORY_NAME, rootName, "100.0", null, true, true);
-
- String interfaceName = "standard";
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
-
- Operation op = buildOperationDefinition();
- Map<String, Operation> operations = new HashMap<String, Operation>();
- operations.put("Create", op);
- interfaceDefinition.setOperations(operations);
-
- Either<InterfaceDefinition, StorageOperationStatus> result = interfaceOperation.addInterfaceToResource(interfaceDefinition, rootResource.getUniqueId(), "standard");
-
- assertTrue(result.isLeft());
- log.debug("{}", result.left().value());
-
- Either<Resource, StorageOperationStatus> getResourceRes = resourceOperation.getResource(rootResource.getUniqueId());
- assertTrue(getResourceRes.isLeft());
- Resource resourceWithInterface = getResourceRes.left().value();
- Map<String, InterfaceDefinition> interfaces = resourceWithInterface.getInterfaces();
- assertNotNull(interfaces);
- assertFalse(interfaces.isEmpty());
- InterfaceDefinition interfaceDefinition2 = interfaces.get(interfaceName);
- assertNotNull(interfaceDefinition2.getOperations());
- assertFalse(interfaceDefinition2.getOperations().isEmpty());
-
- }
-
- @Test
- public void updateInterfaceToResourceTest() {
-
- String reqName = "host";
- String rootName = "Root200";
- String softwareCompName = "tosca.nodes.SoftwareComponent";
-
- ResourceOperationTest resourceOperationTest = new ResourceOperationTest();
- resourceOperationTest.setOperations(janusGraphDao, resourceOperation, propertyOperation);
-
- Resource rootResource = resourceOperationTest.createResource(USER_ID, CATEGORY_NAME, rootName, "200.0", null, true, true);
-
- String interfaceName = "standard";
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
-
- Operation op = buildOperationDefinition();
- Map<String, Operation> operations = new HashMap<String, Operation>();
- operations.put("create", op);
- interfaceDefinition.setOperations(operations);
-
- Either<InterfaceDefinition, StorageOperationStatus> result = interfaceOperation.addInterfaceToResource(interfaceDefinition, rootResource.getUniqueId(), "standard");
-
- ResourceMetadataData resourceData = new ResourceMetadataData();
- resourceData.getMetadataDataDefinition().setUniqueId(rootResource.getUniqueId());
- resourceData.getMetadataDataDefinition().setState(LifecycleStateEnum.CERTIFIED.name());
- Either<ResourceMetadataData, JanusGraphOperationStatus> updateNode = janusGraphDao.updateNode(resourceData, ResourceMetadataData.class);
- assertTrue(updateNode.isLeft());
-
- Either<Resource, StorageOperationStatus> fetchRootResource = resourceOperation.getResource(rootResource.getUniqueId());
-
- assertTrue(fetchRootResource.isLeft());
- String rootResourceJson = prettyGson.toJson(fetchRootResource.left().value());
- log.debug(rootResourceJson);
-
- Resource softwareComponent = resourceOperationTest.createResource(USER_ID, CATEGORY_NAME, softwareCompName, "400.0", rootResource.getName(), true, true);
-
- assertTrue(result.isLeft());
- log.debug("{}", result.left().value());
-
- addImplementationToOperation(op);
- // String resourceId, String interfaceName, String
- // operationName,Operation interf
-
- Either<Operation, StorageOperationStatus> opResult = interfaceOperation.updateInterfaceOperation(softwareComponent.getUniqueId(), "standard", "create", op);
- // PrintGraph pg = new PrintGraph();
- // System.out.println(pg.buildGraphForWebgraphWiz(janusGraphDao.getGraph().left().value()));
- assertTrue(opResult.isLeft());
- log.debug("{}", opResult.left().value());
-
- Either<Resource, StorageOperationStatus> getResourceRes = resourceOperation.getResource(softwareComponent.getUniqueId());
- assertTrue(getResourceRes.isLeft());
- Resource resourceWithInterface = getResourceRes.left().value();
- Map<String, InterfaceDefinition> interfaces = resourceWithInterface.getInterfaces();
- assertNotNull(interfaces);
- assertFalse(interfaces.isEmpty());
- InterfaceDefinition interfaceDefinition2 = interfaces.get(interfaceName);
- assertNotNull(interfaceDefinition2.getOperations());
- assertFalse(interfaceDefinition2.getOperations().isEmpty());
- Operation operation = interfaceDefinition2.getOperations().get("create");
- assertNotNull(operation);
- assertNotNull(operation.getImplementation());
- }
-*/
- private void addImplementationToOperation(Operation op) {
- ArtifactDataDefinition artifactDataDef = new ArtifactDataDefinition();
- artifactDataDef.setArtifactChecksum("YTg2Mjg4MWJhNmI5NzBiNzdDFkMWI=");
- artifactDataDef.setArtifactName("create_myRoot.sh");
- artifactDataDef.setArtifactLabel("create_myRoot");
- artifactDataDef.setArtifactType("SHELL");
- artifactDataDef.setDescription("good description");
- artifactDataDef.setEsId("esId");
- artifactDataDef.setUniqueId(op.getUniqueId() + "." + artifactDataDef.getArtifactLabel());
- ArtifactDefinition artifactDef = new ArtifactDefinition(artifactDataDef, "UEsDBAoAAAAIAAeLb0bDQz");
- op.setImplementation(artifactDef);
}
private InterfaceDefinition buildInterfaceDefinition() {
InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
interfaceDefinition.setType("tosca.interfaces.standard");
- interfaceDefinition.setCreationDate(new Long(101232));
+ interfaceDefinition.setCreationDate(101232L);
return interfaceDefinition;
}
- private Operation buildOperationDefinition() {
- Operation op = new Operation();
- op.setCreationDate(new Long(101232));
- op.setDescription("asda");
-
- return op;
- }
-
private void deleteAndCreateCategory(String category) {
String[] names = category.split("/");
OperationTestsUtil.deleteAndCreateResourceCategory(names[0], names[1], janusGraphGenericDao);
-
- /*
- * CategoryData categoryData = new CategoryData(); categoryData.setName(category);
- *
- * janusGraphDao.deleteNode(categoryData, CategoryData.class); Either<CategoryData, JanusGraphOperationStatus> createNode = janusGraphDao .createNode(categoryData, CategoryData.class); System.out.println("after creating caetgory " + createNode);
- */
-
}
private UserData deleteAndCreateUser(String userId, String firstName, String lastName) {
@@ -271,6 +117,39 @@ public class InterfaceLifecycleOperationTest {
}
@Test
+ public void createInterfaceOnResourceTest() {
+ when(janusGraphGenericDao.getChildrenNodes(any(), any(), any(), any(), eq(InterfaceData.class))).thenReturn(Either.right(JanusGraphOperationStatus.GRAPH_IS_NOT_AVAILABLE));
+ when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ when(janusGraphGenericDao.getNode(any(), any(), eq(InterfaceData.class))).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
+ when(janusGraphGenericDao.createNode(any(), eq(InterfaceData.class))).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
+ when(janusGraphGenericDao.createRelation(any(), any(), eq(GraphEdgeLabels.INTERFACE), any())).thenReturn(Either.right(JanusGraphOperationStatus.OK));
+ Assert.assertTrue(interfaceLifecycleOperation.createInterfaceOnResource(buildInterfaceDefinition(), "", "", false, false).isRight());
+ when(janusGraphGenericDao.createRelation(any(), any(), eq(GraphEdgeLabels.INTERFACE), any())).thenReturn(Either.left(Mockito.mock(GraphRelation.class)));
+ Assert.assertTrue(interfaceLifecycleOperation.createInterfaceOnResource(buildInterfaceDefinition(), "", "", false, false).isRight());
+ }
+
+ @Test
+ public void getAllInterfacesOfResourceTest() {
+ assertTrue(interfaceLifecycleOperation.getAllInterfacesOfResource(null, true).isRight());
+ when(janusGraphGenericDao.getChildrenNodes(any(), any(), any(), any(), eq(InterfaceData.class))).thenReturn(Either.right(JanusGraphOperationStatus.GRAPH_IS_NOT_AVAILABLE));
+ when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ assertTrue(interfaceLifecycleOperation.getAllInterfacesOfResource("null", true).isLeft());
+
+ when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
+ assertTrue(interfaceLifecycleOperation.getAllInterfacesOfResource("null", true).isRight());
+
+ ResourceMetadataData key = Mockito.mock(ResourceMetadataData.class);
+ ComponentMetadataDataDefinition def = Mockito.mock(ComponentMetadataDataDefinition.class);
+ when(def.getUniqueId()).thenReturn("UNIIIIIIQUE IDDDD");
+ when(key.getMetadataDataDefinition()).thenReturn(def);
+ ImmutablePair<ResourceMetadataData, GraphEdge> pair = new ImmutablePair<>(key, Mockito.mock(GraphEdge.class));
+ when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class)))
+ .thenReturn(Either.left(pair))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ assertTrue(interfaceLifecycleOperation.getAllInterfacesOfResource("null", true).isLeft());
+ }
+
+ @Test
public void testGetAllInterfaceLifecycleTypes_TypesNotFound() {
when(janusGraphGenericDao.getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(),
InterfaceData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));