Search in sources :

Example 1 with WorkerPoolName

use of com.google.cloudbuild.v1.WorkerPoolName in project java-cloudbuild by googleapis.

the class CloudBuildClientTest method getWorkerPoolExceptionTest.

@Test
public void getWorkerPoolExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockCloudBuild.addException(exception);
    try {
        WorkerPoolName name = WorkerPoolName.of("[PROJECT]", "[LOCATION]", "[WORKER_POOL]");
        client.getWorkerPool(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : WorkerPoolName(com.google.cloudbuild.v1.WorkerPoolName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 2 with WorkerPoolName

use of com.google.cloudbuild.v1.WorkerPoolName in project java-cloudbuild by googleapis.

the class CloudBuildClientTest method deleteWorkerPoolTest.

@Test
public void deleteWorkerPoolTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    Operation resultOperation = Operation.newBuilder().setName("deleteWorkerPoolTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockCloudBuild.addResponse(resultOperation);
    WorkerPoolName name = WorkerPoolName.of("[PROJECT]", "[LOCATION]", "[WORKER_POOL]");
    client.deleteWorkerPoolAsync(name).get();
    List<AbstractMessage> actualRequests = mockCloudBuild.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteWorkerPoolRequest actualRequest = ((DeleteWorkerPoolRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) WorkerPoolName(com.google.cloudbuild.v1.WorkerPoolName) AbstractMessage(com.google.protobuf.AbstractMessage) Operation(com.google.longrunning.Operation) DeleteWorkerPoolRequest(com.google.cloudbuild.v1.DeleteWorkerPoolRequest) Test(org.junit.Test)

Example 3 with WorkerPoolName

use of com.google.cloudbuild.v1.WorkerPoolName in project java-cloudbuild by googleapis.

the class CloudBuildClientTest method deleteWorkerPoolExceptionTest.

@Test
public void deleteWorkerPoolExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockCloudBuild.addException(exception);
    try {
        WorkerPoolName name = WorkerPoolName.of("[PROJECT]", "[LOCATION]", "[WORKER_POOL]");
        client.deleteWorkerPoolAsync(name).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : WorkerPoolName(com.google.cloudbuild.v1.WorkerPoolName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with WorkerPoolName

use of com.google.cloudbuild.v1.WorkerPoolName in project java-cloudbuild by googleapis.

the class CloudBuildClientTest method getWorkerPoolTest.

@Test
public void getWorkerPoolTest() throws Exception {
    WorkerPool expectedResponse = WorkerPool.newBuilder().setName(WorkerPoolName.of("[PROJECT]", "[LOCATION]", "[WORKER_POOL]").toString()).setDisplayName("displayName1714148973").setUid("uid115792").putAllAnnotations(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setDeleteTime(Timestamp.newBuilder().build()).setEtag("etag3123477").build();
    mockCloudBuild.addResponse(expectedResponse);
    WorkerPoolName name = WorkerPoolName.of("[PROJECT]", "[LOCATION]", "[WORKER_POOL]");
    WorkerPool actualResponse = client.getWorkerPool(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockCloudBuild.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetWorkerPoolRequest actualRequest = ((GetWorkerPoolRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : WorkerPool(com.google.cloudbuild.v1.WorkerPool) WorkerPoolName(com.google.cloudbuild.v1.WorkerPoolName) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) GetWorkerPoolRequest(com.google.cloudbuild.v1.GetWorkerPoolRequest) Test(org.junit.Test)

Aggregations

WorkerPoolName (com.google.cloudbuild.v1.WorkerPoolName)4 Test (org.junit.Test)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 DeleteWorkerPoolRequest (com.google.cloudbuild.v1.DeleteWorkerPoolRequest)1 GetWorkerPoolRequest (com.google.cloudbuild.v1.GetWorkerPoolRequest)1 WorkerPool (com.google.cloudbuild.v1.WorkerPool)1 Operation (com.google.longrunning.Operation)1 Empty (com.google.protobuf.Empty)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1