Search in sources :

Example 1 with CreateViewRequest

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

the class ConfigClientTest method createViewTest.

@Test
public void createViewTest() 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);
    CreateViewRequest request = CreateViewRequest.newBuilder().setParent("parent-995424086").setViewId("viewId-816632160").setView(LogView.newBuilder().build()).build();
    LogView actualResponse = client.createView(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateViewRequest actualRequest = ((CreateViewRequest) actualRequests.get(0));
    Assert.assertEquals(request.getParent(), actualRequest.getParent());
    Assert.assertEquals(request.getViewId(), actualRequest.getViewId());
    Assert.assertEquals(request.getView(), actualRequest.getView());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogView(com.google.logging.v2.LogView) CreateViewRequest(com.google.logging.v2.CreateViewRequest) Test(org.junit.Test)

Example 2 with CreateViewRequest

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

the class AsyncCreateView method asyncCreateView.

public static void asyncCreateView() throws Exception {
    // It may require modifications to work in your environment.
    try (ConfigClient configClient = ConfigClient.create()) {
        CreateViewRequest request = CreateViewRequest.newBuilder().setParent("parent-995424086").setViewId("viewId-816632160").setView(LogView.newBuilder().build()).build();
        ApiFuture<LogView> future = configClient.createViewCallable().futureCall(request);
        // Do something.
        LogView response = future.get();
    }
}
Also used : ConfigClient(com.google.cloud.logging.v2.ConfigClient) CreateViewRequest(com.google.logging.v2.CreateViewRequest) LogView(com.google.logging.v2.LogView)

Example 3 with CreateViewRequest

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

the class SyncCreateView method syncCreateView.

public static void syncCreateView() throws Exception {
    // It may require modifications to work in your environment.
    try (ConfigClient configClient = ConfigClient.create()) {
        CreateViewRequest request = CreateViewRequest.newBuilder().setParent("parent-995424086").setViewId("viewId-816632160").setView(LogView.newBuilder().build()).build();
        LogView response = configClient.createView(request);
    }
}
Also used : ConfigClient(com.google.cloud.logging.v2.ConfigClient) CreateViewRequest(com.google.logging.v2.CreateViewRequest) LogView(com.google.logging.v2.LogView)

Example 4 with CreateViewRequest

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

the class ConfigClientTest method createViewTest.

@Test
public void createViewTest() 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);
    CreateViewRequest request = CreateViewRequest.newBuilder().setParent("parent-995424086").setViewId("viewId-816632160").setView(LogView.newBuilder().build()).build();
    LogView actualResponse = client.createView(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateViewRequest actualRequest = ((CreateViewRequest) actualRequests.get(0));
    Assert.assertEquals(request.getParent(), actualRequest.getParent());
    Assert.assertEquals(request.getViewId(), actualRequest.getViewId());
    Assert.assertEquals(request.getView(), actualRequest.getView());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogView(com.google.logging.v2.LogView) CreateViewRequest(com.google.logging.v2.CreateViewRequest) Test(org.junit.Test)

Example 5 with CreateViewRequest

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

the class ConfigClientTest method createViewExceptionTest.

@Test
public void createViewExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        CreateViewRequest request = CreateViewRequest.newBuilder().setParent("parent-995424086").setViewId("viewId-816632160").setView(LogView.newBuilder().build()).build();
        client.createView(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) CreateViewRequest(com.google.logging.v2.CreateViewRequest) Test(org.junit.Test)

Aggregations

CreateViewRequest (com.google.logging.v2.CreateViewRequest)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