Search in sources :

Example 16 with DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testTypesAreCoerced.

@Test
void testTypesAreCoerced() {
    final DataContainer source = DataContainer.createNew();
    source.set(DataQuery.of("i'm a short"), (short) 5);
    final ConfigurationNode destination = BasicConfigurationNode.root(ConfigurationOptions.defaults().nativeTypes(Collections.singleton(Integer.class)));
    ConfigurateTranslator.instance().translateDataToNode(destination, source);
    assertEquals(5, destination.node("i'm a short").raw());
}
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 17 with DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testMapInsideList.

@Test
void testMapInsideList() throws IOException {
    final JsonDataFormat json = new JsonDataFormat();
    final ConfigurationNode node = CommentedConfigurationNode.root();
    final Map<String, String> map = Collections.singletonMap("mkey", "mvalue");
    final List<Object> list = Arrays.asList("lelement", map);
    node.node("foo").raw("bar");
    node.node("l").raw(list);
    final DataContainer jc = json.read("{\"foo\":\"bar\",\"l\":[\"lelement\",{\"mkey\":\"mvalue\"}]}");
    final DataContainer hc = ConfigurateTranslator.instance().translate(node);
    assertEquals(jc.getMap(DataQuery.of()), hc.getMap(DataQuery.of()));
}
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 18 with DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testEmptyDataToNode.

@Test
void testEmptyDataToNode() {
    final DataContainer source = DataContainer.createNew();
    final ConfigurationNode destination = ConfigurateTranslator.instance().translate(source);
    assertTrue(destination.empty());
}
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 DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testColor.

@Test
void testColor() throws IOException {
    final Color color = Color.ofRgb(0x66, 0xCC, 0xFF);
    final DataContainer original = color.toContainer();
    final String serialized = ConfigurateDataViewTest.HOCON.write(original);
    final DataContainer ret = ConfigurateDataViewTest.HOCON.read(serialized);
    assertEquals(original, ret);
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) Color(org.spongepowered.api.util.Color) Test(org.junit.jupiter.api.Test)

Example 20 with DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testFireworkEffectData.

@Test
void testFireworkEffectData() throws IOException {
    final Color color = Color.ofRgb(0x66, 0xCC, 0xFF);
    final FireworkEffect fe = new SpongeFireworkEffectBuilder().colors(color, color, color).build();
    final DataContainer container = fe.toContainer();
    final String s = ConfigurateDataViewTest.HOCON.write(container);
    final DataContainer dc = ConfigurateDataViewTest.HOCON.read(s);
    assertEquals(container, dc);
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) SpongeFireworkEffectBuilder(org.spongepowered.common.item.SpongeFireworkEffectBuilder) Color(org.spongepowered.api.util.Color) FireworkEffect(org.spongepowered.api.item.FireworkEffect) Test(org.junit.jupiter.api.Test)

Aggregations

DataContainer (org.spongepowered.api.data.persistence.DataContainer)43 ResourceKey (org.spongepowered.api.ResourceKey)14 DataView (org.spongepowered.api.data.persistence.DataView)12 CompoundTag (net.minecraft.nbt.CompoundTag)9 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)7 DataQuery (org.spongepowered.api.data.persistence.DataQuery)7 BasicConfigurationNode (org.spongepowered.configurate.BasicConfigurationNode)7 CommentedConfigurationNode (org.spongepowered.configurate.CommentedConfigurationNode)7 ConfigurationNode (org.spongepowered.configurate.ConfigurationNode)7 Optional (java.util.Optional)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)6 Map (java.util.Map)5 NonNull (org.checkerframework.checker.nullness.qual.NonNull)5 Sponge (org.spongepowered.api.Sponge)5 DataTranslator (org.spongepowered.api.data.persistence.DataTranslator)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Collection (java.util.Collection)4 DataManager (org.spongepowered.api.data.DataManager)4