use of org.structr.core.entity.TestOne in project structr by structr.
the class PropertyTest method testSimpleBooleanPropertySearchOnRelationship.
@Test
public void testSimpleBooleanPropertySearchOnRelationship() {
try {
final TestOne testOne = createTestNode(TestOne.class);
final TestFour testFour = createTestNode(TestFour.class);
final Property<Boolean> key = OneFourOneToOne.booleanProperty;
assertNotNull(testOne);
assertNotNull(testFour);
final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class);
assertNotNull(testEntity);
try (final Tx tx = app.tx()) {
testEntity.setProperty(key, true);
tx.success();
}
try (final Tx tx = app.tx()) {
// check value from database
assertEquals((Boolean) true, (Boolean) testEntity.getProperty(key));
Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, true).getResult();
assertEquals(1, result.size());
assertEquals(testEntity, result.get(0));
}
} catch (FrameworkException fex) {
fail("Unable to store array");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class PropertyTest method testSimpleDoublePropertySearchOnRelationship.
@Test
public void testSimpleDoublePropertySearchOnRelationship() {
try {
final TestOne testOne = createTestNode(TestOne.class);
final TestFour testFour = createTestNode(TestFour.class);
final Property<Double> key = OneFourOneToOne.doubleProperty;
assertNotNull(testOne);
assertNotNull(testFour);
final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class);
assertNotNull(testEntity);
try (final Tx tx = app.tx()) {
testEntity.setProperty(key, 3.141592653589793238);
tx.success();
}
try (final Tx tx = app.tx()) {
// check value from database
assertEquals(3.141592653589793238, testEntity.getProperty(key), 0.0);
Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, 3.141592653589793238).getResult();
assertEquals(1, result.size());
assertEquals(testEntity, result.get(0));
}
} catch (FrameworkException fex) {
fail("Unable to store array");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class PropertyTest method testOneToManyOnCollectionProperty.
// ----- collection property tests -----
@Test
public void testOneToManyOnCollectionProperty() throws Exception {
TestOne testOne = null;
List<TestSix> testSixs = null;
List<TestSix> testSixs2 = null;
int index = 0;
List<Integer> index1 = new LinkedList();
List<Integer> index2 = new LinkedList();
try (final Tx tx = app.tx()) {
testOne = createTestNode(TestOne.class);
testSixs = createTestNodes(TestSix.class, 20);
for (final TestSix testSix : testSixs) {
int i = index++;
testSix.setProperty(TestSix.index, i);
System.out.println(i + " ");
index1.add(i);
}
testOne.setProperty(TestOne.manyToManyTestSixs, testSixs);
tx.success();
}
try (final Tx tx = app.tx()) {
testSixs2 = testOne.getProperty(TestOne.manyToManyTestSixs);
for (final TestSix testSix : testSixs2) {
int i = testSix.getProperty(TestSix.index);
System.out.println(i + " ");
index2.add(i);
}
assertEquals(index1, index2);
tx.success();
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class PropertyTest method testManyToManyOnCollectionProperty.
@Test
public void testManyToManyOnCollectionProperty() throws Exception {
try {
Property<List<TestOne>> instance = TestSix.manyToManyTestOnes;
TestSix testSix1 = null;
TestSix testSix2 = null;
TestOne testOne1 = null;
TestOne testOne2 = null;
testSix1 = createTestNode(TestSix.class);
testSix2 = createTestNode(TestSix.class);
testOne1 = createTestNode(TestOne.class);
testOne2 = createTestNode(TestOne.class);
assertNotNull(testSix1);
assertNotNull(testSix2);
assertNotNull(testOne1);
assertNotNull(testOne2);
// set two TestOne entities on both TestSix entities
List<TestOne> twoTestOnesList = new LinkedList<>();
twoTestOnesList.add(testOne1);
twoTestOnesList.add(testOne2);
try (final Tx tx = app.tx()) {
instance.setProperty(securityContext, testSix1, twoTestOnesList);
instance.setProperty(securityContext, testSix2, twoTestOnesList);
tx.success();
}
try (final Tx tx = app.tx()) {
List<TestOne> testOnesFromTestSix1 = instance.getProperty(securityContext, testSix1, true);
List<TestOne> testOnesFromTestSix2 = instance.getProperty(securityContext, testSix2, true);
assertNotNull(testOnesFromTestSix1);
assertNotNull(testOnesFromTestSix2);
// both entities should have the two related nodes
assertEquals(2, testOnesFromTestSix1.size());
assertEquals(2, testOnesFromTestSix2.size());
}
// create new list with one TestOne entity
List<TestOne> oneTestOneList = new LinkedList<>();
oneTestOneList.add(testOne1);
try (final Tx tx = app.tx()) {
// set list with one TestOne node as related nodes
instance.setProperty(securityContext, testSix1, oneTestOneList);
tx.success();
}
try (final Tx tx = app.tx()) {
List<TestOne> oneTestOnesFromTestSix1 = instance.getProperty(securityContext, testSix1, true);
// entity should have exactly one related node
assertNotNull(oneTestOnesFromTestSix1);
assertEquals(1, oneTestOnesFromTestSix1.size());
assertEquals(oneTestOnesFromTestSix1.get(0).getUuid(), testOne1.getUuid());
}
} catch (FrameworkException fex) {
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class PropertyTest method testSimpleEnumPropertySearchOnRelationship.
@Test
public void testSimpleEnumPropertySearchOnRelationship() {
try {
final TestOne testOne = createTestNode(TestOne.class);
final TestFour testFour = createTestNode(TestFour.class);
final Property<TestEnum> key = OneFourOneToOne.enumProperty;
assertNotNull(testOne);
assertNotNull(testFour);
final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class);
assertNotNull(testEntity);
try (final Tx tx = app.tx()) {
testEntity.setProperty(key, TestEnum.Status1);
tx.success();
}
try (final Tx tx = app.tx()) {
// check value from database
assertEquals(TestEnum.Status1, testEntity.getProperty(key));
Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, TestEnum.Status1).getResult();
assertEquals(1, result.size());
assertEquals(testEntity, result.get(0));
}
} catch (FrameworkException fex) {
fail("Unable to store array");
}
}
Aggregations