use of io.grafeas.v1.Occurrence in project java-docs-samples by GoogleCloudPlatform.
the class SamplesTests method testUpdateOccurrence.
@Test
public void testUpdateOccurrence() throws Exception {
String typeId = "newType";
Occurrence o = Samples.createOccurrence(imageUrl, noteId, PROJECT_ID);
Occurrence.Builder b = Occurrence.newBuilder(o);
VulnerabilityDetails.Builder v = VulnerabilityDetails.newBuilder();
v.setType(typeId);
b.setVulnerabilityDetails(v.build());
Samples.updateOccurrence(o.getName(), b.build());
Occurrence o2 = Samples.getOccurrence(o.getName());
assertEquals(typeId, o2.getVulnerabilityDetails().getType());
// clean up
Samples.deleteOccurrence(o2.getName());
}
use of io.grafeas.v1.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());
}
use of io.grafeas.v1.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
}
}
use of io.grafeas.v1.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());
}
use of io.grafeas.v1.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
}
}
Aggregations