86 } |
88 } |
87 |
89 |
88 @DataProvider(name="strings") |
90 @DataProvider(name="strings") |
89 public Object[][] createStrings() { |
91 public Object[][] createStrings() { |
90 return new Object[][]{ |
92 return new Object[][]{ |
91 {"runtime", MAJOR_VERSION}, |
93 {"runtime", MAJOR_VERSION, "8"}, |
92 {null, 8}, |
94 {null, 8, Integer.toString(MAJOR_VERSION)}, |
93 {"8", 8}, |
95 {"8", 8, "9"}, |
94 {"9", 9}, |
96 {"9", 9, null}, |
95 {Integer.toString(MAJOR_VERSION), MAJOR_VERSION}, |
97 {Integer.toString(MAJOR_VERSION), MAJOR_VERSION, "8"}, |
96 {Integer.toString(MAJOR_VERSION+1), MAJOR_VERSION}, |
98 {Integer.toString(MAJOR_VERSION+1), MAJOR_VERSION, "8"}, |
97 {"50", MAJOR_VERSION} |
99 {"50", MAJOR_VERSION, "9"} |
98 }; |
100 }; |
99 } |
101 } |
100 |
102 |
101 @DataProvider(name="integers") |
103 @DataProvider(name="integers") |
102 public Object[][] createIntegers() { |
104 public Object[][] createIntegers() { |
103 return new Object[][] { |
105 return new Object[][] { |
104 {null, 8}, |
106 {null, 8, Integer.valueOf(9)}, |
105 {Integer.valueOf(8), 8}, |
107 {Integer.valueOf(8), 8, Integer.valueOf(9)}, |
106 {Integer.valueOf(9), 9}, |
108 {Integer.valueOf(9), 9, Integer.valueOf(MAJOR_VERSION)}, |
107 {Integer.valueOf(MAJOR_VERSION), MAJOR_VERSION}, |
109 {Integer.valueOf(MAJOR_VERSION), MAJOR_VERSION, Integer.valueOf(8)}, |
108 {Integer.valueOf(MAJOR_VERSION + 1), MAJOR_VERSION}, |
110 {Integer.valueOf(MAJOR_VERSION + 1), MAJOR_VERSION, null}, |
109 {Integer.valueOf(100), MAJOR_VERSION} |
111 {Integer.valueOf(100), MAJOR_VERSION, Integer.valueOf(8)} |
110 }; |
112 }; |
111 } |
113 } |
112 |
114 |
113 @DataProvider(name="versions") |
115 @DataProvider(name="versions") |
114 public Object[][] createVersions() { |
116 public Object[][] createVersions() { |
115 return new Object[][] { |
117 return new Object[][] { |
116 {null, 8}, |
118 {null, 8, Version.parse("14")}, |
117 {Version.parse("8"), 8}, |
119 {Version.parse("8"), 8, Version.parse("7")}, |
118 {Version.parse("9"), 9}, |
120 {Version.parse("9"), 9, null}, |
119 {Version.parse(Integer.toString(MAJOR_VERSION)), MAJOR_VERSION}, |
121 {Version.parse(Integer.toString(MAJOR_VERSION)), MAJOR_VERSION, Version.parse("8")}, |
120 {Version.parse(Integer.toString(MAJOR_VERSION) + 1), MAJOR_VERSION}, |
122 {Version.parse(Integer.toString(MAJOR_VERSION) + 1), MAJOR_VERSION, Version.parse("9")}, |
121 {Version.parse("100"), MAJOR_VERSION} |
123 {Version.parse("100"), MAJOR_VERSION, Version.parse("14")} |
122 }; |
124 }; |
123 } |
125 } |
124 |
126 |
125 @DataProvider(name="invalidVersions") |
127 @DataProvider(name="invalidVersions") |
126 public Object[][] invalidVersions() { |
128 public Object[][] invalidVersions() { |
127 return new Object[][] { |
129 return new Object[][] { |
128 {Map.of("releaseVersion", "")}, |
130 {Map.of(PROPERTY_RELEASE_VERSION, "")}, |
129 {Map.of("releaseVersion", "invalid")}, |
131 {Map.of(PROPERTY_RELEASE_VERSION, "invalid")}, |
130 {Map.of("releaseVersion", "0")}, |
132 {Map.of(PROPERTY_RELEASE_VERSION, "0")}, |
131 {Map.of("releaseVersion", "-1")}, |
133 {Map.of(PROPERTY_RELEASE_VERSION, "-1")}, |
132 {Map.of("releaseVersion", "11.0.1")}, |
134 {Map.of(PROPERTY_RELEASE_VERSION, "11.0.1")}, |
133 {Map.of("releaseVersion", new ArrayList<Long>())}, |
135 {Map.of(PROPERTY_RELEASE_VERSION, new ArrayList<Long>())}, |
134 {Map.of("releaseVersion", Integer.valueOf(0))}, |
136 {Map.of(PROPERTY_RELEASE_VERSION, Integer.valueOf(0))}, |
135 {Map.of("releaseVersion", Integer.valueOf(-1))} |
137 {Map.of(PROPERTY_RELEASE_VERSION, Integer.valueOf(-1))} |
136 }; |
138 }; |
137 } |
139 } |
138 |
140 |
139 // Not the best test but all I can do since ZipFileSystem and JarFileSystem |
141 // Not the best test but all I can do since ZipFileSystem |
140 // are not public, so I can't use (fs instanceof ...) |
142 // is not public, so I can't use (fs instanceof ...) |
141 @Test |
143 @Test |
142 public void testNewFileSystem() throws Exception { |
144 public void testNewFileSystem() throws Exception { |
143 Map<String,String> env = new HashMap<>(); |
145 Map<String,String> env = new HashMap<>(); |
144 // no configuration, treat multi-release jar as unversioned |
146 // no configuration, treat multi-release jar as unversioned |
145 try (FileSystem fs = FileSystems.newFileSystem(mruri, env)) { |
147 try (FileSystem fs = FileSystems.newFileSystem(mruri, env)) { |
146 Assert.assertTrue(readAndCompare(fs, 8)); |
148 Assert.assertTrue(readAndCompare(fs, 8)); |
147 } |
149 } |
148 env.put("releaseVersion", "runtime"); |
150 env.put(PROPERTY_RELEASE_VERSION, "runtime"); |
149 // a configuration and jar file is multi-release |
151 // a configuration and jar file is multi-release |
150 try (FileSystem fs = FileSystems.newFileSystem(mruri, env)) { |
152 try (FileSystem fs = FileSystems.newFileSystem(mruri, env)) { |
151 Assert.assertTrue(readAndCompare(fs, MAJOR_VERSION)); |
153 Assert.assertTrue(readAndCompare(fs, MAJOR_VERSION)); |
152 } |
154 } |
153 // a configuration but jar file is unversioned |
155 // a configuration but jar file is unversioned |
161 String src = new String(Files.readAllBytes(path)); |
163 String src = new String(Files.readAllBytes(path)); |
162 return src.contains("return " + expected); |
164 return src.contains("return " + expected); |
163 } |
165 } |
164 |
166 |
165 @Test(dataProvider="strings") |
167 @Test(dataProvider="strings") |
166 public void testStrings(String value, int expected) throws Throwable { |
168 public void testStrings(String value, int expected, String ignorable) throws Throwable { |
167 stringEnv.put("releaseVersion", value); |
169 stringEnv.clear(); |
|
170 stringEnv.put(PROPERTY_RELEASE_VERSION, value); |
|
171 // we check, that values for "multi-release" are ignored |
|
172 stringEnv.put(PROPERTY_MULTI_RELEASE, ignorable); |
168 runTest(stringEnv, expected); |
173 runTest(stringEnv, expected); |
169 } |
174 } |
170 |
175 |
171 @Test(dataProvider="integers") |
176 @Test(dataProvider="integers") |
172 public void testIntegers(Integer value, int expected) throws Throwable { |
177 public void testIntegers(Integer value, int expected, Integer ignorable) throws Throwable { |
173 integerEnv.put("releaseVersion", value); |
178 integerEnv.clear(); |
|
179 integerEnv.put(PROPERTY_RELEASE_VERSION, value); |
|
180 // we check, that values for "multi-release" are ignored |
|
181 integerEnv.put(PROPERTY_MULTI_RELEASE, value); |
174 runTest(integerEnv, expected); |
182 runTest(integerEnv, expected); |
175 } |
183 } |
176 |
184 |
177 @Test(dataProvider="versions") |
185 @Test(dataProvider="versions") |
178 public void testVersions(Version value, int expected) throws Throwable { |
186 public void testVersions(Version value, int expected, Version ignorable) throws Throwable { |
179 versionEnv.put("releaseVersion", value); |
187 versionEnv.clear(); |
|
188 versionEnv.put(PROPERTY_RELEASE_VERSION, value); |
|
189 // we check, that values for "multi-release" are ignored |
|
190 versionEnv.put(PROPERTY_MULTI_RELEASE, ignorable); |
180 runTest(versionEnv, expected); |
191 runTest(versionEnv, expected); |
181 } |
192 } |
182 |
193 |
183 @Test |
194 @Test |
184 public void testShortJar() throws Throwable { |
195 public void testShortJar() throws Throwable { |
185 integerEnv.put("releaseVersion", Integer.valueOf(MAJOR_VERSION)); |
196 integerEnv.clear(); |
|
197 integerEnv.put(PROPERTY_RELEASE_VERSION, Integer.valueOf(MAJOR_VERSION)); |
186 runTest(smruri, integerEnv, MAJOR_VERSION); |
198 runTest(smruri, integerEnv, MAJOR_VERSION); |
187 integerEnv.put("releaseVersion", Integer.valueOf(9)); |
199 integerEnv.put(PROPERTY_RELEASE_VERSION, Integer.valueOf(9)); |
188 runTest(smruri, integerEnv, 8); |
200 runTest(smruri, integerEnv, 8); |
189 } |
201 } |
190 |
202 |
191 /** |
203 /** |
192 * Validate that an invalid value for the "releaseVersion" property throws |
204 * Validate that an invalid value for the "releaseVersion" property throws |
203 } |
215 } |
204 |
216 |
205 // The following tests are for backwards compatibility to validate that |
217 // The following tests are for backwards compatibility to validate that |
206 // the original property still works |
218 // the original property still works |
207 @Test(dataProvider="strings") |
219 @Test(dataProvider="strings") |
208 public void testMRStrings(String value, int expected) throws Throwable { |
220 public void testMRStrings(String value, int expected, String ignorable) throws Throwable { |
209 stringEnv.clear(); |
221 stringEnv.clear(); |
210 stringEnv.put("multi-release", value); |
222 stringEnv.put(PROPERTY_MULTI_RELEASE, value); |
211 runTest(stringEnv, expected); |
223 runTest(stringEnv, expected); |
212 } |
224 } |
213 |
225 |
214 @Test(dataProvider="integers") |
226 @Test(dataProvider="integers") |
215 public void testMRIntegers(Integer value, int expected) throws Throwable { |
227 public void testMRIntegers(Integer value, int expected, Integer ignorable) throws Throwable { |
216 integerEnv.clear(); |
228 integerEnv.clear(); |
217 integerEnv.put("multi-release", value); |
229 integerEnv.put(PROPERTY_MULTI_RELEASE, value); |
218 runTest(integerEnv, expected); |
230 runTest(integerEnv, expected); |
219 } |
231 } |
220 |
232 |
221 @Test(dataProvider="versions") |
233 @Test(dataProvider="versions") |
222 public void testMRVersions(Version value, int expected) throws Throwable { |
234 public void testMRVersions(Version value, int expected, Version ignorable) throws Throwable { |
223 versionEnv.clear(); |
235 versionEnv.clear(); |
224 versionEnv.put("multi-release", value); |
236 versionEnv.put(PROPERTY_MULTI_RELEASE, value); |
225 runTest(versionEnv, expected); |
237 runTest(versionEnv, expected); |
226 } |
238 } |
227 |
239 |
228 private void runTest(Map<String,?> env, int expected) throws Throwable { |
240 private void runTest(Map<String,?> env, int expected) throws Throwable { |
229 runTest(mruri, env, expected); |
241 runTest(mruri, env, expected); |