Search in sources :

Example 16 with DiagCollector

use of com.google.api.tools.framework.model.DiagCollector in project toolkit by googleapis.

the class LongRunningConfigTest method testCreateSameLROFromProtoFileAndGapicConfig.

@Test
public void testCreateSameLROFromProtoFileAndGapicConfig() {
    Mockito.when(protoParser.isProtoAnnotationsEnabled()).thenReturn(true);
    // Given a Protobuf LRO method annotated with the same Return and Metadata Type
    // as in the GAPIC config, use the GAPIC config settings.
    DiagCollector diagCollector = new BoundedDiagCollector();
    // Use a GAPIC config with the same return and metadata types as the LRO proto annotations.
    LongRunningConfigProto longRunningConfigProto = lroConfigProtoWithPollSettings.toBuilder().setMetadataType(PROTO_PACKAGE_NAME + "." + ANNOTATIONS_METADATA_TYPE).setReturnType(PROTO_PACKAGE_NAME + "." + ANNOTATIONS_RETURN_TYPE_NAME).build();
    LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig(lroAnnotatedMethod, diagCollector, longRunningConfigProto, protoParser);
    assertThat(diagCollector.getErrorCount()).isEqualTo(0);
    assertThat(longRunningConfig).isNotNull();
    // Assert that we are using gapic config LRO settings.
    ProtoTypeRef metadataTypeModel = (ProtoTypeRef) longRunningConfig.getMetadataType();
    assertThat(metadataTypeModel.getProtoType()).isEqualTo(annotationsMetadataType);
    ProtoTypeRef returnTypeModel = (ProtoTypeRef) longRunningConfig.getReturnType();
    assertThat(returnTypeModel.getProtoType()).isEqualTo(annotationsReturnType);
    assertThat(longRunningConfig.getInitialPollDelay().toMillis()).isEqualTo(TEST_INITIAL_POLL_DELAY);
    assertThat(longRunningConfig.getMaxPollDelay().toMillis()).isEqualTo(TEST_MAX_POLL_DELAY);
    assertThat(longRunningConfig.getPollDelayMultiplier()).isEqualTo(TEST_POLL_DELAY_MULTIPLIER);
    assertThat(longRunningConfig.getTotalPollTimeout().toMillis()).isEqualTo(TEST_TOTAL_POLL_TIMEOUT);
}
Also used : BoundedDiagCollector(com.google.api.tools.framework.model.BoundedDiagCollector) DiagCollector(com.google.api.tools.framework.model.DiagCollector) BoundedDiagCollector(com.google.api.tools.framework.model.BoundedDiagCollector) LongRunningConfigProto(com.google.api.codegen.LongRunningConfigProto) Test(org.junit.Test)

Example 17 with DiagCollector

use of com.google.api.tools.framework.model.DiagCollector in project toolkit by googleapis.

the class DiscoGapicGeneratorApp method loadConfigFromFiles.

private static ConfigProto loadConfigFromFiles(List<String> configFileNames) {
    ConfigProto configProto = null;
    DiagCollector diagCollector = new SimpleDiagCollector();
    if (configFileNames.size() > 0) {
        // Read the YAML config and convert it to proto.
        ConfigSource configSource = loadGapicConfigFromFiles(configFileNames, diagCollector);
        if (configSource == null) {
            return null;
        }
        configProto = (ConfigProto) configSource.getConfig();
        if (configProto == null || configProto.equals(ConfigProto.getDefaultInstance())) {
            return null;
        }
    }
    return configProto;
}
Also used : ConfigSource(com.google.api.tools.framework.model.ConfigSource) ConfigProto(com.google.api.codegen.ConfigProto) SimpleDiagCollector(com.google.api.tools.framework.model.SimpleDiagCollector) DiagCollector(com.google.api.tools.framework.model.DiagCollector) SimpleDiagCollector(com.google.api.tools.framework.model.SimpleDiagCollector)

Aggregations

DiagCollector (com.google.api.tools.framework.model.DiagCollector)17 BoundedDiagCollector (com.google.api.tools.framework.model.BoundedDiagCollector)11 Test (org.junit.Test)10 ConfigProto (com.google.api.codegen.ConfigProto)3 ResourceNameTreatment (com.google.api.codegen.ResourceNameTreatment)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 CollectionConfigProto (com.google.api.codegen.CollectionConfigProto)2 FlatteningConfigProto (com.google.api.codegen.FlatteningConfigProto)2 InterfaceConfigProto (com.google.api.codegen.InterfaceConfigProto)2 MethodConfigProto (com.google.api.codegen.MethodConfigProto)2 ReleaseLevel (com.google.api.codegen.ReleaseLevel)2 ResourceNameMessageConfigProto (com.google.api.codegen.ResourceNameMessageConfigProto)2 SurfaceTreatmentProto (com.google.api.codegen.SurfaceTreatmentProto)2 SimpleDiagCollector (com.google.api.tools.framework.model.SimpleDiagCollector)2 ImmutableList (com.google.common.collect.ImmutableList)2 File (java.io.File)2 Nullable (javax.annotation.Nullable)2 ResourceDescriptor (com.google.api.ResourceDescriptor)1 ResourceReference (com.google.api.ResourceReference)1