1 package com.atlassian.plugin.manager;
2
3 import com.atlassian.plugin.PluginDependencies;
4 import com.google.common.collect.ImmutableList;
5 import com.google.common.collect.ImmutableSet;
6 import org.junit.Test;
7 import org.junit.runner.RunWith;
8 import org.junit.runners.Parameterized;
9
10 import java.util.Arrays;
11 import java.util.Collection;
12 import java.util.List;
13 import java.util.Set;
14 import java.util.stream.Collectors;
15
16 import static com.atlassian.plugin.PluginDependencies.Type.DYNAMIC;
17 import static com.atlassian.plugin.PluginDependencies.Type.MANDATORY;
18 import static com.atlassian.plugin.PluginDependencies.Type.OPTIONAL;
19 import static org.hamcrest.Matchers.containsInAnyOrder;
20 import static org.hamcrest.Matchers.equalTo;
21 import static org.hamcrest.Matchers.is;
22 import static org.junit.Assert.assertThat;
23
24 @RunWith(Parameterized.class)
25 public class TestDependentPluginsToPluginDependencyType extends TestDependentPlugins {
26 @Parameterized.Parameters(name = "{index}: ({1}, {0})")
27 public static Collection<Object[]> data() {
28 return Arrays.asList(new Object[][]{
29 {ImmutableSet.of(MANDATORY, OPTIONAL, DYNAMIC),
30 ImmutableList.of("C"),
31 new String[]{
32 "A(OPTIONAL)",
33 "B(DYNAMIC)",
34 "D(OPTIONAL)",
35 "F(OPTIONAL)",
36 "E(MANDATORY)",
37 "H(MANDATORY)"
38 }
39 },
40 {ImmutableSet.of(MANDATORY, OPTIONAL, DYNAMIC),
41 ImmutableList.of("C", "D"),
42 new String[]{
43 "A(OPTIONAL)",
44 "B(DYNAMIC)",
45 "F(MANDATORY)",
46 "E(MANDATORY)",
47 "H(MANDATORY)"
48 }
49 },
50 {ImmutableSet.of(MANDATORY, OPTIONAL),
51 ImmutableList.of("G"),
52 new String[]{
53 "C(MANDATORY)",
54 "A(OPTIONAL)",
55 "D(OPTIONAL)",
56 "F(OPTIONAL)",
57 "E(MANDATORY)",
58 "H(MANDATORY)"
59 }
60 },
61 {ImmutableSet.of(MANDATORY),
62 ImmutableList.of("G"),
63 new String[]{
64 "C(MANDATORY)",
65 "E(MANDATORY)",
66 "H(MANDATORY)"
67 }
68 },
69 {ImmutableSet.of(OPTIONAL),
70 ImmutableList.of("C"),
71 new String[]{
72 "A(OPTIONAL)",
73 "D(OPTIONAL)",
74 "F(OPTIONAL)",
75 }
76 },
77 {ImmutableSet.of(OPTIONAL),
78 ImmutableList.of("G"),
79 new String[]{
80 }
81 },
82 {ImmutableSet.of(DYNAMIC),
83 ImmutableList.of("C"),
84 new String[]{
85 "B(DYNAMIC)",
86 "F(DYNAMIC)",
87 "A(DYNAMIC)",
88 "H(DYNAMIC)",
89 }
90 },
91 {ImmutableSet.of(DYNAMIC),
92 ImmutableList.of("G"),
93 new String[]{
94 }
95 },
96 {ImmutableSet.of(MANDATORY),
97 ImmutableList.of("a"),
98 new String[]{
99 "b(MANDATORY)",
100 "c(MANDATORY)"
101 }
102 },
103 {ImmutableSet.of(MANDATORY, OPTIONAL, DYNAMIC),
104 ImmutableList.of("mC"),
105 new String[]{
106 "mA(MANDATORY)",
107 "mX(MANDATORY)",
108 "mB(DYNAMIC)",
109 "mD(OPTIONAL)",
110 "mE(MANDATORY)"
111 }
112 },
113 {ImmutableSet.of(MANDATORY, OPTIONAL, DYNAMIC),
114 ImmutableList.of("mC", "mD", "mE"),
115 new String[]{
116 "mA(MANDATORY)",
117 "mB(DYNAMIC)",
118 "mX(MANDATORY)",
119 }
120 },
121 {ImmutableSet.of(MANDATORY, OPTIONAL, DYNAMIC),
122 ImmutableList.of("aC"),
123 new String[]{}
124 },
125 });
126 }
127
128 @Parameterized.Parameter
129 public Set<PluginDependencies.Type> dependencyTypes;
130
131 @Parameterized.Parameter(1)
132 public List<String> pluginKeys;
133
134 @Parameterized.Parameter(2)
135 public String[] expected;
136
137 @Test
138 public void testToPluginKeyDependencyTypes() throws Exception {
139 final DependentPlugins dp = new DependentPlugins(pluginKeys, allPlugins, dependencyTypes);
140 assertThat(dp.toStringList(), containsInAnyOrder(expected));
141 }
142
143 @Test
144 public void testGet() throws Exception {
145 final DependentPlugins dp = new DependentPlugins(pluginKeys, allPlugins, dependencyTypes);
146
147 final Set<String> keysExpected = Arrays.stream(expected)
148 .map(input -> input.substring(0, input.indexOf('(')))
149 .collect(Collectors.toSet());
150
151 assertThat(getKeys(dp.getPlugins(false)), is(equalTo(keysExpected)));
152 }
153 }