1 package org.onap.sdc.dcae.catalog;
3 import static org.assertj.core.api.Assertions.*;
5 import java.net.URISyntaxException;
6 import java.util.ArrayList;
7 import java.util.Arrays;
8 import java.util.Collection;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.rules.ExpectedException;
14 import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog;
15 import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog.FolderAction;
16 import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog.Resource;
18 import static org.mockito.Mockito.*;
21 public class ASDCCatalogTest {
24 public ExpectedException thrown = ExpectedException.none();
26 private static FolderAction getTarget() {
27 ASDCCatalog catalog = mock(ASDCCatalog.class);
28 when(catalog.folder("test")).thenCallRealMethod();
29 FolderAction target = catalog.folder("test");
34 public void filterLatestVersion_null_throwIllegalArgumentException() {
36 FolderAction target = getTarget();
38 thrown.expect(IllegalArgumentException.class);
40 target.filterLatestVersion(null);
44 public void filterLatestVersion_emptyItemsList_emptyItemsList() throws URISyntaxException {
46 FolderAction target = getTarget();
48 Collection<Resource> result = target.filterLatestVersion(new ArrayList<>());
50 assertThat(result).isEmpty();
54 public void filterLatestVersion_itemWithTwoVersions_itemWithLatestVersion() {
56 FolderAction target = getTarget();
58 UUID invariantUUID = UUID.randomUUID();
59 Resource r1v1 = mock(Resource.class);
60 Resource r1v2 = mock(Resource.class);
61 when(r1v1.invariantUUID()).thenReturn(invariantUUID);
62 when(r1v2.invariantUUID()).thenReturn(invariantUUID);
63 when(r1v1.version()).thenReturn("1.0");
64 when(r1v2.version()).thenReturn("2.0");
65 ArrayList<Resource> listItemWithTwoVersions = new ArrayList<Resource>(Arrays.asList(r1v1, r1v2));
67 Collection<Resource> result = target.filterLatestVersion(listItemWithTwoVersions);
69 assertThat(result).containsExactly(r1v2);
73 public void filterLatestVersion_2distinctItems_2distinctItems() {
75 FolderAction target = getTarget();
77 Resource r1 = mock(Resource.class);
78 Resource r2 = mock(Resource.class);
79 when(r1.invariantUUID()).thenReturn(UUID.randomUUID());
80 when(r2.invariantUUID()).thenReturn(UUID.randomUUID());
81 ArrayList<Resource> listOfTwoDistinctItems = new ArrayList<Resource>(Arrays.asList(r1, r2));
83 Collection<Resource> result = target.filterLatestVersion(listOfTwoDistinctItems);
85 assertThat(result).containsExactlyInAnyOrder(r1, r2);