Search in sources :

Example 1 with EntityAlreadyExistsException

use of org.apache.rya.indexing.entity.storage.EntityStorage.EntityAlreadyExistsException in project incubator-rya by apache.

the class MongoEntityStorageIT method can_not_create_with_same_subject.

@Test
public void can_not_create_with_same_subject() throws Exception {
    // A Type that will be stored.
    final Entity entity = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/00012345600012")).setExplicitType(new RyaURI("urn:icecream")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Chocolate"))).build();
    // Create it.
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    storage.create(entity);
    // Try to create it again. This will fail.
    boolean failed = false;
    try {
        storage.create(entity);
    } catch (final EntityAlreadyExistsException e) {
        failed = true;
    }
    assertTrue(failed);
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaURI(org.apache.rya.api.domain.RyaURI) EntityAlreadyExistsException(org.apache.rya.indexing.entity.storage.EntityStorage.EntityAlreadyExistsException) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Aggregations

RyaType (org.apache.rya.api.domain.RyaType)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 Entity (org.apache.rya.indexing.entity.model.Entity)1 Property (org.apache.rya.indexing.entity.model.Property)1 TypedEntity (org.apache.rya.indexing.entity.model.TypedEntity)1 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)1 EntityAlreadyExistsException (org.apache.rya.indexing.entity.storage.EntityStorage.EntityAlreadyExistsException)1 Test (org.junit.Test)1