You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2017/02/24 14:36:53 UTC
[1/3] flex-blazeds git commit: - Converted the testsuite to JUnit 4
Repository: flex-blazeds
Updated Branches:
refs/heads/develop 11b0aa132 -> 9f2a242d3
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java b/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java
index afd2680..956dd44 100644
--- a/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java
+++ b/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java
@@ -20,163 +20,136 @@ package flex.messaging.services.http;
import flex.messaging.MessageBroker;
import flex.messaging.MessageException;
import flex.messaging.util.SettingsReplaceUtil;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import java.util.ArrayList;
import java.util.Set;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.junit.Assert;
-public class SettingsReplaceUtilTest extends TestCase
-{
- public SettingsReplaceUtilTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(SettingsReplaceUtilTest.class);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
+public class SettingsReplaceUtilTest {
+ @Before
+ public void setUp() throws Exception {
MessageBroker broker = new MessageBroker(false);
broker.initThreadLocals();
}
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void testReplaceContextPathDash()
- {
+ @Test
+ public void testReplaceContextPathDash() {
String actual = SettingsReplaceUtil.replaceContextPath("http://localhost:8100/{context-root}/foo.mxml", "/dev");
String expected = "http://localhost:8100/dev/foo.mxml";
Assert.assertEquals(expected, actual);
}
- public void testReplaceContextPathDot()
- {
+ @Test
+ public void testReplaceContextPathDot() {
String actual = SettingsReplaceUtil.replaceContextPath("http://localhost:8100/{context.root}/foo.mxml", "/dev");
String expected = "http://localhost:8100/dev/foo.mxml";
Assert.assertEquals(expected, actual);
}
- public void testReplaceContextPathBegin()
- {
+ @Test
+ public void testReplaceContextPathBegin() {
String actual = SettingsReplaceUtil.replaceContextPath("{context.root}/foo.mxml", "/dev");
String expected = "/dev/foo.mxml";
Assert.assertEquals(expected, actual);
}
- public void testReplaceContextPathEnd()
- {
+ @Test
+ public void testReplaceContextPathEnd() {
String actual = SettingsReplaceUtil.replaceContextPath("http://localhost:8100/{context.root}", "/dev");
String expected = "http://localhost:8100/dev";
Assert.assertEquals(expected, actual);
}
- public void testReplaceContextPathNull()
- {
- try
- {
+ @Test
+ public void testReplaceContextPathNull() {
+ try {
String actual = SettingsReplaceUtil.replaceContextPath("http://localhost:8100/{context.root}", null);
- fail("MessageException expected. Result was " + actual);
- }
- catch (MessageException me)
- {
+ Assert.fail("MessageException expected. Result was " + actual);
+ } catch (MessageException me) {
String error = "{context.root} token cannot";
- Assert.assertTrue(me.getMessage().indexOf(error) != -1);
+ Assert.assertTrue(me.getMessage().contains(error));
}
}
- public void testReplaceGivenServerDash()
- {
+ @Test
+ public void testReplaceGivenServerDash() {
String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server-name}:{server-port}/dev/foo.mxml",
- "/dev", "10.1.1.1", "80", "http");
+ "/dev", "10.1.1.1", "80", "http");
String expected = "http://10.1.1.1:80/dev/foo.mxml";
Assert.assertEquals(expected, actual);
}
- public void testReplaceGivenServerDot()
- {
+ @Test
+ public void testReplaceGivenServerDot() {
String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:{server.port}/dev/foo.mxml",
- "/dev", "10.1.1.1", "80", "http");
+ "/dev", "10.1.1.1", "80", "http");
String expected = "http://10.1.1.1:80/dev/foo.mxml";
Assert.assertEquals(expected, actual);
}
- public void testReplaceGivenServerNullPort()
- {
- try
- {
+ @Test
+ public void testReplaceGivenServerNullPort() {
+ try {
String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:{server.port}/dev/foo.mxml",
- "/dev", "10.1.1.1", null, "http");
- fail("MessageException expected. Result was " + actual);
- }
- catch (MessageException me)
- {
+ "/dev", "10.1.1.1", null, "http");
+ Assert.fail("MessageException expected. Result was " + actual);
+ } catch (MessageException me) {
String error = "{server.port} token cannot";
- Assert.assertTrue(me.getMessage().indexOf(error) != -1);
+ Assert.assertTrue(me.getMessage().contains(error));
}
}
- public void testReplaceGivenServerStarPort()
- {
+ @Test
+ public void testReplaceGivenServerStarPort() {
String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:*/dev/foo.mxml",
- "/dev", "10.1.1.1", "80", "http");
+ "/dev", "10.1.1.1", "80", "http");
String expected = "http://10.1.1.1:*/dev/foo.mxml";
Assert.assertEquals(expected, actual);
}
- public void testReplaceGivenServerContextRoot()
- {
+ @Test
+ public void testReplaceGivenServerContextRoot() {
String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:{server.port}/{context.root}/foo.mxml",
- "/dev", "10.1.1.1", "80", "http");
+ "/dev", "10.1.1.1", "80", "http");
String expected = "http://10.1.1.1:80/dev/foo.mxml";
Assert.assertEquals(expected, actual);
}
- public void testReplaceGivenServerNoPort()
- {
+ @Test
+ public void testReplaceGivenServerNoPort() {
String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}/dev/foo.mxml",
- "/dev", "10.1.1.1", "80", "http");
+ "/dev", "10.1.1.1", "80", "http");
String expected = "http://10.1.1.1/dev/foo.mxml";
Assert.assertEquals(expected, actual);
}
- public void testReplaceGivenServerNull()
- {
- try
- {
+ @Test
+ public void testReplaceGivenServerNull() {
+ try {
String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:{server.port}/{context.root}/foo.mxml",
- null, null, null, "http");
- fail("MessageException expected. Result was " + actual);
- }
- catch (MessageException me)
- {
+ null, null, null, "http");
+ Assert.fail("MessageException expected. Result was " + actual);
+ } catch (MessageException me) {
String error = "{context.root} token cannot";
- Assert.assertTrue(me.getMessage().indexOf(error) != -1);
+ Assert.assertTrue(me.getMessage().contains(error));
}
}
- public void testReplaceGivenServerRelative()
- {
+ @Test
+ public void testReplaceGivenServerRelative() {
String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("/dev/foo.mxml",
- "/dev", "10.1.1.1", "80", "http");
+ "/dev", "10.1.1.1", "80", "http");
String expected = "http://10.1.1.1:80/dev/foo.mxml";
Assert.assertEquals(expected, actual);
}
- public void testReplaceCalculateServer()
- {
- ArrayList urls = new ArrayList();
+ @Test
+ public void testReplaceCalculateServer() {
+ ArrayList<String> urls = new ArrayList<String>();
urls.add("http://{server.name}:*/dev/foo.mxml");
Set updatedUrls = SettingsReplaceUtil.replaceAllTokensCalculateServerName(urls, "/dev");
@@ -185,25 +158,22 @@ public class SettingsReplaceUtilTest extends TestCase
Assert.assertTrue(updatedUrls.contains("http://127.0.0.1:*/dev/foo.mxml"));
}
- public void testReplaceCalculateServerPort()
- {
- try
- {
- ArrayList urls = new ArrayList();
+ @Test
+ public void testReplaceCalculateServerPort() {
+ try {
+ ArrayList<String> urls = new ArrayList<String>();
urls.add("http://{server.name}:{server.port}/dev/foo.mxml");
Set updatedUrls = SettingsReplaceUtil.replaceAllTokensCalculateServerName(urls, "/dev");
- fail("MessageException expected. Instead result was " + updatedUrls);
- }
- catch (MessageException me)
- {
+ Assert.fail("MessageException expected. Instead result was " + updatedUrls);
+ } catch (MessageException me) {
String error = "{server.port} token cannot";
- Assert.assertTrue(me.getMessage().indexOf(error) != -1);
+ Assert.assertTrue(me.getMessage().contains(error));
}
}
- public void testReplaceCalculateServerMultiple()
- {
- ArrayList urls = new ArrayList();
+ @Test
+ public void testReplaceCalculateServerMultiple() {
+ ArrayList<String> urls = new ArrayList<String>();
urls.add("http://{server.name}:*/dev/foo.mxml");
Set updatedUrls = SettingsReplaceUtil.replaceAllTokensCalculateServerName(urls, "/dev");
int count = updatedUrls.size();
@@ -212,8 +182,8 @@ public class SettingsReplaceUtilTest extends TestCase
Assert.assertTrue(updatedUrls.size() == count); // should result in the same list
}
- public void testIPv6ShortForm()
- {
+ @Test
+ public void testIPv6ShortForm() {
String src = "http://[fe80::20d:60ff:fef9:8757]:8400/qa-regress/basic.html";
String expected = "http://[fe80:0:0:0:20d:60ff:fef9:8757]:8400/qa-regress/basic.html";
Assert.assertEquals(expected, SettingsReplaceUtil.updateIPv6(src));
@@ -221,7 +191,7 @@ public class SettingsReplaceUtilTest extends TestCase
src = "http://[fe80::20d:60ff:fef9:8757]:8400/*";
expected = "http://[fe80:0:0:0:20d:60ff:fef9:8757]:8400/*";
Assert.assertEquals(expected, SettingsReplaceUtil.updateIPv6(src));
-
+
src = "http://[::1]:8400/*";
expected = "http://[0:0:0:0:0:0:0:1]:8400/*";
Assert.assertEquals(expected, SettingsReplaceUtil.updateIPv6(src));
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java b/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java
index 8286345..5e96fe6 100644
--- a/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java
+++ b/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java
@@ -17,99 +17,86 @@
package flex.messaging.services.messaging;
import org.junit.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.Test;
-public class SubtopicTest extends TestCase
-{
+public class SubtopicTest {
private static final String DEFAULT_SEPERATOR = ".";
private static final String ANOTHER_SEPERATOR = "*";
- public SubtopicTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(SubtopicTest.class);
- }
-
- public void testMatches1()
- {
+ @Test
+ public void testMatches1() {
Subtopic s1 = new Subtopic("foo", DEFAULT_SEPERATOR);
Subtopic s2 = new Subtopic("foo", DEFAULT_SEPERATOR);
boolean result = s1.matches(s2);
Assert.assertTrue(result);
}
- public void testMatches2()
- {
+ @Test
+ public void testMatches2() {
Subtopic s1 = new Subtopic("foo", DEFAULT_SEPERATOR);
Subtopic s2 = new Subtopic("bar", DEFAULT_SEPERATOR);
boolean result = s1.matches(s2);
Assert.assertFalse(result);
}
-
- public void testMatches3()
- {
+
+ @Test
+ public void testMatches3() {
Subtopic s1 = new Subtopic("foo.bar", DEFAULT_SEPERATOR);
Subtopic s2 = new Subtopic("foo.bar", DEFAULT_SEPERATOR);
boolean result = s1.matches(s2);
Assert.assertTrue(result);
}
- public void testMatches4()
- {
+ @Test
+ public void testMatches4() {
Subtopic s1 = new Subtopic("foo.bar", DEFAULT_SEPERATOR);
Subtopic s2 = new Subtopic("foo*bar", ANOTHER_SEPERATOR);
boolean result = s1.matches(s2);
Assert.assertFalse(result);
}
- public void testMatches5()
- {
+ @Test
+ public void testMatches5() {
Subtopic s1 = new Subtopic("*", DEFAULT_SEPERATOR);
- Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR);
+ Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR);
boolean result = s1.matches(s2);
Assert.assertTrue(result);
}
- public void testMatches6()
- {
+ @Test
+ public void testMatches6() {
Subtopic s1 = new Subtopic("foo.*", DEFAULT_SEPERATOR);
Subtopic s2 = new Subtopic("foo.bar", DEFAULT_SEPERATOR);
boolean result = s1.matches(s2);
Assert.assertTrue(result);
}
- public void testMatches7()
- {
+ @Test
+ public void testMatches7() {
Subtopic s1 = new Subtopic("foo.*", DEFAULT_SEPERATOR);
Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR);
boolean result = s1.matches(s2);
Assert.assertTrue(result);
}
- public void testMatches8()
- {
+ @Test
+ public void testMatches8() {
Subtopic s1 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR);
- Subtopic s2 = new Subtopic("foo.*", DEFAULT_SEPERATOR);
+ Subtopic s2 = new Subtopic("foo.*", DEFAULT_SEPERATOR);
boolean result = s1.matches(s2);
Assert.assertTrue(result);
}
- public void testMatches9()
- {
+ @Test
+ public void testMatches9() {
Subtopic s1 = new Subtopic("foo.bar.*", DEFAULT_SEPERATOR);
- Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR);
+ Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR);
boolean result = s1.matches(s2);
Assert.assertTrue(result);
}
- public void testMatches10()
- {
+ @Test
+ public void testMatches10() {
Subtopic s1 = new Subtopic("foo.*", DEFAULT_SEPERATOR);
Subtopic s2 = new Subtopic("foo", DEFAULT_SEPERATOR);
boolean result = s1.matches(s2);
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/util/Basae64Test.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/util/Basae64Test.java b/core/src/test/java/flex/messaging/util/Basae64Test.java
index 284163b..5d90fa3 100644
--- a/core/src/test/java/flex/messaging/util/Basae64Test.java
+++ b/core/src/test/java/flex/messaging/util/Basae64Test.java
@@ -17,38 +17,25 @@
package flex.messaging.util;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-public class Basae64Test extends TestCase
-{
- public Basae64Test(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(Basae64Test.class);
- }
+import org.junit.Test;
+public class Basae64Test {
/**
* Try encoding and decoding 10,000 random combinations of bytes.
*/
- public void testEncodingAndDecoding()
- {
+ @Test
+ public void testEncodingAndDecoding() {
int randomLimit = 500;
boolean success = true;
- byte raw [] = new byte[(int)(Math.random() * randomLimit)];
+ byte raw[] = new byte[(int) (Math.random() * randomLimit)];
- for (int i = 0; i < raw.length; ++i)
- {
+ for (int i = 0; i < raw.length; ++i) {
if ((i % 1024) < 256)
- raw[i] = (byte)(i % 1024);
+ raw[i] = (byte) (i % 1024);
else
- raw[i] = (byte)((int)(Math.random() * 255) - 128);
+ raw[i] = (byte) ((int) (Math.random() * 255) - 128);
}
Base64.Encoder encoder = new Base64.Encoder(100);
encoder.encode(raw);
@@ -59,22 +46,17 @@ public class Basae64Test extends TestCase
decoder.decode(encoded);
byte check[] = decoder.flush();
- if (check.length != raw.length)
- {
+ if (check.length != raw.length) {
success = false;
- }
- else
- {
- for (int i = 0; i < check.length; ++i)
- {
- if (check[i] != raw[i])
- {
+ } else {
+ for (int i = 0; i < check.length; ++i) {
+ if (check[i] != raw[i]) {
success = false;
break;
}
}
}
- assertTrue(success);
+ org.junit.Assert.assertTrue(success);
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/util/HexTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/util/HexTest.java b/core/src/test/java/flex/messaging/util/HexTest.java
index cf5a055..f22e2f5 100644
--- a/core/src/test/java/flex/messaging/util/HexTest.java
+++ b/core/src/test/java/flex/messaging/util/HexTest.java
@@ -17,40 +17,26 @@
package flex.messaging.util;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class HexTest extends TestCase
-{
- public HexTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(HexTest.class);
- }
+import org.junit.*;
+public class HexTest {
/**
* Try encoding and decoding 10,000 random combinations of bytes.
*/
- public void testEncodingAndDecoding()
- {
+ @Test
+ public void testEncodingAndDecoding() {
int randomLimit = 500;
boolean success = true;
- for (int myCount = 0; myCount < 10000; myCount++)
- {
- byte raw [] = new byte[(int)(Math.random() * randomLimit)];
+ for (int myCount = 0; myCount < 10000; myCount++) {
+ byte raw[] = new byte[(int) (Math.random() * randomLimit)];
- for (int i = 0; i < raw.length; ++i)
- {
- if ((i % 1024) < 256)
- raw[i] = (byte)(i % 1024);
- else
- raw[i] = (byte)((int)(Math.random() * 255) - 128);
+ for (int i = 0; i < raw.length; ++i) {
+ if ((i % 1024) < 256) {
+ raw[i] = (byte) (i % 1024);
+ } else {
+ raw[i] = (byte) ((int) (Math.random() * 255) - 128);
+ }
}
Hex.Encoder encoder = new Hex.Encoder(100);
encoder.encode(raw);
@@ -61,28 +47,22 @@ public class HexTest extends TestCase
decoder.decode(encoded);
byte check[] = decoder.flush();
- if (check.length != raw.length)
- {
+ if (check.length != raw.length) {
success = false;
- }
- else
- {
- for (int i = 0; i < check.length; ++i)
- {
- if (check[i] != raw[i])
- {
+ } else {
+ for (int i = 0; i < check.length; ++i) {
+ if (check[i] != raw[i]) {
success = false;
break;
}
}
}
- if (!success)
- {
+ if (!success) {
break;
}
}
- assertTrue(success);
+ org.junit.Assert.assertTrue(success);
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/util/UUIDUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/util/UUIDUtilTest.java b/core/src/test/java/flex/messaging/util/UUIDUtilTest.java
index 2f8b93d..4cb3a82 100644
--- a/core/src/test/java/flex/messaging/util/UUIDUtilTest.java
+++ b/core/src/test/java/flex/messaging/util/UUIDUtilTest.java
@@ -17,146 +17,137 @@
package flex.messaging.util;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.*;
-public class UUIDUtilTest extends TestCase
+public class UUIDUtilTest
{
- public UUIDUtilTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(UUIDUtilTest.class);
- }
-
+ @Test
public void testIsUID()
{
// Randomly generated
String uid = UUIDUtils.createUUID();
boolean result = UUIDUtils.isUID(uid);
- assertEquals(true, result);
+ org.junit.Assert.assertEquals(true, result);
// Pre-determined normal UID
uid = "8653177A-930D-F5DC-6FAA-E1E6F557504E";
result = UUIDUtils.isUID(uid);
- assertEquals(true, result);
+ org.junit.Assert.assertEquals(true, result);
// All numbers
uid = "06531779-9303-5532-6123-617685575043";
result = UUIDUtils.isUID(uid);
- assertEquals(true, result);
+ org.junit.Assert.assertEquals(true, result);
// All letters
uid = "FEABCDEE-FFCC-FCED-DAAB-BCDEFFABCDAE";
result = UUIDUtils.isUID(uid);
- assertEquals(true, result);
+ org.junit.Assert.assertEquals(true, result);
// All Fs
uid = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
result = UUIDUtils.isUID(uid);
- assertEquals(true, result);
+ org.junit.Assert.assertEquals(true, result);
// All 0s
uid = "00000000-0000-0000-0000-000000000000";
result = UUIDUtils.isUID(uid);
- assertEquals(true, result);
+ org.junit.Assert.assertEquals(true, result);
// Invalid: Too long
uid = "8653177A-930D-F5DC-6FAA-E1E6F557504EA";
result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ org.junit.Assert.assertEquals(false, result);
// Invalid: Too short
uid = "8653177A-930D-F5DC-6FAA-E1E6F557504";
result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ org.junit.Assert.assertEquals(false, result);
// Invalid: all hyphens
uid = "------------------------------------";
result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ org.junit.Assert.assertEquals(false, result);
// Invalid: No hyphens
uid = "8653177A0930D0F5DC06FAA0E1E6F557504E";
result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ org.junit.Assert.assertEquals(false, result);
// Invalid: non-hex char at end
uid = "8653177A-930D-F5DC-6FAA-E1E6F557504Z";
result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ org.junit.Assert.assertEquals(false, result);
// Invalid: non-hex char at start
uid = "G653177A-930D-F5DC-6FAA-E1E6F557504E";
result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ org.junit.Assert.assertEquals(false, result);
// Invalid: null-char
uid = "8653177A-930D-F5DC-6FAA-E1E6F557504\u0000";
result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ org.junit.Assert.assertEquals(false, result);
// Invalid: random word
uid = "Cacophony";
result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ org.junit.Assert.assertEquals(false, result);
// Invalid: empty string
uid = "";
result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ org.junit.Assert.assertEquals(false, result);
// Invalid: null
- uid = null;
- result = UUIDUtils.isUID(uid);
- assertEquals(false, result);
+ result = UUIDUtils.isUID(null);
+ org.junit.Assert.assertEquals(false, result);
}
+ @Test
public void testUIDToByteArray()
{
// Randomly generated
String uid = UUIDUtils.createUUID();
byte[] result = UUIDUtils.toByteArray(uid);
- assertEquals(true, result.length == 16);
+ org.junit.Assert.assertNotNull(result);
+ org.junit.Assert.assertEquals(true, result.length == 16);
// Pre-determined normal UID
uid = "8FEB51AC-1443-CA4C-D3A7-1AC1C5DC517B";
result = UUIDUtils.toByteArray(uid);
- assertEquals(true, result.length == 16);
+ org.junit.Assert.assertNotNull(result);
+ org.junit.Assert.assertEquals(true, result.length == 16);
// Invalid UID
uid = "8FEB51AC-1443-CA4C-D3A7-1AC1C5DC517Z";
result = UUIDUtils.toByteArray(uid);
- assertEquals(null, result);
+ org.junit.Assert.assertNull(result);
}
+ @Test
public void testUIDFromByteArray()
{
// Randomly generated
String uid1 = UUIDUtils.createUUID();
byte[] ba = UUIDUtils.toByteArray(uid1);
String uid2 = UUIDUtils.fromByteArray(ba);
- assertEquals(uid1, uid2);
+ org.junit.Assert.assertEquals(uid1, uid2);
// Pre-determined normal UID
uid1 = "86531839-0109-8B18-BB3A-CF8F546D0399";
ba = UUIDUtils.toByteArray(uid1);
uid2 = UUIDUtils.fromByteArray(ba);
- assertEquals(uid1, uid2);
+ org.junit.Assert.assertEquals(uid1, uid2);
// Invalid: ByteArray too short
ba = new byte[1];
ba[0] = 19;
uid2 = UUIDUtils.fromByteArray(ba);
- assertEquals(null, uid2);
+ org.junit.Assert.assertEquals(null, uid2);
// Invalid: null ByteArray
- ba = null;
- uid2 = UUIDUtils.fromByteArray(ba);
- assertEquals(null, uid2);
+ uid2 = UUIDUtils.fromByteArray(null);
+ org.junit.Assert.assertEquals(null, uid2);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java b/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java
index d3c0286..799f656 100644
--- a/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java
+++ b/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java
@@ -17,10 +17,8 @@
package flex.messaging.util.concurrent;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
import org.junit.Assert;
+import org.junit.Test;
import java.util.ArrayList;
import java.util.concurrent.ArrayBlockingQueue;
@@ -29,18 +27,10 @@ import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
-public class DefaultThreadPoolExecutorTest extends TestCase
+public class DefaultThreadPoolExecutorTest
{
- public DefaultThreadPoolExecutorTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(DefaultThreadPoolExecutorTest.class);
- }
-
+
+ @Test
public void testSimpleExecution()
{
// Create a small pool with a synchronous queue (no bounding or storage).
@@ -59,31 +49,32 @@ public class DefaultThreadPoolExecutorTest extends TestCase
boolean success = continueSignal.await(2, TimeUnit.SECONDS);
if (!success)
{
- fail("Test timed out waiting for execution to complete.");
+ Assert.fail("Test timed out waiting for execution to complete.");
}
}
catch (InterruptedException e)
{
- fail("Test was interrupted: " + e);
+ Assert.fail("Test was interrupted: " + e);
}
// Shut down; because we create the thread pool in this specific impl be sure to shut it down.
DefaultThreadPoolExecutor tpe = (DefaultThreadPoolExecutor)executor;
tpe.shutdown();
}
-
+
+ @Test
public void testFailedExecutionHandling()
{
// Create a small pool with a bounded queue that can only contain one queued task.
final DefaultThreadPoolExecutor executor = new DefaultThreadPoolExecutor(1, 1, Integer.MAX_VALUE, TimeUnit.SECONDS, new ArrayBlockingQueue(1));
final CountDownLatch taskPauseSignal = new CountDownLatch(1);
final CountDownLatch executorPauseSignal = new CountDownLatch(1);
- final ArrayList failedTasks = new ArrayList();
+ final ArrayList<Runnable> failedTasks = new ArrayList<Runnable>();
executor.setFailedExecutionHandler(new FailedExecutionHandler(){
public void failedExecution(Runnable command, Executor ex, Exception exception)
{
- assertEquals(executor, ex);
- assertTrue(exception instanceof RejectedExecutionException);
+ Assert.assertEquals(executor, ex);
+ Assert.assertTrue(exception instanceof RejectedExecutionException);
failedTasks.add(command);
// Unpause the initial task processing.
@@ -92,27 +83,27 @@ public class DefaultThreadPoolExecutorTest extends TestCase
});
// This first task will pause.
- executor.execute(new Task("first", this, taskPauseSignal, executorPauseSignal, executor));
+ executor.execute(new Task("first", taskPauseSignal, executorPauseSignal, executor));
// Now queue two more tasks to overflow the executor's queue.
- executor.execute(new Task("second", this, null, null, null));
- executor.execute(new Task("third", this, null, null, null));
+ executor.execute(new Task("second", null, null, null));
+ executor.execute(new Task("third", null, null, null));
// and wait.
try
{
boolean success = executorPauseSignal.await(5 * 60, TimeUnit.SECONDS);
if (!success)
{
- fail("Test timed out waiting for execution to complete.");
+ Assert.fail("Test timed out waiting for execution to complete.");
}
}
catch (InterruptedException e)
{
- fail("Test was interrupted: " + e);
+ Assert.fail("Test was interrupted: " + e);
}
// Test failed execution handling
- assertEquals(failedTasks.size(), 1);
- assertTrue(((Task)failedTasks.get(0)).name.equals("third"));
+ Assert.assertEquals(failedTasks.size(), 1);
+ Assert.assertTrue(((Task)failedTasks.get(0)).name.equals("third"));
// Shut down; because we create the thread pool in this specific impl be sure we shut it down.
executor.shutdown();
@@ -120,17 +111,15 @@ public class DefaultThreadPoolExecutorTest extends TestCase
static class Task implements Runnable
{
- public Task(String name, TestCase test, CountDownLatch taskPauseSignal, CountDownLatch executorPauseSignal, DefaultThreadPoolExecutor executor)
+ Task(String name, CountDownLatch taskPauseSignal, CountDownLatch executorPauseSignal, DefaultThreadPoolExecutor executor)
{
this.name = name;
- this.test = test;
this.taskPauseSignal = taskPauseSignal;
this.executorPauseSignal = executorPauseSignal;
this.executor = executor;
}
public String name;
- private TestCase test;
private CountDownLatch taskPauseSignal;
private CountDownLatch executorPauseSignal;
private DefaultThreadPoolExecutor executor;
@@ -149,8 +138,8 @@ public class DefaultThreadPoolExecutorTest extends TestCase
else
{
// At this point we should have the second task queued and the third task should have failed (overflow).
- assertEquals(executor.getQueue().size(), 1);
- assertTrue(((Task)executor.getQueue().peek()).name.equals("second"));
+ Assert.assertEquals(executor.getQueue().size(), 1);
+ Assert.assertTrue(((Task)executor.getQueue().peek()).name.equals("second"));
// Unblock the executor test thread.
executorPauseSignal.countDown();
[3/3] flex-blazeds git commit: - Converted the testsuite to JUnit 4
Posted by cd...@apache.org.
- Converted the testsuite to JUnit 4
Project: http://git-wip-us.apache.org/repos/asf/flex-blazeds/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-blazeds/commit/9f2a242d
Tree: http://git-wip-us.apache.org/repos/asf/flex-blazeds/tree/9f2a242d
Diff: http://git-wip-us.apache.org/repos/asf/flex-blazeds/diff/9f2a242d
Branch: refs/heads/develop
Commit: 9f2a242d36ee577bdfca54e20bf728946374c14d
Parents: 11b0aa1
Author: Christofer Dutz <ch...@codecentric.de>
Authored: Fri Feb 24 15:36:43 2017 +0100
Committer: Christofer Dutz <ch...@codecentric.de>
Committed: Fri Feb 24 15:36:43 2017 +0100
----------------------------------------------------------------------
.../java/flex/messaging/DestinationTest.java | 171 +++----
.../java/flex/messaging/MessageBrokerTest.java | 272 +++++------
.../messaging/client/FlexClientManagerTest.java | 99 ++--
.../cluster/SerializationProxyTest.java | 14 +-
.../config/ChannelSettingsParseUriTest.java | 118 ++---
.../config/ConfigurationConfirmation.java | 475 +++++++++----------
.../config/ConfigurationParserTest.java | 145 ++----
.../messaging/config/ThrottleSettingsTest.java | 144 ++----
.../io/ClassDeserializationValidatorTest.java | 7 -
.../messaging/io/amf/AmfDeserializerTest.java | 83 ++--
.../flex/messaging/io/amf/MessageGenerator.java | 214 +++------
.../amf/translator/HashReferenceTableTest.java | 208 ++++----
.../translator/StrictReferenceTableTest.java | 108 ++---
.../AmfDeserializationValidatorTest.java | 62 +--
.../io/amfx/AllowDocumentTypeDeclaration.java | 16 +-
.../io/amfx/AmfxSerializationTest.java | 218 ++++-----
.../test/java/flex/messaging/log/LogTest.java | 139 +++---
.../java/flex/messaging/log/LoggerTest.java | 97 ++--
.../java/flex/messaging/log/TestingTarget.java | 15 +-
.../BlazeDsXmlProcessingXXEVulnerability.java | 64 ---
.../messaging/services/AbstractServiceTest.java | 367 --------------
.../messaging/services/ServiceAdapterTest.java | 89 ++--
.../services/http/SettingsReplaceUtilTest.java | 166 +++----
.../services/messaging/SubtopicTest.java | 65 +--
.../java/flex/messaging/util/Basae64Test.java | 44 +-
.../test/java/flex/messaging/util/HexTest.java | 56 +--
.../java/flex/messaging/util/UUIDUtilTest.java | 73 ++-
.../DefaultThreadPoolExecutorTest.java | 53 +--
28 files changed, 1249 insertions(+), 2333 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/DestinationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/DestinationTest.java b/core/src/test/java/flex/messaging/DestinationTest.java
index 65985a9..382531e 100644
--- a/core/src/test/java/flex/messaging/DestinationTest.java
+++ b/core/src/test/java/flex/messaging/DestinationTest.java
@@ -17,58 +17,34 @@
package flex.messaging;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import flex.messaging.config.ChannelSettings;
-import flex.messaging.config.ConfigurationConstants;
-import flex.messaging.config.ConfigurationException;
-import flex.messaging.config.NetworkSettings;
-import flex.messaging.config.SecurityConstraint;
+import flex.messaging.config.*;
import flex.messaging.services.AbstractService;
import flex.messaging.services.MessageService;
import flex.messaging.services.ServiceAdapter;
import flex.messaging.services.messaging.adapters.ActionScriptAdapter;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
/**
* Important: While adding new tests, make sure you don't create dependencies
* to other modules. (eg. don't use RemotingDestination as that would create
* dependency on remoting module; instead add the test in remoting module).
*/
-public class DestinationTest extends TestCase
-{
+public class DestinationTest {
protected Destination destination;
- protected MessageBroker broker;
-
- public DestinationTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(DestinationTest.class);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
destination = new MessageDestination();
destination.setId("destId");
}
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void testSetService()
- {
+ @Test
+ public void testSetService() {
MessageBroker broker = new MessageBroker(false);
broker.initThreadLocals();
@@ -77,7 +53,7 @@ public class DestinationTest extends TestCase
broker.addService(service);
destination.setService(service);
- MessageService actualSvc = (MessageService)destination.getService();
+ MessageService actualSvc = (MessageService) destination.getService();
Assert.assertEquals(service, actualSvc);
@@ -85,23 +61,20 @@ public class DestinationTest extends TestCase
Assert.assertEquals(destination, actualDest);
}
- public void testSetServiceNull()
- {
- try
- {
+ @Test
+ public void testSetServiceNull() {
+ try {
destination.setService(null);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = 11116; //ManageableComponent.NULL_COMPONENT_PROPERTY;
Assert.assertEquals(ce.getNumber(), error);
}
}
- public void testSetAdapter()
- {
+ @Test
+ public void testSetAdapter() {
ServiceAdapter expected = new ActionScriptAdapter();
expected.setId("adapterId");
destination.setAdapter(expected);
@@ -111,16 +84,16 @@ public class DestinationTest extends TestCase
}
- public void testSetAdapterNull()
- {
+ @Test
+ public void testSetAdapterNull() {
destination.setAdapter(null);
ServiceAdapter actual = destination.getAdapter();
Assert.assertNull(actual);
}
- public void testSetAdapterNullId()
- {
+ @Test
+ public void testSetAdapterNullId() {
ServiceAdapter adapter = new ActionScriptAdapter();
destination.setAdapter(adapter);
@@ -129,8 +102,8 @@ public class DestinationTest extends TestCase
}
- public void testAddChannelNotStarted()
- {
+ @Test
+ public void testAddChannelNotStarted() {
String id = "default-channel";
destination.addChannel(id);
@@ -142,12 +115,12 @@ public class DestinationTest extends TestCase
* In running code, the channels would be added from the services-config.xml.
* Here, we have to force them into the broker.
*/
- public void testAddChannelStartedBrokerKnows()
- {
- start();
+ @Test
+ public void testAddChannelStartedBrokerKnows() {
String id = "default-channel";
Map<String, ChannelSettings> csMap = new HashMap<String, ChannelSettings>();
csMap.put(id, null);
+ MessageBroker broker = start();
broker.setChannelSettings(csMap);
destination.addChannel(id);
@@ -155,11 +128,11 @@ public class DestinationTest extends TestCase
Assert.assertTrue(contains);
}
- public void testCreateAdapterRegisteredWithService ()
- {
+ @Test
+ public void testCreateAdapterRegisteredWithService() {
MessageService service = new MessageService();
service.setId("dummy-service");
- broker = new MessageBroker(false);
+ MessageBroker broker = new MessageBroker(false);
broker.addService(service);
String adapterId = "id";
@@ -173,65 +146,55 @@ public class DestinationTest extends TestCase
Assert.assertEquals(expected, actual);
}
- public void testCreateAdapterWithoutService()
- {
- try
- {
+ @Test
+ public void testCreateAdapterWithoutService() {
+ try {
destination.createAdapter("id");
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = 11117; // Destination.NO_SERVICE;
Assert.assertEquals(ce.getNumber(), error);
}
}
- public void testCreateAdapterUnregisteredWithService()
- {
+ @Test
+ public void testCreateAdapterUnregisteredWithService() {
MessageService service = new MessageService();
service.setId("dummy-service");
- broker = new MessageBroker(false);
+ MessageBroker broker = new MessageBroker(false);
broker.addService(service);
destination.setService(service);
- try
- {
+ try {
destination.createAdapter("id");
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = ConfigurationConstants.UNREGISTERED_ADAPTER;
Assert.assertEquals(ce.getNumber(), error);
}
}
- public void testCreateAdapterWithExistingId()
- {
+ @Test
+ public void testCreateAdapterWithExistingId() {
String id = "java-adapter";
start();
- try
- {
+ try {
destination.createAdapter(id);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = ConfigurationConstants.UNREGISTERED_ADAPTER;
Assert.assertEquals(error, ce.getNumber());
}
}
-
- public void testSetNetworkSettings()
- {
+ @Test
+ public void testSetNetworkSettings() {
NetworkSettings ns = new NetworkSettings();
ns.setSubscriptionTimeoutMinutes(1);
destination.setNetworkSettings(ns);
@@ -240,8 +203,8 @@ public class DestinationTest extends TestCase
Assert.assertEquals(ns, actual);
}
- public void testSetSecurityConstraint()
- {
+ @Test
+ public void testSetSecurityConstraint() {
SecurityConstraint sc = new SecurityConstraint();
destination.setSecurityConstraint(sc);
@@ -249,8 +212,8 @@ public class DestinationTest extends TestCase
Assert.assertEquals(sc, actual);
}
- public void testSetSecurityConstraintRefNotStarted()
- {
+ @Test
+ public void testSetSecurityConstraintRefNotStarted() {
String ref = "sample-security";
destination.setSecurityConstraint(ref);
@@ -258,8 +221,8 @@ public class DestinationTest extends TestCase
Assert.assertNull(sc);
}
- public void testStop()
- {
+ @Test
+ public void testStop() {
start();
destination.stop();
@@ -267,20 +230,20 @@ public class DestinationTest extends TestCase
Assert.assertFalse(started);
}
- public void testSetManaged()
- {
+ @Test
+ public void testSetManaged() {
destination.setManaged(true);
boolean managed = destination.isManaged();
Assert.assertTrue(managed);
}
- public void testSetManagedParentUnmanaged()
- {
+ @Test
+ public void testSetManagedParentUnmanaged() {
MessageService service = new MessageService();
service.setId("dummy-service");
service.setManaged(false);
- broker = new MessageBroker(false);
+ MessageBroker broker = new MessageBroker(false);
broker.addService(service);
destination.setService(service);
@@ -290,15 +253,15 @@ public class DestinationTest extends TestCase
Assert.assertFalse(managed);
}
- public void testGetLogCategory()
- {
+ @Test
+ public void testGetLogCategory() {
String logCat = destination.getLogCategory();
String logCat2 = destination.getLogCategory();
Assert.assertEquals(logCat, logCat2);
}
- public void testExtraProperties()
- {
+ @Test
+ public void testExtraProperties() {
String propertyName = "extraProperty";
String propertyValue = "extraValue";
@@ -317,9 +280,8 @@ public class DestinationTest extends TestCase
Assert.assertEquals(actualDest.getExtraProperty(propertyName), propertyValue);
}
- private void start()
- {
- broker = new MessageBroker(false);
+ private MessageBroker start() {
+ MessageBroker broker = new MessageBroker(false);
MessageService service = new MessageService();
service.setId("dummy-service");
service.setMessageBroker(broker);
@@ -331,5 +293,6 @@ public class DestinationTest extends TestCase
destination.addChannel("some-Channel");
destination.setService(service);
destination.start();
+ return broker;
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/MessageBrokerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/MessageBrokerTest.java b/core/src/test/java/flex/messaging/MessageBrokerTest.java
index f5be8d7..8151793 100644
--- a/core/src/test/java/flex/messaging/MessageBrokerTest.java
+++ b/core/src/test/java/flex/messaging/MessageBrokerTest.java
@@ -17,136 +17,108 @@
package flex.messaging;
-import java.util.List;
-import java.util.Map;
-
import flex.messaging.config.ConfigurationConstants;
import flex.messaging.config.ConfigurationException;
import flex.messaging.factories.JavaFactory;
import flex.messaging.services.MessageService;
import flex.messaging.services.Service;
import org.junit.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.Map;
/**
* Important: While adding new tests, make sure you don't create dependencies
* to other modules. (eg. don't use RemotingDestination as that would create
* dependency on remoting module; instead add the test in remoting module).
*/
-public class MessageBrokerTest extends TestCase
-{
-
- protected MessageBroker broker;
+public class MessageBrokerTest {
- public MessageBrokerTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(MessageBrokerTest.class);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
+ private MessageBroker broker;
+ @Before
+ public void setUp() throws Exception {
broker = new MessageBroker(false);
broker.initThreadLocals();
}
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void testAddFactory()
- {
+ @Test
+ public void testAddFactory() {
String id = "java2";
- JavaFactory expected = new JavaFactory();
+ JavaFactory expected = new JavaFactory();
broker.addFactory("java2", expected);
-
- JavaFactory actual = (JavaFactory)broker.getFactory(id);
- Assert.assertEquals(expected, actual);
+
+ JavaFactory actual = (JavaFactory) broker.getFactory(id);
+ Assert.assertEquals(expected, actual);
}
-
- public void testAddSameFactoryIdTwice()
- {
+
+ @Test
+ public void testAddSameFactoryIdTwice() {
String id = "java";
- JavaFactory expected = new JavaFactory();
- try
- {
+ JavaFactory expected = new JavaFactory();
+ try {
broker.addFactory(id, expected);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = ConfigurationConstants.DUPLICATE_COMPONENT_ID;
Assert.assertTrue(ce.getNumber() == error);
- }
+ }
}
-
- public void testAddSameFactoryInstanceTwice()
- {
+
+ @Test
+ public void testAddSameFactoryInstanceTwice() {
String id = "java2";
JavaFactory expected = new JavaFactory();
broker.addFactory("java2", expected);
broker.addFactory("java2", expected);
-
- JavaFactory actual = (JavaFactory)broker.getFactory(id);
+
+ JavaFactory actual = (JavaFactory) broker.getFactory(id);
Assert.assertEquals(expected, actual);
}
-
- public void testAddFactoryNullId()
- {
- String id = null;
+
+ @Test
+ public void testAddFactoryNullId() {
JavaFactory expected = new JavaFactory();
- try
- {
- broker.addFactory(id, expected);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ try {
+ broker.addFactory(null, expected);
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = ConfigurationConstants.NULL_COMPONENT_ID;
Assert.assertTrue(ce.getNumber() == error);
}
- }
-
- public void testGetFactories()
- {
+ }
+
+ @Test
+ public void testGetFactories() {
String id = "java2";
- JavaFactory expected = new JavaFactory();
+ JavaFactory expected = new JavaFactory();
broker.addFactory(id, expected);
-
+
int size = broker.getFactories().size();
Assert.assertEquals(2, size);
}
-
- public void testRemoveFactory()
- {
+
+ @Test
+ public void testRemoveFactory() {
String id = "java";
broker.removeFactory(id);
FlexFactory actual = broker.getFactory(id);
- Service expected = null;
- Assert.assertEquals(expected, actual);
+ Assert.assertEquals(null, actual);
}
-
- public void testRemoveFactoryNonexistent()
- {
+
+ @Test
+ public void testRemoveFactoryNonexistent() {
String id = "nonexistent";
FlexFactory actual = broker.removeFactory(id);
-
+
Assert.assertNull(actual);
}
-
-
- public void testAddService()
- {
+
+ @Test
+ public void testAddService() {
String id = "dummy-service";
MessageService expected = new MessageService();
expected.setId(id);
@@ -157,8 +129,8 @@ public class MessageBrokerTest extends TestCase
Assert.assertEquals(expected.isManaged(), actual.isManaged());
}
- public void testAddServiceNonManaged()
- {
+ @Test
+ public void testAddServiceNonManaged() {
String id = "dummy-service";
MessageService expected = new MessageService(false);
expected.setId(id);
@@ -167,43 +139,36 @@ public class MessageBrokerTest extends TestCase
Service actual = broker.getService(id);
Assert.assertEquals(expected, actual);
Assert.assertEquals(expected.isManaged(), actual.isManaged());
- }
-
- public void testAddServiceNull()
- {
- try
- {
+ }
+
+ @Test
+ public void testAddServiceNull() {
+ try {
broker.addService(null);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = ConfigurationConstants.NULL_COMPONENT;
Assert.assertTrue(ce.getNumber() == error);
}
}
- public void testAddServiceNullId()
- {
- try
- {
+ @Test
+ public void testAddServiceNullId() {
+ try {
MessageService svc = new MessageService();
broker.addService(svc);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = ConfigurationConstants.NULL_COMPONENT_ID;
Assert.assertTrue(ce.getNumber() == error);
}
}
- public void testAddServiceExists()
- {
- try
- {
+ @Test
+ public void testAddServiceExists() {
+ try {
String id = "dummy-service";
MessageService svc1 = new MessageService();
svc1.setId(id);
@@ -212,17 +177,15 @@ public class MessageBrokerTest extends TestCase
svc2.setId(id);
broker.addService(svc2);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = ConfigurationConstants.DUPLICATE_COMPONENT_ID;
Assert.assertTrue(ce.getNumber() == error);
}
}
- public void testCreateService()
- {
+ @Test
+ public void testCreateService() {
String serviceId = "message-service";
String serviceClass = MessageService.class.getName();
@@ -232,45 +195,39 @@ public class MessageBrokerTest extends TestCase
Assert.assertEquals(expected, actual);
}
- public void testCreateServiceNonexistingClass()
- {
+ @Test
+ public void testCreateServiceNonexistingClass() {
String serviceId = "remoting-service";
String serviceClass = "NonexistingClass";
-
- try
- {
+
+ try {
broker.createService(serviceId, serviceClass);
- fail ("MessageException expected");
- }
- catch (MessageException me)
- {
+ Assert.fail("MessageException expected");
+ } catch (MessageException me) {
int error = 10008; //ClassUtil.TYPE_NOT_FOUND
Assert.assertEquals(me.getNumber(), error);
}
}
-
- public void testCreateServiceWithExistingId()
- {
+
+ @Test
+ public void testCreateServiceWithExistingId() {
String id = "message-service";
String serviceClass = MessageService.class.getName();
-
+
broker.createService(id, serviceClass);
- try
- {
+ try {
broker.createService(id, serviceClass);
-
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
- int error = ConfigurationConstants.DUPLICATE_COMPONENT_ID;
+
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
+ int error = ConfigurationConstants.DUPLICATE_COMPONENT_ID;
Assert.assertEquals(ce.getNumber(), error);
- }
+ }
}
-
- public void testRemoveService()
- {
+
+ @Test
+ public void testRemoveService() {
String id = "dummy-service";
MessageService svc = new MessageService();
svc.setId(id);
@@ -278,46 +235,45 @@ public class MessageBrokerTest extends TestCase
broker.removeService(id);
Service actual = broker.getService(id);
- Service expected = null;
- Assert.assertEquals(expected, actual);
+ Assert.assertEquals(null, actual);
}
-
- public void testRemoveServiceNonexistent()
- {
+
+ @Test
+ public void testRemoveServiceNonexistent() {
Service actual = broker.removeService("id");
- Assert.assertNull(actual);
+ Assert.assertNull(actual);
}
-
- public void testGetService()
- {
+
+ @Test
+ public void testGetService() {
String id = "dummy-service";
MessageService expected = new MessageService();
expected.setId(id);
broker.addService(expected);
-
+
Service actual = broker.getService(id);
Assert.assertEquals(expected, actual);
}
-
-
+
+
//Get services_no AUthentication
- public void testGetServices()
- {
+ @Test
+ public void testGetServices() {
String id = "remoting-service";
MessageService expected1 = new MessageService();
expected1.setId(id);
id = "message-service";
MessageService expected2 = new MessageService();
expected2.setId(id);
-
+
broker.addService(expected1);
broker.addService(expected2);
-
+
Map<String, Service> actual = broker.getServices();
Assert.assertEquals(expected1, actual.get("remoting-service"));
Assert.assertEquals(expected2, actual.get("message-service"));
}
-
+
//GetServices should not return an AuthenticationService to the client
// public void testGetServicesNoAuthenticationSvc()
// {
@@ -336,15 +292,15 @@ public class MessageBrokerTest extends TestCase
// Assert.assertNotSame(notExpected, actual.get(1));
// Assert.assertEquals(1, actual.size());
// }
-
- public void testGetServiceNonExistent()
- {
+
+ @Test
+ public void testGetServiceNonExistent() {
Service actual = broker.getService("non-existent-id");
Assert.assertNull(actual);
}
-
- public void testGetChannelIdsNull()
- {
+
+ @Test
+ public void testGetChannelIdsNull() {
List<String> channelIds = broker.getChannelIds();
Assert.assertNull(channelIds);
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/client/FlexClientManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/client/FlexClientManagerTest.java b/core/src/test/java/flex/messaging/client/FlexClientManagerTest.java
index 3bf5cc3..f4c3f08 100644
--- a/core/src/test/java/flex/messaging/client/FlexClientManagerTest.java
+++ b/core/src/test/java/flex/messaging/client/FlexClientManagerTest.java
@@ -18,105 +18,92 @@ package flex.messaging.client;
import flex.messaging.MessageBroker;
import org.junit.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.Before;
+import org.junit.Test;
/**
* Unit tests for the flex.messaging.client.FlexClientManager
*/
-public class FlexClientManagerTest extends TestCase {
-
- protected MessageBroker broker;
- protected FlexClientManager manager;
+public class FlexClientManagerTest {
- public FlexClientManagerTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(FlexClientManagerTest.class);
- }
+ private FlexClientManager manager;
- protected void setUp() throws Exception
- {
- super.setUp();
-
- broker = new MessageBroker(false);
+ @Before
+ public void setUp() throws Exception {
+ MessageBroker broker = new MessageBroker(false);
broker.initThreadLocals();
manager = new FlexClientManager(broker);
}
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
+
/**
- * Test that FlexClientManager.createFlexClient(id) returns
- * a FlexClient instance with the correct id.
+ * Test that FlexClientManager.createFlexClient(id) returns
+ * a FlexClient instance with the correct id.
*/
- public void testCreateFlexClientWithId()
- {
+ @Test
+ public void testCreateFlexClientWithId() {
String id = "abc";
- FlexClient client = manager.createFlexClient(id);
- Assert.assertEquals(id, client.getId());
+ FlexClient client = manager.createFlexClient(id);
+ Assert.assertEquals(id, client.getId());
}
+
/**
- * Test that calling FlexClientManager.getFlexClient(id) with
+ * Test that calling FlexClientManager.getFlexClient(id) with
* a new id, returns a new FlexClient instance with the correct
- * id.
+ * id.
*/
- public void testGetFlexClientNewId()
- {
+ @Test
+ public void testGetFlexClientNewId() {
String id = "def";
FlexClient client = manager.getFlexClient(id);
Assert.assertNotNull(client);
- Assert.assertEquals(id, client.getId());
+ Assert.assertEquals(id, client.getId());
}
+
/**
- * Test that calling FlexClientManager.getFlexClient(id) with
- * an id for an existing FlexClient, returns the FlexClient
- * instance with the correct id.
+ * Test that calling FlexClientManager.getFlexClient(id) with
+ * an id for an existing FlexClient, returns the FlexClient
+ * instance with the correct id.
*/
- public void testGetFlexClientExistingId()
- {
+ @Test
+ public void testGetFlexClientExistingId() {
String id = "ghi";
manager.createFlexClient(id);
- FlexClient client = manager.getFlexClient(id);
- Assert.assertEquals(id, client.getId());
+ FlexClient client = manager.getFlexClient(id);
+ Assert.assertEquals(id, client.getId());
}
+
/**
- * Test that calling FlexClientManager.getFlexClient(id, createNewIfNotExist)
+ * Test that calling FlexClientManager.getFlexClient(id, createNewIfNotExist)
* with an id for a nonexistent FlexClient and false returns null.
*/
- public void testGetFlexClientCreateNewFalse()
- {
+ @Test
+ public void testGetFlexClientCreateNewFalse() {
String id = "jkl";
- FlexClient client = manager.getFlexClient(id,false);
- Assert.assertNull(client);
+ FlexClient client = manager.getFlexClient(id, false);
+ Assert.assertNull(client);
}
+
/**
* Test that calling FlexClientManager.getFlexClientCount() returns
* 2 when there are 2 FlexClients.
*/
- public void testGetFlexClientCount()
- {
+ @Test
+ public void testGetFlexClientCount() {
manager.getFlexClient("client1");
manager.getFlexClient("client2");
- Assert.assertEquals(2, manager.getFlexClientCount());
+ Assert.assertEquals(2, manager.getFlexClientCount());
}
+
/**
* Test that FlexClientManager.removeFlexClient(FlexClient) removes
- * the correct FlexClient.
+ * the correct FlexClient.
*/
- public void testRemoveFlexClient()
- {
+ @Test
+ public void testRemoveFlexClient() {
FlexClient client = manager.getFlexClient("client1");
manager.getFlexClient("client2");
manager.removeFlexClient(client);
- Assert.assertEquals(1, manager.getFlexClientCount());
+ Assert.assertEquals(1, manager.getFlexClientCount());
Assert.assertEquals("client2", manager.getClientIds()[0]);
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/cluster/SerializationProxyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/cluster/SerializationProxyTest.java b/core/src/test/java/flex/messaging/cluster/SerializationProxyTest.java
index 8cbce75..ceb9d05 100644
--- a/core/src/test/java/flex/messaging/cluster/SerializationProxyTest.java
+++ b/core/src/test/java/flex/messaging/cluster/SerializationProxyTest.java
@@ -18,21 +18,18 @@ package flex.messaging.cluster;
import flex.messaging.io.SerializationProxy;
import flex.messaging.io.amf.ASObject;
+import org.junit.Assert;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import junit.framework.TestCase;
-public class SerializationProxyTest extends TestCase
+public class SerializationProxyTest
{
- public SerializationProxyTest(String valueExpression)
- {
- super(valueExpression);
- }
-
/**
* For clustering, SerializationProxys must be serialized and
* deserialized. This is because any message with a SerializationProxy,
@@ -41,6 +38,7 @@ public class SerializationProxyTest extends TestCase
* cluster.
* Bug: LCDS-910
*/
+ @Test
public void testRoundTripSerialization() throws Exception
{
ASObject as = new ASObject();
@@ -59,6 +57,6 @@ public class SerializationProxyTest extends TestCase
ObjectInputStream ois = new ObjectInputStream(in);
Object o = ois.readObject();
- assertNotNull("The object should be correctly serialized/deserialized.", o);
+ Assert.assertNotNull("The object should be correctly serialized/deserialized.", o);
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/config/ChannelSettingsParseUriTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/config/ChannelSettingsParseUriTest.java b/core/src/test/java/flex/messaging/config/ChannelSettingsParseUriTest.java
index 22c68a9..a6fd55c 100644
--- a/core/src/test/java/flex/messaging/config/ChannelSettingsParseUriTest.java
+++ b/core/src/test/java/flex/messaging/config/ChannelSettingsParseUriTest.java
@@ -20,12 +20,9 @@ package flex.messaging.config;
import flex.messaging.endpoints.AMFEndpoint;
import flex.messaging.endpoints.Endpoint;
import org.junit.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.Test;
-public class ChannelSettingsParseUriTest extends TestCase
-{
+public class ChannelSettingsParseUriTest {
private static String confirm = "/messagebroker/amf";
private static String data1 = "http://{server.name}:{server.port}/{context.root}/messagebroker/amf";
@@ -58,139 +55,118 @@ public class ChannelSettingsParseUriTest extends TestCase
private static String clientData6a = "{context.root}";
private static String clientData6b = "/{context.root}";
-
- public ChannelSettingsParseUriTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(ChannelSettingsParseUriTest.class);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void testReplaceContextRoot()
- {
+ @Test
+ public void testReplaceContextRoot() {
Endpoint fooEndpoint = new AMFEndpoint();
- fooEndpoint.setUrl(data1);
+ fooEndpoint.setUrl(data1);
String actual = fooEndpoint.getParsedUrl("/ctx");
Assert.assertEquals(confirm, actual);
}
- public void testReplaceContextRootDash()
- {
+ @Test
+ public void testReplaceContextRootDash() {
Endpoint fooEndpoint = new AMFEndpoint();
- fooEndpoint.setUrl(data2);
+ fooEndpoint.setUrl(data2);
String actual = fooEndpoint.getParsedUrl("/ctx");
Assert.assertEquals(confirm, actual);
}
- public void testReplaceContextRootStart()
- {
+ @Test
+ public void testReplaceContextRootStart() {
Endpoint fooEndpoint = new AMFEndpoint();
- fooEndpoint.setUrl(data3);
+ fooEndpoint.setUrl(data3);
String actual = fooEndpoint.getParsedUrl("/ctx");
Assert.assertEquals(confirm, actual);
}
- public void testReplaceContextRootSlashStart()
- {
+ @Test
+ public void testReplaceContextRootSlashStart() {
Endpoint fooEndpoint = new AMFEndpoint();
- fooEndpoint.setUrl(data4);
+ fooEndpoint.setUrl(data4);
String actual = fooEndpoint.getParsedUrl("/ctx");
Assert.assertEquals(confirm, actual);
}
-
+
// Client Channel Tests
-
- public void testClientReplaceContextRoot()
- {
+
+ @Test
+ public void testClientReplaceContextRoot() {
ChannelSettings fooChannel = new ChannelSettings("channel-one");
- fooChannel.setUri(clientData1a);
+ fooChannel.setUri(clientData1a);
String actual = fooChannel.getClientParsedUri("/");
Assert.assertEquals(clientConfirm1, actual);
- fooChannel.setUri(clientData1a);
+ fooChannel.setUri(clientData1a);
actual = fooChannel.getClientParsedUri("");
Assert.assertEquals(clientConfirm1, actual);
-
- fooChannel.setUri(clientData2a);
+
+ fooChannel.setUri(clientData2a);
actual = fooChannel.getClientParsedUri("/ctx");
Assert.assertEquals(clientConfirm2, actual);
}
- public void testClientReplaceContextRootDash()
- {
+ @Test
+ public void testClientReplaceContextRootDash() {
ChannelSettings fooChannel = new ChannelSettings("channel-one");
- fooChannel.setUri(clientData1b);
+ fooChannel.setUri(clientData1b);
String actual = fooChannel.getClientParsedUri("/");
Assert.assertEquals(clientConfirm1, actual);
- fooChannel.setUri(clientData1b);
+ fooChannel.setUri(clientData1b);
actual = fooChannel.getClientParsedUri("");
Assert.assertEquals(clientConfirm1, actual);
- fooChannel.setUri(clientData2b);
+ fooChannel.setUri(clientData2b);
actual = fooChannel.getClientParsedUri("/ctx");
Assert.assertEquals(clientConfirm2, actual);
}
-
- public void testClientReplaceContextRootStart()
- {
+
+ @Test
+ public void testClientReplaceContextRootStart() {
ChannelSettings fooChannel = new ChannelSettings("channel-one");
- fooChannel.setUri(clientData3a);
+ fooChannel.setUri(clientData3a);
String actual = fooChannel.getClientParsedUri("/");
Assert.assertEquals(clientConfirm3, actual);
fooChannel = new ChannelSettings("channel-one");
- fooChannel.setUri(clientData4a);
+ fooChannel.setUri(clientData4a);
actual = fooChannel.getClientParsedUri("/ctx");
Assert.assertEquals(clientConfirm4, actual);
}
-
- public void testClientReplaceContextRootSlashStart()
- {
+
+ @Test
+ public void testClientReplaceContextRootSlashStart() {
ChannelSettings fooChannel = new ChannelSettings("channel-one");
- fooChannel.setUri(clientData3b);
+ fooChannel.setUri(clientData3b);
String actual = fooChannel.getClientParsedUri("");
Assert.assertEquals(clientConfirm3, actual);
- fooChannel.setUri(clientData4b);
+ fooChannel.setUri(clientData4b);
actual = fooChannel.getClientParsedUri("/ctx");
Assert.assertEquals(clientConfirm4, actual);
}
-
- public void testClientReplaceContextRootOnly()
- {
+
+ @Test
+ public void testClientReplaceContextRootOnly() {
ChannelSettings fooChannel = new ChannelSettings("channel-one");
- fooChannel.setUri(clientData5a);
+ fooChannel.setUri(clientData5a);
String actual = fooChannel.getClientParsedUri("/");
Assert.assertEquals(clientConfirm5, actual);
- fooChannel.setUri(clientData6a);
+ fooChannel.setUri(clientData6a);
actual = fooChannel.getClientParsedUri("/ctx");
Assert.assertEquals(clientConfirm6, actual);
}
-
- public void testClientReplaceSlashContextRootOnly()
- {
+
+ @Test
+ public void testClientReplaceSlashContextRootOnly() {
ChannelSettings fooChannel = new ChannelSettings("channel-one");
- fooChannel.setUri(clientData5b);
+ fooChannel.setUri(clientData5b);
String actual = fooChannel.getClientParsedUri("/");
Assert.assertEquals(clientConfirm5, actual);
- fooChannel.setUri(clientData6b);
+ fooChannel.setUri(clientData6b);
actual = fooChannel.getClientParsedUri("/ctx");
Assert.assertEquals(clientConfirm6, actual);
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/config/ConfigurationConfirmation.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/config/ConfigurationConfirmation.java b/core/src/test/java/flex/messaging/config/ConfigurationConfirmation.java
index bd78c7a..a2b5957 100644
--- a/core/src/test/java/flex/messaging/config/ConfigurationConfirmation.java
+++ b/core/src/test/java/flex/messaging/config/ConfigurationConfirmation.java
@@ -19,23 +19,15 @@ package flex.messaging.config;
import flex.messaging.LocalizedException;
-import java.util.Collection;
-import java.util.Date;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-public abstract class ConfigurationConfirmation
-{
+import java.util.*;
+
+public abstract class ConfigurationConfirmation {
private IdentityHashMap knownObjects;
- public ConfigurationConfirmation()
- {
+ public ConfigurationConfirmation() {
}
- private void init()
- {
+ private void init() {
knownObjects = new IdentityHashMap(64);
}
@@ -43,71 +35,64 @@ public abstract class ConfigurationConfirmation
public abstract LocalizedException getExpectedException();
- public boolean isNegativeTest()
- {
+ public boolean isNegativeTest() {
return false;
}
- public boolean matches(MessagingConfiguration config)
- {
+ public boolean matches(MessagingConfiguration config) {
init();
- try
- {
- boolean match = configMatch(config, getExpectedConfiguration());
- return match;
- }
- catch (Exception ex)
- {
+ try {
+ return configMatch(config, getExpectedConfiguration());
+ } catch (Exception ex) {
return false;
}
}
- public boolean negativeMatches(LocalizedException ex)
- {
+ public boolean negativeMatches(LocalizedException ex) {
init();
String message1 = ex.getMessage();
String message2 = getExpectedException().getMessage();
- if (message1 == null && message2 == null)
+ if (message1 == null && message2 == null) {
return true;
+ }
- if ((message1 == null && message2 != null) || (message1 != null && message2 == null))
+ if (message1 == null || message2 == null) {
return false;
+ }
return message1.equalsIgnoreCase(message2);
}
- public boolean configMatch(MessagingConfiguration c1, MessagingConfiguration c2)
- {
- if (c1 == null && c2 == null)
+ public boolean configMatch(MessagingConfiguration c1, MessagingConfiguration c2) {
+ if (c1 == null && c2 == null) {
return true;
+ }
- if (c1 == null || c2 == null)
- return fail("Services sections didn't match: {0} != {1}", new Object[] {c1, c2});
+ if (c1 == null || c2 == null) {
+ return fail("Services sections didn't match: {0} != {1}", new Object[]{c1, c2});
+ }
// Services
List s1 = c1.getAllServiceSettings();
List s2 = c2.getAllServiceSettings();
- if (!servicesMatch(s1, s2))
+ if (!servicesMatch(s1, s2)) {
return false;
+ }
// Security
SecuritySettings sec1 = c1.getSecuritySettings();
SecuritySettings sec2 = c2.getSecuritySettings();
- if (!securityMatch(sec1, sec2))
- return false;
- return true;
+ return securityMatch(sec1, sec2);
}
- private boolean securityMatch(SecuritySettings sec1, SecuritySettings sec2)
- {
+ private boolean securityMatch(SecuritySettings sec1, SecuritySettings sec2) {
Collection<SecurityConstraint> constraintSet1 = sec1.getConstraints();
- for (SecurityConstraint sc1 : constraintSet1)
- {
+ for (SecurityConstraint sc1 : constraintSet1) {
SecurityConstraint sc2 = sec2.getConstraint(sc1.getId());
if (!securityConstraintsMatch(sc1, sc2))
return false;
@@ -116,29 +101,24 @@ public abstract class ConfigurationConfirmation
}
- protected boolean servicesMatch(List s1, List s2)
- {
+ protected boolean servicesMatch(List s1, List s2) {
if (s1 == null && s2 == null)
return true;
if (s1 == null || s2 == null)
- return fail("Services sections didn't match: {0} != {1}", new Object[] {s1, s2});
+ return fail("Services sections didn't match: {0} != {1}", new Object[]{s1, s2});
if (s1.size() != s2.size())
- return fail("Services sections didn't match by size: {0} != {1}", new Object[] {new Integer(s1.size()), new Integer(s2.size())});
+ return fail("Services sections didn't match by size: {0} != {1}", new Object[]{new Integer(s1.size()), new Integer(s2.size())});
- Iterator it = s1.iterator();
- while (it.hasNext())
- {
- ServiceSettings ss1 =(ServiceSettings) it.next();
+ for (Object aS1 : s1) {
+ ServiceSettings ss1 = (ServiceSettings) aS1;
String key = ss1.getId();
ServiceSettings ss2 = null;
- for (Iterator iter = s2.iterator(); iter.hasNext();)
- {
- ServiceSettings element = (ServiceSettings) iter.next();
- if (element.getId().equals(key))
- {
+ for (Object aS2 : s2) {
+ ServiceSettings element = (ServiceSettings) aS2;
+ if (element.getId().equals(key)) {
ss2 = element;
break;
}
@@ -151,267 +131,285 @@ public abstract class ConfigurationConfirmation
return true;
}
- protected boolean serviceSettingsMatch(ServiceSettings ss1, ServiceSettings ss2)
- {
- if (ss1 == null && ss2 == null)
+ protected boolean serviceSettingsMatch(ServiceSettings ss1, ServiceSettings ss2) {
+ if (ss1 == null && ss2 == null) {
return true;
+ }
- if (ss1 == null || ss2 == null)
- return fail("Service sections didn't match: {0} != {1}", new Object[] {ss1, ss2});
+ if (ss1 == null || ss2 == null) {
+ return fail("Service sections didn't match: {0} != {1}", new Object[]{ss1, ss2});
+ }
- if (!ss1.getId().equals(ss2.getId()))
- return fail("Service ids didn't match: {0} != {1}", new Object[] {ss1.getId(), ss2.getId()});
+ if (!ss1.getId().equals(ss2.getId())) {
+ return fail("Service ids didn't match: {0} != {1}", new Object[]{ss1.getId(), ss2.getId()});
+ }
+
+ if (!ss1.getClassName().equals(ss2.getClassName())) {
+ return fail("Service class names didn't match: {0} != {1}", new Object[]{ss1.getClassName(), ss2.getClassName()});
+ }
- if (!ss1.getClassName().equals(ss2.getClassName()))
- return fail("Service class names didn't match: {0} != {1}", new Object[] {ss1.getClassName(), ss2.getClassName()});
-
// Adapters
Map a1 = ss1.getAllAdapterSettings();
Map a2 = ss2.getAllAdapterSettings();
- if (!adaptersMatch(a1, a2))
+ if (!adaptersMatch(a1, a2)) {
return false;
+ }
// Default Adapters
- AdapterSettings as1 = (AdapterSettings)ss1.getDefaultAdapter();
- AdapterSettings as2 = (AdapterSettings)ss2.getDefaultAdapter();
- if (!adapterDefinitionsMatch(as1, as2))
+ AdapterSettings as1 = ss1.getDefaultAdapter();
+ AdapterSettings as2 = ss2.getDefaultAdapter();
+ if (!adapterDefinitionsMatch(as1, as2)) {
return false;
+ }
// Default Channels
List dc1 = ss1.getDefaultChannels();
List dc2 = ss2.getDefaultChannels();
- if (dc1.size() != dc2.size())
- return fail("Default channels sections didn't match by size: {0} != {1}", new Object[] {new Integer(dc1.size()), new Integer(dc2.size())});
-
- for (int i = 0; i < dc1.size(); i++)
- {
- ChannelSettings c1 = (ChannelSettings)dc1.get(i);
- ChannelSettings c2 = (ChannelSettings)dc2.get(i);
- if (!channelDefinitionsMatch(c1, c2))
+ if (dc1.size() != dc2.size()) {
+ return fail("Default channels sections didn't match by size: {0} != {1}", new Object[]{new Integer(dc1.size()), new Integer(dc2.size())});
+ }
+
+ for (int i = 0; i < dc1.size(); i++) {
+ ChannelSettings c1 = (ChannelSettings) dc1.get(i);
+ ChannelSettings c2 = (ChannelSettings) dc2.get(i);
+ if (!channelDefinitionsMatch(c1, c2)) {
return false;
+ }
}
// Destinations
Map d1 = ss1.getDestinationSettings();
Map d2 = ss2.getDestinationSettings();
- if (!destinationsMatch(d1, d2))
- return false;
-
- return true;
+ return destinationsMatch(d1, d2);
}
- protected boolean adaptersMatch(Map a1, Map a2)
- {
- if (a1 == null && a2 == null)
+ protected boolean adaptersMatch(Map a1, Map a2) {
+ if (a1 == null && a2 == null) {
return true;
+ }
- if (a1 == null || a2 == null)
- return fail("Adapters sections didn't match: {0} != {1}", new Object[] {a1, a2});
+ if (a1 == null || a2 == null) {
+ return fail("Adapters sections didn't match: {0} != {1}", new Object[]{a1, a2});
+ }
- if (a1.size() != a2.size())
- return fail("Adapters sections didn't match by size: {0} != {1}", new Object[] {new Integer(a1.size()), new Integer(a2.size())});
+ if (a1.size() != a2.size()) {
+ return fail("Adapters sections didn't match by size: {0} != {1}", new Object[]{new Integer(a1.size()), new Integer(a2.size())});
+ }
- Iterator it = a1.keySet().iterator();
- while (it.hasNext())
- {
- String key = (String)it.next();
+ for (Object o : a1.keySet()) {
+ String key = (String) o;
- AdapterSettings as1 = (AdapterSettings)a1.get(key);
- AdapterSettings as2 = (AdapterSettings)a2.get(key);
- if (!adapterDefinitionsMatch(as1, as2))
+ AdapterSettings as1 = (AdapterSettings) a1.get(key);
+ AdapterSettings as2 = (AdapterSettings) a2.get(key);
+ if (!adapterDefinitionsMatch(as1, as2)) {
return false;
+ }
}
return true;
}
- protected boolean adapterDefinitionsMatch(AdapterSettings as1, AdapterSettings as2)
- {
- if (as1 == null && as2 == null)
+ protected boolean adapterDefinitionsMatch(AdapterSettings as1, AdapterSettings as2) {
+ if (as1 == null && as2 == null) {
return true;
+ }
- if (as1 == null || as2 == null)
- return fail("Adapters didn't match: {0} != {1}", new Object[] {as1, as2});
+ if (as1 == null || as2 == null) {
+ return fail("Adapters didn't match: {0} != {1}", new Object[]{as1, as2});
+ }
- if (!as1.getId().equals(as2.getId()))
- return fail("Adapter ids didn't match: {0} != {1}", new Object[] {as1.getId(), as2.getId()});
+ if (!as1.getId().equals(as2.getId())) {
+ return fail("Adapter ids didn't match: {0} != {1}", new Object[]{as1.getId(), as2.getId()});
+ }
- if (!as1.getClassName().equals(as2.getClassName()))
- return fail("Adapter class names didn't match: {0} != {1}", new Object[] {as1.getClassName(), as2.getClassName()});
+ if (!as1.getClassName().equals(as2.getClassName())) {
+ return fail("Adapter class names didn't match: {0} != {1}", new Object[]{as1.getClassName(), as2.getClassName()});
+ }
- if (as1.isDefault() != as2.isDefault())
- return fail("Adapter default attributes didn't match: {0} != {1}", new Object[] {Boolean.valueOf(as1.isDefault()), Boolean.valueOf(as2.isDefault())});
+ if (as1.isDefault() != as2.isDefault()) {
+ return fail("Adapter default attributes didn't match: {0} != {1}", new Object[]{Boolean.valueOf(as1.isDefault()), Boolean.valueOf(as2.isDefault())});
+ }
- if (!propertiesMatch(as1.getProperties(), as2.getProperties()))
+ if (!propertiesMatch(as1.getProperties(), as2.getProperties())) {
return false;
+ }
return true;
}
- protected boolean channelDefinitionsMatch(ChannelSettings c1, ChannelSettings c2)
- {
- if (c1 == null && c2 == null)
+ protected boolean channelDefinitionsMatch(ChannelSettings c1, ChannelSettings c2) {
+ if (c1 == null && c2 == null) {
return true;
+ }
- if (c1 == null || c2 == null)
- return fail("Channels didn't match: {0} != {1}", new Object[] {c1, c2});
+ if (c1 == null || c2 == null) {
+ return fail("Channels didn't match: {0} != {1}", new Object[]{c1, c2});
+ }
- if (!c1.getId().equals(c2.getId()))
- return fail("Channel ids didn't match: {0} != {1}", new Object[] {c1.getId(), c2.getId()});
+ if (!c1.getId().equals(c2.getId())) {
+ return fail("Channel ids didn't match: {0} != {1}", new Object[]{c1.getId(), c2.getId()});
+ }
- if (!c1.getEndpointType().equals(c1.getEndpointType()))
- return fail("Channel endpoint types didn't match: {0} != {1}", new Object[] {c1.getEndpointType(), c2.getEndpointType()});
+ if (!c1.getEndpointType().equals(c1.getEndpointType())) {
+ return fail("Channel endpoint types didn't match: {0} != {1}", new Object[]{c1.getEndpointType(), c2.getEndpointType()});
+ }
- if (!c1.getUri().equals(c2.getUri()))
- return fail("Channel endpoint URIs didn't match: {0} != {1}", new Object[] {c1.getUri(), c2.getUri()});
+ if (!c1.getUri().equals(c2.getUri())) {
+ return fail("Channel endpoint URIs didn't match: {0} != {1}", new Object[]{c1.getUri(), c2.getUri()});
+ }
- if (!propertiesMatch(c1.getProperties(), c2.getProperties()))
+ if (!propertiesMatch(c1.getProperties(), c2.getProperties())) {
return false;
+ }
return true;
}
- protected boolean destinationsMatch(Map d1, Map d2)
- {
- if (d1 == null && d2 == null)
+ protected boolean destinationsMatch(Map d1, Map d2) {
+ if (d1 == null && d2 == null) {
return true;
+ }
- if (d1 == null || d2 == null)
- return fail("Destinations sections didn't match: {0} != {1}", new Object[] {d1, d2});
+ if (d1 == null || d2 == null) {
+ return fail("Destinations sections didn't match: {0} != {1}", new Object[]{d1, d2});
+ }
- if (d1.size() != d2.size())
- return fail("Destinations sections didn't match by size: {0} != {1}", new Object[] {new Integer(d1.size()), new Integer(d2.size())});
+ if (d1.size() != d2.size()) {
+ return fail("Destinations sections didn't match by size: {0} != {1}", new Object[]{new Integer(d1.size()), new Integer(d2.size())});
+ }
- Iterator it = d1.keySet().iterator();
- while (it.hasNext())
- {
- String key = (String)it.next();
+ for (Object o : d1.keySet()) {
+ String key = (String) o;
- DestinationSettings ds1 = (DestinationSettings)d1.get(key);
- DestinationSettings ds2 = (DestinationSettings)d2.get(key);
- if (!destinationDefinitionsMatch(ds1, ds2))
+ DestinationSettings ds1 = (DestinationSettings) d1.get(key);
+ DestinationSettings ds2 = (DestinationSettings) d2.get(key);
+ if (!destinationDefinitionsMatch(ds1, ds2)) {
return false;
+ }
}
return true;
}
- protected boolean destinationDefinitionsMatch(DestinationSettings d1, DestinationSettings d2)
- {
- if (d1 == null && d2 == null)
+ protected boolean destinationDefinitionsMatch(DestinationSettings d1, DestinationSettings d2) {
+ if (d1 == null && d2 == null) {
return true;
+ }
- if (d1 == null || d2 == null)
- return fail("Destinations didn't match: {0} != {1}", new Object[] {d1, d2});
+ if (d1 == null || d2 == null) {
+ return fail("Destinations didn't match: {0} != {1}", new Object[]{d1, d2});
+ }
- if (!d1.getId().equals(d2.getId()))
- return fail("Destination ids didn't match: {0} != {1}", new Object[] {d1.getId(), d2.getId()});
+ if (!d1.getId().equals(d2.getId())) {
+ return fail("Destination ids didn't match: {0} != {1}", new Object[]{d1.getId(), d2.getId()});
+ }
// Properties
- if (!propertiesMatch(d1.getProperties(), d1.getProperties()))
+ if (!propertiesMatch(d1.getProperties(), d1.getProperties())) {
return false;
+ }
- // Channels
+ // Channels
List dc1 = d1.getChannelSettings();
List dc2 = d2.getChannelSettings();
- if (dc1.size() != dc2.size())
- return fail("Destination channels sections didn't match by size: {0} != {1}", new Object[] {new Integer(dc1.size()), new Integer(dc2.size())});
-
- for (int i = 0; i < dc1.size(); i++)
- {
- ChannelSettings c1 = (ChannelSettings)dc1.get(i);
- ChannelSettings c2 = (ChannelSettings)dc2.get(i);
- if (!channelDefinitionsMatch(c1, c2))
+ if (dc1.size() != dc2.size()) {
+ return fail("Destination channels sections didn't match by size: {0} != {1}", new Object[]{new Integer(dc1.size()), new Integer(dc2.size())});
+ }
+
+ for (int i = 0; i < dc1.size(); i++) {
+ ChannelSettings c1 = (ChannelSettings) dc1.get(i);
+ ChannelSettings c2 = (ChannelSettings) dc2.get(i);
+ if (!channelDefinitionsMatch(c1, c2)) {
return false;
+ }
}
// Security
SecurityConstraint sc1 = d1.getConstraint();
SecurityConstraint sc2 = d2.getConstraint();
- if (!securityConstraintsMatch(sc1, sc2))
+ if (!securityConstraintsMatch(sc1, sc2)) {
return false;
+ }
// Adapter
AdapterSettings as1 = d1.getAdapterSettings();
AdapterSettings as2 = d2.getAdapterSettings();
- if (!adapterDefinitionsMatch(as1, as2))
+ if (!adapterDefinitionsMatch(as1, as2)) {
return false;
+ }
return true;
}
- protected boolean securityConstraintsMatch(SecurityConstraint sc1, SecurityConstraint sc2)
- {
- if (sc1 == null && sc2 == null)
+ protected boolean securityConstraintsMatch(SecurityConstraint sc1, SecurityConstraint sc2) {
+ if (sc1 == null && sc2 == null) {
return true;
+ }
+
+ if (sc1 == null || sc2 == null) {
+ return fail("Security constraints didn't match: {0} != {1}", new Object[]{sc1, sc2});
+ }
- if (sc1 == null || sc2 == null)
- return fail("Security constraints didn't match: {0} != {1}", new Object[] {sc1, sc2});
+ if (!sc1.getId().equals(sc2.getId())) {
+ return fail("Security constraint ids didn't match: {0} != {1}", new Object[]{sc1.getId(), sc2.getId()});
+ }
- if (!sc1.getId().equals(sc2.getId()))
- return fail("Security constraint ids didn't match: {0} != {1}", new Object[] {sc1.getId(), sc2.getId()});
+ if (!sc1.getMethod().equals(sc2.getMethod())) {
+ return fail("Security constraint methods didn't match: {0} != {1}", new Object[]{sc1.getMethod(), sc2.getMethod()});
+ }
- if (!sc1.getMethod().equals(sc2.getMethod()))
- return fail("Security constraint methods didn't match: {0} != {1}", new Object[] {sc1.getMethod(), sc2.getMethod()});
-
// Roles
- List r1 = sc1.getRoles();
- List r2 = sc2.getRoles();
- if (r1.size() != r2.size())
- return fail("Security constraint roles sections didn't match by size: {0} != {1}", new Object[] {new Integer(r1.size()), new Integer(r2.size())});
+ List r1 = sc1.getRoles();
+ List r2 = sc2.getRoles();
+ if (r1.size() != r2.size()) {
+ return fail("Security constraint roles sections didn't match by size: {0} != {1}", new Object[]{new Integer(r1.size()), new Integer(r2.size())});
+ }
- for (int i = 0; i < r1.size(); i++)
- {
- String role1 = (String)r1.get(i);
- String role2 = (String)r2.get(i);
- if (!role1.equals(role2))
- return fail("Security constraint roles didn't match: {0} != {1}", new Object[] {role1, role2});
+ for (int i = 0; i < r1.size(); i++) {
+ String role1 = (String) r1.get(i);
+ String role2 = (String) r2.get(i);
+ if (!role1.equals(role2)) {
+ return fail("Security constraint roles didn't match: {0} != {1}", new Object[]{role1, role2});
+ }
}
return true;
}
- protected boolean propertiesMatch(Map p1, Map p2)
- {
- if (p1 == null && p2 == null)
+ protected boolean propertiesMatch(Map p1, Map p2) {
+ if (p1 == null && p2 == null) {
return true;
+ }
- if (p1 == null || p2 == null)
- return fail("Properties didn't match: {0} != {1}", new Object[] {p1, p2});
+ if (p1 == null || p2 == null) {
+ return fail("Properties didn't match: {0} != {1}", new Object[]{p1, p2});
+ }
- if (!mapsMatch(p1, p2))
+ if (!mapsMatch(p1, p2)) {
return false;
+ }
return true;
}
- protected boolean valuesMatch(Object o1, Object o2)
- {
- if (o1 == null && o2 == null)
+ protected boolean valuesMatch(Object o1, Object o2) {
+ if (o1 == null && o2 == null) {
return true;
-
- if (o1 instanceof Map)
- {
- return mapsMatch((Map)o1, (Map)o2);
}
- else if (o1 instanceof List)
- {
- return listsMatch((List)o1, (List)o2);
- }
- else if (o1 != null)
- {
- if (hasComplexChildren(o1))
- {
+
+ if (o1 instanceof Map) {
+ return mapsMatch((Map) o1, (Map) o2);
+ } else if (o1 instanceof List) {
+ return listsMatch((List) o1, (List) o2);
+ } else if (o1 != null) {
+ if (hasComplexChildren(o1)) {
// We avoid checking a complex/custom types twice in
// case of circular dependencies
Object known = knownObjects.get(o1);
- if (known != null)
- {
+ if (known != null) {
return true;
- }
- else
- {
+ } else {
knownObjects.put(o1, o2);
}
}
@@ -422,49 +420,41 @@ public abstract class ConfigurationConfirmation
return false;
}
- protected boolean stringValuesMatch(String str1, String str2)
- {
- if (str1 == null && str2 == null)
+ protected boolean stringValuesMatch(String str1, String str2) {
+ if (str1 == null && str2 == null) {
return true;
+ }
- if (str1 != null && !str1.equals(str2))
+ if (str1 != null && !str1.equals(str2)) {
return false;
+ }
return true;
}
- protected boolean mapsMatch(Map map1, Map map2)
- {
- if (map1.size() != map2.size())
+ protected boolean mapsMatch(Map map1, Map map2) {
+ if (map1.size() != map2.size()) {
return false;
+ }
// We avoid checking a Map twice in case
// of circular dependencies
Object known = knownObjects.get(map1);
- if (known != null)
- {
+ if (known != null) {
return true;
- }
- else
- {
+ } else {
knownObjects.put(map1, map2);
}
- Iterator it = map1.keySet().iterator();
- while (it.hasNext())
- {
- Object next = it.next();
- if (next instanceof String)
- {
- String key = (String)next;
+ for (Object next : map1.keySet()) {
+ if (next instanceof String) {
+ String key = (String) next;
Object val1 = map1.get(key);
Object val2 = map2.get(key);
if (!valuesMatch(val1, val2))
return false;
- }
- else
- {
+ } else {
return false;
}
}
@@ -472,66 +462,51 @@ public abstract class ConfigurationConfirmation
return true;
}
- protected boolean listsMatch(List list1, List list2)
- {
- if (list1.size() != list2.size())
+ protected boolean listsMatch(List list1, List list2) {
+ if (list1.size() != list2.size()) {
return false;
+ }
// We avoid checking a List twice in case
// of circular dependencies
Object known = knownObjects.get(list1);
- if (known != null)
- {
+ if (known != null) {
return true;
- }
- else
- {
+ } else {
knownObjects.put(list1, list2);
}
- for (int i = 0; i < list1.size(); i++)
- {
+ for (int i = 0; i < list1.size(); i++) {
Object o1 = list1.get(i);
Object o2 = list2.get(i);
- if (!valuesMatch(o1, o2))
+ if (!valuesMatch(o1, o2)) {
return false;
+ }
}
return true;
}
- private static boolean hasComplexChildren(Object o)
- {
- if (o instanceof String
+ private static boolean hasComplexChildren(Object o) {
+ return !(o instanceof String
|| o instanceof Boolean
|| o instanceof Number
|| o instanceof Character
- || o instanceof Date)
- {
- return false;
- }
-
- return true;
+ || o instanceof Date);
}
- protected boolean fail(String message)
- {
+ protected boolean fail(String message) {
return fail(message, null);
}
- protected boolean fail(String message, Object[] parameters)
- {
- if (!isNegativeTest())
- {
- if (parameters != null)
- {
+ protected boolean fail(String message, Object[] parameters) {
+ if (!isNegativeTest()) {
+ if (parameters != null) {
// replace all of the parameters in the msg string
- for (int i = 0; i < parameters.length; i++)
- {
+ for (int i = 0; i < parameters.length; i++) {
String replacement = parameters[i] != null ? parameters[i].toString() : "null";
-
message = message.replaceAll("\\{" + i + "\\}", replacement);
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/config/ConfigurationParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/config/ConfigurationParserTest.java b/core/src/test/java/flex/messaging/config/ConfigurationParserTest.java
index 338285e..924c007 100644
--- a/core/src/test/java/flex/messaging/config/ConfigurationParserTest.java
+++ b/core/src/test/java/flex/messaging/config/ConfigurationParserTest.java
@@ -19,95 +19,65 @@ package flex.messaging.config;
import flex.messaging.LocalizedException;
import flex.messaging.MessageBroker;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URL;
-public class ConfigurationParserTest extends TestCase
-{
+public class ConfigurationParserTest {
private String resourceBase = "/flex/messaging/config/";
private String baseFilePath;
- public ConfigurationParserTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(ConfigurationParserTest.class);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
+ @Before
+ public void setUp() throws Exception {
MessageBroker broker = new MessageBroker(false);
broker.initThreadLocals();
}
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
-
/*
* TESTS
*/
-
- public void testConfiguration()
- {
- try
- {
+ @Test
+ public void testConfiguration() {
+ try {
URL url = this.getClass().getResource(resourceBase + "ConfigurationParserTest.class");
File file = new File(url.getFile());
File dir = new File(file.getParent());
baseFilePath = dir.getAbsolutePath();
- if (dir.isDirectory())
- {
+ if (dir.isDirectory()) {
String resourcePath = getResourcePath(baseFilePath);
processDirectory(dir, resourcePath);
}
- }
- catch (IOException ioe)
- {
- fail("Configuration test failed: " + ioe.getMessage());
+ } catch (IOException ioe) {
+ Assert.fail("Configuration test failed: " + ioe.getMessage());
}
}
- private void processDirectory(File dir, String resourcePath) throws IOException
- {
+ private void processDirectory(File dir, String resourcePath) throws IOException {
File[] files = dir.listFiles(new XMLFilenameFilter());
- for (int i = 0; i < files.length; i++)
- {
- File f = files[i];
- if (f.isDirectory())
- {
- resourcePath = getResourcePath(f.getAbsolutePath());
- processDirectory(f, resourcePath);
- }
- else
- {
- String testName = getTestName(f.getName());
- System.out.println("Running test: " + testName);
- processRequest(f.toString(), testName, resourcePath);
+ if(files != null) {
+ for (File f : files) {
+ if (f.isDirectory()) {
+ resourcePath = getResourcePath(f.getAbsolutePath());
+ processDirectory(f, resourcePath);
+ } else {
+ String testName = getTestName(f.getName());
+ System.out.println("Running test: " + testName);
+ processRequest(f.toString(), testName, resourcePath);
+ }
}
}
}
- private String getResourcePath(String path)
- {
- if (path.startsWith(baseFilePath))
- {
+ private String getResourcePath(String path) {
+ if (path.startsWith(baseFilePath)) {
path = path.substring(baseFilePath.length());
path = path.replace('\\', '/');
return path;
@@ -116,84 +86,69 @@ public class ConfigurationParserTest extends TestCase
return null;
}
- private String getTestName(String fileName)
- {
+ private String getTestName(String fileName) {
fileName = fileName.toLowerCase();
int pos = fileName.indexOf(".xml");
return fileName.substring(0, pos);
}
- private void processRequest(String filename, String testName, String resourcePath) throws IOException
- {
+ private void processRequest(String filename, String testName, String resourcePath) throws IOException {
MessagingConfiguration config = new MessagingConfiguration();
ConfigurationParser parser = new ApacheXPathServerConfigurationParser();
- try
- {
+ try {
parser.parse(filename, new LocalFileResolver(), config);
ConfigurationConfirmation confirmation = getConfirmation(resourcePath, testName);
- if (!confirmation.matches(config))
- fail("MessagingConfiguration did not match test: " + testName);
- }
- catch (LocalizedException ex)
- {
+ if (!confirmation.matches(config)) {
+ Assert.fail("MessagingConfiguration did not match test: " + testName);
+ }
+ } catch (LocalizedException ex) {
ConfigurationConfirmation confirmation = getConfirmation(resourcePath, testName);
- if (confirmation.isNegativeTest())
- {
- if (!confirmation.negativeMatches(ex))
- fail("MessageException did not match negative test " + testName);
- }
- else
- {
+ if (confirmation.isNegativeTest()) {
+ if (!confirmation.negativeMatches(ex)) {
+ Assert.fail("MessageException did not match negative test " + testName);
+ }
+ } else {
throw ex;
}
}
}
- private ConfigurationConfirmation getConfirmation(String resourcePath, String testName) throws IOException
- {
- try
- {
- if (resourceBase.endsWith("/") && resourcePath.startsWith("/"))
+ private ConfigurationConfirmation getConfirmation(String resourcePath, String testName) throws IOException {
+ try {
+ if (resourceBase.endsWith("/") && resourcePath.startsWith("/")) {
resourcePath = resourcePath.substring(1);
+ }
String resource = resourceBase + resourcePath;
- if (resource.startsWith("/"))
+ if (resource.startsWith("/")) {
resource = resource.substring(1);
+ }
String packageName = resource.replace('/', '.');
- if (packageName.length() > 0 && !packageName.endsWith("."))
+ if (packageName.length() > 0 && !packageName.endsWith(".")) {
packageName = packageName + ".";
+ }
String className = packageName + "Confirm" + testName;
Class c = Class.forName(className);
Object obj = c.newInstance();
- ConfigurationConfirmation confirm = (ConfigurationConfirmation)obj;
- return confirm;
- }
- catch (Exception e)
- {
+ return (ConfigurationConfirmation) obj;
+ } catch (Exception e) {
throw new IOException("Unable to load confirmation for testName: " + testName + " in " + resourcePath);
}
}
- static class XMLFilenameFilter implements FilenameFilter
- {
- public boolean accept(File dir, String name)
- {
+ static class XMLFilenameFilter implements FilenameFilter {
+ public boolean accept(File dir, String name) {
String child = dir.getAbsolutePath() + File.separator + name;
File f = new File(child);
- if (f.isDirectory())
- return true;
- else if (name.toLowerCase().endsWith(".xml") && name.indexOf("include") == -1)
- return true;
- else
- return false;
+ return f.isDirectory() || name.toLowerCase().endsWith(".xml") && !name.contains("include");
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/config/ThrottleSettingsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/config/ThrottleSettingsTest.java b/core/src/test/java/flex/messaging/config/ThrottleSettingsTest.java
index 019e258..fe9d37e 100644
--- a/core/src/test/java/flex/messaging/config/ThrottleSettingsTest.java
+++ b/core/src/test/java/flex/messaging/config/ThrottleSettingsTest.java
@@ -20,119 +20,77 @@ package flex.messaging.config;
import flex.messaging.config.ThrottleSettings.Policy;
import flex.messaging.services.messaging.ThrottleManager;
import org.junit.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.Test;
-public class ThrottleSettingsTest extends TestCase
-{
+public class ThrottleSettingsTest {
private static final String UNEXPECTED_EXCEPTION_STRING = "Unexpected exception: ";
- public ThrottleSettingsTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite();
- suite.addTest(new ThrottleSettingsTest("testSetIncomingClientFrequencyHigherThanDestinationFrequency"));
- suite.addTest(new ThrottleSettingsTest("testSetIncomingDestinationFrequencyLowerThanClientFrequency"));
- suite.addTest(new ThrottleSettingsTest("testSetOutgoingClientFrequencyHigherThanDestinationFrequency"));
- suite.addTest(new ThrottleSettingsTest("testSetOutgoingDestinationFrequencyLowerThanClientFrequency"));
- suite.addTest(new ThrottleSettingsTest("testSetIncomingClientFrequencyWithZeroDestinationFrequency"));
- suite.addTest(new ThrottleSettingsTest("testSetIncomingDestinationFrequencyWithZeroClientFrequency"));
- suite.addTest(new ThrottleSettingsTest("testUnknownPolicy"));
- suite.addTest(new ThrottleSettingsTest("testOutgoingPolicyError"));
- return suite;
- }
-
- public void testSetIncomingClientFrequencyHigherThanDestinationFrequency()
- {
+ @Test
+ public void testSetIncomingClientFrequencyHigherThanDestinationFrequency() {
ThrottleSettings ts = new ThrottleSettings();
ts.setIncomingDestinationFrequency(10);
- try
- {
+ try {
ts.setIncomingClientFrequency(15);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
// Success.
- }
- catch (Exception e)
- {
- fail(UNEXPECTED_EXCEPTION_STRING + e);
+ } catch (Exception e) {
+ Assert.fail(UNEXPECTED_EXCEPTION_STRING + e);
}
}
- public void testSetIncomingDestinationFrequencyLowerThanClientFrequency()
- {
+ @Test
+ public void testSetIncomingDestinationFrequencyLowerThanClientFrequency() {
ThrottleSettings ts = new ThrottleSettings();
ts.setIncomingClientFrequency(15);
- try
- {
+ try {
ts.setIncomingDestinationFrequency(10);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
// Success.
- }
- catch (Exception e)
- {
- fail(UNEXPECTED_EXCEPTION_STRING + e);
+ } catch (Exception e) {
+ Assert.fail(UNEXPECTED_EXCEPTION_STRING + e);
}
}
- public void testSetOutgoingClientFrequencyHigherThanDestinationFrequency()
- {
+ @Test
+ public void testSetOutgoingClientFrequencyHigherThanDestinationFrequency() {
ThrottleSettings ts = new ThrottleSettings();
ts.setOutgoingDestinationFrequency(10);
- try
- {
+ try {
ts.setOutgoingClientFrequency(15);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
// Success.
- }
- catch (Exception e)
- {
- fail(UNEXPECTED_EXCEPTION_STRING + e);
+ } catch (Exception e) {
+ Assert.fail(UNEXPECTED_EXCEPTION_STRING + e);
}
}
- public void testSetOutgoingDestinationFrequencyLowerThanClientFrequency()
- {
+ @Test
+ public void testSetOutgoingDestinationFrequencyLowerThanClientFrequency() {
ThrottleSettings ts = new ThrottleSettings();
ts.setOutgoingClientFrequency(15);
- try
- {
+ try {
ts.setOutgoingDestinationFrequency(10);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
// Success.
- }
- catch (Exception e)
- {
- fail(UNEXPECTED_EXCEPTION_STRING + e);
+ } catch (Exception e) {
+ Assert.fail(UNEXPECTED_EXCEPTION_STRING + e);
}
}
- public void testSetIncomingClientFrequencyWithZeroDestinationFrequency()
- {
+ @Test
+ public void testSetIncomingClientFrequencyWithZeroDestinationFrequency() {
ThrottleSettings ts = new ThrottleSettings();
ts.setIncomingDestinationFrequency(0);
ts.setIncomingClientFrequency(10);
Assert.assertEquals(10, ts.getIncomingClientFrequency());
}
- public void testSetIncomingDestinationFrequencyWithZeroClientFrequency()
- {
+ @Test
+ public void testSetIncomingDestinationFrequencyWithZeroClientFrequency() {
ThrottleSettings ts = new ThrottleSettings();
ts.setIncomingClientFrequency(0);
ts.setIncomingDestinationFrequency(10);
@@ -142,41 +100,31 @@ public class ThrottleSettingsTest extends TestCase
/**
* Test that an UNKNOWN policy throws ConfigurationException.
*/
- public void testUnknownPolicy()
- {
- try
- {
+ @Test
+ public void testUnknownPolicy() {
+ try {
ThrottleSettings.parsePolicy("UNKNOWN");
- }
- catch (ConfigurationException ce)
- {
+ } catch (ConfigurationException ce) {
// Success.
- }
- catch (Exception e)
- {
- fail(UNEXPECTED_EXCEPTION_STRING + e);
+ } catch (Exception e) {
+ Assert.fail(UNEXPECTED_EXCEPTION_STRING + e);
}
}
/**
* Test that outgoing policy of ERROR throws ConfigurationException.
*/
- public void testOutgoingPolicyError()
- {
+ @Test
+ public void testOutgoingPolicyError() {
ThrottleManager manager = new ThrottleManager();
ThrottleSettings ts = new ThrottleSettings();
ts.setOutboundPolicy(Policy.ERROR);
- try
- {
+ try {
manager.setThrottleSettings(ts);
- }
- catch (ConfigurationException ce)
- {
+ } catch (ConfigurationException ce) {
// Success.
- }
- catch (Exception e)
- {
- fail(UNEXPECTED_EXCEPTION_STRING + e);
+ } catch (Exception e) {
+ Assert.fail(UNEXPECTED_EXCEPTION_STRING + e);
}
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/io/ClassDeserializationValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/io/ClassDeserializationValidatorTest.java b/core/src/test/java/flex/messaging/io/ClassDeserializationValidatorTest.java
deleted file mode 100644
index f61f5f7..0000000
--- a/core/src/test/java/flex/messaging/io/ClassDeserializationValidatorTest.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package flex.messaging.io;
-
-/**
- * Created by christoferdutz on 09.08.16.
- */
-public class ClassDeserializationValidatorTest {
-}
[2/3] flex-blazeds git commit: - Converted the testsuite to JUnit 4
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/io/amf/AmfDeserializerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/io/amf/AmfDeserializerTest.java b/core/src/test/java/flex/messaging/io/amf/AmfDeserializerTest.java
index 46b2f73..ec0f84a 100644
--- a/core/src/test/java/flex/messaging/io/amf/AmfDeserializerTest.java
+++ b/core/src/test/java/flex/messaging/io/amf/AmfDeserializerTest.java
@@ -19,74 +19,50 @@ package flex.messaging.io.amf;
import flex.messaging.io.MessageDeserializer;
import flex.messaging.io.SerializationContext;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
import macromedia.qa.metrics.MetricsManager;
import macromedia.qa.metrics.Value;
import macromedia.util.UnitTrace;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
+import java.io.*;
import java.net.URI;
import java.net.URL;
-public class AmfDeserializerTest extends TestCase
-{
+public class AmfDeserializerTest {
private MetricsManager metricsManager;
- public AmfDeserializerTest(String name)
- {
- super(name);
- }
-
-
- protected void setUp()
- {
- try
- {
+ @Before
+ public void setUp() {
+ try {
String project = System.getProperty("project.name");
String build = System.getProperty("build.number");
String props = System.getProperty("metrics.properties");
if (project != null && build != null
- && !build.trim().toUpperCase().equals("N/A") && props != null)
- {
+ && !build.trim().toUpperCase().equals("N/A") && props != null) {
File file = new File(props);
- if (file.exists())
- {
+ if (file.exists()) {
metricsManager = new MetricsManager(project, build, file);
-
metricsManager.newRun();
metricsManager.newMetric("AMF Deserialization Time", "ms");
}
}
- }
- catch (Throwable t)
- {
- if (UnitTrace.errors)
+ } catch (Throwable t) {
+ if (UnitTrace.errors) {
t.printStackTrace();
+ }
}
}
-
- public static Test suite()
- {
- return new TestSuite(AmfDeserializerTest.class);
- }
-
- public void testDeserializeMessage()
- {
- try
- {
+ @Test
+ public void testDeserializeMessage() {
+ try {
String sample = System.getProperty("AMF_SAMPLE_FILE");
- if (sample == null || sample.length() < 1)
- {
+ if (sample == null || sample.length() < 1) {
sample = "amf_request.xml";
}
@@ -125,32 +101,29 @@ public class AmfDeserializerTest extends TestCase
long finish = System.currentTimeMillis();
trace.endMessage();
- try
- {
- if (metricsManager != null)
- {
+ try {
+ if (metricsManager != null) {
long duration = finish - start;
Value v2 = metricsManager.createValue(duration);
metricsManager.saveValue(v2);
trace.newLine();
- if (UnitTrace.debug)
+ if (UnitTrace.debug) {
System.out.print("AMF Deserialization Time: " + duration + "ms");
+ }
}
- }
- catch (Throwable t)
- {
- if (UnitTrace.errors)
+ } catch (Throwable t) {
+ if (UnitTrace.errors) {
t.printStackTrace();
+ }
}
- if (UnitTrace.debug)
+ if (UnitTrace.debug) {
System.out.print(trace.toString());
- }
- catch (Exception e)
- {
+ }
+ } catch (Exception e) {
e.printStackTrace();
- fail();
+ Assert.fail();
}
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/io/amf/MessageGenerator.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/io/amf/MessageGenerator.java b/core/src/test/java/flex/messaging/io/amf/MessageGenerator.java
index 9ae13e8..21f0308 100644
--- a/core/src/test/java/flex/messaging/io/amf/MessageGenerator.java
+++ b/core/src/test/java/flex/messaging/io/amf/MessageGenerator.java
@@ -17,22 +17,21 @@
package flex.messaging.io.amf;
+import flex.messaging.io.SerializationContext;
import org.apache.xpath.CachedXPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import flex.messaging.io.SerializationContext;
-
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.io.File;
import java.io.IOException;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
/**
* Test programs use this class to simulate Flash Player AMF requests.
@@ -43,118 +42,91 @@ import java.util.ArrayList;
* underlying DataOutputStream.
* </p>
*/
-public class MessageGenerator extends Amf0Output
-{
+public class MessageGenerator extends Amf0Output {
private DocumentBuilder docBuilder;
- public MessageGenerator()
- {
+ public MessageGenerator() {
super(new SerializationContext());
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setIgnoringComments(true);
docBuilderFactory.setIgnoringElementContentWhitespace(true);
- try
- {
+ try {
docBuilder = docBuilderFactory.newDocumentBuilder();
- }
- catch (ParserConfigurationException ex)
- {
+ } catch (ParserConfigurationException ex) {
throw new RuntimeException(ex);
}
}
- public void parse(String path)
- {
+ public void parse(String path) {
parse(new File(path));
}
- public void parse(File file)
- {
- try
- {
+ public void parse(File file) {
+ try {
Document doc = docBuilder.parse(file);
doc.getDocumentElement().normalize();
parseAmf(doc);
- }
- catch (TransformerException ex)
- {
+ } catch (TransformerException ex) {
throw new RuntimeException(ex);
- }
- catch (SAXException ex)
- {
+ } catch (SAXException ex) {
throw new RuntimeException(ex);
- }
- catch (IOException ex)
- {
+ } catch (IOException ex) {
throw new RuntimeException(ex);
}
}
- private void parseAmf(Document doc) throws TransformerException, IOException
- {
+ private void parseAmf(Document doc) throws TransformerException, IOException {
CachedXPathAPI xpath = new CachedXPathAPI();
Node root = xpath.selectSingleNode(doc, "/amf-request");
- if (root != null)
- {
+ if (root != null) {
// messages
NodeList list = xpath.selectNodeList(root, "message");
- for (int i = 0; i < list.getLength(); i++)
- {
+ for (int i = 0; i < list.getLength(); i++) {
Node message = list.item(i);
message(xpath, message);
}
}
}
- private void message(CachedXPathAPI xpath, Node message) throws TransformerException, IOException
- {
- int version = (int)xpath.eval(message, "version").num();
+ private void message(CachedXPathAPI xpath, Node message) throws TransformerException, IOException {
+ int version = (int) xpath.eval(message, "version").num();
out.writeShort(version);
// Headers
Node headers = xpath.selectSingleNode(message, "headers");
- int headerCount = (int)xpath.eval(headers, "@count").num();
+ int headerCount = (int) xpath.eval(headers, "@count").num();
out.writeShort(headerCount);
NodeList list = xpath.selectNodeList(headers, "header");
- for (int i = 0; i < headerCount; i++)
- {
+ for (int i = 0; i < headerCount; i++) {
Node header = list.item(i);
- if (header != null)
- {
+ if (header != null) {
header(xpath, header, i);
- }
- else
- {
+ } else {
throw new RuntimeException("Missing header(s). Specified " + headerCount + ", found " + (i - 1));
}
}
// Bodies
Node bodies = xpath.selectSingleNode(message, "bodies");
- int bodyCount = (int)xpath.eval(bodies, "@count").num();
+ int bodyCount = (int) xpath.eval(bodies, "@count").num();
out.writeShort(bodyCount);
list = xpath.selectNodeList(bodies, "body");
- for (int i = 0; i < bodyCount; i++)
- {
+ for (int i = 0; i < bodyCount; i++) {
Node body = list.item(i);
- if (body != null)
- {
+ if (body != null) {
body(xpath, body, i);
- }
- else
- {
+ } else {
throw new RuntimeException("Missing body(ies). Specified " + bodyCount + ", found " + (i - 1));
}
}
}
- private void header(CachedXPathAPI xpath, Node header, int i) throws TransformerException, IOException
- {
+ private void header(CachedXPathAPI xpath, Node header, int i) throws TransformerException, IOException {
String name = xpath.eval(header, "@name").toString();
boolean mustUnderstand = xpath.eval(header, "@mustUnderstand").bool();
@@ -173,12 +145,11 @@ public class MessageGenerator extends Amf0Output
Object value = value(xpath, data);
writeObject(value);
- if (isDebug)
+ if (isDebug)
trace.endHeader();
}
- private void body(CachedXPathAPI xpath, Node body, int i) throws TransformerException, IOException
- {
+ private void body(CachedXPathAPI xpath, Node body, int i) throws TransformerException, IOException {
String targetUri = xpath.eval(body, "@targetUri").toString();
String responseUri = xpath.eval(body, "@responseUri").toString();
@@ -198,61 +169,43 @@ public class MessageGenerator extends Amf0Output
writeObject(value);
if (isDebug)
- trace.endMessage();
+ trace.endMessage();
}
- private Object value(CachedXPathAPI xpath, Node node) throws TransformerException, IOException
- {
+ private Object value(CachedXPathAPI xpath, Node node) throws TransformerException, IOException {
String type = node.getNodeName();
String value = xpath.eval(node, ".").toString();
- if (value == null)
- {
+ if (value == null) {
return null;
}
- if (avmPlus)
- {
- if ("string".equals(type))
- {
+ if (avmPlus) {
+ if ("string".equals(type)) {
return value;
- }
- else if ("boolean".equals(type))
- {
+ } else if ("boolean".equals(type)) {
return Boolean.valueOf(value.trim());
- }
- else if ("integer".equals(type))
- {
+ } else if ("integer".equals(type)) {
return Integer.valueOf(value.trim());
- }
- else if ("double".equals(type))
- {
+ } else if ("double".equals(type)) {
return Double.valueOf(value.trim());
- }
- else if ("array".equals(type))
- {
+ } else if ("array".equals(type)) {
List<Object> array = new ArrayList<Object>();
- int count = (int)xpath.eval(node, "@count").num();
+ int count = (int) xpath.eval(node, "@count").num();
NodeList list = xpath.selectNodeList(node, "*");
- for (int i = 0; i < count; i++)
- {
+ for (int i = 0; i < count; i++) {
Node item = list.item(i);
- if (item != null)
- {
+ if (item != null) {
array.add(value(xpath, item));
- }
- else
- {
+ } else {
throw new RuntimeException("Missing array item(s). Specified " + count + ", found " + (i - 1));
}
}
return array;
- }
- else if ("object".equals(type))
- {
+ } else if ("object".equals(type)) {
ASObject object = new ASObject();
NodeList list = xpath.selectNodeList(node, "*[not(self::property)]");
@@ -260,50 +213,40 @@ public class MessageGenerator extends Amf0Output
List<Object> traitProperties = null;
// TRAIT PROPERTIES
- for (int i = 0; i < list.getLength(); i++)
- {
- if (i == 0)
- {
+ for (int i = 0; i < list.getLength(); i++) {
+ if (i == 0) {
Node traits = list.item(i);
String className = xpath.eval(traits, "@classname").toString().trim();
- int count = (int)xpath.eval(traits, "@count").num();
+ int count = (int) xpath.eval(traits, "@count").num();
// boolean dynamic = xpath.eval(traits, "@dynamic").bool();
traitProperties = new ArrayList<Object>(count);
- if (className.length() > 0)
- {
+ if (className.length() > 0) {
object.setType(className);
}
NodeList propList = xpath.selectNodeList(traits, "property");
- for (int p = 0; p < count; p++)
- {
+ for (int p = 0; p < count; p++) {
Node prop = propList.item(p);
- if (prop != null )
- {
+ if (prop != null) {
String propName = xpath.eval(prop, "@name").toString().trim();
traitProperties.add(propName);
- }
- else
- {
+ } else {
throw new RuntimeException("Missing trait property(ies). Specified " + count + ", found " + (p - 1));
}
}
- }
- else
- {
+ } else {
Node prop = list.item(i);
- String propName = (String)traitProperties.get(i - 1);
+ String propName = (String) traitProperties.get(i - 1);
object.put(propName, value(xpath, prop));
}
}
// DYNAMIC PROPERTIES
list = xpath.selectNodeList(node, "property");
- for (int i = 0; i < list.getLength(); i++)
- {
+ for (int i = 0; i < list.getLength(); i++) {
Node prop = list.item(i);
String propName = xpath.eval(prop, "@name").toString();
Node propValue = xpath.selectSingleNode(prop, "*");
@@ -312,76 +255,53 @@ public class MessageGenerator extends Amf0Output
return object;
- }
- else if ("xml".equals(type))
- {
+ } else if ("xml".equals(type)) {
return value;
}
- }
- else
- {
- if ("avmplus".equals(type))
- {
+ } else {
+ if ("avmplus".equals(type)) {
setAvmPlus(true);
Node data = xpath.selectSingleNode(node, "*"); // Only one data item can be sent as the body...
return value(xpath, data);
- }
- else if ("string".equals(type))
- {
+ } else if ("string".equals(type)) {
return value;
- }
- else if ("boolean".equals(type))
- {
+ } else if ("boolean".equals(type)) {
return Boolean.valueOf(value.trim());
- }
- else if ("number".equals(type))
- {
+ } else if ("number".equals(type)) {
return Double.valueOf(value.trim());
- }
- else if ("array".equals(type))
- {
+ } else if ("array".equals(type)) {
List<Object> array = new ArrayList<Object>();
- int count = (int)xpath.eval(node, "@count").num();
+ int count = (int) xpath.eval(node, "@count").num();
NodeList list = xpath.selectNodeList(node, "*");
- for (int i = 0; i < count; i++)
- {
+ for (int i = 0; i < count; i++) {
Node item = list.item(i);
- if (item != null)
- {
+ if (item != null) {
array.add(value(xpath, item));
- }
- else
- {
+ } else {
throw new RuntimeException("Missing array item(s). Specified " + count + ", found " + (i - 1));
}
}
return array;
- }
- else if ("object".equals(type))
- {
+ } else if ("object".equals(type)) {
ASObject object = new ASObject();
String className = xpath.eval(node, "@classname").toString().trim();
- if (className.length() > 0)
- {
+ if (className.length() > 0) {
object.setType(className);
}
NodeList list = xpath.selectNodeList(node, "property");
- for (int i = 0; i < list.getLength(); i++)
- {
+ for (int i = 0; i < list.getLength(); i++) {
Node prop = list.item(i);
String propName = xpath.eval(prop, "@name").toString().trim();
object.put(propName, value(xpath, prop));
}
return object;
- }
- else if ("xml".equals(type))
- {
+ } else if ("xml".equals(type)) {
return value;
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/io/amf/translator/HashReferenceTableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/io/amf/translator/HashReferenceTableTest.java b/core/src/test/java/flex/messaging/io/amf/translator/HashReferenceTableTest.java
index b03ec5a..3c3d47b 100644
--- a/core/src/test/java/flex/messaging/io/amf/translator/HashReferenceTableTest.java
+++ b/core/src/test/java/flex/messaging/io/amf/translator/HashReferenceTableTest.java
@@ -17,20 +17,21 @@
package flex.messaging.io.amf.translator;
+import flex.messaging.io.amf.TraitsInfo;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.framework.Test;
-import flex.messaging.io.amf.TraitsInfo;
-
/**
* Simple test to check that the HashReferenceTableTest
* auto increments correctly, does not try to access items
* out of bounds, and correct auto generates index-based
* and incremented Integer values for added keys.
- *
+ * <p>
* This test also checks that the condition for equality
* is enforced, despite look ups being optimized with
* a hashcode. The most important class to test is
@@ -39,8 +40,7 @@ import flex.messaging.io.amf.TraitsInfo;
*
* @see flex.messaging.io.amf.TraitsInfo;
*/
-public class HashReferenceTableTest extends TestCase
-{
+public class HashReferenceTableTest {
private Map<Object, Object> table;
private static Object ONE = 1;
@@ -50,34 +50,37 @@ public class HashReferenceTableTest extends TestCase
private static Object THREE = "Hello";
private static Object THREEPRIME = "Hello";
private static TraitsInfo FOUR = new TraitsInfo("flex.messaging.messages.RemotingMessage", true, false, 2);
- static
- {
+
+ static {
String prop1 = "prop1";
FOUR.addProperty(prop1);
String prop2 = "prop2";
FOUR.addProperty(prop2);
}
+
private static TraitsInfo FOURPRIME = new TraitsInfo("flex.messaging.messages.RemotingMessage", true, false, 2);
- static
- {
+
+ static {
String prop1 = "prop1";
FOURPRIME.addProperty(prop1);
String prop2 = "prop2";
FOURPRIME.addProperty(prop2);
}
+
private static Object FIVE = "Apples";
private static Object FIVEPRIME = "Oranges";
private static TraitsInfo SIX = new TraitsInfo("flex.messaging.messages.RemotingMessage", true, false, 2);
- static
- {
+
+ static {
String prop1 = "propA";
SIX.addProperty(prop1);
String prop2 = "propB";
SIX.addProperty(prop2);
}
+
private static TraitsInfo SIXPRIME = new TraitsInfo("flex.messaging.messages.RemotingMessage", true, false, 2);
- static
- {
+
+ static {
String prop1 = "propA";
SIXPRIME.addProperty(prop1);
String prop2 = "propZ";
@@ -90,27 +93,22 @@ public class HashReferenceTableTest extends TestCase
private static final int length = 2;
- public HashReferenceTableTest()
- {
- }
-
- protected void setUp() throws Exception
- {
+ @Before
+ public void setUp() throws Exception {
table = new HashMap<Object, Object>(length);
}
- public static Test suite()
- {
- return new TestSuite(HashReferenceTableTest.class);
+ @After
+ public void tearDown() throws Exception {
+ table = null;
}
- public void testCapacity()
- {
+ @Test
+ public void testCapacity() {
table.clear();
int goal = length * 2;
- for (int i = 0; i < goal; i++)
- {
+ for (int i = 0; i < goal; i++) {
table.put(keys[i], values[i]);
}
@@ -118,162 +116,132 @@ public class HashReferenceTableTest extends TestCase
table.put(SIX, SIXPRIME);
Object one = table.get(ONE);
- if (one != ONEPRIME)
- {
- fail();
+ if (one != ONEPRIME) {
+ Assert.fail();
}
one = table.get(ONEPRIME);
- if (one != ONEPRIME)
- {
- fail();
+ if (one != ONEPRIME) {
+ Assert.fail();
}
Object two = table.get(TWO);
- if (two != TWOPRIME)
- {
- fail();
+ if (two != TWOPRIME) {
+ Assert.fail();
}
two = table.get(TWOPRIME);
- if (two != TWOPRIME)
- {
- fail();
+ if (two != TWOPRIME) {
+ Assert.fail();
}
Object three = table.get(THREE);
- if (three != THREEPRIME)
- {
- fail();
+ if (three != THREEPRIME) {
+ Assert.fail();
}
three = table.get(THREEPRIME);
- if (three != THREEPRIME)
- {
- fail();
+ if (three != THREEPRIME) {
+ Assert.fail();
}
Object four = table.get(FOUR);
- if (four != FOURPRIME)
- {
- fail();
+ if (four != FOURPRIME) {
+ Assert.fail();
}
four = table.get(FOURPRIME);
- if (four != FOURPRIME)
- {
- fail();
+ if (four != FOURPRIME) {
+ Assert.fail();
}
Object five = table.get(FIVE);
- if (five == FIVEPRIME)
- {
- fail();
+ if (five == FIVEPRIME) {
+ Assert.fail();
}
five = table.get(FIVEPRIME);
- if (five == FIVEPRIME)
- {
- fail();
+ if (five == FIVEPRIME) {
+ Assert.fail();
}
Object six = table.get(SIX);
- if (six != SIXPRIME)
- {
- fail();
+ if (six != SIXPRIME) {
+ Assert.fail();
}
six = table.get(SIXPRIME);
- if (six != null)
- {
- fail();
+ if (six != null) {
+ Assert.fail();
}
- if (table.size() != 5)
- {
- fail();
+ if (table.size() != 5) {
+ Assert.fail();
}
}
- public void testIndex()
- {
+ @Test
+ public void testIndex() {
table.clear();
int goal = length * 2;
- for (int i = 0; i < goal; i++)
- {
+ for (int i = 0; i < goal; i++) {
table.put(keys[i], table.size());
}
- Integer first = (Integer)table.get(ONE);
- if (first != 0)
- {
- fail();
+ Integer first = (Integer) table.get(ONE);
+ if (first != 0) {
+ Assert.fail();
}
- first = (Integer)table.get(ONEPRIME);
- if (first != 0)
- {
- fail();
+ first = (Integer) table.get(ONEPRIME);
+ if (first != 0) {
+ Assert.fail();
}
- Integer second = (Integer)table.get(TWO);
- if (second != 1)
- {
- fail();
+ Integer second = (Integer) table.get(TWO);
+ if (second != 1) {
+ Assert.fail();
}
- second = (Integer)table.get(TWOPRIME);
- if (second != 1)
- {
- fail();
+ second = (Integer) table.get(TWOPRIME);
+ if (second != 1) {
+ Assert.fail();
}
- Integer third = (Integer)table.get(THREE);
- if (third != 2)
- {
- fail();
+ Integer third = (Integer) table.get(THREE);
+ if (third != 2) {
+ Assert.fail();
}
- third = (Integer)table.get(THREEPRIME);
- if (third != 2)
- {
- fail();
+ third = (Integer) table.get(THREEPRIME);
+ if (third != 2) {
+ Assert.fail();
}
- Integer four = (Integer)table.get(FOUR);
- if (four != 3)
- {
- fail();
+ Integer four = (Integer) table.get(FOUR);
+ if (four != 3) {
+ Assert.fail();
}
- four = (Integer)table.get(FOURPRIME);
- if (four != 3)
- {
- fail();
+ four = (Integer) table.get(FOURPRIME);
+ if (four != 3) {
+ Assert.fail();
}
- Integer five = (Integer)table.get(FIVE);
- if (five != null)
- {
- fail();
+ Integer five = (Integer) table.get(FIVE);
+ if (five != null) {
+ Assert.fail();
}
- five = (Integer)table.get(FIVEPRIME);
- if (five != null)
- {
- fail();
+ five = (Integer) table.get(FIVEPRIME);
+ if (five != null) {
+ Assert.fail();
}
- if (table.size() != 4)
- {
- fail();
+ if (table.size() != 4) {
+ Assert.fail();
}
}
-
- protected void tearDown() throws Exception
- {
- table = null;
- }
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/io/amf/translator/StrictReferenceTableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/io/amf/translator/StrictReferenceTableTest.java b/core/src/test/java/flex/messaging/io/amf/translator/StrictReferenceTableTest.java
index 5d620d3..a870c34 100644
--- a/core/src/test/java/flex/messaging/io/amf/translator/StrictReferenceTableTest.java
+++ b/core/src/test/java/flex/messaging/io/amf/translator/StrictReferenceTableTest.java
@@ -17,21 +17,21 @@
package flex.messaging.io.amf.translator;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
import java.util.IdentityHashMap;
import java.util.Map;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.framework.Test;
-
/**
* Simple test to check that the StrictReferenceTable
* auto increments correctly, does not try to access items
* out of bounds, and correct auto generates index-based
* and incremented Integer values for added keys.
*/
-public class StrictReferenceTableTest extends TestCase
-{
+public class StrictReferenceTableTest {
private Map<Object, Object> table;
private static Object ONE = new Object();
@@ -43,109 +43,87 @@ public class StrictReferenceTableTest extends TestCase
private static final int length = 2;
- public StrictReferenceTableTest()
- {
- }
-
- protected void setUp() throws Exception
- {
+ @Before
+ public void setUp() throws Exception {
table = new IdentityHashMap<Object, Object>(length);
}
- public static Test suite()
- {
- return new TestSuite(StrictReferenceTableTest.class);
+ @After
+ public void tearDown() throws Exception {
+ table = null;
}
- public void testCapacity()
- {
+ @Test
+ public void testCapacity() {
table.clear();
int goal = length * 2;
- for (int i = 0; i < goal; i++)
- {
+ for (int i = 0; i < goal; i++) {
table.put(objects[i], objects[i]);
}
Object one = table.get(ONE);
- if (one != ONE)
- {
- fail();
+ if (one != ONE) {
+ Assert.fail();
}
Object two = table.get(TWO);
- if (two != TWO)
- {
- fail();
+ if (two != TWO) {
+ Assert.fail();
}
Object three = table.get(THREE);
- if (three != THREE)
- {
- fail();
+ if (three != THREE) {
+ Assert.fail();
}
Object four = table.get(FOUR);
- if (four != FOUR)
- {
- fail();
+ if (four != FOUR) {
+ Assert.fail();
}
Object five = table.get(FIVE);
- if (five != null)
- {
- fail();
+ if (five != null) {
+ Assert.fail();
}
- if (table.size() != 4)
- {
- fail();
+ if (table.size() != 4) {
+ Assert.fail();
}
}
- public void testIndex()
- {
+ @Test
+ public void testIndex() {
table.clear();
int goal = length * 2;
- for (int i = 0; i < goal; i++)
- {
+ for (int i = 0; i < goal; i++) {
table.put(objects[i], table.size());
}
- Integer first = (Integer)table.get(ONE);
- if (first != 0)
- {
- fail();
+ Integer first = (Integer) table.get(ONE);
+ if (first != 0) {
+ Assert.fail();
}
- Integer second = (Integer)table.get(TWO);
- if (second != 1)
- {
- fail();
+ Integer second = (Integer) table.get(TWO);
+ if (second != 1) {
+ Assert.fail();
}
- Integer third = (Integer)table.get(THREE);
- if (third != 2)
- {
- fail();
+ Integer third = (Integer) table.get(THREE);
+ if (third != 2) {
+ Assert.fail();
}
- Integer fourth = (Integer)table.get(FOUR);
- if (fourth != 3)
- {
- fail();
+ Integer fourth = (Integer) table.get(FOUR);
+ if (fourth != 3) {
+ Assert.fail();
}
Object fifth = table.get(FIVE);
- if (fifth != null)
- {
- fail();
+ if (fifth != null) {
+ Assert.fail();
}
}
-
- protected void tearDown() throws Exception
- {
- table = null;
- }
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/io/amf/validators/AmfDeserializationValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/io/amf/validators/AmfDeserializationValidatorTest.java b/core/src/test/java/flex/messaging/io/amf/validators/AmfDeserializationValidatorTest.java
index f1114e4..60b0012 100644
--- a/core/src/test/java/flex/messaging/io/amf/validators/AmfDeserializationValidatorTest.java
+++ b/core/src/test/java/flex/messaging/io/amf/validators/AmfDeserializationValidatorTest.java
@@ -20,42 +20,26 @@ package flex.messaging.io.amf.validators;
import flex.messaging.config.ConfigMap;
import flex.messaging.io.MessageDeserializer;
import flex.messaging.io.SerializationContext;
-import flex.messaging.io.amf.ActionContext;
-import flex.messaging.io.amf.ActionMessage;
-import flex.messaging.io.amf.AmfMessageDeserializer;
-import flex.messaging.io.amf.AmfTrace;
-import flex.messaging.io.amf.MessageGenerator;
+import flex.messaging.io.amf.*;
import flex.messaging.validators.DeserializationValidator;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
import macromedia.util.UnitTrace;
+import org.junit.Assert;
+import org.junit.Test;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
+import java.io.*;
import java.net.URI;
import java.net.URL;
-public class AmfDeserializationValidatorTest extends TestCase
-{
- public static Test suite()
- {
- return new TestSuite(AmfDeserializationValidatorTest.class);
- }
-
- public void testDeserializationValidator()
- {
+public class AmfDeserializationValidatorTest {
+ @Test
+ public void testDeserializationValidator() {
deserializateRequest(null);
long duration1 = 0, duration2 = 0;
DeserializationValidator validator = new TestDeserializationValidator();
int n = 100; // Number of times to run the tests, use an even number.
- for (int i = 0; i < n/2; i++)
- {
+ for (int i = 0; i < n / 2; i++) {
long start1 = System.currentTimeMillis();
deserializateRequest(null);
duration1 += (System.currentTimeMillis() - start1);
@@ -65,8 +49,7 @@ public class AmfDeserializationValidatorTest extends TestCase
duration2 += (System.currentTimeMillis() - start2);
}
- for (int i = 0; i < n/2; i++)
- {
+ for (int i = 0; i < n / 2; i++) {
long start2 = System.currentTimeMillis();
deserializateRequest(validator);
duration2 += (System.currentTimeMillis() - start2);
@@ -83,10 +66,8 @@ public class AmfDeserializationValidatorTest extends TestCase
}
}
- private void deserializateRequest(DeserializationValidator validator)
- {
- try
- {
+ private void deserializateRequest(DeserializationValidator validator) {
+ try {
// Find sample AMF data, or read the default file.
String sample = System.getProperty("AMF_SAMPLE_FILE");
if (sample == null || sample.length() < 1)
@@ -129,38 +110,31 @@ public class AmfDeserializationValidatorTest extends TestCase
//if (UnitTrace.debug) // Print trace output.
// System.out.print(trace.toString());
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
- fail();
+ Assert.fail();
}
}
// A simple deserialization validator that simply returns true for all creation
// and assignments validations.
- class TestDeserializationValidator implements DeserializationValidator
- {
- public boolean validateAssignment(Object instance, int index, Object value)
- {
+ class TestDeserializationValidator implements DeserializationValidator {
+ public boolean validateAssignment(Object instance, int index, Object value) {
//System.out.println("validateAssign: [" + (instance == null? "null" : instance.getClass().getName()) + "," + index + "," + value + "]");
return true;
}
- public boolean validateAssignment(Object instance, String propertyName, Object value)
- {
+ public boolean validateAssignment(Object instance, String propertyName, Object value) {
//System.out.println("validateAssign: [" + (instance == null? "null" : instance.getClass().getName()) + "," + propertyName + "," + value + "]");
return true;
}
- public boolean validateCreation(Class<?> c)
- {
+ public boolean validateCreation(Class<?> c) {
//System.out.println("validateCreate: " + (c == null? "null" : c.getName()));
return true;
}
- public void initialize(String id, ConfigMap configMap)
- {
+ public void initialize(String id, ConfigMap configMap) {
// No-op
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/io/amfx/AllowDocumentTypeDeclaration.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/io/amfx/AllowDocumentTypeDeclaration.java b/core/src/test/java/flex/messaging/io/amfx/AllowDocumentTypeDeclaration.java
index f90f7da..fb07a84 100644
--- a/core/src/test/java/flex/messaging/io/amfx/AllowDocumentTypeDeclaration.java
+++ b/core/src/test/java/flex/messaging/io/amfx/AllowDocumentTypeDeclaration.java
@@ -21,7 +21,7 @@ package flex.messaging.io.amfx;
import flex.messaging.MessageException;
import flex.messaging.util.XMLUtil;
import org.junit.Assert;
-import junit.framework.TestCase;
+import org.junit.Test;
import java.io.BufferedReader;
import java.io.IOException;
@@ -30,15 +30,16 @@ import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
-public class AllowDocumentTypeDeclaration extends TestCase {
+public class AllowDocumentTypeDeclaration {
+ @Test
public void testDoctypeEnabled() throws Exception {
// Start a simple server socket.
TinyServer server = new TinyServer();
server.start();
// Wait till the server is up.
- while(server.port == 0) {
+ while (server.port == 0) {
Thread.sleep(100);
}
@@ -56,13 +57,14 @@ public class AllowDocumentTypeDeclaration extends TestCase {
}
}
+ @Test
public void testDoctypeDisabled() throws Exception {
// Start a simple server socket.
TinyServer server = new TinyServer();
server.start();
// Wait till the server is up.
- while(server.port == 0) {
+ while (server.port == 0) {
Thread.sleep(100);
}
@@ -102,7 +104,7 @@ public class AllowDocumentTypeDeclaration extends TestCase {
clientSocket = serverSocket.accept();
connected = true;
BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
- while(reader.ready()) {
+ while (reader.ready()) {
String line = reader.readLine();
System.out.println(line);
}
@@ -122,12 +124,12 @@ public class AllowDocumentTypeDeclaration extends TestCase {
} finally {
try {
clientSocket.getOutputStream().close();
- } catch(Exception e) {
+ } catch (Exception e) {
// Ignore ...
}
try {
clientSocket.getOutputStream().close();
- } catch(Exception e) {
+ } catch (Exception e) {
// Ignore ...
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/io/amfx/AmfxSerializationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/io/amfx/AmfxSerializationTest.java b/core/src/test/java/flex/messaging/io/amfx/AmfxSerializationTest.java
index eb3b32b..84c32d2 100644
--- a/core/src/test/java/flex/messaging/io/amfx/AmfxSerializationTest.java
+++ b/core/src/test/java/flex/messaging/io/amfx/AmfxSerializationTest.java
@@ -16,60 +16,37 @@
*/
package flex.messaging.io.amfx;
+import flex.messaging.MessageException;
+import flex.messaging.io.SerializationContext;
+import flex.messaging.io.amf.*;
import flex.messaging.validators.ClassDeserializationValidator;
-import junit.framework.TestCase;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.FileInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.*;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Iterator;
-
-import flex.messaging.io.SerializationContext;
-import flex.messaging.io.amf.ActionContext;
-import flex.messaging.io.amf.ActionMessage;
-import flex.messaging.io.amf.AmfTrace;
-import flex.messaging.io.amf.MessageBody;
-import flex.messaging.io.amf.MessageHeader;
-import flex.messaging.MessageException;
/**
* Runs through an extensive suite of deserialization
* test cases for AMFX data types and message structures.
- *
+ * <p>
* The first step is to turn an XML file into an AMFX request.
* If the request is not a negative test then it is reserialized
* back to XML to test the serializer. Finally, the serialized
* XML is re-deserialized back into a request and once more
* tested.
*/
-public class AmfxSerializationTest extends TestCase
-{
+public class AmfxSerializationTest {
private String resourceBase = "/flex/messaging/io/amfx/";
private String baseFilePath;
private SerializationContext serializationContext;
private AmfTrace trace;
- public AmfxSerializationTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(AmfxSerializationTest.class);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
ClassDeserializationValidator classDeserializationValidator = new ClassDeserializationValidator();
classDeserializationValidator.addAllowClassPattern("flex.messaging.io.amfx.testtypes.*");
serializationContext = new SerializationContext();
@@ -78,68 +55,56 @@ public class AmfxSerializationTest extends TestCase
//trace = new AmfTrace();
}
- protected void tearDown() throws Exception
- {
- super.tearDown();
+ @After
+ public void tearDown() throws Exception {
SerializationContext.setSerializationContext(null);
trace = null;
}
- public void testSerialization()
- {
- try
- {
+ @Test
+ public void testSerialization() {
+ try {
URL url = this.getClass().getResource(resourceBase + "AmfxSerializationTest.class");
File file = new File(url.getFile());
File dir = new File(file.getParent());
baseFilePath = dir.getAbsolutePath();
- if (dir.isDirectory())
- {
+ if (dir.isDirectory()) {
String resourcePath = getResourcePath(baseFilePath);
processDirectory(dir, resourcePath);
}
- }
- catch (IOException ioe)
- {
- fail("AMFX deserialization test failed: " + ioe.getMessage());
- }
- finally
- {
- if (trace != null)
+ } catch (IOException ioe) {
+ Assert.fail("AMFX deserialization test failed: " + ioe.getMessage());
+ } finally {
+ if (trace != null) {
System.out.println(trace.toString());
+ }
}
}
- private void processDirectory(File dir, String resourcePath) throws IOException
- {
+ private void processDirectory(File dir, String resourcePath) throws IOException {
File[] files = dir.listFiles(new XMLFilenameFilter());
- for (int i = 0; i < files.length; i++)
- {
- File f = files[i];
- if (f.isDirectory())
- {
- resourcePath = getResourcePath(f.getAbsolutePath());
- processDirectory(f, resourcePath);
- }
- else
- {
- String testName = getTestName(f.getName());
- System.out.println("Running test: " + testName);
+ if(files != null) {
+ for (File f : files) {
+ if (f.isDirectory()) {
+ resourcePath = getResourcePath(f.getAbsolutePath());
+ processDirectory(f, resourcePath);
+ } else {
+ String testName = getTestName(f.getName());
+ System.out.println("Running test: " + testName);
- FileInputStream fis = new FileInputStream(f);
+ FileInputStream fis = new FileInputStream(f);
- processRequest(resourcePath, testName, fis);
+ processRequest(resourcePath, testName, fis);
+ }
}
}
}
- private String getResourcePath(String path)
- {
- if (path.startsWith(baseFilePath))
- {
+ private String getResourcePath(String path) {
+ if (path.startsWith(baseFilePath)) {
path = path.substring(baseFilePath.length());
path = path.replace('\\', '/');
return path;
@@ -148,18 +113,15 @@ public class AmfxSerializationTest extends TestCase
return null;
}
- private String getTestName(String fileName)
- {
+ private String getTestName(String fileName) {
fileName = fileName.toLowerCase();
int pos = fileName.indexOf(".xml");
return fileName.substring(0, pos);
}
- private void processRequest(String resourcePath, String testName, InputStream is) throws IOException
- {
- try
- {
- SerializationContext.setSerializationContext((SerializationContext)serializationContext.clone());
+ private void processRequest(String resourcePath, String testName, InputStream is) throws IOException {
+ try {
+ SerializationContext.setSerializationContext((SerializationContext) serializationContext.clone());
// STEP 1. Deserialize Message
ActionContext context = new ActionContext();
context.setResponseMessage(new ActionMessage());
@@ -169,56 +131,51 @@ public class AmfxSerializationTest extends TestCase
AmfxMessageDeserializer deserializer = new AmfxMessageDeserializer();
deserializer.initialize(serializationContext, is, trace);
- if (trace != null)
+ if (trace != null) {
trace.startRequest("Deserializing AMF/HTTP request");
+ }
DeserializationConfirmation confirm = getConfirmation(resourcePath, testName);
confirm.setContext(serializationContext);
- try
- {
+ try {
deserializer.readMessage(requestMessage, context);
- }
- catch (MessageException me) // For negative tests that cause MessageExceptions.
+ } catch (MessageException me) // For negative tests that cause MessageExceptions.
{
- if (!confirm.isNegativeTest())
- fail("Only negative tests might cause MessageExceptions: " + testName);
+ if (!confirm.isNegativeTest()) {
+ Assert.fail("Only negative tests might cause MessageExceptions: " + testName);
+ }
}
- if (!confirm.isNegativeTest() && !confirm.successMatches(requestMessage))
- fail("ActionMessage did not match test: " + testName);
+ if (!confirm.isNegativeTest() && !confirm.successMatches(requestMessage)) {
+ Assert.fail("ActionMessage did not match test: " + testName);
+ }
// STEP 2. Re-serialize Message (Negative tests won't make it this far...)
// create the response body
- if (requestMessage.getBodyCount() > 0 || requestMessage.getHeaderCount() > 0)
- {
+ if (requestMessage.getBodyCount() > 0 || requestMessage.getHeaderCount() > 0) {
ActionMessage responseMessage = context.getResponseMessage();
- if (requestMessage.getBodyCount() > 0)
- {
+ if (requestMessage.getBodyCount() > 0) {
ArrayList bodies = requestMessage.getBodies();
- Iterator it = bodies.iterator();
- while (it.hasNext())
- {
- MessageBody requestBody = (MessageBody)it.next();
+ for (Object body : bodies) {
+ MessageBody requestBody = (MessageBody) body;
MessageBody responseBody = new MessageBody();
responseBody.setData(requestBody.getData());
responseMessage.addBody(responseBody);
}
}
- if (requestMessage.getHeaderCount() > 0)
- {
+ if (requestMessage.getHeaderCount() > 0) {
ArrayList headers = requestMessage.getHeaders();
- Iterator it = headers.iterator();
- while (it.hasNext())
- {
- responseMessage.addHeader((MessageHeader)it.next());
+ for (Object header : headers) {
+ responseMessage.addHeader((MessageHeader) header);
}
}
- if (trace != null)
+ if (trace != null) {
trace.startRequest("Serializing AMF/HTTP request");
+ }
ByteArrayOutputStream bout = new ByteArrayOutputStream();
@@ -235,71 +192,66 @@ public class AmfxSerializationTest extends TestCase
deserializer = new AmfxMessageDeserializer();
deserializer.initialize(serializationContext, bis, trace);
- if (trace != null)
+ if (trace != null) {
trace.startRequest("Deserializing AMF/HTTP request");
+ }
deserializer.readMessage(requestMessage, context);
confirm.setContext(serializationContext);
- if (!confirm.successMatches(requestMessage))
- fail("ActionMessage did not match test on deserialization after re-serialization: " + testName);
+ if (!confirm.successMatches(requestMessage)) {
+ Assert.fail("ActionMessage did not match test on deserialization after re-serialization: " + testName);
+ }
}
- }
- catch (MessageException ex)
- {
- throw ex;
- }
- finally
- {
+ } finally {
SerializationContext.setSerializationContext(null);
}
}
- private DeserializationConfirmation getConfirmation(String resourcePath, String testName) throws IOException
- {
- try
- {
- if (resourceBase.endsWith("/") && resourcePath.startsWith("/"))
+ private DeserializationConfirmation getConfirmation(String resourcePath, String testName) throws IOException {
+ try {
+ if (resourceBase.endsWith("/") && resourcePath.startsWith("/")) {
resourcePath = resourcePath.substring(1);
+ }
String resource = resourceBase + resourcePath;
- if (resource.startsWith("/"))
+ if (resource.startsWith("/")) {
resource = resource.substring(1);
+ }
String packageName = resource.replace('/', '.');
- if (packageName.length() > 0 && !packageName.endsWith("."))
+ if (packageName.length() > 0 && !packageName.endsWith(".")) {
packageName = packageName + ".";
+ }
String className = packageName + "Confirm" + testName;
Class c = Class.forName(className);
Object obj = c.newInstance();
- DeserializationConfirmation confirm = (DeserializationConfirmation)obj;
- return confirm;
- }
- catch (Exception e)
- {
+ return (DeserializationConfirmation) obj;
+ } catch (Exception e) {
throw new IOException("Unable to load confirmation for testName: " + testName + " in " + resourcePath);
}
}
- static class XMLFilenameFilter implements FilenameFilter
- {
- public boolean accept(File dir, String name)
- {
+ static class XMLFilenameFilter implements FilenameFilter {
+ public boolean accept(File dir, String name) {
String child = dir.getAbsolutePath() + File.separator + name;
File f = new File(child);
- if (f.isDirectory() && !name.startsWith(".svn"))
+ if (f.isDirectory() && !name.startsWith(".svn")) {
return true;
- else if (name.toLowerCase().endsWith(".xml"))
+ }
+ else if (name.toLowerCase().endsWith(".xml")) {
return true;
- else
+ }
+ else {
return false;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/log/LogTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/log/LogTest.java b/core/src/test/java/flex/messaging/log/LogTest.java
index afcfa48..0e04b53 100644
--- a/core/src/test/java/flex/messaging/log/LogTest.java
+++ b/core/src/test/java/flex/messaging/log/LogTest.java
@@ -17,83 +17,60 @@
package flex.messaging.log;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
import java.util.ArrayList;
import java.util.List;
-import org.junit.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class LogTest extends TestCase
-{
- public LogTest(String name)
- {
- super(name);
- }
-
+public class LogTest {
+
private TestingTarget testTarget;
-
- public static Test suite()
- {
+
+ @Before
+ public void setUp() throws Exception {
// Make sure the logger is reset before starting the tests.
Log.clear();
-
- // Explicitly specify the order of the tests.
- TestSuite suite = new TestSuite();
- suite.addTest(new LogTest("testInitialLogState"));
- suite.addTest(new LogTest("testLogStateAfterAddingTarget"));
- suite.addTest(new LogTest("testLogStateAfterAddRemoveTarget"));
- suite.addTest(new LogTest("testAddTargetGetLogger"));
- suite.addTest(new LogTest("testAddTargetGetLoggerThenRemoveFilter"));
- suite.addTest(new LogTest("testGetLoggerAddTarget"));
- suite.addTest(new LogTest("testLogAddFilterNull"));
- suite.addTest(new LogTest("testLogSetFilterNull"));
- return suite;
- }
-
- protected void setUp() throws Exception
- {
Log.createLog();
- // Init a ConsoleLogTarget for testing purposes.
+ // Init a ConsoleLogTarget for testing purposes.
testTarget = new TestingTarget(); // Defaults to a log level of none with no filters.
- super.setUp();
}
- protected void tearDown() throws Exception
- {
+ @After
+ public void tearDown() throws Exception {
Log.flush();
- super.tearDown();
}
-
- public void testInitialLogState()
- {
+
+ @Test
+ public void testInitialLogState() {
Assert.assertEquals(Log.getTargetLevel(), LogEvent.NONE);
- Assert.assertTrue(Log.getTargets().size() == 0);
+ Assert.assertTrue(Log.getTargets().size() == 0);
}
-
- public void testLogStateAfterAddingTarget()
- {
+
+ @Test
+ public void testLogStateAfterAddingTarget() {
Assert.assertEquals(testTarget.getLevel(), LogEvent.ERROR);
testTarget.setLevel(LogEvent.FATAL);
- Assert.assertEquals(testTarget.getLevel(), LogEvent.FATAL);
+ Assert.assertEquals(testTarget.getLevel(), LogEvent.FATAL);
Assert.assertTrue(testTarget.getFilters().size() == 1);
Log.addTarget(testTarget);
Assert.assertEquals(Log.getTargetLevel(), LogEvent.FATAL);
Assert.assertTrue(Log.getTargets().size() == 1);
}
-
- public void testLogStateAfterAddRemoveTarget()
- {
+
+ @Test
+ public void testLogStateAfterAddRemoveTarget() {
testTarget.setLevel(LogEvent.FATAL);
Log.addTarget(testTarget);
Log.removeTarget(testTarget);
Assert.assertEquals(Log.getTargetLevel(), LogEvent.NONE);
Assert.assertTrue(Log.getTargets().size() == 0);
}
-
- public void testAddTargetGetLogger()
- {
+
+ @Test
+ public void testAddTargetGetLogger() {
testTarget.setLevel(LogEvent.ALL);
testTarget.addFilter("*");
Assert.assertTrue(testTarget.getFilters().size() == 1);
@@ -107,9 +84,9 @@ public class LogTest extends TestCase
testTarget.removeFilter("*");
Assert.assertTrue(testTarget.getFilters().size() == 0);
}
-
- public void testAddTargetGetLoggerThenRemoveFilter()
- {
+
+ @Test
+ public void testAddTargetGetLoggerThenRemoveFilter() {
testTarget.setLevel(LogEvent.ALL);
testTarget.addFilter("foo.*");
Assert.assertTrue(testTarget.getFilters().size() == 1);
@@ -119,60 +96,60 @@ public class LogTest extends TestCase
testTarget.removeFilter("foo.*");
Assert.assertTrue(testTarget.loggerCount == 0);
}
-
- public void testGetLoggerAddTarget()
- {
+
+ @Test
+ public void testGetLoggerAddTarget() {
// First, remove the default "*" filter.
testTarget.removeFilter("*");
-
+
Log.getLogger("foo");
Log.getLogger("bar");
Log.getLogger("baz"); // Shouldn't be added to the target later.
-
+
testTarget.setLevel(LogEvent.ALL);
- Log.addTarget(testTarget);
+ Log.addTarget(testTarget);
Assert.assertTrue(testTarget.loggerCount == 0);
-
+
// Now add filters.
List<String> filters = new ArrayList<String>();
filters.add("foo");
- filters.add("bar");
- testTarget.setFilters(filters);
+ filters.add("bar");
+ testTarget.setFilters(filters);
Assert.assertTrue(testTarget.loggerCount == 2);
}
-
- public void testLogAddFilterNull()
- {
+
+ @Test
+ public void testLogAddFilterNull() {
// First, remove the default "*" filter.
testTarget.removeFilter("*");
-
+
Log.getLogger("foo");
-
+
testTarget.setLevel(LogEvent.ALL);
- Log.addTarget(testTarget);
+ Log.addTarget(testTarget);
Assert.assertTrue(testTarget.loggerCount == 0);
-
+
// Now null filters.
- List filters = new ArrayList();
- testTarget.addFilter(null);
- testTarget.setFilters(filters);
+ List filters = new ArrayList();
+ testTarget.addFilter(null);
+ testTarget.setFilters(filters);
Assert.assertTrue(testTarget.loggerCount == 1);
}
-
- public void testLogSetFilterNull()
- {
+
+ @Test
+ public void testLogSetFilterNull() {
// First, remove the default "*" filter.
testTarget.removeFilter("*");
-
+
Log.getLogger("foo");
-
+
testTarget.setLevel(LogEvent.ALL);
- Log.addTarget(testTarget);
+ Log.addTarget(testTarget);
Assert.assertTrue(testTarget.loggerCount == 0);
-
+
// Now null filters.
- List filters = new ArrayList();
- testTarget.setFilters(filters);
+ List filters = new ArrayList();
+ testTarget.setFilters(filters);
Assert.assertTrue(testTarget.loggerCount == 1);
}
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/log/LoggerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/log/LoggerTest.java b/core/src/test/java/flex/messaging/log/LoggerTest.java
index 107db69..f0fb632 100644
--- a/core/src/test/java/flex/messaging/log/LoggerTest.java
+++ b/core/src/test/java/flex/messaging/log/LoggerTest.java
@@ -17,83 +17,65 @@
package flex.messaging.log;
-import junit.framework.TestCase;
-import junit.framework.Test;
-import junit.framework.TestSuite;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class LoggerTest extends TestCase
-{
- private TestingTarget target;
- private TestingTarget target2;
-
- public LoggerTest(String name)
- {
- super(name);
- }
+public class LoggerTest {
- public static Test suite()
- {
- return new TestSuite(LoggerTest.class);
- }
+ private TestingTarget target;
- protected void setUp() throws Exception
- {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
Log.createLog();
- target = new TestingTarget();
+ target = new TestingTarget();
target.setLevel(LogEvent.ALL);
target.addFilter("*");
Log.addTarget(target);
}
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void testLogDebug()
- {
+ @Test
+ public void testLogDebug() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
lg1.debug("testing");
Assert.assertEquals(LogEvent.DEBUG, target.lastEvent.level);
Assert.assertEquals("testing", target.lastEvent.message);
}
- public void testLogInfo()
- {
+ @Test
+ public void testLogInfo() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
lg1.info("testing");
Assert.assertEquals(LogEvent.INFO, target.lastEvent.level);
Assert.assertEquals("testing", target.lastEvent.message);
}
- public void testLogWarning()
- {
+ @Test
+ public void testLogWarning() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
lg1.warn("testing");
Assert.assertEquals(LogEvent.WARN, target.lastEvent.level);
Assert.assertEquals("testing", target.lastEvent.message);
}
- public void testLogError()
- {
+ @Test
+ public void testLogError() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
lg1.error("testing");
Assert.assertEquals(LogEvent.ERROR, target.lastEvent.level);
Assert.assertEquals("testing", target.lastEvent.message);
}
- public void testLogFatal()
- {
+ @Test
+ public void testLogFatal() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
lg1.fatal("testing");
Assert.assertEquals(LogEvent.FATAL, target.lastEvent.level);
Assert.assertEquals("testing", target.lastEvent.message);
}
- public void testTargetLevelDebug()
- {
+ @Test
+ public void testTargetLevelDebug() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
target.level = LogEvent.DEBUG;
lg1.error("testing");
@@ -102,57 +84,57 @@ public class LoggerTest extends TestCase
Assert.assertEquals("testing", target.lastEvent.message);
}
- public void testTargetLevelInfo()
- {
+ @Test
+ public void testTargetLevelInfo() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
target.level = LogEvent.INFO;
lg1.debug("testing");
Assert.assertNull(target.lastEvent);
}
- public void testTargetLevelFatal()
- {
+ @Test
+ public void testTargetLevelFatal() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
target.level = LogEvent.FATAL;
lg1.info("testing");
Assert.assertNull(target.lastEvent);
lg1.fatal("fatal");
- assertNotNull(target.lastEvent);
- assertEquals(LogEvent.FATAL, target.lastEvent.level);
- assertEquals("fatal", target.lastEvent.message);
+ Assert.assertNotNull(target.lastEvent);
+ Assert.assertEquals(LogEvent.FATAL, target.lastEvent.level);
+ Assert.assertEquals("fatal", target.lastEvent.message);
}
- public void testTargetLevelWarn()
- {
+ @Test
+ public void testTargetLevelWarn() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
target.level = LogEvent.WARN;
lg1.error("testing");
Assert.assertNotNull(target.lastEvent);
- assertEquals(LogEvent.ERROR, target.lastEvent.level);
- assertEquals("testing", target.lastEvent.message);
+ Assert.assertEquals(LogEvent.ERROR, target.lastEvent.level);
+ Assert.assertEquals("testing", target.lastEvent.message);
lg1.warn("warn");
Assert.assertNotNull(target.lastEvent);
- assertEquals(LogEvent.WARN, target.lastEvent.level);
- assertEquals("warn", target.lastEvent.message);
+ Assert.assertEquals(LogEvent.WARN, target.lastEvent.level);
+ Assert.assertEquals("warn", target.lastEvent.message);
}
- public void testTargetLevelError()
- {
+ @Test
+ public void testTargetLevelError() {
Logger lg1 = Log.getLogger("mx.rpc.SOAP");
target.level = LogEvent.ERROR;
lg1.info("testing");
Assert.assertNull(target.lastEvent);
lg1.error("error");
Assert.assertNotNull(target.lastEvent);
- assertEquals(LogEvent.ERROR, target.lastEvent.level);
- assertEquals("error", target.lastEvent.message);
+ Assert.assertEquals(LogEvent.ERROR, target.lastEvent.level);
+ Assert.assertEquals("error", target.lastEvent.message);
}
- public void testGetTargetId()
- {
+ @Test
+ public void testGetTargetId() {
String tid = target.getId();
Assert.assertNotNull(tid);
- target2 = new TestingTarget();
+ TestingTarget target2 = new TestingTarget();
target2.setLevel(LogEvent.ALL);
target2.addFilter("*");
Log.addTarget(target2);
@@ -161,5 +143,4 @@ public class LoggerTest extends TestCase
Assert.assertNotSame(tid, tid2);
}
-
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/log/TestingTarget.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/log/TestingTarget.java b/core/src/test/java/flex/messaging/log/TestingTarget.java
index d21c81b..2d68679 100644
--- a/core/src/test/java/flex/messaging/log/TestingTarget.java
+++ b/core/src/test/java/flex/messaging/log/TestingTarget.java
@@ -17,27 +17,22 @@
package flex.messaging.log;
-public class TestingTarget extends AbstractTarget
-{
- public TestingTarget()
- {
+public class TestingTarget extends AbstractTarget {
+ public TestingTarget() {
super();
}
- public void addLogger(Logger logger)
- {
+ public void addLogger(Logger logger) {
super.addLogger(logger);
addLoggerCalled = true;
}
- public void removeLogger(Logger logger)
- {
+ public void removeLogger(Logger logger) {
super.removeLogger(logger);
removeLoggerCalled = true;
}
- public void logEvent(LogEvent event)
- {
+ public void logEvent(LogEvent event) {
lastEvent = event;
}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/securityadvisories/BlazeDsXmlProcessingXXEVulnerability.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/securityadvisories/BlazeDsXmlProcessingXXEVulnerability.java b/core/src/test/java/flex/messaging/securityadvisories/BlazeDsXmlProcessingXXEVulnerability.java
deleted file mode 100644
index c850f6f..0000000
--- a/core/src/test/java/flex/messaging/securityadvisories/BlazeDsXmlProcessingXXEVulnerability.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package flex.messaging.securityadvisories;
-
-import com.sun.org.apache.xml.internal.serialize.OutputFormat;
-import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
-import flex.messaging.util.XMLUtil;
-import org.junit.Assert;
-import junit.framework.TestCase;
-import org.w3c.dom.Document;
-
-import java.io.File;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-/**
- * Created by christoferdutz on 23.07.15.
- */
-
-public class BlazeDsXmlProcessingXXEVulnerability extends TestCase {
-
- public void testVulnerability() throws Exception {
- int secret = (int) (Math.random() * 1000);
-
- // Create a temp file containing a secret.
- File temp = File.createTempFile("xxe-test", ".txt");
- PrintWriter out = new PrintWriter(temp);
- out.println(Integer.toString(secret));
- out.close();
-
- String uri = temp.toURI().toASCIIString();
- String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
- "<!DOCTYPE foo [\r\n" +
- "<!ELEMENT foo ANY >\r\n" +
- "<!ENTITY xxe SYSTEM \"" + uri + "\" >]>\r\n" +
- "<foo>The Secret is: &xxe;</foo>";
-
- Document data = XMLUtil.stringToDocument(xml);
-
- OutputFormat format = new OutputFormat(data);
- StringWriter stringOut = new StringWriter();
- XMLSerializer serial = new XMLSerializer(stringOut, format);
- serial.serialize(data);
-
- Assert.assertFalse(stringOut.toString().contains("The Secret is: " + Integer.toString(secret)));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/services/AbstractServiceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/services/AbstractServiceTest.java b/core/src/test/java/flex/messaging/services/AbstractServiceTest.java
deleted file mode 100644
index 6c7025b..0000000
--- a/core/src/test/java/flex/messaging/services/AbstractServiceTest.java
+++ /dev/null
@@ -1,367 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package flex.messaging.services;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import flex.messaging.Destination;
-import flex.messaging.MessageBroker;
-import flex.messaging.MessageDestination;
-import flex.messaging.MessageException;
-import flex.messaging.config.ChannelSettings;
-import flex.messaging.config.ConfigurationConstants;
-import flex.messaging.config.ConfigurationException;
-import flex.messaging.messages.AsyncMessage;
-
-public abstract class AbstractServiceTest extends TestCase
-{
- protected AbstractService service;
- protected MessageBroker broker;
-
- public AbstractServiceTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(AbstractServiceTest.class);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- service = new MessageService();
- service.setId("message-service");
- }
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void testSetMessageBroker()
- {
- broker = new MessageBroker(false);
- service.setMessageBroker(broker);
-
- Service actual = broker.getService(service.getId());
- Assert.assertEquals(service, actual);
-
- MessageBroker actual2 = service.getMessageBroker();
- Assert.assertEquals(broker, actual2);
- }
-
- public void testSetMessageBrokerTwice()
- {
- broker = new MessageBroker(false);
- service.setMessageBroker(broker);
- service.setMessageBroker(broker);
-
- Service actual = broker.getService(service.getId());
- Assert.assertEquals(service, actual);
- }
-
- public void testSetMessageBrokerAndAddService()
- {
- broker = new MessageBroker(false);
- service.setMessageBroker(broker);
- broker.addService(service);
-
- Service actual = broker.getService(service.getId());
- Assert.assertEquals(service, actual);
- }
-
- public void testAddDefaultChannelNotStarted()
- {
- String id = "default-channel";
- service.addDefaultChannel(id);
-
- boolean contains = service.getDefaultChannels().contains(id);
- Assert.assertTrue(contains);
- }
-
- public void testAddDefaultChannelStartedBrokerKnows()
- {
- start();
- String id = "default-channel";
- Map<String, ChannelSettings> csMap = new HashMap<String, ChannelSettings>();
- csMap.put(id, null);
- broker.setChannelSettings(csMap);
- service.addDefaultChannel(id);
-
- boolean contains = service.getDefaultChannels().contains(id);
- Assert.assertTrue(contains);
- }
-
- public void testRemoveDefaultChannel()
- {
- String id = "default-channel";
- service.addDefaultChannel(id);
- service.removeDefaultChannel(id);
-
- boolean contains = service.getDefaultChannels().contains(id);
- Assert.assertFalse(contains);
-
- }
-
- public void testRemoveDefaultChannelNonexistent()
- {
- boolean actual = service.removeDefaultChannel("non-existent-id");
- Assert.assertFalse(actual);
- }
-
- public void testAddDestination()
- {
- String id = "destId";
- Destination expected = new MessageDestination();
- expected.setId(id);
- broker = new MessageBroker(false);
- broker.addService(service);
- service.addDestination(expected);
-
- Destination actual = service.getDestination(id);
- Assert.assertEquals(expected, actual);
- }
-
- public void testAddDestinationNull()
- {
- try
- {
- service.addDestination(null);
-
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
- int error = ConfigurationConstants.NULL_COMPONENT;
- Assert.assertEquals(ce.getNumber(), error);
- }
- }
-
- public void testAddDestinationNullId()
- {
- try
- {
- Destination destination = new MessageDestination();
- service.addDestination(destination);
-
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
- int error = ConfigurationConstants.NULL_COMPONENT_ID;
- Assert.assertEquals(ce.getNumber(), error);
- }
- }
-
- public void testGetDestinationFromMessage()
- {
- String id = "destId";
- Destination expected = new MessageDestination();
- expected.setId(id);
- broker = new MessageBroker(false);
- broker.addService(service);
- service.addDestination(expected);
-
- AsyncMessage msg = new AsyncMessage();
- msg.setDestination(id);
-
- Destination actual = service.getDestination(msg);
- Assert.assertEquals(expected, actual);
- }
-
- public void testGetDestinationFromMessageNonexistent()
- {
- String id = "destId";
- AsyncMessage msg = new AsyncMessage();
- msg.setDestination(id);
-
- try
- {
- service.getDestination(msg);
- }
- catch (MessageException me)
- {
- int error = 0;
- Assert.assertEquals(error, me.getNumber());
- }
- }
-
- public void testAddDestinationExists()
- {
- try
- {
- String id = "destId";
- Destination dest1 = new MessageDestination();
- dest1.setId(id);
-
- broker = new MessageBroker(false);
- broker.addService(service);
- service.addDestination(dest1);
-
- Destination dest2 = new MessageDestination();
- dest2.setId(id);
- service.addDestination(dest2);
-
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
- int error = ConfigurationConstants.DUPLICATE_DEST_ID;
- Assert.assertEquals(ce.getNumber(), error);
- }
- }
-
- public void testCreateDestination()
- {
- String id = "destId";
- broker = new MessageBroker(false);
- broker.addService(service);
- Destination expected = service.createDestination(id);
-
- Destination actual = service.getDestination(id);
- Assert.assertEquals(expected, actual);
- }
-
- public void testCreateDestinationWithExistingId()
- {
- String id = "destId";
- broker = new MessageBroker(false);
- broker.addService(service);
- service.createDestination(id);
- try
- {
- service.createDestination(id);
-
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
- int error = ConfigurationConstants.DUPLICATE_DEST_ID;
- Assert.assertEquals(ce.getNumber(), error);
- }
- }
-
- public void testRemoveDestination()
- {
- String id = "destId";
- Destination dest = new MessageDestination();
- dest.setId(id);
- broker = new MessageBroker(false);
- broker.addService(service);
- service.addDestination(dest);
- service.removeDestination(id);
- Destination actual = service.getDestination(id);
-
- Assert.assertNull(actual);
- }
-
- public void testRemoveDestinationNonexistent()
- {
- Destination actual = service.removeDestination("non-existent");
- Assert.assertNull(actual);
- }
-
- public void testRegisterAdapter()
- {
- String id = "id";
- String expected = "adapterClass";
- service.registerAdapter(id, expected);
- Map<String, String> adapters = service.getRegisteredAdapters();
-
- String actual = (String) adapters.get(id);
- Assert.assertEquals(expected, actual);
-
- }
-
- public void testRegisterAdapterExisting()
- {
- String id = "id";
- service.registerAdapter(id, "adapterClass");
- String expected = "adapterClass2";
- service.registerAdapter(id, expected);
- Map<String, String> adapters = service.getRegisteredAdapters();
-
- String actual = (String) adapters.get(id);
- Assert.assertEquals(expected, actual);
- }
-
- public void testUnregisterAdapter()
- {
- String id = "id";
- service.registerAdapter(id, "adapterClass");
- service.unregisterAdapter(id);
- Map<String, String> adapters = service.getRegisteredAdapters();
- String actual = (String) adapters.get(id);
-
- Assert.assertNull(actual);
- }
-
- public void testSetDefaultAdapterWithRegisteredAdapter()
- {
- String expected = "id";
- service.registerAdapter(expected, "adapterClass");
- service.setDefaultAdapter(expected);
-
- String actual = service.getDefaultAdapter();
- Assert.assertEquals(expected, actual);
- }
-
- public void testSetDefaultAdapterWithWrongId()
- {
- try
- {
- String id = "NonExistantId";
- service.setDefaultAdapter(id);
-
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
- int error = ConfigurationConstants.UNREGISTERED_ADAPTER;
- Assert.assertEquals(ce.getNumber(), error);
- }
- }
-
- public void testGetDefaultAdapterAfterUnregisteringAdapter()
- {
- String id = "id";
- service.registerAdapter(id, "adapterClass");
- service.setDefaultAdapter(id);
- service.unregisterAdapter(id);
- String actual = service.getDefaultAdapter();
-
- String expected = null;
- Assert.assertEquals(expected, actual);
- }
-
- private void start()
- {
- broker = new MessageBroker(false);
- service.setMessageBroker(broker);
- service.start();
- }
-}
-
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/services/ServiceAdapterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/flex/messaging/services/ServiceAdapterTest.java b/core/src/test/java/flex/messaging/services/ServiceAdapterTest.java
index 526f7c6..83f58d7 100644
--- a/core/src/test/java/flex/messaging/services/ServiceAdapterTest.java
+++ b/core/src/test/java/flex/messaging/services/ServiceAdapterTest.java
@@ -22,82 +22,59 @@ import flex.messaging.MessageDestination;
import flex.messaging.config.ConfigurationException;
import flex.messaging.services.messaging.adapters.ActionScriptAdapter;
import org.junit.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ServiceAdapterTest {
-public class ServiceAdapterTest extends TestCase
-{
protected ServiceAdapter adapter;
protected Destination destination;
-
- public ServiceAdapterTest(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(ServiceAdapterTest.class);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
adapter = new ActionScriptAdapter();
adapter.setId("as-adapter");
}
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void testSetDestination()
- {
+ @Test
+ public void testSetDestination() {
destination = new MessageDestination();
adapter.setDestination(destination);
-
+
Destination actual = adapter.getDestination();
Assert.assertEquals(destination, actual);
-
+
ServiceAdapter actual2 = destination.getAdapter();
Assert.assertEquals(adapter, actual2);
}
-
- public void testSetDestinationNull()
- {
- try
- {
+
+ @Test
+ public void testSetDestinationNull() {
+ try {
adapter.setDestination(null);
- fail("ConfigurationException expected");
- }
- catch (ConfigurationException ce)
- {
+ Assert.fail("ConfigurationException expected");
+ } catch (ConfigurationException ce) {
int error = 11116; // ManageableComponent.NULL_COMPONENT_PROPERTY;
Assert.assertEquals(ce.getNumber(), error);
}
}
-
- public void testSetDestinationWrongType()
- {
+
+ @Test
+ public void testSetDestinationWrongType() {
destination = new Destination();
-
- try
- {
+
+ try {
adapter.setDestination(destination);
-
- fail("ClassCastException expected");
+
+ Assert.fail("ClassCastException expected");
+ } catch (ClassCastException e) {
+ // Ignore this as we are expecting this.
}
- catch (ClassCastException e)
- {
- }
}
-
- public void testSetManagedParentUnmanaged()
- {
+
+ @Test
+ public void testSetManagedParentUnmanaged() {
destination = new MessageDestination();
destination.setManaged(false);
destination.setAdapter(adapter);
@@ -105,13 +82,13 @@ public class ServiceAdapterTest extends TestCase
boolean managed = adapter.isManaged();
Assert.assertFalse(managed);
-
+
}
-
- public void testSetManaged()
- {
+
+ @Test
+ public void testSetManaged() {
adapter.setManaged(true);
-
+
boolean managed = adapter.isManaged();
Assert.assertTrue(managed);
}