Search in sources :

Example 46 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class EntityTypeTest method whenAddingResourceTypeAsResourceAfterResource_Throw.

@Test
public void whenAddingResourceTypeAsResourceAfterResource_Throw() {
    AttributeType<String> attributeType = tx.putAttributeType("Shared Attribute", AttributeType.DataType.STRING);
    EntityType entityType = tx.putEntityType("EntityType");
    entityType.key(attributeType);
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(CANNOT_BE_KEY_AND_RESOURCE.getMessage(entityType.getLabel(), attributeType.getLabel()));
    entityType.attribute(attributeType);
}
Also used : EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Example 47 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class EntityTypeTest method whenRemovingRoleFromEntityType_TheRoleCanNoLongerBePlayed.

@Test
public void whenRemovingRoleFromEntityType_TheRoleCanNoLongerBePlayed() {
    Role role1 = tx.putRole("A Role 1");
    Role role2 = tx.putRole("A Role 2");
    EntityType type = tx.putEntityType("A Concept Type").plays(role1).plays(role2);
    assertThat(type.plays().collect(toSet()), containsInAnyOrder(role1, role2));
    type.deletePlays(role1);
    assertThat(type.plays().collect(toSet()), containsInAnyOrder(role2));
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Example 48 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class EntityTypeTest method whenGettingTheInstancesOfType_ReturnAllInstances.

@Test
public void whenGettingTheInstancesOfType_ReturnAllInstances() {
    EntityType e1 = tx.putEntityType("e1");
    EntityType e2 = tx.putEntityType("e2").sup(e1);
    EntityType e3 = tx.putEntityType("e3").sup(e1);
    Entity e2_child1 = e2.addEntity();
    Entity e2_child2 = e2.addEntity();
    Entity e3_child1 = e3.addEntity();
    Entity e3_child2 = e3.addEntity();
    Entity e3_child3 = e3.addEntity();
    assertThat(e1.instances().collect(toSet()), containsInAnyOrder(e2_child1, e2_child2, e3_child1, e3_child2, e3_child3));
    assertThat(e2.instances().collect(toSet()), containsInAnyOrder(e2_child1, e2_child2));
    assertThat(e3.instances().collect(toSet()), containsInAnyOrder(e3_child1, e3_child2, e3_child3));
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Test(org.junit.Test)

Example 49 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class RemoteConceptsTest method whenSettingSuper_ExecuteAConceptMethod.

@Test
public void whenSettingSuper_ExecuteAConceptMethod() {
    EntityType sup = RemoteConcepts.createEntityType(tx, A);
    assertEquals(entityType, entityType.sup(sup));
    verifyConceptMethodCalled(ConceptMethods.setDirectSuperConcept(sup));
}
Also used : EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Example 50 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class GraknTxJanusTest method whenCreatingIndependentMutatingTransactionsConcurrently_TheGraphIsUpdatedSafely.

@Test
public void whenCreatingIndependentMutatingTransactionsConcurrently_TheGraphIsUpdatedSafely() throws ExecutionException, InterruptedException {
    Set<Future> futures = new HashSet<>();
    ExecutorService pool = Executors.newFixedThreadPool(40);
    EntityType type = graknTx.putEntityType("A Type");
    graknTx.commit();
    for (int i = 0; i < 100; i++) {
        futures.add(pool.submit(() -> addEntity(type)));
    }
    for (Future future : futures) {
        future.get();
    }
    graknTx = janusGraphFactory.open(GraknTxType.WRITE);
    assertEquals(100L, graknTx.admin().getMetaEntityType().instances().count());
}
Also used : EntityType(ai.grakn.concept.EntityType) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

EntityType (ai.grakn.concept.EntityType)168 Test (org.junit.Test)141 Role (ai.grakn.concept.Role)83 RelationshipType (ai.grakn.concept.RelationshipType)82 Entity (ai.grakn.concept.Entity)74 GraknTx (ai.grakn.GraknTx)45 Relationship (ai.grakn.concept.Relationship)21 Attribute (ai.grakn.concept.Attribute)19 AttributeType (ai.grakn.concept.AttributeType)17 ConceptId (ai.grakn.concept.ConceptId)17 Label (ai.grakn.concept.Label)17 Set (java.util.Set)16 HashSet (java.util.HashSet)15 Thing (ai.grakn.concept.Thing)14 GraknTxType (ai.grakn.GraknTxType)8 ArrayList (java.util.ArrayList)8 GraknSession (ai.grakn.GraknSession)7 Concept (ai.grakn.concept.Concept)7 HashMap (java.util.HashMap)7 Before (org.junit.Before)7