Search in sources :

Example 1 with GetViewRequest

use of com.google.logging.v2.GetViewRequest in project gapic-generator-java by googleapis.

the class ConfigClientTest method getViewTest.

@Test
public void getViewTest() throws Exception {
    LogView expectedResponse = LogView.newBuilder().setName(LogViewName.ofProjectLocationBucketViewName("[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]").toString()).setDescription("description-1724546052").setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setFilter("filter-1274492040").build();
    mockConfigServiceV2.addResponse(expectedResponse);
    GetViewRequest request = GetViewRequest.newBuilder().setName(LogViewName.ofProjectLocationBucketViewName("[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]").toString()).build();
    LogView actualResponse = client.getView(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetViewRequest actualRequest = ((GetViewRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogView(com.google.logging.v2.LogView) GetViewRequest(com.google.logging.v2.GetViewRequest) Test(org.junit.Test)

Example 2 with GetViewRequest

use of com.google.logging.v2.GetViewRequest in project gapic-generator-java by googleapis.

the class AsyncGetView method asyncGetView.

public static void asyncGetView() throws Exception {
    // It may require modifications to work in your environment.
    try (ConfigClient configClient = ConfigClient.create()) {
        GetViewRequest request = GetViewRequest.newBuilder().setName(LogViewName.ofProjectLocationBucketViewName("[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]").toString()).build();
        ApiFuture<LogView> future = configClient.getViewCallable().futureCall(request);
        // Do something.
        LogView response = future.get();
    }
}
Also used : ConfigClient(com.google.cloud.logging.v2.ConfigClient) GetViewRequest(com.google.logging.v2.GetViewRequest) LogView(com.google.logging.v2.LogView)

Example 3 with GetViewRequest

use of com.google.logging.v2.GetViewRequest in project gapic-generator-java by googleapis.

the class SyncGetView method syncGetView.

public static void syncGetView() throws Exception {
    // It may require modifications to work in your environment.
    try (ConfigClient configClient = ConfigClient.create()) {
        GetViewRequest request = GetViewRequest.newBuilder().setName(LogViewName.ofProjectLocationBucketViewName("[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]").toString()).build();
        LogView response = configClient.getView(request);
    }
}
Also used : ConfigClient(com.google.cloud.logging.v2.ConfigClient) GetViewRequest(com.google.logging.v2.GetViewRequest) LogView(com.google.logging.v2.LogView)

Example 4 with GetViewRequest

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

the class ConfigClientTest method getViewTest.

@Test
public void getViewTest() throws Exception {
    LogView expectedResponse = LogView.newBuilder().setName(LogViewName.ofProjectLocationBucketViewName("[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]").toString()).setDescription("description-1724546052").setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setFilter("filter-1274492040").build();
    mockConfigServiceV2.addResponse(expectedResponse);
    GetViewRequest request = GetViewRequest.newBuilder().setName(LogViewName.ofProjectLocationBucketViewName("[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]").toString()).build();
    LogView actualResponse = client.getView(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetViewRequest actualRequest = ((GetViewRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogView(com.google.logging.v2.LogView) GetViewRequest(com.google.logging.v2.GetViewRequest) Test(org.junit.Test)

Example 5 with GetViewRequest

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

the class ConfigClientTest method getViewExceptionTest.

@Test
public void getViewExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        GetViewRequest request = GetViewRequest.newBuilder().setName(LogViewName.ofProjectLocationBucketViewName("[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]").toString()).build();
        client.getView(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) GetViewRequest(com.google.logging.v2.GetViewRequest) Test(org.junit.Test)

Aggregations

GetViewRequest (com.google.logging.v2.GetViewRequest)6 LogView (com.google.logging.v2.LogView)4 Test (org.junit.Test)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 ConfigClient (com.google.cloud.logging.v2.ConfigClient)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2