/** * * * <pre> * [Required] The error event to be reported. * </pre> * * <code>.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent event = 2;</code> */ public Builder setEvent( com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent.Builder builderForValue) { if (eventBuilder_ == null) { event_ = builderForValue.build(); onChanged(); } else { eventBuilder_.setMessage(builderForValue.build()); } return this; } /**
@Test @SuppressWarnings("all") public void reportErrorEventTest() { ReportErrorEventResponse expectedResponse = ReportErrorEventResponse.newBuilder().build(); mockReportErrorsService.addResponse(expectedResponse); ProjectName projectName = ProjectName.of("[PROJECT]"); ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build(); ReportErrorEventResponse actualResponse = client.reportErrorEvent(projectName, event); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockReportErrorsService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ReportErrorEventRequest actualRequest = (ReportErrorEventRequest) actualRequests.get(0); Assert.assertEquals(projectName, ProjectName.parse(actualRequest.getProjectName())); Assert.assertEquals(event, actualRequest.getEvent()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
/** * * * <pre> * [Required] The error event to be reported. * </pre> * * <code>.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent event = 2;</code> */ public Builder setEvent( com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent.Builder builderForValue) { if (eventBuilder_ == null) { event_ = builderForValue.build(); onChanged(); } else { eventBuilder_.setMessage(builderForValue.build()); } return this; } /**
public static void executeNoCatch(String projectId) throws Exception { try (ReportErrorsServiceClient client = ReportErrorsServiceClient.create()) { ProjectName projectName = ProjectName.of(projectId); String message = "[MESSAGE]"; String service = "[SERVICE]"; ServiceContext serviceContext = ServiceContext.newBuilder().setService(service).build(); String filePath = "path/to/file.lang"; int lineNumber = 42; String functionName = "meaningOfLife"; SourceLocation reportLocation = SourceLocation.newBuilder() .setFilePath(filePath) .setLineNumber(lineNumber) .setFunctionName(functionName) .build(); ErrorContext context = ErrorContext.newBuilder().setReportLocation(reportLocation).build(); ReportedErrorEvent event = ReportedErrorEvent.newBuilder() .setMessage(message) .setServiceContext(serviceContext) .setContext(context) .build(); ReportErrorEventResponse response = client.reportErrorEvent(projectName, event); } }
@Test @SuppressWarnings("all") public void reportErrorEventExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockReportErrorsService.addException(exception); try { ProjectName projectName = ProjectName.of("[PROJECT]"); ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build(); client.reportErrorEvent(projectName, event); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } } }