ConfigPayload { public <ConfigType extends ConfigInstance> ConfigType toInstance(Class<ConfigType> clazz, String configId) { return ConfigInstanceUtil.getNewInstance(clazz, configId, this); } ConfigPayload(Slime slime); static ConfigPayload fromInstance(ConfigInstance instance); static ConfigPayload fromBuilder(ConfigPayloadBuilder builder); Slime getSlime(); void serialize(OutputStream os, SlimeFormat format); @Override String toString(); String toString(boolean compact); ConfigPayload applyDefaultsFromDef(InnerCNode clientDef); static ConfigPayload empty(); static ConfigPayload fromString(String jsonString); boolean isEmpty(); Utf8Array toUtf8Array(boolean compact); static ConfigPayload fromUtf8Array(Utf8Array payload); ConfigType toInstance(Class<ConfigType> clazz, String configId);  }
@Test public void test_simple_struct() { Slime slime = new Slime(); addStructFields(slime.setObject().setObject("simple"), "foobar", "MALE", new String[] { "foo@bar", "bar@foo" }); StructtypesConfig config = new ConfigPayload(slime).toInstance(StructtypesConfig.class, ""); assertThat(config.simple().name(), is("foobar")); assertThat(config.simple().gender(), is(StructtypesConfig.Simple.Gender.Enum.MALE)); assertThat(config.simple().emails(0), is("foo@bar")); assertThat(config.simple().emails(1), is("bar@foo")); }
@Test public void test_simple_map() { Slime slime = new Slime(); Cursor map = slime.setObject().setObject("stringmap"); map.setString("key","val"); MaptypesConfig config = new ConfigPayload(slime).toInstance(MaptypesConfig.class, ""); assertThat(config.stringmap("key"), is("val")); }
@Test public void test_map_of_struct() { Slime slime = new Slime(); Cursor map = slime.setObject().setObject("innermap"); map.setObject("one").setLong("foo", 1); map.setObject("two").setLong("foo", 2); MaptypesConfig config = new ConfigPayload(slime).toInstance(MaptypesConfig.class, ""); assertThat(config.innermap("one").foo(), is(1)); assertThat(config.innermap("two").foo(), is(2)); }
@Test public void test_map_of_map() { Slime slime = new Slime(); Cursor map = slime.setObject().setObject("nestedmap").setObject("my-nested").setObject("inner"); map.setLong("one", 1); map.setLong("two", 2); MaptypesConfig config = new ConfigPayload(slime).toInstance(MaptypesConfig.class, ""); assertThat(config.nestedmap("my-nested").inner("one"), is(1)); assertThat(config.nestedmap("my-nested").inner("two"), is(2)); }
@Test public void non_existent_struct_in_payload_is_ignored() { Slime slime = new Slime(); addStructFields(slime.setObject().setObject("non_existent"), "", "", null); StructtypesConfig config = new ConfigPayload(slime).toInstance(StructtypesConfig.class, ""); assertNotNull(config); }
@Test public void non_existent_struct_in_struct_in_payload_is_ignored() { Slime slime = new Slime(); addStructFields(slime.setObject().setObject("nested").setObject("non_existent_inner"), "", "", null); StructtypesConfig config = new ConfigPayload(slime).toInstance(StructtypesConfig.class, ""); assertNotNull(config); }
@Test public void non_existent_array_of_struct_in_payload_is_ignored() { Slime slime = new Slime(); Cursor array = slime.setObject().setArray("non_existent_arr"); array.addObject().setString("name", "val"); StructtypesConfig config = new ConfigPayload(slime).toInstance(StructtypesConfig.class, ""); assertNotNull(config); }
@Test public void non_existent_struct_in_array_of_struct_in_payload_is_ignored() { Slime slime = new Slime(); Cursor nestedArrEntry = slime.setObject().setArray("nestedarr").addObject(); addStructFields(nestedArrEntry.setObject("inner"), "existing", "MALE", null); addStructFields(nestedArrEntry.setObject("non_existent"), "non-existent", "MALE", null); StructtypesConfig config = new ConfigPayload(slime).toInstance(StructtypesConfig.class, ""); assertThat(config.nestedarr(0).inner().name(), is("existing")); }
@Test public void non_existent_simple_map_in_payload_is_ignored() { Slime slime = new Slime(); Cursor map = slime.setObject().setObject("non_existent_map"); map.setString("key","val"); MaptypesConfig config = new ConfigPayload(slime).toInstance(MaptypesConfig.class, ""); assertNotNull(config); }
@Test public void non_existent_map_of_struct_in_payload_is_ignored() { Slime slime = new Slime(); Cursor map = slime.setObject().setObject("non_existent_inner_map"); map.setObject("one").setLong("foo", 1); MaptypesConfig config = new ConfigPayload(slime).toInstance(MaptypesConfig.class, ""); assertNotNull(config); }
@Test public void non_existent_map_in_map_in_payload_is_ignored() { Slime slime = new Slime(); Cursor map = slime.setObject().setObject("nestedmap").setObject("my-nested"); map.setObject("inner").setLong("one", 1); map.setObject("non_existent").setLong("non-existent", 0); MaptypesConfig config = new ConfigPayload(slime).toInstance(MaptypesConfig.class, ""); assertThat(config.nestedmap("my-nested").inner("one"), is(1)); }
@Test public void test_empty_payload() { Slime slime = new Slime(); slime.setObject(); IntConfig config = new ConfigPayload(slime).toInstance(IntConfig.class, ""); assertThat(config.intVal(), is(1)); }