Search in sources :

Example 16 with ConfigurationNode

use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testNullMapKey.

@Test
void testNullMapKey() {
    final ConfigurationNode node = CommentedConfigurationNode.root();
    final Map<String, String> map = Collections.singletonMap(null, "v");
    final List<Object> list = Arrays.asList("e", map);
    node.node("foo").raw("bar");
    node.node("l").raw(list);
    assertThrows(IllegalArgumentException.class, () -> ConfigurateTranslator.instance().translate(node));
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) Test(org.junit.jupiter.api.Test)

Example 17 with ConfigurationNode

use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testNodeToData.

@Test
void testNodeToData() {
    final ConfigurationNode node = BasicConfigurationNode.root();
    node.node("foo", "int").raw(1);
    node.node("foo", "double").raw(10.0D);
    node.node("foo", "long").raw(Long.MAX_VALUE);
    final List<String> stringList = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        stringList.add("String" + i);
    }
    node.node("foo", "stringList").raw(stringList);
    final List<SimpleData> dataList = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        dataList.add(new SimpleData(i, 10.0 + i, "String" + i, Collections.emptyList()));
    }
    node.node("foo", "nested", "Data").raw(dataList);
    final DataContainer manual = DataContainer.createNew();
    manual.set(DataQuery.of("foo", "int"), 1).set(DataQuery.of("foo", "double"), 10.0D).set(DataQuery.of("foo", "long"), Long.MAX_VALUE).set(DataQuery.of("foo", "stringList"), stringList).set(DataQuery.of("foo", "nested", "Data"), dataList);
    final DataView container = ConfigurateTranslator.instance().translate(node);
    assertEquals(manual, container);
    ConfigurateTranslator.instance().translate(container);
// assertEquals(node, translated); // TODO Test is broken, depends on quite a bit of init
}
Also used : DataView(org.spongepowered.api.data.persistence.DataView) DataContainer(org.spongepowered.api.data.persistence.DataContainer) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 18 with ConfigurationNode

use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testEmptyNodeToData.

@Test
void testEmptyNodeToData() {
    final ConfigurationNode source = BasicConfigurationNode.root();
    final DataContainer container = ConfigurateTranslator.instance().translate(source);
    assertTrue(container.isEmpty());
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) Test(org.junit.jupiter.api.Test)

Example 19 with ConfigurationNode

use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testNonRootNodeToData.

@Test
void testNonRootNodeToData() {
    final ConfigurationNode root = CommentedConfigurationNode.root(n -> {
        n.node("test").act(c -> {
            c.node("child").raw("hello");
            c.node("other").raw("world");
        });
    });
    final DataView view = ConfigurateTranslator.instance().translate(root.node("test"));
    assertEquals("hello", view.getString(DataQuery.of("child")).get());
    assertEquals("world", view.getString(DataQuery.of("other")).get());
    ConfigurateTranslator.instance().translateDataToNode(root.node("test2"), view);
    assertEquals(root.node("test").raw(), root.node("test2").raw());
}
Also used : DataView(org.spongepowered.api.data.persistence.DataView) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) Test(org.junit.jupiter.api.Test)

Example 20 with ConfigurationNode

use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testRespawnLocationData.

@Test
void testRespawnLocationData() throws IOException {
    final Map<ResourceKey, RespawnLocation> m = new HashMap<>();
    for (int i = 0; i < 5; i++) {
        final ResourceKey key = ResourceKey.sponge("overworld" + i);
        final RespawnLocation loc = RespawnLocation.builder().world(key).position(Vector3d.ZERO).build();
        m.put(key, loc);
    }
    final DataContainer container = DataContainer.createNew().set(DataQuery.of("respawn_locations"), m);
    final ConfigurationNode node = ConfigurateTranslator.instance().translate(container);
    final DataContainer dc = ConfigurateTranslator.instance().translate(node);
    assertEquals(container, dc);
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) RespawnLocation(org.spongepowered.api.util.RespawnLocation) HashMap(java.util.HashMap) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) ResourceKey(org.spongepowered.api.ResourceKey) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationNode (org.spongepowered.configurate.ConfigurationNode)24 CommentedConfigurationNode (org.spongepowered.configurate.CommentedConfigurationNode)20 Test (org.junit.jupiter.api.Test)19 BasicConfigurationNode (org.spongepowered.configurate.BasicConfigurationNode)19 DataContainer (org.spongepowered.api.data.persistence.DataContainer)7 DataView (org.spongepowered.api.data.persistence.DataView)2 ConfigurateException (org.spongepowered.configurate.ConfigurateException)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 InvalidPathException (java.nio.file.InvalidPathException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ResourceKey (org.spongepowered.api.ResourceKey)1 RespawnLocation (org.spongepowered.api.util.RespawnLocation)1 NodePath (org.spongepowered.configurate.NodePath)1 HoconConfigurationLoader (org.spongepowered.configurate.hocon.HoconConfigurationLoader)1