Search in sources :

Example 1 with MaptypesConfig

use of com.yahoo.foo.MaptypesConfig in project vespa by vespa-engine.

the class ConfigInstanceBuilderTest method inner_map_setter_merges_maps.

@Test
public void inner_map_setter_merges_maps() {
    MaptypesConfig.Builder builder = new MaptypesConfig.Builder().innermap("one", new Innermap.Builder().foo(1));
    Map<String, Innermap.Builder> newMap = new HashMap<>();
    newMap.put("two", new Innermap.Builder().foo(2));
    builder.innermap(newMap);
    MaptypesConfig config = new MaptypesConfig(builder);
    assertThat(config.innermap("one").foo(), is(1));
    assertThat(config.innermap("two").foo(), is(2));
}
Also used : HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MaptypesConfig(com.yahoo.foo.MaptypesConfig) Test(org.junit.Test)

Example 2 with MaptypesConfig

use of com.yahoo.foo.MaptypesConfig in project vespa by vespa-engine.

the class ConfigInstanceBuilderTest method leaf_map_setter_merges_maps.

@Test
public void leaf_map_setter_merges_maps() {
    MaptypesConfig.Builder builder = new MaptypesConfig.Builder().intmap("one", 1);
    Map<String, Integer> newMap = new HashMap<>();
    newMap.put("two", 2);
    builder.intmap(newMap);
    MaptypesConfig config = new MaptypesConfig(builder);
    assertThat(config.intmap("one"), is(1));
    assertThat(config.intmap("two"), is(2));
}
Also used : HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MaptypesConfig(com.yahoo.foo.MaptypesConfig) Test(org.junit.Test)

Example 3 with MaptypesConfig

use of com.yahoo.foo.MaptypesConfig in project vespa by vespa-engine.

the class ConfigBuilderMergeTest method source_map_is_copied_into_destination_map_on_merge.

@Test
public void source_map_is_copied_into_destination_map_on_merge() {
    MaptypesConfig.Builder destination = new MaptypesConfig.Builder().intmap("one", 1).innermap("first", new Innermap.Builder().foo(1));
    MaptypesConfig.Builder source = new MaptypesConfig.Builder().intmap("two", 2).innermap("second", new Innermap.Builder().foo(2));
    ConfigInstanceUtil.setValues(destination, source);
    MaptypesConfig config = new MaptypesConfig(destination);
    assertThat(config.intmap("one"), is(1));
    assertThat(config.intmap("two"), is(2));
    assertThat(config.innermap("first").foo(), is(1));
    assertThat(config.innermap("second").foo(), is(2));
}
Also used : MaptypesConfig(com.yahoo.foo.MaptypesConfig) Test(org.junit.Test)

Example 4 with MaptypesConfig

use of com.yahoo.foo.MaptypesConfig in project vespa by vespa-engine.

the class ConfigInstancePayloadTest method map_types_are_correctly_deserialized.

@Test
public void map_types_are_correctly_deserialized() {
    MaptypesConfig orig = createMapTypesConfig();
    List<String> lines = ConfigInstance.serialize(orig);
    ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(lines);
    System.out.println(payload.toString());
    MaptypesConfig config = ConfigInstanceUtil.getNewInstance(MaptypesConfig.class, "foo", payload);
    System.out.println(config);
    assertThat(config.intmap().size(), is(1));
    assertThat(config.intmap("foo"), is(1337));
    assertNotNull(config.innermap("bar"));
    assertThat(config.innermap("bar").foo(), is(93));
    assertThat(config.nestedmap().size(), is(1));
    assertNotNull(config.nestedmap("baz"));
    assertThat(config.nestedmap("baz").inner("foo"), is(1));
    assertThat(config.nestedmap("baz").inner("bar"), is(2));
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) MaptypesConfig(com.yahoo.foo.MaptypesConfig) Test(org.junit.Test)

Example 5 with MaptypesConfig

use of com.yahoo.foo.MaptypesConfig in project vespa by vespa-engine.

the class ConfigInstanceSerializerTest method test_that_maps_are_formatted_to_json.

@Test
public void test_that_maps_are_formatted_to_json() throws IOException {
    MaptypesConfig.Builder builder = new MaptypesConfig.Builder();
    builder.boolmap("foo", true);
    builder.intmap("bar", 3);
    builder.stringmap("hei", "hallo");
    MaptypesConfig.Innermap.Builder inner = new MaptypesConfig.Innermap.Builder();
    inner.foo(133);
    builder.innermap("baz", inner);
    MaptypesConfig.Nestedmap.Builder nested = new MaptypesConfig.Nestedmap.Builder();
    nested.inner("foo", 33);
    builder.nestedmap("bim", nested);
    final MaptypesConfig config = new MaptypesConfig(builder);
    final String expectedJson = inputJson("{", "  'boolmap': {", "        'foo': true", "    },", "    'doublemap': {},", "    'filemap': {},", "    'innermap': {", "        'baz': {", "            'foo': 133", "        }", "    },", "    'intmap': {", "        'bar': 3", "    },", "    'longmap': {},", "    'nestedmap': {", "        'bim': {", "            'inner': {", "                'foo': 33", "            }", "        }", "    },", "    'stringmap': {", "        'hei': 'hallo'", "    }", "}");
    assertConfigEquals(expectedJson, config);
}
Also used : MaptypesConfig(com.yahoo.foo.MaptypesConfig) Test(org.junit.Test)

Aggregations

MaptypesConfig (com.yahoo.foo.MaptypesConfig)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)1