/** * Returns the service config file location of the given named field in the (sub)message. The key * identifies the key of the map. For repeated fields, the element key is a zero-based index. * Returns {@link SimpleLocation#TOPLEVEL} if the location is not known. */ @Override public Location getLocationOfRepeatedFieldInConfig( Message message, String fieldName, Object elementKey) { Location loc = getLocation(message, fieldName, elementKey); return loc != SimpleLocation.UNKNOWN ? loc : SimpleLocation.TOPLEVEL; }
/** * Returns the service config file location of the given named field in the (sub)message. Returns * {@link SimpleLocation#TOPLEVEL} if the location is not known. */ @Override public Location getLocationInConfig(Message message, String fieldName) { Location loc = getLocation(message, fieldName, null); return loc != SimpleLocation.UNKNOWN ? loc : SimpleLocation.TOPLEVEL; }
/** * Returns the service config file location of the given named field in the (sub)message. Returns * {@link SimpleLocation#TOPLEVEL} if the location is not known. */ @Override public Location getLocationInConfig(Message message, String fieldName) { Location loc = getLocation(message, fieldName, null); return loc != SimpleLocation.UNKNOWN ? loc : SimpleLocation.TOPLEVEL; }
/** * Returns the service config file location of the given named field in the (sub)message. The key * identifies the key of the map. For repeated fields, the element key is a zero-based index. * Returns {@link SimpleLocation#TOPLEVEL} if the location is not known. */ @Override public Location getLocationOfRepeatedFieldInConfig( Message message, String fieldName, Object elementKey) { Location loc = getLocation(message, fieldName, elementKey); return loc != SimpleLocation.UNKNOWN ? loc : SimpleLocation.TOPLEVEL; }
@Test public void mapField() { ConfigSource.Builder builder = ConfigSource.newBuilder(SomeConfig.getDefaultInstance()); builder.setValue(MAP_VALUE_FIELD, "X", "A", L1); builder.setValue(MAP_VALUE_FIELD, "Y", "B", L2); ConfigSource source = builder.build(); SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getMapValue().get("X")).isEqualTo("A"); Truth.assertThat(config.getMapValue().get("Y")).isEqualTo("B"); Truth.assertThat(source.getLocation(config, MAP_VALUE_FIELD.getName(), "X")).isEqualTo(L1); Truth.assertThat(source.getLocation(config, MAP_VALUE_FIELD.getName(), "Y")).isEqualTo(L2); }
@Test public void simpleRepeatedField() { ConfigSource.Builder builder = ConfigSource.newBuilder(SomeConfig.getDefaultInstance()); builder.addValue(REPEATED_STRING_VALUE_FIELD, "a", L1); builder.addValue(REPEATED_STRING_VALUE_FIELD, "b", L2); ConfigSource source = builder.build(); SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getRepeatedStringValueList()).containsExactly("a", "b"); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 0)) .isEqualTo(L1); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 1)) .isEqualTo(L2); builder = source.toBuilder(); builder.addValue(REPEATED_STRING_VALUE_FIELD, "c", L3); source = builder.build(); config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getRepeatedStringValueList()).containsExactly("a", "b", "c"); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 0)) .isEqualTo(L1); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 1)) .isEqualTo(L2); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 2)) .isEqualTo(L3); }
@Test public void simpleField() { ConfigSource.Builder builder = ConfigSource.newBuilder(SomeConfig.getDefaultInstance()); builder.setValue(STRING_VALUE_FIELD, null, "Hello World", L1); ConfigSource source = builder.build(); SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getStringValue()).isEqualTo("Hello World"); Truth.assertThat(source.getLocation(config, STRING_VALUE_FIELD.getName(), null)).isEqualTo(L1); builder = source.toBuilder(); builder.setValue(STRING_VALUE_FIELD, null, "", L2); source = builder.build(); config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getStringValue()).isEqualTo(""); Truth.assertThat(source.getLocation(config, STRING_VALUE_FIELD.getName(), null)).isEqualTo(L2); }
Truth.assertThat(nested2.getNestedStringValue()).isEqualTo("B"); Truth.assertThat(source.getLocation(nested1, NESTED_STRING_VALUE_FIELD.getName(), null)) .isEqualTo(L1); Truth.assertThat(source.getLocation(nested2, NESTED_STRING_VALUE_FIELD.getName(), null)) .isEqualTo(L2);
@Test public void nestedSimpleField() { ConfigSource.Builder builder = ConfigSource.newBuilder(SomeConfig.getDefaultInstance()); builder.setValue(STRING_VALUE_FIELD, null, "Hello World", L1); builder.withBuilder( NESTED_CONFIG_FIELD, null, new BuildAction() { @Override public void accept(ConfigSource.Builder subBuilder) { subBuilder.setValue(NESTED_STRING_VALUE_FIELD, null, "Sub World", L2); } }); ConfigSource source = builder.build(); SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getStringValue()).isEqualTo("Hello World"); Truth.assertThat(source.getLocation(config, STRING_VALUE_FIELD.getName(), null)).isEqualTo(L1); Truth.assertThat(config.getNestedConfig().getNestedStringValue()).isEqualTo("Sub World"); Truth.assertThat( source.getLocation(config.getNestedConfig(), NESTED_STRING_VALUE_FIELD.getName(), null)) .isEqualTo(L2); }
Truth.assertThat(nested1.getNestedRepeatedInt32ValueList()).containsExactly(0, 1); Truth.assertThat(nested2.getNestedRepeatedInt32ValueList()).containsExactly(2); Truth.assertThat(source.getLocation(nested1, NESTED_REPEATED_INT32_VALUE_FIELD.getName(), 0)) .isEqualTo(L1); Truth.assertThat(source.getLocation(nested1, NESTED_REPEATED_INT32_VALUE_FIELD.getName(), 1)) .isEqualTo(L2); Truth.assertThat(source.getLocation(nested2, NESTED_REPEATED_INT32_VALUE_FIELD.getName(), 0)) .isEqualTo(L3);
Truth.assertThat(source.getLocation(config, STRING_VALUE_FIELD.getName(), null)).isEqualTo(L2); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 0)) .isEqualTo(L1); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 1)) .isEqualTo(L2); Truth.assertThat(source.getLocation(nested, NESTED_STRING_VALUE_FIELD.getName(), null)) .isEqualTo(L2);