Search in sources :

Example 1 with AttachmentUsage

use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.

the class AttachmentHandlerTest method testReplacementOfUsageWithoutEmptyUsageData.

@Test
public void testReplacementOfUsageWithoutEmptyUsageData() throws Exception {
    AttachmentUsage usage1 = createUsage("p1", "r1", "a11");
    usage1.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet("l1", "l2"))));
    AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
    usage2.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet())));
    AttachmentUsage usage3 = createUsage("p1", "r2", "a21");
    AttachmentUsage usage4 = createUsage("p2", "r1", "a11");
    AttachmentUsage usage5 = createUsage("p3", "r1", "a11");
    usage5.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet("l3"))));
    handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5));
    AttachmentUsage usage6 = createUsage("p1", "r19", "a91");
    usage6.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet("l9"))));
    handler.replaceAttachmentUsages(Source.projectId("p1"), Lists.newArrayList(usage6));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p1"), null), Matchers.containsInAnyOrder(usage3, usage6));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p2"), null), Matchers.containsInAnyOrder(usage4));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p3"), null), Matchers.containsInAnyOrder(usage5));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)

Example 2 with AttachmentUsage

use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.

the class AttachmentHandlerTest method testGetAttachmentUsagesWithFilter.

@Test
public void testGetAttachmentUsagesWithFilter() throws Exception {
    AttachmentUsage usage1 = createUsage("p1", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
    AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
    AttachmentUsage usage3 = createUsage("p2", "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.getAttachmentUsages(Source.releaseId("r1"), "a11", UsageData.licenseInfo(new LicenseInfoUsage())), Matchers.containsInAnyOrder(usage1, usage5));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)

Example 3 with AttachmentUsage

use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.

the class AttachmentHandlerTest method testGetUsedAttachments.

@Test
public void testGetUsedAttachments() throws Exception {
    AttachmentUsage usage1 = createUsage("p1", "r1", "a11");
    AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
    AttachmentUsage usage3 = createUsage("p1", "r2", "a21");
    AttachmentUsage usage4 = createUsage("p3", "r1", "a11");
    AttachmentUsage usage5 = createUsage("p4", "r1", "a11");
    handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p1"), null), Matchers.containsInAnyOrder(usage1, usage2, usage3));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage)

Example 4 with AttachmentUsage

use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.

the class AttachmentHandlerTest method testBulkDeleteAttachmentUsage.

@Test
public void testBulkDeleteAttachmentUsage() throws Exception {
    AttachmentUsage usage1 = createUsage("p1", "r1", "a11");
    AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
    AttachmentUsage usage3 = createUsage("p1", "r2", "a21");
    handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3));
    Assert.assertTrue(usage1.isSetId());
    Assert.assertTrue(usage2.isSetId());
    Assert.assertTrue(usage3.isSetId());
    handler.deleteAttachmentUsages(Lists.newArrayList(usage1, usage3));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p1"), null), Matchers.containsInAnyOrder(usage2));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage)

Example 5 with AttachmentUsage

use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.

the class AttachmentHandlerTest method createUsage.

private AttachmentUsage createUsage(String usedBy, String owner, String attachmentId) {
    AttachmentUsage usage = new AttachmentUsage();
    usage.setUsedBy(Source.projectId(usedBy));
    usage.setOwner(Source.releaseId(owner));
    usage.setAttachmentContentId(attachmentId);
    return usage;
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage)

Aggregations

AttachmentUsage (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage)19 LicenseInfoUsage (org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)10 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Map (java.util.Map)2 Set (java.util.Set)2 Source (org.eclipse.sw360.datahandler.thrift.Source)2 LicenseNameWithText (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)1