summaryrefslogtreecommitdiffstats
path: root/branches/pre-spec-changes/kernel/api/src/test
diff options
context:
space:
mode:
authordims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
committerdims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
commitbdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch)
tree38a92061c0793434c4be189f1d70c3458b6bc41d /branches/pre-spec-changes/kernel/api/src/test
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/pre-spec-changes/kernel/api/src/test')
-rw-r--r--branches/pre-spec-changes/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java164
-rw-r--r--branches/pre-spec-changes/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java142
2 files changed, 306 insertions, 0 deletions
diff --git a/branches/pre-spec-changes/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java b/branches/pre-spec-changes/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java
new file mode 100644
index 0000000000..9f0674238f
--- /dev/null
+++ b/branches/pre-spec-changes/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.tuscany.api;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyExceptionTestCase extends TestCase {
+ private static final Throwable CAUSE = new Throwable("Cause");
+ private static final String IDENTIFIER = "IDENTIFIER";
+ private static final String MESSAGE = "Message";
+ private static final String CONTEXT1 = "CONTEXT1";
+ private static final String CONTEXT2 = "CONTEXT2";
+
+ public void testNoArgConstructor() {
+ TuscanyException ex = new DummyException();
+ assertNull(ex.getMessage());
+ assertNull(ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testMessageConstructor() {
+ TuscanyException ex = new DummyException(MESSAGE);
+ assertEquals(MESSAGE, ex.getMessage());
+ assertNull(ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testAppendBaseMessage() {
+ TuscanyException ex = new DummyException(MESSAGE, IDENTIFIER);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendBaseMessage(pw);
+ assertEquals("Message [IDENTIFIER]", writer.toString());
+ }
+
+ public void testAppendBaseMessageNoIdentifier() {
+ TuscanyException ex = new DummyException(MESSAGE);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendBaseMessage(pw);
+ assertEquals("Message", writer.toString());
+ }
+
+ public void testThrowableConstructor() {
+ TuscanyException ex = new DummyException(CAUSE);
+ assertEquals(CAUSE.getClass().getName() + ": " + CAUSE.getMessage(), ex.getMessage());
+ assertEquals(CAUSE, ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testMessageThrowableConstructor() {
+ TuscanyException ex = new DummyException(MESSAGE, CAUSE);
+ assertEquals(MESSAGE, ex.getMessage());
+ assertEquals(CAUSE, ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testContextStack() {
+ TuscanyException ex = new DummyException(MESSAGE);
+ List<String> contexts = new ArrayList<String>();
+ contexts.add(CONTEXT1);
+ ex.addContextName(CONTEXT1);
+ assertEquals(contexts, ex.returnContextNames());
+ contexts.add(CONTEXT2);
+ ex.addContextName(CONTEXT2);
+ assertEquals(contexts, ex.returnContextNames());
+ }
+
+ public void testAppendContextMessage() {
+ TuscanyException ex = new DummyException(MESSAGE);
+ ex.addContextName(CONTEXT1);
+ ex.addContextName(CONTEXT2);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendContextStack(pw);
+ assertEquals("\nContext stack trace: [CONTEXT2][CONTEXT1]", writer.toString());
+ }
+
+ public void testAddContext() throws Exception {
+ TuscanyException e = new DummyException();
+ e.addContextName("foo");
+ e.addContextName("bar");
+ assertEquals("foo", e.returnContextNames().get(0));
+ assertEquals("bar", e.returnContextNames().get(1));
+ }
+
+ public void testEmptyContext() throws Exception {
+ TuscanyException e = new DummyException();
+ assertEquals(0, e.returnContextNames().size());
+ }
+
+ public void testGetMessage() throws Exception {
+ TuscanyException e = new DummyException();
+ e.getMessage();
+ }
+
+ public void testFullMessage() throws Exception {
+ TuscanyException e = new DummyException("message", "foo");
+ e.addContextName("foo");
+ e.getMessage();
+ }
+
+ public void testImmutableContextNames() {
+ TuscanyException e = new DummyException("message", "foo");
+ try {
+ e.returnContextNames().add("foo");
+ fail();
+ } catch (UnsupportedOperationException e1) {
+ // expected
+ }
+ }
+
+
+ public static class DummyException extends TuscanyException {
+
+ public DummyException() {
+ }
+
+ public DummyException(String message) {
+ super(message);
+ }
+
+
+ public DummyException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public DummyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public DummyException(Throwable cause) {
+ super(cause);
+ }
+ }
+}
diff --git a/branches/pre-spec-changes/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java b/branches/pre-spec-changes/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java
new file mode 100644
index 0000000000..4addd5ab38
--- /dev/null
+++ b/branches/pre-spec-changes/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java
@@ -0,0 +1,142 @@
+/*
+ * 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 org.apache.tuscany.api;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyRuntimeExceptionTestCase extends TestCase {
+ private static final Throwable CAUSE = new Throwable("Cause");
+ private static final String MESSAGE = "Message";
+ private static final String IDENTIFIER = "IDENTIFIER";
+ private static final String CONTEXT1 = "CONTEXT1";
+ private static final String CONTEXT2 = "CONTEXT2";
+
+ public void testNoArgConstructor() {
+ TuscanyRuntimeException ex = new DummyException();
+ assertNull(ex.getMessage());
+ assertNull(ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testMessageConstructor() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE);
+ assertSame(MESSAGE, ex.getMessage());
+ assertNull(ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testThrowableConstructor() {
+ TuscanyRuntimeException ex = new DummyException(CAUSE);
+ assertEquals(CAUSE.getClass().getName() + ": " + CAUSE.getMessage(), ex.getMessage());
+ assertSame(CAUSE, ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testMessageThrowableConstructor() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE, CAUSE);
+ assertSame(MESSAGE, ex.getMessage());
+ assertSame(CAUSE, ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testIdentifier() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE, IDENTIFIER);
+ assertEquals(IDENTIFIER, ex.getIdentifier());
+ }
+
+ public void testContextStack() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE);
+ List<String> contexts = new ArrayList<String>();
+ contexts.add(CONTEXT1);
+ ex.addContextName(CONTEXT1);
+ assertEquals(contexts, ex.returnContextNames());
+ contexts.add(CONTEXT2);
+ ex.addContextName(CONTEXT2);
+ assertEquals(contexts, ex.returnContextNames());
+ }
+
+ public void testAppendContextMessage() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE);
+ ex.addContextName(CONTEXT1);
+ ex.addContextName(CONTEXT2);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendContextStack(pw);
+ assertEquals("Context stack trace: [CONTEXT2][CONTEXT1]", writer.toString());
+ }
+
+ public void testAppendBaseMessage() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE, IDENTIFIER);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendBaseMessage(pw);
+ assertEquals("Message [IDENTIFIER]", writer.toString());
+ }
+
+ public void testAppendBaseMessageNoIdentifier() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendBaseMessage(pw);
+ assertEquals("Message", writer.toString());
+ }
+
+ public void testImmutableContextNames() {
+ TuscanyRuntimeException e = new DummyException("message", "foo");
+ try {
+ e.returnContextNames().add("foo");
+ fail();
+ } catch (UnsupportedOperationException e1) {
+ // expected
+ }
+ }
+
+ public static class DummyException extends TuscanyRuntimeException {
+ public DummyException() {
+ }
+
+ public DummyException(String message) {
+ super(message);
+ }
+
+ public DummyException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public DummyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public DummyException(Throwable cause) {
+ super(cause);
+ }
+ }
+}