Search in sources :

Example 6 with ListExclusionsResponse

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

the class LoggingImplTest method testListExclusionNextPage.

@Test
public void testListExclusionNextPage() {
    EasyMock.replay(rpcFactoryMock);
    logging = options.getService();
    ListExclusionsRequest request1 = ListExclusionsRequest.newBuilder().setParent(PROJECT_PARENT).build();
    List<Exclusion> exclusionList1 = ImmutableList.of(Exclusion.of(EXCLUSION_NAME, EXCLUSION_FILTER));
    ListExclusionsResponse response1 = ListExclusionsResponse.newBuilder().setNextPageToken(CURSOR).addAllExclusions(Lists.transform(exclusionList1, Exclusion.TO_PROTOBUF_FUNCTION)).build();
    ListExclusionsRequest request2 = ListExclusionsRequest.newBuilder().setParent(PROJECT_PARENT).setPageToken(CURSOR).build();
    List<Exclusion> exclusionList2 = ImmutableList.of(Exclusion.of(EXCLUSION_NAME, EXCLUSION_FILTER));
    ListExclusionsResponse response2 = ListExclusionsResponse.newBuilder().setNextPageToken(NEXT_CURSOR).addAllExclusions(Lists.transform(exclusionList2, Exclusion.TO_PROTOBUF_FUNCTION)).build();
    ApiFuture<ListExclusionsResponse> futureResponse1 = ApiFutures.immediateFuture(response1);
    ApiFuture<ListExclusionsResponse> futureResponse2 = ApiFutures.immediateFuture(response2);
    EasyMock.expect(loggingRpcMock.list(request1)).andReturn(futureResponse1);
    EasyMock.expect(loggingRpcMock.list(request2)).andReturn(futureResponse2);
    EasyMock.replay(loggingRpcMock);
    Page<Exclusion> page = logging.listExclusions();
    assertEquals(CURSOR, page.getNextPageToken());
    assertArrayEquals(exclusionList1.toArray(), Iterables.toArray(page.getValues(), Exclusion.class));
    page = page.getNextPage();
    assertEquals(NEXT_CURSOR, page.getNextPageToken());
    assertArrayEquals(exclusionList2.toArray(), Iterables.toArray(page.getValues(), Exclusion.class));
}
Also used : ListExclusionsRequest(com.google.logging.v2.ListExclusionsRequest) ListExclusionsResponse(com.google.logging.v2.ListExclusionsResponse) LogExclusion(com.google.logging.v2.LogExclusion) Test(org.junit.Test)

Example 7 with ListExclusionsResponse

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

the class LoggingImplTest method testListExclusionEmpty.

@Test
public void testListExclusionEmpty() {
    EasyMock.replay(rpcFactoryMock);
    logging = options.getService();
    ListExclusionsRequest request = ListExclusionsRequest.newBuilder().setParent(PROJECT_PARENT).build();
    List<Exclusion> exclusionList = ImmutableList.of();
    ListExclusionsResponse response = ListExclusionsResponse.newBuilder().setNextPageToken("").addAllExclusions(Lists.transform(exclusionList, Exclusion.TO_PROTOBUF_FUNCTION)).build();
    ApiFuture<ListExclusionsResponse> futureResponse = ApiFutures.immediateFuture(response);
    EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
    EasyMock.replay(loggingRpcMock);
    Page<Exclusion> page = logging.listExclusions();
    assertNull(page.getNextPageToken());
    assertNull(page.getNextPage());
    assertArrayEquals(exclusionList.toArray(), Iterables.toArray(page.getValues(), Exclusion.class));
}
Also used : ListExclusionsRequest(com.google.logging.v2.ListExclusionsRequest) ListExclusionsResponse(com.google.logging.v2.ListExclusionsResponse) LogExclusion(com.google.logging.v2.LogExclusion) Test(org.junit.Test)

Example 8 with ListExclusionsResponse

use of com.google.logging.v2.ListExclusionsResponse 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 9 with ListExclusionsResponse

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

the class ConfigClientTest method listExclusionsTest3.

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

Example 10 with ListExclusionsResponse

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

the class ConfigClientTest method listExclusionsTest5.

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

Aggregations

ListExclusionsRequest (com.google.logging.v2.ListExclusionsRequest)14 ListExclusionsResponse (com.google.logging.v2.ListExclusionsResponse)14 LogExclusion (com.google.logging.v2.LogExclusion)13 Test (org.junit.Test)13 ListExclusionsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 AsyncPage (com.google.api.gax.paging.AsyncPage)1 ImmutableList (com.google.common.collect.ImmutableList)1 BillingAccountName (com.google.logging.v2.BillingAccountName)1 FolderName (com.google.logging.v2.FolderName)1 OrganizationName (com.google.logging.v2.OrganizationName)1 ProjectName (com.google.logging.v2.ProjectName)1