private void makeSureIsNamed(ClassInfo ci) {
   logger.info("Checking class " + ci.getName());
   if (!ci.load().isAnnotationPresent(Named.class)) {
     throw new RuntimeException(
         "Configuration error: class "
             + ci.getName()
             + " has no @javax.inject.Named-annotation! "
             + "The contents of this class will not be loaded into the database!");
   }
 }
Exemplo n.º 2
0
  @SuppressWarnings({"rawtypes"})
  private Set<Class> getTableBeans() throws IOException, URISyntaxException {

    ClassLoader loader = getClass().getClassLoader();
    ClassPath cp;
    Set<ClassInfo> rss = null;
    try {
      cp = ClassPath.from(loader);
      rss = cp.getAllClasses();
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    Set<Class> results = Sets.newHashSet();

    for (ClassInfo info : rss) {
      String className = info.getName();
      if (exclude(className)) continue;
      Class clazz;
      try {
        clazz = loader.loadClass(className);
        if (Storable.class.isAssignableFrom(clazz) && clazz != Storable.class) {
          results.add(clazz);
        }
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      }
    }
    return results;
  }
  @SuppressWarnings("deprecation")
  @Test
  public void testExceptionsAreGood() throws Exception {
    ImmutableSet<ClassInfo> classes =
        ClassPath.from(Thread.currentThread().getContextClassLoader())
            .getTopLevelClasses(BaseServerResponseException.class.getPackage().getName());
    assertTrue(classes.size() > 5);

    for (ClassInfo classInfo : classes) {
      ourLog.info("Scanning {}", classInfo.getName());

      Class<?> next = Class.forName(classInfo.getName());
      assertNotNull(next);

      if (next == getClass()) {
        continue;
      }
      if (next == BaseServerResponseException.class) {
        continue;
      }
      if (next == UnclassifiedServerFailureException.class) {
        continue;
      }
      if (next == ResourceVersionNotSpecifiedException.class) {
        // This one is deprocated
        continue;
      }

      assertTrue(
          "Type " + next + " is not registered",
          BaseServerResponseException.isExceptionTypeRegistered(next));

      if (next == AuthenticationException.class) {
        continue;
      }

      try {
        next.getConstructor(String.class, IBaseOperationOutcome.class);
      } catch (NoSuchMethodException e) {
        fail(
            classInfo.getName()
                + " has no constructor with params: (String, IBaseOperationOutcome)");
      }
    }
  }