Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.moduletestingenvironment;

import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.SimpleUri;
import org.terasology.engine.TerasologyConstants;
import org.terasology.engine.module.ModuleManager;
import org.terasology.engine.subsystem.headless.mode.StateHeadlessSetup;
import org.terasology.game.GameManifest;
import org.terasology.module.DependencyInfo;
import org.terasology.module.DependencyResolver;
import org.terasology.module.Module;
import org.terasology.module.ResolutionResult;
Expand All @@ -21,6 +19,7 @@

import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

public class TestingStateHeadlessSetup extends StateHeadlessSetup {
private static final Logger logger = LoggerFactory.getLogger(TestingStateHeadlessSetup.class);
Expand All @@ -33,27 +32,22 @@ public TestingStateHeadlessSetup(Collection<String> dependencies, String worldGe

@Override
public GameManifest createGameManifest() {

GameManifest gameManifest = new GameManifest();

gameManifest.setTitle("testworld");
gameManifest.setSeed("seed");
DependencyResolver resolver = new DependencyResolver(CoreRegistry.get(ModuleManager.class).getRegistry());

Set<Name> dependencyNames = Sets.newHashSet();
for (String moduleName : dependencies) {
logger.warn("Adding dependencies for {}", moduleName);
dependencyNames.add(new Name(moduleName));
recursivelyAddModuleDependencies(dependencyNames, new Name(moduleName));
}
Set<Name> dependencyNames = dependencies.stream().map(Name::new).collect(Collectors.toSet());
logger.info("Building manifest for module dependencies: {}", dependencyNames);

ResolutionResult result = resolver.resolve(dependencyNames);
if (!result.isSuccess()) {
logger.warn("Unable to resolve modules: {}", dependencyNames);
logger.error("Unable to resolve modules: {}", dependencyNames);
}

for (Module module : result.getModules()) {
logger.warn("Loading module {} {}", module.getId(), module.getVersion());
logger.info("Loading module {} {}", module.getId(), module.getVersion());
gameManifest.addModule(module.getId(), module.getVersion());
}

Expand All @@ -63,15 +57,4 @@ public GameManifest createGameManifest() {
gameManifest.addWorld(worldInfo);
return gameManifest;
}

private void recursivelyAddModuleDependencies(Set<Name> modules, Name moduleName) {
Module module = CoreRegistry.get(ModuleManager.class).getRegistry().getLatestModuleVersion(moduleName);
if (module != null) {
for (DependencyInfo dependencyInfo : module.getMetadata().getDependencies()) {
logger.warn("Adding dependency {}", dependencyInfo.getId());
modules.add(dependencyInfo.getId());
recursivelyAddModuleDependencies(modules, dependencyInfo.getId());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
/*
* Copyright 2020 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.moduletestingenvironment;

import com.google.common.collect.Sets;
import org.junit.Assert;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -29,6 +15,8 @@

import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class ReuseEngineTest {
private static ModuleTestingHelper helper;
private EntityRef entity;
Expand Down Expand Up @@ -61,11 +49,11 @@ public void prepareEntityForTest() {
@Test
public void someTest() {
entity.send(new DummyEvent());
Assert.assertTrue(entity.getComponent(DummyComponent.class).dummy);
assertTrue(entity.getComponent(DummyComponent.class).dummy);
}

@Test
public void someOtherTest() {
Assert.assertTrue(entity.hasComponent(DummyComponent.class));
assertTrue(entity.hasComponent(DummyComponent.class));
}
}