Search in sources :

Example 26 with Occurrence

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

the class SamplesTests method testCreateOccurrence.

@Test
public void testCreateOccurrence() throws Exception {
    Occurrence o = Samples.createOccurrence(imageUrl, noteId, PROJECT_ID);
    Occurrence retrieved = Samples.getOccurrence(o.getName());
    assertEquals(o.getName(), retrieved.getName());
    // clean up
    Samples.deleteOccurrence(o.getName());
}
Also used : Occurrence(com.google.containeranalysis.v1alpha1.Occurrence) Test(org.junit.Test)

Example 27 with Occurrence

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

the class SamplesTests method testDeleteOccurrence.

@Test
public void testDeleteOccurrence() throws Exception {
    Occurrence o = Samples.createOccurrence(imageUrl, noteId, PROJECT_ID);
    String occName = o.getName();
    Samples.deleteOccurrence(occName);
    try {
        Samples.getOccurrence(occName);
        // getOccurrence should fail, because occurrence was deleted
        fail("failed to delete occurrence");
    } catch (Exception e) {
    // test passes
    }
}
Also used : Occurrence(com.google.containeranalysis.v1alpha1.Occurrence) Test(org.junit.Test)

Example 28 with Occurrence

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

the class SamplesTests method testOccurrencesForImage.

@Test
public void testOccurrencesForImage() throws Exception {
    int newCount;
    int tries = 0;
    int origCount = Samples.getOccurrencesForImage(imageUrl, PROJECT_ID);
    final Occurrence o = Samples.createOccurrence(imageUrl, noteId, PROJECT_ID);
    do {
        newCount = Samples.getOccurrencesForImage(imageUrl, PROJECT_ID);
        sleep(SLEEP_TIME);
    } while (newCount != 1 && tries < TRY_LIMIT);
    assertEquals(1, newCount);
    assertEquals(0, origCount);
    // clean up
    Samples.deleteOccurrence(o.getName());
}
Also used : Occurrence(com.google.containeranalysis.v1alpha1.Occurrence) Test(org.junit.Test)

Example 29 with Occurrence

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

the class SamplesTest method testDeleteOccurrence.

@Test
public void testDeleteOccurrence() throws Exception {
    Occurrence o = CreateOccurrence.createOccurrence(imageUrl, noteId, PROJECT_ID, PROJECT_ID);
    String occName = o.getName();
    String[] nameArr = occName.split("/");
    String occId = nameArr[nameArr.length - 1];
    DeleteOccurrence.deleteOccurrence(occId, PROJECT_ID);
    try {
        GetOccurrence.getOccurrence(occId, PROJECT_ID);
        // getOccurrence should fail, because occurrence was deleted
        Assert.fail("failed to delete occurrence");
    } catch (NotFoundException e) {
    // test passes
    }
}
Also used : NotFoundException(com.google.api.gax.rpc.NotFoundException) Occurrence(io.grafeas.v1.Occurrence) VulnerabilityOccurrence(io.grafeas.v1.VulnerabilityOccurrence) DiscoveryOccurrence(io.grafeas.v1.DiscoveryOccurrence) Test(org.junit.Test)

Example 30 with Occurrence

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

the class SamplesTest method testOccurrencesForNote.

@Test
public void testOccurrencesForNote() throws Exception {
    int newCount;
    int tries = 0;
    int origCount = OccurrencesForNote.getOccurrencesForNote(noteId, PROJECT_ID);
    final Occurrence o = CreateOccurrence.createOccurrence(imageUrl, noteId, PROJECT_ID, PROJECT_ID);
    do {
        newCount = OccurrencesForNote.getOccurrencesForNote(noteId, PROJECT_ID);
        sleep(SLEEP_TIME);
        tries += 1;
    } while (newCount != 1 && tries < TRY_LIMIT);
    assertEquals(0, origCount);
    assertEquals(1, newCount);
    // clean up
    String[] nameArr = o.getName().split("/");
    String occId = nameArr[nameArr.length - 1];
    DeleteOccurrence.deleteOccurrence(occId, PROJECT_ID);
}
Also used : Occurrence(io.grafeas.v1.Occurrence) VulnerabilityOccurrence(io.grafeas.v1.VulnerabilityOccurrence) DiscoveryOccurrence(io.grafeas.v1.DiscoveryOccurrence) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 Occurrence (io.grafeas.v1.Occurrence)17 Occurrence (com.google.containeranalysis.v1alpha1.Occurrence)10 VulnerabilityOccurrence (io.grafeas.v1.VulnerabilityOccurrence)10 DiscoveryOccurrence (io.grafeas.v1.DiscoveryOccurrence)9 GrafeasClient (io.grafeas.v1.GrafeasClient)9 Occurrence (io.grafeas.v1beta1.Occurrence)9 AbstractMessage (com.google.protobuf.AbstractMessage)8 OccurrenceName (com.google.containeranalysis.v1beta1.OccurrenceName)5 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)5 ContainerAnalysisClient (com.google.cloud.devtools.containeranalysis.v1alpha1.ContainerAnalysisClient)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)3 NoteName (io.grafeas.v1.NoteName)3 DeleteOccurrenceRequest (io.grafeas.v1beta1.DeleteOccurrenceRequest)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 ListOccurrencesPagedResponse (com.google.cloud.devtools.containeranalysis.v1alpha1.PagedResponseWrappers.ListOccurrencesPagedResponse)2 Subscriber (com.google.cloud.pubsub.v1.Subscriber)2 ListOccurrencesRequest (com.google.containeranalysis.v1alpha1.ListOccurrencesRequest)2 VulnerabilityDetails (com.google.containeranalysis.v1alpha1.VulnerabilityType.VulnerabilityDetails)2 FieldMask (com.google.protobuf.FieldMask)2