Search in sources :

Example 6 with BillingAccountName

use of com.google.logging.v2.BillingAccountName in project java-logging by googleapis.

the class ConfigClientTest method createSinkExceptionTest.

@Test
public void createSinkExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
        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) BillingAccountName(com.google.logging.v2.BillingAccountName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 7 with BillingAccountName

use of com.google.logging.v2.BillingAccountName in project java-logging by googleapis.

the class ConfigClientTest method listExclusionsTest.

@Test
public void listExclusionsTest() throws Exception {
    LogExclusion responsesElement = LogExclusion.newBuilder().build();
    ListExclusionsResponse expectedResponse = ListExclusionsResponse.newBuilder().setNextPageToken("").addAllExclusions(Arrays.asList(responsesElement)).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
    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) BillingAccountName(com.google.logging.v2.BillingAccountName) LogExclusion(com.google.logging.v2.LogExclusion) ListExclusionsPagedResponse(com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse) Test(org.junit.Test)

Example 8 with BillingAccountName

use of com.google.logging.v2.BillingAccountName in project java-logging by googleapis.

the class ConfigClientTest method createExclusionExceptionTest.

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

Example 9 with BillingAccountName

use of com.google.logging.v2.BillingAccountName in project java-logging by googleapis.

the class LoggingClientTest method listLogsTest.

@Test
public void listLogsTest() throws Exception {
    String responsesElement = "responsesElement-318365110";
    ListLogsResponse expectedResponse = ListLogsResponse.newBuilder().setNextPageToken("").addAllLogNames(Arrays.asList(responsesElement)).build();
    mockLoggingServiceV2.addResponse(expectedResponse);
    BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
    ListLogsPagedResponse pagedListResponse = client.listLogs(parent);
    List<String> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getLogNamesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockLoggingServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListLogsRequest actualRequest = ((ListLogsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListLogsResponse(com.google.logging.v2.ListLogsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) BillingAccountName(com.google.logging.v2.BillingAccountName) ListLogsRequest(com.google.logging.v2.ListLogsRequest) ListLogsPagedResponse(com.google.cloud.logging.v2.LoggingClient.ListLogsPagedResponse) Test(org.junit.Test)

Example 10 with BillingAccountName

use of com.google.logging.v2.BillingAccountName in project java-logging by googleapis.

the class LoggingClientTest method listLogsExceptionTest.

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

Aggregations

BillingAccountName (com.google.logging.v2.BillingAccountName)10 Test (org.junit.Test)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 LogExclusion (com.google.logging.v2.LogExclusion)3 LogSink (com.google.logging.v2.LogSink)3 ListExclusionsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse)1 ListSinksPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse)1 ListLogsPagedResponse (com.google.cloud.logging.v2.LoggingClient.ListLogsPagedResponse)1 CreateExclusionRequest (com.google.logging.v2.CreateExclusionRequest)1 CreateSinkRequest (com.google.logging.v2.CreateSinkRequest)1 ListExclusionsRequest (com.google.logging.v2.ListExclusionsRequest)1 ListExclusionsResponse (com.google.logging.v2.ListExclusionsResponse)1 ListLogsRequest (com.google.logging.v2.ListLogsRequest)1 ListLogsResponse (com.google.logging.v2.ListLogsResponse)1 ListSinksRequest (com.google.logging.v2.ListSinksRequest)1 ListSinksResponse (com.google.logging.v2.ListSinksResponse)1 ArrayList (java.util.ArrayList)1