Search in sources :

Example 1 with StringComponent

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);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 2 with StringComponent

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);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) StringComponent(org.terasology.unittest.stubs.StringComponent) NetworkSystem(org.terasology.engine.network.NetworkSystem) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) EntitySerializer(org.terasology.engine.persistence.serializers.EntitySerializer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with StringComponent

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());
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) Component(org.terasology.gestalt.entitysystem.component.Component) GetterSetterComponent(org.terasology.unittest.stubs.GetterSetterComponent) IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) StringComponent(org.terasology.unittest.stubs.StringComponent) Test(org.junit.jupiter.api.Test)

Example 4 with StringComponent

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);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) Component(org.terasology.gestalt.entitysystem.component.Component) GetterSetterComponent(org.terasology.unittest.stubs.GetterSetterComponent) IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) StringComponent(org.terasology.unittest.stubs.StringComponent) Test(org.junit.jupiter.api.Test)

Example 5 with StringComponent

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());
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) Test(org.junit.jupiter.api.Test)

Aggregations

StringComponent (org.terasology.unittest.stubs.StringComponent)41 Test (org.junit.jupiter.api.Test)38 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)22 EntityData (org.terasology.protobuf.EntityData)8 IntegerComponent (org.terasology.unittest.stubs.IntegerComponent)8 EventSystem (org.terasology.engine.entitySystem.event.internal.EventSystem)5 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)5 PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)4 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)3 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)3 Vector3i (org.joml.Vector3i)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 NetworkSystem (org.terasology.engine.network.NetworkSystem)2 Component (org.terasology.gestalt.entitysystem.component.Component)2 GetterSetterComponent (org.terasology.unittest.stubs.GetterSetterComponent)2 Map (java.util.Map)1 Reflections (org.reflections.Reflections)1 StorageManager (org.terasology.engine.persistence.StorageManager)1 EntitySerializer (org.terasology.engine.persistence.serializers.EntitySerializer)1