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