Search in sources :

Example 46 with MethodModel

use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.

the class GoGapicSurfaceTransformerTest method testGetImportsNotLro.

@Test
public void testGetImportsNotLro() {
    MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "NotLroMethod"));
    transformer.addXApiImports(context, Collections.singletonList(method));
    Truth.assertThat(context.getImportTypeTable().getImports()).doesNotContainKey("cloud.google.com/go/longrunning");
}
Also used : ProtoMethodModel(com.google.api.codegen.config.ProtoMethodModel) MethodModel(com.google.api.codegen.config.MethodModel) ProtoMethodModel(com.google.api.codegen.config.ProtoMethodModel) Test(org.junit.Test)

Example 47 with MethodModel

use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.

the class GoGapicSurfaceTransformerTest method testGetImportsPlain.

@Test
public void testGetImportsPlain() {
    MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "SimpleMethod"));
    transformer.addXApiImports(context, Collections.singletonList(method));
    transformer.generateRetryConfigDefinitions(context, Collections.singletonList(method));
    Truth.assertThat(context.getImportTypeTable().getImports()).doesNotContainKey("time");
    Truth.assertThat(context.getImportTypeTable().getImports()).doesNotContainKey("cloud.google.com/go/longrunning");
}
Also used : ProtoMethodModel(com.google.api.codegen.config.ProtoMethodModel) MethodModel(com.google.api.codegen.config.MethodModel) ProtoMethodModel(com.google.api.codegen.config.ProtoMethodModel) Test(org.junit.Test)

Example 48 with MethodModel

use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.

the class GoGapicSurfaceTransformerTest method testGetImportsLro.

@Test
public void testGetImportsLro() {
    MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "LroMethod"));
    transformer.addXApiImports(context, Collections.singletonList(method));
    transformer.generateRetryConfigDefinitions(context, Collections.singletonList(method));
    Truth.assertThat(context.getImportTypeTable().getImports()).doesNotContainKey("math");
    Truth.assertThat(context.getImportTypeTable().getImports()).containsKey("cloud.google.com/go/longrunning");
}
Also used : ProtoMethodModel(com.google.api.codegen.config.ProtoMethodModel) MethodModel(com.google.api.codegen.config.MethodModel) ProtoMethodModel(com.google.api.codegen.config.ProtoMethodModel) Test(org.junit.Test)

Example 49 with MethodModel

use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.

the class RubySurfaceNamerTest method getApiMethodName.

@Test
public void getApiMethodName() {
    RubySurfaceNamer namer = new RubySurfaceNamer("Unused::Package::Name");
    MethodModel method = Mockito.mock(MethodModel.class);
    Mockito.when(method.getSimpleName()).thenReturn("PrintHTML");
    Truth.assertThat(namer.getApiMethodName(method, VisibilityConfig.PUBLIC)).isEqualTo("print_html");
    Mockito.when(method.getSimpleName()).thenReturn("AMethod");
    Truth.assertThat(namer.getApiMethodName(method, VisibilityConfig.PUBLIC)).isEqualTo("a_method");
    Mockito.when(method.getSimpleName()).thenReturn("AnRpc");
    Truth.assertThat(namer.getApiMethodName(method, VisibilityConfig.PUBLIC)).isEqualTo("an_rpc");
    Mockito.when(method.getSimpleName()).thenReturn("SeeHTMLBooks");
    Truth.assertThat(namer.getApiMethodName(method, VisibilityConfig.PUBLIC)).isEqualTo("see_html_books");
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) Test(org.junit.Test)

Example 50 with MethodModel

use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.

the class ApiCallableTransformer method generateMethodDescriptor.

private MethodDescriptorView generateMethodDescriptor(MethodContext context) {
    ImportTypeTable typeTable = context.getTypeTable();
    MethodModel method = context.getMethodModel();
    MethodConfig methodConfig = context.getMethodConfig();
    SurfaceNamer namer = context.getNamer();
    MethodDescriptorView.Builder methodDescriptorBuilder = MethodDescriptorView.newBuilder();
    if (methodConfig.isGrpcStreaming()) {
        methodDescriptorBuilder.grpcStreamingType(methodConfig.getGrpcStreaming().getType());
    }
    methodDescriptorBuilder.requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer));
    methodDescriptorBuilder.responseTypeName(method.getAndSaveResponseTypeName(typeTable, namer));
    methodDescriptorBuilder.hasResponse(!method.isOutputTypeEmpty());
    methodDescriptorBuilder.name(namer.getMethodDescriptorName(method));
    methodDescriptorBuilder.protoMethodName(method.getSimpleName());
    methodDescriptorBuilder.fullServiceName(context.getTargetInterface().getFullName());
    methodDescriptorBuilder.transportSettingsVar(namer.getTransportSettingsVar(method));
    methodDescriptorBuilder.headerRequestParams(headerRequestParamTransformer.generateHeaderRequestParams(context));
    methodDescriptorBuilder.httpMethod(generateHttpFields(context));
    return methodDescriptorBuilder.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) MethodDescriptorView(com.google.api.codegen.viewmodel.MethodDescriptorView)

Aggregations

MethodModel (com.google.api.codegen.config.MethodModel)95 ArrayList (java.util.ArrayList)30 MethodConfig (com.google.api.codegen.config.MethodConfig)29 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)23 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)20 ImmutableList (com.google.common.collect.ImmutableList)16 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)14 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)14 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)12 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)11 FieldConfig (com.google.api.codegen.config.FieldConfig)11 ProtoMethodModel (com.google.api.codegen.config.ProtoMethodModel)9 Test (org.junit.Test)9 FieldModel (com.google.api.codegen.config.FieldModel)8 MethodContext (com.google.api.codegen.transformer.MethodContext)8 SymbolTable (com.google.api.codegen.util.SymbolTable)8 TypeModel (com.google.api.codegen.config.TypeModel)7 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)7 InterfaceModel (com.google.api.codegen.config.InterfaceModel)6 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)6