Search in sources :

Example 26 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class EntitySerializerTest method testMappedTypeHandling.

@Test
public void testMappedTypeHandling() throws Exception {
    componentLibrary.register(new SimpleUri("test", "mappedtype"), MappedTypeComponent.class);
    EntityRef entity = entityManager.create();
    entity.addComponent(new MappedTypeComponent());
    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(MappedTypeComponent.class));
}
Also used : SimpleUri(org.terasology.engine.SimpleUri) EntityData(org.terasology.protobuf.EntityData) MappedTypeComponent(org.terasology.entitySystem.stubs.MappedTypeComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 27 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class EntitySerializerTest method setup.

@Before
public void setup() {
    context.put(NetworkSystem.class, mock(NetworkSystem.class));
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
    entityManager.getComponentLibrary().register(new SimpleUri("test", "gettersetter"), GetterSetterComponent.class);
    entityManager.getComponentLibrary().register(new SimpleUri("test", "string"), StringComponent.class);
    entityManager.getComponentLibrary().register(new SimpleUri("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.entitySystem.entity.internal.EngineEntityManager) PrefabData(org.terasology.entitySystem.prefab.PrefabData) StringComponent(org.terasology.entitySystem.stubs.StringComponent) NetworkSystem(org.terasology.network.NetworkSystem) SimpleUri(org.terasology.engine.SimpleUri) ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab) EntitySerializer(org.terasology.persistence.serializers.EntitySerializer) Before(org.junit.Before)

Example 28 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class BindsSubsystemTest method testUpdateBinds.

@Test
public void testUpdateBinds() {
    registerBindButtonClasses.add(TestEventButton.class);
    bindsSubsystem.updateConfigWithDefaultBinds();
    List<Input> defaultBinds = bindsSubsystem.getDefaultBindsConfig().getBinds(new SimpleUri(TEST_MODULE, "testEvent"));
    assertThat(defaultBinds.size(), is(1));
    assertThat(defaultBinds.get(0).getType(), is(InputType.KEY));
    assertThat(defaultBinds.get(0).getId(), is(KeyId.T));
    assertThat(defaultBinds.get(0).getName(), is(Key.T.getName()));
    assertThat(defaultBinds.get(0).getDisplayName(), is(Key.T.getDisplayName()));
    List<Input> binds = bindsSubsystem.getBindsConfig().getBinds(new SimpleUri(TEST_MODULE, "testEvent"));
    assertThat(binds.size(), is(1));
    assertThat(binds.get(0).getType(), is(InputType.KEY));
    assertThat(binds.get(0).getId(), is(KeyId.T));
    assertThat(binds.get(0).getName(), is(Key.T.getName()));
    assertThat(binds.get(0).getDisplayName(), is(Key.T.getDisplayName()));
}
Also used : Input(org.terasology.input.Input) SimpleUri(org.terasology.engine.SimpleUri) Test(org.junit.Test)

Example 29 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class PojoEventSystemTests method testChildEvent.

@Test
public void testChildEvent() {
    entity.addComponent(new IntegerComponent());
    TestEventHandler handler = new TestEventHandler();
    eventSystem.registerEvent(new SimpleUri("test:childEvent"), TestChildEvent.class);
    eventSystem.registerEventHandler(handler);
    TestChildEvent event = new TestChildEvent();
    eventSystem.send(entity, event);
    assertEquals(1, handler.childEventReceived.size());
    assertEquals(1, handler.receivedList.size());
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) SimpleUri(org.terasology.engine.SimpleUri) Test(org.junit.Test)

Example 30 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class FieldMetadataTest method testOwnsAnnotationCollectionProcessed.

@Test
public void testOwnsAnnotationCollectionProcessed() throws NoSuchMethodException {
    ComponentMetadata<OwnedCollectionComponent> classMetadata = new ComponentMetadata<>(new SimpleUri("unittest:OwnedCollectionComponent"), OwnedCollectionComponent.class, factory, copyStrategyLibrary);
    ComponentFieldMetadata metadata = classMetadata.getField("items");
    assertTrue(metadata.isOwnedReference());
}
Also used : SimpleUri(org.terasology.engine.SimpleUri) Test(org.junit.Test)

Aggregations

SimpleUri (org.terasology.engine.SimpleUri)71 Test (org.junit.Test)18 Map (java.util.Map)10 Name (org.terasology.naming.Name)9 ResourceUrn (org.terasology.assets.ResourceUrn)7 DefaultClassMetadata (org.terasology.reflection.metadata.DefaultClassMetadata)7 Config (org.terasology.config.Config)6 Input (org.terasology.input.Input)6 FBO (org.terasology.rendering.opengl.FBO)6 ModuleManager (org.terasology.engine.module.ModuleManager)5 Command (org.terasology.logic.console.commandSystem.annotations.Command)5 ModuleEnvironment (org.terasology.module.ModuleEnvironment)5 List (java.util.List)4 DependencyResolver (org.terasology.module.DependencyResolver)4 ResolutionResult (org.terasology.module.ResolutionResult)4 UILabel (org.terasology.rendering.nui.widgets.UILabel)4 Lists (com.google.common.collect.Lists)3 IOException (java.io.IOException)3 Type (java.lang.reflect.Type)3 Locale (java.util.Locale)3