Search in sources :

Example 11 with DiagCollector

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

the class DiscoConfigBaselineTestCase method test.

/**
 * 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));
        }
    }
}
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) Map(java.util.Map)

Example 12 with DiagCollector

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

the class GapicGeneratorAppTest method writeCodeGenOutputAndSetPermissions.

@Test
public void writeCodeGenOutputAndSetPermissions() throws Exception {
    Map<String, Object> outputFiles = Maps.newHashMap();
    outputFiles.put("tmp.txt", Doc.text("Sample data"));
    outputFiles.put("tmp2.txt", Doc.text("Sample data"));
    outputFiles.put("tmp3", "Sample \"runnable\" data");
    // Verify that files are outputed to a directory.
    String outputDir = tempDir.getRoot().getPath();
    FileGapicWriter gapicWriter = new FileGapicWriter(ToolOptions.create().get(GapicGeneratorApp.OUTPUT_FILE));
    GapicGeneratorApp generator = new GapicGeneratorApp(ToolOptions.create(), ArtifactType.LEGACY_GAPIC_AND_PACKAGE, gapicWriter);
    gapicWriter.writeCodeGenOutput(outputFiles, outputDir);
    DiagCollector diagCollector = generator.getDiagCollector();
    gapicWriter.setOutputFilesPermissions(Collections.singleton("tmp3"), outputDir, diagCollector);
    assertTrue((new File(outputDir, "tmp.txt")).exists());
    assertTrue((new File(outputDir, "tmp2.txt")).exists());
    assertTrue((new File(outputDir, "tmp3")).exists());
    if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
        assertTrue((new File(outputDir, "tmp3")).canExecute());
    }
    // Verify that files are outputed into a jar file.
    File outputJar = new File(outputDir, "output.jar");
    gapicWriter.writeCodeGenOutput(outputFiles, outputJar.getPath());
    gapicWriter.setOutputFilesPermissions(Collections.singleton("tmp3"), outputJar.getPath(), diagCollector);
    assertTrue(outputJar.exists());
    assertFalse((new File(outputJar.getPath(), "tmp3")).exists());
}
Also used : DiagCollector(com.google.api.tools.framework.model.DiagCollector) File(java.io.File) Test(org.junit.Test)

Example 13 with DiagCollector

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

the class RetryDefinitionsTransformerTest method testWithConfigAndInterface.

@Test
public void testWithConfigAndInterface() {
    DiagCollector diagCollector = new BoundedDiagCollector();
    RetryCodesConfig retryCodesConfig = RetryCodesConfig.create(interfaceConfigProto, apiInterface.getMethods(), protoParser);
    Map<String, ImmutableList<String>> retryCodesDef = retryCodesConfig.getRetryCodesDefinition();
    Map<String, String> retryCodesMap = retryCodesConfig.getMethodRetryNames();
    assertThat(retryCodesMap.size()).isEqualTo(4);
    String getHttpRetryName = retryCodesMap.get(GET_HTTP_METHOD_NAME);
    String nonIdempotentRetryName = retryCodesMap.get(NON_IDEMPOTENT_METHOD_NAME);
    String permissionDeniedRetryName = retryCodesMap.get(PERMISSION_DENIED_METHOD_NAME);
    String idempotentRetryName = retryCodesMap.get(IDEMPOTENT_METHOD_NAME);
    // RETRY_CODES_IDEMPOTENT_NAME name for HTTP-GET method had to be escaped because "idempotent"
    // was already defined in the config proto retry code map already, and the config proto's
    // "idempotent" refers to a different set of retry codes compared to the default codes for
    // HTTP-GET.
    assertThat(getHttpRetryName).isEqualTo("idempotent2");
    // Even though "non_idempotent" already exists in the GAPIC config, we can
    // reuse the name for this unconfigured method because it has the same set of retry codes as
    // a non-HTTP-GET method.
    assertThat(nonIdempotentRetryName).isEqualTo(RETRY_CODES_NON_IDEMPOTENT_NAME);
    assertThat(permissionDeniedRetryName).isEqualTo(RetryTransformer.RETRY_CODES_NON_IDEMPOTENT_NAME);
    assertThat(idempotentRetryName).isEqualTo(RetryTransformer.RETRY_CODES_IDEMPOTENT_NAME);
    // httpGetMethod was an HTTP Get method, so it has two codes by default; config proto didn't
    // have a retry config.
    assertThat(retryCodesDef.get(getHttpRetryName)).isEqualTo(RetryCodesConfig.RETRY_CODES_FOR_HTTP_GET);
    // Config proto gives [] for nonIdempotentMethod; method from protofile has
    // [] for retry codes.
    assertThat(retryCodesDef.get(nonIdempotentRetryName).size()).isEqualTo(0);
    // For permissionDeniedMethod, Config proto gives [] and proto method gives [PERMISSION_DENIED].
    assertThat(retryCodesDef.get(permissionDeniedRetryName).size()).isEqualTo(0);
    assertThat(retryCodesDef.get(idempotentRetryName).iterator().next()).isEqualTo(RESOURCE_EXHAUSTED.name());
}
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) ImmutableList(com.google.common.collect.ImmutableList) RetryCodesConfig(com.google.api.codegen.config.RetryCodesConfig) Test(org.junit.Test)

Example 14 with DiagCollector

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

the class LongRunningConfigTest method testCreateLROWithNonLROMethod.

@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();
}
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) Test(org.junit.Test)

Example 15 with DiagCollector

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

the class LongRunningConfigTest method testCreateLROWithGapicConfigOnly.

@Test
public void testCreateLROWithGapicConfigOnly() {
    DiagCollector diagCollector = new BoundedDiagCollector();
    Mockito.when(protoParser.isProtoAnnotationsEnabled()).thenReturn(false);
    // simpleMethod has no LRO proto annotations.
    // lroConfigProtoWithPollSettings contains LRO settings.
    LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfigFromGapicConfigOnly(simpleMethod.getModel(), diagCollector, lroConfigProtoWithPollSettings);
    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);
}
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) Test(org.junit.Test)

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