diff options
author | Sopot Cela | 2016-04-25 16:08:13 +0000 |
---|---|---|
committer | Sopot Cela | 2016-04-25 16:08:13 +0000 |
commit | 80269cc8c3f47c08b6d36f2a0b1298e0d088f27f (patch) | |
tree | 0a90f1ccba0e1cd6e857d43ac5c0a5b10834a88e /bundles/org.eclipse.equinox.compendium.tests | |
parent | cbfe3daa3a92b858cc0def6d7c94ce127411142a (diff) | |
download | rt.equinox.bundles-80269cc8c3f47c08b6d36f2a0b1298e0d088f27f.tar.gz rt.equinox.bundles-80269cc8c3f47c08b6d36f2a0b1298e0d088f27f.tar.xz rt.equinox.bundles-80269cc8c3f47c08b6d36f2a0b1298e0d088f27f.zip |
Bug 490273 - Move tests to JUnit 4
Port of compendium tests.
Change-Id: Ic717815ca668f5e7309285dadc6706954315afd0
Signed-off-by: Sopot Cela <scela@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.compendium.tests')
30 files changed, 476 insertions, 354 deletions
diff --git a/bundles/org.eclipse.equinox.compendium.tests/.classpath b/bundles/org.eclipse.equinox.compendium.tests/.classpath index 7aa0ba16f..730a16cd0 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/.classpath +++ b/bundles/org.eclipse.equinox.compendium.tests/.classpath @@ -2,7 +2,7 @@ <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="src" output="bundle_tests/metatype/getMinMax.tb1" path="bundles_src/metatype/getMinMax.tb1"/> - <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" output="bundle_tests/metatype/tb1" path="bundles_src/metatype/tb1"/> <classpathentry kind="src" output="bundle_tests/metatype/tb2" path="bundles_src/metatype/tb2"/> diff --git a/bundles/org.eclipse.equinox.compendium.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.compendium.tests/.settings/org.eclipse.jdt.core.prefs index f31f25003..0a67bc6f0 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/.settings/org.eclipse.jdt.core.prefs +++ b/bundles/org.eclipse.equinox.compendium.tests/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,3 @@ -#Tue Aug 21 11:27:47 CDT 2007 eclipse.preferences.version=1 org.eclipse.jdt.core.builder.cleanOutputFolder=clean org.eclipse.jdt.core.builder.duplicateResourceTask=warning @@ -7,24 +6,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=error 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.fieldHiding=warning org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning @@ -72,7 +71,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=en org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error 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 @@ -144,7 +143,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.compendium.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.compendium.tests/META-INF/MANIFEST.MF index 47649d31f..777ef452b 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.compendium.tests/META-INF/MANIFEST.MF @@ -4,18 +4,18 @@ Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.equinox.compendium.tests Bundle-Version: 1.2.0 Bundle-Activator: org.eclipse.equinox.compendium.tests.Activator -Require-Bundle: org.eclipse.core.runtime +Require-Bundle: org.eclipse.core.runtime, + org.junit;bundle-version="4.12.0" Eclipse-LazyStart: true -Import-Package: junit.framework;version="3.8.2", - org.eclipse.equinox.metatype;version="1.2.0", +Import-Package: org.eclipse.equinox.metatype;version="1.2.0", org.eclipse.equinox.metatype.impl;version="1.2.0", org.eclipse.osgi.tests.bundles, org.osgi.framework;version="1.3.0", + org.osgi.service.coordinator;version="1.0", org.osgi.service.event;version="1.1.0", org.osgi.service.metatype;version="1.2", org.osgi.service.packageadmin;version="1.2.0", - org.osgi.service.useradmin;version="1.0", - org.osgi.service.coordinator;version="1.0" -Bundle-RequiredExecutionEnvironment: J2SE-1.4 + org.osgi.service.useradmin;version="1.0" +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-Localization: plugin Bundle-Vendor: %bundleVendor diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/compendium/tests/AllTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/compendium/tests/AllTests.java index c5e518962..a96659e04 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/compendium/tests/AllTests.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/compendium/tests/AllTests.java @@ -10,20 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.compendium.tests; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +@RunWith(Suite.class) +@SuiteClasses({org.eclipse.equinox.coordinator.tests.AllTests.class, org.eclipse.equinox.event.tests.AllTests.class, org.eclipse.equinox.metatype.tests.AllTests.class, org.eclipse.equinox.useradmin.tests.AllTests.class}) public class AllTests { - - public static Test suite() { - TestSuite suite = new TestSuite("Tests for Equinox Compendium"); //$NON-NLS-1$ - suite.addTest(org.eclipse.equinox.metatype.tests.AllTests.suite()); - // Second run for EquinoxMetaTypeService. - suite.addTest(org.eclipse.equinox.metatype.tests.AllTests.suite()); - suite.addTest(org.eclipse.equinox.useradmin.tests.AllTests.suite()); - suite.addTest(org.eclipse.equinox.event.tests.AllTests.suite()); - suite.addTest(org.eclipse.equinox.coordinator.tests.AllTests.suite()); - return suite; - } - + //see @SuiteClasses } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/AllTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/AllTests.java index e2a8557b4..fdebeeeae 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/AllTests.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/AllTests.java @@ -10,15 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.coordinator.tests; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +@RunWith(Suite.class) +@SuiteClasses({CoordinationMaxTimeoutTest.class, ReverseParticipantOrderNotifyTest.class, BugTests.class}) public class AllTests { - public static Test suite() { - TestSuite suite = new TestSuite("Tests for Equinox Coordinator"); //$NON-NLS-1$ - suite.addTestSuite(CoordinationMaxTimeoutTest.class); - suite.addTestSuite(ReverseParticipantOrderNotifyTest.class); - suite.addTestSuite(BugTests.class); - return suite; - } + //see @SuiteClasses } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/BugTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/BugTests.java index e8afdda3e..4d639b1d7 100755 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/BugTests.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/BugTests.java @@ -10,11 +10,18 @@ *******************************************************************************/ package org.eclipse.equinox.coordinator.tests; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import java.lang.ref.WeakReference; +import org.junit.Test; import org.osgi.service.coordinator.Coordination; import org.osgi.service.coordinator.CoordinationException; public class BugTests extends CoordinatorTest { + + @Test public void testBug421487() throws Exception { // Begin a thread coordination on this thread. Coordination c1 = coordinator.begin("c1", 0); //$NON-NLS-1$ @@ -22,7 +29,7 @@ public class BugTests extends CoordinatorTest { Coordination c2 = coordinator.begin("c2", 0); //$NON-NLS-1$ // c2's enclosing coordination will be c1. assertEquals("Wrong enclosing coordination", c1, c2.getEnclosingCoordination()); //$NON-NLS-1$ - WeakReference reference = new WeakReference(c1); + WeakReference<Coordination> reference = new WeakReference<Coordination>(c1); // Set c1 to null so it will become weakly reachable and enqueued. c1 = null; // Ensure c1 becomes weakly reachable. diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinationMaxTimeoutTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinationMaxTimeoutTest.java index a44294eab..3933e1eb8 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinationMaxTimeoutTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinationMaxTimeoutTest.java @@ -10,7 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.coordinator.tests; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.eclipse.equinox.compendium.tests.Activator; +import org.junit.Before; +import org.junit.Test; import org.osgi.service.coordinator.*; /* @@ -24,6 +29,7 @@ public class CoordinationMaxTimeoutTest extends CoordinatorTest { private static final String PROPERTY_NAME = "org.eclipse.equinox.coordinator.timeout"; //$NON-NLS-1$ private static final long TIMEOUT = 5000; + @Test public void testMaxTimeoutWithNoTimeout() throws Exception { long start = System.currentTimeMillis(); Coordination c = coordinator.create("c", 0); //$NON-NLS-1$ @@ -41,6 +47,7 @@ public class CoordinationMaxTimeoutTest extends CoordinatorTest { } } + @Test public void testMaxTimeoutWithGreaterTimeout() throws Exception { long start = System.currentTimeMillis(); Coordination c = coordinator.create("c", 10000); //$NON-NLS-1$ @@ -58,6 +65,7 @@ public class CoordinationMaxTimeoutTest extends CoordinatorTest { } } + @Test public void testMaxTimeoutWithLesserTimeout() throws Exception { long start = System.currentTimeMillis(); long timeout = 2000; @@ -76,6 +84,7 @@ public class CoordinationMaxTimeoutTest extends CoordinatorTest { } } + @Test public void testExtendTimeoutWhenMaxTimeoutAlreadyReached() throws Exception { long start = System.currentTimeMillis(); Coordination c = coordinator.create("c", 0); //$NON-NLS-1$ @@ -92,6 +101,7 @@ public class CoordinationMaxTimeoutTest extends CoordinatorTest { } } + @Test public void testExtendTimeoutWhenMaxTimeoutNotAlreadyReached() throws Exception { long start = System.currentTimeMillis(); long timeout = 1500; @@ -113,11 +123,12 @@ public class CoordinationMaxTimeoutTest extends CoordinatorTest { } } + @Test public void testNoMaxTimeoutWithTimeout() throws Exception { Activator.getBundleContext().ungetService(coordinatorRef); System.setProperty(PROPERTY_NAME, String.valueOf(0)); - coordinatorRef = Activator.getBundleContext().getServiceReference(Coordinator.class.getName()); - coordinator = (Coordinator) Activator.getBundleContext().getService(coordinatorRef); + coordinatorRef = Activator.getBundleContext().getServiceReference(Coordinator.class); + coordinator = Activator.getBundleContext().getService(coordinatorRef); long start = System.currentTimeMillis(); long timeout = 2000; Coordination c = coordinator.create("c", timeout); //$NON-NLS-1$ @@ -135,7 +146,8 @@ public class CoordinationMaxTimeoutTest extends CoordinatorTest { } } - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { System.setProperty(PROPERTY_NAME, String.valueOf(TIMEOUT)); assertSystemProperty(PROPERTY_NAME, String.valueOf(TIMEOUT)); assertFrameworkProperty(PROPERTY_NAME, String.valueOf(TIMEOUT)); diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinatorTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinatorTest.java index 50ec0cc71..a1642ca93 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinatorTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinatorTest.java @@ -10,22 +10,25 @@ *******************************************************************************/ package org.eclipse.equinox.coordinator.tests; -import junit.framework.TestCase; import org.eclipse.equinox.compendium.tests.Activator; +import org.junit.After; +import org.junit.Before; import org.osgi.framework.ServiceReference; import org.osgi.service.coordinator.Coordinator; -public abstract class CoordinatorTest extends TestCase { +public abstract class CoordinatorTest { protected Coordinator coordinator; - protected ServiceReference coordinatorRef; + protected ServiceReference<Coordinator> coordinatorRef; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Activator.getBundle(Activator.BUNDLE_COORDINATOR).start(); - coordinatorRef = Activator.getBundleContext().getServiceReference(Coordinator.class.getName()); - coordinator = (Coordinator) Activator.getBundleContext().getService(coordinatorRef); + coordinatorRef = Activator.getBundleContext().getServiceReference(Coordinator.class); + coordinator = Activator.getBundleContext().getService(coordinatorRef); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { Activator.getBundleContext().ungetService(coordinatorRef); Activator.getBundle(Activator.BUNDLE_COORDINATOR).stop(); } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/ReverseParticipantOrderNotifyTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/ReverseParticipantOrderNotifyTest.java index fffab7c87..50fad5a1a 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/ReverseParticipantOrderNotifyTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/ReverseParticipantOrderNotifyTest.java @@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.coordinator.tests; +import static org.junit.Assert.assertEquals; + import java.util.*; +import org.junit.Test; import org.osgi.service.coordinator.Coordination; import org.osgi.service.coordinator.Participant; @@ -22,9 +25,9 @@ import org.osgi.service.coordinator.Participant; */ public class ReverseParticipantOrderNotifyTest extends CoordinatorTest { private static class TestParticipant implements Participant { - private final List participants; + private final List<TestParticipant> participants; - public TestParticipant(List participants) { + public TestParticipant(List<TestParticipant> participants) { this.participants = participants; } @@ -37,9 +40,10 @@ public class ReverseParticipantOrderNotifyTest extends CoordinatorTest { } } + @Test public void testReverseParticipateOrderNotifyEnded() { - List before = new ArrayList(); - List after = Collections.synchronizedList(new ArrayList()); + List<Participant> before = new ArrayList<Participant>(); + List<TestParticipant> after = Collections.synchronizedList(new ArrayList<TestParticipant>()); Coordination c = coordinator.create("c", 0); //$NON-NLS-1$ for (int i = 0; i < 10; i++) { Participant p = new TestParticipant(after); @@ -51,9 +55,10 @@ public class ReverseParticipantOrderNotifyTest extends CoordinatorTest { assertEquals("Not notified in reverse participation order", before, after); //$NON-NLS-1$ } + @Test public void testReverseParticipateOrderNotifyFailed() { - List before = new ArrayList(); - List after = Collections.synchronizedList(new ArrayList()); + List<Participant> before = new ArrayList<Participant>(); + List<TestParticipant> after = Collections.synchronizedList(new ArrayList<TestParticipant>()); Coordination c = coordinator.begin("c", 0); //$NON-NLS-1$ for (int i = 0; i < 10; i++) { Participant p = new TestParticipant(after); diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/AllTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/AllTests.java index 274e9813f..dcd23e42e 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/AllTests.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/AllTests.java @@ -10,13 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.event.tests; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +@RunWith(Suite.class) +@SuiteClasses(EventAdminTest.class) public class AllTests { - public static Test suite() { - TestSuite suite = new TestSuite("Tests for Equinox EventAdmin"); //$NON-NLS-1$ - suite.addTestSuite(EventAdminTest.class); - return suite; - } + //see @SuiteClasses } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventAdminTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventAdminTest.java index 2da46fbe5..5f4c7dada 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventAdminTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventAdminTest.java @@ -10,24 +10,29 @@ *******************************************************************************/ package org.eclipse.equinox.event.tests; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import java.util.Dictionary; import java.util.Hashtable; -import junit.framework.TestCase; import org.eclipse.equinox.compendium.tests.Activator; +import org.junit.*; import org.osgi.framework.*; import org.osgi.service.event.*; -public class EventAdminTest extends TestCase { +public class EventAdminTest { private EventAdmin eventAdmin; - private ServiceReference eventAdminReference; + private ServiceReference<EventAdmin> eventAdminReference; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Activator.getBundle(Activator.BUNDLE_EVENT).start(); - eventAdminReference = Activator.getBundleContext().getServiceReference(EventAdmin.class.getName()); - eventAdmin = (EventAdmin) Activator.getBundleContext().getService(eventAdminReference); + eventAdminReference = Activator.getBundleContext().getServiceReference(EventAdmin.class); + eventAdmin = Activator.getBundleContext().getService(eventAdminReference); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { Activator.getBundleContext().ungetService(eventAdminReference); Activator.getBundle(Activator.BUNDLE_EVENT).stop(); } @@ -38,13 +43,14 @@ public class EventAdminTest extends TestCase { * * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=325064. */ + @Test public void testEventDeliveryForWildcardTopic1() { - Dictionary properties = new Hashtable(); + Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$ BundleContext bundleContext = Activator.getBundleContext(); EventHandlerHelper handler = new EventHandlerHelper(); - ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); - Event event = new Event("a/b/c", (Dictionary) null); //$NON-NLS-1$ + ServiceRegistration<EventHandler> handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); + Event event = new Event("a/b/c", (Dictionary<String, Object>) null); //$NON-NLS-1$ eventAdmin.sendEvent(event); assertNull("Received event published to topic 'a/b/c' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$ handlerRegistration.unregister(); @@ -54,13 +60,14 @@ public class EventAdminTest extends TestCase { * Ensures EventAdmin does not deliver an event published on topic "a/b" to * an EventHandler listening to topic a/b/c/*. */ + @Test public void testEventDeliveryForWildcardTopic2() { - Dictionary properties = new Hashtable(); + Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$ BundleContext bundleContext = Activator.getBundleContext(); EventHandlerHelper handler = new EventHandlerHelper(); - ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); - Event event = new Event("a/b", (Dictionary) null); //$NON-NLS-1$ + ServiceRegistration<EventHandler> handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); + Event event = new Event("a/b", (Dictionary<String, Object>) null); //$NON-NLS-1$ eventAdmin.sendEvent(event); assertNull("Received event published to topic 'a/b' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$ handlerRegistration.unregister(); @@ -70,13 +77,14 @@ public class EventAdminTest extends TestCase { * Ensures EventAdmin does not deliver an event published on topic "a" to * an EventHandler listening to topic a/b/c/*. */ + @Test public void testEventDeliveryForWildcardTopic3() { - Dictionary properties = new Hashtable(); + Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$ BundleContext bundleContext = Activator.getBundleContext(); EventHandlerHelper handler = new EventHandlerHelper(); - ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); - Event event = new Event("a", (Dictionary) null); //$NON-NLS-1$ + ServiceRegistration<EventHandler> handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); + Event event = new Event("a", (Dictionary<String, Object>) null); //$NON-NLS-1$ eventAdmin.sendEvent(event); assertNull("Received event published to topic 'a' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$ handlerRegistration.unregister(); @@ -86,13 +94,14 @@ public class EventAdminTest extends TestCase { * Ensures EventAdmin delivers an event published on topic "a/b/c/d" to an * EventHandler listening to topic "a/b/c/*". */ + @Test public void testEventDeliveryForWildcardTopic4() { - Dictionary properties = new Hashtable(); + Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$ BundleContext bundleContext = Activator.getBundleContext(); EventHandlerHelper handler = new EventHandlerHelper(); - ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); - Event event = new Event("a/b/c/d", (Dictionary) null); //$NON-NLS-1$ + ServiceRegistration<EventHandler> handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); + Event event = new Event("a/b/c/d", (Dictionary<String, Object>) null); //$NON-NLS-1$ eventAdmin.sendEvent(event); assertNotNull("Did not receive event published to topic 'a/b/c/d' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$ handlerRegistration.unregister(); @@ -102,13 +111,14 @@ public class EventAdminTest extends TestCase { * Ensures EventAdmin delivers an event published on topic "a/b/c/d/e" to * an EventHandler listening to topic "a/b/c/*". */ + @Test public void testEventDeliveryForWildcardTopic5() { - Dictionary properties = new Hashtable(); + Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$ BundleContext bundleContext = Activator.getBundleContext(); EventHandlerHelper handler = new EventHandlerHelper(); - ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); - Event event = new Event("a/b/c/d/e", (Dictionary) null); //$NON-NLS-1$ + ServiceRegistration<EventHandler> handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); + Event event = new Event("a/b/c/d/e", (Dictionary<String, Object>) null); //$NON-NLS-1$ eventAdmin.sendEvent(event); assertNotNull("Did not receive event published to topic 'a/b/c/d/e' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$ handlerRegistration.unregister(); @@ -118,13 +128,14 @@ public class EventAdminTest extends TestCase { * Ensures EventAdmin delivers an event published on topic "a/b/c/d/e/f" to * an EventHandler listening to topic "a/b/c/*". */ + @Test public void testEventDeliveryForWildcardTopic6() { - Dictionary properties = new Hashtable(); + Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$ BundleContext bundleContext = Activator.getBundleContext(); EventHandlerHelper handler = new EventHandlerHelper(); - ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); - Event event = new Event("a/b/c/d/e/f", (Dictionary) null); //$NON-NLS-1$ + ServiceRegistration<EventHandler> handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); + Event event = new Event("a/b/c/d/e/f", (Dictionary<String, Object>) null); //$NON-NLS-1$ eventAdmin.sendEvent(event); assertNotNull("Did not receive event published to topic 'a/b/c/d/e/f' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$ handlerRegistration.unregister(); @@ -136,16 +147,17 @@ public class EventAdminTest extends TestCase { * * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=325064. */ + @Test public void testEventDeliveryForWildcardTopic7() { - Dictionary properties = new Hashtable(); + Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(EventConstants.EVENT_TOPIC, new String[] {"a/b/c", "a/b/c/*"}); //$NON-NLS-1$ //$NON-NLS-2$ BundleContext bundleContext = Activator.getBundleContext(); EventHandlerHelper handler = new EventHandlerHelper(); - ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); - Event event = new Event("a/b/c", (Dictionary) null); //$NON-NLS-1$ + ServiceRegistration<EventHandler> handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties); + Event event = new Event("a/b/c", (Dictionary<String, Object>) null); //$NON-NLS-1$ eventAdmin.sendEvent(event); assertNotNull("Did not receive event published to topic 'a/b/c' while listening to 'a/b/c'", handler.clearLastEvent()); //$NON-NLS-1$ - event = new Event("a/b/c/d", (Dictionary) null); //$NON-NLS-1$ + event = new Event("a/b/c/d", (Dictionary<String, Object>) null); //$NON-NLS-1$ eventAdmin.sendEvent(event); assertNotNull("Did not receive event published to topic 'a/b/c/d' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$ handlerRegistration.unregister(); diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AbstractTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AbstractTest.java index f3d41e91e..9a7891d2d 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AbstractTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AbstractTest.java @@ -10,35 +10,38 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.*; import javax.swing.Icon; import javax.swing.ImageIcon; -import junit.framework.TestCase; import org.eclipse.equinox.compendium.tests.Activator; import org.eclipse.equinox.metatype.EquinoxMetaTypeService; import org.eclipse.osgi.tests.bundles.BundleInstaller; +import org.junit.*; import org.osgi.framework.ServiceReference; import org.osgi.service.metatype.*; -public abstract class AbstractTest extends TestCase { +public abstract class AbstractTest { protected BundleInstaller bundleInstaller; protected EquinoxMetaTypeService metatype; - protected ServiceReference metaTypeReference; + protected ServiceReference<EquinoxMetaTypeService> metaTypeReference; protected void assertAttributeDefinition(AttributeDefinition ad, int cardinality, String[] defaultValue, String description, String id, String name, String[] optionLabels, String[] optionValues, int type) { - assertEquals("Wrong cardinality", cardinality, ad.getCardinality()); //$NON-NLS-1$ + Assert.assertEquals("Wrong cardinality", cardinality, ad.getCardinality()); //$NON-NLS-1$ assertEquals("Wrong default value", defaultValue, ad.getDefaultValue()); //$NON-NLS-1$ - assertEquals("Wrong description", description, ad.getDescription()); //$NON-NLS-1$ - assertEquals("Wrong id", id, ad.getID()); //$NON-NLS-1$ - assertEquals("Wrong name", name, ad.getName()); //$NON-NLS-1$ + Assert.assertEquals("Wrong description", description, ad.getDescription()); //$NON-NLS-1$ + Assert.assertEquals("Wrong id", id, ad.getID()); //$NON-NLS-1$ + Assert.assertEquals("Wrong name", name, ad.getName()); //$NON-NLS-1$ assertEquals("Wrong option labels", optionLabels, ad.getOptionLabels()); //$NON-NLS-1$ assertEquals("Wrong option values", optionValues, ad.getOptionValues()); //$NON-NLS-1$ - assertEquals("Wrong type", type, ad.getType()); //$NON-NLS-1$ + Assert.assertEquals("Wrong type", type, ad.getType()); //$NON-NLS-1$ } protected void assertAttributeDefinitions(AttributeDefinition[] ads, int size) { - assertNotNull("Null attribute definitions", ads); //$NON-NLS-1$ - assertEquals("Wrong attribute definitions size", size, ads.length); //$NON-NLS-1$ + Assert.assertNotNull("Null attribute definitions", ads); //$NON-NLS-1$ + Assert.assertEquals("Wrong attribute definitions size", size, ads.length); //$NON-NLS-1$ } protected void assertEquals(String message, String[] s1, String[] s2) { @@ -50,11 +53,11 @@ public abstract class AbstractTest extends TestCase { if (s1.length != s2.length) fail(message + " (array lengths weren't equal)"); //$NON-NLS-1$ for (int i = 0; i < s1.length; i++) - assertEquals(message, s1[i], s2[i]); + Assert.assertEquals(message, s1[i], s2[i]); } protected void assertIcon(InputStream icon, int size) throws IOException { - assertNotNull("Icon was null", icon); //$NON-NLS-1$ + Assert.assertNotNull("Icon was null", icon); //$NON-NLS-1$ ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { byte[] bytes = new byte[2048]; @@ -67,25 +70,25 @@ public abstract class AbstractTest extends TestCase { icon.close(); } Icon i = new ImageIcon(baos.toByteArray()); - assertEquals("Wrong icon size", size, i.getIconHeight() * i.getIconWidth()); //$NON-NLS-1$ + Assert.assertEquals("Wrong icon size", size, i.getIconHeight() * i.getIconWidth()); //$NON-NLS-1$ } finally { baos.close(); } } protected void assertNotNull(MetaTypeInformation mti) { - assertNotNull("Metatype information was null", mti); //$NON-NLS-1$ + Assert.assertNotNull("Metatype information was null", mti); //$NON-NLS-1$ } protected void assertNotNull(ObjectClassDefinition ocd) { - assertNotNull("Object class definition was null", ocd); //$NON-NLS-1$ + Assert.assertNotNull("Object class definition was null", ocd); //$NON-NLS-1$ } protected void assertObjectClassDefinition(ObjectClassDefinition ocd, String id, String name, String description) { assertNotNull(ocd); - assertEquals("Wrong object class definition ID", id, ocd.getID()); //$NON-NLS-1$ - assertEquals("Wrong object class definition name", name, ocd.getName()); //$NON-NLS-1$ - assertEquals("Wrong object class definition description", description, ocd.getDescription()); //$NON-NLS-1$ + Assert.assertEquals("Wrong object class definition ID", id, ocd.getID()); //$NON-NLS-1$ + Assert.assertEquals("Wrong object class definition name", name, ocd.getName()); //$NON-NLS-1$ + Assert.assertEquals("Wrong object class definition description", description, ocd.getDescription()); //$NON-NLS-1$ } protected void assertValidationFail(String value, AttributeDefinition ad) { @@ -95,12 +98,12 @@ public abstract class AbstractTest extends TestCase { protected void assertValidationPass(String value, AttributeDefinition ad) { String result = assertValidationPresent(value, ad); - assertEquals("Validation failed", 0, result.length()); //$NON-NLS-1$ + Assert.assertEquals("Validation failed", 0, result.length()); //$NON-NLS-1$ } protected String assertValidationPresent(String value, AttributeDefinition ad) { String result = ad.validate(value); - assertNotNull("No validation was present", result); //$NON-NLS-1$ + Assert.assertNotNull("No validation was present", result); //$NON-NLS-1$ return result; } @@ -138,16 +141,18 @@ public abstract class AbstractTest extends TestCase { return defaultValue[0]; } - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Activator.getBundle(Activator.BUNDLE_METATYPE).start(); - metaTypeReference = Activator.getBundleContext().getServiceReference(EquinoxMetaTypeService.class.getName()); - assertNotNull("Metatype service reference not found", metaTypeReference); //$NON-NLS-1$ - metatype = (EquinoxMetaTypeService) Activator.getBundleContext().getService(metaTypeReference); - assertNotNull("Metatype service not found", metatype); //$NON-NLS-1$ + metaTypeReference = Activator.getBundleContext().getServiceReference(EquinoxMetaTypeService.class); + Assert.assertNotNull("Metatype service reference not found", metaTypeReference); //$NON-NLS-1$ + metatype = Activator.getBundleContext().getService(metaTypeReference); + Assert.assertNotNull("Metatype service not found", metatype); //$NON-NLS-1$ bundleInstaller = new BundleInstaller("bundle_tests/metatype", Activator.getBundleContext()); //$NON-NLS-1$ } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { bundleInstaller.shutdown(); Activator.getBundleContext().ungetService(metaTypeReference); Activator.getBundle(Activator.BUNDLE_METATYPE).stop(); diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AllTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AllTests.java index 768534e41..7c23654fe 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AllTests.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AllTests.java @@ -10,24 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +@RunWith(Suite.class) +@SuiteClasses({AttributeTypePasswordTest.class, Bug332161Test.class, Bug340899Test.class, BugTests.class, SameOcdPidFactoryPidTest.class, ExtendableTest.class, Bug358969Test.class, UnresolvedBundleTest.class, GetDefaultValueTest.class, IconTest.class, Bug395196Test.class, NoADTest.class}) public class AllTests { - public static Test suite() { - TestSuite suite = new TestSuite("Tests for Equinox MetaType"); //$NON-NLS-1$ - suite.addTestSuite(AttributeTypePasswordTest.class); - suite.addTestSuite(Bug332161Test.class); - suite.addTestSuite(Bug340899Test.class); - suite.addTestSuite(BugTests.class); - suite.addTestSuite(SameOcdPidFactoryPidTest.class); - suite.addTestSuite(ExtendableTest.class); - suite.addTestSuite(Bug358969Test.class); - suite.addTestSuite(UnresolvedBundleTest.class); - suite.addTestSuite(GetDefaultValueTest.class); - suite.addTestSuite(IconTest.class); - suite.addTestSuite(Bug395196Test.class); - suite.addTestSuite(NoADTest.class); - return suite; - } + //see @SuiteClasses } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AttributeTypePasswordTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AttributeTypePasswordTest.java index db4a2584d..0232913a3 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AttributeTypePasswordTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AttributeTypePasswordTest.java @@ -10,19 +10,22 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.service.metatype.*; public class AttributeTypePasswordTest extends AbstractTest { private Bundle bundle; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); bundle = bundleInstaller.installBundle("tb1"); //$NON-NLS-1$ bundle.start(); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { bundle.stop(); super.tearDown(); } @@ -30,13 +33,14 @@ public class AttributeTypePasswordTest extends AbstractTest { /* * Ensures the PASSWORD type is recognized. */ + @Test public void testAttributeTypePassword1() { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$ AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); for (int i = 0; i < ads.length; i++) { if (ads[i].getID().equals("password1")) { //$NON-NLS-1$ - assertEquals("Attribute type is not PASSWORD", AttributeDefinition.PASSWORD, ads[i].getType()); //$NON-NLS-1$ + Assert.assertEquals("Attribute type is not PASSWORD", AttributeDefinition.PASSWORD, ads[i].getType()); //$NON-NLS-1$ } } } @@ -44,18 +48,20 @@ public class AttributeTypePasswordTest extends AbstractTest { /* * Ensures the PASSWORD type is treated the same as the STRING type. */ + @Test public void testAttributeTypePassword2() { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$ AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); AttributeDefinition ad = findAttributeDefinitionById("password1", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ assertValidationPass("1234abcd", ad); //$NON-NLS-1$ } /* * Ensures the PASSWORD type is treated the same as the STRING type. */ + @Test public void testAttributeTypePassword3() { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$ @@ -69,6 +75,7 @@ public class AttributeTypePasswordTest extends AbstractTest { * Ensures the PASSWORD type is treated the same as the STRING type. * PASSWORD length should be no less than min. */ + @Test public void testAttributeTypePassword4() { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$ @@ -83,6 +90,7 @@ public class AttributeTypePasswordTest extends AbstractTest { * Ensures the PASSWORD type is treated the same as the STRING type. * PASSWORD length should be no greater than max. */ + @Test public void testAttributeTypePassword5() { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$ @@ -97,6 +105,7 @@ public class AttributeTypePasswordTest extends AbstractTest { * Ensures the PASSWORD type is treated the same as the STRING type. * PASSWORD length should be no less than min and no greater than max. */ + @Test public void testAttributeTypePassword6() { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug332161Test.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug332161Test.java index 00abe7042..d5594d60b 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug332161Test.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug332161Test.java @@ -10,7 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.Arrays; +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.service.metatype.*; @@ -99,12 +104,13 @@ public class Bug332161Test extends AbstractTest { * Tests an enumerated Char type consisting of a mixture of whitespace and * non-whitespace characters. A whitespace default value is used. */ + @Test public void test1() { AttributeDefinition ad = findAttributeDefinitionById("char1", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ String defaultValue = getFirstDefaultValue(ad.getDefaultValue()); - assertNotNull("Default value not found", defaultValue); //$NON-NLS-1$ - assertEquals("Wrong default value", "\r", defaultValue); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Default value not found", defaultValue); //$NON-NLS-1$ + Assert.assertEquals("Wrong default value", "\r", defaultValue); //$NON-NLS-1$ //$NON-NLS-2$ validateChar1Options(ad.getOptionLabels(), ad.getOptionValues()); assertValidationPass("\\ ", ad); //$NON-NLS-1$ assertValidationPass("\\\u0020", ad); //$NON-NLS-1$ @@ -122,12 +128,13 @@ public class Bug332161Test extends AbstractTest { /* * Tests a String type with a default value of CRLF. */ + @Test public void test2() { AttributeDefinition ad = findAttributeDefinitionById("string1", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ String defaultValue = getFirstDefaultValue(ad.getDefaultValue()); - assertNotNull("Default value not found", defaultValue); //$NON-NLS-1$ - assertEquals("Wrong default value", "\r\n", defaultValue); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Default value not found", defaultValue); //$NON-NLS-1$ + Assert.assertEquals("Wrong default value", "\r\n", defaultValue); //$NON-NLS-1$ //$NON-NLS-2$ assertValidationPass("\\\r\\\n", ad); //$NON-NLS-1$ } @@ -136,11 +143,12 @@ public class Bug332161Test extends AbstractTest { * with a mixture of whitespace (significant and not significant), escapes, * and non-whitespace characters. */ + @Test public void test3() { AttributeDefinition ad = findAttributeDefinitionById("string2", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ String[] defaultValue = ad.getDefaultValue(); - assertNotNull("Default value not found", defaultValue); //$NON-NLS-1$ + Assert.assertNotNull("Default value not found", defaultValue); //$NON-NLS-1$ String[] expectedValue = new String[] {"\\ Hello, world!", //$NON-NLS-1$ "\"Goodbye, cruel world ...\" \r\n", //$NON-NLS-1$ "To Be,\r\nOr not to be\u0009\u0009" //$NON-NLS-1$ @@ -173,18 +181,20 @@ public class Bug332161Test extends AbstractTest { * Make sure these changes still return null for the default value when * unspecified. */ + @Test public void test4() { AttributeDefinition ad = findAttributeDefinitionById("string3", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ assertNull("Default value was not null", ad.getDefaultValue()); //$NON-NLS-1$ } /* * Invalid default and option values should be logged and ignored. */ + @Test public void test5() { AttributeDefinition ad = findAttributeDefinitionById("char2", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ assertNull("Default value was not null", ad.getDefaultValue()); //$NON-NLS-1$ validateChar2Options(ad.getOptionLabels(), ad.getOptionValues()); } @@ -193,9 +203,10 @@ public class Bug332161Test extends AbstractTest { * Null validation parameters are always invalid. Empty string validation * parameters are valid for type String. */ + @Test public void test6() { AttributeDefinition ad = findAttributeDefinitionById("string3", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ assertValidationFail(null, ad); assertValidationPass("", ad); //$NON-NLS-1$ ad = findAttributeDefinitionById("string2", ads); //$NON-NLS-1$ @@ -206,9 +217,10 @@ public class Bug332161Test extends AbstractTest { /* * Test whitespace characters using min and max. No escapes on min or max. */ + @Test public void test7() { AttributeDefinition ad = findAttributeDefinitionById("char3", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ assertValidationPass("\\\u0009", ad); //$NON-NLS-1$ assertValidationPass("\\\u0020", ad); //$NON-NLS-1$ assertValidationPass("\\ ", ad); //$NON-NLS-1$ @@ -225,17 +237,18 @@ public class Bug332161Test extends AbstractTest { * Test that empty string is a valid default and option value when * cardinality is zero. */ + @Test public void test8() { AttributeDefinition ad = findAttributeDefinitionById("string4", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ String[] defaultValue = ad.getDefaultValue(); - assertNotNull("Default value was null", defaultValue); //$NON-NLS-1$ - assertEquals("Wrong number of default values", 1, defaultValue.length); //$NON-NLS-1$ - assertEquals("Wrong default value", "", defaultValue[0]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Default value was null", defaultValue); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of default values", 1, defaultValue.length); //$NON-NLS-1$ + Assert.assertEquals("Wrong default value", "", defaultValue[0]); //$NON-NLS-1$ //$NON-NLS-2$ String[] optionValues = ad.getOptionValues(); - assertNotNull("Option values was null", optionValues); //$NON-NLS-1$ - assertEquals("Wrong number of option values", 1, optionValues.length); //$NON-NLS-1$ - assertEquals("Wrong option value", "", optionValues[0]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Option values was null", optionValues); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of option values", 1, optionValues.length); //$NON-NLS-1$ + Assert.assertEquals("Wrong option value", "", optionValues[0]); //$NON-NLS-1$ //$NON-NLS-2$ } /* @@ -244,9 +257,10 @@ public class Bug332161Test extends AbstractTest { * getOptionValues() returns null if options were specified but all were * invalid and removed. */ + @Test public void test9() { AttributeDefinition ad = findAttributeDefinitionById("integer1", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ String[] defaultValue = ad.getDefaultValue(); assertNull("Default value was not null", defaultValue); //$NON-NLS-1$ assertNull("Option labels was not null", ad.getOptionLabels()); //$NON-NLS-1$ @@ -257,60 +271,63 @@ public class Bug332161Test extends AbstractTest { * Test that empty string is a valid default and option value when * cardinality is other than zero. */ + @Test public void test10() { AttributeDefinition ad = findAttributeDefinitionById("string5", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ String[] defaultValue = ad.getDefaultValue(); - assertNotNull("Default value was null", defaultValue); //$NON-NLS-1$ - assertEquals("Wrong number of default values", 2, defaultValue.length); //$NON-NLS-1$ - assertEquals("Wrong default value", "", defaultValue[0]); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong default value", "", defaultValue[1]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Default value was null", defaultValue); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of default values", 2, defaultValue.length); //$NON-NLS-1$ + Assert.assertEquals("Wrong default value", "", defaultValue[0]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong default value", "", defaultValue[1]); //$NON-NLS-1$ //$NON-NLS-2$ String[] optionValues = ad.getOptionValues(); - assertNotNull("Option values was null", optionValues); //$NON-NLS-1$ - assertEquals("Wrong number of option values", 5, optionValues.length); //$NON-NLS-1$ - assertEquals("Wrong option value", "", optionValues[0]); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong option value", ",", optionValues[1]); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong option value", ",,", optionValues[2]); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong option value", ",,,", optionValues[3]); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong option value", ",,,,", optionValues[4]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Option values was null", optionValues); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of option values", 5, optionValues.length); //$NON-NLS-1$ + Assert.assertEquals("Wrong option value", "", optionValues[0]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong option value", ",", optionValues[1]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong option value", ",,", optionValues[2]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong option value", ",,,", optionValues[3]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong option value", ",,,,", optionValues[4]); //$NON-NLS-1$ //$NON-NLS-2$ } - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); bundle = bundleInstaller.installBundle("tb4"); //$NON-NLS-1$ bundle.start(); mti = metatype.getMetaTypeInformation(bundle); - assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ + Assert.assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb4", null); //$NON-NLS-1$ - assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ + Assert.assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ - assertEquals("Wrong number of attribute definitions", 9, ads.length); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of attribute definitions", 9, ads.length); //$NON-NLS-1$ } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { bundle.stop(); super.tearDown(); } private void validateChar1Options(String[] optionLabels, String[] optionValues) { - assertNotNull("Option labels not found", optionLabels); //$NON-NLS-1$ - assertEquals("Wrong number of option labels", 6, optionLabels.length); //$NON-NLS-1$ - assertNotNull("Option values not found", optionValues); //$NON-NLS-1$ - assertEquals("Wrong number of option values", 6, optionValues.length); //$NON-NLS-1$ + Assert.assertNotNull("Option labels not found", optionLabels); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of option labels", 6, optionLabels.length); //$NON-NLS-1$ + Assert.assertNotNull("Option values not found", optionValues); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of option values", 6, optionValues.length); //$NON-NLS-1$ for (int i = 0; i < optionLabels.length; i++) { if ("Space".equals(optionLabels[i])) { //$NON-NLS-1$ - assertEquals("\u0020", optionValues[i]); //$NON-NLS-1$ + Assert.assertEquals("\u0020", optionValues[i]); //$NON-NLS-1$ } else if ("Tab".equals(optionLabels[i])) { //$NON-NLS-1$ - assertEquals("\u0009", optionValues[i]); //$NON-NLS-1$ + Assert.assertEquals("\u0009", optionValues[i]); //$NON-NLS-1$ } else if ("Line Feed".equals(optionLabels[i])) { //$NON-NLS-1$ - assertEquals("\n", optionValues[i]); //$NON-NLS-1$ + Assert.assertEquals("\n", optionValues[i]); //$NON-NLS-1$ } else if ("Carriage Return".equals(optionLabels[i])) { //$NON-NLS-1$ - assertEquals("\r", optionValues[i]); //$NON-NLS-1$ + Assert.assertEquals("\r", optionValues[i]); //$NON-NLS-1$ } else if ("Capital A".equals(optionLabels[i])) { //$NON-NLS-1$ - assertEquals("A", optionValues[i]); //$NON-NLS-1$ + Assert.assertEquals("A", optionValues[i]); //$NON-NLS-1$ } else if ("Lowercase Z".equals(optionLabels[i])) { //$NON-NLS-1$ - assertEquals("z", optionValues[i]); //$NON-NLS-1$ + Assert.assertEquals("z", optionValues[i]); //$NON-NLS-1$ } else { fail("Wrong number of option labels"); //$NON-NLS-1$ } @@ -318,17 +335,17 @@ public class Bug332161Test extends AbstractTest { } private void validateChar2Options(String[] optionLabels, String[] optionValues) { - assertNotNull("Option labels not found", optionLabels); //$NON-NLS-1$ - assertEquals("Wrong number of option labels", 3, optionLabels.length); //$NON-NLS-1$ - assertNotNull("Option values not found", optionValues); //$NON-NLS-1$ - assertEquals("Wrong number of option values", 3, optionValues.length); //$NON-NLS-1$ + Assert.assertNotNull("Option labels not found", optionLabels); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of option labels", 3, optionLabels.length); //$NON-NLS-1$ + Assert.assertNotNull("Option values not found", optionValues); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of option values", 3, optionValues.length); //$NON-NLS-1$ for (int i = 0; i < optionLabels.length; i++) { if ("Capital A".equals(optionLabels[i])) { //$NON-NLS-1$ - assertEquals("A", optionValues[i]); //$NON-NLS-1$ + Assert.assertEquals("A", optionValues[i]); //$NON-NLS-1$ } else if ("Capital B".equals(optionLabels[i])) { //$NON-NLS-1$ - assertEquals("B", optionValues[i]); //$NON-NLS-1$ + Assert.assertEquals("B", optionValues[i]); //$NON-NLS-1$ } else if ("Capital E".equals(optionLabels[i])) { //$NON-NLS-1$ - assertEquals("E", optionValues[i]); //$NON-NLS-1$ + Assert.assertEquals("E", optionValues[i]); //$NON-NLS-1$ } else { fail("Wrong number of option labels"); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug340899Test.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug340899Test.java index 6d7dff6ee..385525f72 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug340899Test.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug340899Test.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import org.junit.Assert; +import org.junit.Test; import org.osgi.framework.Bundle; import org.osgi.service.metatype.*; @@ -24,6 +26,7 @@ public class Bug340899Test extends AbstractTest { * the Bundle-Localization manifest header, the default property file base * name of 'OSGI-INF/l10n/bundle' should be used. */ + @Test public void test1() throws Exception { execute("tb5", "org.eclipse.equinox.metatype.tests.tb5"); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -33,6 +36,7 @@ public class Bug340899Test extends AbstractTest { * property file base name declared within the Bundle-Localization manifest * header should override the default base name. */ + @Test public void test2() throws Exception { execute("tb6", "org.eclipse.equinox.metatype.tests.tb6"); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -42,35 +46,28 @@ public class Bug340899Test extends AbstractTest { * <MetaData> localization attribute should override the * Bundle-Localization manifest header and the default base name. */ + @Test public void test3() throws Exception { execute("tb7", "org.eclipse.equinox.metatype.tests.tb7"); //$NON-NLS-1$ //$NON-NLS-2$ } - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - private void execute(String bundleName, String ocdId) throws Exception { - Bundle bundle = bundleInstaller.installBundle(bundleName); //$NON-NLS-1$ + Bundle bundle = bundleInstaller.installBundle(bundleName); try { bundle.start(); MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); - assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ - ObjectClassDefinition ocd = mti.getObjectClassDefinition(ocdId, null); //$NON-NLS-1$ - assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ - assertEquals("Wrong OCD name", ocd1name, ocd.getName()); //$NON-NLS-1$ - assertEquals("Wrong OCD description", ocd1description, ocd.getDescription()); //$NON-NLS-1$ + Assert.assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ + ObjectClassDefinition ocd = mti.getObjectClassDefinition(ocdId, null); + Assert.assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ + Assert.assertEquals("Wrong OCD name", ocd1name, ocd.getName()); //$NON-NLS-1$ + Assert.assertEquals("Wrong OCD description", ocd1description, ocd.getDescription()); //$NON-NLS-1$ AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ - assertEquals("Wrong number of attribute definitions", 1, ads.length); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of attribute definitions", 1, ads.length); //$NON-NLS-1$ AttributeDefinition ad = findAttributeDefinitionById("ad1", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ - assertEquals("Wrong AD name", ad1name, ad.getName()); //$NON-NLS-1$ - assertEquals("Wrong AD description", ad1description, ad.getDescription()); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertEquals("Wrong AD name", ad1name, ad.getName()); //$NON-NLS-1$ + Assert.assertEquals("Wrong AD description", ad1description, ad.getDescription()); //$NON-NLS-1$ } finally { try { bundle.stop(); diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug358969Test.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug358969Test.java index fe9af9377..184e73705 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug358969Test.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug358969Test.java @@ -10,10 +10,14 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import static org.junit.Assert.assertFalse; + import org.eclipse.equinox.metatype.impl.LogTrackerMsg; import org.eclipse.equinox.metatype.impl.MetaTypeMsg; +import org.junit.Test; public class Bug358969Test extends AbstractTest { + @Test public void test1() { String message = "NLS properties file not configured correctly"; //$NON-NLS-1$ String prefix = "NLS missing message:"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug395196Test.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug395196Test.java index 28dff1638..7f4739022 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug395196Test.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/Bug395196Test.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import static org.junit.Assert.assertNull; + +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.service.metatype.*; @@ -27,26 +30,29 @@ public class Bug395196Test extends AbstractTest { private MetaTypeInformation mti; private ObjectClassDefinition ocd; + @Test public void testRejectDefaultValueWhenNotAnOption() { AttributeDefinition ad = findAttributeDefinitionById("ocd3-ad1", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ assertNull("Default value not matching one of the options was not rejected", ad.getDefaultValue()); //$NON-NLS-1$ } - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); bundle = bundleInstaller.installBundle("tb1"); //$NON-NLS-1$ bundle.start(); mti = metatype.getMetaTypeInformation(bundle); - assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ + Assert.assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1.testRejectDefaultValueWhenNotAnOption", null); //$NON-NLS-1$ - assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ + Assert.assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ - assertEquals("Wrong number of attribute definitions", 1, ads.length); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of attribute definitions", 1, ads.length); //$NON-NLS-1$ } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { bundle.stop(); super.tearDown(); } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/BugTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/BugTests.java index ea5185765..c49f2efc6 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/BugTests.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/BugTests.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.service.metatype.*; @@ -19,64 +23,68 @@ public class BugTests extends AbstractTest { /* * A cardinality of zero should not require a default value to be specified. */ + @Test public void test334642() { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); - assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ + Assert.assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb3", null); //$NON-NLS-1$ - assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ + Assert.assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ - assertEquals("Wrong number of attribute definitions", 3, ads.length); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of attribute definitions", 3, ads.length); //$NON-NLS-1$ AttributeDefinition ad = findAttributeDefinitionById("password1", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ - assertEquals("Wrong cardinality", 0, ad.getCardinality()); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertEquals("Wrong cardinality", 0, ad.getCardinality()); //$NON-NLS-1$ assertNull("Default value should be null", ad.getDefaultValue()); //$NON-NLS-1$ - assertNotNull("Validation should be present", ad.validate(getFirstDefaultValue(ad.getDefaultValue()))); //$NON-NLS-1$ + Assert.assertNotNull("Validation should be present", ad.validate(getFirstDefaultValue(ad.getDefaultValue()))); //$NON-NLS-1$ assertTrue("Validation should fail", ad.validate(getFirstDefaultValue(ad.getDefaultValue())).length() > 0); //$NON-NLS-1$ ad = findAttributeDefinitionById("password2", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ - assertEquals("Wrong cardinality", 0, ad.getCardinality()); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertEquals("Wrong cardinality", 0, ad.getCardinality()); //$NON-NLS-1$ assertNull("Default value should be null", ad.getDefaultValue()); //$NON-NLS-1$ - assertNotNull("Validation should be present", ad.validate(getFirstDefaultValue(ad.getDefaultValue()))); //$NON-NLS-1$ + Assert.assertNotNull("Validation should be present", ad.validate(getFirstDefaultValue(ad.getDefaultValue()))); //$NON-NLS-1$ assertTrue("Validation should fail", ad.validate(getFirstDefaultValue(ad.getDefaultValue())).length() > 0); //$NON-NLS-1$ ad = findAttributeDefinitionById("string1", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ - assertEquals("Wrong cardinality", 0, ad.getCardinality()); //$NON-NLS-1$ - assertEquals("Only one default value should exist", 1, ad.getDefaultValue().length); //$NON-NLS-1$ - assertEquals("Wrong default value", "Hello, world!", getFirstDefaultValue(ad.getDefaultValue())); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertEquals("Wrong cardinality", 0, ad.getCardinality()); //$NON-NLS-1$ + Assert.assertEquals("Only one default value should exist", 1, ad.getDefaultValue().length); //$NON-NLS-1$ + Assert.assertEquals("Wrong default value", "Hello, world!", getFirstDefaultValue(ad.getDefaultValue())); //$NON-NLS-1$ //$NON-NLS-2$ assertValidationPass(escape(getFirstDefaultValue(ad.getDefaultValue())), ad); } /* * StringIndexOutOfBoundsException when description or name attributes are an empty string */ + @Test public void test341963() { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); - assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ + Assert.assertNotNull("Metatype information not found", mti); //$NON-NLS-1$ ObjectClassDefinition ocd = mti.getObjectClassDefinition("ocd2", null); //$NON-NLS-1$ - assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ - assertEquals("Wrong name", "", ocd.getName()); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong description", "", ocd.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$ + Assert.assertEquals("Wrong name", "", ocd.getName()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong description", "", ocd.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$ AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ - assertEquals("Wrong number of attribute definitions", 1, ads.length); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of attribute definitions", 1, ads.length); //$NON-NLS-1$ AttributeDefinition ad = findAttributeDefinitionById("ad1", ads); //$NON-NLS-1$ - assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ - assertEquals("Wrong name", "", ad.getName()); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong description", "", ad.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$ + Assert.assertEquals("Wrong name", "", ad.getName()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong description", "", ad.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$ } - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); bundle = bundleInstaller.installBundle("tb3"); //$NON-NLS-1$ bundle.start(); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { bundle.stop(); super.tearDown(); } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/ExtendableTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/ExtendableTest.java index d2fe8d408..6a93680ba 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/ExtendableTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/ExtendableTest.java @@ -10,55 +10,59 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; -import org.eclipse.equinox.metatype.*; +import static org.junit.Assert.assertTrue; import java.util.Map; import java.util.Set; +import org.eclipse.equinox.metatype.*; +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.service.metatype.ObjectClassDefinition; public class ExtendableTest extends AbstractTest { private Bundle bundle; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); bundle = bundleInstaller.installBundle("extendable.tb1"); //$NON-NLS-1$ bundle.start(); } + @Test public void testExtensions() { EquinoxMetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); EquinoxObjectClassDefinition ocd = mti.getObjectClassDefinition("metatype.extendable.tb1.1", null); //$NON-NLS-1$ - Set schemas = ocd.getExtensionUris(); - assertNotNull("Null extension schemas", schemas); //$NON-NLS-1$ - assertEquals("Wrong schemas size", 2, schemas.size()); //$NON-NLS-1$ + Set<String> schemas = ocd.getExtensionUris(); + Assert.assertNotNull("Null extension schemas", schemas); //$NON-NLS-1$ + Assert.assertEquals("Wrong schemas size", 2, schemas.size()); //$NON-NLS-1$ assertTrue("Missing schema", schemas.contains("urn:xmlns:foo")); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue("Missing schema", schemas.contains("urn:xmlns:validation")); //$NON-NLS-1$ //$NON-NLS-2$ - Map attributes = ocd.getExtensionAttributes("urn:xmlns:foo"); //$NON-NLS-1$ - assertNotNull("Null attributes", attributes); //$NON-NLS-1$ - assertEquals("Wrong attributes size", 1, attributes.size()); //$NON-NLS-1$ - assertEquals("Wrong value", "bar", attributes.get("foo")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Map<String, String> attributes = ocd.getExtensionAttributes("urn:xmlns:foo"); //$NON-NLS-1$ + Assert.assertNotNull("Null attributes", attributes); //$NON-NLS-1$ + Assert.assertEquals("Wrong attributes size", 1, attributes.size()); //$NON-NLS-1$ + Assert.assertEquals("Wrong value", "bar", attributes.get("foo")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ attributes = ocd.getExtensionAttributes("urn:xmlns:validation"); //$NON-NLS-1$ - assertNotNull("Null attributes", attributes); //$NON-NLS-1$ - assertEquals("Wrong attributes size", 1, attributes.size()); //$NON-NLS-1$ - assertEquals("Wrong value", "true", attributes.get("enabled")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Assert.assertNotNull("Null attributes", attributes); //$NON-NLS-1$ + Assert.assertEquals("Wrong attributes size", 1, attributes.size()); //$NON-NLS-1$ + Assert.assertEquals("Wrong value", "true", attributes.get("enabled")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ EquinoxAttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); for (int i = 0; i < ads.length; i++) { if (ads[i].getID().equals("ad1")) { //$NON-NLS-1$ schemas = ads[i].getExtensionUris(); - assertNotNull("Null extension schemas", schemas); //$NON-NLS-1$ - assertEquals("Wrong schemas size", 2, schemas.size()); //$NON-NLS-1$ + Assert.assertNotNull("Null extension schemas", schemas); //$NON-NLS-1$ + Assert.assertEquals("Wrong schemas size", 2, schemas.size()); //$NON-NLS-1$ assertTrue("Missing schema", schemas.contains("urn:xmlns:foo")); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue("Missing schema", schemas.contains("urn:xmlns:validation")); //$NON-NLS-1$ //$NON-NLS-2$ attributes = ads[i].getExtensionAttributes("urn:xmlns:foo"); //$NON-NLS-1$ - assertNotNull("Null attributes", attributes); //$NON-NLS-1$ - assertEquals("Wrong attributes size", 1, attributes.size()); //$NON-NLS-1$ - assertEquals("Wrong value", "foo", attributes.get("bar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Assert.assertNotNull("Null attributes", attributes); //$NON-NLS-1$ + Assert.assertEquals("Wrong attributes size", 1, attributes.size()); //$NON-NLS-1$ + Assert.assertEquals("Wrong value", "foo", attributes.get("bar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ attributes = ads[i].getExtensionAttributes("urn:xmlns:validation"); //$NON-NLS-1$ - assertNotNull("Null attributes", attributes); //$NON-NLS-1$ - assertEquals("Wrong attributes size", 2, attributes.size()); //$NON-NLS-1$ - assertEquals("Wrong value", "[a-zA-Z0-9]", attributes.get("regexp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - assertEquals("Wrong value", "validation", attributes.get("validation")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Assert.assertNotNull("Null attributes", attributes); //$NON-NLS-1$ + Assert.assertEquals("Wrong attributes size", 2, attributes.size()); //$NON-NLS-1$ + Assert.assertEquals("Wrong value", "[a-zA-Z0-9]", attributes.get("regexp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Assert.assertEquals("Wrong value", "validation", attributes.get("validation")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetDefaultValueTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetDefaultValueTest.java index fd5d533ac..6f0d09eb0 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetDefaultValueTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetDefaultValueTest.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import static org.junit.Assert.fail; + +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.service.metatype.*; @@ -23,15 +26,16 @@ import org.osgi.service.metatype.*; public class GetDefaultValueTest extends AbstractTest { private Bundle bundle; + @Test public void testGetDefaultValue() { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); - assertNotNull("Metatype information was null", mti); //$NON-NLS-1$ + Assert.assertNotNull("Metatype information was null", mti); //$NON-NLS-1$ ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1.getDefaultValues", null); //$NON-NLS-1$ - assertNotNull("Object class definition was null", ocd); //$NON-NLS-1$ - assertEquals("Wrong object class definition ID", "ocd2", ocd.getID()); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong object class definition name", "getDefaultValues", ocd.getName()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Object class definition was null", ocd); //$NON-NLS-1$ + Assert.assertEquals("Wrong object class definition ID", "ocd2", ocd.getID()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong object class definition name", "getDefaultValues", ocd.getName()); //$NON-NLS-1$ //$NON-NLS-2$ AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - assertEquals("Wrong number of attribute definitions", 24, ads.length); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of attribute definitions", 24, ads.length); //$NON-NLS-1$ for (int i = 0; i < ads.length; i++) { switch (Integer.parseInt(ads[i].getID())) { case 1 : @@ -112,12 +116,9 @@ public class GetDefaultValueTest extends AbstractTest { } } - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); bundle = bundleInstaller.installBundle("tb1"); //$NON-NLS-1$ } - - protected void tearDown() throws Exception { - super.tearDown(); - } } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetMinMaxTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetMinMaxTest.java index 2ab45127c..e43ed60c5 100755 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetMinMaxTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetMinMaxTest.java @@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import static org.junit.Assert.assertTrue; + import org.eclipse.equinox.metatype.*; +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.service.metatype.ObjectClassDefinition; @@ -18,7 +21,8 @@ public class GetMinMaxTest extends AbstractTest { private Bundle bundle; private EquinoxObjectClassDefinition ocd; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); bundle = bundleInstaller.installBundle("getMinMax.tb1"); //$NON-NLS-1$ bundle.start(); @@ -26,30 +30,37 @@ public class GetMinMaxTest extends AbstractTest { ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.getMinMax.tb1", null); //$NON-NLS-1$ } + @Test public void testGetMax() throws Exception { assertMaxValue("getMax", "0"); //$NON-NLS-1$ //$NON-NLS-2$ } + @Test public void testGetMaxAsNotANumber() { assertMaxValue("getMaxAsNotANumber", "1.0.0"); //$NON-NLS-1$ //$NON-NLS-2$ } + @Test public void testGetMaxNull() { assertMaxValue("getMaxNull", null); //$NON-NLS-1$ } + @Test public void testGetMin() { assertMinValue("getMin", "5"); //$NON-NLS-1$ //$NON-NLS-2$ } + @Test public void testGetMinAsNotANumber() { assertMinValue("getMinAsNotANumber", "foo"); //$NON-NLS-1$ //$NON-NLS-2$ } + @Test public void testGetMinNull() { assertMinValue("getMinNull", null); //$NON-NLS-1$ } + @Test public void testMinMaxStringValidationUsingInteger() { String name = "minMaxValidUsingInt"; //$NON-NLS-1$ assertValid(name, "12345678"); //$NON-NLS-1$ @@ -58,6 +69,7 @@ public class GetMinMaxTest extends AbstractTest { assertInvalid(name, "12345678123456789"); //$NON-NLS-1$ } + @Test public void testMinMaxStringValidationUsingString() { String name = "minMaxValidUsingString"; //$NON-NLS-1$ assertValid(name, "1"); //$NON-NLS-1$ @@ -76,7 +88,7 @@ public class GetMinMaxTest extends AbstractTest { private void assertMinMaxValue(boolean max, String name, String value) { EquinoxAttributeDefinition ad = getAttributeDefinition(name); - assertEquals("Wrong " + (max ? "max" : "min") + " value", value, max ? ad.getMax() : ad.getMin()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + Assert.assertEquals("Wrong " + (max ? "max" : "min") + " value", value, max ? ad.getMax() : ad.getMin()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } private void assertValid(String name, String value) { @@ -90,10 +102,11 @@ public class GetMinMaxTest extends AbstractTest { private void assertValidation(String name, String value, boolean valid) { EquinoxAttributeDefinition ad = getAttributeDefinition(name); - if (valid) - assertEquals("Should be valid", "", ad.validate(value)); //$NON-NLS-1$ //$NON-NLS-2$ - else + if (valid) { + Assert.assertEquals("Should be valid", "", ad.validate(value)); //$NON-NLS-1$ //$NON-NLS-2$ + } else { assertTrue("Should be invalid", ad.validate(value).length() > 0); //$NON-NLS-1$ + } } private EquinoxAttributeDefinition getAttributeDefinition(String name) { diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/IconTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/IconTest.java index e1388d6b3..86a7acdf5 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/IconTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/IconTest.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; +import static org.junit.Assert.assertNull; + +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.service.metatype.*; @@ -30,6 +33,7 @@ import org.osgi.service.metatype.*; public class IconTest extends AbstractTest { private Bundle bundle; + @Test public void testIcon() throws Exception { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); assertNotNull(mti); @@ -49,6 +53,7 @@ public class IconTest extends AbstractTest { assertIcon(ocd.getIcon(31251), 40000); } + @Test public void testNullIcon() throws Exception { MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); assertNotNull(mti); @@ -60,12 +65,14 @@ public class IconTest extends AbstractTest { assertNull("Icon was not null", ocd.getIcon(10000)); //$NON-NLS-1$ } - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); bundle = bundleInstaller.installBundle("tb9"); //$NON-NLS-1$ } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { bundle.uninstall(); super.tearDown(); } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/NoADTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/NoADTest.java index 6c38b9143..fc0983ae0 100755 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/NoADTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/NoADTest.java @@ -10,30 +10,35 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.eclipse.equinox.compendium.tests.Activator; import org.eclipse.osgi.tests.bundles.BundleInstaller; +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.framework.ServiceReference; import org.osgi.service.metatype.*; -public class NoADTest extends TestCase { +public class NoADTest { private Bundle bundle; private BundleInstaller bundleInstaller; private MetaTypeService metaType; - private ServiceReference metaTypeReference; + private ServiceReference<MetaTypeService> metaTypeReference; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Activator.getBundle(Activator.BUNDLE_METATYPE).start(); - metaTypeReference = Activator.getBundleContext().getServiceReference(MetaTypeService.class.getName()); - metaType = (MetaTypeService) Activator.getBundleContext().getService(metaTypeReference); + metaTypeReference = Activator.getBundleContext().getServiceReference(MetaTypeService.class); + metaType = Activator.getBundleContext().getService(metaTypeReference); bundleInstaller = new BundleInstaller("bundle_tests/metatype", Activator.getBundleContext()); //$NON-NLS-1$ bundleInstaller.refreshPackages(null); bundle = bundleInstaller.installBundle("tb10"); //$NON-NLS-1$ bundle.start(); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { bundleInstaller.shutdown(); Activator.getBundleContext().ungetService(metaTypeReference); Activator.getBundle(Activator.BUNDLE_METATYPE).stop(); @@ -42,6 +47,7 @@ public class NoADTest extends TestCase { /* * Ensures an OCD can exist with no ADs */ + @Test public void testNoADs() { MetaTypeInformation mti = metaType.getMetaTypeInformation(bundle); String[] pids = mti.getPids(); diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/SameOcdPidFactoryPidTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/SameOcdPidFactoryPidTest.java index c2920c832..74e30df08 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/SameOcdPidFactoryPidTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/SameOcdPidFactoryPidTest.java @@ -10,31 +10,36 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.tests; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.eclipse.equinox.compendium.tests.Activator; import org.eclipse.osgi.tests.bundles.BundleInstaller; +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.framework.ServiceReference; import org.osgi.service.metatype.MetaTypeInformation; import org.osgi.service.metatype.MetaTypeService; -public class SameOcdPidFactoryPidTest extends TestCase { +public class SameOcdPidFactoryPidTest { private Bundle bundle; private BundleInstaller bundleInstaller; private MetaTypeService metaType; - private ServiceReference metaTypeReference; + private ServiceReference<MetaTypeService> metaTypeReference; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Activator.getBundle(Activator.BUNDLE_METATYPE).start(); - metaTypeReference = Activator.getBundleContext().getServiceReference(MetaTypeService.class.getName()); - metaType = (MetaTypeService) Activator.getBundleContext().getService(metaTypeReference); + metaTypeReference = Activator.getBundleContext().getServiceReference(MetaTypeService.class); + metaType = Activator.getBundleContext().getService(metaTypeReference); bundleInstaller = new BundleInstaller("bundle_tests/metatype", Activator.getBundleContext()); //$NON-NLS-1$ bundleInstaller.refreshPackages(null); bundle = bundleInstaller.installBundle("tb2"); //$NON-NLS-1$ bundle.start(); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { bundleInstaller.shutdown(); Activator.getBundleContext().ungetService(metaTypeReference); Activator.getBundle(Activator.BUNDLE_METATYPE).stop(); @@ -45,6 +50,7 @@ public class SameOcdPidFactoryPidTest extends TestCase { * the factoryPid attribute and the other only the pid attribute, is * accessible via both getPids() and getFactoryPids(). */ + @Test public void test1() { MetaTypeInformation mti = metaType.getMetaTypeInformation(bundle); String[] pids = mti.getPids(); diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/UnresolvedBundleTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/UnresolvedBundleTest.java index eee81f667..228b93328 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/UnresolvedBundleTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/UnresolvedBundleTest.java @@ -12,6 +12,7 @@ package org.eclipse.equinox.metatype.tests; import java.io.IOException; import java.io.InputStream; +import org.junit.*; import org.osgi.framework.Bundle; import org.osgi.service.metatype.*; @@ -23,45 +24,43 @@ import org.osgi.service.metatype.*; public class UnresolvedBundleTest extends AbstractTest { private Bundle bundle; + @Test public void testUnresolvedBundle() throws Exception { assertBundleUnresolved(); MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle); - assertNotNull("Metatype information was null", mti); //$NON-NLS-1$ + Assert.assertNotNull("Metatype information was null", mti); //$NON-NLS-1$ ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb8", null); //$NON-NLS-1$ - assertNotNull("Object class definition was null", ocd); //$NON-NLS-1$ - assertEquals("Wrong object class definition ID", "1", ocd.getID()); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong object class definition name", "OCD1 Name", ocd.getName()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Object class definition was null", ocd); //$NON-NLS-1$ + Assert.assertEquals("Wrong object class definition ID", "1", ocd.getID()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong object class definition name", "OCD1 Name", ocd.getName()); //$NON-NLS-1$ //$NON-NLS-2$ AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - assertEquals("Wrong number of attribute definitions", 1, ads.length); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of attribute definitions", 1, ads.length); //$NON-NLS-1$ AttributeDefinition ad = ads[0]; - assertNotNull("Attribute definition was null", ad); //$NON-NLS-1$ - assertEquals("Wrong attribute definition ID", "1", ad.getID()); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong attribute definition name", "AD1 Name", ad.getName()); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Wrong attribute definition type", AttributeDefinition.STRING, ad.getType()); //$NON-NLS-1$ + Assert.assertNotNull("Attribute definition was null", ad); //$NON-NLS-1$ + Assert.assertEquals("Wrong attribute definition ID", "1", ad.getID()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong attribute definition name", "AD1 Name", ad.getName()); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("Wrong attribute definition type", AttributeDefinition.STRING, ad.getType()); //$NON-NLS-1$ InputStream icon = ocd.getIcon(10000); - assertNotNull("Icon was null", icon); //$NON-NLS-1$ + Assert.assertNotNull("Icon was null", icon); //$NON-NLS-1$ try { icon.close(); } catch (IOException e) { // noop } String[] locales = mti.getLocales(); - assertNotNull("Locales was null", locales); //$NON-NLS-1$ - assertEquals("Wrong number of locales", 1, locales.length); //$NON-NLS-1$ - assertEquals("Wrong locale", "en", locales[0]); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertNotNull("Locales was null", locales); //$NON-NLS-1$ + Assert.assertEquals("Wrong number of locales", 1, locales.length); //$NON-NLS-1$ + Assert.assertEquals("Wrong locale", "en", locales[0]); //$NON-NLS-1$ //$NON-NLS-2$ } - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); bundle = bundleInstaller.installBundle("tb8"); //$NON-NLS-1$ assertBundleUnresolved(); } - protected void tearDown() throws Exception { - super.tearDown(); - } - private void assertBundleUnresolved() { - assertEquals("Bundle should not be resolved", Bundle.INSTALLED, bundle.getState()); //$NON-NLS-1$ + Assert.assertEquals("Bundle should not be resolved", Bundle.INSTALLED, bundle.getState()); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/AllTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/AllTests.java index ceddb5e99..f0f32145f 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/AllTests.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/AllTests.java @@ -10,17 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.useradmin.tests; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +@RunWith(Suite.class) +@SuiteClasses({UserTest.class, GroupTest.class, UserAdminEventAdapterTest.class}) public class AllTests { - - public static Test suite() { - TestSuite suite = new TestSuite("Tests for Equinox UserAdmin"); //$NON-NLS-1$ - suite.addTestSuite(UserTest.class); - suite.addTestSuite(GroupTest.class); - suite.addTestSuite(UserAdminEventAdapterTest.class); - return suite; - } - + // See @SuiteClasses } diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/GroupTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/GroupTest.java index e93506010..de1117b36 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/GroupTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/GroupTest.java @@ -10,30 +10,38 @@ *******************************************************************************/ package org.eclipse.equinox.useradmin.tests; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import org.eclipse.equinox.compendium.tests.Activator; +import org.junit.*; import org.osgi.framework.ServiceReference; import org.osgi.service.useradmin.*; -public class GroupTest extends TestCase { +public class GroupTest { private UserAdmin userAdmin; - private ServiceReference userAdminReference; + private ServiceReference<UserAdmin> userAdminReference; boolean locked = false; Object lock = new Object(); - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Activator.getBundle(Activator.BUNDLE_USERADMIN).start(); - userAdminReference = Activator.getBundleContext().getServiceReference(UserAdmin.class.getName()); - userAdmin = (UserAdmin) Activator.getBundleContext().getService(userAdminReference); + userAdminReference = Activator.getBundleContext().getServiceReference(UserAdmin.class); + userAdmin = Activator.getBundleContext().getService(userAdminReference); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { Activator.getBundleContext().ungetService(userAdminReference); Activator.getBundle(Activator.BUNDLE_USERADMIN).stop(); } + @Test public void testGroupCreateAndRemove() throws Exception { Group group = (Group) userAdmin.createRole("testGroupCreateAndRemove", Role.GROUP); //$NON-NLS-1$ assertNotNull(group); @@ -43,6 +51,7 @@ public class GroupTest extends TestCase { assertNull(userAdmin.getRole("testGroupCreateAndRemove")); //$NON-NLS-1$ } + @Test public void testGroupAddingAndRemovingMembers() throws Exception { Group group = (Group) userAdmin.createRole("testGroupAddingAndRemovingMembers", Role.GROUP); //$NON-NLS-1$ assertNotNull(group); diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserAdminEventAdapterTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserAdminEventAdapterTest.java index d88ef0f74..28ba86e09 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserAdminEventAdapterTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserAdminEventAdapterTest.java @@ -10,37 +10,42 @@ *******************************************************************************/ package org.eclipse.equinox.useradmin.tests; +import static org.junit.Assert.assertFalse; + import java.util.Dictionary; import java.util.Hashtable; -import junit.framework.TestCase; import org.eclipse.equinox.compendium.tests.Activator; +import org.junit.*; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.service.event.*; import org.osgi.service.useradmin.Role; import org.osgi.service.useradmin.UserAdmin; -public class UserAdminEventAdapterTest extends TestCase { +public class UserAdminEventAdapterTest { private UserAdmin userAdmin; - private ServiceReference userAdminReference; + private ServiceReference<UserAdmin> userAdminReference; boolean locked = false; Object lock = new Object(); - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Activator.getBundle(Activator.BUNDLE_EVENT).start(); Activator.getBundle(Activator.BUNDLE_USERADMIN).start(); - userAdminReference = Activator.getBundleContext().getServiceReference(UserAdmin.class.getName()); - userAdmin = (UserAdmin) Activator.getBundleContext().getService(userAdminReference); + userAdminReference = Activator.getBundleContext().getServiceReference(UserAdmin.class); + userAdmin = Activator.getBundleContext().getService(userAdminReference); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { Activator.getBundleContext().ungetService(userAdminReference); Activator.getBundle(Activator.BUNDLE_USERADMIN).stop(); Activator.getBundle(Activator.BUNDLE_EVENT).stop(); } + @Test public void testUserAdminEvent() throws Exception { EventHandler handler = new EventHandler() { @@ -53,10 +58,10 @@ public class UserAdminEventAdapterTest extends TestCase { }; String[] topics = new String[] {"org/osgi/service/useradmin/UserAdmin/*"}; //$NON-NLS-1$ - Dictionary handlerProps = new Hashtable(); + Dictionary<String, Object> handlerProps = new Hashtable<String, Object>(); handlerProps.put(EventConstants.EVENT_TOPIC, topics); - ServiceRegistration reg = Activator.getBundleContext().registerService(EventHandler.class.getName(), handler, handlerProps); + ServiceRegistration<EventHandler> reg = Activator.getBundleContext().registerService(EventHandler.class, handler, handlerProps); synchronized (lock) { userAdmin.createRole("testRole", Role.USER); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserTest.java index 3dfff0d3a..4982862d1 100644 --- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserTest.java +++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserTest.java @@ -10,18 +10,24 @@ *******************************************************************************/ package org.eclipse.equinox.useradmin.tests; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.Dictionary; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; import org.eclipse.equinox.compendium.tests.Activator; +import org.junit.*; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; import org.osgi.service.useradmin.*; -public class UserTest extends TestCase { +public class UserTest { private UserAdmin userAdmin; - private ServiceReference userAdminReference; + private ServiceReference<UserAdmin> userAdminReference; + @Test public void testUser1() { try { createUser1(); @@ -42,6 +48,7 @@ public class UserTest extends TestCase { } } + @Test public void testUser2() { try { createUser2(); @@ -62,7 +69,7 @@ public class UserTest extends TestCase { assertEquals("2", 2, bytes[1]); //$NON-NLS-1$ assertEquals("3", 3, bytes[2]); //$NON-NLS-1$ - Dictionary creds = ((User) user).getCredentials(); + Dictionary<String, Object> creds = (((User) user).getCredentials()); test1 = creds.get("test1"); //$NON-NLS-1$ assertEquals("test1", "valu", test1); //$NON-NLS-1$ //$NON-NLS-2$ test2 = creds.get("test2"); //$NON-NLS-1$ @@ -88,6 +95,7 @@ public class UserTest extends TestCase { } } + @Test public void testUserCreateAndRemove() throws Exception { User user = (User) userAdmin.createRole("testUserCreateAndRemove", Role.USER); //$NON-NLS-1$ assertNotNull(user); @@ -97,17 +105,20 @@ public class UserTest extends TestCase { assertNull(userAdmin.getRole("testUserCreateAndRemove")); //$NON-NLS-1$ } - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Activator.getBundle(Activator.BUNDLE_USERADMIN).start(); - userAdminReference = Activator.getBundleContext().getServiceReference(UserAdmin.class.getName()); - userAdmin = (UserAdmin) Activator.getBundleContext().getService(userAdminReference); + userAdminReference = Activator.getBundleContext().getServiceReference(UserAdmin.class); + userAdmin = Activator.getBundleContext().getService(userAdminReference); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { Activator.getBundleContext().ungetService(userAdminReference); Activator.getBundle(Activator.BUNDLE_USERADMIN).stop(); } + @SuppressWarnings("unchecked") private void createUser1() { User user = (User) userAdmin.createRole("testUserCreate1", Role.USER); //$NON-NLS-1$ assertNotNull(user); @@ -125,11 +136,12 @@ public class UserTest extends TestCase { removeUser1(); } catch (Exception e) { // Ignore. - } catch (AssertionFailedError e) { + } catch (AssertionError error) { // Ignore. } } + @SuppressWarnings("unchecked") private void createUser2() { User user = (User) userAdmin.createRole("testUserCreate2", Role.USER); //$NON-NLS-1$ assertNotNull(user); @@ -153,7 +165,7 @@ public class UserTest extends TestCase { removeUser2(); } catch (Exception e) { // Ignore. - } catch (AssertionFailedError e) { + } catch (AssertionError error) { // Ignore. } } |