Search in sources :

Example 1 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class VectorEventSerializer method setup.

@BeforeEach
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    context.put(ReflectFactory.class, reflectFactory);
    context.put(CopyStrategyLibrary.class, copyStrategies);
    ModuleTypeRegistry typeRegistry = new ModuleTypeRegistry(moduleManager.getEnvironment());
    TypeHandlerLibrary typeHandlerLibrary = TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry);
    entitySystemLibrary = new EntitySystemLibrary(context, typeHandlerLibrary);
    serializer = new EventSerializer(entitySystemLibrary.getEventLibrary(), typeHandlerLibrary);
    registerEvent(Vector3fTestEvent.class);
    serializer.setIdMapping(eventMap);
}
Also used : ModuleTypeRegistry(org.terasology.reflection.ModuleTypeRegistry) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) EventSerializer(org.terasology.engine.persistence.serializers.EventSerializer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class EventSystemReplayImplTest method setup.

@BeforeEach
public void setup() {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    Reflections reflections = new Reflections(getClass().getClassLoader());
    TypeHandlerLibrary serializationLibrary = new TypeHandlerLibraryImpl(reflections);
    EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, serializationLibrary);
    PojoEntityManager entityManager = new PojoEntityManager();
    entityManager.setComponentLibrary(entitySystemLibrary.getComponentLibrary());
    entityManager.setPrefabManager(new PojoPrefabManager(context));
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    recordAndReplayCurrentStatus = new RecordAndReplayCurrentStatus();
    RecordedEventStore eventStore = new RecordedEventStore();
    RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils();
    CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
    ModuleManager moduleManager = mock(ModuleManager.class);
    when(moduleManager.getEnvironment()).thenReturn(mock(ModuleEnvironment.class));
    RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, eventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, mock(TypeRegistry.class));
    recordAndReplayCurrentStatus.setStatus(RecordAndReplayStatus.REPLAYING);
    entity = entityManager.create();
    Long id = entity.getId();
    eventStore.add(new RecordedEvent(id, new AttackButton(), 1, 1));
    eventStore.add(new RecordedEvent(id, new AttackButton(), 2, 2));
    eventStore.add(new RecordedEvent(id, new AttackButton(), 3, 3));
    List<Class<?>> selectedClassesToReplay = new ArrayList<>();
    selectedClassesToReplay.add(InputEvent.class);
    eventSystem = new EventSystemReplayImpl(entitySystemLibrary.getEventLibrary(), networkSystem, entityManager, eventStore, recordAndReplaySerializer, recordAndReplayUtils, selectedClassesToReplay, recordAndReplayCurrentStatus);
    entityManager.setEventSystem(eventSystem);
    handler = new TestEventHandler();
    eventSystem.registerEventHandler(handler);
}
Also used : PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) ArrayList(java.util.ArrayList) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) TypeRegistry(org.terasology.reflection.TypeRegistry) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) Reflections(org.reflections.Reflections) NetworkSystem(org.terasology.engine.network.NetworkSystem) TypeHandlerLibraryImpl(org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) PojoEntityManager(org.terasology.engine.entitySystem.entity.internal.PojoEntityManager) AttackButton(org.terasology.engine.input.binds.interaction.AttackButton) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class InjectionHelperTest method testConstructorInjectionNoDefaultConstructorForFallback.

@Test
public void testConstructorInjectionNoDefaultConstructorForFallback() {
    Context context = new ContextImpl();
    context.put(ServiceA.class, serviceA);
    // context.put(ServiceB.class, serviceB);
    // there is only one constructor for serviceB which is not present on the context.
    // a default constructor is not available, so the injection fails.
    Assertions.assertThrows(NoSuchElementException.class, () -> InjectionHelper.createWithConstructorInjection(ConstructorB.class, context));
}
Also used : Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) Test(org.junit.jupiter.api.Test)

Example 4 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class InjectionHelperTest method setUp.

@BeforeEach
public void setUp() {
    serviceA = new ServiceAImpl();
    serviceB = new ServiceBImpl();
    // injection helper uses the core registry,
    // make sure the shared classes are not used over multiple tests
    CoreRegistry.setContext(new ContextImpl());
}
Also used : ContextImpl(org.terasology.engine.context.internal.ContextImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ContextImpl

use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class InjectionHelperTest method testConstructorInjectionNotAllParametersPopulated.

@Test
public void testConstructorInjectionNotAllParametersPopulated() {
    Context context = new ContextImpl();
    context.put(ServiceA.class, serviceA);
    // context.put(ServiceB.class, serviceB);
    ConstructorAB constructorAB = InjectionHelper.createWithConstructorInjection(ConstructorAB.class, context);
    // the two-arg constructor can't be populated because serviceB is not available
    // there is no fallback for a constructor with only serviceA, so the default constructor is called
    assertNull(constructorAB.getServiceA());
    assertNull(constructorAB.getServiceB());
}
Also used : Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) Test(org.junit.jupiter.api.Test)

Aggregations

ContextImpl (org.terasology.engine.context.internal.ContextImpl)26 BeforeEach (org.junit.jupiter.api.BeforeEach)13 ModuleManager (org.terasology.engine.core.module.ModuleManager)8 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)8 Context (org.terasology.engine.context.Context)7 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)7 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)6 ModuleAwareAssetTypeManagerImpl (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl)6 BeforeAll (org.junit.jupiter.api.BeforeAll)5 Test (org.junit.jupiter.api.Test)4 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)4 NetworkSystem (org.terasology.engine.network.NetworkSystem)4 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)4 Reflections (org.reflections.Reflections)3 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)3 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)3 TypeHandlerLibraryImpl (org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl)3 Config (org.terasology.engine.config.Config)2 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2