use of com.google.cloud.datalabeling.v1beta1.ProjectName in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceClientTest method createAssessmentExceptionTest.
@Test
public void createAssessmentExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockRecaptchaEnterpriseService.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
Assessment assessment = Assessment.newBuilder().build();
client.createAssessment(parent, assessment);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.cloud.datalabeling.v1beta1.ProjectName in project java-asset by googleapis.
the class ExportAssetsExample method exportAssets.
// Export assets for a project.
// @param exportPath where the results will be exported to.
public static void exportAssets(String exportPath, ContentType contentType) throws IOException, IllegalArgumentException, InterruptedException, ExecutionException {
try (AssetServiceClient client = AssetServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
OutputConfig outputConfig = OutputConfig.newBuilder().setGcsDestination(GcsDestination.newBuilder().setUri(exportPath).build()).build();
ExportAssetsRequest request = ExportAssetsRequest.newBuilder().setParent(parent.toString()).setOutputConfig(outputConfig).setContentType(contentType).build();
ExportAssetsResponse response = client.exportAssetsAsync(request).get();
System.out.println(response);
}
}
use of com.google.cloud.datalabeling.v1beta1.ProjectName in project java-asset by googleapis.
the class ListAssetsExample method listAssets.
public static void listAssets(String projectId, String[] assetTypes, ContentType contentType) throws IOException, IllegalArgumentException {
try (AssetServiceClient client = AssetServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
// Build initial ListAssetsRequest without setting page token.
ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(parent.toString()).addAllAssetTypes(Arrays.asList(assetTypes)).setContentType(contentType).build();
// Repeatedly call ListAssets until page token is empty.
ListAssetsPagedResponse response = client.listAssets(request);
System.out.println(response);
while (!response.getNextPageToken().isEmpty()) {
request = request.toBuilder().setPageToken(response.getNextPageToken()).build();
response = client.listAssets(request);
System.out.println(response);
}
}
}
use of com.google.cloud.datalabeling.v1beta1.ProjectName in project grpc-gcp-java by GoogleCloudPlatform.
the class StackdriverUtils method reportError.
/**
* Report the error to the stackdriver errorlog.
*/
public void reportError(String error, String funcName, int line) {
// Report to the std error.
System.err.println(error);
// Report to the stackdriver.
if (errClient != null) {
String projectId = ServiceOptions.getDefaultProjectId();
ProjectName projectName = ProjectName.of(projectId);
// Custom error events require an error reporting location as well.
ErrorContext errorContext = ErrorContext.newBuilder().setReportLocation(SourceLocation.newBuilder().setFilePath("Prober.java").setLineNumber(line).setFunctionName(funcName).build()).build();
// Report a custom error event
ReportedErrorEvent customErrorEvent = ReportedErrorEvent.getDefaultInstance().toBuilder().setMessage(error).setContext(errorContext).build();
// Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
errClient.reportErrorEvent(projectName, customErrorEvent);
}
}
use of com.google.cloud.datalabeling.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method listMetricDescriptorsTest.
@Test
@SuppressWarnings("all")
public void listMetricDescriptorsTest() {
String nextPageToken = "";
MetricDescriptor metricDescriptorsElement = MetricDescriptor.newBuilder().build();
List<MetricDescriptor> metricDescriptors = Arrays.asList(metricDescriptorsElement);
ListMetricDescriptorsResponse expectedResponse = ListMetricDescriptorsResponse.newBuilder().setNextPageToken(nextPageToken).addAllMetricDescriptors(metricDescriptors).build();
mockMetricService.addResponse(expectedResponse);
ProjectName name = ProjectName.create("[PROJECT]");
ListMetricDescriptorsPagedResponse pagedListResponse = client.listMetricDescriptors(name);
List<MetricDescriptor> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getMetricDescriptorsList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListMetricDescriptorsRequest actualRequest = (ListMetricDescriptorsRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsProjectName());
}
Aggregations