Search in sources :

Example 11 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testChangedComponentsRevertedBeforeCleanUp.

@Test
public void testChangedComponentsRevertedBeforeCleanUp() {
    worldStub.setBlock(Vector3i.zero(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    StringComponent comp = entity.getComponent(StringComponent.class);
    comp.value = "Moo";
    entity.saveComponent(comp);
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(OnChangedComponent.newInstance(), entity)), checker.receivedEvents);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) Vector3i(org.terasology.math.geom.Vector3i) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 12 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testEntityExtraComponentsRemovedBeforeCleanUp.

@Test
public void testEntityExtraComponentsRemovedBeforeCleanUp() {
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    entity.addComponent(new StringComponent("test"));
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) Vector3i(org.terasology.math.geom.Vector3i) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 13 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testIterateEntitiesDoesNotFindEntityMissingAComponent.

@Test
public void testIterateEntitiesDoesNotFindEntityMissingAComponent() {
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    List<EntityRef> results = Lists.newArrayList(entityManager.getEntitiesWith(StringComponent.class, IntegerComponent.class));
    assertEquals(Collections.<EntityRef>emptyList(), results);
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 14 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testChangeComponentEventSentWhenAddOverExisting.

@Test
public void testChangeComponentEventSentWhenAddOverExisting() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    StringComponent comp2 = entity1.addComponent(new StringComponent());
    verify(eventSystem).send(entity1, OnChangedComponent.newInstance(), comp2);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 15 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testChangeComponentEventSentWhenSave.

@Test
public void testChangeComponentEventSentWhenSave() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    StringComponent comp = entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    entity1.saveComponent(comp);
    verify(eventSystem).send(entity1, OnChangedComponent.newInstance(), comp);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

StringComponent (org.terasology.entitySystem.stubs.StringComponent)41 Test (org.junit.Test)38 EntityRef (org.terasology.entitySystem.entity.EntityRef)22 IntegerComponent (org.terasology.entitySystem.stubs.IntegerComponent)8 EntityData (org.terasology.protobuf.EntityData)8 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)5 ResourceUrn (org.terasology.assets.ResourceUrn)4 PrefabData (org.terasology.entitySystem.prefab.PrefabData)4 Prefab (org.terasology.entitySystem.prefab.Prefab)3 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)3 Before (org.junit.Before)2 SimpleUri (org.terasology.engine.SimpleUri)2 Component (org.terasology.entitySystem.Component)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 GetterSetterComponent (org.terasology.entitySystem.stubs.GetterSetterComponent)2 Vector3i (org.terasology.math.geom.Vector3i)2 NetworkSystem (org.terasology.network.NetworkSystem)2 Map (java.util.Map)1 EntityRefComponent (org.terasology.entitySystem.stubs.EntityRefComponent)1 StorageManager (org.terasology.persistence.StorageManager)1