Search in sources :

Example 1 with NodeHasLocation

use of org.structr.core.entity.relationship.NodeHasLocation in project structr by structr.

the class SearchAndSortingTest method test03SearchRelationship.

@Test
public void test03SearchRelationship() {
    try {
        final NodeHasLocation rel = createTestRelationships(NodeHasLocation.class, 1).get(0);
        final PropertyKey key1 = new StringProperty("jghsdkhgshdhgsdjkfgh").indexed();
        final Class type = NodeHasLocation.class;
        final String val1 = "54354354546806849870";
        final Result<RelationshipInterface> result;
        try (final Tx tx = app.tx()) {
            rel.setProperty(key1, val1);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            assertTrue(rel.getProperty(key1).equals(val1));
            result = app.relationshipQuery(type).and(key1, val1).getResult();
            assertTrue(result.size() == 1);
            assertTrue(result.get(0).equals(rel));
        }
        final String val2 = "ölllldjöoa8w4rasf";
        try (final Tx tx = app.tx()) {
            rel.setProperty(key1, val2);
            tx.success();
        }
        assertTrue(result.size() == 1);
        assertTrue(result.get(0).equals(rel));
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) RelationshipInterface(org.structr.core.graph.RelationshipInterface) StringProperty(org.structr.core.property.StringProperty) NodeHasLocation(org.structr.core.entity.relationship.NodeHasLocation) PropertyKey(org.structr.core.property.PropertyKey) Test(org.junit.Test)

Example 2 with NodeHasLocation

use of org.structr.core.entity.relationship.NodeHasLocation in project structr by structr.

the class BasicTest method test03CreateRelationship.

@Test
public void test03CreateRelationship() {
    try {
        final List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
        final NodeInterface startNode = nodes.get(0);
        final NodeInterface endNode = nodes.get(1);
        NodeHasLocation rel = null;
        assertTrue(startNode != null);
        assertTrue(endNode != null);
        try (final Tx tx = app.tx()) {
            rel = app.create(startNode, endNode, NodeHasLocation.class);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            assertEquals(startNode.getUuid(), rel.getSourceNodeId());
            assertEquals(endNode.getUuid(), rel.getTargetNodeId());
            assertEquals(RelType.IS_AT.name(), rel.getType());
            assertEquals(NodeHasLocation.class, rel.getClass());
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) GenericNode(org.structr.core.entity.GenericNode) NodeHasLocation(org.structr.core.entity.relationship.NodeHasLocation) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test)

Example 3 with NodeHasLocation

use of org.structr.core.entity.relationship.NodeHasLocation in project structr by structr.

the class BasicTest method test05CheckRelationshipEntities.

/**
 * Create a node for each configured entity class and check the type
 */
@Test
public void test05CheckRelationshipEntities() {
    try (final Tx tx = app.tx()) {
        List<Class> entityList = null;
        try {
            entityList = getClasses("org.structr.core.entity");
        } catch (IOException | ClassNotFoundException ex) {
            logger.error("Unable to get list of entity classes", ex);
        }
        assertTrue(entityList.contains(AbstractRelationship.class));
        assertTrue(entityList.contains(GenericRelationship.class));
        for (Class entityClass : entityList) {
            // Class entityClass = entity.getValue();
            if (AbstractRelationship.class.isAssignableFrom(entityClass)) {
                String type = entityClass.getSimpleName();
                logger.info("Creating relationship of type {}", type);
                List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
                final NodeInterface startNode = nodes.get(0);
                final NodeInterface endNode = nodes.get(1);
                final RelationshipType relType = RelType.IS_AT;
                NodeHasLocation rel = app.create(startNode, endNode, NodeHasLocation.class);
                assertTrue(rel != null);
                assertTrue(rel.getType().equals(relType.name()));
            }
        }
        tx.success();
    } catch (Throwable ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) AbstractRelationship(org.structr.core.entity.AbstractRelationship) GenericNode(org.structr.core.entity.GenericNode) RelationshipType(org.structr.api.graph.RelationshipType) IOException(java.io.IOException) GenericRelationship(org.structr.core.entity.GenericRelationship) NodeHasLocation(org.structr.core.entity.relationship.NodeHasLocation) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test)

Example 4 with NodeHasLocation

use of org.structr.core.entity.relationship.NodeHasLocation in project structr by structr.

the class BasicTest method test02ModifyRelationship.

/**
 * Test the results of setProperty and getProperty of a relationship
 */
@Test
public void test02ModifyRelationship() {
    try {
        final NodeHasLocation rel = (createTestRelationships(NodeHasLocation.class, 1)).get(0);
        final PropertyKey key1 = new StringProperty("jghsdkhgshdhgsdjkfgh");
        final String val1 = "54354354546806849870";
        try (final Tx tx = app.tx()) {
            rel.setProperty(key1, val1);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            assertTrue("Expected relationship to have a value for key '" + key1.dbName() + "'", rel.getRelationship().hasProperty(key1.dbName()));
            assertEquals(val1, rel.getRelationship().getProperty(key1.dbName()));
            Object vrfy1 = rel.getProperty(key1);
            assertEquals(val1, vrfy1);
        }
        final String val2 = "öljkhöohü8osdfhoödhi";
        try (final Tx tx = app.tx()) {
            rel.setProperty(key1, val2);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            Object vrfy2 = rel.getProperty(key1);
            assertEquals(val2, vrfy2);
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StringProperty(org.structr.core.property.StringProperty) NodeHasLocation(org.structr.core.entity.relationship.NodeHasLocation) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey) Test(org.junit.Test)

Example 5 with NodeHasLocation

use of org.structr.core.entity.relationship.NodeHasLocation in project structr by structr.

the class PerformanceTest method testPerformanceOfRelationshipCreation.

/**
 * Tests basic throughput of relationship creation operations
 *
 * Note that this is just a very rought test as performance is heavily
 * depending on hardware and setup (cache parameters etc.)
 *
 * The assumed rate is low so if this test fails, there may be issues
 * with the test setup.
 *
 * If the test passes, one can expect structr to create relationship with typical performance.
 */
@Test
public void testPerformanceOfRelationshipCreation() {
    try {
        int expected = 1000;
        final App app = StructrApp.getInstance(setup());
        final List<GenericNode> nodes = new ArrayList<>(createNodes(app, GenericNode.class, expected + 1));
        List<NodeHasLocation> rels = new LinkedList<>();
        long t0 = System.nanoTime();
        try (final Tx tx = app.tx()) {
            for (int i = 0; i < expected; i++) {
                final GenericNode n1 = nodes.get(i);
                final GenericNode n2 = nodes.get(i + 1);
                rels.add(app.create(n1, n2, NodeHasLocation.class));
            }
            tx.success();
        }
        long t1 = System.nanoTime();
        assertEquals("Invalid relationship creation result", expected, rels.size());
        DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
        Double time = (t1 - t0) / 1000000000.0;
        Double rate = expected / ((t1 - t0) / 1000000000.0);
        logger.info("Created {} relationships in {} seconds ({} per s)", new Object[] { expected, decimalFormat.format(time), decimalFormat.format(rate) });
        assertTrue(rate > 50);
    } catch (FrameworkException ex) {
        ex.printStackTrace();
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DecimalFormat(java.text.DecimalFormat) GenericNode(org.structr.core.entity.GenericNode) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NodeHasLocation(org.structr.core.entity.relationship.NodeHasLocation) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Test (org.junit.Test)5 NodeHasLocation (org.structr.core.entity.relationship.NodeHasLocation)5 Tx (org.structr.core.graph.Tx)5 FrameworkException (org.structr.common.error.FrameworkException)4 GenericNode (org.structr.core.entity.GenericNode)3 NodeInterface (org.structr.core.graph.NodeInterface)2 PropertyKey (org.structr.core.property.PropertyKey)2 StringProperty (org.structr.core.property.StringProperty)2 IOException (java.io.IOException)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 RelationshipType (org.structr.api.graph.RelationshipType)1 GraphObject (org.structr.core.GraphObject)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 AbstractRelationship (org.structr.core.entity.AbstractRelationship)1 GenericRelationship (org.structr.core.entity.GenericRelationship)1 RelationshipInterface (org.structr.core.graph.RelationshipInterface)1 StructrUiTest (org.structr.web.StructrUiTest)1