use of com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DATETIME in project grakn by graknlabs.
the class BasicTest method write_attributes_successfully.
@Test
public void write_attributes_successfully() throws IOException {
LocalDateTime date_1991_1_1_0_0 = LocalDateTime.of(1991, 1, 1, 0, 0);
reset_directory_and_create_attribute_types();
try (TypeDB.DatabaseManager typedb = CoreDatabaseManager.open(options)) {
try (TypeDB.Session session = typedb.session(database, Arguments.Session.Type.DATA)) {
try (TypeDB.Transaction txn = session.transaction(Arguments.Transaction.Type.WRITE)) {
isAlive(txn).put(true);
age(txn).put(18);
score(txn).put(90.5);
name(txn).put("alice");
dob(txn).put(date_1991_1_1_0_0);
assertEquals(1, isAlive(txn).getInstances().count());
assertTrue(isAlive(txn).getInstances().anyMatch(att -> att.getValue().equals(true)));
assertEquals(1, age(txn).getInstances().count());
assertTrue(age(txn).getInstances().anyMatch(att -> att.getValue() == 18));
assertEquals(1, score(txn).getInstances().count());
assertTrue(score(txn).getInstances().anyMatch(att -> att.getValue() == 90.5));
assertEquals(1, name(txn).getInstances().count());
assertTrue(name(txn).getInstances().anyMatch(att -> att.getValue().equals("alice")));
assertEquals(1, dob(txn).getInstances().count());
assertTrue(dob(txn).getInstances().anyMatch(att -> att.getValue().equals(date_1991_1_1_0_0)));
txn.commit();
}
try (TypeDB.Transaction txn = session.transaction(Arguments.Transaction.Type.READ)) {
LocalDateTime dateTime = LocalDateTime.of(1991, 1, 1, 0, 0);
Attribute.Boolean isAlive = isAlive(txn).get(true);
Attribute.Long age = age(txn).get(18);
Attribute.Double score = score(txn).get(90.5);
Attribute.String name = name(txn).get("alice");
Attribute.DateTime dob = dob(txn).get(dateTime);
assertNotNulls(isAlive, age, score, name, dob);
assertEquals(true, isAlive.getValue());
assertEquals(18, age.getValue().longValue());
assertEquals(90.5, score.getValue(), 0.001);
assertEquals("alice", name.getValue());
assertEquals(dateTime, dob.getValue());
assertEquals(1, isAlive(txn).getInstances().count());
assertTrue(isAlive(txn).getInstances().anyMatch(att -> att.getValue().equals(true)));
assertEquals(1, age(txn).getInstances().count());
assertTrue(age(txn).getInstances().anyMatch(att -> att.getValue() == 18));
assertEquals(1, score(txn).getInstances().count());
assertTrue(score(txn).getInstances().anyMatch(att -> att.getValue() == 90.5));
assertEquals(1, name(txn).getInstances().count());
assertTrue(name(txn).getInstances().anyMatch(att -> att.getValue().equals("alice")));
assertEquals(1, dob(txn).getInstances().count());
assertTrue(dob(txn).getInstances().anyMatch(att -> att.getValue().equals(date_1991_1_1_0_0)));
}
}
}
}
Aggregations