/** Returns the associated service config raw value. */ @Requires(Merged.class) public Service getServiceConfig() { return (Service) serviceConfig.getConfig(); }
@Override public Message apply(ConfigSource input) { return input.getConfig(); } })
/** Returns the associated service config raw value. */ @Requires(Merged.class) public Service getServiceConfig() { return (Service) serviceConfig.getConfig(); }
private ConfigSource testFromInputString(String inputName, String content) { SimpleDiagCollector diag = new SimpleDiagCollector(); ConfigSource config = YamlReader.readConfig(diag, inputName, content, supportedConfigTypes); if (config == null) { testOutput().println("errors!!"); testOutput().println(diag); } else { testOutput().println(TextFormatForTest.INSTANCE.printToString(config.getConfig())); } return config; }
configProto = (ConfigProto) configSource.getConfig(); if (configProto == null) { return;
/** * Constructs a sub-builder for given field and calls the action on it. After the action's * processing, the sub-message will be build and stored into the field of this builder. * Moreover, update locations of the sub-builder are integrated into this builder. */ public Builder withBuilder(FieldDescriptor field, BuildAction action) { // Construct a fresh builder for the given field and merge in the current value. As we depend // on message identity, we need to control this builder directly, so can't use implicit // building via getFieldBuilder. A builder created by getFieldBuilder as build() called // when the parent is called, resulting in a different message identity. Message currentValue = (Message) configBuilder.getField(field); Message.Builder protoBuilder = configBuilder.newBuilderForField(field); protoBuilder.mergeFrom(currentValue); // Construct config builder, and let the action process it. Builder fieldConfigBuilder = new Builder(currentValue, protoBuilder, locations); action.accept(fieldConfigBuilder); // Build config, which updates the location mapping, and update proto builder. ConfigSource fieldConfig = fieldConfigBuilder.build(); configBuilder.setField(field, fieldConfig.getConfig()); return this; }
/** * Constructs a sub-builder for given field and calls the action on it. After the action's * processing, the sub-message will be build and stored into the field of this builder. * Moreover, update locations of the sub-builder are integrated into this builder. */ public Builder withBuilder(FieldDescriptor field, BuildAction action) { // Construct a fresh builder for the given field and merge in the current value. As we depend // on message identity, we need to control this builder directly, so can't use implicit // building via getFieldBuilder. A builder created by getFieldBuilder as build() called // when the parent is called, resulting in a different message identity. Message currentValue = (Message) configBuilder.getField(field); Message.Builder protoBuilder = configBuilder.newBuilderForField(field); protoBuilder.mergeFrom(currentValue); // Construct config builder, and let the action process it. Builder fieldConfigBuilder = new Builder(currentValue, protoBuilder, locations); action.accept(fieldConfigBuilder); // Build config, which updates the location mapping, and update proto builder. ConfigSource fieldConfig = fieldConfigBuilder.build(); configBuilder.setField(field, fieldConfig.getConfig()); return this; }
Descriptor descriptor = config.getConfig().getDescriptorForType(); ConfigSource.Builder builder = mergedConfigs.get(descriptor); if (builder == null) {
Descriptor descriptor = config.getConfig().getDescriptorForType(); ConfigSource.Builder builder = mergedConfigs.get(descriptor); if (builder == null) {
@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 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); }
@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); }
SomeConfig config = (SomeConfig) source.getConfig();
@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); }
SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getRepeatedNestedConfigCount()).isEqualTo(2); NestedConfig nested1 = config.getRepeatedNestedConfig(0);
SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getStringValue()).isEqualTo(""); Truth.assertThat(source.getLocation(config, STRING_VALUE_FIELD.getName(), null)).isEqualTo(L2);