Package org.jtester.exception

Examples of org.jtester.exception.JTesterException


      while (resultSet.next()) {
        result.add(resultSet.getString(4)); // COLUMN_NAME
      }
      return result;
    } catch (SQLException e) {
      throw new JTesterException("Error while querying for Derby primary keys for table name: " + tableName, e);
    } finally {
      closeQuietly(connection, null, resultSet);
    }
  }
View Full Code Here


          result.add(resultSet.getString(4)); // COLUMN_NAME
        }
      }
      return result;
    } catch (SQLException e) {
      throw new JTesterException("Error while querying for Derby primary keys for table name: " + tableName, e);
    } finally {
      closeQuietly(connection, null, resultSet);
    }
  }
View Full Code Here

   * @return
   */
  public static String getString(Properties properties, String key) {
    String value = getString(properties, key, "");
    if (StringHelper.isBlankOrNull(value)) {
      throw new JTesterException("No value found for property " + key);
    } else {
      return value.trim();
    }
  }
View Full Code Here

   */
  public static List<String> getStringList(String propertyName, boolean required) {
    String values = getString(propertyName);
    if (values == null || "".equals(values.trim())) {
      if (required) {
        throw new JTesterException("No value found for property " + propertyName);
      }
      return new ArrayList<String>(0);
    }
    String[] splitValues = values.split(",");
    List<String> result = new ArrayList<String>(splitValues.length);
    for (String value : splitValues) {
      result.add(value.trim());
    }

    if (required && result.isEmpty()) {
      throw new JTesterException("No value found for property " + propertyName);
    }
    return result;
  }
View Full Code Here

    if (ConfigurationHelper.hasProperty(propKey)) {
      return getString(propKey);
    }

    // no configuration found
    throw new JTesterException("Missing configuration for " + propKey);
  }
View Full Code Here

   *            injected, not null
   * @return The object that was replaced by the injection
   */
  public static Object injectInto(Object objectToInject, Object target, String property) {
    if (target == null) {
      throw new JTesterException("Target for injection should not be null");
    }
    try {
      OgnlContext ognlContext = new OgnlContext();
      ognlContext.setMemberAccess(new DefaultMemberAccess(true));
      Object ognlExpression = Ognl.parseExpression(property);

      Object oldValue = null;
      try {
        Ognl.getValue(ognlExpression, ognlContext, target);

      } catch (Throwable e) {
        JTesterLogger
            .warn("Unable to retrieve current value of field to inject into. Will not be able to restore value after injection.",
                e);
      }
      Ognl.setValue(ognlExpression, ognlContext, target, objectToInject);
      return oldValue;

    } catch (OgnlException e) {
      throw new JTesterException("Failed to set value using OGNL expression " + property, e);
    }
  }
View Full Code Here

   *            Defines if field or setter injection is used
   * @return The object that was replaced by the injection
   */
  public static Object injectIntoByType(Object objectToInject, Type objectToInjectType, Object target) {
    if (target == null) {
      throw new JTesterException("Target for injection should not be null");
    }
    return injectIntoFieldByType(objectToInject, objectToInjectType, target, target.getClass());
  }
View Full Code Here

    Set<Method> annotatedMethods = AnnotationUtils.getMethodsAnnotatedWith(target.getClass(), annotation);
    for (Method annotatedMethod : annotatedMethods) {
      try {
        annotatedMethod.invoke(target, objectToInject);
      } catch (IllegalArgumentException e) {
        throw new JTesterException(
            "Method "
                + annotatedMethod.getName()
                + " annotated with "
                + annotation.getName()
                + " must have exactly one argument with a type equal to or a superclass / implemented interface of "
                + objectToInject.getClass().getSimpleName());
      } catch (IllegalAccessException e) {
        throw new JTesterException("Unable to inject value into following method annotated with "
            + annotation.getName() + ": " + annotatedMethod.getName(), e);
      } catch (InvocationTargetException e) {
        throw new JTesterException("Unable to inject value into following method annotated with "
            + annotation.getName() + ": " + annotatedMethod.getName(), e);
      }
    }
  }
View Full Code Here

          + " found in " + targetClass.getSimpleName() + ".");
      if (objectToInjectType instanceof Class) {
        message.append(" If the target is a generic type, this can be caused by type erasure.");
      }
      message.append(" Specify the target field explicitly instead of injecting into by type.");
      throw new JTesterException(message.toString());

    } else if (fieldsWithExactType.size() == 1) {
      fieldToInjectTo = fieldsWithExactType.iterator().next();

    } else {
      // Try to find a supertype field:
      // If one field exist that has a type which is more specific than
      // all other fields of the given type,
      // this one is taken. Otherwise, an exception is thrown
      Set<Field> fieldsOfType = FieldHelper.getFieldsAssignableFrom(targetClass, objectToInjectType);
      if (fieldsOfType.size() == 0) {
        throw new JTesterException("No field with (super)type " + objectToInjectType + " found in "
            + targetClass.getSimpleName());
      }
      for (Field field : fieldsOfType) {
        boolean moreSpecific = true;
        for (Field compareToField : fieldsOfType) {
          if (field != compareToField) {
            if (field.getClass().isAssignableFrom(compareToField.getClass())) {
              moreSpecific = false;
              break;
            }
          }
        }
        if (moreSpecific) {
          fieldToInjectTo = field;
          break;
        }
      }
      if (fieldToInjectTo == null) {
        throw new JTesterException("Multiple candidate target fields found in " + targetClass.getSimpleName()
            + ", with none of them more specific than all others.");
      }
    }

    // Field to inject into found, inject the object and return old value
View Full Code Here

        String constraintName = resultSet.getString("CONSTRAINT_NAME");
        alterStatement.executeUpdate("alter table " + qualified(tableName) + " disable constraint "
            + quoted(constraintName));
      }
    } catch (Throwable e) {
      throw new JTesterException("Error while disabling referential constraints on schema " + getSchemaName(), e);
    } finally {
      closeQuietly(queryStatement);
      closeQuietly(connection, alterStatement, resultSet);
    }
  }
View Full Code Here

TOP

Related Classes of org.jtester.exception.JTesterException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.