Improve Exception Handling in Library 17/8217/4
authorDave Tucker <djt@redhat.com>
Sat, 21 Jun 2014 23:48:55 +0000 (00:48 +0100)
committerDave Tucker <djt@redhat.com>
Fri, 27 Jun 2014 17:07:55 +0000 (18:07 +0100)
- Create new exception types that support exception wrapping
- Move exceptions to a "error" package
- Fix bug in version check logic

Change-Id: I067f746aaeb828215130ff01297b1af564e06e9f
Signed-off-by: Dave Tucker <djt@redhat.com>
20 files changed:
library/src/main/java/org/opendaylight/ovsdb/lib/error/BadSchemaException.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/error/ColumnSchemaNotFoundException.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/error/InvalidEncodingException.java [moved from library/src/main/java/org/opendaylight/ovsdb/lib/jsonrpc/InvalidEncodingException.java with 83% similarity]
library/src/main/java/org/opendaylight/ovsdb/lib/error/ParsingException.java [moved from library/src/main/java/org/opendaylight/ovsdb/lib/ParsingException.java with 87% similarity]
library/src/main/java/org/opendaylight/ovsdb/lib/error/SchemaVersionMismatchException.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/error/TableSchemaNotFoundException.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/error/TyperException.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/error/UnexpectedResultException.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/error/UnsupportedArgumentException.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/error/UnsupportedMethodException.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/jsonrpc/ExceptionHandler.java
library/src/main/java/org/opendaylight/ovsdb/lib/jsonrpc/JsonRpcDecoder.java
library/src/main/java/org/opendaylight/ovsdb/lib/jsonrpc/JsonRpcEndpoint.java
library/src/main/java/org/opendaylight/ovsdb/lib/schema/BaseType.java
library/src/main/java/org/opendaylight/ovsdb/lib/schema/ColumnSchema.java
library/src/main/java/org/opendaylight/ovsdb/lib/schema/ColumnType.java
library/src/main/java/org/opendaylight/ovsdb/lib/schema/DatabaseSchema.java
library/src/main/java/org/opendaylight/ovsdb/lib/schema/GenericTableSchema.java
library/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java
schemas/Open_vSwitch/src/test/java/org/opendaylight/ovsdb/schema/openvswitch/IpfixTestCases.java

diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/error/BadSchemaException.java b/library/src/main/java/org/opendaylight/ovsdb/lib/error/BadSchemaException.java
new file mode 100644 (file)
index 0000000..7c420b3
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * BadSchema exception is thrown when the received schema is invalid
+ */
+public class BadSchemaException extends RuntimeException {
+    public BadSchemaException(String message){
+        super(message);
+    }
+
+    public BadSchemaException(String message, Throwable cause){
+        super(message, cause);
+    }
+
+}
diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/error/ColumnSchemaNotFoundException.java b/library/src/main/java/org/opendaylight/ovsdb/lib/error/ColumnSchemaNotFoundException.java
new file mode 100644 (file)
index 0000000..55169af
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * This exception is thrown when a ColumnSchema cannot be found
+ */
+public class ColumnSchemaNotFoundException extends RuntimeException {
+
+    public ColumnSchemaNotFoundException(String message){
+        super(message);
+    }
+
+    public ColumnSchemaNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public static String createMessage(String columnName, String tableName){
+        String message = "Unable to locate ColumnSchema for "+  columnName + " in "+ tableName;
+        return message;
+    }
+
+}
similarity index 83%
rename from library/src/main/java/org/opendaylight/ovsdb/lib/jsonrpc/InvalidEncodingException.java
rename to library/src/main/java/org/opendaylight/ovsdb/lib/error/InvalidEncodingException.java
index 26e0146f26d0fd890efa55c05ea0f67b147fd014..0709f67f551e33d70b941b093ed52275675cde3d 100644 (file)
@@ -7,8 +7,11 @@
  *
  * Authors : Ashwin Raveendran, Madhu Venugopal
  */
-package org.opendaylight.ovsdb.lib.jsonrpc;
+package org.opendaylight.ovsdb.lib.error;
 
+/**
+ * InvalidEncodingException in cases where something is not UTF-8 Encoded.
+ */
 public class InvalidEncodingException extends RuntimeException {
 
     private final String actual;
similarity index 87%
rename from library/src/main/java/org/opendaylight/ovsdb/lib/ParsingException.java
rename to library/src/main/java/org/opendaylight/ovsdb/lib/error/ParsingException.java
index bc7ec40d73c980cab1d4b965c685f653fc555752..7b59a077b9990ce129c1b746569ff80fb87eab20 100644 (file)
  *
  */
 
-package org.opendaylight.ovsdb.lib;
+package org.opendaylight.ovsdb.lib.error;
 
+/**
+ * The ParsingException is thrown when JSON could not be successfully parsed
+ */
 public class ParsingException extends RuntimeException {
 
     public ParsingException() {
diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/error/SchemaVersionMismatchException.java b/library/src/main/java/org/opendaylight/ovsdb/lib/error/SchemaVersionMismatchException.java
new file mode 100644 (file)
index 0000000..8dceb13
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+import org.opendaylight.ovsdb.lib.notation.Version;
+
+/**
+ * This exception is used when the a table or row is accessed though a typed interface
+ * and the version requirements are not met
+ */
+public class SchemaVersionMismatchException extends RuntimeException {
+
+    public SchemaVersionMismatchException(String message) {
+        super(message);
+    }
+
+    public SchemaVersionMismatchException(String message, Throwable cause){
+        super(message, cause);
+    }
+
+    public static String createMessage(Version currentVersion, Version requiredVersion) {
+        String message = "The schema version used to access this Table/Column does not match the required version.\n" +
+                "Current Version: " + currentVersion.toString() + "\n";
+
+        if (currentVersion.compareTo(requiredVersion) > 1) {
+            message += "Removed in Version: " + requiredVersion.toString();
+
+        } else {
+            message += "Added in Version: " + requiredVersion.toString();
+
+        }
+
+        return message;
+    }
+}
diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/error/TableSchemaNotFoundException.java b/library/src/main/java/org/opendaylight/ovsdb/lib/error/TableSchemaNotFoundException.java
new file mode 100644 (file)
index 0000000..f4fab96
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * This exception is thrown when a TableSchema cannot be found
+ */
+public class TableSchemaNotFoundException extends RuntimeException {
+
+    public TableSchemaNotFoundException(String message){
+        super(message);
+    }
+
+    public TableSchemaNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public static String createMessage(String tableName, String schemaName){
+        String message = "Unable to locate TableSchema for "+  tableName + " in "+ schemaName;
+        return message;
+    }
+
+}
diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/error/TyperException.java b/library/src/main/java/org/opendaylight/ovsdb/lib/error/TyperException.java
new file mode 100644 (file)
index 0000000..3b26cfd
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * This is a generic exception thrown by the Typed Schema utilities
+ */
+public class TyperException extends RuntimeException {
+
+    public TyperException(String message){
+        super(message);
+    }
+
+    public TyperException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}
diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/error/UnexpectedResultException.java b/library/src/main/java/org/opendaylight/ovsdb/lib/error/UnexpectedResultException.java
new file mode 100644 (file)
index 0000000..bbe4be1
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * This exception is thrown when a result does not meet any of the known formats in RFC7047
+ */
+public class UnexpectedResultException extends RuntimeException {
+    public UnexpectedResultException(String message){
+        super(message);
+    }
+
+    public UnexpectedResultException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}
diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/error/UnsupportedArgumentException.java b/library/src/main/java/org/opendaylight/ovsdb/lib/error/UnsupportedArgumentException.java
new file mode 100644 (file)
index 0000000..7244654
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+public class UnsupportedArgumentException extends RuntimeException {
+
+    public UnsupportedArgumentException(String message){
+        super(message);
+    }
+
+   public UnsupportedArgumentException(String message, Throwable cause){
+       super(message, cause);
+   }
+}
diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/error/UnsupportedMethodException.java b/library/src/main/java/org/opendaylight/ovsdb/lib/error/UnsupportedMethodException.java
new file mode 100644 (file)
index 0000000..0564dca
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+public class UnsupportedMethodException extends RuntimeException {
+
+    public UnsupportedMethodException(String message) {
+        super(message);
+    }
+    public UnsupportedMethodException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}
index b0f6d24d959c628e609afd129b08934f9a2c2bdc..9dad2f2f834d94ffbced288779ea8b86e68a5196 100644 (file)
@@ -12,6 +12,7 @@ package org.opendaylight.ovsdb.lib.jsonrpc;
 import io.netty.channel.ChannelHandlerAdapter;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.TooLongFrameException;
+import org.opendaylight.ovsdb.lib.error.InvalidEncodingException;
 
 public class ExceptionHandler extends ChannelHandlerAdapter {
 
index 0c909367f38061721e30039c27b3ddc255d4712f..a02b6824647718f061290e003dedc486913c0918 100644 (file)
@@ -19,6 +19,7 @@ import io.netty.handler.codec.TooLongFrameException;
 import java.io.IOException;
 import java.util.List;
 
+import org.opendaylight.ovsdb.lib.error.InvalidEncodingException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index ce254f5afd41f8cb855744f0d9c9350e163f2222..89584bd8bcc6d27b122c428ab0c8dfcf31b78372 100644 (file)
@@ -18,6 +18,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
+import org.opendaylight.ovsdb.lib.error.UnexpectedResultException;
+import org.opendaylight.ovsdb.lib.error.UnsupportedArgumentException;
 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -97,7 +99,7 @@ public class JsonRpcEndpoint {
                         }
 
                         if (params == null) {
-                            throw new RuntimeException("do not understand this argument yet");
+                            throw new UnsupportedArgumentException("do not understand this argument yet");
                         }
                         request.setParams(params);
                     }
@@ -139,7 +141,7 @@ public class JsonRpcEndpoint {
             returnCtxt.getFuture().set(result1);
 
         } else {
-            throw new RuntimeException("donno how to deal with this");
+            throw new UnexpectedResultException("Don't know how to handle this");
         }
     }
 
index 52c2f1a26812c155a5c78a6d5849436ce879a6f3..2addab460dc4c188e03f10ab35e815fd9c5edfad 100644 (file)
@@ -11,10 +11,10 @@ package org.opendaylight.ovsdb.lib.schema;
 
 import java.util.Set;
 
-import org.opendaylight.ovsdb.lib.notation.UUID;
-
 import com.fasterxml.jackson.databind.JsonNode;
 import com.google.common.collect.Sets;
+import org.opendaylight.ovsdb.lib.error.TyperException;
+import org.opendaylight.ovsdb.lib.notation.UUID;
 
 public abstract class BaseType<E extends BaseType<E>> {
 
@@ -38,7 +38,7 @@ public abstract class BaseType<E extends BaseType<E>> {
             }
         } else {
             if (!json.has(keyorval)) {
-                throw new RuntimeException("Not a type");
+                throw new TyperException("Not a type");
             }
 
             for (BaseType baseTypeFactory : types) {
index 2d0f32ad12518ab8ba37f172734505d17bd76a5e..27aef09ca100f74d44e1ee33b3a37c70ae1ae064 100644 (file)
@@ -12,6 +12,7 @@ package org.opendaylight.ovsdb.lib.schema;
 import java.util.Map;
 import java.util.Set;
 
+import org.opendaylight.ovsdb.lib.error.BadSchemaException;
 import org.opendaylight.ovsdb.lib.notation.Condition;
 import org.opendaylight.ovsdb.lib.notation.Function;
 import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
@@ -33,8 +34,7 @@ public class ColumnSchema<E extends TableSchema<E>, D> {
 
     public static ColumnSchema fromJson(String name, JsonNode json) {
         if (!json.isObject() || !json.has("type")) {
-            //todo specific types of exception
-            throw new RuntimeException("bad column schema root, expected \"type\" as child");
+            throw new BadSchemaException("bad column schema root, expected \"type\" as child");
         }
 
         return new ColumnSchema(name, ColumnType.fromJson(json.get("type")));
index c9829cf85302db425fea4d36dfbb1f81fc25ba43..ee1208cf946ad67f8ac3ed8bb9c6ed5481265c1a 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.ovsdb.lib.schema;
 
 import java.util.Set;
 
+import org.opendaylight.ovsdb.lib.error.TyperException;
 import org.opendaylight.ovsdb.lib.jsonrpc.JsonUtils;
 import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
 
@@ -82,7 +83,7 @@ public abstract class ColumnType {
             }
         }
         //todo move to speicfic typed exception
-        throw new RuntimeException(String.format("could not find the right column type %s",
+        throw new TyperException(String.format("could not find the right column type %s",
                 JsonUtils.prettyString(json)));
     }
 
index 9ad7cbaaf04608d664226553cba82ac0ff00b8ff..34a5e06ed3d8b849c0013dded5c97316fa883c7c 100644 (file)
@@ -15,7 +15,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
-import org.opendaylight.ovsdb.lib.ParsingException;
+import org.opendaylight.ovsdb.lib.error.ParsingException;
 import org.opendaylight.ovsdb.lib.notation.Version;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.slf4j.Logger;
index 2b35a3e388554fa8650bb98a7009795579720a5d..d5f493df47feccbbaff36adb84bb4498d91aa87b 100644 (file)
@@ -13,6 +13,7 @@
 package org.opendaylight.ovsdb.lib.schema;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import org.opendaylight.ovsdb.lib.error.BadSchemaException;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -34,8 +35,7 @@ public class GenericTableSchema extends TableSchema<GenericTableSchema> {
     public GenericTableSchema fromJson(String tableName, JsonNode json) {
 
         if (!json.isObject() || !json.has("columns")) {
-            //todo specific types of exception
-            throw new RuntimeException("bad tableschema root, expected \"columns\" as child");
+            throw new BadSchemaException("bad tableschema root, expected \"columns\" as child");
         }
 
         Map<String, ColumnSchema> columns = new HashMap<>();
index 1b5cd5b5b1898d6d3de901ffef1105d485a8485d..2f4c1b55eb469becdf05671f69a2f48606d0d917 100644 (file)
@@ -13,6 +13,11 @@ package org.opendaylight.ovsdb.lib.schema.typed;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 
+
+import org.opendaylight.ovsdb.lib.error.ColumnSchemaNotFoundException;
+import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
+import org.opendaylight.ovsdb.lib.error.TableSchemaNotFoundException;
+import org.opendaylight.ovsdb.lib.error.TyperException;
 import org.opendaylight.ovsdb.lib.notation.Column;
 import org.opendaylight.ovsdb.lib.notation.Row;
 import org.opendaylight.ovsdb.lib.notation.Version;
@@ -124,24 +129,32 @@ public class TyperUtils {
         return false;
     }
 
-    public static Version getFromVersion (Method method) {
+    public static Version getColumnFromVersion(Method method) {
         TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
         if (typedColumn != null) {
             return Version.fromString(typedColumn.fromVersion());
         }
-        TypedTable typedTable = method.getAnnotation(TypedTable.class);
+        return Version.NULL;
+    }
+
+    public static <T> Version getTableFromVersion(final Class<T> klazz) {
+        TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
         if (typedTable != null) {
             return Version.fromString(typedTable.fromVersion());
         }
         return Version.NULL;
     }
 
-    public static Version getUntilVersion(Method method) {
+    public static Version getColumnUntilVersion(Method method) {
         TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
         if (typedColumn != null) {
             return Version.fromString(typedColumn.untilVersion());
         }
-        TypedTable typedTable = method.getAnnotation(TypedTable.class);
+        return Version.NULL;
+    }
+
+    public static <T> Version getTableUntilVersion(final Class<T> klazz) {
+        TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
         if (typedTable != null) {
             return Version.fromString(typedTable.untilVersion());
         }
@@ -169,25 +182,36 @@ public class TyperUtils {
             }
         }
 
-        if (!dbSchema.getTables().contains(getTableName(klazz))) {
-            return false;
-        }
+        checkTableSchemaVersion(dbSchema, klazz);
+
         return true;
     }
 
-    private static void checkSchemaVersion(DatabaseSchema dbSchema, Method method) {
-        Version fromVersion = getFromVersion(method);
-        Version untilVersion = getUntilVersion(method);
+    private static void checkColumnSchemaVersion(DatabaseSchema dbSchema, Method method) {
+        Version fromVersion = getColumnFromVersion(method);
+        Version untilVersion = getColumnUntilVersion(method);
+        Version schemaVersion = dbSchema.getVersion();
+        checkVersion(schemaVersion, fromVersion, untilVersion);
+    }
+
+    private static <T> void checkTableSchemaVersion(DatabaseSchema dbSchema, Class<T> klazz) {
+        Version fromVersion = getTableFromVersion(klazz);
+        Version untilVersion = getTableUntilVersion(klazz);
+        Version schemaVersion = dbSchema.getVersion();
+        checkVersion(schemaVersion, fromVersion, untilVersion);
+    }
+
+    private static void checkVersion(Version schemaVersion, Version fromVersion, Version untilVersion){
         if (!fromVersion.equals(Version.NULL)) {
-            if (dbSchema.getVersion().compareTo(fromVersion) < 0) {
-                throw new RuntimeException("This row is not supported until version "
-                        + fromVersion + "of the Schema");
+            if (schemaVersion.compareTo(fromVersion) < 0) {
+                String message = SchemaVersionMismatchException.createMessage(schemaVersion, fromVersion);
+                throw new SchemaVersionMismatchException(message);
             }
         }
         if (!untilVersion.equals(Version.NULL)) {
-            if (dbSchema.getVersion().compareTo(untilVersion) > 0) {
-                throw new RuntimeException("This row was deprecated in "
-                        + untilVersion + "of the Schema");
+            if (schemaVersion.compareTo(untilVersion) > 0) {
+                String message = SchemaVersionMismatchException.createMessage(schemaVersion, untilVersion);
+                throw new SchemaVersionMismatchException(message);
             }
         }
     }
@@ -214,17 +238,19 @@ public class TyperUtils {
         return Reflection.newProxy(klazz, new InvocationHandler() {
             private Object processGetData(Method method) throws Throwable {
                 String columnName = getColumnName(method);
-                checkSchemaVersion(dbSchema, method);
+                checkColumnSchemaVersion(dbSchema, method);
                 if (columnName == null) {
-                    throw new RuntimeException("Error processing Getter : "+ method.getName());
+                    throw new TyperException("Error processing Getter : "+ method.getName());
                 }
                 GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz);
                 if (tableSchema == null) {
-                    throw new RuntimeException("Unable to locate TableSchema for "+getTableName(klazz)+ " in "+ dbSchema.getName());
+                    String message = TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName());
+                    throw new TableSchemaNotFoundException(message);
                 }
                 ColumnSchema<GenericTableSchema, Object> columnSchema = getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
                 if (columnSchema == null) {
-                    throw new RuntimeException("Unable to locate ColumnSchema for "+columnName+ " in "+ tableSchema.getName());
+                    String message = ColumnSchemaNotFoundException.createMessage(columnName, tableSchema.getName());
+                    throw new ColumnSchemaNotFoundException(message);
                 }
                 if (row == null) {
                     return null;
@@ -238,17 +264,19 @@ public class TyperUtils {
 
             private Object processGetColumn(Method method) throws Throwable {
                 String columnName = getColumnName(method);
-                checkSchemaVersion(dbSchema, method);
+                checkColumnSchemaVersion(dbSchema, method);
                 if (columnName == null) {
-                    throw new RuntimeException("Error processing GetColumn : "+ method.getName());
+                    throw new TyperException("Error processing GetColumn : "+ method.getName());
                 }
                 GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz);
                 if (tableSchema == null) {
-                    throw new RuntimeException("Unable to locate TableSchema for "+getTableName(klazz)+ " in "+ dbSchema.getName());
+                    String message = TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName());
+                    throw new TableSchemaNotFoundException(message);
                 }
                 ColumnSchema<GenericTableSchema, Object> columnSchema = getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
                 if (columnSchema == null) {
-                    throw new RuntimeException("Unable to locate ColumnSchema for "+columnName+ " in "+ tableSchema.getName());
+                    String message = ColumnSchemaNotFoundException.createMessage(columnName, tableSchema.getName());
+                    throw new ColumnSchemaNotFoundException(message);
                 }
                 // When the row is null, that might indicate that the user maybe interested only in the ColumnSchema and not on the Data.
                 if (row == null) {
@@ -259,12 +287,12 @@ public class TyperUtils {
 
             private Object processSetData(Object proxy, Method method, Object[] args) throws Throwable {
                 if (args == null || args.length != 1) {
-                    throw new RuntimeException("Setter method : "+method.getName() + " requires 1 argument");
+                    throw new TyperException("Setter method : "+method.getName() + " requires 1 argument");
                 }
-                checkSchemaVersion(dbSchema, method);
+                checkColumnSchemaVersion(dbSchema, method);
                 String columnName = getColumnName(method);
                 if (columnName == null) {
-                    throw new RuntimeException("Unable to locate Column Name for "+method.getName());
+                    throw new TyperException("Unable to locate Column Name for "+method.getName());
                 }
                 GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz);
                 ColumnSchema<GenericTableSchema, Object> columnSchema = getColumnSchema(tableSchema, columnName,
index 221cbb27aa5b96c76877c109e2eaa81c62c6da2b..e14fabe567d00202f0cd8a648e61be0b5abda727 100644 (file)
@@ -18,6 +18,7 @@ import junit.framework.Assert;
 import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
 import org.opendaylight.ovsdb.lib.notation.Mutator;
 import org.opendaylight.ovsdb.lib.notation.UUID;
@@ -38,7 +39,7 @@ public class IpfixTestCases extends OpenVswitchSchemaTestBase {
 
     Logger logger = LoggerFactory.getLogger(IpfixTestCases.class);
     Version schemaVersion;
-    Version ipfixFromVersion = Version.fromString("7.3.0");
+    Version ipfixFromVersion = Version.fromString("7.1.0");
 
 
     @Before
@@ -47,12 +48,17 @@ public class IpfixTestCases extends OpenVswitchSchemaTestBase {
         schemaVersion = ovs.getDatabaseSchema("Open_vSwitch").getVersion();
     }
 
-    @Test(expected=RuntimeException.class)
-    public void testUnsupportedTable() {
+    @Test
+    public void testTableNotSupported() {
         // Don't run this test if we can run the IPFIX test
         Assume.assumeTrue(schemaVersion.compareTo(ipfixFromVersion) < 0);
-        IPFIX ipfix = ovs.createTypedRowWrapper(IPFIX.class);
-        ipfix.setTargets(ImmutableSet.of("1.1.1.1:9988"));
+        boolean isExceptionRaised = false;
+        try {
+            IPFIX ipfix = ovs.createTypedRowWrapper(IPFIX.class);
+        } catch (SchemaVersionMismatchException e) {
+            isExceptionRaised = true;
+        }
+        Assert.assertTrue(isExceptionRaised);
     }
 
     @Test