Search in sources :

Example 1 with SetLabelsRequest

use of com.google.container.v1.SetLabelsRequest in project java-container by googleapis.

the class ClusterManagerClientTest method setLabelsTest.

@Test
public void setLabelsTest() throws Exception {
    Operation expectedResponse = Operation.newBuilder().setName("name3373707").setZone("zone3744684").setDetail("detail-1335224239").setStatusMessage("statusMessage-958704715").setSelfLink("selfLink1191800166").setTargetLink("targetLink486368555").setLocation("location1901043637").setStartTime("startTime-2129294769").setEndTime("endTime-1607243192").setProgress(OperationProgress.newBuilder().build()).addAllClusterConditions(new ArrayList<StatusCondition>()).addAllNodepoolConditions(new ArrayList<StatusCondition>()).setError(Status.newBuilder().build()).build();
    mockClusterManager.addResponse(expectedResponse);
    SetLabelsRequest request = SetLabelsRequest.newBuilder().setProjectId("projectId-894832108").setZone("zone3744684").setClusterId("clusterId561939637").putAllResourceLabels(new HashMap<String, String>()).setLabelFingerprint("labelFingerprint379449680").setName("name3373707").build();
    Operation actualResponse = client.setLabels(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SetLabelsRequest actualRequest = ((SetLabelsRequest) actualRequests.get(0));
    Assert.assertEquals(request.getProjectId(), actualRequest.getProjectId());
    Assert.assertEquals(request.getZone(), actualRequest.getZone());
    Assert.assertEquals(request.getClusterId(), actualRequest.getClusterId());
    Assert.assertEquals(request.getResourceLabelsMap(), actualRequest.getResourceLabelsMap());
    Assert.assertEquals(request.getLabelFingerprint(), actualRequest.getLabelFingerprint());
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SetLabelsRequest(com.google.container.v1.SetLabelsRequest) Operation(com.google.container.v1.Operation) StatusCondition(com.google.container.v1.StatusCondition) Test(org.junit.Test)

Example 2 with SetLabelsRequest

use of com.google.container.v1.SetLabelsRequest in project java-container by googleapis.

the class ClusterManagerClientTest method setLabelsExceptionTest.

@Test
public void setLabelsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockClusterManager.addException(exception);
    try {
        SetLabelsRequest request = SetLabelsRequest.newBuilder().setProjectId("projectId-894832108").setZone("zone3744684").setClusterId("clusterId561939637").putAllResourceLabels(new HashMap<String, String>()).setLabelFingerprint("labelFingerprint379449680").setName("name3373707").build();
        client.setLabels(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) HashMap(java.util.HashMap) StatusRuntimeException(io.grpc.StatusRuntimeException) SetLabelsRequest(com.google.container.v1.SetLabelsRequest) Test(org.junit.Test)

Example 3 with SetLabelsRequest

use of com.google.container.v1.SetLabelsRequest in project java-container by googleapis.

the class ClusterManagerClientTest method setLabelsTest.

@Test
public void setLabelsTest() throws Exception {
    Operation expectedResponse = Operation.newBuilder().setName("name3373707").setZone("zone3744684").setDetail("detail-1335224239").setStatusMessage("statusMessage-958704715").setSelfLink("selfLink1191800166").setTargetLink("targetLink486368555").setLocation("location1901043637").setStartTime("startTime-2129294769").setEndTime("endTime-1607243192").setProgress(OperationProgress.newBuilder().build()).addAllClusterConditions(new ArrayList<StatusCondition>()).addAllNodepoolConditions(new ArrayList<StatusCondition>()).setError(Status.newBuilder().build()).build();
    mockClusterManager.addResponse(expectedResponse);
    String projectId = "projectId-894832108";
    String zone = "zone3744684";
    String clusterId = "clusterId561939637";
    Map<String, String> resourceLabels = new HashMap<>();
    String labelFingerprint = "labelFingerprint379449680";
    Operation actualResponse = client.setLabels(projectId, zone, clusterId, resourceLabels, labelFingerprint);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SetLabelsRequest actualRequest = ((SetLabelsRequest) actualRequests.get(0));
    Assert.assertEquals(projectId, actualRequest.getProjectId());
    Assert.assertEquals(zone, actualRequest.getZone());
    Assert.assertEquals(clusterId, actualRequest.getClusterId());
    Assert.assertEquals(resourceLabels, actualRequest.getResourceLabelsMap());
    Assert.assertEquals(labelFingerprint, actualRequest.getLabelFingerprint());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SetLabelsRequest(com.google.container.v1beta1.SetLabelsRequest) Operation(com.google.container.v1beta1.Operation) StatusCondition(com.google.container.v1beta1.StatusCondition) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)3 Test (org.junit.Test)3 SetLabelsRequest (com.google.container.v1.SetLabelsRequest)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ArrayList (java.util.ArrayList)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 Operation (com.google.container.v1.Operation)1 StatusCondition (com.google.container.v1.StatusCondition)1 Operation (com.google.container.v1beta1.Operation)1 SetLabelsRequest (com.google.container.v1beta1.SetLabelsRequest)1 StatusCondition (com.google.container.v1beta1.StatusCondition)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1