Search in sources :

Example 1 with EntityRefComponent

use of org.terasology.unittest.stubs.EntityRefComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testDestroyingEntityInvalidatesEntityRefs.

@Test
public void testDestroyingEntityInvalidatesEntityRefs() {
    EntityRef main = entityManager.create();
    main.addComponent(new StringComponent());
    EntityRef reference = entityManager.create();
    EntityRefComponent refComp = reference.addComponent(new EntityRefComponent());
    refComp.entityRef = entityManager.getEntitiesWith(StringComponent.class).iterator().next();
    assertTrue(main.exists());
    entityManager.getEntitiesWith(StringComponent.class).iterator().next().destroy();
    assertFalse(main.exists());
    assertFalse(refComp.entityRef.exists());
}
Also used : EntityRefComponent(org.terasology.unittest.stubs.EntityRefComponent) StringComponent(org.terasology.unittest.stubs.StringComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 2 with EntityRefComponent

use of org.terasology.unittest.stubs.EntityRefComponent in project Terasology by MovingBlocks.

the class StorageManagerTest method testReferenceRemainsValidOverStorageRestoral.

@Test
public void testReferenceRemainsValidOverStorageRestoral() throws Exception {
    EntityRef someEntity = entityManager.create();
    character.addComponent(new EntityRefComponent(someEntity));
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    PlayerStore restored = newSM.loadPlayerStore(PLAYER_ID);
    restored.restoreEntities();
    assertTrue(restored.getCharacter().getComponent(EntityRefComponent.class).entityRef.exists());
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) EntityRefComponent(org.terasology.unittest.stubs.EntityRefComponent) PlayerStore(org.terasology.engine.persistence.PlayerStore) StorageManager(org.terasology.engine.persistence.StorageManager) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 EntityRefComponent (org.terasology.unittest.stubs.EntityRefComponent)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)1 PlayerStore (org.terasology.engine.persistence.PlayerStore)1 StorageManager (org.terasology.engine.persistence.StorageManager)1 StringComponent (org.terasology.unittest.stubs.StringComponent)1