-
Notifications
You must be signed in to change notification settings - Fork 750
Home
PODAM main documentation can be found at PODAM Home Page.
The most basic usage for PODAM is the following:
PodamFactory factory = new PodamFactoryImpl(); //This will use the default Random Data Provider Strategy
Pojo myPojo = factory.manufacturePojo(Pojo.class);
Alternatively, if you want to define your own Strategy to assign values, you can use the following version:
DataProviderStrategy strategy = new MyDataProviderStrategy();
PodamFactory factory = new PodamFactoryImpl(strategy);
Pojo myPojo = factory.manufacturePojo(Pojo.class);
You can easily use PODAM with Spring too:
-
Define the Data Provider Strategy as a bean
-
Define PodamFactory bean, initialised with the Data Provider Strategy
-
Use the PodamFactory bean in your code
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- The definition of the default strategy -->
<bean id="randomDataProviderStrategy"
class="uk.co.jemos.podam.api.RandomDataProviderStrategy"
factory-method="getInstance" />
<!-- The definition of PODAM factory -->
<bean id="podamFactory" class="uk.co.jemos.podam.api.PodamFactoryImpl">
<constructor-arg index="0" ref="randomDataProviderStrategy" />
</bean>
</beans>
/**
*
*/
package uk.co.jemos.podam.test.unit.integration;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.test.dto.SimplePojoToTestSetters;
/**
* @author mtedone
*
*/
@ContextConfiguration(locations = { "classpath:podam-test-appContext.xml" })
public class PodamFactoryInjectionIntegrationTest extends
AbstractJUnit4SpringContextTests {
/** The Podam Factory */
@Autowired
private PodamFactory factory;
@Before
public void init() {
Assert.assertNotNull("The PODAM factory cannot be null!", factory);
Assert.assertNotNull("The factory strategy cannot be null!",
factory.getStrategy());
}
@Test
public void testSimplePojo() {
SimplePojoToTestSetters pojo = factory
.manufacturePojo(SimplePojoToTestSetters.class);
Assert.assertNotNull("The pojo cannot be null!", pojo);
...etc
}
}
PODAM uses introspection to figure out which data to fill in a POJO / JavaBean. It supports the following configurations:
-
Simple, one dimensional POJOs / JavaBeans
-
Complex graphs of POJOs / JavaBeans
-
Immutable-like POJOs / JavaBeans (e.g. classes without setters and all final instance attributes)
-
Singleton-like POJOs / JavaBeans (e.g. with a private constructor and a public static factory method, with or without arguments)
PODAM offers also custom annotations to customise numeric types and String values. Currently there is an annotation to customise each of the following types:
-
byte / Byte
-
char / Character
-
short / Short
-
int / Integer
-
long / Long
-
float / Float
-
double / Double
-
String
-
Container-type attributes (such as Collections, Maps and Arrays)
Additionally PODAM offers an annotation (@PodamExclude) to exclude a particular attribute from being set and another one (@PodamConstructor) to indicate which constructor to use in an Immutable-like POJO scenario.
As for types, PODAM supports the following Java types:
-
Primitive types
-
Wrapper types
-
Collections
-
Maps
-
Arrays
-
Custom POJOs / JavaBeans
-
Classes in the java / javax namespace which provide either a no-argument constructor or a static factory method, with or without arguments
PODAM supports also the following corner cases:
-
Inheritance (POJOs / JavaBeans extending other classes, either abstract or not)
-
Recursion. A POJO can declare an instance attribute of its type. Currently the nesting level is set to one, but one can change the constant and increase it
PODAM is open source and runs under the MIT license. The full documentation is available on Jemos PODAM home page
You can join our community on Podam Google group and file bugs or requests for enhancements on Jemos JIRA
I hope you will enjoy PODAM as much as I do. I know for sure that I will start using it at work from tomorrow, which is ultimately the reason why I wrote it.
Happy technology