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:54 UTC
[2/3] flex-blazeds git commit: - Converted the testsuite to JUnit 4
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);
}