use of com.google.api.codegen.util.Scanner in project toolkit by googleapis.
the class OutputTransformerTest method testAccessorNewVariableFromScopeTable.
@Test
public void testAccessorNewVariableFromScopeTable() {
TypeModel oldVarTypeModel = mock(TypeModel.class);
assertThat(parent.put("old_var", oldVarTypeModel, "OldVarTypeName")).isTrue();
Scanner scanner = new Scanner("old_var");
when(namer.localVarName(Name.from("old_var"))).thenReturn("oldVar");
when(typeTable.getNicknameFor(oldVarTypeModel)).thenReturn("OldVarTypeName");
OutputView.VariableView variableView = accessorNewVariable(scanner, context, sampleContext, parent, "newVar", false);
assertThat(variableView.variable()).isEqualTo("oldVar");
assertThat(variableView.accessors()).isEmpty();
assertThat(parent.getTypeName("newVar")).isEqualTo("OldVarTypeName");
assertThat(parent.getTypeModel("newVar")).isEqualTo(oldVarTypeModel);
}
use of com.google.api.codegen.util.Scanner in project toolkit by googleapis.
the class OutputTransformerTest method testAccessorNewVariableResourceNameFromScopeTable.
@Test
public void testAccessorNewVariableResourceNameFromScopeTable() {
assertThat(parent.put("old_var", null, "ShelfBookName")).isTrue();
Scanner scanner = new Scanner("old_var");
when(namer.localVarName(Name.from("old_var"))).thenReturn("oldVar");
OutputView.VariableView variableView = accessorNewVariable(scanner, context, sampleContext, parent, "newVar", false);
assertThat(variableView.variable()).isEqualTo("oldVar");
assertThat(variableView.accessors()).isEmpty();
assertThat(parent.getTypeName("newVar")).isEqualTo("ShelfBookName");
assertThat(parent.getTypeModel("newVar")).isEqualTo(null);
}
use of com.google.api.codegen.util.Scanner in project toolkit by googleapis.
the class OutputTransformerTest method testAccessorNewVariableWithIndex.
@Test
public void testAccessorNewVariableWithIndex() {
Scanner scanner = new Scanner("old_var.property[0]");
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(namer.getFieldGetFunctionName(propertyFieldModel)).thenReturn("getProperty");
when(propertyTypeModel.isRepeated()).thenReturn(true);
TypeModel optionalPropertyTypeModel = mock(TypeModel.class);
when(propertyTypeModel.makeOptional()).thenReturn(optionalPropertyTypeModel);
when(typeTable.getNicknameFor(optionalPropertyTypeModel)).thenReturn("OptionalPropertyTypeName");
when(namer.getFieldAccessorName(propertyFieldModel)).thenReturn(".getProperty()");
when(namer.getIndexAccessorName(0)).thenReturn("[0]");
when(propertyFieldModel.getType()).thenReturn(propertyTypeModel);
OutputView.VariableView variableView = accessorNewVariable(scanner, context, sampleContext, parent, "newVar", false);
assertThat(variableView.variable()).isEqualTo("oldVar");
assertThat(variableView.accessors()).containsExactly(".getProperty()", "[0]").inOrder();
assertThat(parent.getTypeName("newVar")).isEqualTo("OptionalPropertyTypeName");
assertThat(parent.getTypeModel("newVar")).isEqualTo(optionalPropertyTypeModel);
}
use of com.google.api.codegen.util.Scanner in project toolkit by googleapis.
the class OutputTransformerTest method testAccessorNewVariablePageStreamingResponse.
@Test
public void testAccessorNewVariablePageStreamingResponse() {
Scanner scanner = new Scanner("$resp");
when(config.getPageStreaming()).thenReturn(pageStreamingConfig);
when(pageStreamingConfig.getResourcesFieldConfig()).thenReturn(resourceFieldConfig);
when(featureConfig.useResourceNameFormatOption(resourceFieldConfig)).thenReturn(false);
FieldModel fieldModel = mock(FieldModel.class);
when(resourceFieldConfig.getField()).thenReturn(fieldModel);
TypeModel typeModel = mock(TypeModel.class);
when(fieldModel.getType()).thenReturn(typeModel);
when(typeModel.makeOptional()).thenReturn(typeModel);
when(typeTable.getNicknameFor(typeModel)).thenReturn("TypeName");
OutputView.VariableView variableView = accessorNewVariable(scanner, context, sampleContext, parent, "newVar", false);
assertThat(variableView.variable()).isEqualTo("sampleResponseVarName");
assertThat(variableView.accessors()).isEmpty();
assertThat(parent.getTypeName("newVar")).isEqualTo("TypeName");
assertThat(parent.getTypeModel("newVar")).isEqualTo(typeModel);
}
use of com.google.api.codegen.util.Scanner in project toolkit by googleapis.
the class OutputTransformerTest method testAccessorNewVariableResponse.
@Test
public void testAccessorNewVariableResponse() {
Scanner scanner = new Scanner("$resp");
when(config.getPageStreaming()).thenReturn(null);
TypeModel typeModel = mock(TypeModel.class);
when(typeTable.getNicknameFor(typeModel)).thenReturn("TypeName");
when(model.getOutputType()).thenReturn(typeModel);
OutputView.VariableView variableView = accessorNewVariable(scanner, context, sampleContext, parent, "newVar", false);
assertThat(variableView.variable()).isEqualTo("sampleResponseVarName");
assertThat(variableView.accessors()).isEmpty();
assertThat(parent.getTypeName("newVar")).isEqualTo("TypeName");
assertThat(parent.getTypeModel("newVar")).isEqualTo(typeModel);
}
Aggregations