Search in sources :

Example 1 with WorkerPool

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

the class CloudBuildClientTest method listWorkerPoolsTest2.

@Test
public void listWorkerPoolsTest2() throws Exception {
    WorkerPool responsesElement = WorkerPool.newBuilder().build();
    ListWorkerPoolsResponse expectedResponse = ListWorkerPoolsResponse.newBuilder().setNextPageToken("").addAllWorkerPools(Arrays.asList(responsesElement)).build();
    mockCloudBuild.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListWorkerPoolsPagedResponse pagedListResponse = client.listWorkerPools(parent);
    List<WorkerPool> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getWorkerPoolsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockCloudBuild.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListWorkerPoolsRequest actualRequest = ((ListWorkerPoolsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListWorkerPoolsPagedResponse(com.google.cloud.devtools.cloudbuild.v1.CloudBuildClient.ListWorkerPoolsPagedResponse) WorkerPool(com.google.cloudbuild.v1.WorkerPool) AbstractMessage(com.google.protobuf.AbstractMessage) ListWorkerPoolsResponse(com.google.cloudbuild.v1.ListWorkerPoolsResponse) ListWorkerPoolsRequest(com.google.cloudbuild.v1.ListWorkerPoolsRequest) Test(org.junit.Test)

Example 2 with WorkerPool

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

the class CloudBuildClientTest method createWorkerPoolTest.

@Test
public void createWorkerPoolTest() 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();
    Operation resultOperation = Operation.newBuilder().setName("createWorkerPoolTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockCloudBuild.addResponse(resultOperation);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    WorkerPool workerPool = WorkerPool.newBuilder().build();
    String workerPoolId = "workerPoolId-46320779";
    WorkerPool actualResponse = client.createWorkerPoolAsync(parent, workerPool, workerPoolId).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockCloudBuild.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateWorkerPoolRequest actualRequest = ((CreateWorkerPoolRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(workerPool, actualRequest.getWorkerPool());
    Assert.assertEquals(workerPoolId, actualRequest.getWorkerPoolId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : WorkerPool(com.google.cloudbuild.v1.WorkerPool) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) Operation(com.google.longrunning.Operation) CreateWorkerPoolRequest(com.google.cloudbuild.v1.CreateWorkerPoolRequest) LocationName(com.google.cloudbuild.v1.LocationName) Test(org.junit.Test)

Example 3 with WorkerPool

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

the class CloudBuildClientTest method createWorkerPoolTest2.

@Test
public void createWorkerPoolTest2() 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();
    Operation resultOperation = Operation.newBuilder().setName("createWorkerPoolTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockCloudBuild.addResponse(resultOperation);
    String parent = "parent-995424086";
    WorkerPool workerPool = WorkerPool.newBuilder().build();
    String workerPoolId = "workerPoolId-46320779";
    WorkerPool actualResponse = client.createWorkerPoolAsync(parent, workerPool, workerPoolId).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockCloudBuild.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateWorkerPoolRequest actualRequest = ((CreateWorkerPoolRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(workerPool, actualRequest.getWorkerPool());
    Assert.assertEquals(workerPoolId, actualRequest.getWorkerPoolId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : WorkerPool(com.google.cloudbuild.v1.WorkerPool) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) Operation(com.google.longrunning.Operation) CreateWorkerPoolRequest(com.google.cloudbuild.v1.CreateWorkerPoolRequest) Test(org.junit.Test)

Example 4 with WorkerPool

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

the class CloudBuildClientTest method updateWorkerPoolExceptionTest.

@Test
public void updateWorkerPoolExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockCloudBuild.addException(exception);
    try {
        WorkerPool workerPool = WorkerPool.newBuilder().build();
        FieldMask updateMask = FieldMask.newBuilder().build();
        client.updateWorkerPoolAsync(workerPool, updateMask).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 : WorkerPool(com.google.cloudbuild.v1.WorkerPool) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 5 with WorkerPool

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

the class CloudBuildClientTest method createWorkerPoolExceptionTest2.

@Test
public void createWorkerPoolExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockCloudBuild.addException(exception);
    try {
        String parent = "parent-995424086";
        WorkerPool workerPool = WorkerPool.newBuilder().build();
        String workerPoolId = "workerPoolId-46320779";
        client.createWorkerPoolAsync(parent, workerPool, workerPoolId).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 : WorkerPool(com.google.cloudbuild.v1.WorkerPool) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

WorkerPool (com.google.cloudbuild.v1.WorkerPool)10 Test (org.junit.Test)10 AbstractMessage (com.google.protobuf.AbstractMessage)7 HashMap (java.util.HashMap)5 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)3 LocationName (com.google.cloudbuild.v1.LocationName)3 Operation (com.google.longrunning.Operation)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 ExecutionException (java.util.concurrent.ExecutionException)3 ListWorkerPoolsPagedResponse (com.google.cloud.devtools.cloudbuild.v1.CloudBuildClient.ListWorkerPoolsPagedResponse)2 CreateWorkerPoolRequest (com.google.cloudbuild.v1.CreateWorkerPoolRequest)2 GetWorkerPoolRequest (com.google.cloudbuild.v1.GetWorkerPoolRequest)2 ListWorkerPoolsRequest (com.google.cloudbuild.v1.ListWorkerPoolsRequest)2 ListWorkerPoolsResponse (com.google.cloudbuild.v1.ListWorkerPoolsResponse)2 FieldMask (com.google.protobuf.FieldMask)2 UpdateWorkerPoolRequest (com.google.cloudbuild.v1.UpdateWorkerPoolRequest)1 WorkerPoolName (com.google.cloudbuild.v1.WorkerPoolName)1