public DiscoApiModel(Document document, String defaultPackageName) { this.document = document; this.diagCollector = new BoundedDiagCollector(); this.defaultPackageName = defaultPackageName; }
@Before public void before() { diagCollector = new BoundedDiagCollector( ImmutableMap.<Kind, Integer>builder() .put(Kind.ERROR, ERROR_MAX_COUNT) .put(Kind.WARNING, WARNING_MAX_COUNT) .build()); }
/** * Creates a new model based on the given file descriptor, list of source file names and list of * experiments to be enabled for the model. */ public static Model create( FileDescriptorSet proto, Iterable<String> sources, Experiments experiments, ExtensionPool extensionPool) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, sources, experiments, extensionPool, diagCollector, new DiagSuppressor(diagCollector)); }
/** Creates an model where all protos in the descriptor are considered to be sources. */ public static Model create(FileDescriptorSet proto) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, null, ExperimentsImpl.none(), ExtensionPool.EMPTY, diagCollector, new DiagSuppressor(diagCollector)); }
/** * Creates a new model based on the given file descriptor, list of source file names and list of * experiments to be enabled for the model. */ public static Model create( FileDescriptorSet proto, Iterable<String> sources, Experiments experiments, ExtensionPool extensionPool) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, sources, experiments, extensionPool, diagCollector, new DiagSuppressor(diagCollector)); }
/** Creates an model where all protos in the descriptor are considered to be sources. */ public static Model create(FileDescriptorSet proto) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, null, ExperimentsImpl.none(), ExtensionPool.EMPTY, diagCollector, new DiagSuppressor(diagCollector)); }
/** * Creates a new model based on the given file descriptor set and list of source file names. The * file descriptor set is self-contained and contains the descriptors for the source files as well * as for all dependencies. */ public static Model create(FileDescriptorSet proto, Iterable<String> sources) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, sources, ExperimentsImpl.none(), ExtensionPool.EMPTY, diagCollector, new DiagSuppressor(diagCollector)); }
/** * Creates a new model based on the given file descriptor set and list of source file names. The * file descriptor set is self-contained and contains the descriptors for the source files as well * as for all dependencies. */ public static Model create(FileDescriptorSet proto, Iterable<String> sources) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, sources, ExperimentsImpl.none(), ExtensionPool.EMPTY, diagCollector, new DiagSuppressor(diagCollector)); }
@Test public void testCreateLROWithNonLROMethod() { DiagCollector diagCollector = new BoundedDiagCollector(); LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( simpleMethod, diagCollector, LongRunningConfigProto.getDefaultInstance(), protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNull(); } }
/** * Run a test for the given file base name(s). Collects all .proto and .yaml files with the given * base name (i.e. baseName.proto or baseName.yaml), constructs model, and calls {@link #run()}. * Post that, prints diags and the result of the run to the baseline. */ protected void test() throws Exception { DiagCollector diagCollector = new BoundedDiagCollector(); // Run test specific logic. Object result = run(); if (!diagCollector.hasErrors() && result != null) { // Output the result depending on its type. if (result instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) result; for (Map.Entry<String, Object> entry : map.entrySet()) { testOutput().printf("============== file: %s ==============%n", entry.getKey()); testOutput().println(displayValue(entry.getValue())); } } else { testOutput().println(displayValue(result)); } } }
@Test public void testWithConfigAndInterface() { DiagCollector diagCollector = new BoundedDiagCollector();
@Test public void testCreateResourceNameConfigs() { DiagCollector diagCollector = new BoundedDiagCollector();
.build(); DiagCollector diagCollector = new BoundedDiagCollector();
ToolOptions options, ModelBuildOverrides registry, String builtDataPath) { DiagCollector diagCollector = new BoundedDiagCollector(); Set<FileWrapper> protoFiles = parseConfigFiles(options, builtDataPath, diagCollector); List<String> protoFileNames = Lists.newArrayList();
ToolOptions options, ModelBuildOverrides registry, String builtDataPath) { DiagCollector diagCollector = new BoundedDiagCollector(); Set<FileWrapper> protoFiles = parseConfigFiles(options, builtDataPath, diagCollector); List<String> protoFileNames = Lists.newArrayList();
@Test public void testCreateLROWithGapicConfigOnly() { DiagCollector diagCollector = new BoundedDiagCollector(); // simpleMethod has no LRO proto annotations. // lroConfigProtoWithPollSettings contains LRO settings. LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( simpleMethod, diagCollector, lroConfigProtoWithPollSettings, protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNotNull(); ProtoTypeRef metadataTypeModel = (ProtoTypeRef) longRunningConfig.getMetadataType(); assertThat(metadataTypeModel.getProtoType()).isEqualTo(gapicConfigMetadataType); ProtoTypeRef returnTypeModel = (ProtoTypeRef) longRunningConfig.getReturnType(); assertThat(returnTypeModel.getProtoType()).isEqualTo(gapicConfigReturnType); // These are the values specified by lroConfigProtoWithPollSettings. 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); assertThat(longRunningConfig.implementsCancel()).isEqualTo(TEST_IMPLEMENTS_CANCEL); assertThat(longRunningConfig.implementsDelete()).isEqualTo(TEST_IMPLEMENTS_DELETE); }
@Test public void testCreateLROWithAnnotationsOverridingGapicConfig() { DiagCollector diagCollector = new BoundedDiagCollector(); // lroAnnotatedMethod contains different settings than that in lroConfigProtoWithPollSettings. LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( lroAnnotatedMethod, diagCollector, lroConfigProtoWithPollSettings, protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNotNull(); // Assert that proto annotations settings take precendence over gapic config. 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(LongRunningConfig.LRO_INITIAL_POLL_DELAY_MILLIS); assertThat(longRunningConfig.getMaxPollDelay().toMillis()) .isEqualTo(LongRunningConfig.LRO_MAX_POLL_DELAY_MILLIS); assertThat(longRunningConfig.getPollDelayMultiplier()) .isEqualTo(LongRunningConfig.LRO_POLL_DELAY_MULTIPLIER); assertThat(longRunningConfig.getTotalPollTimeout().toMillis()) .isEqualTo(LongRunningConfig.LRO_TOTAL_POLL_TIMEOUT_MILLS); assertThat(longRunningConfig.implementsCancel()) .isEqualTo(LongRunningConfig.LRO_IMPLEMENTS_CANCEL); assertThat(longRunningConfig.implementsDelete()) .isEqualTo(LongRunningConfig.LRO_IMPLEMENTS_DELETE); }
@Test public void testCreateLROWithoutGapicConfig() { DiagCollector diagCollector = new BoundedDiagCollector(); LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( lroAnnotatedMethod, diagCollector, LongRunningConfigProto.getDefaultInstance(), protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNotNull(); 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(LongRunningConfig.LRO_INITIAL_POLL_DELAY_MILLIS); assertThat(longRunningConfig.getMaxPollDelay().toMillis()) .isEqualTo(LongRunningConfig.LRO_MAX_POLL_DELAY_MILLIS); assertThat(longRunningConfig.getPollDelayMultiplier()) .isEqualTo(LongRunningConfig.LRO_POLL_DELAY_MULTIPLIER); assertThat(longRunningConfig.getTotalPollTimeout().toMillis()) .isEqualTo(LongRunningConfig.LRO_TOTAL_POLL_TIMEOUT_MILLS); assertThat(longRunningConfig.implementsCancel()) .isEqualTo(LongRunningConfig.LRO_IMPLEMENTS_CANCEL); assertThat(longRunningConfig.implementsDelete()) .isEqualTo(LongRunningConfig.LRO_IMPLEMENTS_DELETE); }
@BeforeClass public static void startUp() { defaultHeaderUtil = LicenseHeaderUtil.create(null, null, new BoundedDiagCollector()); ConfigProto configProto = ConfigProto.newBuilder() .setLicenseHeader( LicenseHeaderProto.newBuilder() .setCopyrightFile(DEFAULT_COPYRIGHT_FILE) .setLicenseFile(DEFAULT_LICENSE_FILE)) .build(); explicitHeaderUtil = LicenseHeaderUtil.create( configProto, LanguageSettingsProto.getDefaultInstance(), new BoundedDiagCollector()); ConfigProto langOverrideConfigProto = configProto .toBuilder() .putLanguageSettings( LANGUAGE, LanguageSettingsProto.newBuilder() .setLicenseHeaderOverride( LicenseHeaderProto.newBuilder().setLicenseFile(IMAGINARY_FILE).build()) .build()) .build(); langOverrideHeaderUtil = LicenseHeaderUtil.create( langOverrideConfigProto, langOverrideConfigProto.getLanguageSettingsMap().get(LANGUAGE), new BoundedDiagCollector()); }
DiagCollector diagCollector = new BoundedDiagCollector();