com.openpojo.validation.rule.impl.GetterMustExistRule Java Examples

The following examples show how to use com.openpojo.validation.rule.impl.GetterMustExistRule. 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: OpenPojoTest.java    From tessera with 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 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 #3
Source File: DomainTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
void testPojoStructureAndBehavior() {

    List<PojoClass> pojoClasses = new ArrayList<>();
    pojoClasses.add(PojoClassFactory.getPojoClass(Region.class));
    pojoClasses.add(PojoClassFactory.getPojoClass(CompactView.class));
    pojoClasses.add(PojoClassFactory.getPojoClass(EnvironmentAuthentication.class));

    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: AwsStsPojoTest.java    From cerberus with Apache License 2.0 6 votes vote down vote up
@Test
public void test_pojo_structure_and_behavior() {

  List<Class> classes =
      Lists.newArrayList(
          GetCallerIdentityFullResponse.class,
          GetCallerIdentityResponse.class,
          AwsStsHttpHeader.class);

  List<PojoClass> pojoClasses =
      classes.stream().map(PojoClassFactory::getPojoClass).collect(Collectors.toList());

  Validator validator =
      ValidatorBuilder.create()
          .with(new GetterMustExistRule())
          .with(new SetterMustExistRule())
          .with(new SetterTester())
          .with(new GetterTester())
          .build();

  validator.validate(pojoClasses);
}
 
Example #5
Source File: RecordPojoTest.java    From cerberus with Apache License 2.0 6 votes vote down vote up
@Test
public void test_pojo_structure_and_behavior() {

  List<PojoClass> pojoClasses = PojoClassFactory.getPojoClasses("com.nike.cerberus.record");

  Assert.assertEquals(15, pojoClasses.size());

  Validator validator =
      ValidatorBuilder.create()
          .with(new GetterMustExistRule())
          .with(new SetterMustExistRule())
          .with(new SetterTester())
          .with(new GetterTester())
          .build();

  validator.validate(pojoClasses);
}
 
Example #6
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 #7
Source File: PojoFieldPrefixedFieldsTest.java    From openpojo with Apache License 2.0 6 votes vote down vote up
@Test
public void unRegisteringAPrefix_reflectsOnMethodLookup() {
  AttributeHelper.registerFieldPrefix("m");
  PojoClass pojoClass = PojoClassFactory.getPojoClass(AClassWithFieldsPrefixed.class);
  Rule getterRule = new GetterMustExistRule();
  getterRule.evaluate(pojoClass);

  AttributeHelper.unregisterFieldPrefix("m");
  PojoCache.clear();

  pojoClass = PojoClassFactory.getPojoClass(AClassWithFieldsPrefixed.class);
  boolean unregisterdSuccessfully = false;
  try {
    getterRule.evaluate(pojoClass);
  } catch (AssertionError ae) {
    unregisterdSuccessfully = true;
  }
  if (!unregisterdSuccessfully)
    Assert.fail("unregistering failed?!");
}
 
Example #8
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 #9
Source File: TestEntityTest.java    From openpojo with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  pojoClasses = PojoClassFactory.getPojoClasses(POJO_PACKAGE);

  ValidatorBuilder validatorBuilder = ValidatorBuilder.create();

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

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

  pojoValidator = validatorBuilder.build();
}
 
Example #10
Source File: IssueTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void testBooleanVariations() {
  PojoClass pojoClass = PojoClassFactory.getPojoClass(ClassWithBooleanFields.class);

  Affirm.affirmEquals("Fields must be 4", 4, pojoClass.getPojoFields().size());

  int countOfbooleans = 0;
  int countOfBooleans = 0;

  for (PojoField pojoField : pojoClass.getPojoFields()) {
    if (pojoField.isPrimitive() && pojoField.getType() == boolean.class) {
      countOfbooleans++;
    }
    if (!pojoField.isPrimitive() && pojoField.getType() == Boolean.class) {
      countOfBooleans++;
    }
  }

  Affirm.affirmEquals("2 boolean fields must exist", 2, countOfbooleans);
  Affirm.affirmEquals("2 Boolean fields must exist", 2, countOfBooleans);

  Validator pojoValidator = ValidatorBuilder.create()
      .with(new GetterMustExistRule())
      .with(new SetterMustExistRule())
      .with(new GetterTester())
      .with(new SetterTester())
      .build();

  pojoValidator.validate(pojoClass);
}
 
Example #11
Source File: IssueTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void whenBooleanStartsWith_is_AndThirdCharacterIsNotUpperCase_Getter_isIsY_Setter_setIsy() {
  PojoClass pojoClass = PojoClassFactory.getPojoClass(ClassWithBoolean_isy.class);

  Validator pojoValidator = ValidatorBuilder.create()
      .with(new GetterMustExistRule())
      .with(new SetterMustExistRule())
      .build();

  pojoValidator.validate(pojoClass);

}
 
Example #12
Source File: IssueTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetterAndSetter() {
   Validator validator = ValidatorBuilder
       .create()
       .with(new GetterMustExistRule())
       .with(new GetterTester())
       .with(new SetterMustExistRule())
       .with(new SetterTester())
       .build();
  validator.validate(getPojoClass(AClassWithBufferedImage.class));
}
 
Example #13
Source File: IssueTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  aClassWithGenericCollectionPojo = PojoClassFactory.getPojoClass(AClassWithGenericCollection.class);
  aParameterizedClass = PojoClassFactory.getPojoClass(AParameterizedClass.class);

  pojoValidator = ValidatorBuilder.create()
      .with(new GetterMustExistRule())
      .with(new SetterMustExistRule())
      .with(new SetterTester())
      .with(new GetterTester())
      .build();
}
 
Example #14
Source File: IssueTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void ensureClassIsDefinedCorrectly() {
  Validator validator = ValidatorBuilder.create()
      .with(new GetterMustExistRule())
      .with(new SetterMustExistRule())
      .with(new AllPimitivesAsArraysDeclaredRule())
      .with(new GetterTester())
      .with(new SetterTester())
      .build();
  validator.validate(pojoClass);
}
 
Example #15
Source File: GenericCollectionMultiThreadedTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
private Verify(List<PojoClass> pojoClasses) {
  this.pojoClasses = pojoClasses;
  pojoValidator = ValidatorBuilder.create()
      .with(new SetterMustExistRule())
      .with(new GetterMustExistRule())
      .with(new SetterTester())
      .with(new GetterTester())
      .build();
}
 
Example #16
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 #17
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 #18
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 #19
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 #20
Source File: ModelTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testPojoStructureAndBehavior() {
    Validator validator = ValidatorBuilder.create()
            .with(new SetterMustExistRule(),
                    new GetterMustExistRule())
            .with(new SetterTester(),
                    new GetterTester())
            .with(new NoStaticExceptFinalRule())
            .with(new NoNestedClassRule())
            .build();
    validator.validate(DOMAIN_PACKAGE, new FilterPackageInfo());
}
 
Example #21
Source File: DirtTruckTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void validate() {
  PojoClass pojoClass = PojoClassFactory.getPojoClass(DirtTruck.class);
  Validator pojoValidator = ValidatorBuilder.create()
      .with(new SetterMustExistRule())
      .with(new GetterMustExistRule())
      .with(new GetterTester())
      .with(new SetterTester())
      .build();

  pojoValidator.validate(pojoClass);
}
 
Example #22
Source File: SSLContextPropertiesTest.java    From tessera with Apache License 2.0 5 votes vote down vote up
@Test
public void executeOpenPojoValidationsNoSetter() {

    final Validator pojoValidator = ValidatorBuilder.create()
        .with(new GetterMustExistRule())
        .with(new GetterTester())
        .with(new EqualsAndHashCodeMatchRule())
        .with(new NoPublicFieldsExceptStaticFinalRule())
        .build();

    pojoValidator.validateRecursively("com.quorum.tessera.ssl.context.model");

}
 
Example #23
Source File: IssueTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void whenBooleanStartsWith_isAndThirdCharacterIsUpperCase_Getter_IsX_Setter_setX() {
  PojoClass pojoClass = PojoClassFactory.getPojoClass(ClassWithBoolean_isX.class);

  Validator pojoValidator = ValidatorBuilder.create()
      .with(new GetterMustExistRule())
      .with(new SetterMustExistRule())
      .build();

  pojoValidator.validate(pojoClass);
}
 
Example #24
Source File: IssueTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldTestAllClasses() {
  Validator validator = ValidatorBuilder.create()
      .with(new GetterMustExistRule())
      .with(new SetterMustExistRule())
      .with(new GetterTester())
      .with(new SetterTester())
      .build();

  List<PojoClass> classes = getPojoClassesRecursively(this.getClass().getPackage().getName() + ".sample", null);

  Assert.assertThat(classes.size(), is(3));
  validator.validate(classes);
}
 
Example #25
Source File: PojoFieldPrefixedFieldsTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void registeringNullOrEmptyPrefixIsIgnored() {
  AttributeHelper.registerFieldPrefix(null);
  AttributeHelper.registerFieldPrefix("");
  PojoClass pojoClass = PojoClassFactory.getPojoClass(AClassWithFieldsNotPrefixed.class);
  Rule getterRule = new GetterMustExistRule();
  getterRule.evaluate(pojoClass);

  AttributeHelper.registerFieldPrefix("m");
  pojoClass = PojoClassFactory.getPojoClass(AClassWithFieldsPrefixed.class);
  getterRule.evaluate(pojoClass);
}
 
Example #26
Source File: PojoFieldPrefixedFieldsTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void unmatchedPrefixesHaveNoEffect() {
  AttributeHelper.registerFieldPrefix("n");
  PojoClass pojoClass = PojoClassFactory.getPojoClass(AClassWithFieldsNotPrefixed.class);
  Rule getterRule = new GetterMustExistRule();
  getterRule.evaluate(pojoClass);
}
 
Example #27
Source File: ByteCodeFactoryTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void endToEndTest() {
  PojoClass pojoClass = PojoClassFactory.getPojoClass(ACompleteAbstractClass.class);

  Validator pojoValidator = ValidatorBuilder.create()
      .with(new GetterMustExistRule())
      .with(new SetterMustExistRule())
      .with(new GetterTester())
      .with(new SetterTester())
      .build();

  pojoValidator.validate(pojoClass);
}
 
Example #28
Source File: DomainPojoTest.java    From cerberus with Apache License 2.0 5 votes vote down vote up
@Test
public void test_pojo_structure_and_behavior() {

  List<PojoClass> pojoClasses = PojoClassFactory.getPojoClasses("com.nike.cerberus.domain");

  pojoClasses.remove(PojoClassFactory.getPojoClass(CerberusAuthToken.class));
  pojoClasses.remove(
      PojoClassFactory.getPojoClass(CerberusAuthToken.CerberusAuthTokenBuilder.class));
  pojoClasses.remove(PojoClassFactory.getPojoClass(VaultStyleErrorResponse.Builder.class));
  pojoClasses.remove(PojoClassFactory.getPojoClass(IamPrincipalPermission.Builder.class));
  pojoClasses.remove(PojoClassFactory.getPojoClass(UserGroupPermission.Builder.class));
  pojoClasses.remove(PojoClassFactory.getPojoClass(SafeDepositBoxV2.Builder.class));
  pojoClasses.remove(
      PojoClassFactory.getPojoClass(SecureDataResponse.SecureDataResponseBuilder.class));

  Assert.assertTrue(pojoClasses.size() > 1);

  Validator validator =
      ValidatorBuilder.create()
          .with(new GetterMustExistRule())
          .with(new SetterMustExistRule())
          .with(new SetterTester())
          .with(new GetterTester())
          .build();

  validator.validate(pojoClasses);
}
 
Example #29
Source File: OneLoginPojoTest.java    From cerberus with Apache License 2.0 5 votes vote down vote up
@Test
public void test_pojo_structure_and_behavior() {

  List<Class> classes =
      Lists.newArrayList(
          CreateSessionLoginTokenRequest.class,
          CreateSessionLoginTokenResponse.class,
          GenerateTokenRequest.class,
          GenerateTokenResponse.class,
          GenerateTokenResponseData.class,
          GetUserResponse.class,
          MfaDevice.class,
          ResponseStatus.class,
          SessionLoginTokenData.class,
          SessionUser.class,
          UserData.class,
          VerifyFactorRequest.class,
          VerifyFactorResponse.class);

  List<PojoClass> pojoClasses =
      classes.stream().map(PojoClassFactory::getPojoClass).collect(Collectors.toList());

  Validator validator =
      ValidatorBuilder.create()
          .with(new GetterMustExistRule())
          .with(new SetterMustExistRule())
          .with(new SetterTester())
          .with(new GetterTester())
          .build();

  validator.validate(pojoClasses);
}
 
Example #30
Source File: ConfigurationPojosTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Test
public void testPojo() {
  ValidatorBuilder
      .create()
      .with(new GetterMustExistRule())
      .with(new SetterMustExistRule())
      .with(new SetterTester())
      .with(new GetterTester())
      .build()
      .validate(Lists
          .transform(ImmutableList
              .<Class<?>> builder()
              .add(MetastoreTunnel.class)
              .add(ReplicaTable.class)
              .add(ReplicaCatalog.class)
              .add(Security.class)
              .add(SourceCatalog.class)
              .add(SourceTable.class)
              .add(TableReplication.class)
              .add(TableReplications.class)
              .add(MetricsReporter.class)
              .build(), new Function<Class<?>, PojoClass>() {
                @Override
                public PojoClass apply(Class<?> input) {
                  return PojoClassFactory.getPojoClass(input);
                }
              }));
}