Operation resultOperation = Operation.newBuilder() .setName("createInstanceTest") .setDone(true) .setResponse(Any.pack(expectedResponse)) .build(); mockBigtableInstanceAdmin.addResponse(resultOperation);
public Builder mergeFrom(com.google.longrunning.Operation other) { if (other == com.google.longrunning.Operation.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); } if (other.hasMetadata()) { mergeMetadata(other.getMetadata()); } if (other.getDone() != false) { setDone(other.getDone()); } switch (other.getResultCase()) { case ERROR: { mergeError(other.getError()); break; } case RESPONSE: { mergeResponse(other.getResponse()); break; } case RESULT_NOT_SET: { break; } } onChanged(); return this; }
public Builder mergeFrom(com.google.longrunning.Operation other) { if (other == com.google.longrunning.Operation.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); } if (other.hasMetadata()) { mergeMetadata(other.getMetadata()); } if (other.getDone() != false) { setDone(other.getDone()); } switch (other.getResultCase()) { case ERROR: { mergeError(other.getError()); break; } case RESPONSE: { mergeResponse(other.getResponse()); break; } case RESULT_NOT_SET: { break; } } onChanged(); return this; }
@Test @SuppressWarnings("all") public void listOperationsTest() { String nextPageToken = ""; Operation operationsElement = Operation.newBuilder().build(); List<Operation> operations = Arrays.asList(operationsElement); ListOperationsResponse expectedResponse = ListOperationsResponse.newBuilder() .setNextPageToken(nextPageToken) .addAllOperations(operations) .build(); mockOperations.addResponse(expectedResponse); String name = "name3373707"; String filter = "filter-1274492040"; ListOperationsPagedResponse pagedListResponse = client.listOperations(name, filter); List<Operation> resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getOperationsList().get(0), resources.get(0)); List<GeneratedMessageV3> actualRequests = mockOperations.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListOperationsRequest actualRequest = (ListOperationsRequest) actualRequests.get(0); Assert.assertEquals(name, actualRequest.getName()); Assert.assertEquals(filter, actualRequest.getFilter()); }
/** * <pre> * A list of operations that matches the specified filter in the request. * </pre> * * <code>repeated .google.longrunning.Operation operations = 1;</code> */ public Builder setOperations( int index, com.google.longrunning.Operation.Builder builderForValue) { if (operationsBuilder_ == null) { ensureOperationsIsMutable(); operations_.set(index, builderForValue.build()); onChanged(); } else { operationsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * A list of operations that matches the specified filter in the request. * </pre> * * <code>repeated .google.longrunning.Operation operations = 1;</code> */ public Builder addOperations( com.google.longrunning.Operation.Builder builderForValue) { if (operationsBuilder_ == null) { ensureOperationsIsMutable(); operations_.add(builderForValue.build()); onChanged(); } else { operationsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * <pre> * A list of operations that matches the specified filter in the request. * </pre> * * <code>repeated .google.longrunning.Operation operations = 1;</code> */ public Builder addOperations( int index, com.google.longrunning.Operation.Builder builderForValue) { if (operationsBuilder_ == null) { ensureOperationsIsMutable(); operations_.add(index, builderForValue.build()); onChanged(); } else { operationsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * A list of operations that matches the specified filter in the request. * </pre> * * <code>repeated .google.longrunning.Operation operations = 1;</code> */ public Builder addOperations( com.google.longrunning.Operation.Builder builderForValue) { if (operationsBuilder_ == null) { ensureOperationsIsMutable(); operations_.add(builderForValue.build()); onChanged(); } else { operationsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * <pre> * A list of operations that matches the specified filter in the request. * </pre> * * <code>repeated .google.longrunning.Operation operations = 1;</code> */ public Builder setOperations( int index, com.google.longrunning.Operation.Builder builderForValue) { if (operationsBuilder_ == null) { ensureOperationsIsMutable(); operations_.set(index, builderForValue.build()); onChanged(); } else { operationsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * A list of operations that matches the specified filter in the request. * </pre> * * <code>repeated .google.longrunning.Operation operations = 1;</code> */ public Builder addOperations( int index, com.google.longrunning.Operation.Builder builderForValue) { if (operationsBuilder_ == null) { ensureOperationsIsMutable(); operations_.add(index, builderForValue.build()); onChanged(); } else { operationsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
@Test public void testMetadataTransformer_mismatchedTypes() { thrown.expect(ApiException.class); thrown.expectMessage("Failed to unpack object"); MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class); Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build(); Status status = Status.newBuilder().setCode(Code.OK.value()).build(); OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create( Operation.newBuilder() .setMetadata(Any.pack(Color.getDefaultInstance())) .setError(status) .build()); Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney); } }
@Test @SuppressWarnings("all") public void getOperationTest() { String name2 = "name2-1052831874"; boolean done = true; Operation expectedResponse = Operation.newBuilder().setName(name2).setDone(done).build(); mockOperations.addResponse(expectedResponse); String name = "name3373707"; Operation actualResponse = client.getOperation(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockOperations.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetOperationRequest actualRequest = (GetOperationRequest) actualRequests.get(0); Assert.assertEquals(name, actualRequest.getName()); }
@Test public void testResponseTransformer_mismatchedTypes() { thrown.expect(ApiException.class); thrown.expectMessage("Failed to unpack object"); ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class); Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build(); Status status = Status.newBuilder().setCode(Code.OK.value()).build(); OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create( Operation.newBuilder() .setResponse(Any.pack(Color.getDefaultInstance())) .setError(status) .build()); Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney); }
@Test public void testMetadataTransformer() { MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class); Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build(); OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create( Operation.newBuilder().setMetadata(Any.pack(inputMoney)).build()); Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney); }
@Override public ApiFuture<Operation> futureCall( GetOperationRequest request, ApiCallContext context) { if (!request.getName().equals("poseidon")) { return ApiFutures.immediateFailedFuture( new IllegalStateException("Unexpected request: " + request)); } else { return ApiFutures.immediateFuture( Operation.newBuilder().setName("greece").build()); } } });
@java.lang.Override protected Builder newBuilderForType( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**
@Test public void testResponseTransformer_exception() { thrown.expect(UnavailableException.class); ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class); Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build(); Status status = Status.newBuilder().setCode(Code.UNAVAILABLE.value()).build(); OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create( Operation.newBuilder().setResponse(Any.pack(inputMoney)).setError(status).build()); Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney); }
@Test public void testResponseTransformer() { ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class); Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build(); OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create( Operation.newBuilder().setResponse(Any.pack(inputMoney)).build()); Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney); }