From f0d4dd5c846f1c56d8b2641934c028b8151b31b3 Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 15 Nov 2021 12:27:54 +0000 Subject: Fix test cases failing incorrectly https://gerrit.onap.org/r/c/sdc/+/124980 Change-Id: I9fbd8a0b5b83d04928feea7624e593b45441ac9b Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3757 --- .../sdc/be/resources/JanusGraphGenericDaoTest.java | 1087 ++++++++++---------- 1 file changed, 544 insertions(+), 543 deletions(-) (limited to 'catalog-dao/src/test/java/org') diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JanusGraphGenericDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JanusGraphGenericDaoTest.java index 09ab6a1745..549841c6cb 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JanusGraphGenericDaoTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JanusGraphGenericDaoTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,23 +20,30 @@ package org.openecomp.sdc.be.resources; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import com.google.gson.Gson; -import org.janusgraph.core.PropertyKey; -import org.janusgraph.core.JanusGraphEdge; -import org.janusgraph.core.JanusGraphFactory; -import org.janusgraph.core.JanusGraph; -import org.janusgraph.core.JanusGraphVertex; -import org.janusgraph.core.attribute.Text; -import org.janusgraph.core.schema.JanusGraphManagement; import fj.data.Either; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.annotation.Resource; import org.apache.commons.configuration.BaseConfiguration; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphEdge; +import org.janusgraph.core.JanusGraphFactory; +import org.janusgraph.core.JanusGraphVertex; +import org.janusgraph.core.PropertyKey; +import org.janusgraph.core.attribute.Text; +import org.janusgraph.core.schema.JanusGraphManagement; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; @@ -45,586 +52,580 @@ import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; import org.openecomp.sdc.be.dao.utils.UserStatusEnum; import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.resources.data.*; +import org.openecomp.sdc.be.resources.data.AdditionalInfoParameterData; +import org.openecomp.sdc.be.resources.data.ArtifactData; +import org.openecomp.sdc.be.resources.data.ComponentInstanceData; +import org.openecomp.sdc.be.resources.data.GraphNodeLock; +import org.openecomp.sdc.be.resources.data.ResourceMetadataData; +import org.openecomp.sdc.be.resources.data.UserData; import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.api.UserRoleEnum; import org.openecomp.sdc.common.impl.ExternalConfiguration; import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.support.DirtiesContextTestExecutionListener; import org.springframework.test.context.transaction.TransactionalTestExecutionListener; -import javax.annotation.Resource; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") -@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class, - DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class }) +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") +@TestExecutionListeners(listeners = {DependencyInjectionTestExecutionListener.class, + DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class}) public class JanusGraphGenericDaoTest { - private static Logger log = LoggerFactory.getLogger(JanusGraphGenericDaoTest.class.getName()); - private static ConfigurationManager configurationManager; - - @Resource(name = "janusgraph-generic-dao") - private JanusGraphGenericDao janusGraphDao; - - @BeforeClass - public static void setupBeforeClass() { - ExternalConfiguration.setAppName("catalog-dao"); - String appConfigDir = "src/test/resources/config/catalog-dao"; - ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), - appConfigDir); - configurationManager = new ConfigurationManager(configurationSource); - configurationManager.getConfiguration().setJanusGraphCfgFile("../catalog-be/src/main/resources/config/janusgraph.properties"); - configurationManager.getConfiguration().setJanusGraphInMemoryGraph(true); - } - - // @Test - public void testcheckEdgeProps() { - JanusGraph graph = janusGraphDao.getGraph().left().value(); - JanusGraphVertex v1 = graph.addVertex(); - v1.property("prop1", 123); - JanusGraphVertex v2 = graph.addVertex(); - v2.property("prop1", 456); - JanusGraphEdge addEdge = v1.addEdge("label11", v2); - addEdge.property("edgeProp", "my prop edge"); - graph.tx().commit(); - - Either v11 = janusGraphDao.getVertexByProperty("prop1", 123); - Iterator edges = v11.left().value().edges(Direction.OUT, "label11"); - Edge edge = edges.next(); - // String value = (String)edge.value("edgeProp"); - String value = (String) janusGraphDao.getProperty(edge, "edgeProp"); - log.debug(value); - - } - - @Test - public void testCrudNode() { - - String id = "userId12345abc"; - UserData userData = new UserData("Myname123", "Mylastname", id, "email123", "Tester", - UserStatusEnum.ACTIVE.name(), null); - - Either newNode = janusGraphDao.createNode(userData, UserData.class); - - assertTrue(newNode.isLeft()); - - log.debug("{}", newNode.left().value()); - - janusGraphDao.commit(); - - ImmutablePair keyValueId = userData.getKeyValueId(); - Either node = janusGraphDao.getNode(keyValueId.getKey(), keyValueId.getValue(), - UserData.class); - janusGraphDao.commit(); - assertTrue(node.isLeft()); - log.debug("{}", node.left().value()); - - userData.setRole("Designer"); - node = janusGraphDao.updateNode(userData, UserData.class); - assertTrue(node.isLeft()); - log.debug("{}", node.left().value()); - assertEquals(null, "Designer", node.left().value().getRole()); - janusGraphDao.commit(); - - node = janusGraphDao.deleteNode(userData, UserData.class); - assertTrue(node.isLeft()); - log.debug("{}", node.left().value()); - janusGraphDao.commit(); - - node = janusGraphDao.getNode(keyValueId.getKey(), keyValueId.getValue(), UserData.class); - assertTrue(node.isRight()); - log.debug("{}", node.right().value()); - - } - - @Test - public void testGetByCategoryAndAll() { - - // create 2 nodes - String id = "userId12345abc"; - UserData userData1 = new UserData("Myname123", "Mylastname", id, "email123", "Tester", - UserStatusEnum.ACTIVE.name(), null); - - Either node1 = janusGraphDao.createNode(userData1, UserData.class); - assertTrue(node1.isLeft()); - log.debug("{}", node1.left().value()); - - id = "userIddfkoer45abc"; - UserData userData2 = new UserData("Mynadyhme123", "Mylasghtname", id, "emaighdl123", "Designer", - UserStatusEnum.ACTIVE.name(), null); - Either node2 = janusGraphDao.createNode(userData2, UserData.class); - assertTrue(node2.isLeft()); - log.debug("{}", node2.left().value()); - - janusGraphDao.commit(); - - ImmutablePair keyValueId1 = userData1.getKeyValueId(); - // get first node - Either node = janusGraphDao.getNode(keyValueId1.getKey(), keyValueId1.getValue(), - UserData.class); - assertTrue(node.isLeft()); - log.debug("{}", node.left().value()); - janusGraphDao.commit(); - - // get all must be 2 + 1 default user = 3 - Either, JanusGraphOperationStatus> all = janusGraphDao.getAll(NodeTypeEnum.User, UserData.class); - assertTrue(all.isLeft()); - assertTrue(all.left().value().size() > 0); - - log.debug("{}", all.left().value()); - - Map props = new HashMap<>(); - - props.put(keyValueId1.getKey(), keyValueId1.getValue()); - - // get by criteria. must be 1 - Either, JanusGraphOperationStatus> byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.User, props, - UserData.class); - assertTrue(byCriteria.isLeft()); - assertEquals(1, byCriteria.left().value().size()); - - log.debug("{}", byCriteria.left().value()); - - // delete all nodes - node = janusGraphDao.deleteNode(userData1, UserData.class); - assertTrue(node.isLeft()); - node = janusGraphDao.deleteNode(userData2, UserData.class); - assertTrue(node.isLeft()); - } - - @Test - public void testGetEdgesForNode() { - String id = "userId12345abc"; - UserData userData = new UserData("Myname123", "Mylastname", id, "email123", UserRoleEnum.ADMIN.name(), - UserStatusEnum.ACTIVE.name(), null); - janusGraphDao.createNode(userData, UserData.class); - ResourceMetadataData resourceData = new ResourceMetadataData(); - resourceData.getMetadataDataDefinition().setName("resourceForLock"); - resourceData.getMetadataDataDefinition().setVersion("0.1"); - resourceData.getMetadataDataDefinition().setState("newState"); - resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." - + resourceData.getMetadataDataDefinition().getVersion()); - - janusGraphDao.createNode(resourceData, ResourceMetadataData.class); - janusGraphDao.createRelation(userData, resourceData, GraphEdgeLabels.LAST_MODIFIER, null); - janusGraphDao.commit(); - - Either, JanusGraphOperationStatus> eitherEdges = janusGraphDao.getEdgesForNode(userData, Direction.OUT); - assertTrue(eitherEdges.isLeft()); + + private static Logger log = LoggerFactory.getLogger(JanusGraphGenericDaoTest.class.getName()); + private static ConfigurationManager configurationManager; + + @Resource(name = "janusgraph-generic-dao") + private JanusGraphGenericDao janusGraphDao; + + @BeforeAll + public static void setupBeforeClass() { + ExternalConfiguration.setAppName("catalog-dao"); + String appConfigDir = "src/test/resources/config/catalog-dao"; + ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), + appConfigDir); + configurationManager = new ConfigurationManager(configurationSource); + configurationManager.getConfiguration().setJanusGraphCfgFile("../catalog-be/src/main/resources/config/janusgraph.properties"); + configurationManager.getConfiguration().setJanusGraphInMemoryGraph(true); + } + + @Test + public void testcheckEdgeProps() { + JanusGraph graph = janusGraphDao.getGraph().left().value(); + JanusGraphVertex v1 = graph.addVertex(); + v1.property("prop1", 123); + JanusGraphVertex v2 = graph.addVertex(); + v2.property("prop1", 456); + JanusGraphEdge addEdge = v1.addEdge("label11", v2); + addEdge.property("edgeProp", "my prop edge"); + graph.tx().commit(); + + Either v11 = janusGraphDao.getVertexByProperty("prop1", 123); + Iterator edges = v11.left().value().edges(Direction.OUT, "label11"); + Edge edge = edges.next(); + // String value = (String)edge.value("edgeProp"); + String value = (String) janusGraphDao.getProperty(edge, "edgeProp"); + log.debug(value); + + } + + @Test + public void testCrudNode() { + + String id = "userId12345abc"; + UserData userData = new UserData("Myname123", "Mylastname", id, "email123", "Tester", + UserStatusEnum.ACTIVE.name(), null); + + Either newNode = janusGraphDao.createNode(userData, UserData.class); + + assertTrue(newNode.isLeft()); + + log.debug("{}", newNode.left().value()); + + janusGraphDao.commit(); + + ImmutablePair keyValueId = userData.getKeyValueId(); + Either node = janusGraphDao.getNode(keyValueId.getKey(), keyValueId.getValue(), + UserData.class); + janusGraphDao.commit(); + assertTrue(node.isLeft()); + log.debug("{}", node.left().value()); + + userData.setRole("Designer"); + node = janusGraphDao.updateNode(userData, UserData.class); + assertTrue(node.isLeft()); + log.debug("{}", node.left().value()); + assertEquals(null, "Designer", node.left().value().getRole()); + janusGraphDao.commit(); + + node = janusGraphDao.deleteNode(userData, UserData.class); + assertTrue(node.isLeft()); + log.debug("{}", node.left().value()); + janusGraphDao.commit(); + + node = janusGraphDao.getNode(keyValueId.getKey(), keyValueId.getValue(), UserData.class); + assertTrue(node.isRight()); + log.debug("{}", node.right().value()); + + } + + @Test + public void testGetByCategoryAndAll() { + + // create 2 nodes + String id = "userId12345abc"; + UserData userData1 = new UserData("Myname123", "Mylastname", id, "email123", "Tester", + UserStatusEnum.ACTIVE.name(), null); + + Either node1 = janusGraphDao.createNode(userData1, UserData.class); + assertTrue(node1.isLeft()); + log.debug("{}", node1.left().value()); + + id = "userIddfkoer45abc"; + UserData userData2 = new UserData("Mynadyhme123", "Mylasghtname", id, "emaighdl123", "Designer", + UserStatusEnum.ACTIVE.name(), null); + Either node2 = janusGraphDao.createNode(userData2, UserData.class); + assertTrue(node2.isLeft()); + log.debug("{}", node2.left().value()); + + janusGraphDao.commit(); + + ImmutablePair keyValueId1 = userData1.getKeyValueId(); + // get first node + Either node = janusGraphDao.getNode(keyValueId1.getKey(), keyValueId1.getValue(), + UserData.class); + assertTrue(node.isLeft()); + log.debug("{}", node.left().value()); + janusGraphDao.commit(); + + // get all must be 2 + 1 default user = 3 + Either, JanusGraphOperationStatus> all = janusGraphDao.getAll(NodeTypeEnum.User, UserData.class); + assertTrue(all.isLeft()); + assertTrue(all.left().value().size() > 0); + + log.debug("{}", all.left().value()); + + Map props = new HashMap<>(); + + props.put(keyValueId1.getKey(), keyValueId1.getValue()); + + // get by criteria. must be 1 + Either, JanusGraphOperationStatus> byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.User, props, + UserData.class); + assertTrue(byCriteria.isLeft()); + assertEquals(1, byCriteria.left().value().size()); + + log.debug("{}", byCriteria.left().value()); + + // delete all nodes + node = janusGraphDao.deleteNode(userData1, UserData.class); + assertTrue(node.isLeft()); + node = janusGraphDao.deleteNode(userData2, UserData.class); + assertTrue(node.isLeft()); + } + + @Test + public void testGetEdgesForNode() { + String id = "userId12345abc"; + UserData userData = new UserData("Myname123", "Mylastname", id, "email123", UserRoleEnum.ADMIN.name(), + UserStatusEnum.ACTIVE.name(), null); + janusGraphDao.createNode(userData, UserData.class); + ResourceMetadataData resourceData = new ResourceMetadataData(); + resourceData.getMetadataDataDefinition().setName("resourceForLock"); + resourceData.getMetadataDataDefinition().setVersion("0.1"); + resourceData.getMetadataDataDefinition().setState("newState"); + resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." + + resourceData.getMetadataDataDefinition().getVersion()); + + janusGraphDao.createNode(resourceData, ResourceMetadataData.class); + janusGraphDao.createRelation(userData, resourceData, GraphEdgeLabels.LAST_MODIFIER, null); + janusGraphDao.commit(); + + Either, JanusGraphOperationStatus> eitherEdges = janusGraphDao.getEdgesForNode(userData, Direction.OUT); + assertTrue(eitherEdges.isLeft()); assertEquals(1, eitherEdges.left().value().size()); - eitherEdges = janusGraphDao.getEdgesForNode(userData, Direction.IN); - assertTrue(eitherEdges.isLeft()); + eitherEdges = janusGraphDao.getEdgesForNode(userData, Direction.IN); + assertTrue(eitherEdges.isLeft()); assertEquals(0, eitherEdges.left().value().size()); - eitherEdges = janusGraphDao.getEdgesForNode(resourceData, Direction.OUT); - assertTrue(eitherEdges.isLeft()); + eitherEdges = janusGraphDao.getEdgesForNode(resourceData, Direction.OUT); + assertTrue(eitherEdges.isLeft()); assertEquals(0, eitherEdges.left().value().size()); - eitherEdges = janusGraphDao.getEdgesForNode(resourceData, Direction.IN); - assertTrue(eitherEdges.isLeft()); + eitherEdges = janusGraphDao.getEdgesForNode(resourceData, Direction.IN); + assertTrue(eitherEdges.isLeft()); assertEquals(1, eitherEdges.left().value().size()); - eitherEdges = janusGraphDao.getEdgesForNode(resourceData, Direction.BOTH); - assertTrue(eitherEdges.isLeft()); + eitherEdges = janusGraphDao.getEdgesForNode(resourceData, Direction.BOTH); + assertTrue(eitherEdges.isLeft()); assertEquals(1, eitherEdges.left().value().size()); - eitherEdges = janusGraphDao.getEdgesForNode(userData, Direction.BOTH); - assertTrue(eitherEdges.isLeft()); + eitherEdges = janusGraphDao.getEdgesForNode(userData, Direction.BOTH); + assertTrue(eitherEdges.isLeft()); assertEquals(1, eitherEdges.left().value().size()); - janusGraphDao.deleteNode(userData, UserData.class); - janusGraphDao.deleteNode(resourceData, ResourceMetadataData.class); - janusGraphDao.commit(); - } + janusGraphDao.deleteNode(userData, UserData.class); + janusGraphDao.deleteNode(resourceData, ResourceMetadataData.class); + janusGraphDao.commit(); + } + + @Test + public void testLockElement() { + + ResourceMetadataData resourceData = new ResourceMetadataData(); + + resourceData.getMetadataDataDefinition().setName("resourceForLock"); + resourceData.getMetadataDataDefinition().setVersion("0.1"); + resourceData.getMetadataDataDefinition().setState("newState"); + resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." + + resourceData.getMetadataDataDefinition().getVersion()); + + Either resource1 = janusGraphDao.createNode(resourceData, + ResourceMetadataData.class); + assertTrue(resource1.isLeft()); + janusGraphDao.commit(); + String lockId = "lock_" + resourceData.getLabel() + "_" + resource1.left().value().getUniqueId(); + + Either nodeLock = janusGraphDao + .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); + assertTrue(nodeLock.isRight()); + assertEquals(JanusGraphOperationStatus.NOT_FOUND, nodeLock.right().value()); + + JanusGraphOperationStatus status = janusGraphDao.lockElement(resourceData); + assertEquals(JanusGraphOperationStatus.OK, status); - @Test - public void testLockElement() { - - ResourceMetadataData resourceData = new ResourceMetadataData(); + nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); + assertTrue(nodeLock.isLeft()); + assertEquals(lockId, nodeLock.left().value().getUniqueId()); - resourceData.getMetadataDataDefinition().setName("resourceForLock"); - resourceData.getMetadataDataDefinition().setVersion("0.1"); - resourceData.getMetadataDataDefinition().setState("newState"); - resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." - + resourceData.getMetadataDataDefinition().getVersion()); + janusGraphDao.commit(); - Either resource1 = janusGraphDao.createNode(resourceData, - ResourceMetadataData.class); - assertTrue(resource1.isLeft()); - janusGraphDao.commit(); - String lockId = "lock_" + resourceData.getLabel() + "_" + resource1.left().value().getUniqueId(); + status = janusGraphDao.lockElement(resourceData); + assertEquals(JanusGraphOperationStatus.ALREADY_LOCKED, status); - Either nodeLock = janusGraphDao - .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); - assertTrue(nodeLock.isRight()); - assertEquals(JanusGraphOperationStatus.NOT_FOUND, nodeLock.right().value()); + status = janusGraphDao.releaseElement(resourceData); + assertEquals(JanusGraphOperationStatus.OK, status); - JanusGraphOperationStatus status = janusGraphDao.lockElement(resourceData); - assertEquals(JanusGraphOperationStatus.OK, status); + nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); + assertTrue(nodeLock.isRight()); + assertEquals(JanusGraphOperationStatus.NOT_FOUND, nodeLock.right().value()); + janusGraphDao.deleteNode(resourceData, ResourceMetadataData.class); + janusGraphDao.commit(); - nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); - assertTrue(nodeLock.isLeft()); - assertEquals(lockId, nodeLock.left().value().getUniqueId()); + } - janusGraphDao.commit(); + @Test + public void testReLockElement() throws InterruptedException { - status = janusGraphDao.lockElement(resourceData); - assertEquals(JanusGraphOperationStatus.ALREADY_LOCKED, status); + ResourceMetadataData resourceData = new ResourceMetadataData(); - status = janusGraphDao.releaseElement(resourceData); - assertEquals(JanusGraphOperationStatus.OK, status); + resourceData.getMetadataDataDefinition().setName("resourceForReLock"); + resourceData.getMetadataDataDefinition().setVersion("0.1"); + resourceData.getMetadataDataDefinition().setState("newState"); + resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." + + resourceData.getMetadataDataDefinition().getVersion()); - nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); - assertTrue(nodeLock.isRight()); - assertEquals(JanusGraphOperationStatus.NOT_FOUND, nodeLock.right().value()); - janusGraphDao.deleteNode(resourceData, ResourceMetadataData.class); - janusGraphDao.commit(); + Either resource1 = janusGraphDao.createNode(resourceData, + ResourceMetadataData.class); + assertTrue(resource1.isLeft()); + janusGraphDao.commit(); + String lockId = "lock_" + resourceData.getLabel() + "_" + resource1.left().value().getUniqueId(); - } + Either nodeLock = janusGraphDao + .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); + assertTrue(nodeLock.isRight()); + assertEquals(JanusGraphOperationStatus.NOT_FOUND, nodeLock.right().value()); - @Test - public void testReLockElement() throws InterruptedException { - - ResourceMetadataData resourceData = new ResourceMetadataData(); + // lock + JanusGraphOperationStatus status = janusGraphDao.lockElement(resourceData); + assertEquals(JanusGraphOperationStatus.OK, status); - resourceData.getMetadataDataDefinition().setName("resourceForReLock"); - resourceData.getMetadataDataDefinition().setVersion("0.1"); - resourceData.getMetadataDataDefinition().setState("newState"); - resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." - + resourceData.getMetadataDataDefinition().getVersion()); + nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); + assertTrue(nodeLock.isLeft()); + assertEquals(lockId, nodeLock.left().value().getUniqueId()); + long time1 = nodeLock.left().value().getTime(); - Either resource1 = janusGraphDao.createNode(resourceData, - ResourceMetadataData.class); - assertTrue(resource1.isLeft()); - janusGraphDao.commit(); - String lockId = "lock_" + resourceData.getLabel() + "_" + resource1.left().value().getUniqueId(); + janusGraphDao.commit(); - Either nodeLock = janusGraphDao - .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); - assertTrue(nodeLock.isRight()); - assertEquals(JanusGraphOperationStatus.NOT_FOUND, nodeLock.right().value()); + // timeout + configurationManager.getConfiguration().setJanusGraphLockTimeout(2L); + Thread.sleep(5001); - // lock - JanusGraphOperationStatus status = janusGraphDao.lockElement(resourceData); - assertEquals(JanusGraphOperationStatus.OK, status); + // relock + status = janusGraphDao.lockElement(resourceData); + assertEquals(JanusGraphOperationStatus.OK, status); - nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); - assertTrue(nodeLock.isLeft()); - assertEquals(lockId, nodeLock.left().value().getUniqueId()); - long time1 = nodeLock.left().value().getTime(); + nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); + assertTrue(nodeLock.isLeft()); + assertEquals(lockId, nodeLock.left().value().getUniqueId()); - janusGraphDao.commit(); + long time2 = nodeLock.left().value().getTime(); - // timeout - configurationManager.getConfiguration().setJanusGraphLockTimeout(2L); - Thread.sleep(5001); + assertTrue(time2 > time1); - // relock - status = janusGraphDao.lockElement(resourceData); - assertEquals(JanusGraphOperationStatus.OK, status); + status = janusGraphDao.releaseElement(resourceData); + assertEquals(JanusGraphOperationStatus.OK, status); - nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); - assertTrue(nodeLock.isLeft()); - assertEquals(lockId, nodeLock.left().value().getUniqueId()); + nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); + assertTrue(nodeLock.isRight()); + assertEquals(JanusGraphOperationStatus.NOT_FOUND, nodeLock.right().value()); - long time2 = nodeLock.left().value().getTime(); + janusGraphDao.deleteNode(resourceData, ResourceMetadataData.class); + janusGraphDao.commit(); - assertTrue(time2 > time1); + } + + @Test + public void testBoolean() { + ResourceMetadataData resourceData = new ResourceMetadataData(); - status = janusGraphDao.releaseElement(resourceData); - assertEquals(JanusGraphOperationStatus.OK, status); + resourceData.getMetadataDataDefinition().setName("resourceForLock"); + resourceData.getMetadataDataDefinition().setVersion("0.1"); + resourceData.getMetadataDataDefinition().setState("NOT_CERTIFIED_CHECKOUT"); + resourceData.getMetadataDataDefinition().setHighestVersion(true); + resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." + + resourceData.getMetadataDataDefinition().getVersion()); - nodeLock = janusGraphDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class); - assertTrue(nodeLock.isRight()); - assertEquals(JanusGraphOperationStatus.NOT_FOUND, nodeLock.right().value()); - - janusGraphDao.deleteNode(resourceData, ResourceMetadataData.class); - janusGraphDao.commit(); + Either resource1 = janusGraphDao.createNode(resourceData, + ResourceMetadataData.class); + assertTrue(resource1.isLeft()); - } - - @Test - public void testBoolean() { - ResourceMetadataData resourceData = new ResourceMetadataData(); - - resourceData.getMetadataDataDefinition().setName("resourceForLock"); - resourceData.getMetadataDataDefinition().setVersion("0.1"); - resourceData.getMetadataDataDefinition().setState("NOT_CERTIFIED_CHECKOUT"); - resourceData.getMetadataDataDefinition().setHighestVersion(true); - resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." - + resourceData.getMetadataDataDefinition().getVersion()); + resourceData = new ResourceMetadataData(); + + resourceData.getMetadataDataDefinition().setName("resourceForLock"); + resourceData.getMetadataDataDefinition().setVersion("0.2"); + resourceData.getMetadataDataDefinition().setState("NOT_CERTIFIED_CHECKOUT"); + resourceData.getMetadataDataDefinition().setHighestVersion(false); + resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." + + resourceData.getMetadataDataDefinition().getVersion()); + + Either resource2 = janusGraphDao.createNode(resourceData, + ResourceMetadataData.class); + janusGraphDao.commit(); + + Map props = new HashMap<>(); + + props.put(GraphPropertiesDictionary.STATE.getProperty(), "NOT_CERTIFIED_CHECKOUT"); + props.put("name", "resourceForLock"); + props.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), false); + + // get by criteria. must be 1 + Either, JanusGraphOperationStatus> byCriteria = janusGraphDao + .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); + assertTrue(byCriteria.isLeft()); + + janusGraphDao.deleteNode(resource1.left().value(), ResourceMetadataData.class); + + janusGraphDao.deleteNode(resource2.left().value(), ResourceMetadataData.class); + janusGraphDao.commit(); + } + + @Test + public void testStringSearch() { + JanusGraph graph; + + BaseConfiguration conf = new BaseConfiguration(); + conf.setProperty("storage.backend", "inmemory"); + graph = JanusGraphFactory.open(conf); + + // JanusGraphManagement graphMgt = graph.getManagementSystem(); + JanusGraphManagement graphMgt = graph.openManagement(); + PropertyKey propKey = graphMgt.makePropertyKey("string1").dataType(String.class).make(); + graphMgt.buildIndex("string1", Vertex.class).addKey(propKey).unique().buildCompositeIndex(); + + propKey = graphMgt.makePropertyKey("string2").dataType(String.class).make(); + + graphMgt.buildIndex("string2", Vertex.class).addKey(propKey).unique().buildCompositeIndex(); + graphMgt.commit(); + + log.debug("**** predicat index search non case"); + Iterable vertices = graph.query().has("string1", Text.REGEX, "my new string 1").vertices(); + Iterator iter = vertices.iterator(); + while (iter.hasNext()) { + Vertex ver = iter.next(); + // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver)); + log.debug("{}", janusGraphDao.getProperties(ver)); + } + + } + + @Test + public void testDuplicateResultDueToJanusGraphBug() { + + ResourceMetadataData resourceData1 = new ResourceMetadataData(); + resourceData1.getMetadataDataDefinition().setUniqueId("A"); + ((ResourceMetadataDataDefinition) resourceData1.getMetadataDataDefinition()).setAbstract(true); + resourceData1.getMetadataDataDefinition().setName("aaaa"); + + Either newNode1 = janusGraphDao.createNode(resourceData1, + ResourceMetadataData.class); + assertTrue(newNode1.isLeft()); + log.debug("{}", newNode1.left().value()); + // janusGraphDao.commit(); + + Map props = new HashMap<>(); + props.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), true); + Either, JanusGraphOperationStatus> byCriteria = janusGraphDao + .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); + assertTrue(byCriteria.isLeft()); + assertEquals("check one result returned", 1, byCriteria.left().value().size()); + // janusGraphDao.commit(); + + ResourceMetadataData resourceToUpdate = new ResourceMetadataData(); + ((ResourceMetadataDataDefinition) resourceToUpdate.getMetadataDataDefinition()).setAbstract(false); + resourceToUpdate.getMetadataDataDefinition().setUniqueId("A"); + Either updateNode = janusGraphDao.updateNode(resourceToUpdate, + ResourceMetadataData.class); + assertTrue(updateNode.isLeft()); + // janusGraphDao.commit(); + + byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); + assertTrue(byCriteria.isRight()); + assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, + byCriteria.right().value()); + + AdditionalInfoParameterData infoParameterData = new AdditionalInfoParameterData(); + infoParameterData.getAdditionalInfoParameterDataDefinition().setUniqueId("123"); + Map idToKey = new HashMap<>(); + idToKey.put("key1", "value1"); + infoParameterData.setIdToKey(idToKey); + + Either newNode2 = janusGraphDao.createNode(infoParameterData, + AdditionalInfoParameterData.class); + assertTrue(newNode2.isLeft()); + log.debug("{}", newNode2.left().value()); + // janusGraphDao.commit(); + + Map idToKey2 = new HashMap<>(); + idToKey2.put("key1", "value2"); + + Map props2 = new HashMap<>(); + props2.put(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), "123"); + Gson gson = new Gson(); + props2.put(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty(), gson.toJson(idToKey2)); + // props2.put(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty(), + // idToKey2); + + Either, JanusGraphOperationStatus> byCriteria2 = janusGraphDao + .getByCriteria(NodeTypeEnum.AdditionalInfoParameters, props2, AdditionalInfoParameterData.class); + assertTrue(byCriteria2.isRight()); + assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, + byCriteria2.right().value()); + + infoParameterData.setIdToKey(idToKey2); + + Either updateNode2 = janusGraphDao.updateNode(infoParameterData, + AdditionalInfoParameterData.class); + assertTrue(updateNode2.isLeft()); + // janusGraphDao.commit(); + + props2.put(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty(), idToKey); + byCriteria2 = janusGraphDao.getByCriteria(NodeTypeEnum.AdditionalInfoParameters, props2, + AdditionalInfoParameterData.class); + assertTrue(byCriteria2.isRight()); + assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, + byCriteria2.right().value()); + + ComponentInstanceData resourceInstanceData = new ComponentInstanceData(); + resourceInstanceData.getComponentInstDataDefinition().setUniqueId("ri123"); + resourceInstanceData.getComponentInstDataDefinition().setPosX("22"); + resourceInstanceData.getComponentInstDataDefinition().setName("myresource_1"); + + Either newNode3 = janusGraphDao.createNode(resourceInstanceData, + ComponentInstanceData.class); + assertTrue(newNode3.isLeft()); + log.debug("{}", newNode3.left().value()); + // janusGraphDao.commit(); + + resourceInstanceData.getComponentInstDataDefinition().setPosX("50"); + Either updateNode3 = janusGraphDao.updateNode(resourceInstanceData, + ComponentInstanceData.class); + assertTrue(updateNode3.isLeft()); + // janusGraphDao.commit(); + + resourceInstanceData.getComponentInstDataDefinition().setName("myresource_2"); + updateNode3 = janusGraphDao.updateNode(resourceInstanceData, ComponentInstanceData.class); + assertTrue(updateNode3.isLeft()); + // janusGraphDao.commit(); + + Map props3 = new HashMap<>(); + props3.put("positionX", "22"); + Either, JanusGraphOperationStatus> byCriteria3 = janusGraphDao + .getByCriteria(NodeTypeEnum.ResourceInstance, props3, ComponentInstanceData.class); + assertTrue(byCriteria3.isRight()); + assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, + byCriteria3.right().value()); + + props3.put("positionX", "50"); + byCriteria3 = janusGraphDao.getByCriteria(NodeTypeEnum.ResourceInstance, props3, ComponentInstanceData.class); + assertTrue(byCriteria3.isLeft()); + + /////////////////////////// check integer //////////////////////// + + ArtifactData artifactData = new ArtifactData(); + artifactData.getArtifactDataDefinition().setUniqueId("ad234"); + artifactData.getArtifactDataDefinition().setTimeout(100); + + Either newNode4 = janusGraphDao.createNode(artifactData, ArtifactData.class); + assertTrue(newNode4.isLeft()); + log.debug("{}", newNode4.left().value()); + // janusGraphDao.commit(); + + artifactData.getArtifactDataDefinition().setTimeout(50); + Either updateNode4 = janusGraphDao.updateNode(artifactData, ArtifactData.class); + assertTrue(updateNode4.isLeft()); + // janusGraphDao.commit(); + + Map props4 = new HashMap<>(); + props4.put("timeout", 100); + Either, JanusGraphOperationStatus> byCriteria4 = janusGraphDao.getByCriteria(NodeTypeEnum.ArtifactRef, + props4, ArtifactData.class); + assertTrue(byCriteria4.isRight()); + assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, + byCriteria4.right().value()); + + props4.put("timeout", 50); + byCriteria4 = janusGraphDao.getByCriteria(NodeTypeEnum.ArtifactRef, props4, ArtifactData.class); + assertTrue(byCriteria4.isLeft()); + + janusGraphDao.rollback(); + } + + @Test + public void testDuplicateResultUSeHasNotQueryDueToJanusGraphBug() { + + String name = "bbbb"; + + ResourceMetadataData resourceData1 = new ResourceMetadataData(); + resourceData1.getMetadataDataDefinition().setUniqueId("A"); + ((ResourceMetadataDataDefinition) resourceData1.getMetadataDataDefinition()).setAbstract(true); + resourceData1.getMetadataDataDefinition().setName(name); + + Either newNode1 = janusGraphDao.createNode(resourceData1, + ResourceMetadataData.class); + assertTrue(newNode1.isLeft()); + log.debug("{}", newNode1.left().value()); + // janusGraphDao.commit(); + + Map props = new HashMap<>(); + props.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), true); + Either, JanusGraphOperationStatus> byCriteria = janusGraphDao + .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); + assertTrue(byCriteria.isLeft()); + assertEquals("check one result returned", 1, byCriteria.left().value().size()); + // janusGraphDao.commit(); + + ResourceMetadataData resourceToUpdate = new ResourceMetadataData(); + ((ResourceMetadataDataDefinition) resourceToUpdate.getMetadataDataDefinition()).setAbstract(false); + resourceToUpdate.getMetadataDataDefinition().setUniqueId("A"); + Either updateNode = janusGraphDao.updateNode(resourceToUpdate, + ResourceMetadataData.class); + assertTrue(updateNode.isLeft()); + // janusGraphDao.commit(); + + // no result where isAbstract = true + byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); + assertTrue(byCriteria.isRight()); + assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, + byCriteria.right().value()); + + // one result where isAbstract != true + byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.Resource, null, props, ResourceMetadataData.class); + assertTrue(byCriteria.isLeft()); + assertEquals("check one result returned", 1, byCriteria.left().value().size()); + + props.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), false); + byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.Resource, null, props, ResourceMetadataData.class); + assertTrue(byCriteria.isRight()); + assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, + byCriteria.right().value()); + + janusGraphDao.rollback(); + + } - Either resource1 = janusGraphDao.createNode(resourceData, - ResourceMetadataData.class); - assertTrue(resource1.isLeft()); - - resourceData = new ResourceMetadataData(); - - resourceData.getMetadataDataDefinition().setName("resourceForLock"); - resourceData.getMetadataDataDefinition().setVersion("0.2"); - resourceData.getMetadataDataDefinition().setState("NOT_CERTIFIED_CHECKOUT"); - resourceData.getMetadataDataDefinition().setHighestVersion(false); - resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "." - + resourceData.getMetadataDataDefinition().getVersion()); - - Either resource2 = janusGraphDao.createNode(resourceData, - ResourceMetadataData.class); - janusGraphDao.commit(); - - Map props = new HashMap<>(); - - props.put(GraphPropertiesDictionary.STATE.getProperty(), "NOT_CERTIFIED_CHECKOUT"); - props.put("name", "resourceForLock"); - props.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), false); - - // get by criteria. must be 1 - Either, JanusGraphOperationStatus> byCriteria = janusGraphDao - .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); - assertTrue(byCriteria.isLeft()); - - janusGraphDao.deleteNode(resource1.left().value(), ResourceMetadataData.class); - - janusGraphDao.deleteNode(resource2.left().value(), ResourceMetadataData.class); - janusGraphDao.commit(); - } - - // @Test - public void testStringSearch() { - JanusGraph graph; - - BaseConfiguration conf = new BaseConfiguration(); - conf.setProperty("storage.backend", "inmemory"); - graph = JanusGraphFactory.open(conf); - - // JanusGraphManagement graphMgt = graph.getManagementSystem(); - JanusGraphManagement graphMgt = graph.openManagement(); - PropertyKey propKey = graphMgt.makePropertyKey("string1").dataType(String.class).make(); - graphMgt.buildIndex("string1", Vertex.class).addKey(propKey).unique().buildCompositeIndex(); - - propKey = graphMgt.makePropertyKey("string2").dataType(String.class).make(); - - graphMgt.buildIndex("string2", Vertex.class).addKey(propKey).unique().buildCompositeIndex(); - graphMgt.commit(); - - - log.debug("**** predicat index search non case"); - Iterable vertices = graph.query().has("string1", Text.REGEX, "my new string 1").vertices(); - Iterator iter = vertices.iterator(); - while (iter.hasNext()) { - Vertex ver = iter.next(); - // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver)); - log.debug("{}", janusGraphDao.getProperties(ver)); - } - - } - - @Test - public void testDuplicateResultDueToJanusGraphBug() { - - ResourceMetadataData resourceData1 = new ResourceMetadataData(); - resourceData1.getMetadataDataDefinition().setUniqueId("A"); - ((ResourceMetadataDataDefinition) resourceData1.getMetadataDataDefinition()).setAbstract(true); - resourceData1.getMetadataDataDefinition().setName("aaaa"); - - Either newNode1 = janusGraphDao.createNode(resourceData1, - ResourceMetadataData.class); - assertTrue(newNode1.isLeft()); - log.debug("{}", newNode1.left().value()); - // janusGraphDao.commit(); - - Map props = new HashMap<>(); - props.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), true); - Either, JanusGraphOperationStatus> byCriteria = janusGraphDao - .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); - assertTrue(byCriteria.isLeft()); - assertEquals("check one result returned", 1, byCriteria.left().value().size()); - // janusGraphDao.commit(); - - ResourceMetadataData resourceToUpdate = new ResourceMetadataData(); - ((ResourceMetadataDataDefinition) resourceToUpdate.getMetadataDataDefinition()).setAbstract(false); - resourceToUpdate.getMetadataDataDefinition().setUniqueId("A"); - Either updateNode = janusGraphDao.updateNode(resourceToUpdate, - ResourceMetadataData.class); - assertTrue(updateNode.isLeft()); - // janusGraphDao.commit(); - - byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); - assertTrue(byCriteria.isRight()); - assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, - byCriteria.right().value()); - - AdditionalInfoParameterData infoParameterData = new AdditionalInfoParameterData(); - infoParameterData.getAdditionalInfoParameterDataDefinition().setUniqueId("123"); - Map idToKey = new HashMap<>(); - idToKey.put("key1", "value1"); - infoParameterData.setIdToKey(idToKey); - - Either newNode2 = janusGraphDao.createNode(infoParameterData, - AdditionalInfoParameterData.class); - assertTrue(newNode2.isLeft()); - log.debug("{}", newNode2.left().value()); - // janusGraphDao.commit(); - - Map idToKey2 = new HashMap<>(); - idToKey2.put("key1", "value2"); - - Map props2 = new HashMap<>(); - props2.put(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), "123"); - Gson gson = new Gson(); - props2.put(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty(), gson.toJson(idToKey2)); - // props2.put(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty(), - // idToKey2); - - Either, JanusGraphOperationStatus> byCriteria2 = janusGraphDao - .getByCriteria(NodeTypeEnum.AdditionalInfoParameters, props2, AdditionalInfoParameterData.class); - assertTrue(byCriteria2.isRight()); - assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, - byCriteria2.right().value()); - - infoParameterData.setIdToKey(idToKey2); - - Either updateNode2 = janusGraphDao.updateNode(infoParameterData, - AdditionalInfoParameterData.class); - assertTrue(updateNode2.isLeft()); - // janusGraphDao.commit(); - - props2.put(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty(), idToKey); - byCriteria2 = janusGraphDao.getByCriteria(NodeTypeEnum.AdditionalInfoParameters, props2, - AdditionalInfoParameterData.class); - assertTrue(byCriteria2.isRight()); - assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, - byCriteria2.right().value()); - - ComponentInstanceData resourceInstanceData = new ComponentInstanceData(); - resourceInstanceData.getComponentInstDataDefinition().setUniqueId("ri123"); - resourceInstanceData.getComponentInstDataDefinition().setPosX("22"); - resourceInstanceData.getComponentInstDataDefinition().setName("myresource_1"); - - Either newNode3 = janusGraphDao.createNode(resourceInstanceData, - ComponentInstanceData.class); - assertTrue(newNode3.isLeft()); - log.debug("{}", newNode3.left().value()); - // janusGraphDao.commit(); - - resourceInstanceData.getComponentInstDataDefinition().setPosX("50"); - Either updateNode3 = janusGraphDao.updateNode(resourceInstanceData, - ComponentInstanceData.class); - assertTrue(updateNode3.isLeft()); - // janusGraphDao.commit(); - - resourceInstanceData.getComponentInstDataDefinition().setName("myresource_2"); - updateNode3 = janusGraphDao.updateNode(resourceInstanceData, ComponentInstanceData.class); - assertTrue(updateNode3.isLeft()); - // janusGraphDao.commit(); - - Map props3 = new HashMap<>(); - props3.put("positionX", "22"); - Either, JanusGraphOperationStatus> byCriteria3 = janusGraphDao - .getByCriteria(NodeTypeEnum.ResourceInstance, props3, ComponentInstanceData.class); - assertTrue(byCriteria3.isRight()); - assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, - byCriteria3.right().value()); - - props3.put("positionX", "50"); - byCriteria3 = janusGraphDao.getByCriteria(NodeTypeEnum.ResourceInstance, props3, ComponentInstanceData.class); - assertTrue(byCriteria3.isLeft()); - - /////////////////////////// check integer //////////////////////// - - ArtifactData artifactData = new ArtifactData(); - artifactData.getArtifactDataDefinition().setUniqueId("ad234"); - artifactData.getArtifactDataDefinition().setTimeout(100); - - Either newNode4 = janusGraphDao.createNode(artifactData, ArtifactData.class); - assertTrue(newNode4.isLeft()); - log.debug("{}", newNode4.left().value()); - // janusGraphDao.commit(); - - artifactData.getArtifactDataDefinition().setTimeout(50); - Either updateNode4 = janusGraphDao.updateNode(artifactData, ArtifactData.class); - assertTrue(updateNode4.isLeft()); - // janusGraphDao.commit(); - - Map props4 = new HashMap<>(); - props4.put("timeout", 100); - Either, JanusGraphOperationStatus> byCriteria4 = janusGraphDao.getByCriteria(NodeTypeEnum.ArtifactRef, - props4, ArtifactData.class); - assertTrue(byCriteria4.isRight()); - assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, - byCriteria4.right().value()); - - props4.put("timeout", 50); - byCriteria4 = janusGraphDao.getByCriteria(NodeTypeEnum.ArtifactRef, props4, ArtifactData.class); - assertTrue(byCriteria4.isLeft()); - - janusGraphDao.rollback(); - } - - @Test - public void testDuplicateResultUSeHasNotQueryDueToJanusGraphBug() { - - String name = "bbbb"; - - ResourceMetadataData resourceData1 = new ResourceMetadataData(); - resourceData1.getMetadataDataDefinition().setUniqueId("A"); - ((ResourceMetadataDataDefinition) resourceData1.getMetadataDataDefinition()).setAbstract(true); - resourceData1.getMetadataDataDefinition().setName(name); - - Either newNode1 = janusGraphDao.createNode(resourceData1, - ResourceMetadataData.class); - assertTrue(newNode1.isLeft()); - log.debug("{}", newNode1.left().value()); - // janusGraphDao.commit(); - - Map props = new HashMap<>(); - props.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), true); - Either, JanusGraphOperationStatus> byCriteria = janusGraphDao - .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); - assertTrue(byCriteria.isLeft()); - assertEquals("check one result returned", 1, byCriteria.left().value().size()); - // janusGraphDao.commit(); - - ResourceMetadataData resourceToUpdate = new ResourceMetadataData(); - ((ResourceMetadataDataDefinition) resourceToUpdate.getMetadataDataDefinition()).setAbstract(false); - resourceToUpdate.getMetadataDataDefinition().setUniqueId("A"); - Either updateNode = janusGraphDao.updateNode(resourceToUpdate, - ResourceMetadataData.class); - assertTrue(updateNode.isLeft()); - // janusGraphDao.commit(); - - // no result where isAbstract = true - byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class); - assertTrue(byCriteria.isRight()); - assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, - byCriteria.right().value()); - - // one result where isAbstract != true - byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.Resource, null, props, ResourceMetadataData.class); - assertTrue(byCriteria.isLeft()); - assertEquals("check one result returned", 1, byCriteria.left().value().size()); - - props.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), false); - byCriteria = janusGraphDao.getByCriteria(NodeTypeEnum.Resource, null, props, ResourceMetadataData.class); - assertTrue(byCriteria.isRight()); - assertEquals("check one result returned due to janusgraph bug", JanusGraphOperationStatus.NOT_FOUND, - byCriteria.right().value()); - - janusGraphDao.rollback(); - - } - } -- cgit 1.2.3-korg