use of io.grafeas.v1.Note in project java-docs-samples by GoogleCloudPlatform.
the class DeleteNote method deleteNote.
// Deletes an existing Note from the server
public static void deleteNote(String noteId, String projectId) throws IOException, InterruptedException {
// String noteId = "my-note";
// String projectId = "my-project-id";
final NoteName noteName = NoteName.of(projectId, noteId);
// Initialize client that will be used to send requests. After completing all of your requests,
// call the "close" method on the client to safely clean up any remaining background resources.
GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
client.deleteNote(noteName);
}
use of io.grafeas.v1.Note in project java-containeranalysis by googleapis.
the class GrafeasV1Beta1ClientTest method updateNoteTest.
@Test
@SuppressWarnings("all")
public void updateNoteTest() {
String name2 = "name2-1052831874";
String shortDescription = "shortDescription-235369287";
String longDescription = "longDescription-1747792199";
Note expectedResponse = Note.newBuilder().setName(name2).setShortDescription(shortDescription).setLongDescription(longDescription).build();
mockGrafeasV1Beta1.addResponse(expectedResponse);
NoteName name = NoteName.of("[PROJECT]", "[NOTE]");
Note note = Note.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
Note actualResponse = client.updateNote(name, note, updateMask);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockGrafeasV1Beta1.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateNoteRequest actualRequest = (UpdateNoteRequest) actualRequests.get(0);
Assert.assertEquals(name, NoteName.parse(actualRequest.getName()));
Assert.assertEquals(note, actualRequest.getNote());
Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of io.grafeas.v1.Note in project java-containeranalysis by googleapis.
the class GrafeasV1Beta1ClientTest method batchCreateNotesExceptionTest.
@Test
@SuppressWarnings("all")
public void batchCreateNotesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockGrafeasV1Beta1.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
Map<String, Note> notes = new HashMap<>();
client.batchCreateNotes(parent, notes);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
use of io.grafeas.v1.Note in project java-containeranalysis by googleapis.
the class GrafeasV1Beta1ClientTest method getOccurrenceNoteTest.
@Test
@SuppressWarnings("all")
public void getOccurrenceNoteTest() {
String name2 = "name2-1052831874";
String shortDescription = "shortDescription-235369287";
String longDescription = "longDescription-1747792199";
Note expectedResponse = Note.newBuilder().setName(name2).setShortDescription(shortDescription).setLongDescription(longDescription).build();
mockGrafeasV1Beta1.addResponse(expectedResponse);
OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]");
Note actualResponse = client.getOccurrenceNote(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockGrafeasV1Beta1.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetOccurrenceNoteRequest actualRequest = (GetOccurrenceNoteRequest) actualRequests.get(0);
Assert.assertEquals(name, OccurrenceName.parse(actualRequest.getName()));
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of io.grafeas.v1.Note in project java-containeranalysis by googleapis.
the class GrafeasV1Beta1ClientTest method updateNoteExceptionTest.
@Test
@SuppressWarnings("all")
public void updateNoteExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockGrafeasV1Beta1.addException(exception);
try {
NoteName name = NoteName.of("[PROJECT]", "[NOTE]");
Note note = Note.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
client.updateNote(name, note, updateMask);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
Aggregations