Thank you for your email! Wow, that's a lot to go through :-) Let me try to
answer your questions where I can...I must say that you highlighted some
points I didn't even consider...
1) This is, strangely enough, one thing I didn't think of. Will add it as a
new requirement for next version 2.1.0.
http://www.jemos.eu/jira/browse/PDM-25 has been created for this.
2) All classes in the java/javax namespace (e.g. java.math.BigDecimal) are
supported provided they offer either a non-argument constructor or, if no
constructor are available, a static factory (with or without arguments). In
the case of BigDecimal, currently this is not supported because it has
public constructors but they accept arguments. I just spotted a "// TODO To
provide support for constructors with argument types" in the exact point in
the code which should have populated a BigDecimal. I will add this as the
next major bug fix. http://www.jemos.eu/jira/browse/PDM-24 has been created
for this. I tried adding a BigDecimal to one of the test POJOs and the
application didn't crash. Currently the workaround would be to have PODAM to
fill your POJO and then you could invoke the setter for BigDecimal (or other
non-supported class) manually on the returned POJO.
3) If one wants to customise numeric/string values through annotations the
assumption is that they have control of the source code, yes. I couldn't
think of a way of annotating classes? Have you got any ideas on how this
could be solved?
4) The @PodamStringValue annotation allows one to define exactly the value
to assign to a string attribute. So on a postcode one could write:
@PodamStringValue(strValue="W1ECP") and similarly on a zipcode another value
could be specified.
And for your next comment on "lowering" the strategy by providing a
class/field pair, I'm not sure I entirely understand what you have got in
mind. Would you be able to drill down a little and come back with a concrete
(yet simple) example?
JSR-303 seems very interesting. It would be nice if PODAM could provide
support for JSR-303, don't you think ;-) This seems like a big piece of
work. I have put it down as an Epic: http://www.jemos.eu/jira/browse/PDM-26.
Vote for it if you would like to see it implemented.
I hope I have answered all your questions. If you want to monitor the
progress on the issues I created above, please feel free to create an
account on Jemos JIRA at: http://www.jemos.eu/jira and watch the issues of
your interest. Better yet, feel free to fork PODAM from GitHub and
contribute the changes yourself ;-)
Regards,
Marco
You will be pleased to know that I fixed
http://www.jemos.eu/jira/browse/PDM-24
I added a BigDecimal to the OneDimensionalTestPojo class and it returns
filled with values. I had to adopt an "adaptive" strategy: I try each public
constructor until I found one that works, or I return null. In case of
BigDecimal, the constructors which accepted a MathContext didn't work, but
PODAM chose the one which accepts a double and it worked fine.
Regards,
Marco
-----Original Message-----
From: po...@googlegroups.com [mailto:po...@googlegroups.com] On Behalf Of
Gary Fleming
Sent: 02 May 2011 19:20
To: PODAM
Subject: [PODAM - Google] Questions about non-primitive/String types.
As for you points, I think annotations are the way to go, maybe with a bit
more flexibility. PODAM supports instantiation of any class (in the
java/javax namespace or not) with a public constructor (with or without
arguments). The fix I put there for BigDecimal fixed this. For those cases
when one wants full control, I was thinking of an annotation of this kind:
@PodamValue( dataProvider=AddressProviderStrategy.class)
private Address address;
public class AddressProviderStrategy implements PodamValueProviderStrategy {
public Object getValue() {
//Fill your Address object here
}
}
public interface PodamValueProviderStrategy {
public Object getValue();
}
Then at runtime, when PODAM found a @PodamValue annotation, it would create
an instance of AddressProviderStrategy like so:
PodamValueProviderStrategy strategy = new AddressProviderStrategy();//PODAM
would actually use introspection to do this
Address address = (Address) strategy.getValue();//PODAM would actually use
introspection to do this
JSR-303 is a bigger chunk of work. Although it would add immensely to the
market value of PODAM I want first to see a user base using it, then voting
for the JSR-303 Epic, and then I would implement it.
Thank you for your feedbacks and please keep them coming.
A simple adjustment to the code allows now PODAM to do what you suggested at
1). I added a JodaTimePojo to the test suite. The POJO contains an instance
variable of type LocalDate. PODAM is able to create an instance (although
with random values for the LocalDate object, as one might guess). The "bug"
is referred in http://www.jemos.eu/jira/browse/PDM-27 and the code is
available in the latest SNAPSHOT, on GitHub. Tomorrow I will release
2.2.0.RELEASE, which contains this bug fix and also the possibility to fix
the value for numeric attributes (the String ones were already covered) with
a numValue attribute in each primitive type annotation.
Regards,
Marco
As for 2) I'd like to hear more concrete suggestions, otherwise I find
difficult to picture what you've got in mind. Please feel free to fork the
code and suggest pull requests.
--
You received this message because you are subscribed to the Google Groups "PODAM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to podam+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public class DataPopulatorFactory {
private final PodamFactory factory = new PodamFactoryImpl();
public <T> T populatePojo(Class<T> pojoClass) {
DataProviderStrategy strategy = factory.getStrategy();
Random random = new Random();
if (pojoClass.isAssignableFrom(LocalDate.class)) {
return (T) new LocalDate(1950 + random.nextInt(100), 1 + random.nextInt(12), 1 + random.nextInt(29));
} else if (pojoClass.isAssignableFrom(DateTime.class)) {
long instant = 1000000 + random.nextInt(500000);
return (T) new DateTime(instant);
} else {
return factory.manufacturePojo(pojoClass);
}
}
This code reminds me to the one that you have inside PodamFactoryImpl.fillCollection(...), where you also use "isAssignableFrom":
if (null != elementStrategy && ObjectStrategy.class.isAssignableFrom(elementStrategy.getClass())
Would you consider to enlarge the Strategy interface to support both Joda LocalDate and Joda DateTime, or you rather prefer to keep it with primitive types? If so, I could contribute to implement it.
Thanks for sharing your framework, it's been really valuable to me.
@Override
public <T> Class<? extends T> getSpecificClass(
Class<T> nonInstantiatableClass) {
Class<? extends T> found = (Class<? extends T>) specificTypes.get(nonInstantiatableClass);
if (found == null) {
found = nonInstantiatableClass;
}
return found;
}