Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorslewis2018-04-02 16:15:49 -0400
committerslewis2018-04-02 16:15:49 -0400
commit4a57e441dc58fb13dd1ed03fbf564d2fb72e3b20 (patch)
tree3907300cae1f2135cb399e672c5761c5d4e948b0 /tests
parent26609be7053ab3524e383a75e11e2b0a25dfca2c (diff)
downloadorg.eclipse.ecf-4a57e441dc58fb13dd1ed03fbf564d2fb72e3b20.tar.gz
org.eclipse.ecf-4a57e441dc58fb13dd1ed03fbf564d2fb72e3b20.tar.xz
org.eclipse.ecf-4a57e441dc58fb13dd1ed03fbf564d2fb72e3b20.zip
Additional fixes for bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=532205 Added support for osgi.basic serialization specification in the form of org.eclipse.ecf.util.OSGIObjectOutputStream and OSGIObjectInputStream Change-Id: Ic82780c6f4179a27928fb95261ad766be7ad4526
Diffstat (limited to 'tests')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.core/META-INF/MANIFEST.MF5
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.core/src/org/eclipse/ecf/tests/core/util/OSGIObjectStreamTest.java153
2 files changed, 156 insertions, 2 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.core/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.core/META-INF/MANIFEST.MF
index 271a3b9e6..b0c740ee7 100644
--- a/tests/bundles/org.eclipse.ecf.tests.core/META-INF/MANIFEST.MF
+++ b/tests/bundles/org.eclipse.ecf.tests.core/META-INF/MANIFEST.MF
@@ -3,11 +3,12 @@ Bundle-ManifestVersion: 2
Bundle-Name: ECF Core Tests
Bundle-SymbolicName: org.eclipse.ecf.tests.core
Automatic-Module-Name: org.eclipse.ecf.tests.core
-Bundle-Version: 1.0.100.qualifier
+Bundle-Version: 1.1.0.qualifier
Bundle-Activator: org.eclipse.ecf.internal.tests.core.Activator
Bundle-Vendor: Eclipse.org - ECF
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Import-Package: org.osgi.framework;version="1.3.0",
+Import-Package: org.osgi.dto;version="1.0.0",
+ org.osgi.framework;version="1.3.0",
org.osgi.util.tracker;version="1.5.1"
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.ecf;bundle-version="3.3.0",
diff --git a/tests/bundles/org.eclipse.ecf.tests.core/src/org/eclipse/ecf/tests/core/util/OSGIObjectStreamTest.java b/tests/bundles/org.eclipse.ecf.tests.core/src/org/eclipse/ecf/tests/core/util/OSGIObjectStreamTest.java
new file mode 100644
index 000000000..639b1f9c7
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.core/src/org/eclipse/ecf/tests/core/util/OSGIObjectStreamTest.java
@@ -0,0 +1,153 @@
+package org.eclipse.ecf.tests.core.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.ecf.core.util.OSGIObjectInputStream;
+import org.eclipse.ecf.core.util.OSGIObjectOutputStream;
+import org.eclipse.ecf.internal.tests.core.Activator;
+import org.osgi.dto.DTO;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+import junit.framework.TestCase;
+
+public class OSGIObjectStreamTest extends TestCase {
+
+ public static class MyDTO extends DTO {
+ public double d1;
+ public String s;
+ public MyDTO dto;
+ }
+
+ public static class MySerializable implements Serializable {
+ private static final long serialVersionUID = 7671873163370195115L;
+ private String first;
+ private long second;
+ private byte[] bytes;
+
+ public MySerializable(String f, long s, byte[] b) {
+ this.first = f;
+ this.second = s;
+ this.bytes = b;
+ }
+
+ public String getFirst() {
+ return first;
+ }
+
+ public long getSecond() {
+ return second;
+ }
+
+ public byte[] getBytes() {
+ return bytes;
+ }
+ }
+
+ MyDTO dto1;
+ MyDTO dto2;
+ Version v1;
+ Version v2;
+ String s;
+ MySerializable ser;
+ Bundle b;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ MyDTO dto1 = new MyDTO();
+ dto1.d1 = 1.0;
+ dto1.s = "test";
+ dto1.dto = null;
+
+ MyDTO dto2 = new MyDTO();
+ dto2.d1 = 2.0;
+ dto2.s = "test2";
+ dto2.dto = new MyDTO();
+ dto2.dto.s = "test3";
+
+ v1 = Version.valueOf("1.0.1.myfirstversion");
+ v2 = Version.valueOf("2.0.2.mysecondversion");
+
+ s = "my string is as it is";
+
+ ser = new MySerializable("first string", 100, new byte[] { 1, 2, 3 });
+
+ b = Activator.getContext().getBundle();
+ }
+
+ public void testOSGIObjectOutputStream() throws Exception {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ OSGIObjectOutputStream oos = new OSGIObjectOutputStream(bos);
+ oos.writeObject(ser);
+ oos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ OSGIObjectInputStream ois = new OSGIObjectInputStream(Activator.getContext().getBundle(),bis);
+ Object result = ois.readObject();
+ ois.close();
+
+ }
+
+ public void testObjectOutputStream() throws Exception {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(ser);
+ oos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bis);
+ Object result = ois.readObject();
+ ois.close();
+
+ }
+
+
+ public void testDTOMap() throws Exception {
+ Map<String, DTO> dtos = new HashMap<String, DTO>();
+ dtos.put("one", dto1);
+ dtos.put("two", dto2);
+ assertTrue(dtos.equals(serializeDeserialize(dtos)));
+ }
+
+ public void testVersionArray() throws Exception {
+ Version[] versions = new Version[2];
+ versions[0] = v1;
+ versions[1] = v2;
+ assertTrue(Arrays.equals(versions, (Version[]) serializeDeserialize(versions)));
+ }
+
+ public void testString() throws Exception {
+ assertEquals(s, (String) serializeDeserialize(s));
+ }
+
+ private Object serializeDeserialize(Object o) throws IOException, ClassNotFoundException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ OSGIObjectOutputStream oos = new OSGIObjectOutputStream(bos);
+ oos.writeObject(o);
+ oos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ OSGIObjectInputStream ois = new OSGIObjectInputStream(b,bis);
+ Object result = ois.readObject();
+ ois.close();
+ return result;
+ }
+
+ public void testSerializable() throws Exception {
+ MySerializable r = (MySerializable) serializeDeserialize(ser);
+ assertEquals(r.getFirst(),ser.getFirst());
+ assertEquals(r.getSecond(),ser.getSecond());
+ assertTrue(Arrays.equals(r.getBytes(),ser.getBytes()));
+ }
+
+
+}

Back to the top