diff options
author | Sopot Cela | 2016-04-19 11:29:19 +0000 |
---|---|---|
committer | Thomas Watson | 2016-04-26 15:51:28 +0000 |
commit | f58a823fd7d1e414607f2bc671312a2acf2ed728 (patch) | |
tree | efaae5e969dc89e2e74bf121a5a887290656c7cf /bundles/org.eclipse.equinox.security.tests | |
parent | 00920f9106e614eff9f89ff334ef0df1809fe88c (diff) | |
download | rt.equinox.bundles-f58a823fd7d1e414607f2bc671312a2acf2ed728.tar.gz rt.equinox.bundles-f58a823fd7d1e414607f2bc671312a2acf2ed728.tar.xz rt.equinox.bundles-f58a823fd7d1e414607f2bc671312a2acf2ed728.zip |
Bug 490273 - Move tests to JUnit 4Y20160428-1430Y20160428-1000I20160504-0035I20160503-2000I20160502-2000I20160501-2000I20160430-2000I20160429-2300I20160429-2000I20160428-0800I20160427-2000I20160427-1200I20160427-0800I20160427-0400I20160426-2330I20160426-2000I20160426-1615
Port of security tests
Change-Id: I356c711a6519629d037ceb47a92305b685f72287
Signed-off-by: Sopot Cela <scela@redhat.com>
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.security.tests')
15 files changed, 134 insertions, 188 deletions
diff --git a/bundles/org.eclipse.equinox.security.tests/.classpath b/bundles/org.eclipse.equinox.security.tests/.classpath index 2fbb7a23e..64c5e31b7 100644 --- a/bundles/org.eclipse.equinox.security.tests/.classpath +++ b/bundles/org.eclipse.equinox.security.tests/.classpath @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> diff --git a/bundles/org.eclipse.equinox.security.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.security.tests/.settings/org.eclipse.jdt.core.prefs index bc54588f1..cad33f4eb 100644 --- a/bundles/org.eclipse.equinox.security.tests/.settings/org.eclipse.jdt.core.prefs +++ b/bundles/org.eclipse.equinox.security.tests/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,3 @@ -#Tue Jan 22 17:24:37 EST 2008 eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true org.eclipse.jdt.core.builder.cleanOutputFolder=clean @@ -8,24 +7,24 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.doc.comment.support=enabled org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.deprecation=warning org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled org.eclipse.jdt.core.compiler.problem.fieldHiding=warning @@ -84,7 +83,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 @@ -156,7 +155,12 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert diff --git a/bundles/org.eclipse.equinox.security.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.security.tests/META-INF/MANIFEST.MF index b2a5243d0..29ea78163 100644 --- a/bundles/org.eclipse.equinox.security.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.security.tests/META-INF/MANIFEST.MF @@ -4,7 +4,7 @@ Bundle-Name: Equinox security tests Bundle-SymbolicName: org.eclipse.equinox.security.tests;singleton:=true Bundle-Version: 1.0.100.qualifier Bundle-Activator: org.eclipse.equinox.internal.security.tests.SecurityTestsActivator -Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-Vendor: Eclipse.org Require-Bundle: org.eclipse.core.tests.harness;bundle-version="3.4.0", org.junit, diff --git a/bundles/org.eclipse.equinox.security.tests/build.properties b/bundles/org.eclipse.equinox.security.tests/build.properties index af624074a..4c0bfa336 100644 --- a/bundles/org.eclipse.equinox.security.tests/build.properties +++ b/bundles/org.eclipse.equinox.security.tests/build.properties @@ -13,9 +13,7 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ about.html,\ - plugin.xml,\ Plugin_Testing/,\ test.xml,\ SecurePrefsSample/ -src.includes = about.html,\ - src/ +src.includes = about.html diff --git a/bundles/org.eclipse.equinox.security.tests/plugin.xml b/bundles/org.eclipse.equinox.security.tests/plugin.xml deleted file mode 100644 index 50c2e3161..000000000 --- a/bundles/org.eclipse.equinox.security.tests/plugin.xml +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?eclipse version="3.2"?> -<plugin> - -</plugin> diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/Base64Test.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/Base64Test.java index 5e2aa3a68..1ee550f86 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/Base64Test.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/Base64Test.java @@ -10,11 +10,15 @@ *******************************************************************************/ package org.eclipse.equinox.internal.security.tests.storage; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import java.util.Random; -import junit.framework.*; import org.eclipse.equinox.security.storage.EncodingUtils; +import org.junit.Test; -public class Base64Test extends TestCase { +public class Base64Test { /** * Number of random-generated round trip tests to run @@ -39,17 +43,10 @@ public class Base64Test extends TestCase { final private static String decoded6 = "a"; final private static String encoded6 = "YQ=="; // tests array bounds - public Base64Test() { - super(); - } - - public Base64Test(String name) { - super(name); - } - /** * Tests encoding using hand-calculated examples. */ + @Test public void testHandCoded() { String encoded = EncodingUtils.encodeBase64(decoded1.getBytes()); assertEquals(encoded1, encoded); @@ -75,6 +72,7 @@ public class Base64Test extends TestCase { /** * Tests edge conditions: null or empty arguments */ + @Test public void testEdge() { assertNull(EncodingUtils.encodeBase64(null)); assertNull(EncodingUtils.decodeBase64(null)); @@ -90,6 +88,7 @@ public class Base64Test extends TestCase { /** * Tests round trip using large random sequences */ + @Test public void testRandom() { Random generator = new Random(System.currentTimeMillis()); @@ -114,7 +113,4 @@ public class Base64Test extends TestCase { assertEquals(array1[i], array2[i]); } - public static Test suite() { - return new TestSuite(Base64Test.class); - } } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/DefaultPreferencesTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/DefaultPreferencesTest.java index edc591a42..30662e8b8 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/DefaultPreferencesTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/DefaultPreferencesTest.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.equinox.internal.security.tests.storage; -import junit.framework.Test; -import junit.framework.TestSuite; - /** * Uses whatever default module is provided for the current installation. */ @@ -21,8 +18,4 @@ public class DefaultPreferencesTest extends SecurePreferencesTest { protected String getModuleID() { return null; } - - public static Test suite() { - return new TestSuite(DefaultPreferencesTest.class); - } } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/DynamicPreferencesTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/DynamicPreferencesTest.java index 53013b347..34aad9c03 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/DynamicPreferencesTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/DynamicPreferencesTest.java @@ -10,17 +10,20 @@ *******************************************************************************/ package org.eclipse.equinox.internal.security.tests.storage; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestSuite; import org.eclipse.core.tests.harness.BundleTestingHelper; import org.eclipse.equinox.internal.security.storage.StorageUtils; import org.eclipse.equinox.internal.security.tests.SecurityTestsActivator; import org.eclipse.equinox.security.storage.ISecurePreferences; import org.eclipse.equinox.security.storage.StorageException; +import org.junit.Test; import org.osgi.framework.*; /** @@ -43,14 +46,6 @@ public class DynamicPreferencesTest extends StorageAbstractTest { final private static String clearTextKey = "data"; final private static String clearTextValue = "-> this should not be encrypted <-"; - public DynamicPreferencesTest() { - super(); - } - - public DynamicPreferencesTest(String name) { - super(name); - } - private void check(ISecurePreferences prefs) throws StorageException { ISecurePreferences node1 = prefs.node("/abc"); assertEquals(value, node1.get(key, defaultValue)); @@ -60,6 +55,7 @@ public class DynamicPreferencesTest extends StorageAbstractTest { /** * Test dynamic behavior while secure preferences remain in memory */ + @Test public void testDynamicMemory() throws Exception { Bundle bundle01 = null; @@ -110,6 +106,7 @@ public class DynamicPreferencesTest extends StorageAbstractTest { /** * Test dynamic behavior with persisted secure preferences */ + @Test public void testDynamicPersisted() throws Exception { URL location = getStorageLocation(); assertNotNull(location); @@ -176,7 +173,7 @@ public class DynamicPreferencesTest extends StorageAbstractTest { assertTrue(exception); } - protected Map getOptions() { + protected Map<String, Object> getOptions() { // Don't specify default password for those tests; they need to have // password providers return getOptions(null); @@ -226,7 +223,4 @@ public class DynamicPreferencesTest extends StorageAbstractTest { } } - public static Test suite() { - return new TestSuite(DynamicPreferencesTest.class); - } } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/ManualTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/ManualTest.java index c53e40fbe..60caeb3e4 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/ManualTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/ManualTest.java @@ -10,34 +10,29 @@ *******************************************************************************/ package org.eclipse.equinox.internal.security.tests.storage; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.security.Provider; import java.security.Security; import java.util.*; -import junit.framework.*; import org.eclipse.equinox.security.storage.*; import org.eclipse.equinox.security.storage.provider.IProviderHints; +import org.junit.Test; /** * This is a semi-manual test; expected to be run with modules requiring * UI interactions. Set configuration before executing this so that desired * storage module is selected. */ -public class ManualTest extends TestCase { +public class ManualTest { static private final String JAVA_MODULE_ID = "org.eclipse.equinox.security.javaCrypt"; //$NON-NLS-1$ - public ManualTest() { - super(); - } - - public ManualTest(String name) { - super(name); - } - final private String passwordSample = "uYTIU689_~@@/"; final private String loginSample = "cheburashka"; + @Test public void testBasic() { // Note that this skips Alg.Alias.Cipher.ABC @@ -45,8 +40,8 @@ public class ManualTest extends TestCase { // aliases from internal ones Provider[] providers = Security.getProviders(); for (int i = 0; i < providers.length; i++) { - for (Iterator j = providers[i].entrySet().iterator(); j.hasNext();) { - Map.Entry entry = (Map.Entry) j.next(); + for (Iterator<Map.Entry<Object, Object>> j = providers[i].entrySet().iterator(); j.hasNext();) { + Map.Entry<Object, Object> entry = j.next(); String key = (String) entry.getKey(); if (key == null) continue; @@ -75,8 +70,8 @@ public class ManualTest extends TestCase { [keyFactory] PBEWithSHA1AndDESede [keyFactory] PBEWithMD5AndTripleDES [keyFactory] PBEWithMD5AndDES - - + + [cypher] DES [cypher] Blowfish [cypher] RC2 @@ -90,7 +85,7 @@ public class ManualTest extends TestCase { [cypher] PBEWithSHA1AndRC2_40 [cypher] PBEWithSHA1AndDESede [cypher] DESedeWrap - + http://java.sun.com/javase/6/docs/technotes/guides/security/StandardNames.html#SecretKeyFactory http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html#AppA */ @@ -100,9 +95,10 @@ public class ManualTest extends TestCase { /** * Manual test for Java module to see password prompt functionality */ + @Test public void testJavaModule() throws IOException, StorageException { // manual test for the Java module - Map options = new HashMap(1); + Map<String, Object> options = new HashMap<String, Object>(1); options.put(IProviderHints.REQUIRED_MODULE_ID, JAVA_MODULE_ID); ISecurePreferences storage = SecurePreferencesFactory.open(null, options); ISecurePreferences node = storage.node("/cvs/account1"); @@ -112,8 +108,4 @@ public class ManualTest extends TestCase { assertEquals(passwordSample, node.get("password", null)); } - public static Test suite() { - return new TestSuite(ManualTest.class); - } - } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SecurePreferencesTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SecurePreferencesTest.java index f6b945e3e..57648cf03 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SecurePreferencesTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SecurePreferencesTest.java @@ -10,17 +10,22 @@ *******************************************************************************/ package org.eclipse.equinox.internal.security.tests.storage; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestSuite; import org.eclipse.core.runtime.FileLocator; import org.eclipse.equinox.internal.security.storage.friends.InternalExchangeUtils; import org.eclipse.equinox.internal.security.tests.SecurityTestsActivator; import org.eclipse.equinox.security.storage.ISecurePreferences; import org.eclipse.equinox.security.storage.StorageException; +import org.junit.Test; import org.osgi.framework.BundleContext; abstract public class SecurePreferencesTest extends StorageAbstractTest { @@ -45,15 +50,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { final private static String unicodeKey = "unicodeKey"; final private static String unicodeValue = "va\u0432lue\u0433"; - public SecurePreferencesTest() { - super(); - } - - public SecurePreferencesTest(String name) { - super(name); - } - - protected Map getOptions() { + protected Map<String, Object> getOptions() { // Note that if the default password value below is modified, // the sample storage file needs to be regenerated. return getOptions("password1"); @@ -125,6 +122,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { * Basic test to fill / read Preferences implementation. Also tests removal of a value * and Preferences#keys(). */ + @Test public void testPreferences() throws IOException, StorageException { URL location = getStorageLocation(); assertNotNull(location); @@ -144,6 +142,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { * Test relative names, absolute names, and children names * @throws StorageException */ + @Test public void testNames() throws IOException, StorageException { ISecurePreferences preferences = newPreferences(getStorageLocation(), getOptions()); fill(preferences); @@ -194,6 +193,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { * Test node existence, resolution: parent -> child; child -> parent, * compare absolute and relative paths. */ + @Test public void testNodeResolution() throws IOException, StorageException { ISecurePreferences preferences = newPreferences(getStorageLocation(), getOptions()); fill(preferences); @@ -253,6 +253,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { * Tests node removal. * @throws StorageException */ + @Test public void testNodeRemoval() throws IOException, StorageException { URL location = getStorageLocation(); assertNotNull(location); @@ -312,6 +313,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { * Tests validation of node paths. * @throws Throwable */ + @Test public void testPathValidation() throws Throwable { ISecurePreferences preferences = newPreferences(getStorageLocation(), getOptions()); boolean exception = false; @@ -342,6 +344,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { /** * Tests URL validation. */ + @Test public void testLocation() throws MalformedURLException { URL invalidURL = new URL("http", "eclipse.org", "testEquinoxFile"); boolean exception = false; @@ -359,6 +362,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { * @throws IOException * @throws MalformedURLException */ + @Test public void testDataTypes() throws StorageException, MalformedURLException, IOException { ISecurePreferences preferences = newPreferences(getStorageLocation(), getOptions()); @@ -400,6 +404,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { /** * Tests corrupted encrypted data. */ + @Test public void testIncorrectData() throws IOException { URL location = getFilePath(sampleLocation); // Same default password as in the SecurePreferencesTest.getOptions() - same note @@ -433,9 +438,10 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { /** * Tests incorrect passwords */ + @Test public void testIncorrectPassword() throws IOException { URL location = getFilePath(sampleLocation); - Map options = getOptions("wrong"); + Map<String, Object> options = getOptions("wrong"); ISecurePreferences preferences = newPreferences(location, options); try { ISecurePreferences node = preferences.node("/cvs/eclipse.org"); @@ -456,6 +462,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { /** * Tests incorrect or unexpected module specifications */ + @Test public void testModules() throws IOException { URL location = getFilePath(sampleLocation); ISecurePreferences preferences = newPreferences(location, getOptions(null)); @@ -490,6 +497,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { /** * Tests edge cases for data (nulls, empty strings, and so on). */ + @Test public void testEdgeCases() throws StorageException, MalformedURLException, IOException { byte[] expectedEmptyArray = new byte[0]; byte[] wrongArray = new byte[] {1, 2, 3}; @@ -568,7 +576,4 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest { return FileLocator.toFileURL(url); } - public static Test suite() { - return new TestSuite(SecurePreferencesTest.class); - } } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SlashEncodeTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SlashEncodeTest.java index f33d6c82a..c898a4f00 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SlashEncodeTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/SlashEncodeTest.java @@ -10,25 +10,21 @@ *******************************************************************************/ package org.eclipse.equinox.internal.security.tests.storage; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.net.URL; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestSuite; import org.eclipse.equinox.internal.security.storage.StorageUtils; import org.eclipse.equinox.security.storage.*; -import org.osgi.service.prefs.BackingStoreException; +import org.junit.Test; public class SlashEncodeTest extends StorageAbstractTest { - public SlashEncodeTest() { - super(); - } - - public SlashEncodeTest(String name) { - super(name); - } - final private static String[] decodedSlash = {"root", "ro/ot", "/root", "root/", "ro/ot/me", "ro//ot"}; final private static String[] encodedSlash = {"root", "ro\\2fot", "\\2froot", "root\\2f", "ro\\2fot\\2fme", "ro\\2f\\2fot"}; @@ -41,6 +37,7 @@ public class SlashEncodeTest extends StorageAbstractTest { /** * Tests forward slash */ + @Test public void testForwardSlash() { for (int i = 0; i < decodedSlash.length; i++) { String tmp = EncodingUtils.encodeSlashes(decodedSlash[i]); @@ -52,6 +49,7 @@ public class SlashEncodeTest extends StorageAbstractTest { /** * Tests backward slash */ + @Test public void testBackwardSlash() { for (int i = 0; i < decodedBackSlash.length; i++) { String tmp = EncodingUtils.encodeSlashes(decodedBackSlash[i]); @@ -63,6 +61,7 @@ public class SlashEncodeTest extends StorageAbstractTest { /** * Tests mixed slashes */ + @Test public void testMixSlash() { for (int i = 0; i < decodedMixSlash.length; i++) { String tmp = EncodingUtils.encodeSlashes(decodedMixSlash[i]); @@ -74,6 +73,7 @@ public class SlashEncodeTest extends StorageAbstractTest { /** * Tests edge conditions: null or empty arguments */ + @Test public void testEdge() { assertNull(EncodingUtils.encodeSlashes(null)); assertNull(EncodingUtils.decodeSlashes(null)); @@ -83,7 +83,7 @@ public class SlashEncodeTest extends StorageAbstractTest { assertEquals("", encoded); } - protected Map getOptions() { + protected Map<String, Object> getOptions() { // Password value really doesn't matter here; we specify it to avoid // triggering UI elements in case default password provider has the // highest priority in the tested configuration @@ -96,6 +96,7 @@ public class SlashEncodeTest extends StorageAbstractTest { * @throws BackingStoreException * @throws */ + @Test public void testPreferencesWithSlashes() throws IOException, StorageException { URL location = getStorageLocation(); assertNotNull(location); @@ -125,8 +126,4 @@ public class SlashEncodeTest extends StorageAbstractTest { } StorageUtils.delete(location); } - - public static Test suite() { - return new TestSuite(SlashEncodeTest.class); - } } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/StorageAbstractTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/StorageAbstractTest.java index 2b8d263a3..902f89192 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/StorageAbstractTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/StorageAbstractTest.java @@ -15,48 +15,40 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.*; import javax.crypto.spec.PBEKeySpec; -import junit.framework.TestCase; import org.eclipse.core.runtime.IPath; import org.eclipse.core.tests.harness.FileSystemHelper; import org.eclipse.equinox.internal.security.storage.*; import org.eclipse.equinox.security.storage.ISecurePreferences; import org.eclipse.equinox.security.storage.SecurePreferencesFactory; import org.eclipse.equinox.security.storage.provider.IProviderHints; +import org.junit.After; /** * Temp directory is used for storage. */ -public class StorageAbstractTest extends TestCase { +public class StorageAbstractTest { final protected String defaultFileName = "secure_storage_test.equinox"; - private List openPreferences = new ArrayList(5); // <ISecurePreferences> - - public StorageAbstractTest() { - super(); - } - - public StorageAbstractTest(String name) { - super(name); - } + private List<ISecurePreferences> openPreferences = new ArrayList<ISecurePreferences>(5); // <ISecurePreferences> protected String getModuleID() { return null; } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { synchronized (openPreferences) { - for (Iterator i = openPreferences.iterator(); i.hasNext();) { - ISecurePreferences root = (ISecurePreferences) i.next(); + for (Iterator<ISecurePreferences> i = openPreferences.iterator(); i.hasNext();) { + ISecurePreferences root = i.next(); SecurePreferencesMapper.close((((SecurePreferencesWrapper) root).getContainer().getRootData())); URL location = ((SecurePreferencesWrapper) root).getContainer().getLocation(); StorageUtils.delete(location); } } - super.tearDown(); } - protected ISecurePreferences newPreferences(URL location, Map options) throws IOException { + protected ISecurePreferences newPreferences(URL location, Map<String, Object> options) throws IOException { synchronized (openPreferences) { ISecurePreferences result = SecurePreferencesFactory.open(location, options); openPreferences.add(result); @@ -66,8 +58,8 @@ public class StorageAbstractTest extends TestCase { protected void closePreferences(ISecurePreferences root) { synchronized (openPreferences) { - for (Iterator i = openPreferences.iterator(); i.hasNext();) { - ISecurePreferences element = (ISecurePreferences) i.next(); + for (Iterator<ISecurePreferences> i = openPreferences.iterator(); i.hasNext();) { + ISecurePreferences element = i.next(); if (element.equals(root)) { SecurePreferencesMapper.close((((SecurePreferencesWrapper) root).getContainer().getRootData())); i.remove(); @@ -76,8 +68,8 @@ public class StorageAbstractTest extends TestCase { } } - protected Map getOptions(String defaultPassword) { - Map options = new HashMap(); + protected Map<String, Object> getOptions(String defaultPassword) { + Map<String, Object> options = new HashMap<String, Object>(); if (defaultPassword != null) { PBEKeySpec password = new PBEKeySpec(defaultPassword.toCharArray()); @@ -96,6 +88,7 @@ public class StorageAbstractTest extends TestCase { * Might consider switching to configuration location. * @throws MalformedURLException */ + @SuppressWarnings("deprecation") protected URL getStorageLocation() throws MalformedURLException { IPath tempDir = FileSystemHelper.getTempDir(); tempDir = tempDir.append(defaultFileName); diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WaitingRegistryListener.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WaitingRegistryListener.java index 0c6480140..dc9508824 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WaitingRegistryListener.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WaitingRegistryListener.java @@ -12,7 +12,6 @@ package org.eclipse.equinox.internal.security.tests.storage; import java.util.ArrayList; import java.util.List; -import junit.framework.Assert; import org.eclipse.core.runtime.*; /** @@ -21,12 +20,12 @@ import org.eclipse.core.runtime.*; * @since 3.4 * Copied from runtime tests */ -public class WaitingRegistryListener extends Assert implements IRegistryEventListener { +public class WaitingRegistryListener extends org.junit.Assert implements IRegistryEventListener { final static long MIN_WAIT_TIME = 100; // minimum wait time in milliseconds - private List extensionIDs; // String[] - private List extPointIDs; // String[] + private List<String> extensionIDs; // String[] + private List<String> extPointIDs; // String[] private volatile boolean added; private volatile boolean removed; @@ -68,7 +67,7 @@ public class WaitingRegistryListener extends Assert implements IRegistryEventLis public synchronized String[] extensionsReceived(long timeout) { if (extensionIDs != null) - return (String[]) extensionIDs.toArray(new String[extensionIDs.size()]); + return extensionIDs.toArray(new String[0]); try { wait(timeout); } catch (InterruptedException e) { @@ -76,12 +75,12 @@ public class WaitingRegistryListener extends Assert implements IRegistryEventLis } if (extensionIDs == null) return null; - return (String[]) extensionIDs.toArray(new String[extensionIDs.size()]); + return extensionIDs.toArray(new String[0]); } public synchronized String[] extPointsReceived(long timeout) { if (extPointIDs != null) - return (String[]) extPointIDs.toArray(new String[extPointIDs.size()]); + return extPointIDs.toArray(new String[0]); try { wait(timeout); } catch (InterruptedException e) { @@ -89,7 +88,7 @@ public class WaitingRegistryListener extends Assert implements IRegistryEventLis } if (extPointIDs == null) return null; - return (String[]) extPointIDs.toArray(new String[extPointIDs.size()]); + return extPointIDs.toArray(new String[0]); } public synchronized int waitFor(int events, long maxTimeout) { @@ -154,7 +153,7 @@ public class WaitingRegistryListener extends Assert implements IRegistryEventLis } private void extensionsToString(IExtension[] extensions) { - extensionIDs = new ArrayList(extensions.length); + extensionIDs = new ArrayList<String>(extensions.length); for (int i = 0; i < extensions.length; i++) { IExtension extension = extensions[i]; extensionIDs.add(extension.getUniqueIdentifier()); @@ -181,7 +180,7 @@ public class WaitingRegistryListener extends Assert implements IRegistryEventLis } private void extPointsToString(IExtensionPoint[] extensionPoints) { - extPointIDs = new ArrayList(extensionPoints.length); + extPointIDs = new ArrayList<String>(extensionPoints.length); for (int i = 0; i < extensionPoints.length; i++) extPointIDs.add(extensionPoints[i].getUniqueIdentifier()); } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java index d98fb092a..6271a2766 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java @@ -11,8 +11,9 @@ package org.eclipse.equinox.internal.security.tests.storage; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.eclipse.equinox.internal.security.tests.SecurityTestsActivator; +import org.junit.Before; +import org.osgi.framework.*; /** * Tests Windows module, if available. @@ -20,21 +21,40 @@ import junit.framework.TestSuite; */ public class WinPreferencesTest extends SecurePreferencesTest { + final private static String WIN_BUNDLE = "org.eclipse.equinox.security.win32.x86"; + final private static String WIN_64BIT_BUNDLE = "org.eclipse.equinox.security.win32.x86_64"; + private boolean is64Bit = "x86-64".equals(SecurityTestsActivator.getDefault().getBundleContext().getProperty(Constants.FRAMEWORK_PROCESSOR)); + + @Before + public void setUp() { + org.junit.Assume.assumeTrue(hasBundle(is64Bit ? WIN_64BIT_BUNDLE : WIN_BUNDLE)); + } + /** * Unique ID of the Windows module. */ static private final String WIN_MODULE_ID = "org.eclipse.equinox.security.WindowsPasswordProvider"; //$NON-NLS-1$ + static private final String WIN_64BIT_MODULE_ID = "org.eclipse.equinox.security.WindowsPasswordProvider64bit"; //$NON-NLS-1$ protected String getModuleID() { - return WIN_MODULE_ID; + return is64Bit ? WIN_64BIT_MODULE_ID : WIN_MODULE_ID; } - public static Test suite() { - return new TestSuite(WinPreferencesTest.class); - } - - protected Map getOptions() { + protected Map<String, Object> getOptions() { // Don't specify default password when testing specific password provider return getOptions(null); } + + static private boolean hasBundle(String symbolicID) { + BundleContext context = SecurityTestsActivator.getDefault().getBundleContext(); + Bundle[] bundles = context.getBundles(); + for (int i = 0; i < bundles.length; i++) { + String bundleName = bundles[i].getSymbolicName(); + if (!symbolicID.equals(bundleName)) + continue; + int bundleState = bundles[i].getState(); + return (bundleState != Bundle.INSTALLED) && (bundleState != Bundle.UNINSTALLED); + } + return false; + } } diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/security/tests/AllSecurityTests.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/security/tests/AllSecurityTests.java index 72deaaaad..10a69785e 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/security/tests/AllSecurityTests.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/security/tests/AllSecurityTests.java @@ -10,57 +10,17 @@ *******************************************************************************/ package org.eclipse.equinox.security.tests; -import junit.framework.*; -import org.eclipse.equinox.internal.security.tests.SecurityTestsActivator; import org.eclipse.equinox.internal.security.tests.storage.*; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; /** * As tests use registry listeners, UI listeners might cause tests to time out and fail. * As such this tests should be run in a headless mode. */ -public class AllSecurityTests extends TestCase { - - final private static String WIN_BUNDLE = "org.eclipse.equinox.security.win32.x86"; - - public AllSecurityTests() { - super(null); - } - - public AllSecurityTests(String name) { - super(name); - } - - public static Test suite() { - TestSuite suite = new TestSuite(AllSecurityTests.class.getName()); - - // stand-alone test for Base64 - suite.addTest(Base64Test.suite()); - // test node names encoding ("slash eliminator") - suite.addTest(SlashEncodeTest.suite()); - // tests secure Preferences functionality using default provider - suite.addTest(DefaultPreferencesTest.suite()); - // check dynamic additions / removals - suite.addTest(DynamicPreferencesTest.suite()); - - // testing Windows-specific path should only be attempted if bundle is resolved - if (hasBundle(WIN_BUNDLE)) - suite.addTest(WinPreferencesTest.suite()); - - return suite; - } - - static private boolean hasBundle(String symbolicID) { - BundleContext context = SecurityTestsActivator.getDefault().getBundleContext(); - Bundle[] bundles = context.getBundles(); - for (int i = 0; i < bundles.length; i++) { - String bundleName = bundles[i].getSymbolicName(); - if (!symbolicID.equals(bundleName)) - continue; - int bundleState = bundles[i].getState(); - return (bundleState != Bundle.INSTALLED) && (bundleState != Bundle.UNINSTALLED); - } - return false; - } +@RunWith(Suite.class) +@SuiteClasses({Base64Test.class, SlashEncodeTest.class, DefaultPreferencesTest.class, DynamicPreferencesTest.class, WinPreferencesTest.class}) +public class AllSecurityTests { + //see @SuiteClasses } |