You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2019/02/22 15:17:59 UTC

[tomee] branch master updated: Testing exceptions

This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/master by this push:
     new 8d65fee  Testing exceptions
8d65fee is described below

commit 8d65fee1bd5a28207b432c125e2f793a1da7f229
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Fri Feb 22 15:17:43 2019 +0000

    Testing exceptions
---
 .../java/org/superbiz/remote/BusinessException.java   | 19 +++++++++++++++++++
 .../src/main/java/org/superbiz/remote/Calculator.java |  1 +
 .../java/org/superbiz/remote/DefaultCalculator.java   | 18 ++++++++++++++++++
 .../src/test/java/org/superbiz/remote/App.java        | 16 +++++++++++++++-
 4 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/examples/ejb-remote-call/src/main/java/org/superbiz/remote/BusinessException.java b/examples/ejb-remote-call/src/main/java/org/superbiz/remote/BusinessException.java
new file mode 100644
index 0000000..8644cc1
--- /dev/null
+++ b/examples/ejb-remote-call/src/main/java/org/superbiz/remote/BusinessException.java
@@ -0,0 +1,19 @@
+package org.superbiz.remote;
+
+public class BusinessException extends Exception {
+
+    public BusinessException() {
+    }
+
+    public BusinessException(String message) {
+        super(message);
+    }
+
+    public BusinessException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public BusinessException(Throwable cause) {
+        super(cause);
+    }
+}
diff --git a/examples/ejb-remote-call/src/main/java/org/superbiz/remote/Calculator.java b/examples/ejb-remote-call/src/main/java/org/superbiz/remote/Calculator.java
index c42487f..c238b9b 100644
--- a/examples/ejb-remote-call/src/main/java/org/superbiz/remote/Calculator.java
+++ b/examples/ejb-remote-call/src/main/java/org/superbiz/remote/Calculator.java
@@ -22,5 +22,6 @@ public interface Calculator   {
 
     int multiply(int mul1, int mul2);
 
+    String echo(String input) throws BusinessException;
 }
 
diff --git a/examples/ejb-remote-call/src/main/java/org/superbiz/remote/DefaultCalculator.java b/examples/ejb-remote-call/src/main/java/org/superbiz/remote/DefaultCalculator.java
index 8021a2b..a030188 100644
--- a/examples/ejb-remote-call/src/main/java/org/superbiz/remote/DefaultCalculator.java
+++ b/examples/ejb-remote-call/src/main/java/org/superbiz/remote/DefaultCalculator.java
@@ -32,5 +32,23 @@ public class DefaultCalculator implements Calculator {
         return mul1 * mul2;
     }
 
+    @Override
+    public String echo(final String input) throws BusinessException {
+        if ("CHECKED".equals(input)) {
+            throw new BusinessException("This is a checked exception");
+        }
+
+        if ("RUNTIME".equals(input)) {
+            throw new RuntimeException("This is a runtime exception");
+        }
+
+        if (input == null) {
+            return "Input was null";
+        }
+
+        return "Input was: " + input;
+    }
+
+
 
 }
diff --git a/examples/ejb-remote-call/src/test/java/org/superbiz/remote/App.java b/examples/ejb-remote-call/src/test/java/org/superbiz/remote/App.java
index 4ee483d..b60ce0f 100644
--- a/examples/ejb-remote-call/src/test/java/org/superbiz/remote/App.java
+++ b/examples/ejb-remote-call/src/test/java/org/superbiz/remote/App.java
@@ -23,7 +23,7 @@ import java.util.Properties;
 
 public class App {
 
-    public static void main(String[] args) throws NamingException {
+    public static void main(String[] args) throws NamingException, BusinessException {
         Properties properties = new Properties();
         properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
         properties.put(Context.PROVIDER_URL, "http://localhost:8080/tomee/ejb");
@@ -34,6 +34,20 @@ public class App {
         Calculator calculator = Calculator.class.cast(ref);
         System.out.println(calculator.sum(1, 2));
 
+        System.out.println("Expecting Hello world: " + calculator.echo("Hello world"));
+        try {
+            System.out.println("Expecting checked exception: ");
+            System.out.println(calculator.echo("CHECKED"));
+        } catch (BusinessException e) {
+            e.printStackTrace();
+        }
+
+        try {
+            System.out.println("Expecting runtime exception: ");
+            System.out.println(calculator.echo("RUNTIME"));
+        } catch (RuntimeException e) {
+            e.printStackTrace();
+        }
 
     }
 }