Java Code Examples for com.openpojo.validation.test.impl.SetterTester

The following examples show how to use com.openpojo.validation.test.impl.SetterTester. 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: OpenPojoEntityTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void executeOpenPojoValidationsWithSetter() {

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

    pojoValidator.validate(PojoClassFactory.getPojoClass(MessageHash.class));
}
 
Example 2
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 3
Source Project: shipping   Source File: UnitPojo.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPojoStructureAndBehavior() {
    Validator validator = ValidatorBuilder.create()
            // Add Rules to validate structure for POJO_PACKAGE
            // See com.openpojo.validation.rule.impl for more ...
            .with(new GetterMustExistRule())
            .with(new SetterMustExistRule())
            // Add Testers to validate behaviour for POJO_PACKAGE
            // See com.openpojo.validation.test.impl for more ...
            .with(new SetterTester())
            .with(new GetterTester())
            // Static fields must be final
            .with(new NoStaticExceptFinalRule())
            // Don't shadow parent's field names.
            .with(new NoFieldShadowingRule())
            // What about public fields, use one of the following rules
            // allow them only if they are static and final.
            .with(new NoPublicFieldsExceptStaticFinalRule())
            .build();

    validator.validate(POJO_PACKAGE, filter);
}
 
Example 4
Source Project: cerberus   Source File: AwsStsPojoTest.java    License: 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 Project: cerberus   Source File: RecordPojoTest.java    License: 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 Project: orders   Source File: UnitPojo.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPojoStructureAndBehavior() {
    Validator validator = ValidatorBuilder.create()
            // Add Rules to validate structure for POJO_PACKAGE
            // See com.openpojo.validation.rule.impl for more ...
            .with(new GetterMustExistRule())
            .with(new SetterMustExistRule())
            // Add Testers to validate behaviour for POJO_PACKAGE
            // See com.openpojo.validation.test.impl for more ...
            .with(new SetterTester())
            .with(new GetterTester())
            // Static fields must be final
            .with(new NoStaticExceptFinalRule())
            // Don't shadow parent's field names.
            .with(new NoFieldShadowingRule())
            // What about public fields, use one of the following rules
            // allow them only if they are static and final.
            .with(new NoPublicFieldsExceptStaticFinalRule())
            .build();

    validator.validate(POJO_PACKAGE, filter);
}
 
Example 7
Source Project: openpojo   Source File: TestEntityTest.java    License: 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 8
Source Project: openpojo   Source File: IssueTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotFail() {
  Validator validator = ValidatorBuilder
      .create()
      .with(new GetterTester())
      .with(new SetterTester())
      .build();

  final PojoClass pojoClass = PojoClassFactory.getPojoClass(AClassWithXMLGregorianCalendar.class);
  validator.validate(pojoClass);

  Assert.assertThat(appender.getEventsForLogger(GetterTester.class).size(), is(1));
  Assert.assertThat(appender.getEventsForLogger(SetterTester.class).size(), is(1));

  PojoField xmlGregorianCalendarPojoField = pojoClass.getPojoFields().get(0);
  final String message = "Testing Field [" + xmlGregorianCalendarPojoField + "] with value [";

  validateLogMessages(appender, GetterTester.class, message);
  validateLogMessages(appender, SetterTester.class, message);
}
 
Example 9
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 10
Source Project: openpojo   Source File: IdentityFactoryRaceConditionTest.java    License: Apache License 2.0 6 votes vote down vote up
private Validator getValidator() {
  return ValidatorBuilder.create()
      .with(new BusinessKeyMustExistRule())
      .with(new GetterMustExistRule())
      .with(new NoFieldShadowingRule())
      .with(new NoNestedClassRule())
      .with(new NoPrimitivesRule())
      .with(new NoPublicFieldsExceptStaticFinalRule())
      .with(new NoPublicFieldsRule())
      .with(new NoStaticExceptFinalRule())
      .with(new SerializableMustHaveSerialVersionUIDRule())
      .with(new SetterMustExistRule())
      .with(new BusinessIdentityTester())
      .with(new DefaultValuesNullTester())
      .with(new GetterTester())
      .with(new SetterTester())
      .build();
}
 
Example 11
Source Project: cia   Source File: AbstractUnitTest.java    License: 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 12
Source Project: cloudbreak   Source File: DomainTest.java    License: 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 13
Source Project: cloudbreak   Source File: ModelTest.java    License: 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 14
Source Project: tessera   Source File: OpenPojoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void executeOpenPojoValidations() {

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

    
    pojoValidator.validate(PojoClassFactory.getPojoClass(ResendRequest.class));

}
 
Example 15
Source Project: tessera   Source File: ConfigurationMixinTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void pojoTest() {
    ValidatorBuilder.create()
            .with(new GetterTester())
            .with(new SetterTester())
            .build()
            .validate(PojoClassFactory.getPojoClass(ConfigurationMixin.class));
}
 
Example 16
Source Project: tessera   Source File: ApiObjectTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAccessorsForApiObjects() {
    Validator validator = ValidatorBuilder.create()
        .with(new GetterTester())
        .with(new SetterTester())
        .build();

    validator.validate("com.quorum.tessera.api");
}
 
Example 17
Source Project: taskana   Source File: PojoTest.java    License: Apache License 2.0 5 votes vote down vote up
@TestFactory
Collection<DynamicTest> validateGetAndSet() {
  return getPojoClasses()
      .map(
          cl ->
              DynamicTest.dynamicTest(
                  "Test set & get " + cl.getSimpleName(),
                  () -> validateWithTester(cl, new GetterTester(), new SetterTester())))
      .collect(Collectors.toList());
}
 
Example 18
Source Project: circus-train   Source File: ConfigurationPojosTest.java    License: 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);
                }
              }));
}
 
Example 19
Source Project: moleculer-java   Source File: PojoTest.java    License: MIT License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
	validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()).build();
	RandomGeneratorService service = ServiceRegistrar.getInstance().getRandomGeneratorService();
	service.registerRandomGenerator(new RandomGenerator() {

		@Override
		public Collection<Class<?>> getTypes() {
			LinkedList<Class<?>> list = new LinkedList<>();
			list.add(SSLContext.class);
			list.add(Serializer.class);
			return list;
		}

		@Override
		public Object doGenerate(Class<?> type) {
			try {
				if (type == SSLContext.class) {
					return SSLContext.getDefault();
				}
				if (type == Serializer.class) {
					return new JsonSerializer();
				}
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
			return null;
		}
	});
}
 
Example 20
Source Project: cerberus   Source File: OneLoginPojoTest.java    License: 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 21
Source Project: cerberus   Source File: DomainPojoTest.java    License: 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 22
Source Project: parallec   Source File: ParallecPojoClassTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the testers.
 *
 * @return the testers
 */
public List<Class<? extends Tester>> getTesters() {
    // Testers to validate behavior for POJO_PACKAGE
    List<Class<? extends Tester>> testers = new ArrayList<Class<? extends Tester>>();
    testers.add(SetterTester.class);
    testers.add(GetterTester.class);

    return testers;
}
 
Example 23
Source Project: openpojo   Source File: PojoValidatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void abstractClassTestingEndToEnd() {
  pojoValidator = ValidatorBuilder.create()
      .with(new GetterTester())
      .with(new SetterTester())
      .build();

  pojoValidator.validate(PojoClassFactory.getPojoClass(AnAbstractClassWithGetterSetter.class));
}
 
Example 24
Source Project: openpojo   Source File: ByteCodeFactoryTest.java    License: 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 25
Source Project: openpojo   Source File: IssueTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void issueTest() {

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

  validator.validate(PojoClassFactory.getPojoClass(TestClass.class));
}
 
Example 26
Source Project: openpojo   Source File: IssueTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSetGenerator() {
  Validator pojoValidator = ValidatorBuilder.create()
      .with(new SetterTester())
      .build();

  PojoClass pojoClass = PojoClassFactory.getPojoClass(TestClass.class);

  pojoValidator.validate(pojoClass);
}
 
Example 27
Source Project: openpojo   Source File: IssueTest.java    License: 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 28
Source Project: openpojo   Source File: IssueTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  classWithUUID = PojoClassFactory.getPojoClass(AClassWithUUID.class);
  validator = ValidatorBuilder.create()
                .with(new GetterTester())
                .with(new SetterTester())
                .build();
}
 
Example 29
Source Project: openpojo   Source File: DirtTruckTest.java    License: 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 30
Source Project: openpojo   Source File: ClassMemberTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {

  pojoClass = PojoClassFactory.getPojoClass(SampleClass.class);
  pojoValidator = ValidatorBuilder.create()
      // Add Testers to create a new instance on the private variable Class and trigger the problem.
      .with(new SetterTester())
      .with(new GetterTester())
      .build();
}