use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.
the class EntitySerializerTest method testDeltaLoadChangedComponent.
@Test
public void testDeltaLoadChangedComponent() throws Exception {
EntityRef entity = entityManager.create("test:Test");
StringComponent comp = entity.getComponent(StringComponent.class);
comp.value = "Delta";
entity.saveComponent(comp);
EntityData.Entity entityData = entitySerializer.serialize(entity);
long nextId = entityManager.getNextId();
entityManager.clear();
entityManager.setNextId(nextId);
EntityRef loadedEntity = entitySerializer.deserialize(entityData);
assertTrue(loadedEntity.exists());
assertTrue(loadedEntity.hasComponent(StringComponent.class));
assertEquals("Delta", loadedEntity.getComponent(StringComponent.class).value);
}
use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.
the class EntitySerializerTest method setup.
@Before
public void setup() {
context.put(NetworkSystem.class, mock(NetworkSystem.class));
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
entityManager = context.get(EngineEntityManager.class);
entityManager.getComponentLibrary().register(new SimpleUri("test", "gettersetter"), GetterSetterComponent.class);
entityManager.getComponentLibrary().register(new SimpleUri("test", "string"), StringComponent.class);
entityManager.getComponentLibrary().register(new SimpleUri("test", "integer"), IntegerComponent.class);
entitySerializer = new EntitySerializer(entityManager);
componentLibrary = entityManager.getComponentLibrary();
PrefabData prefabData = new PrefabData();
prefabData.addComponent(new StringComponent("Value"));
prefab = Assets.generateAsset(new ResourceUrn("test:Test"), prefabData, Prefab.class);
}
use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.
the class StorageManagerTest method testGlobalEntitiesStoredAndRestored.
@Test
public void testGlobalEntitiesStoredAndRestored() throws Exception {
EntityRef entity = entityManager.create(new StringComponent("Test"));
long entityId = entity.getId();
esm.waitForCompletionOfPreviousSaveAndStartSaving();
esm.finishSavingAndShutdown();
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, false);
newSM.loadGlobalStore();
List<EntityRef> entities = Lists.newArrayList(newEntityManager.getEntitiesWith(StringComponent.class));
assertEquals(1, entities.size());
assertEquals(entityId, entities.get(0).getId());
}
use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.
the class ByteCodeReflectFactoryTest method testCreateFieldAccessorDirectToField.
@Test
public void testCreateFieldAccessorDirectToField() throws Exception {
ReflectFactory reflectFactory = new ByteCodeReflectFactory();
FieldAccessor<StringComponent, String> fieldAccessor = reflectFactory.createFieldAccessor(StringComponent.class, StringComponent.class.getDeclaredField("value"), String.class);
StringComponent comp = new StringComponent();
fieldAccessor.setValue(comp, "String");
assertEquals("String", fieldAccessor.getValue(comp));
}
use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method createPrefabWithString.
private Prefab createPrefabWithString(String urn, String text, AssetManager assetManager) {
PrefabData prefabData = new PrefabData();
prefabData.addComponent(new StringComponent(text));
return assetManager.loadAsset(new ResourceUrn(urn), prefabData, Prefab.class);
}
Aggregations