DCAE-D be initial commit
[sdc/dcae-d/dt-be-main.git] / dcaedt_catalog / api / src / test / java / org / onap / sdc / dcae / catalog / ASDCCatalogTest.java
1 package org.onap.sdc.dcae.catalog;
2
3 import static org.assertj.core.api.Assertions.*;
4
5 import java.net.URISyntaxException;
6 import java.util.ArrayList;
7 import java.util.Arrays;
8 import java.util.Collection;
9 import java.util.UUID;
10
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;
17
18 import static org.mockito.Mockito.*;
19
20
21 public class ASDCCatalogTest {
22         
23         @Rule
24         public ExpectedException thrown = ExpectedException.none();
25         
26         private static FolderAction getTarget() {
27                 ASDCCatalog catalog = mock(ASDCCatalog.class);
28                 when(catalog.folder("test")).thenCallRealMethod();
29                 FolderAction target = catalog.folder("test");
30                 return target;
31         }
32         
33         @Test
34         public void filterLatestVersion_null_throwIllegalArgumentException() {
35                 // arrange
36                 FolderAction target = getTarget();
37                 // assert
38                 thrown.expect(IllegalArgumentException.class);
39                 // act
40                 target.filterLatestVersion(null);
41         }
42         
43         @Test
44         public void filterLatestVersion_emptyItemsList_emptyItemsList() throws URISyntaxException {
45                 // arrange
46                 FolderAction target = getTarget();
47                 // act
48                 Collection<Resource> result = target.filterLatestVersion(new ArrayList<>());
49                 // assert
50                 assertThat(result).isEmpty();
51         }
52         
53         @Test
54         public void filterLatestVersion_itemWithTwoVersions_itemWithLatestVersion() {
55                 // arrange
56                 FolderAction target = getTarget();
57                 
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));
66                 // act
67                 Collection<Resource> result = target.filterLatestVersion(listItemWithTwoVersions);
68                 // assert
69                 assertThat(result).containsExactly(r1v2);
70         }
71         
72         @Test
73         public void filterLatestVersion_2distinctItems_2distinctItems() {
74                 // arrange
75                 FolderAction target = getTarget();
76                 
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));
82                 // act
83                 Collection<Resource> result = target.filterLatestVersion(listOfTwoDistinctItems);
84                 // assert
85                 assertThat(result).containsExactlyInAnyOrder(r1, r2);
86         }
87         
88 }