public Entity fromMap( Map<String, Object> map, boolean topLevel ) { Entity entity = new Entity(); return fromMap( entity, map, null, null, topLevel ); }
public static Entity fromMap( Entity entity, Map<String, Object> map, String entityType, boolean topLevel ) { if ( entity == null ) { entity = new Entity(); } SchemaManager schemaManager = Schema.getDefaultSchema(); return mapConverter.fromMap(entity,map, schemaManager, entityType,topLevel); }
@Test( expected = NullPointerException.class ) public void idRequired() { new Entity( (Id)null); }
@Test( expected = NullPointerException.class ) public void typeRequired() { new Entity( (String)null); }
private Entity invalidVersion(){ Entity entity = new Entity("test"); EntityUtils.setVersion( entity, UUID.randomUUID() ); return entity; } }
/** * Generate a valid entity * * @return */ public static Entity generateEntity(final Id id, final UUID version) { final Entity entity = new Entity(id); EntityUtils.setVersion(entity, version); return entity; }
@Test(expected = NullPointerException.class) public void entityIdRequired() { new MvccEntityImpl( null, UUIDGenerator.newTimeUUID(), MvccEntity.Status.COMPLETE,Optional.of( new Entity() ) ); }
@Test(expected = NullPointerException.class) public void versionRequired() { new MvccEntityImpl( new SimpleId( "test" ), null, MvccEntity.Status.COMPLETE, Optional.of( new Entity() ) ); }
private MvccEntity getEntity( final String type ) { final SimpleId entityId = new SimpleId( type ); final UUID version = UUIDGenerator.newTimeUUID(); final Entity entity = new Entity( entityId ); MvccEntityImpl logEntry = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, entity ); return logEntry; }
/** * Generate a valid entity * * @return */ public static Entity generateEntity() { final Entity entity = new Entity(generateId()); final UUID version = UUIDGenerator.newTimeUUID(); EntityUtils.setVersion(entity, version); return entity; }
@Test public void equals() { final SimpleId entityId = new SimpleId( "test" ); final UUID version = UUIDGenerator.newTimeUUID(); final Entity entity = new Entity( entityId ); MvccEntityImpl first = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, Optional.of( entity ) ); MvccEntityImpl second = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, Optional.of( entity ) ); assertEquals( first, second ); }
@Test public void testNullSerialization() throws IOException { Map<String, Object> properties = new HashMap<>(); List<Object> array = new ArrayList<>(); array.add(null); array.add("test"); properties.put("array", array); org.apache.usergrid.persistence.model.entity.Entity entity = new org.apache.usergrid.persistence.model.entity.Entity( new SimpleId( "user" ) ); entity = CpEntityMapUtils.fromMap( entity, properties, null, true ); assertTrue( entity.getField("array") instanceof ListField ); assertTrue( entity.getField("array").getValue() instanceof List ); List arrayReturned = (List) entity.getField("array").getValue(); assertEquals( null, arrayReturned.get(0) ); assertEquals( "test", arrayReturned.get(1) ); }
/** * Convert a usergrid 1.0 entity into a usergrid 2.0 entity */ public static org.apache.usergrid.persistence.model.entity.Entity entityToCpEntity( org.apache.usergrid.persistence.Entity entity, UUID importId ) { UUID uuid = importId != null ? importId : entity.getUuid(); org.apache.usergrid.persistence.model.entity.Entity cpEntity = new org.apache.usergrid.persistence.model.entity.Entity( new SimpleId( uuid, entity.getType() ) ); cpEntity = CpEntityMapUtils.fromMap( cpEntity, entity.getProperties(), entity.getType(), true ); cpEntity = CpEntityMapUtils.fromMap( cpEntity, entity.getDynamicProperties(), entity.getType(), true ); return cpEntity; }
@Test public void testHashCode() { final SimpleId entityId = new SimpleId( "test" ); final UUID version = UUIDGenerator.newTimeUUID(); final Entity entity = new Entity( entityId ); MvccEntityImpl first = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE,Optional.of( entity ) ); MvccEntityImpl second = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, Optional.of( entity ) ); assertEquals( first.hashCode(), second.hashCode() ); } }
@Test public void correctValueOptional() { final SimpleId entityId = new SimpleId( "test" ); final UUID version = UUIDGenerator.newTimeUUID(); final Entity entity = new Entity( entityId ); MvccEntityImpl logEntry = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE,Optional.of( entity ) ); assertEquals( entityId, logEntry.getId() ); assertEquals( version, logEntry.getVersion() ); assertEquals( entity, logEntry.getEntity().get() ); }
@Test public void testSingleIndexFromSource() { final Entity entity = new Entity( createId( "test" ), UUIDGenerator.newTimeUUID() ); entity.setField( new StringField( "string", "foo" ) ); final Edge collectionEdge = createCollectionEdge( applicationScope.getApplication(), "tests", entity.getId() ); //write the edge graphManager.writeEdge( collectionEdge ).toBlocking().last(); //index the edge final Observable<IndexOperationMessage> indexed = indexService.indexEntity( applicationScope, entity ); //real users should never call to blocking, we're not sure what we'll get final IndexOperationMessage results = indexed.toBlocking().last(); indexProducer.put(results).subscribe(); final Set<IndexOperation> indexRequests = results.getIndexRequests(); //ensure our value made it to the index request final IndexOperation indexRequest = indexRequests.iterator().next(); assertNotNull( indexRequest ); }
@Test public void correctValueEntity() { final SimpleId entityId = new SimpleId( "test" ); final UUID version = UUIDGenerator.newTimeUUID(); final Entity entity = new Entity( entityId ); MvccEntityImpl logEntry = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE, entity ); assertEquals( entityId, logEntry.getId() ); assertEquals( version, logEntry.getVersion() ); assertEquals( entity, logEntry.getEntity().get() ); }
@Test public void write() { ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) ); Entity newEntity = new Entity( new SimpleId( "test" ) ); EntityCollectionManager manager = factory.createCollectionManager( context ); Observable<Entity> observable = manager.write( newEntity, null ); Entity returned = observable.toBlocking().lastOrDefault( null ); assertNotNull( "Returned has a uuid", returned.getId() ); assertNotNull( "Version exists", returned.getVersion() ); }
@Test public void writeAndLoad() { ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) ); Entity newEntity = new Entity( new SimpleId( "test" ) ); EntityCollectionManager manager = factory.createCollectionManager( context ); Observable<Entity> observable = manager.write( newEntity, null ); Entity createReturned = observable.toBlocking().lastOrDefault( null ); assertNotNull( "Id was assigned", createReturned.getId() ); assertNotNull( "Version was assigned", createReturned.getVersion() ); Observable<Entity> loadObservable = manager.load( createReturned.getId() ); Entity loadReturned = loadObservable.toBlocking().lastOrDefault( null ); assertEquals( "Same value", createReturned, loadReturned ); }
@Test public void writeLoadDelete() { ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) ); Entity newEntity = new Entity( new SimpleId( "test" ) ); EntityCollectionManager manager = factory.createCollectionManager( context ); Observable<Entity> observable = manager.write( newEntity, null ); Entity createReturned = observable.toBlocking().lastOrDefault( null ); assertNotNull( "Id was assigned", createReturned.getId() ); Observable<Entity> loadObservable = manager.load( createReturned.getId() ); Entity loadReturned = loadObservable.toBlocking().lastOrDefault( null ); assertEquals( "Same value", createReturned, loadReturned ); manager.mark( createReturned.getId(), null ).toBlocking().last(); loadObservable = manager.load( createReturned.getId() ); //load may return null, use last or default loadReturned = loadObservable.toBlocking().lastOrDefault( null ); assertNull( "Entity was deleted", loadReturned ); }