use of org.terasology.unittest.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.unittest.stubs.StringComponent in project Terasology by MovingBlocks.
the class EntitySerializerTest method setup.
@BeforeEach
public void setup() {
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
context.put(NetworkSystem.class, networkSystem);
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
entityManager = context.get(EngineEntityManager.class);
entityManager.getComponentLibrary().register(new ResourceUrn("test", "gettersetter"), GetterSetterComponent.class);
entityManager.getComponentLibrary().register(new ResourceUrn("test", "string"), StringComponent.class);
entityManager.getComponentLibrary().register(new ResourceUrn("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.unittest.stubs.StringComponent in project Terasology by MovingBlocks.
the class ComponentSerializerTest method testComponentTypeIdUsedWhenLookupTableEnabled.
@Test
public void testComponentTypeIdUsedWhenLookupTableEnabled() throws Exception {
componentSerializer.setIdMapping(ImmutableMap.<Class<? extends Component>, Integer>builder().put(StringComponent.class, 1).build());
Component stringComponent = new StringComponent("Test");
EntityData.Component compData = componentSerializer.serialize(stringComponent);
assertEquals(1, compData.getTypeIndex());
assertFalse(compData.hasType());
}
use of org.terasology.unittest.stubs.StringComponent in project Terasology by MovingBlocks.
the class ComponentSerializerTest method testComponentTypeIdDeserializes.
@Test
public void testComponentTypeIdDeserializes() throws Exception {
componentSerializer.setIdMapping(ImmutableMap.<Class<? extends Component>, Integer>builder().put(StringComponent.class, 1).build());
EntityData.Component compData = EntityData.Component.newBuilder().setTypeIndex(1).addField(EntityData.NameValue.newBuilder().setName("value").setValue(EntityData.Value.newBuilder().addString("item"))).build();
Component comp = componentSerializer.deserialize(compData);
assertTrue(comp instanceof StringComponent);
assertEquals("item", ((StringComponent) comp).value);
}
use of org.terasology.unittest.stubs.StringComponent in project Terasology by MovingBlocks.
the class ComponentSerializerTest method testComponentTypeIdUsedWhenLookupTableEnabledForComponentDeltas.
@Test
public void testComponentTypeIdUsedWhenLookupTableEnabledForComponentDeltas() throws Exception {
componentSerializer.setIdMapping(ImmutableMap.<Class<? extends Component>, Integer>builder().put(StringComponent.class, 413).build());
EntityData.Component componentData = componentSerializer.serialize(new StringComponent("Original"), new StringComponent("Value"));
assertEquals(413, componentData.getTypeIndex());
}
Aggregations