Search in sources :

Example 11 with AttributeType

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);
}
Also used : AttributeType(ai.grakn.concept.AttributeType) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 12 with AttributeType

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();
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) ArrayList(java.util.ArrayList)

Example 13 with AttributeType

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);
}
Also used : AttributeType(ai.grakn.concept.AttributeType) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 14 with AttributeType

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();
}
Also used : AttributeType(ai.grakn.concept.AttributeType) Ignore(org.junit.Ignore) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 15 with AttributeType

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));
}
Also used : EntityType(ai.grakn.concept.EntityType) EdgeElement(ai.grakn.kb.internal.structure.EdgeElement) AttributeType(ai.grakn.concept.AttributeType) Label(ai.grakn.concept.Label) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Aggregations

AttributeType (ai.grakn.concept.AttributeType)27 Test (org.junit.Test)13 EntityType (ai.grakn.concept.EntityType)7 Label (ai.grakn.concept.Label)7 RelationshipType (ai.grakn.concept.RelationshipType)7 GraknTx (ai.grakn.GraknTx)6 Role (ai.grakn.concept.Role)6 Attribute (ai.grakn.concept.Attribute)5 Property (com.pholser.junit.quickcheck.Property)5 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)4 GraknSession (ai.grakn.GraknSession)3 SchemaConcept (ai.grakn.concept.SchemaConcept)3 GraknTxType (ai.grakn.GraknTxType)2 Keyspace (ai.grakn.Keyspace)2 Concept (ai.grakn.concept.Concept)2 ConceptId (ai.grakn.concept.ConceptId)2 Entity (ai.grakn.concept.Entity)2 EmbeddedGraknSession (ai.grakn.factory.EmbeddedGraknSession)2 EngineContext (ai.grakn.test.rule.EngineContext)2 Collection (java.util.Collection)2