Search in sources :

Example 1 with LogNameOneof

use of com.google.logging.v2.LogNameOneof in project google-cloud-java by GoogleCloudPlatform.

the class LoggingClientTest method deleteLogTest.

@Test
@SuppressWarnings("all")
public void deleteLogTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockLoggingServiceV2.addResponse(expectedResponse);
    LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
    client.deleteLog(logName);
    List<GeneratedMessageV3> actualRequests = mockLoggingServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteLogRequest actualRequest = (DeleteLogRequest) actualRequests.get(0);
    Assert.assertEquals(logName, actualRequest.getLogNameAsLogNameOneof());
}
Also used : DeleteLogRequest(com.google.logging.v2.DeleteLogRequest) Empty(com.google.protobuf.Empty) LogNameOneof(com.google.logging.v2.LogNameOneof) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with LogNameOneof

use of com.google.logging.v2.LogNameOneof in project google-cloud-java by GoogleCloudPlatform.

the class LoggingClientTest method writeLogEntriesExceptionTest.

@Test
@SuppressWarnings("all")
public void writeLogEntriesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLoggingServiceV2.addException(exception);
    try {
        LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
        MonitoredResource resource = MonitoredResource.newBuilder().build();
        Map<String, String> labels = new HashMap<>();
        List<LogEntry> entries = new ArrayList<>();
        client.writeLogEntries(logName, resource, labels, entries);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : LogNameOneof(com.google.logging.v2.LogNameOneof) HashMap(java.util.HashMap) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) MonitoredResource(com.google.api.MonitoredResource) LogEntry(com.google.logging.v2.LogEntry) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 3 with LogNameOneof

use of com.google.logging.v2.LogNameOneof in project google-cloud-java by GoogleCloudPlatform.

the class LoggingClientTest method writeLogEntriesTest.

@Test
@SuppressWarnings("all")
public void writeLogEntriesTest() {
    WriteLogEntriesResponse expectedResponse = WriteLogEntriesResponse.newBuilder().build();
    mockLoggingServiceV2.addResponse(expectedResponse);
    LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
    MonitoredResource resource = MonitoredResource.newBuilder().build();
    Map<String, String> labels = new HashMap<>();
    List<LogEntry> entries = new ArrayList<>();
    WriteLogEntriesResponse actualResponse = client.writeLogEntries(logName, resource, labels, entries);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLoggingServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    WriteLogEntriesRequest actualRequest = (WriteLogEntriesRequest) actualRequests.get(0);
    Assert.assertEquals(logName, actualRequest.getLogNameAsLogNameOneof());
    Assert.assertEquals(resource, actualRequest.getResource());
    Assert.assertEquals(labels, actualRequest.getLabelsMap());
    Assert.assertEquals(entries, actualRequest.getEntriesList());
}
Also used : LogNameOneof(com.google.logging.v2.LogNameOneof) WriteLogEntriesRequest(com.google.logging.v2.WriteLogEntriesRequest) HashMap(java.util.HashMap) WriteLogEntriesResponse(com.google.logging.v2.WriteLogEntriesResponse) ArrayList(java.util.ArrayList) MonitoredResource(com.google.api.MonitoredResource) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) LogEntry(com.google.logging.v2.LogEntry) Test(org.junit.Test)

Example 4 with LogNameOneof

use of com.google.logging.v2.LogNameOneof in project google-cloud-java by GoogleCloudPlatform.

the class LoggingClientTest method deleteLogExceptionTest.

@Test
@SuppressWarnings("all")
public void deleteLogExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLoggingServiceV2.addException(exception);
    try {
        LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
        client.deleteLog(logName);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : LogNameOneof(com.google.logging.v2.LogNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 5 with LogNameOneof

use of com.google.logging.v2.LogNameOneof in project google-cloud-java by GoogleCloudPlatform.

the class LoggingClient method deleteLog.

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
   * Deletes all the log entries in a log. The log reappears if it receives new entries. Log entries
   * written shortly before the delete operation might not be deleted.
   *
   * <p>Sample code:
   *
   * <pre><code>
   * try (LoggingClient loggingClient = LoggingClient.create()) {
   *   LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
   *   loggingClient.deleteLog(logName);
   * }
   * </code></pre>
   *
   * @param logName Required. The resource name of the log to delete:
   *     <p>"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]"
   *     "billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]" "folders/[FOLDER_ID]/logs/[LOG_ID]"
   *     <p>`[LOG_ID]` must be URL-encoded. For example, `"projects/my-project-id/logs/syslog"`,
   *     `"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"`. For more
   *     information about log names, see [LogEntry][google.logging.v2.LogEntry].
   * @throws com.google.api.gax.grpc.ApiException if the remote call fails
   */
public final void deleteLog(LogNameOneof logName) {
    DeleteLogRequest request = DeleteLogRequest.newBuilder().setLogNameWithLogNameOneof(logName).build();
    deleteLog(request);
}
Also used : DeleteLogRequest(com.google.logging.v2.DeleteLogRequest)

Aggregations

LogNameOneof (com.google.logging.v2.LogNameOneof)4 Test (org.junit.Test)4 MonitoredResource (com.google.api.MonitoredResource)2 ApiException (com.google.api.gax.grpc.ApiException)2 DeleteLogRequest (com.google.logging.v2.DeleteLogRequest)2 LogEntry (com.google.logging.v2.LogEntry)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 WriteLogEntriesRequest (com.google.logging.v2.WriteLogEntriesRequest)1 WriteLogEntriesResponse (com.google.logging.v2.WriteLogEntriesResponse)1 Empty (com.google.protobuf.Empty)1