DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Culture and Methodologies
  3. Agile
  4. PODAM - Gathering Requirements

PODAM - Gathering Requirements

Marco Tedone user avatar by
Marco Tedone
·
Mar. 31, 11 · Interview
Like (2)
Save
Tweet
Share
8.05K Views

Join the DZone community and get the full member experience.

Join For Free

as announced in my previous article i am starting a new project to provide an easy api to fill in pojos with dummy data.

the goal of this article is to collect a first draft of requirements for podam. ok, so what's needed by a tool to fill pojos with dummy data?

  1. the tool should provide a black box through a simple function: given as argument a pojo class, the function must return an instance of the pojo class with all its instance variables filled with data, unless otherwise stated by a custom annotation (see next point).
  2. the possibility, through annotations, to customise the behaviour of such tool. for instance one might want to skip the auto-generation of data for some pojo attributes; or one might want to pilot the values assigned to a pojo: for instance on a numeric attribute the value assigned by the tool should be between 5 and 100. other customisation could go in the direction of fine grained value assignments to properties (boolean, date, etc)
  3. the possibility to be integrated with tools such as junit, although podam should not extend junit but rather junit could make use of podam through composition. in this scenario, instead of invoking a factory function which returns an instance of a pojo, one could declared a @podam annotation on a (instance) local variable in a junit (or other testing framework) test and the factory method would then be invoked.
  4. for podam to work the pojo being set with dummy data must have a non-argument constructor

let's try to capture the above requirements in steps. let's start with the simplest scenario, e.g. i want a pojo with all its attributes (including its graph objects) set with some dummy values. given the following domain model:

podam example domain model

a client has got an address and one or more bankaccounts. if i am writing a junit test for a service which uses the client pojo, i'd like podam to offer something like this:


public class clientserviceunittest {

@junit

public void testclientservice() throws exception {

clientservice service = easymock.createmock(clientservice.class);

client clientdto = podamfactory.createdummy(client.class);

service.persistclient(clientdto);

easymock.expectlastcall();

//etc. replay and mock validation

}

}

podamfactory should return a client pojo whose primitive types attributes are filled with values but also whose graphed objects are filled with data. so the client will have an address object filled with dummy data and a collection of one or more bank accounts.

now let's look at some more interesting scenarios. let's say that i wanted a client pojo filled with data but i wanted the address attribute to be skipped. i could write something like the following:


//imports omitted

public class client implements serializable {

private string firstname;

private string lastname;

@podam(skip=true) private address address;

private list<bankaccount> bankaccounts;

//constructors, getters/setters, equals/hashcode and tostring methods omitted for brevity

}

i could use a @podam annotation with boolean attribute skip = true to indicate that a certain attribute should not be filled by podam. of course for graphed objects to be filled with dummy data, these should be podam-compliant (e.g. have a no-arguments constructor).

another scenario could be that i wanted to specify exactly how many bank accounts i wanted. using the same class as before i could have:


//imports omitted

public class client implements serializable {

private string firstname;

private string lastname;

private address address;

@podam(nbrelements=5)

private list<bankaccount> bankaccounts;

//constructors, getters/setters, equals/hashcode and tostring methods omitted for brevity

}

by using the nbrelements attribute i could instruct podam on how many elements in the list i'd like to be filled with dummy data. so it seems that a @podam annotation is emerging from the initial requirements. the question here is whether such annotation (which belongs mainly to the testing world) would be acceptable in a production pojo code. my view is that annotations in general are innocuous and that the benefits of having fine grained control over auto-generated dummy data during testing outweighs the cons of having a "test related" import in our code.

let's see if i can define some attributes of a @podam annotation.

  • skip. (boolean). it instructs the tool to skip the auto-generation of dummy data for the annotated attribute. the default is false.
  • value. (string). it asks the tool to assign exactly the value specified in the attribute. the default is a blank string.
  • minvalue. (numeric). it requires the tool to assign a numeric value to the annotated attribute which should not be less than the value defined in the annotation.
  • maxvalue. (numeric). similar to minvalue except that the value assigned to the annotated attribute should not be greater than the value indicated by the annotation. the default is the maximum value for the type of the annotated attribute.
  • nbrelements. in case of a collection, the number of elements the tool should create with dummy values. the default is 1.
  • length. (numeric). the length of the dummy string value assigned to the annotated attribute. the default can be an arbitrary number, such as 5, 10, 20, etc.

so far these are the attributes i could think of. what do you think folks?

from http://tedone.typepad.com/blog/2011/03/podam-gathering-requirements.html

Requirement Attribute (computing) Data (computing) Dummy data Annotation

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Handle Secrets in Docker
  • Fargate vs. Lambda: The Battle of the Future
  • Spring Boot vs Eclipse MicroProfile: Resident Set Size (RSS) and Time to First Request (TFR) Comparative
  • Reliability Is Slowing You Down

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: