use of ai.grakn.concept.AttributeType in project grakn by graknlabs.
the class GraknTxPropertyTest method whenSetRegexOnMetaResourceType_Throw.
// TODO: Everything below this point should be moved to more appropriate test classes
@Property
public void whenSetRegexOnMetaResourceType_Throw(@Open GraknTx graph, String regex) {
AttributeType resource = graph.admin().getMetaAttributeType();
exception.expect(GraknTxOperationException.class);
exception.expectMessage(GraknTxOperationException.cannotSetRegex(resource).getMessage());
resource.setRegex(regex);
}
use of ai.grakn.concept.AttributeType in project grakn by graknlabs.
the class ConnectedComponentTest method addSchemaAndEntities.
private void addSchemaAndEntities() throws InvalidKBException {
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
EntityType entityType1 = graph.putEntityType(thing);
EntityType entityType2 = graph.putEntityType(anotherThing);
Entity entity1 = entityType1.addEntity();
Entity entity2 = entityType1.addEntity();
Entity entity3 = entityType1.addEntity();
Entity entity4 = entityType2.addEntity();
entityId1 = entity1.getId();
entityId2 = entity2.getId();
entityId3 = entity3.getId();
entityId4 = entity4.getId();
Role role1 = graph.putRole("role1");
Role role2 = graph.putRole("role2");
entityType1.plays(role1).plays(role2);
entityType2.plays(role1).plays(role2);
RelationshipType relationshipType = graph.putRelationshipType(related).relates(role1).relates(role2);
relationshipType.addRelationship().addRolePlayer(role1, entity1).addRolePlayer(role2, entity2).getId();
relationshipType.addRelationship().addRolePlayer(role1, entity2).addRolePlayer(role2, entity3).getId();
relationshipType.addRelationship().addRolePlayer(role1, entity2).addRolePlayer(role2, entity4).getId();
List<AttributeType> attributeTypeList = new ArrayList<>();
attributeTypeList.add(graph.putAttributeType(resourceType1, AttributeType.DataType.DOUBLE));
attributeTypeList.add(graph.putAttributeType(resourceType2, AttributeType.DataType.LONG));
attributeTypeList.add(graph.putAttributeType(resourceType3, AttributeType.DataType.LONG));
attributeTypeList.add(graph.putAttributeType(resourceType4, AttributeType.DataType.STRING));
attributeTypeList.add(graph.putAttributeType(resourceType5, AttributeType.DataType.LONG));
attributeTypeList.add(graph.putAttributeType(resourceType6, AttributeType.DataType.DOUBLE));
attributeTypeList.add(graph.putAttributeType(resourceType7, AttributeType.DataType.DOUBLE));
attributeTypeList.forEach(attributeType -> {
entityType1.attribute(attributeType);
entityType2.attribute(attributeType);
});
graph.commit();
}
}
use of ai.grakn.concept.AttributeType in project grakn by graknlabs.
the class GraknTxPropertyTest method whenCreateInstanceOfMetaResourceType_Throw.
@Property
public void whenCreateInstanceOfMetaResourceType_Throw(@Open GraknTx graph, @From(ResourceValues.class) Object value) {
AttributeType resource = graph.admin().getMetaAttributeType();
exception.expect(GraknTxOperationException.class);
exception.expectMessage(GraknTxOperationException.metaTypeImmutable(resource.getLabel()).getMessage());
resource.putAttribute(value);
}
use of ai.grakn.concept.AttributeType in project grakn by graknlabs.
the class GraknTxPropertyTest method whenCallingSuperTypeOnMetaResourceType_Throw.
// TODO: Fix this
@Ignore
@Property
public void whenCallingSuperTypeOnMetaResourceType_Throw(@Open GraknTx graph) {
AttributeType resource = graph.admin().getMetaAttributeType();
// TODO: Test for a better error message
exception.expect(GraknTxOperationException.class);
// noinspection ResultOfMethodCallIgnored
resource.sup();
}
use of ai.grakn.concept.AttributeType in project grakn by graknlabs.
the class SchemaConceptTest method whenSpecifyingTheResourceTypeOfAnEntityType_EnsureTheImplicitStructureIsCreated.
@Test
public void whenSpecifyingTheResourceTypeOfAnEntityType_EnsureTheImplicitStructureIsCreated() {
Label resourceLabel = Label.of("Attribute Type");
EntityType entityType = tx.putEntityType("Entity1");
AttributeType attributeType = tx.putAttributeType("Attribute Type", AttributeType.DataType.STRING);
// Implicit Names
Label hasResourceOwnerLabel = Schema.ImplicitType.HAS_OWNER.getLabel(resourceLabel);
Label hasResourceValueLabel = Schema.ImplicitType.HAS_VALUE.getLabel(resourceLabel);
Label hasResourceLabel = Schema.ImplicitType.HAS.getLabel(resourceLabel);
entityType.attribute(attributeType);
RelationshipType relationshipType = tx.getRelationshipType(hasResourceLabel.getValue());
Assert.assertEquals(hasResourceLabel, relationshipType.getLabel());
Set<Label> roleLabels = relationshipType.relates().map(SchemaConcept::getLabel).collect(toSet());
assertThat(roleLabels, containsInAnyOrder(hasResourceOwnerLabel, hasResourceValueLabel));
assertThat(entityType.plays().collect(toSet()), containsInAnyOrder(tx.getRole(hasResourceOwnerLabel.getValue())));
assertThat(attributeType.plays().collect(toSet()), containsInAnyOrder(tx.getRole(hasResourceValueLabel.getValue())));
// Check everything is implicit
assertTrue(relationshipType.isImplicit());
relationshipType.relates().forEach(role -> assertTrue(role.isImplicit()));
// Check that resource is not required
EdgeElement entityPlays = ((EntityTypeImpl) entityType).vertex().getEdgesOfType(Direction.OUT, Schema.EdgeLabel.PLAYS).iterator().next();
assertFalse(entityPlays.propertyBoolean(Schema.EdgeProperty.REQUIRED));
EdgeElement resourcePlays = ((AttributeTypeImpl<?>) attributeType).vertex().getEdgesOfType(Direction.OUT, Schema.EdgeLabel.PLAYS).iterator().next();
assertFalse(resourcePlays.propertyBoolean(Schema.EdgeProperty.REQUIRED));
}
Aggregations