Search in sources :

Example 1 with PodamFactory

use of uk.co.jemos.podam.api.PodamFactory in project podam by devopsfolks.

the class SingletonsTest method podamShouldHandleSingletonsWithParametersInPublicStaticMethod.

@Test
@Title("Podam should handle Singletons with parameters in the static method")
public void podamShouldHandleSingletonsWithParametersInPublicStaticMethod() throws Exception {
    PodamFactory podamFactory = podamFactorySteps.givenAStandardPodamFactory();
    SingletonWithParametersInStaticFactoryPojo pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(SingletonWithParametersInStaticFactoryPojo.class, podamFactory);
    podamValidationSteps.thePojoMustBeOfTheType(pojo, SingletonWithParametersInStaticFactoryPojo.class);
    podamValidationSteps.thePojoMustBeOfTheType(pojo.getCreateDate(), GregorianCalendar.class);
    podamValidationSteps.theStringFieldCannotBeNullOrEmpty(pojo.getFirstName());
    List<OneDimensionalTestPojo> pojoList = pojo.getPojoList();
    podamValidationSteps.theCollectionShouldNotBeNullOrEmptyAndContainElementsOfType(pojoList, OneDimensionalTestPojo.class);
    Map<String, OneDimensionalTestPojo> pojoMap = pojo.getPojoMap();
    podamValidationSteps.theMapShouldNotBeNullOrEmptyAndContainElementsOfType(pojoMap, String.class, OneDimensionalTestPojo.class);
}
Also used : OneDimensionalTestPojo(uk.co.jemos.podam.test.dto.OneDimensionalTestPojo) PodamFactory(uk.co.jemos.podam.api.PodamFactory) SingletonWithParametersInStaticFactoryPojo(uk.co.jemos.podam.test.dto.SingletonWithParametersInStaticFactoryPojo) Test(org.junit.Test) Title(net.thucydides.core.annotations.Title)

Example 2 with PodamFactory

use of uk.co.jemos.podam.api.PodamFactory in project podam by devopsfolks.

the class ValidatedPojoTest method podamShouldFulfillMostOfTheJavaxValidationFramework.

@Test
@Title("Podam should be able to fulfill most of the javax Validation framework")
public void podamShouldFulfillMostOfTheJavaxValidationFramework() throws Exception {
    AttributeStrategy<?> strategy = new EmailStrategy();
    PodamFactory podamFactory = podamFactorySteps.givenAPodamFactoryWithCustomStrategy(Email.class, strategy);
    ValidatedPojo pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(ValidatedPojo.class, podamFactory);
    podamValidationSteps.theObjectShouldNotBeNull(pojo);
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getBoolFalse());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getBoolTrue());
    podamValidationSteps.theStringFieldCannotBeNullOrEmpty(pojo.getFilledString());
    podamValidationSteps.theObjectShouldBeNull(pojo.getEmptyString());
    podamValidationSteps.theStringFieldCannotBeNullOrEmpty(pojo.getNotEmptyString());
    podamValidationSteps.theStringFieldCannotBeNullOrEmpty(pojo.getNotBlankString());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getDecimalDouble());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getDecimalFloat());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getDecimalString());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getLongNumber());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getIntNumber());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getBigIntNumber());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getShortNumber());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getByteNumber());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getIntString());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getFractionDecimal());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getFractionString());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getPastDate());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getFutureCalendar());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getSizedString());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getMaxCollection());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getMinCollection());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getDefaultCollection());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getDefaultMap());
    podamValidationSteps.theObjectShouldNotBeNull(pojo.getEmail());
    podamValidationSteps.theObjectShouldBeNull(pojo.getIdentifier());
    Validator validator = podamFactorySteps.givenAJavaxValidator();
    validatorSteps.thePojoShouldNotViolateAnyValidations(validator, pojo);
    podamFactorySteps.removeCustomStrategy(podamFactory, Email.class);
}
Also used : PodamFactory(uk.co.jemos.podam.api.PodamFactory) EmailStrategy(uk.co.jemos.podam.test.strategies.EmailStrategy) ValidatedPojo(uk.co.jemos.podam.test.dto.ValidatedPojo) Validator(javax.validation.Validator) Test(org.junit.Test) Title(net.thucydides.core.annotations.Title)

Example 3 with PodamFactory

use of uk.co.jemos.podam.api.PodamFactory in project podam by devopsfolks.

the class ValidatedPojoTest method whenMaxLengthIsNotSpecifiedInSizeAnnotationPodamShouldAssignASensibleDefault.

@Test
@Title("When the @Size annotation doesn't have a max length specified, Podam should assign a sensible value")
public void whenMaxLengthIsNotSpecifiedInSizeAnnotationPodamShouldAssignASensibleDefault() throws Exception {
    PodamFactory podamFactory = podamFactorySteps.givenAStandardPodamFactory();
    ValidationPojoForStringWithSizeAndNoMax pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(ValidationPojoForStringWithSizeAndNoMax.class, podamFactory);
    podamValidationSteps.theObjectShouldNotBeNull(pojo);
    Validator validator = podamFactorySteps.givenAJavaxValidator();
    validatorSteps.thePojoShouldNotViolateAnyValidations(validator, pojo);
}
Also used : PodamFactory(uk.co.jemos.podam.api.PodamFactory) ValidationPojoForStringWithSizeAndNoMax(uk.co.jemos.podam.test.dto.ValidationPojoForStringWithSizeAndNoMax) Validator(javax.validation.Validator) Test(org.junit.Test) Title(net.thucydides.core.annotations.Title)

Example 4 with PodamFactory

use of uk.co.jemos.podam.api.PodamFactory in project podam by devopsfolks.

the class RandomDataProviderStrategyImplInitialisationUnitTest method podamShouldCorrectGenerateHashMapsWithLongAsKeyType.

@Test
@Title("Podam should correctly generate HashMaps with Long as key type")
public void podamShouldCorrectGenerateHashMapsWithLongAsKeyType() throws Exception {
    DataProviderStrategy strategy = podamFactorySteps.givenACustomRandomDataProviderStrategy();
    PodamFactory podamFactory = podamFactorySteps.givenAPodamFactoryWithCustomDataProviderStrategy(strategy);
    Map<?, ?> pojo = podamInvocationSteps.whenIInvokeTheFactoryForGenericTypeWithSpecificType(HashMap.class, podamFactory, Long.class, String.class);
    podamValidationSteps.theObjectShouldNotBeNull(pojo);
    podamValidationSteps.theTwoObjectsShouldBeEqual(strategy.getNumberOfCollectionElements(String.class), pojo.size());
}
Also used : DataProviderStrategy(uk.co.jemos.podam.api.DataProviderStrategy) AbstractRandomDataProviderStrategy(uk.co.jemos.podam.api.AbstractRandomDataProviderStrategy) PodamFactory(uk.co.jemos.podam.api.PodamFactory) Test(org.junit.Test) Title(net.thucydides.core.annotations.Title)

Example 5 with PodamFactory

use of uk.co.jemos.podam.api.PodamFactory in project podam by devopsfolks.

the class AbnormalPojosTest method podamShouldHandlePojosWithPrivateOnlyConstructors.

@Test
@Title("Podam should handle POJOs with private constructors only")
public void podamShouldHandlePojosWithPrivateOnlyConstructors() throws Exception {
    PodamFactory podamFactory = podamFactorySteps.givenAStandardPodamFactory();
    PrivateOnlyConstructorPojo pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(PrivateOnlyConstructorPojo.class, podamFactory);
    podamValidationSteps.theObjectShouldNotBeNull(pojo);
    podamValidationSteps.theStringFieldCannotBeNullOrEmpty(pojo.getFirstName());
    podamValidationSteps.theIntFieldShouldNotBeZero(pojo.getIntField());
}
Also used : PrivateOnlyConstructorPojo(uk.co.jemos.podam.test.dto.pdm33.PrivateOnlyConstructorPojo) PodamFactory(uk.co.jemos.podam.api.PodamFactory) Test(org.junit.Test) Title(net.thucydides.core.annotations.Title)

Aggregations

PodamFactory (uk.co.jemos.podam.api.PodamFactory)130 Test (org.junit.Test)127 Title (net.thucydides.core.annotations.Title)126 Validator (javax.validation.Validator)4 DataProviderStrategy (uk.co.jemos.podam.api.DataProviderStrategy)3 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 AbstractRandomDataProviderStrategy (uk.co.jemos.podam.api.AbstractRandomDataProviderStrategy)2 PodamFactoryImpl (uk.co.jemos.podam.api.PodamFactoryImpl)2 PojoWithMapsAndCollections (uk.co.jemos.podam.test.dto.PojoWithMapsAndCollections)2 SimplePojoToTestSetters (uk.co.jemos.podam.test.dto.SimplePojoToTestSetters)2 GenericCollectionsConstructorPojo (uk.co.jemos.podam.test.dto.issue123.GenericCollectionsConstructorPojo)2 BeanContextServicesSupport (java.beans.beancontext.BeanContextServicesSupport)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 URL (java.net.URL)1 Timestamp (java.sql.Timestamp)1 Currency (java.util.Currency)1 Date (java.util.Date)1 Observable (java.util.Observable)1