use of com.google.api.generator.gapic.model.MethodArgument in project gapic-generator-java by googleapis.
the class MethodSignatureParserTest method flattenMethodSignatures_basic.
@Test
public void flattenMethodSignatures_basic() {
String fooName = "fooName";
TypeNode fooTypeOne = TypeNode.withReference(VaporReference.builder().setName("FooName").setPakkage("com.google.foobar").build());
TypeNode fooTypeTwo = TypeNode.withReference(VaporReference.builder().setName("FooTwoName").setPakkage("com.google.foobar").build());
List<String> argumentNames = Arrays.asList(fooName);
BiFunction<String, TypeNode, MethodArgument> methodArgFn = (name, type) -> MethodArgument.builder().setName(name).setType(type).setField(Field.builder().setName(name).setType(type).build()).build();
List<MethodArgument> fooArgs = Arrays.asList(TypeNode.STRING, fooTypeOne, fooTypeTwo).stream().map(t -> methodArgFn.apply(fooName, t)).collect(Collectors.toList());
Map<String, List<MethodArgument>> argumentNameToOverloads = new HashMap<>();
argumentNameToOverloads.put(fooName, fooArgs);
List<List<MethodArgument>> flattenedSignatures = MethodSignatureParser.flattenMethodSignatureVariants(argumentNames, argumentNameToOverloads);
assertEquals(3, flattenedSignatures.size());
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(TypeNode.STRING)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeOne)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeTwo)));
}
use of com.google.api.generator.gapic.model.MethodArgument in project gapic-generator-java by googleapis.
the class MethodSignatureParserTest method flattenMethodSignatures_manyToMany.
@Test
public void flattenMethodSignatures_manyToMany() {
String fooName = "fooName";
String barName = "barName";
String anInt = "anInt";
String anotherInt = "anotherInt";
TypeNode fooTypeOne = TypeNode.withReference(VaporReference.builder().setName("FooName").setPakkage("com.google.foobar").build());
TypeNode fooTypeTwo = TypeNode.withReference(VaporReference.builder().setName("FooTwoName").setPakkage("com.google.foobar").build());
TypeNode barTypeOne = TypeNode.withReference(VaporReference.builder().setName("BarName").setPakkage("com.google.foobar").build());
TypeNode barTypeTwo = TypeNode.withReference(VaporReference.builder().setName("BarTwoName").setPakkage("com.google.foobar").build());
TypeNode barTypeThree = TypeNode.withReference(VaporReference.builder().setName("BarCarName").setPakkage("com.google.foobar").build());
List<String> argumentNames = Arrays.asList(fooName, anInt, barName, anotherInt);
BiFunction<String, TypeNode, MethodArgument> methodArgFn = (name, type) -> MethodArgument.builder().setName(name).setType(type).setField(Field.builder().setName(name).setType(type).build()).build();
List<MethodArgument> fooArgs = Arrays.asList(TypeNode.STRING, fooTypeOne, fooTypeTwo).stream().map(t -> methodArgFn.apply(fooName, t)).collect(Collectors.toList());
List<MethodArgument> barArgs = Arrays.asList(TypeNode.STRING, barTypeOne, barTypeTwo, barTypeThree).stream().map(t -> methodArgFn.apply(barName, t)).collect(Collectors.toList());
Map<String, List<MethodArgument>> argumentNameToOverloads = new HashMap<>();
argumentNameToOverloads.put(fooName, fooArgs);
argumentNameToOverloads.put(anInt, Arrays.asList(methodArgFn.apply(anInt, TypeNode.INT)));
argumentNameToOverloads.put(barName, barArgs);
argumentNameToOverloads.put(anotherInt, Arrays.asList(methodArgFn.apply(anotherInt, TypeNode.INT)));
List<List<MethodArgument>> flattenedSignatures = MethodSignatureParser.flattenMethodSignatureVariants(argumentNames, argumentNameToOverloads);
assertEquals(12, flattenedSignatures.size());
// Types 0 - 4: String, int, {String, BarName, BarTwoName, BarCarName}, int.
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(TypeNode.STRING, TypeNode.INT, TypeNode.STRING, TypeNode.INT)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(TypeNode.STRING, TypeNode.INT, barTypeOne, TypeNode.INT)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(TypeNode.STRING, TypeNode.INT, barTypeTwo, TypeNode.INT)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(TypeNode.STRING, TypeNode.INT, barTypeThree, TypeNode.INT)));
// Types 5 - 8: FooName, int, {String, BarName, BarTwoName, BarCarName}, int.
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeOne, TypeNode.INT, TypeNode.STRING, TypeNode.INT)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeOne, TypeNode.INT, barTypeOne, TypeNode.INT)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeOne, TypeNode.INT, barTypeTwo, TypeNode.INT)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeOne, TypeNode.INT, barTypeThree, TypeNode.INT)));
// Types 9 - 12: FooTwoName, int, {String, BarName, BarTwoName, BarCarName}, int.
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeTwo, TypeNode.INT, TypeNode.STRING, TypeNode.INT)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeTwo, TypeNode.INT, barTypeOne, TypeNode.INT)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeTwo, TypeNode.INT, barTypeTwo, TypeNode.INT)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(fooTypeTwo, TypeNode.INT, barTypeThree, TypeNode.INT)));
}
use of com.google.api.generator.gapic.model.MethodArgument in project gapic-generator-java by googleapis.
the class MethodSignatureParserTest method flattenMethodSignatures_oneToMany.
@Test
public void flattenMethodSignatures_oneToMany() {
String fooName = "fooName";
String anInt = "anInt";
TypeNode fooTypeOne = TypeNode.withReference(VaporReference.builder().setName("FooName").setPakkage("com.google.foobar").build());
TypeNode fooTypeTwo = TypeNode.withReference(VaporReference.builder().setName("FooTwoName").setPakkage("com.google.foobar").build());
List<String> argumentNames = Arrays.asList(anInt, fooName);
BiFunction<String, TypeNode, MethodArgument> methodArgFn = (name, type) -> MethodArgument.builder().setName(name).setType(type).setField(Field.builder().setName(name).setType(type).build()).build();
List<MethodArgument> fooArgs = Arrays.asList(TypeNode.STRING, fooTypeOne, fooTypeTwo).stream().map(t -> methodArgFn.apply(fooName, t)).collect(Collectors.toList());
Map<String, List<MethodArgument>> argumentNameToOverloads = new HashMap<>();
argumentNameToOverloads.put(fooName, fooArgs);
argumentNameToOverloads.put(anInt, Arrays.asList(methodArgFn.apply(anInt, TypeNode.INT)));
List<List<MethodArgument>> flattenedSignatures = MethodSignatureParser.flattenMethodSignatureVariants(argumentNames, argumentNameToOverloads);
assertEquals(3, flattenedSignatures.size());
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(TypeNode.INT, TypeNode.STRING)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(TypeNode.INT, fooTypeOne)));
assertTrue(containsTypes(flattenedSignatures, Arrays.asList(TypeNode.INT, fooTypeTwo)));
}
use of com.google.api.generator.gapic.model.MethodArgument in project gapic-generator-java by googleapis.
the class ParserTest method parseMethodSignatures_basic.
@Test
public void parseMethodSignatures_basic() {
MethodDescriptor echoMethodDescriptor = echoService.getMethods().get(0);
TypeNode inputType = TypeParser.parseType(echoMethodDescriptor.getInputType());
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
Set<ResourceName> outputResourceNames = new HashSet<>();
List<List<MethodArgument>> methodSignatures = MethodSignatureParser.parseMethodSignatures(echoMethodDescriptor, ECHO_PACKAGE, inputType, messageTypes, resourceNames, outputResourceNames);
assertEquals(8, methodSignatures.size());
// Signature contents: [].
List<MethodArgument> methodArgs = methodSignatures.get(0);
assertEquals(Collections.emptyList(), methodArgs);
// Signature contents: ["parent"].
methodArgs = methodSignatures.get(1);
assertEquals(1, methodArgs.size());
MethodArgument argument = methodArgs.get(0);
TypeNode resourceNameType = TypeNode.withReference(ConcreteReference.withClazz(com.google.api.resourcenames.ResourceName.class));
assertMethodArgumentEquals("parent", resourceNameType, ImmutableList.of(), argument);
// Signature contents: ["error"].
methodArgs = methodSignatures.get(2);
assertEquals(1, methodArgs.size());
argument = methodArgs.get(0);
assertMethodArgumentEquals("error", TypeNode.withReference(createStatusReference()), ImmutableList.of(), argument);
// Signature contents: ["name"], resource helper variant.
methodArgs = methodSignatures.get(3);
assertEquals(1, methodArgs.size());
argument = methodArgs.get(0);
TypeNode foobarNameType = TypeNode.withReference(VaporReference.builder().setName("FoobarName").setPakkage(ECHO_PACKAGE).build());
assertMethodArgumentEquals("name", foobarNameType, ImmutableList.of(), argument);
// Signature contents: ["content"].
methodArgs = methodSignatures.get(4);
assertEquals(1, methodArgs.size());
argument = methodArgs.get(0);
assertMethodArgumentEquals("content", TypeNode.STRING, ImmutableList.of(), argument);
// Signature contents: ["name"], String variant.
methodArgs = methodSignatures.get(5);
assertEquals(1, methodArgs.size());
argument = methodArgs.get(0);
assertMethodArgumentEquals("name", TypeNode.STRING, ImmutableList.of(), argument);
// Signature contents: ["parent"], String variant.
methodArgs = methodSignatures.get(6);
assertEquals(1, methodArgs.size());
argument = methodArgs.get(0);
assertMethodArgumentEquals("parent", TypeNode.STRING, ImmutableList.of(), argument);
// Signature contents: ["content", "severity"].
methodArgs = methodSignatures.get(7);
assertEquals(2, methodArgs.size());
argument = methodArgs.get(0);
assertMethodArgumentEquals("content", TypeNode.STRING, ImmutableList.of(), argument);
argument = methodArgs.get(1);
assertMethodArgumentEquals("severity", TypeNode.withReference(VaporReference.builder().setName("Severity").setPakkage(ECHO_PACKAGE).build()), ImmutableList.of(), argument);
}
Aggregations