Search in sources :

Example 1 with FolderName

use of com.google.monitoring.v3.FolderName in project java-logging by googleapis.

the class ConfigClientTest method createSinkExceptionTest2.

@Test
public void createSinkExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        FolderName parent = FolderName.of("[FOLDER]");
        LogSink sink = LogSink.newBuilder().build();
        client.createSink(parent, sink);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : LogSink(com.google.logging.v2.LogSink) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) FolderName(com.google.logging.v2.FolderName) Test(org.junit.Test)

Example 2 with FolderName

use of com.google.monitoring.v3.FolderName in project java-logging by googleapis.

the class LoggingClientTest method listLogsExceptionTest2.

@Test
public void listLogsExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockLoggingServiceV2.addException(exception);
    try {
        FolderName parent = FolderName.of("[FOLDER]");
        client.listLogs(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) FolderName(com.google.logging.v2.FolderName) Test(org.junit.Test)

Example 3 with FolderName

use of com.google.monitoring.v3.FolderName in project java-logging by googleapis.

the class ConfigClientTest method listSinksTest2.

@Test
public void listSinksTest2() throws Exception {
    LogSink responsesElement = LogSink.newBuilder().build();
    ListSinksResponse expectedResponse = ListSinksResponse.newBuilder().setNextPageToken("").addAllSinks(Arrays.asList(responsesElement)).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    FolderName parent = FolderName.of("[FOLDER]");
    ListSinksPagedResponse pagedListResponse = client.listSinks(parent);
    List<LogSink> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSinksList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSinksRequest actualRequest = ((ListSinksRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : LogSink(com.google.logging.v2.LogSink) ListSinksResponse(com.google.logging.v2.ListSinksResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListSinksPagedResponse(com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse) ListSinksRequest(com.google.logging.v2.ListSinksRequest) FolderName(com.google.logging.v2.FolderName) Test(org.junit.Test)

Example 4 with FolderName

use of com.google.monitoring.v3.FolderName in project java-logging by googleapis.

the class ConfigClientTest method listExclusionsTest2.

@Test
public void listExclusionsTest2() throws Exception {
    LogExclusion responsesElement = LogExclusion.newBuilder().build();
    ListExclusionsResponse expectedResponse = ListExclusionsResponse.newBuilder().setNextPageToken("").addAllExclusions(Arrays.asList(responsesElement)).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    FolderName parent = FolderName.of("[FOLDER]");
    ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent);
    List<LogExclusion> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListExclusionsRequest(com.google.logging.v2.ListExclusionsRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListExclusionsResponse(com.google.logging.v2.ListExclusionsResponse) LogExclusion(com.google.logging.v2.LogExclusion) FolderName(com.google.logging.v2.FolderName) ListExclusionsPagedResponse(com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse) Test(org.junit.Test)

Example 5 with FolderName

use of com.google.monitoring.v3.FolderName in project java-monitoring by googleapis.

the class GroupServiceClientTest method listGroupsExceptionTest.

@Test
public void listGroupsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockGroupService.addException(exception);
    try {
        FolderName name = FolderName.of("[FOLDER]");
        client.listGroups(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)40 FolderName (com.google.monitoring.v3.FolderName)30 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)20 AbstractMessage (com.google.protobuf.AbstractMessage)20 StatusRuntimeException (io.grpc.StatusRuntimeException)20 FolderName (com.google.logging.v2.FolderName)10 ArrayList (java.util.ArrayList)5 MetricDescriptor (com.google.api.MetricDescriptor)3 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)3 LogExclusion (com.google.logging.v2.LogExclusion)3 LogSink (com.google.logging.v2.LogSink)3 AlertPolicy (com.google.monitoring.v3.AlertPolicy)3 Group (com.google.monitoring.v3.Group)3 NotificationChannel (com.google.monitoring.v3.NotificationChannel)3 Service (com.google.monitoring.v3.Service)3 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)2 UptimeCheckConfig (com.google.monitoring.v3.UptimeCheckConfig)2 HashMap (java.util.HashMap)2 MonitoredResourceDescriptor (com.google.api.MonitoredResourceDescriptor)1 ListExclusionsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse)1