Package org.structr.core.entity

Examples of org.structr.core.entity.TestOne


 
  public void testSimpleSearchOnRelationship() {
   
    try {

      final TestOne testOne        = createTestNode(TestOne.class);
      final TestFour testFour      = createTestNode(TestFour.class);
      final Property<Integer> key = OneFourOneToOne.integerProperty;
     
      assertNotNull(testOne);
      assertNotNull(testFour);
View Full Code Here


 
  public void testSimpleSearchOnRelationship() {
   
    try {

      final TestOne testOne        = createTestNode(TestOne.class);
      final TestFour testFour      = createTestNode(TestFour.class);
      final Property<Long> key = OneFourOneToOne.longProperty;
     
      assertNotNull(testOne);
      assertNotNull(testFour);
View Full Code Here

      List<TestUser> users = createTestNodes(TestUser.class, 1);
      TestUser user = (TestUser) users.get(0);

      // Create node with user context
      Class type = TestOne.class;
      TestOne t1 = createTestNode(TestOne.class, user);

      SecurityContext publicContext = SecurityContext.getInstance(null, AccessMode.Frontend);

      try (final Tx tx = app.tx()) {
View Full Code Here

      PropertyMap props = new PropertyMap();
      props.put(AbstractNode.visibleToPublicUsers, true);

      // Create two nodes with user context, one of them is visible to public users
      Class type = TestOne.class;
      TestOne t1 = createTestNode(TestOne.class, props, user);
      TestOne t2 = createTestNode(TestOne.class, user);

      SecurityContext publicContext = SecurityContext.getInstance(null, AccessMode.Frontend);

      try (final Tx tx = app.tx()) {
View Full Code Here

      PropertyMap props = new PropertyMap();
      props.put(AbstractNode.visibleToPublicUsers, true);

      // Create two nodes with user context, one of them is visible to public users
      Class type = TestOne.class;
      TestOne t1 = createTestNode(TestOne.class, props, user);

      props = new PropertyMap();
      props.put(AbstractNode.visibleToAuthenticatedUsers, true);

      TestOne t2 = createTestNode(TestOne.class, props, user);

      SecurityContext publicContext = SecurityContext.getInstance(null, AccessMode.Frontend);

      try (final Tx tx = app.tx()) {
        Result result = StructrApp.getInstance(publicContext).nodeQuery(type).getResult();
View Full Code Here

      PropertyMap props = new PropertyMap();
      props.put(AbstractNode.visibleToPublicUsers, true);

      // Create two nodes with user context, one of them is visible to public users
      Class type = TestOne.class;
      TestOne t1 = createTestNode(TestOne.class, props, user1);

      props = new PropertyMap();
      props.put(AbstractNode.visibleToAuthenticatedUsers, true);

      TestOne t2 = createTestNode(TestOne.class, props, user1);

      // Let another user search
      SecurityContext user2Context = SecurityContext.getInstance(user2, AccessMode.Backend);

      try (final Tx tx = app.tx()) {
View Full Code Here

      PropertyMap props = new PropertyMap();
      props.put(AbstractNode.visibleToPublicUsers, true);

      // Create two nodes with user context, one of them is visible to public users
      Class type = TestOne.class;
      TestOne t1 = createTestNode(TestOne.class, props, user1);

      props = new PropertyMap();
      props.put(AbstractNode.visibleToAuthenticatedUsers, true);

      TestOne t2 = createTestNode(TestOne.class, props, user1);

      // Let another user search
      SecurityContext user2Context = SecurityContext.getInstance(user2, AccessMode.Frontend);

      try (final Tx tx = app.tx()) {
View Full Code Here

      TestUser user2 = (TestUser) users.get(1);
      Result result = null;

      // Let user 1 create a node
      Class type = TestOne.class;
      final TestOne t1 = createTestNode(TestOne.class, user1);

      try (final Tx tx = app.tx()) {

        // Grant read permission to user 2
        user2.grant(Permission.read, t1);
        tx.success();
      }

      // Let user 2 search
      SecurityContext user2Context = SecurityContext.getInstance(user2, AccessMode.Backend);

      try (final Tx tx = app.tx()) {

        result = StructrApp.getInstance(user2Context).nodeQuery(type).getResult();

        assertEquals(1, result.size());
        assertEquals(t1.getUuid(), result.get(0).getUuid());
      }

      try (final Tx tx = app.tx()) {

        // Revoke permission again
View Full Code Here

 
  public void testSimpleSearchOnRelationship() {
   
    try {

      final TestOne testOne        = createTestNode(TestOne.class);
      final TestFour testFour      = createTestNode(TestFour.class);
      final Property<TestEnum> key = OneFourOneToOne.enumProperty;
     
      assertNotNull(testOne);
      assertNotNull(testFour);
View Full Code Here

      final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);

      // 1. create data and export
      try (final Tx tx = app.tx()) {

        final TestOne test1 = createTestNode(TestOne.class);
        final TestOne test2 = createTestNode(TestOne.class);
        final TestOne test3 = createTestNode(TestOne.class);
        final TestOne test4 = createTestNode(TestOne.class);

        test1.setProperty(TestOne.aString, string1);
        test1.setProperty(TestOne.anInt, 1);

        test2.setProperty(TestOne.aString, string2);
        test2.setProperty(TestOne.anInt, 2);

        test3.setProperty(TestOne.aString, string3);
        test3.setProperty(TestOne.anInt, 3);

        test4.setProperty(TestOne.aString, string4);
        test4.setProperty(TestOne.anInt, 4);

        SyncCommand.exportToStream(
          outputStream,
          app.nodeQuery(TestOne.class).getAsList(),
          app.relationshipQuery(RelationshipInterface.class).getAsList(),
          null,
          false
        );

        tx.success();
      }


      // 2. clear database
      try (final Tx tx = app.tx()) {

        for (final TestOne test : app.nodeQuery(TestOne.class).getAsList()) {

          app.delete(test);
        }

        tx.success();
      }

      // 3. verify that database is empty
      try (final Tx tx = app.tx()) {

        assertEquals("Database should contain not TestOne entities.", 0, app.nodeQuery(TestOne.class).getResult().size());
        tx.success();
      }


      // 4. import data again
      try (final Tx tx = app.tx()) {

        SyncCommand.importFromStream(
          app.getGraphDatabaseService(),
          securityContext,
          new ByteArrayInputStream(outputStream.toByteArray()),
          true
        );

        tx.success();

      }

      // 5. check result
      try (final Tx tx = app.tx()) {

        final TestOne test1 = app.nodeQuery(TestOne.class).and(TestOne.anInt, 1).getFirst();
        final TestOne test2 = app.nodeQuery(TestOne.class).and(TestOne.anInt, 2).getFirst();
        final TestOne test3 = app.nodeQuery(TestOne.class).and(TestOne.anInt, 3).getFirst();
        final TestOne test4 = app.nodeQuery(TestOne.class).and(TestOne.anInt, 4).getFirst();

        assertEquals("Strings from exported and re-imported data should be equal", string1, test1.getProperty(TestOne.aString));
        assertEquals("Strings from exported and re-imported data should be equal", string2, test2.getProperty(TestOne.aString));
        assertEquals("Strings from exported and re-imported data should be equal", string3, test3.getProperty(TestOne.aString));
        assertEquals("Strings from exported and re-imported data should be equal", string4, test4.getProperty(TestOne.aString));

        tx.success();
      }

View Full Code Here

TOP

Related Classes of org.structr.core.entity.TestOne

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.