Search in sources :

Example 6 with AttachmentUsage

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()));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage)

Example 7 with AttachmentUsage

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()));
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Source(org.eclipse.sw360.datahandler.thrift.Source)

Example 8 with AttachmentUsage

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));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)

Example 9 with AttachmentUsage

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));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)

Example 10 with AttachmentUsage

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));
}
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