Search in sources :

Example 26 with TypeModel

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

the class NodeJSGapicSurfaceTransformer method createLongRunningDescriptors.

private List<LongRunningOperationDetailView> createLongRunningDescriptors(GapicInterfaceContext context) {
    List<LongRunningOperationDetailView> result = new ArrayList<>();
    for (MethodModel method : context.getLongRunningMethods()) {
        GapicMethodContext methodContext = context.asRequestMethodContext(method);
        LongRunningConfig lroConfig = methodContext.getLongRunningConfig();
        TypeModel returnType = lroConfig.getReturnType();
        TypeModel metadataType = lroConfig.getMetadataType();
        result.add(LongRunningOperationDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).constructorName("").clientReturnTypeName("").operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).isEmptyMetadata(lroConfig.getMetadataType().isEmptyType()).metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build());
    }
    return result;
}
Also used : LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) LongRunningConfig(com.google.api.codegen.config.LongRunningConfig) ArrayList(java.util.ArrayList) TypeModel(com.google.api.codegen.config.TypeModel)

Example 27 with TypeModel

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

the class PhpGapicSurfaceTransformer method createLongRunningDescriptors.

private List<LongRunningOperationDetailView> createLongRunningDescriptors(GapicInterfaceContext context) {
    List<LongRunningOperationDetailView> result = new ArrayList<>();
    for (MethodModel method : context.getLongRunningMethods()) {
        GapicMethodContext methodContext = context.asRequestMethodContext(method);
        LongRunningConfig lroConfig = methodContext.getLongRunningConfig();
        TypeModel returnType = lroConfig.getReturnType();
        TypeModel metadataType = lroConfig.getMetadataType();
        result.add(LongRunningOperationDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).transportMethodName(context.getNamer().getGrpcMethodName(method)).constructorName("").clientReturnTypeName("").operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).isEmptyMetadata(lroConfig.getMetadataType().isEmptyType()).metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build());
    }
    return result;
}
Also used : LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) LongRunningConfig(com.google.api.codegen.config.LongRunningConfig) ArrayList(java.util.ArrayList) TypeModel(com.google.api.codegen.config.TypeModel)

Example 28 with TypeModel

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

the class OutputTransformerTest method testScopeTableGetTypeModel.

@Test
public void testScopeTableGetTypeModel() {
    TypeModel stringTypeModel = ProtoTypeRef.create(TypeRef.fromPrimitiveName("string"));
    assertThat(parent.put("str", stringTypeModel, "String")).isTrue();
    assertThat(parent.getTypeModel("str")).isEqualTo(stringTypeModel);
    assertThat(parent.getTypeName("str")).isEqualTo("String");
    assertThat(parent.getTypeModel("book")).isNull();
    assertThat(parent.getTypeName("book")).isNull();
}
Also used : TypeModel(com.google.api.codegen.config.TypeModel) Test(org.junit.Test)

Example 29 with TypeModel

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

the class OutputTransformerTest method testAccessorNewVariableMapKeyUnquoatedStringFail.

@Test
public void testAccessorNewVariableMapKeyUnquoatedStringFail() {
    Scanner scanner = new Scanner("old_var.property{unquoted_string}");
    when(namer.localVarName(Name.from("old_var"))).thenReturn("oldVar");
    TypeModel oldVarTypeModel = mock(TypeModel.class);
    assertThat(parent.put("old_var", oldVarTypeModel, "OldVarType")).isTrue();
    when(oldVarTypeModel.isMessage()).thenReturn(true);
    when(oldVarTypeModel.isRepeated()).thenReturn(false);
    when(oldVarTypeModel.isMap()).thenReturn(false);
    FieldModel propertyFieldModel = mock(FieldModel.class);
    when(oldVarTypeModel.getField("property")).thenReturn(propertyFieldModel);
    TypeModel propertyTypeModel = mock(TypeModel.class);
    when(propertyFieldModel.getType()).thenReturn(propertyTypeModel);
    when(propertyTypeModel.isRepeated()).thenReturn(true);
    when(propertyTypeModel.isMap()).thenReturn(true);
    when(namer.getFieldGetFunctionName(propertyFieldModel)).thenReturn("getProperty");
    when(namer.getFieldAccessorName(propertyFieldModel)).thenReturn(".getProperty()");
    TypeModel stringTypeModel = ProtoTypeRef.create(TypeRef.fromPrimitiveName("string"));
    when(propertyTypeModel.getMapKeyType()).thenReturn(stringTypeModel);
    when(propertyTypeModel.getMapValueType()).thenReturn(stringTypeModel);
    try {
        accessorNewVariable(scanner, context, sampleContext, parent, "newVar", false);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage()).contains("expected string type for map key");
    }
}
Also used : Scanner(com.google.api.codegen.util.Scanner) TypeModel(com.google.api.codegen.config.TypeModel) FieldModel(com.google.api.codegen.config.FieldModel) Test(org.junit.Test)

Example 30 with TypeModel

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

the class OutputTransformerTest method testAccessorNewVariableScalarTypeForCollectionFail.

@Test
public void testAccessorNewVariableScalarTypeForCollectionFail() {
    TypeModel oldVarTypeModel = mock(TypeModel.class);
    assertThat(parent.put("old_var", oldVarTypeModel, "OldVarTypeName")).isTrue();
    Scanner scanner = new Scanner("old_var");
    when(oldVarTypeModel.isRepeated()).thenReturn(false);
    when(namer.localVarName(Name.from("old_var"))).thenReturn("oldVar");
    when(namer.getAndSaveTypeName(typeTable, oldVarTypeModel)).thenReturn("OldVarTypeName");
    try {
        OutputView.VariableView variableView = accessorNewVariable(scanner, context, sampleContext, parent, "newVar", true);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage()).contains("is not a repeated field");
    }
}
Also used : Scanner(com.google.api.codegen.util.Scanner) OutputView(com.google.api.codegen.viewmodel.OutputView) TypeModel(com.google.api.codegen.config.TypeModel) Test(org.junit.Test)

Aggregations

TypeModel (com.google.api.codegen.config.TypeModel)32 MethodModel (com.google.api.codegen.config.MethodModel)12 Test (org.junit.Test)12 Scanner (com.google.api.codegen.util.Scanner)10 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)10 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)10 OutputView (com.google.api.codegen.viewmodel.OutputView)8 FieldModel (com.google.api.codegen.config.FieldModel)7 ImmutableList (com.google.common.collect.ImmutableList)4 LongRunningConfig (com.google.api.codegen.config.LongRunningConfig)3 ArrayList (java.util.ArrayList)3 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)2 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)2 OutputTransformer (com.google.api.codegen.transformer.OutputTransformer)2 LongRunningOperationDetailView (com.google.api.codegen.viewmodel.LongRunningOperationDetailView)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HashSet (java.util.HashSet)2 OutputSpec (com.google.api.codegen.OutputSpec)1 SampleValueSet (com.google.api.codegen.SampleValueSet)1 FieldConfig (com.google.api.codegen.config.FieldConfig)1