blob: 360b76d946b3063046d806706c040cbdf4b03038 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package org.onap.sdc.dcae.catalog;
import static org.assertj.core.api.Assertions.*;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog;
import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog.CatalogFolderAction;
import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog.Resource;
import static org.mockito.Mockito.*;
public class ASDCCatalogTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private static CatalogFolderAction getTarget() {
ASDCCatalog catalog = mock(ASDCCatalog.class);
when(catalog.folder("test")).thenCallRealMethod();
CatalogFolderAction target = catalog.folder("test");
return target;
}
@Test
public void filterLatestVersion_null_throwIllegalArgumentException() {
// arrange
CatalogFolderAction target = getTarget();
// assert
thrown.expect(IllegalArgumentException.class);
// act
target.filterLatestVersion(null);
}
@Test
public void filterLatestVersion_emptyItemsList_emptyItemsList() throws URISyntaxException {
// arrange
CatalogFolderAction target = getTarget();
// act
Collection<Resource> result = target.filterLatestVersion(new ArrayList<>());
// assert
assertThat(result).isEmpty();
}
@Test
public void filterLatestVersion_itemWithTwoVersions_itemWithLatestVersion() {
// arrange
CatalogFolderAction target = getTarget();
UUID invariantUUID = UUID.randomUUID();
Resource r1v1 = mock(Resource.class);
Resource r1v2 = mock(Resource.class);
when(r1v1.invariantUUID()).thenReturn(invariantUUID);
when(r1v2.invariantUUID()).thenReturn(invariantUUID);
when(r1v1.version()).thenReturn("1.0");
when(r1v2.version()).thenReturn("2.0");
ArrayList<Resource> listItemWithTwoVersions = new ArrayList<Resource>(Arrays.asList(r1v1, r1v2));
// act
Collection<Resource> result = target.filterLatestVersion(listItemWithTwoVersions);
// assert
assertThat(result).containsExactly(r1v2);
}
@Test
public void filterLatestVersion_2distinctItems_2distinctItems() {
// arrange
CatalogFolderAction target = getTarget();
Resource r1 = mock(Resource.class);
Resource r2 = mock(Resource.class);
when(r1.invariantUUID()).thenReturn(UUID.randomUUID());
when(r2.invariantUUID()).thenReturn(UUID.randomUUID());
ArrayList<Resource> listOfTwoDistinctItems = new ArrayList<Resource>(Arrays.asList(r1, r2));
// act
Collection<Resource> result = target.filterLatestVersion(listOfTwoDistinctItems);
// assert
assertThat(result).containsExactlyInAnyOrder(r1, r2);
}
}
|