From 17a221a49b324c10c4a804202fac6ee753940fc3 Mon Sep 17 00:00:00 2001
From: Andrew M Finkbeiner
Date: Mon, 18 Mar 2013 16:41:17 -0700
Subject: feature[ats_5Z6FP]: Add OTE api test
Change-Id: Ib44785586cd7ccb57450616c338bddc3153f391a
---
plugins/org.eclipse.osee.ote.test/.classpath | 7 +
plugins/org.eclipse.osee.ote.test/.project | 28 ++++
.../org.eclipse.osee.ote.test/META-INF/MANIFEST.MF | 10 ++
plugins/org.eclipse.osee.ote.test/build.properties | 5 +
.../data/loading.test1.jar | Bin 0 -> 1167 bytes
.../data/loading.test2.jar | Bin 0 -> 1176 bytes
.../data/loading.test3.jar | Bin 0 -> 1182 bytes
.../org/eclipse/osee/ote/internal/OTEApiTest.java | 141 +++++++++++++++++++++
.../ote/internal/OTEStatusCallbackForTests.java | 39 ++++++
9 files changed, 230 insertions(+)
create mode 100644 plugins/org.eclipse.osee.ote.test/.classpath
create mode 100644 plugins/org.eclipse.osee.ote.test/.project
create mode 100644 plugins/org.eclipse.osee.ote.test/META-INF/MANIFEST.MF
create mode 100644 plugins/org.eclipse.osee.ote.test/build.properties
create mode 100644 plugins/org.eclipse.osee.ote.test/data/loading.test1.jar
create mode 100644 plugins/org.eclipse.osee.ote.test/data/loading.test2.jar
create mode 100644 plugins/org.eclipse.osee.ote.test/data/loading.test3.jar
create mode 100644 plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEApiTest.java
create mode 100644 plugins/org.eclipse.osee.ote.test/src/org/eclipse/osee/ote/internal/OTEStatusCallbackForTests.java
(limited to 'plugins/org.eclipse.osee.ote.test')
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 @@
+
+
+
+
+
+
+
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 @@
+
+
+ org.eclipse.osee.ote.test
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
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
new file mode 100644
index 00000000000..0e6549aaa3a
Binary files /dev/null and b/plugins/org.eclipse.osee.ote.test/data/loading.test1.jar differ
diff --git a/plugins/org.eclipse.osee.ote.test/data/loading.test2.jar b/plugins/org.eclipse.osee.ote.test/data/loading.test2.jar
new file mode 100644
index 00000000000..dac01e7d2a7
Binary files /dev/null and b/plugins/org.eclipse.osee.ote.test/data/loading.test2.jar differ
diff --git a/plugins/org.eclipse.osee.ote.test/data/loading.test3.jar b/plugins/org.eclipse.osee.ote.test/data/loading.test3.jar
new file mode 100644
index 00000000000..ccd4c16226b
Binary files /dev/null and b/plugins/org.eclipse.osee.ote.test/data/loading.test3.jar differ
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 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 callable = new OTEStatusCallbackForTests();
+
+ OTEFuture 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 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 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 good = oteApi.loadConfiguration(validConfiguration, callable);
+ OTEFuture 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 implements OTEStatusCallback {
+
+ @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);
+ }
+
+}
--
cgit v1.2.3