Search in sources :

Example 1 with BillingAccountName

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

the class ConfigClientTest method listExclusionsExceptionTest.

@Test
public void listExclusionsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
        client.listExclusions(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)

Example 2 with BillingAccountName

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

the class ConfigClientTest method listSinksTest.

@Test
public void listSinksTest() throws Exception {
    LogSink responsesElement = LogSink.newBuilder().build();
    ListSinksResponse expectedResponse = ListSinksResponse.newBuilder().setNextPageToken("").addAllSinks(Arrays.asList(responsesElement)).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
    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) BillingAccountName(com.google.logging.v2.BillingAccountName) ListSinksRequest(com.google.logging.v2.ListSinksRequest) Test(org.junit.Test)

Example 3 with BillingAccountName

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

the class ConfigClientTest method createExclusionTest.

@Test
public void createExclusionTest() throws Exception {
    LogExclusion expectedResponse = LogExclusion.newBuilder().setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()).setDescription("description-1724546052").setFilter("filter-1274492040").setDisabled(true).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
    LogExclusion exclusion = LogExclusion.newBuilder().build();
    LogExclusion actualResponse = client.createExclusion(parent, exclusion);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateExclusionRequest actualRequest = ((CreateExclusionRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(exclusion, actualRequest.getExclusion());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateExclusionRequest(com.google.logging.v2.CreateExclusionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) BillingAccountName(com.google.logging.v2.BillingAccountName) LogExclusion(com.google.logging.v2.LogExclusion) Test(org.junit.Test)

Example 4 with BillingAccountName

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

the class ConfigClientTest method createSinkTest.

@Test
public void createSinkTest() throws Exception {
    LogSink expectedResponse = LogSink.newBuilder().setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()).setDestination("destination-1429847026").setFilter("filter-1274492040").setDescription("description-1724546052").setDisabled(true).addAllExclusions(new ArrayList<LogExclusion>()).setWriterIdentity("writerIdentity925193809").setIncludeChildren(true).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
    LogSink sink = LogSink.newBuilder().build();
    LogSink actualResponse = client.createSink(parent, sink);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSinkRequest actualRequest = ((CreateSinkRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(sink, actualRequest.getSink());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : LogSink(com.google.logging.v2.LogSink) AbstractMessage(com.google.protobuf.AbstractMessage) BillingAccountName(com.google.logging.v2.BillingAccountName) ArrayList(java.util.ArrayList) CreateSinkRequest(com.google.logging.v2.CreateSinkRequest) Test(org.junit.Test)

Example 5 with BillingAccountName

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

the class ConfigClientTest method listSinksExceptionTest.

@Test
public void listSinksExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
        client.listSinks(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