Search in sources :

Example 26 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 27 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 28 with FolderName

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

the class ConfigClientTest method createExclusionTest2.

@Test
public void createExclusionTest2() 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);
    FolderName parent = FolderName.of("[FOLDER]");
    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) LogExclusion(com.google.logging.v2.LogExclusion) FolderName(com.google.logging.v2.FolderName) Test(org.junit.Test)

Example 29 with FolderName

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

the class ConfigClientTest method createExclusionExceptionTest2.

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

Example 30 with FolderName

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

the class LoggingClientTest method listLogsTest2.

@Test
public void listLogsTest2() throws Exception {
    String responsesElement = "responsesElement-318365110";
    ListLogsResponse expectedResponse = ListLogsResponse.newBuilder().setNextPageToken("").addAllLogNames(Arrays.asList(responsesElement)).build();
    mockLoggingServiceV2.addResponse(expectedResponse);
    FolderName parent = FolderName.of("[FOLDER]");
    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) ListLogsRequest(com.google.logging.v2.ListLogsRequest) ListLogsPagedResponse(com.google.cloud.logging.v2.LoggingClient.ListLogsPagedResponse) FolderName(com.google.logging.v2.FolderName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)50 FolderName (com.google.monitoring.v3.FolderName)30 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)25 AbstractMessage (com.google.protobuf.AbstractMessage)25 StatusRuntimeException (io.grpc.StatusRuntimeException)25 FolderName (com.google.logging.v2.FolderName)22 LogExclusion (com.google.logging.v2.LogExclusion)7 LogSink (com.google.logging.v2.LogSink)7 ArrayList (java.util.ArrayList)6 MetricDescriptor (com.google.api.MetricDescriptor)3 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)3 AlertPolicy (com.google.monitoring.v3.AlertPolicy)3 Group (com.google.monitoring.v3.Group)3 ConfigClient (com.google.cloud.logging.v2.ConfigClient)2 ListExclusionsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse)2 ListSinksPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse)2 ListLogsPagedResponse (com.google.cloud.logging.v2.LoggingClient.ListLogsPagedResponse)2 CreateExclusionRequest (com.google.logging.v2.CreateExclusionRequest)2 CreateSinkRequest (com.google.logging.v2.CreateSinkRequest)2 ListExclusionsRequest (com.google.logging.v2.ListExclusionsRequest)2