Java Code Examples for com.openpojo.reflection.PojoClassFilter

The following examples show how to use com.openpojo.reflection.PojoClassFilter. These examples are extracted from open source projects. 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 Project: tessera   Source File: OpenPojoTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void executeOpenPojoValidations() {
    final Validator pojoValidator =
            ValidatorBuilder.create()
                    .with(new GetterMustExistRule())
                    .with(new GetterTester())
                    .with(new SetterTester())
                    .build();

    final PojoClassFilter[] filters =
            new PojoClassFilter[] {
                pc -> !pc.getClazz().getName().contains(KeyVaultConfigTest.class.getSimpleName()),
                pc -> !pc.getClazz().isAssignableFrom(ObjectFactory.class),
                pc -> !pc.getClazz().getName().startsWith(JaxbConfigFactory.class.getName()),
                pc -> !pc.getClazz().isAssignableFrom(ConfigException.class),
                pc -> !pc.getClazz().getName().contains(ConfigItem.class.getName()),
                pc -> !pc.getClazz().getSimpleName().contains("Test"),
                pc -> !pc.isNestedClass()
            };

    pojoValidator.validate("com.quorum.tessera.config", filters);
}
 
Example 2
Source Project: openpojo   Source File: DefaultPojoClassLookupService.java    License: Apache License 2.0 6 votes vote down vote up
public List<PojoClass> getPojoClassesRecursively(final String packageName, final PojoClassFilter pojoClassFilter) {
  final List<PojoClass> pojoClasses = new LinkedList<PojoClass>();
  final PojoClassFilter finalFilterChain = getFinalFilterChain(pojoClassFilter);

  final PojoPackage pojoPackage = PojoPackageFactory.getPojoPackage(packageName);

  Queue<PojoPackage> pending = new ConcurrentLinkedQueue<PojoPackage>();
  pending.add(pojoPackage);

  while (!pending.isEmpty()) {
    final PojoPackage entry = pending.remove();
    pending.addAll(entry.getPojoSubPackages());
    pojoClasses.addAll(entry.getPojoClasses(finalFilterChain));
  }
  return pojoClasses;
}
 
Example 3
Source Project: openpojo   Source File: FilterNonConcreteTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInclude() {
  PojoClassFilter pojoClassFilter = new FilterNonConcrete();
  PojoClass stubPojoClass = PojoStubFactory.getStubPojoClass(false);

  Affirm.affirmTrue(String.format("Filter[%s] was supposed to filter OUT non concrete class", pojoClassFilter), stubPojoClass
      .isConcrete() == pojoClassFilter.include(stubPojoClass));

  stubPojoClass = PojoStubFactory.getStubPojoClass(true);
  Affirm.affirmTrue(String.format("Filter[%s] was supposed to filter IN concrete class", pojoClassFilter),
      stubPojoClass.isConcrete() == pojoClassFilter.include(stubPojoClass));

  final StubPojoClassFilter stubPojoClassFilter = new StubPojoClassFilter();
  pojoClassFilter = new FilterChain(new FilterNonConcrete(), stubPojoClassFilter);

  stubPojoClass = PojoStubFactory.getStubPojoClass(true);
  pojoClassFilter.include(stubPojoClass);
  Affirm.affirmTrue(String.format("Filter [%s] didn't invoke next in filter chain", pojoClassFilter), stubPojoClassFilter
      .includeCalled);
}
 
Example 4
Source Project: openpojo   Source File: BeanTest.java    License: 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 5
Source Project: openpojo   Source File: DefaultPojoClassLookupService.java    License: Apache License 2.0 5 votes vote down vote up
public List<PojoClass> enumerateClassesByExtendingType(final String packageName, final Class<?> type,
                                                       final PojoClassFilter pojoClassFilter) {

  final FilterBasedOnInheritance inheritanceFilter = new FilterBasedOnInheritance(type);
  final FilterChain filterChain = new FilterChain(inheritanceFilter, pojoClassFilter);
  return getPojoClassesRecursively(packageName, filterChain);
}
 
Example 6
Source Project: openpojo   Source File: PojoClassCoverageFilter.java    License: Apache License 2.0 5 votes vote down vote up
public boolean include(PojoClass pojoClass) {
  for (PojoClassFilter filter : filters) {
    if (!filter.include(pojoClass))
      return false;
  }
  return true;
}
 
Example 7
Source Project: openpojo   Source File: PojoPackageImpl.java    License: Apache License 2.0 5 votes vote down vote up
public List<PojoClass> getPojoClasses(final PojoClassFilter filter) {
  List<PojoClass> pojoClasses = new LinkedList<PojoClass>();

  for (Type type : jdkPackage.getTypes()) {
    PojoClass pojoClass = PojoClassFactory.getPojoClass((Class<?>) type);
    if (pojoClass != null && (filter == null || filter.include(pojoClass))) {
      pojoClasses.add(pojoClass);
    }
  }

  return pojoClasses;
}
 
Example 8
Source Project: openpojo   Source File: FilterChain.java    License: Apache License 2.0 5 votes vote down vote up
public FilterChain(final PojoClassFilter... pojoClassFilters) {
  if (pojoClassFilters != null)
    for (PojoClassFilter pojoClassFilter : pojoClassFilters) {
      if (pojoClassFilter != null) {
        this.pojoClassFilters.add(pojoClassFilter);
      }
    }
}
 
Example 9
Source Project: openpojo   Source File: FilterChain.java    License: Apache License 2.0 5 votes vote down vote up
public boolean include(final PojoClass pojoClass) {
  for (PojoClassFilter pojoClassFilter : pojoClassFilters) {
    if (!pojoClassFilter.include(pojoClass))
      return false;
  }
  return true;
}
 
Example 10
Source Project: openpojo   Source File: GetterTesterAndSetterTesterTest.java    License: Apache License 2.0 5 votes vote down vote up
private List<PojoClass> getGoodPojoClasses() {
  return PojoClassFactory.getPojoClasses(TESTPACKAGE, new PojoClassFilter() {
    public boolean include(PojoClass pojoClass) {
      return pojoClass.getClazz().getSimpleName().startsWith("Good_");
    }
  });
}
 
Example 11
Source Project: openpojo   Source File: GetterTesterAndSetterTesterTest.java    License: 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 12
Source Project: openpojo   Source File: FilterChainTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void oneOneFilterAdded_FilterChainHasOneFilter() {
  PojoClassFilter dummyFilter = new DummyPojoClassFilter();
  FilterChain filter = new FilterChain(dummyFilter);
  Assert.assertEquals(1, filter.size());
  Assert.assertTrue(filter.getPojoClassFilters().contains(dummyFilter));
}
 
Example 13
Source Project: openpojo   Source File: FilterChainTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void addingArrayWithNullFilters_ignored() {
  PojoClassFilter dummyFilter = new DummyPojoClassFilter();
  FilterChain filter = new FilterChain(dummyFilter, null);
  Assert.assertEquals(1, filter.size());
  Assert.assertTrue(filter.getPojoClassFilters().contains(dummyFilter));
}
 
Example 14
Source Project: openpojo   Source File: FilterClassNameTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldExcludeFileName() {

  // Include only class names that are in the format of xSample
  final PojoClassFilter filter = new FilterClassName(".+Sample$");

  final String[] classNames = new String[] { "packagepath.packageSample.MyClass", "SampleClass", "Sample", "sample",
      "Somesample", "someSampleClass" };

  for (final String className : classNames) {
    PojoClass pojoClassStub = PojoStubFactory.getStubPojoClass(className);
    Affirm.affirmFalse(String.format("[%s] didn't exclude class [%s]!!", filter, className), filter.include(pojoClassStub));
  }

}
 
Example 15
Source Project: openpojo   Source File: DefaultValidator.java    License: Apache License 2.0 4 votes vote down vote up
public List<PojoClass> validate(String packageName, PojoClassFilter... filters) {
  PojoClassFilter pojoClassFilter = new FilterChain(filters);
  List<PojoClass> pojoClasses = PojoClassFactory.getPojoClasses(packageName, pojoClassFilter);
  validate(pojoClasses);
  return pojoClasses;
}
 
Example 16
Source Project: openpojo   Source File: DefaultValidator.java    License: 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 17
Source Project: openpojo   Source File: PojoClassLookupService.java    License: Apache License 2.0 4 votes vote down vote up
List<PojoClass> enumerateClassesByExtendingType(final String packageName, final Class<?> type, final PojoClassFilter
pojoClassFilter);
 
Example 18
Source Project: openpojo   Source File: DefaultPojoClassLookupService.java    License: Apache License 2.0 4 votes vote down vote up
public List<PojoClass> getPojoClasses(final String packageName, final PojoClassFilter pojoClassFilter) {
  return PojoPackageFactory.getPojoPackage(packageName).getPojoClasses(getFinalFilterChain(pojoClassFilter));
}
 
Example 19
Source Project: openpojo   Source File: DefaultPojoClassLookupService.java    License: Apache License 2.0 4 votes vote down vote up
private PojoClassFilter getFinalFilterChain(PojoClassFilter pojoClassFilter) {
  return new FilterChain(pojoClassFilter, ServiceRegistrar.getInstance().getPojoCoverageFilterService());
}
 
Example 20
Source Project: openpojo   Source File: PojoClassCoverageFilter.java    License: Apache License 2.0 4 votes vote down vote up
public void add(PojoClassFilter pojoClassFilter) {
  if (pojoClassFilter != null) {
    filters.add(pojoClassFilter);
  }
}
 
Example 21
Source Project: openpojo   Source File: Jacoco.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public PojoClassFilter getPojoClassFilter() {
  return null;
}
 
Example 22
Source Project: openpojo   Source File: Clover3.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public PojoClassFilter getPojoClassFilter() {
  return FilterCloverClasses.getInstance();
}
 
Example 23
Source Project: openpojo   Source File: Clover4.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public PojoClassFilter getPojoClassFilter() {
  return FilterCloverClasses.getInstance();
}
 
Example 24
Source Project: openpojo   Source File: Cobertura.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public PojoClassFilter getPojoClassFilter() {
  return null;
}
 
Example 25
Source Project: openpojo   Source File: FilterChain.java    License: Apache License 2.0 4 votes vote down vote up
public Collection<PojoClassFilter> getPojoClassFilters() {
  return Collections.unmodifiableSet(pojoClassFilters);
}
 
Example 26
Source Project: openpojo   Source File: FilterChainTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void filterChain_shouldIgonreNullFilterArray() {
  FilterChain filter = new FilterChain((PojoClassFilter[]) null);
  Assert.assertEquals(0, filter.size());
}
 
Example 27
Source Project: openpojo   Source File: Validator.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Validate for a given package and a filter.
 *
 * @param packageName
 *     The package name to run the validation against.
 * @param filters
 *     The filter(s) to be used for filtering which classes are to be included in the validation.
 *
 * @return the list of PojoClasses that were validated.
 */
List<PojoClass> validate(String packageName, PojoClassFilter... filters);
 
Example 28
Source Project: openpojo   Source File: Validator.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Validate for a given package and all its sub-packages with a given filter.
 *
 * @param packageName
 *     The package name to run the validation against.
 * @param filters
 *     The filter(s) to be used for filtering which classes are to be included in the validation.
 *
 * @return the list of PojoClasses that were validated.
 */
List<PojoClass> validateRecursively(String packageName, PojoClassFilter... filters);
 
Example 29
Source Project: openpojo   Source File: PojoClassFactory.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * This method returns a list of PojoClasses in a package representation with filtering capabilities.
 *
 * @param packageName
 *     Package to introspect (eg. com.mypackage.pojo).
 * @param pojoClassFilter
 *     The filter to apply to the list of PojoClasses.
 * @return A list of PojoClasses.
 */
public static List<PojoClass> getPojoClasses(final String packageName, final PojoClassFilter pojoClassFilter) {
  return ServiceRegistrar.getInstance().getPojoClassLookupService().getPojoClasses(packageName, pojoClassFilter);
}
 
Example 30
Source Project: openpojo   Source File: PojoClassFactory.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * This method enumerates all classes in a package path. This method will enumerate using the class loader, so if
 * you're tests live in the same package as your code, make sure you pass in a filter that can weed those out for
 * testing.
 *
 * @param packageName
 *     The package name in question.
 * @param pojoClassFilter
 *     The filter to use.
 * @return List of PojoClasses enumerated.
 */
public static List<PojoClass> getPojoClassesRecursively(final String packageName, final PojoClassFilter pojoClassFilter) {
  return ServiceRegistrar.getInstance().getPojoClassLookupService().getPojoClassesRecursively(packageName, pojoClassFilter);
}