diff options
author | Andrew M Finkbeiner | 2013-03-18 23:41:17 +0000 |
---|---|---|
committer | donald.g.dunne | 2013-03-27 19:21:14 +0000 |
commit | 17a221a49b324c10c4a804202fac6ee753940fc3 (patch) | |
tree | 92518a1cbe53553d83eb52cd5c5ad240973fa047 /plugins/org.eclipse.osee.ote.test | |
parent | 2c20a3cc3324603350c040dbd64d0991e2428aa6 (diff) | |
download | org.eclipse.osee-17a221a49b324c10c4a804202fac6ee753940fc3.tar.gz org.eclipse.osee-17a221a49b324c10c4a804202fac6ee753940fc3.tar.xz org.eclipse.osee-17a221a49b324c10c4a804202fac6ee753940fc3.zip |
feature[ats_5Z6FP]: Add OTE api test
Change-Id: Ib44785586cd7ccb57450616c338bddc3153f391a
Diffstat (limited to 'plugins/org.eclipse.osee.ote.test')
-rw-r--r-- | plugins/org.eclipse.osee.ote.test/.classpath | 7 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ote.test/.project | 28 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ote.test/META-INF/MANIFEST.MF | 10 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ote.test/build.properties | 5 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ote.test/data/loading.test1.jar | bin | 0 -> 1167 bytes | |||
-rw-r--r-- | plugins/org.eclipse.osee.ote.test/data/loading.test2.jar | bin | 0 -> 1176 bytes | |||
-rw-r--r-- | plugins/org.eclipse.osee.ote.test/data/loading.test3.jar | bin | 0 -> 1182 bytes | |||
-rw-r--r-- | plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEApiTest.java | 141 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEStatusCallbackForTests.java | 39 |
9 files changed, 230 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ote.test/.classpath b/plugins/org.eclipse.osee.ote.test/.classpath new file mode 100644 index 00000000000..ad32c83a788 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.test/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.osee.ote.test/.project b/plugins/org.eclipse.osee.ote.test/.project new file mode 100644 index 00000000000..eab8cb11976 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.test/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.osee.ote.test</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.eclipse.osee.ote.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.test/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..62aef733961 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.test/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Test +Bundle-SymbolicName: org.eclipse.osee.ote.test +Bundle-Version: 1.0.0.qualifier +Fragment-Host: org.eclipse.osee.ote;bundle-version="1.0.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Require-Bundle: org.junit, + org.eclipse.equinox.event;bundle-version="1.2.200", + org.eclipse.equinox.ds;bundle-version="1.4.0" diff --git a/plugins/org.eclipse.osee.ote.test/build.properties b/plugins/org.eclipse.osee.ote.test/build.properties new file mode 100644 index 00000000000..be6734d3b42 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.test/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + data/ diff --git a/plugins/org.eclipse.osee.ote.test/data/loading.test1.jar b/plugins/org.eclipse.osee.ote.test/data/loading.test1.jar Binary files differnew file mode 100644 index 00000000000..0e6549aaa3a --- /dev/null +++ b/plugins/org.eclipse.osee.ote.test/data/loading.test1.jar diff --git a/plugins/org.eclipse.osee.ote.test/data/loading.test2.jar b/plugins/org.eclipse.osee.ote.test/data/loading.test2.jar Binary files differnew file mode 100644 index 00000000000..dac01e7d2a7 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.test/data/loading.test2.jar diff --git a/plugins/org.eclipse.osee.ote.test/data/loading.test3.jar b/plugins/org.eclipse.osee.ote.test/data/loading.test3.jar Binary files differnew file mode 100644 index 00000000000..ccd4c16226b --- /dev/null +++ b/plugins/org.eclipse.osee.ote.test/data/loading.test3.jar diff --git a/plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEApiTest.java b/plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEApiTest.java new file mode 100644 index 00000000000..b32a0f7d03f --- /dev/null +++ b/plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEApiTest.java @@ -0,0 +1,141 @@ +package org.eclipse.osee.ote.internal; + +import java.io.IOException; +import java.net.URL; + +import org.eclipse.osee.framework.jdk.core.util.ChecksumUtil; +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.OTEConfiguration; +import org.eclipse.osee.ote.OTEConfigurationItem; +import org.eclipse.osee.ote.OTEConfigurationStatus; +import org.eclipse.osee.ote.OTEFuture; +import org.eclipse.osee.ote.OTEStatusCallback; +import org.eclipse.osgi.framework.internal.core.BundleFragment; +import org.eclipse.osgi.framework.internal.core.BundleHost; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; + +@SuppressWarnings("restriction") +public class OTEApiTest { + + private OTEApi oteApi; + + @Before + public void setup(){ + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + ServiceReference<OTEApi> ref = context.getServiceReference(OTEApi.class); + Assert.assertNotNull(ref); + oteApi = context.getService(ref); + Assert.assertNotNull(oteApi); + } + + @Test + public void testConfigurationLoading() throws IOException, Exception { + clearJarCache(); + URL bundle1 = findEntry("data/loading.test1.jar"); + URL bundle2 = findEntry("data/loading.test2.jar"); + URL bundle3 = findEntry("data/loading.test3.jar"); + OTEConfigurationItem config1 = new OTEConfigurationItem(bundle1.toString(), "1.0.0", "loading.test1", ChecksumUtil.createChecksumAsString(bundle1.openStream(), "MD5")); + OTEConfigurationItem config2 = new OTEConfigurationItem(bundle2.toString(), "1.0.0", "loading.test2", ChecksumUtil.createChecksumAsString(bundle2.openStream(), "MD5")); + OTEConfigurationItem config3 = new OTEConfigurationItem(bundle3.toString(), "1.0.0", "loading.test3", ChecksumUtil.createChecksumAsString(bundle3.openStream(), "MD5")); + + OTEConfiguration validConfiguration = new OTEConfiguration(); + validConfiguration.addItem(config1); + validConfiguration.addItem(config2); + validConfiguration.addItem(config3); + + OTEStatusCallback<OTEConfigurationStatus> callable = new OTEStatusCallbackForTests<OTEConfigurationStatus>(); + + OTEFuture<OTEConfigurationStatus> statusFuture = oteApi.loadConfiguration(validConfiguration, callable); + OTEConfigurationStatus status = statusFuture.get(); + Assert.assertTrue(status.isSuccess()); + Assert.assertEquals(validConfiguration, status.getConfiguration()); + Assert.assertEquals(validConfiguration, oteApi.getConfiguration().get().getConfiguration()); + + + Bundle bundle = findBundle("loading.test1"); + Assert.assertNotNull(bundle); + Assert.assertEquals(Bundle.ACTIVE, bundle.getState()); + + bundle = findBundle("loading.test2"); + Assert.assertNotNull(bundle); + Assert.assertEquals(Bundle.ACTIVE, bundle.getState()); + + bundle = findBundle("loading.test3"); + Assert.assertNotNull(bundle); + Assert.assertEquals(Bundle.ACTIVE, bundle.getState()); + + + OTEFuture<OTEConfigurationStatus> resetFeature = oteApi.resetConfiguration(callable); + OTEConfigurationStatus resetStatus = resetFeature.get(); + Assert.assertTrue(resetStatus.isSuccess()); + Assert.assertNull(findBundle("loading.test1")); + Assert.assertNull(findBundle("loading.test2")); + Assert.assertNull(findBundle("loading.test3")); + + OTEConfiguration invalidConfiguration = new OTEConfiguration(); + invalidConfiguration.addItem(config1); + invalidConfiguration.addItem(config3); + OTEFuture<OTEConfigurationStatus> failStatusFuture = oteApi.loadConfiguration(invalidConfiguration, callable); + OTEConfigurationStatus failStatus = failStatusFuture.get(); + Assert.assertFalse(failStatus.isSuccess()); + System.out.println(failStatus.getMessage()); + Assert.assertNull(findBundle("loading.test1")); + Assert.assertNull(findBundle("loading.test2")); + Assert.assertNull(findBundle("loading.test3")); + + //test the doing load case + OTEFuture<OTEConfigurationStatus> good = oteApi.loadConfiguration(validConfiguration, callable); + OTEFuture<OTEConfigurationStatus> bad = oteApi.loadConfiguration(validConfiguration, callable); + + OTEConfigurationStatus goodStatus = good.get(); + OTEConfigurationStatus badStatus = bad.get(); + Assert.assertTrue(goodStatus.isSuccess()); + Assert.assertFalse(badStatus.isSuccess()); + System.out.println(badStatus.getMessage()); + + //test already configured + bad = oteApi.loadConfiguration(validConfiguration, callable); + badStatus = bad.get(); + Assert.assertFalse(badStatus.isSuccess()); + System.out.println(badStatus.getMessage()); + } + + private void clearJarCache() { + OTEApiComponent impl = (OTEApiComponent)oteApi; + impl.clearJarCache(); + } + + private Bundle findBundle(String symbolicName){ + Bundle[] bundles = FrameworkUtil.getBundle(OTEApiTest.class).getBundleContext().getBundles(); + for(Bundle bundle:bundles){ + if(bundle.getSymbolicName().equals(symbolicName)){ + return bundle; + } + } + return null; + } + + private URL findEntry(String path){ + URL url = null; + Bundle bundle = FrameworkUtil.getBundle(OTEApiTest.class); + url = bundle.getEntry(path); + if(url == null && bundle instanceof BundleHost){ + BundleFragment[] fragments = ((BundleHost)bundle).getFragments(); + for(BundleFragment fragment: fragments){ + url = fragment.getEntry(path); + if(url != null){ + break; + } + } + } + Assert.assertNotNull(url); + return url; + } + +} diff --git a/plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEStatusCallbackForTests.java b/plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEStatusCallbackForTests.java new file mode 100644 index 00000000000..a11c9134648 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEStatusCallbackForTests.java @@ -0,0 +1,39 @@ +package org.eclipse.osee.ote.internal; + +import org.eclipse.osee.ote.OTEConfigurationStatus; +import org.eclipse.osee.ote.OTEStatusCallback; + +public class OTEStatusCallbackForTests<T> implements OTEStatusCallback<OTEConfigurationStatus> { + + @Override + public void complete(OTEConfigurationStatus done) { + System.out.println("done"); + } + + @Override + public void setTotalUnitsOfWork(int totalUnitsOfWork) { + System.out.println("units " + totalUnitsOfWork); + } + + @Override + public void incrememtUnitsWorked(int count) { + System.out.println("units " + count); + } + + @Override + public void log(String string) { + System.out.println(string); + } + + @Override + public void error(String message, Throwable th) { + System.out.println(message); + th.printStackTrace(); + } + + @Override + public void error(String message) { + System.out.println(message); + } + +} |