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());
}
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());
}
}
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());
}
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());
}
}
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);
}
Aggregations