summaryrefslogtreecommitdiffstats
path: root/tags/java/sca/1.0-incubator-M2/kernel/api/src
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 /tags/java/sca/1.0-incubator-M2/kernel/api/src
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 'tags/java/sca/1.0-incubator-M2/kernel/api/src')
-rw-r--r--tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java135
-rw-r--r--tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java136
-rw-r--r--tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataContext.java42
-rw-r--r--tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java60
-rw-r--r--tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java40
-rw-r--r--tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java34
-rw-r--r--tags/java/sca/1.0-incubator-M2/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java118
-rw-r--r--tags/java/sca/1.0-incubator-M2/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java118
8 files changed, 683 insertions, 0 deletions
diff --git a/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java
new file mode 100644
index 0000000000..80ce0c652f
--- /dev/null
+++ b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java
@@ -0,0 +1,135 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+
+/**
+ * The root checked exception for the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class TuscanyException extends Exception {
+ private static final long serialVersionUID = -7847121698339635268L;
+ private List<String> contextStack;
+ private String identifier;
+
+ /**
+ * Override constructor from Exception.
+ *
+ * @see Exception
+ */
+ public TuscanyException() {
+ super();
+ }
+
+ /**
+ * Override constructor from Exception.
+ *
+ * @param message passed to Exception
+ * @see Exception
+ */
+ public TuscanyException(String message) {
+ super(message);
+ }
+
+ /**
+ * Override constructor from Exception.
+ *
+ * @param message passed to Exception
+ * @param cause passed to Exception
+ * @see Exception
+ */
+ public TuscanyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Override constructor from Exception.
+ *
+ * @param cause passed to Exception
+ * @see Exception
+ */
+ public TuscanyException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns a collection of names representing the context call stack where the error occured. The top of the stack
+ * is the first element in the collection.
+ *
+ * @return a collection of names representing the context call stack
+ */
+ public List<String> returnContextNames() {
+ if (contextStack == null) {
+ contextStack = new ArrayList<String>();
+ }
+ return contextStack;
+ }
+
+ /**
+ * Pushes a context name where an error occured onto the call stack.
+ *
+ * @param name the name of a context to push on the stack
+ */
+ public void addContextName(String name) {
+ if (contextStack == null) {
+ contextStack = new ArrayList<String>();
+ }
+ contextStack.add(name);
+ }
+
+ /**
+ * Returns a string representing additional error information referred to in the error message.
+ *
+ * @return additional error information
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /**
+ * Sets an additional error information referred to in the error message.
+ *
+ * @param identifier additional error information
+ */
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public String getMessage() {
+ if (identifier == null && contextStack == null) {
+ return super.getMessage();
+ }
+ StringBuilder b = new StringBuilder(256);
+ b.append(super.getMessage());
+
+ if (identifier != null) {
+ b.append(" [").append(identifier).append(']');
+ }
+ if (contextStack != null) {
+ b.append("\nContext stack trace: ");
+ for (int i = contextStack.size() - 1; i >= 0; i--) {
+ b.append('[').append(contextStack.get(i)).append(']');
+ }
+ }
+ return b.toString();
+ }
+}
diff --git a/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java
new file mode 100644
index 0000000000..ed70b8670e
--- /dev/null
+++ b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java
@@ -0,0 +1,136 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+
+/**
+ * The root unchecked exception for the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+
+public abstract class TuscanyRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = -759677431966121786L;
+ private List<String> contextStack;
+ private String identifier;
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @see RuntimeException
+ */
+ public TuscanyRuntimeException() {
+ super();
+ }
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @param message passed to RuntimeException
+ * @see RuntimeException
+ */
+ public TuscanyRuntimeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @param message passed to RuntimeException
+ * @param cause passed to RuntimeException
+ * @see RuntimeException
+ */
+ public TuscanyRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @param cause passed to RuntimeException
+ * @see RuntimeException
+ */
+ public TuscanyRuntimeException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns a collection of names representing the context call stack where the error occured. The top of the stack
+ * is the first element in the collection.
+ *
+ * @return a collection of names representing the context call stack
+ */
+ public List<String> returnContextNames() {
+ if (contextStack == null) {
+ contextStack = new ArrayList<String>();
+ }
+ return contextStack;
+ }
+
+ /**
+ * Pushes a context name where an error occured onto the call stack.
+ *
+ * @param name the name of a context to push on the stack
+ */
+ public void addContextName(String name) {
+ if (contextStack == null) {
+ contextStack = new ArrayList<String>();
+ }
+ contextStack.add(name);
+ }
+
+ /**
+ * Returns a string representing additional error information referred to in the error message.
+ *
+ * @return additional error information
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /**
+ * Sets an additional error information referred to in the error message.
+ *
+ * @param identifier additional error information
+ */
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public String getMessage() {
+ if (identifier == null && contextStack == null) {
+ return super.getMessage();
+ }
+ StringBuilder b = new StringBuilder(256);
+ b.append(super.getMessage());
+
+ if (identifier != null) {
+ b.append(" [").append(identifier).append(']');
+ }
+ if (contextStack != null) {
+ b.append("\nContext stack trace: ");
+ for (int i = contextStack.size() - 1; i >= 0; i--) {
+ b.append('[').append(contextStack.get(i)).append(']');
+ }
+ }
+ return b.toString();
+ }
+}
diff --git a/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataContext.java b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataContext.java
new file mode 100644
index 0000000000..ab74ba9e5c
--- /dev/null
+++ b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataContext.java
@@ -0,0 +1,42 @@
+/*
+ * 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.annotation;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * A key/value pair to represent information pertaining to a {@link DataType}
+ */
+@Target(ANNOTATION_TYPE)
+@Retention(RUNTIME)
+public @interface DataContext {
+ /**
+ * @return key for the context entry
+ */
+ String key();
+
+ /**
+ * @return key for the context value
+ */
+ String value();
+
+}
diff --git a/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java
new file mode 100644
index 0000000000..439aa837d2
--- /dev/null
+++ b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java
@@ -0,0 +1,60 @@
+/*
+ * 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.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Used to demarcate expected data types for an operation
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+public @interface DataType {
+
+ /**
+ * Returns the unique name of the data binding
+ * @return the unique name of the data binding
+ */
+ String name();
+
+ /**
+ * Returns the logical data type
+ * @return the logical data type
+ */
+ Class logicalType() default Object.class;
+
+ /**
+ * Returns the physical data type
+ * @return the physical data type
+ */
+ Class physicalType() default Object.class;
+
+ /**
+ * Returns an array of extensibility elements
+ * @return an array of extensibility elements
+ */
+ DataContext[] context() default {};
+
+}
diff --git a/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java
new file mode 100644
index 0000000000..83c5df26d9
--- /dev/null
+++ b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java
@@ -0,0 +1,40 @@
+/*
+ * 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.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that can be applied to methods in a monitoring interface to indicate to logging frameworks the severity of
+ * the event.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({METHOD})
+@Retention(RUNTIME)
+public @interface LogLevel {
+
+ /**
+ * The log level as specified by {@link java.util.logging.Level}.
+ */
+ @SuppressWarnings({"JavaDoc"}) String value();
+}
diff --git a/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java
new file mode 100644
index 0000000000..dea9489e5b
--- /dev/null
+++ b/tags/java/sca/1.0-incubator-M2/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java
@@ -0,0 +1,34 @@
+/*
+ * 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.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A system annotation to inject a monitor
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Monitor {
+}
diff --git a/tags/java/sca/1.0-incubator-M2/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java b/tags/java/sca/1.0-incubator-M2/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java
new file mode 100644
index 0000000000..304706142c
--- /dev/null
+++ b/tags/java/sca/1.0-incubator-M2/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.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 MESSAGE = "Message";
+ private static final String IDENTIFIER = "IDENTIFIER";
+ 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);
+ assertSame(MESSAGE, ex.getMessage());
+ assertNull(ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testThrowableConstructor() {
+ TuscanyException 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() {
+ TuscanyException ex = new DummyException(MESSAGE, CAUSE);
+ assertSame(MESSAGE, ex.getMessage());
+ assertSame(CAUSE, ex.getCause());
+ assertNull(ex.getIdentifier());
+ assertTrue(ex.returnContextNames().isEmpty());
+ }
+
+ public void testIdentifier() {
+ TuscanyException ex = new DummyException(MESSAGE);
+ ex.setIdentifier(IDENTIFIER);
+ assertSame(IDENTIFIER, ex.getIdentifier());
+ assertEquals(MESSAGE + " [" + IDENTIFIER + ']', ex.getMessage());
+ }
+
+ 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 testContextMessageWithNoIdentifier() {
+ TuscanyException ex = new DummyException(MESSAGE);
+ ex.addContextName(CONTEXT1);
+ ex.addContextName(CONTEXT2);
+ assertEquals("Message\nContext stack trace: [CONTEXT2][CONTEXT1]", ex.getMessage());
+ }
+
+
+ public void testContextMessageWithIdentifier() {
+ TuscanyException ex = new DummyException(MESSAGE);
+ ex.setIdentifier(IDENTIFIER);
+ ex.addContextName(CONTEXT1);
+ ex.addContextName(CONTEXT2);
+ assertEquals("Message [IDENTIFIER]\nContext stack trace: [CONTEXT2][CONTEXT1]", ex.getMessage());
+ }
+
+ public static class DummyException extends TuscanyException {
+ public DummyException() {
+ }
+
+ public DummyException(String message) {
+ super(message);
+ }
+
+ public DummyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public DummyException(Throwable cause) {
+ super(cause);
+ }
+ }
+}
diff --git a/tags/java/sca/1.0-incubator-M2/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java b/tags/java/sca/1.0-incubator-M2/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java
new file mode 100644
index 0000000000..85cc1e752a
--- /dev/null
+++ b/tags/java/sca/1.0-incubator-M2/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.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);
+ ex.setIdentifier(IDENTIFIER);
+ assertSame(IDENTIFIER, ex.getIdentifier());
+ assertEquals(MESSAGE + " [" + IDENTIFIER + ']', ex.getMessage());
+ }
+
+ 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 testContextMessageWithNoIdentifier() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE);
+ ex.addContextName(CONTEXT1);
+ ex.addContextName(CONTEXT2);
+ assertEquals("Message\nContext stack trace: [CONTEXT2][CONTEXT1]", ex.getMessage());
+ }
+
+
+ public void testContextMessageWithIdentifier() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE);
+ ex.setIdentifier(IDENTIFIER);
+ ex.addContextName(CONTEXT1);
+ ex.addContextName(CONTEXT2);
+ assertEquals("Message [IDENTIFIER]\nContext stack trace: [CONTEXT2][CONTEXT1]", ex.getMessage());
+ }
+
+ public static class DummyException extends TuscanyRuntimeException {
+ public DummyException() {
+ }
+
+ public DummyException(String message) {
+ super(message);
+ }
+
+ public DummyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public DummyException(Throwable cause) {
+ super(cause);
+ }
+ }
+}