use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testDeleteAttachmentUsage.
@Test(expected = SW360Exception.class)
public void testDeleteAttachmentUsage() throws Exception {
AttachmentUsage usage1 = new AttachmentUsage();
usage1.setOwner(Source.projectId("r1"));
usage1.setUsedBy(Source.projectId("p1"));
usage1.setAttachmentContentId("a1");
handler.makeAttachmentUsage(usage1);
Assert.assertTrue(usage1.isSetId());
handler.deleteAttachmentUsage(usage1);
Assert.assertNull(handler.getAttachmentUsage(usage1.getId()));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testAttachmentUsageCount.
@Test
public void testAttachmentUsageCount() throws Exception {
AttachmentUsage usage1 = createUsage("p1", "r1", "a11");
AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
AttachmentUsage usage3 = createUsage("p2", "r2", "a21");
AttachmentUsage usage4 = createUsage("p3", "r1", "a11");
AttachmentUsage usage5 = createUsage("p4", "r1", "a11");
AttachmentUsage usage6 = createUsage("p5", "r3", "a31");
handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5, usage6));
Map<Source, Set<String>> queryFor = ImmutableMap.of(Source.releaseId("r1"), ImmutableSet.of("a11", "a12"), Source.releaseId("r3"), ImmutableSet.of("a31"));
Map<Map<Source, String>, Integer> counts = handler.getAttachmentUsageCount(queryFor, null);
Map<Map<Source, String>, Integer> expected = ImmutableMap.of(ImmutableMap.of(Source.releaseId("r1"), "a11"), 3, ImmutableMap.of(Source.releaseId("r1"), "a12"), 1, ImmutableMap.of(Source.releaseId("r3"), "a31"), 1);
for (Entry<Map<Source, String>, Integer> entry : expected.entrySet()) {
Assert.assertThat(counts.get(entry.getKey()), is(entry.getValue()));
}
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testUpdateAttachmentUsage.
@Test
public void testUpdateAttachmentUsage() throws Exception {
AttachmentUsage usage1 = new AttachmentUsage();
usage1.setOwner(Source.projectId("r1"));
usage1.setUsedBy(Source.projectId("p1"));
usage1.setAttachmentContentId("a1");
handler.makeAttachmentUsage(usage1);
usage1.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet("l1", "l2"))));
handler.updateAttachmentUsage(usage1);
Assert.assertThat(handler.getAttachmentUsage(usage1.getId()), is(usage1));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testGetUsedAttachmentsWithFilter.
@Test
public void testGetUsedAttachmentsWithFilter() throws Exception {
AttachmentUsage usage1 = createUsage("p1", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
AttachmentUsage usage2 = createUsage("p1", "r1", "a12", UsageData.licenseInfo(new LicenseInfoUsage()));
AttachmentUsage usage3 = createUsage("p1", "r2", "a21");
AttachmentUsage usage4 = createUsage("p3", "r1", "a11");
AttachmentUsage usage5 = createUsage("p4", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5));
Assert.assertThat(handler.getUsedAttachments(Source.projectId("p1"), UsageData.licenseInfo(new LicenseInfoUsage())), Matchers.containsInAnyOrder(usage1, usage2));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testMakeAndGetAttachmentUsage.
@Test
public void testMakeAndGetAttachmentUsage() throws Exception {
AttachmentUsage usage1 = new AttachmentUsage();
usage1.setOwner(Source.projectId("r1"));
usage1.setUsedBy(Source.projectId("p1"));
usage1.setAttachmentContentId("a1");
usage1 = handler.makeAttachmentUsage(usage1);
AttachmentUsage usage2 = new AttachmentUsage();
usage2.setOwner(Source.projectId("r2"));
usage2.setUsedBy(Source.projectId("p1"));
usage2.setAttachmentContentId("a2");
usage2 = handler.makeAttachmentUsage(usage2);
Assert.assertThat(handler.getAttachmentUsage(usage1.getId()), is(usage1));
Assert.assertThat(handler.getAttachmentUsage(usage2.getId()), is(usage2));
}
Aggregations