Search in sources :

Example 26 with Service

use of com.google.cloud.servicedirectory.v1.Service in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method listServicesTest2.

@Test
public void listServicesTest2() throws Exception {
    Service responsesElement = Service.newBuilder().build();
    ListServicesResponse expectedResponse = ListServicesResponse.newBuilder().setNextPageToken("").addAllServices(Arrays.asList(responsesElement)).build();
    mockServiceMonitoringService.addResponse(expectedResponse);
    OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    ListServicesPagedResponse pagedListResponse = client.listServices(parent);
    List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) ListServicesRequest(com.google.monitoring.v3.ListServicesRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListServicesResponse(com.google.monitoring.v3.ListServicesResponse) ListServicesPagedResponse(com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServicesPagedResponse) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) Test(org.junit.Test)

Example 27 with Service

use of com.google.cloud.servicedirectory.v1.Service in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method listServicesTest4.

@Test
public void listServicesTest4() throws Exception {
    Service responsesElement = Service.newBuilder().build();
    ListServicesResponse expectedResponse = ListServicesResponse.newBuilder().setNextPageToken("").addAllServices(Arrays.asList(responsesElement)).build();
    mockServiceMonitoringService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListServicesPagedResponse pagedListResponse = client.listServices(parent);
    List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListServicesRequest(com.google.monitoring.v3.ListServicesRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListServicesResponse(com.google.monitoring.v3.ListServicesResponse) ListServicesPagedResponse(com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServicesPagedResponse) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) Test(org.junit.Test)

Example 28 with Service

use of com.google.cloud.servicedirectory.v1.Service in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method createServiceTest3.

@Test
public void createServiceTest3() throws Exception {
    Service expectedResponse = Service.newBuilder().setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()).setDisplayName("displayName1714148973").setTelemetry(Service.Telemetry.newBuilder().build()).putAllUserLabels(new HashMap<String, String>()).build();
    mockServiceMonitoringService.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    Service service = Service.newBuilder().build();
    Service actualResponse = client.createService(parent, service);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateServiceRequest actualRequest = ((CreateServiceRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(service, actualRequest.getService());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ProjectName(com.google.monitoring.v3.ProjectName) CreateServiceRequest(com.google.monitoring.v3.CreateServiceRequest) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) Test(org.junit.Test)

Example 29 with Service

use of com.google.cloud.servicedirectory.v1.Service in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method updateServiceTest.

@Test
public void updateServiceTest() throws Exception {
    Service expectedResponse = Service.newBuilder().setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()).setDisplayName("displayName1714148973").setTelemetry(Service.Telemetry.newBuilder().build()).putAllUserLabels(new HashMap<String, String>()).build();
    mockServiceMonitoringService.addResponse(expectedResponse);
    Service service = Service.newBuilder().build();
    Service actualResponse = client.updateService(service);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateServiceRequest actualRequest = ((UpdateServiceRequest) actualRequests.get(0));
    Assert.assertEquals(service, actualRequest.getService());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) UpdateServiceRequest(com.google.monitoring.v3.UpdateServiceRequest) Test(org.junit.Test)

Example 30 with Service

use of com.google.cloud.servicedirectory.v1.Service in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method updateServiceExceptionTest.

@Test
public void updateServiceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        Service service = Service.newBuilder().build();
        client.updateService(service);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) Test(org.junit.Test)

Aggregations

Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)22 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)22 Test (org.junit.Test)19 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)18 CoreException (org.eclipse.core.runtime.CoreException)18 Service (io.fabric8.knative.serving.v1.Service)17 Service (com.google.monitoring.v3.Service)16 Test (org.junit.jupiter.api.Test)15 AbstractMessage (com.google.protobuf.AbstractMessage)14 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 ServerPort (org.eclipse.wst.server.core.ServerPort)9 ServiceBuilder (io.fabric8.knative.serving.v1.ServiceBuilder)8 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 ListServicesPagedResponse (com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServicesPagedResponse)4 CreateServiceRequest (com.google.monitoring.v3.CreateServiceRequest)4 ListServicesRequest (com.google.monitoring.v3.ListServicesRequest)4 ListServicesResponse (com.google.monitoring.v3.ListServicesResponse)4