Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Revert a bunch of merge collateral damage #407

Merged
merged 1 commit into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main/resources/com/google/api/codegen/java/main.snip
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
@join commentLine : apiMethodDoc.mainDocLines
{@""} * {@commentLine}
{@""} * {@commentLine}
@end
*
* Sample code:
Expand All @@ -368,7 +368,7 @@
* </code></pre>
@if apiMethodDoc.paramDocs
{@""} *
@join doc : apiMethodDoc.paramDocs
@join doc : apiMethodDoc.paramDocs
{@paramDoc(doc)}
@end
@end
Expand Down Expand Up @@ -406,5 +406,13 @@
@end

@private pathTemplateCheckLine(pathTemplateCheck)
{@pathTemplateCheck.pathTemplateName}.validate({@pathTemplateCheck.paramName}, "{@pathTemplateCheck.validationMessageContext}");
@if pathTemplateCheck.allowEmptyString
if (!{@pathTemplateCheck.paramName}.isEmpty()) {
{@pathTemplateCheck.pathTemplateName}.validate({@pathTemplateCheck.paramName}, \
"{@pathTemplateCheck.validationMessageContext}");
}
@else
{@pathTemplateCheck.pathTemplateName}.validate({@pathTemplateCheck.paramName}, \
"{@pathTemplateCheck.validationMessageContext}");
@end
@end
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
return serviceImpl.getRequests();
}

@@Override
public void setResponses(List<GeneratedMessage> responses) {
serviceImpl.setResponses(responses);
}

@@Override
public ServerServiceDefinition getServiceDefinition() {
return {@mockService.grpcContainerName}.bindService(serviceImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,41 @@

@@javax.annotation.Generated("by GAPIC")
public class {@mockServiceImpl.name} implements {@mockServiceImpl.grpcClassName} {
private ArrayList<GeneratedMessage> requests;
private ArrayList<GeneratedMessage> requests;
private Queue<GeneratedMessage> responses;

public {@mockServiceImpl.name}() {
requests = new ArrayList<>();
}
public {@mockServiceImpl.name}() {
requests = new ArrayList<>();
responses = new LinkedList<>();
}

public List<GeneratedMessage> getRequests() {
return requests;
}
public List<GeneratedMessage> getRequests() {
return requests;
}

public void reset() {
requests = new ArrayList<>();
}
public void setResponses(List<GeneratedMessage> responses) {
this.responses = Lists.newLinkedList(responses);
}

public void reset() {
requests = new ArrayList<>();
responses = new LinkedList<>();
}

@join method : mockServiceImpl.grpcMethods
{@grpcMethod(method)}
@join method : mockServiceImpl.grpcMethods
{@grpcMethod(method)}

@end
@end
}
@end

@private grpcMethod(method)
@@Override
@if method.isStreaming
public StreamObserver<{@method.requestTypeName}> {@method.name}(
StreamObserver<{@method.responseTypeName}> responseObserver) {
System.err.println("Streaming method is not supported.");
return null;
}
@else
public void {@method.name}({@method.requestTypeName} request,
StreamObserver<{@method.responseTypeName}> responseObserver) {
{@method.responseTypeName} response = ({@method.responseTypeName}) responses.remove();
requests.add(request);
responseObserver.onNext(response);
responseObserver.onCompleted();
}
@end
public void {@method.name}({@method.requestTypeName} request,
StreamObserver<{@method.responseTypeName}> responseObserver) {
{@method.responseTypeName} response = ({@method.responseTypeName}) responses.remove();
requests.add(request);
responseObserver.onNext(response);
responseObserver.onCompleted();
}
@end
33 changes: 25 additions & 8 deletions src/main/resources/com/google/api/codegen/java/test.snip
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,48 @@
@@Test
@@SuppressWarnings("all")
public void {@test.name}() {
{@setResponse(test.mockResponse)}

{@initCode(test.initCode)}
{@methodCall(test)}

List<GeneratedMessage> requests = serviceHelper.getService().getRequests();
Assert.assertEquals(1, requests.size());
{@test.requestTypeName} request = ({@test.requestTypeName})requests.get(0);
List<GeneratedMessage> actualRequests = serviceHelper.getService().getRequests();
Assert.assertEquals(1, actualRequests.size());
{@test.requestTypeName} actualRequest = ({@test.requestTypeName})actualRequests.get(0);

@join assert : test.asserts
Assert.assertEquals(request.{@assert.actualValueGetter}(), {@assert.expectedValueIdentifier});
Assert.assertEquals(actualRequest.{@assert.actualValueGetter}(), {@assert.expectedValueIdentifier});
@end
}
@end

@private setResponse(response)
{@initCode(response.initCode)}
List<GeneratedMessage> expectedResponses = new ArrayList<>();
expectedResponses.add(expectedResponse);
serviceHelper.getService().setResponses(expectedResponses);
@end

@private methodCall(test)
@switch test.methodType
@case "PagedFlattenedMethod"
PageAccessor<{@test.resourceTypeName}> response = api.{@test.surfaceMethodName}(\
PageAccessor<{@test.resourceTypeName}> pageAccessor = api.{@test.surfaceMethodName}(\
{@sampleMethodCallArgList(test.initCode.fieldSettings)});

// PageAccessor will not make actual request until it is being used.
// Add all the pages here in order to make grpc requests.
List<{@test.resourceTypeName}> resources = Lists.newArrayList(response.getPageValues());
List<{@test.resourceTypeName}> resources = Lists.newArrayList(pageAccessor.getPageValues());
Assert.assertEquals(0, resources.size());
@case "FlattenedMethod"
api.{@test.surfaceMethodName}(\
{@sampleMethodCallArgList(test.initCode.fieldSettings)});
@if test.hasReturnValue
{@test.responseTypeName} actualResponse =
api.{@test.surfaceMethodName}(\
{@sampleMethodCallArgList(test.initCode.fieldSettings)});
Assert.assertEquals(expectedResponse, actualResponse);
@else
api.{@test.surfaceMethodName}(\
{@sampleMethodCallArgList(test.initCode.fieldSettings)});
@end
@default
$unhandledCase: {@test.type}$
@end
Expand Down
Loading