Java Code Examples for com.openpojo.reflection.impl.PojoClassFactory#getPojoClassesRecursively()

The following examples show how to use com.openpojo.reflection.impl.PojoClassFactory#getPojoClassesRecursively() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanTest.java    From openpojo with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  LogHelper.initializeLoggers();
  PojoClassFilter pojoClassFilter = new FilterChain(new FilterEnum(), new FilterPackageInfo());
  pojoClasses = PojoClassFactory.getPojoClassesRecursively(this.getClass().getPackage().getName() + ".sampleclasses",
      pojoClassFilter);

  ValidatorBuilder validatorBuilder = ValidatorBuilder.create();

  // Create Rules to validate structure for POJO_PACKAGE
  validatorBuilder.with(new NoPublicFieldsRule());
  validatorBuilder.with(new NoStaticExceptFinalRule());
  validatorBuilder.with(new GetterMustExistRule());
  validatorBuilder.with(new SetterMustExistRule());

  // Create Testers to validate behaviour for POJO_PACKAGE
  validatorBuilder.with(new DefaultValuesNullTester());
  validatorBuilder.with(new SetterTester());
  validatorBuilder.with(new GetterTester());

  pojoValidator = validatorBuilder.build();
}
 
Example 2
Source File: AbstractUnitTest.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Check all classes in package.
 *
 * @param string the string
 * @return true, if successful
 */
protected final boolean checkAllClassesInPackage(final String string) {
	final List<PojoClass> pojoClassesRecursively = PojoClassFactory.getPojoClassesRecursively(string,
			new FilterTestClasses());

	final Validator validator = ValidatorBuilder.create().with(new SetterMustExistRule(), new GetterMustExistRule())
			.with(new SetterTester(), new GetterTester()).with(new InvokeToStringTester())
			.with(new InvokeHashcodeTester()).with(new DummyEqualsTester()).with(new WithTester())
			.with(new ObjectFactoryTester()).with(new EqualsAndHashCodeMatchRule()).build();
	validator.validate(pojoClassesRecursively);

	final List<PojoClass> enumClassesRecursively = PojoClassFactory.getPojoClassesRecursively(string,
			new FilterNonEnumClasses());

	final Validator enumValidator = ValidatorBuilder.create().with(new EnumTester()).build();
	enumValidator.validate(enumClassesRecursively);

	return true;
}
 
Example 3
Source File: ModelTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testPojoStructureAndBehavior() {
    List<PojoClass> pojoClasses = PojoClassFactory.getPojoClassesRecursively(MODEL_PACKAGE, BASE_CLASS_FILTER);

    Validator validator = ValidatorBuilder.create()
            .with(new SetterMustExistRule(),
                    new GetterMustExistRule())
            .with(new GetterTester())
            .with(new NoPublicFieldsExceptStaticFinalRule())
            .with(new NoStaticExceptFinalRule())
            .with(new NoNestedClassRule())
            .with(new NoFieldShadowingRule())
            .build();
    validator.validate(pojoClasses);

    validator = ValidatorBuilder.create()
            .with(new SetterTester())
            .build();
    validator.validate(pojoClasses);
    // openpojo will do for now (seems buggy) but later would worth experimenting with pojo-tester (https://www.pojo.pl/)
}
 
Example 4
Source File: GetterTesterAndSetterTesterTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
private List<PojoClass> getBadPojoClasses() {
  return PojoClassFactory.getPojoClassesRecursively(TESTPACKAGE, new PojoClassFilter() {

    public boolean include(final PojoClass pojoClass) {
      return pojoClass.getClazz().getSimpleName().startsWith("Bad_");
    }
  });
}
 
Example 5
Source File: JavaClassPathClassLoaderTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void end2end_shouldLoadAllClassesInJavaLang() {
  List<PojoClass> types = PojoClassFactory.getPojoClassesRecursively("java.lang", null);
  checkListOfPojoClassesContains(types, java.lang.Class.class);
  checkListOfPojoClassesContains(types, java.lang.CharSequence.class);
  checkListOfPojoClassesContains(types, java.lang.Runnable.class);
  checkListOfPojoClassesContains(types, java.lang.Throwable.class);
  checkListOfPojoClassesContains(types, java.lang.Double.class);
  checkListOfPojoClassesContains(types, java.lang.Float.class);
  checkListOfPojoClassesContains(types, java.lang.Object.class);
  checkListOfPojoClassesContains(types, java.lang.Error.class);

  Assert.assertThat(types.size(), greaterThan(minJavaLangClasses));
}
 
Example 6
Source File: JavaClassPathClassLoaderTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void end2endLoadAllClassesInTheVM() {
  List<PojoClass> types = PojoClassFactory.getPojoClassesRecursively("", null);
  Assert.assertTrue(types.contains(PojoClassFactory.getPojoClass(this.getClass())));
  final String reason = "Loaded " + types.size() + " classes instead of expected " + minExpectedTotalClasses;
  Assert.assertThat(reason, types.size(), greaterThan(minExpectedTotalClasses));
  checkListOfPojoClassesContains(types, java.rmi.registry.LocateRegistry.class);
}
 
Example 7
Source File: IssueTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
/**
 * This is the main issue experienced.
 */
@Test
public void shouldNotThrowNoClassDefFoundError() {
  final Package aPackage = org.testng.Assert.class.getPackage();
  final String packageName = aPackage.getName();
  List<PojoClass> pojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName, null);
  Assert.assertTrue("Should have found some classes", pojoClasses.size() > 0);
}
 
Example 8
Source File: AbstractUnitTest.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Check all dto classes in package.
 *
 * @param string the string
 * @return true, if successful
 */
protected final boolean checkAllDtoClassesInPackage(final String string) {

	final List<PojoClass> pojoClassesRecursively = PojoClassFactory.getPojoClassesRecursively(string,
			new FilterTestClasses());

	final Validator validator = ValidatorBuilder.create().with(new GetterMustExistRule()).with(new GetterTester())
			.with(new EqualsAndHashCodeMatchRule()).with(new InvokeToStringTester())
			.with(new InvokeHashcodeTester()).with(new DummyEqualsTester()).with(new WithTester()).build();
	validator.validate(pojoClassesRecursively);
	return true;
}
 
Example 9
Source File: ModelTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testPojoStructureAndBehavior() {
    List<PojoClass> pojoClasses = PojoClassFactory.getPojoClassesRecursively(DOMAIN_PACKAGE, POJO_CLASS_FILTER);

    Validator validator = ValidatorBuilder.create()
            .with(new SetterMustExistRule(),
                    new GetterMustExistRule())
            .with(new SetterTester(),
                    new GetterTester())
            .with(new NoStaticExceptFinalRule())
            .with(new NoNestedClassRule())
            .build();
    validator.validate(pojoClasses);
}
 
Example 10
Source File: ModelTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testImmutableStructureAndBehavior() {
    List<PojoClass> pojoClasses = PojoClassFactory.getPojoClassesRecursively(DOMAIN_PACKAGE, IMMUTABLE_CLASS_FILTER);

    Validator validator = ValidatorBuilder.create()
            .with(new GetterMustExistRule())
            .with(new GetterTester())
            .with(new NoStaticExceptFinalRule())
            .with(new NoNestedClassRule())
            .build();
    validator.validate(pojoClasses);
}
 
Example 11
Source File: ModelTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetterTypeChangerPojoStructureAndBehavior() {
    List<PojoClass> pojoClasses = PojoClassFactory.getPojoClassesRecursively(DOMAIN_PACKAGE, GETTER_TYPE_CHANGER_CLASS_FILTER);

    Validator validator = ValidatorBuilder.create()
            .with(new SetterMustExistRule())
            .with(new SetterTester(),
                    new GetterTester())
            .with(new NoStaticExceptFinalRule())
            .with(new NoNestedClassRule())
            .build();
    validator.validate(pojoClasses);
}
 
Example 12
Source File: ModelTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetterTypeChangerPojoStructureAndBehavior() {
    List<PojoClass> pojoClasses = PojoClassFactory.getPojoClassesRecursively(DOMAIN_PACKAGE, SETTER_TYPE_CHANGER_CLASS_FILTER);

    Validator validator = ValidatorBuilder.create()
            .with(new GetterMustExistRule())
            .with(new SetterTester(),
                    new GetterTester())
            .with(new NoStaticExceptFinalRule())
            .with(new NoNestedClassRule())
            .build();
    validator.validate(pojoClasses);
}
 
Example 13
Source File: DefaultValidator.java    From openpojo with Apache License 2.0 4 votes vote down vote up
public List<PojoClass> validateRecursively(String packageName, PojoClassFilter... filters) {
  PojoClassFilter pojoClassFilter = new FilterChain(filters);
  List<PojoClass> pojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName, pojoClassFilter);
  validate(pojoClasses);
  return pojoClasses;
}
 
Example 14
Source File: IssueTest.java    From openpojo with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  pojoClasses = PojoClassFactory.getPojoClassesRecursively("com.openpojo.issues.issue46.sample", null);
  pojoValidator = ValidatorBuilder.create().with(new DefaultValuesNullTester()).build();
}