Search in sources :

Example 16 with Note

use of io.grafeas.v1beta1.Note in project java-docs-samples by GoogleCloudPlatform.

the class SamplesTest method testCreateNote.

@Test
public void testCreateNote() throws Exception {
    // note should have been created as part of set up. verify that it succeeded
    Note n = GetNote.getNote(noteId, PROJECT_ID);
    assertEquals(n.getName(), noteObj.getName());
}
Also used : VulnerabilityNote(io.grafeas.v1.VulnerabilityNote) DiscoveryNote(io.grafeas.v1.DiscoveryNote) Note(io.grafeas.v1.Note) Test(org.junit.Test)

Example 17 with Note

use of io.grafeas.v1beta1.Note in project java-docs-samples by GoogleCloudPlatform.

the class SamplesTest method testPollDiscoveryOccurrenceFinished.

@Test
public void testPollDiscoveryOccurrenceFinished() throws Exception {
    try {
        // expect fail on first try
        PollDiscoveryOccurrenceFinished.pollDiscoveryOccurrenceFinished(imageUrl, PROJECT_ID, 5);
        Assert.fail("found unexpected discovery occurrence");
    } catch (TimeoutException e) {
    // test passes
    }
    // create discovery note
    Note newNote = Note.newBuilder().setDiscovery(DiscoveryNote.newBuilder().setAnalysisKind(NoteKind.DISCOVERY)).build();
    String discNoteId = "discovery-note-" + (new Date()).getTime();
    NoteName noteName = NoteName.of(PROJECT_ID, discNoteId);
    GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
    client.createNote(ProjectName.format(PROJECT_ID), discNoteId, newNote);
    // create discovery occurrence
    Occurrence newOcc = Occurrence.newBuilder().setNoteName(noteName.toString()).setResourceUri(imageUrl).setDiscovery(DiscoveryOccurrence.newBuilder().setAnalysisStatus(AnalysisStatus.FINISHED_SUCCESS)).build();
    Occurrence result = client.createOccurrence(ProjectName.format(PROJECT_ID), newOcc);
    // poll again
    Occurrence found = PollDiscoveryOccurrenceFinished.pollDiscoveryOccurrenceFinished(imageUrl, PROJECT_ID, 5);
    AnalysisStatus foundStatus = found.getDiscovery().getAnalysisStatus();
    assertEquals(foundStatus, AnalysisStatus.FINISHED_SUCCESS);
    // clean up
    String[] nameArr = found.getName().split("/");
    String occId = nameArr[nameArr.length - 1];
    DeleteOccurrence.deleteOccurrence(occId, PROJECT_ID);
    DeleteNote.deleteNote(discNoteId, PROJECT_ID);
}
Also used : GrafeasClient(io.grafeas.v1.GrafeasClient) VulnerabilityNote(io.grafeas.v1.VulnerabilityNote) DiscoveryNote(io.grafeas.v1.DiscoveryNote) Note(io.grafeas.v1.Note) NoteName(io.grafeas.v1.NoteName) AnalysisStatus(io.grafeas.v1.DiscoveryOccurrence.AnalysisStatus) Occurrence(io.grafeas.v1.Occurrence) VulnerabilityOccurrence(io.grafeas.v1.VulnerabilityOccurrence) DiscoveryOccurrence(io.grafeas.v1.DiscoveryOccurrence) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 18 with Note

use of io.grafeas.v1beta1.Note in project java-docs-samples by GoogleCloudPlatform.

the class CreateNote method createNote.

// Creates and returns a new Note
public static Note createNote(String noteId, String projectId) throws IOException, InterruptedException {
    // String noteId = "my-note";
    // String projectId = "my-project-id";
    final String projectName = ProjectName.format(projectId);
    Note newNote = Note.newBuilder().setVulnerability(VulnerabilityNote.newBuilder().addDetails(VulnerabilityNote.Detail.newBuilder().setAffectedCpeUri("your-uri-here").setAffectedPackage("your-package-here").setAffectedVersionStart(Version.newBuilder().setKind(Version.VersionKind.MINIMUM)).setAffectedVersionEnd(Version.newBuilder().setKind(Version.VersionKind.MAXIMUM)))).build();
    // 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();
    Note result = client.createNote(projectName, noteId, newNote);
    return result;
}
Also used : GrafeasClient(io.grafeas.v1.GrafeasClient) VulnerabilityNote(io.grafeas.v1.VulnerabilityNote) Note(io.grafeas.v1.Note)

Example 19 with Note

use of io.grafeas.v1beta1.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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) UpdateNoteRequest(io.grafeas.v1beta1.UpdateNoteRequest) Note(io.grafeas.v1beta1.Note) NoteName(com.google.containeranalysis.v1beta1.NoteName) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 20 with Note

use of io.grafeas.v1beta1.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
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.containeranalysis.v1beta1.ProjectName) HashMap(java.util.HashMap) Note(io.grafeas.v1beta1.Note) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 Note (io.grafeas.v1beta1.Note)9 AbstractMessage (com.google.protobuf.AbstractMessage)8 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)5 Note (io.grafeas.v1.Note)5 NoteName (com.google.containeranalysis.v1beta1.NoteName)4 IOException (java.io.IOException)4 BookID (biblemulticonverter.data.BookID)3 FormattingInstructionKind (biblemulticonverter.data.FormattedText.FormattingInstructionKind)3 Visitor (biblemulticonverter.data.FormattedText.Visitor)3 BR (biblemulticonverter.schema.zef2005.BR)3 DIV (biblemulticonverter.schema.zef2005.DIV)3 Note (com.google.containeranalysis.v1alpha1.Note)3 VulnerabilityNote (io.grafeas.v1.VulnerabilityNote)3 Note (biblemulticonverter.schema.usx3.Note)2 Verse (biblemulticonverter.schema.usx3.Verse)2 GRAM (biblemulticonverter.schema.zef2005.GRAM)2 NOTE (biblemulticonverter.schema.zef2005.NOTE)2 STYLE (biblemulticonverter.schema.zef2005.STYLE)2 XREF (biblemulticonverter.schema.zef2005.XREF)2