Closed tanqiwei closed 3 years ago
Hi,
For the question #1, you ask Podam to create a map with 2 elements. So Podam will call I18nMapKeyStrategy.getValue() twice, which in its turn will return 2 random strings from set of 2 strings. Sometimes strings will identical, sometimes not. One way to fix it is to make a counter and return values in loop.
For the question #2, I do not understand what phrase "the final generated data" refers to.
Thanks, Daniil
What I mean is that my custom factory generates the value of the name
field of the Product
class, and the length of the map field of the i18nValue
returned by this value is 2. But in the end, the data generated by the podam factory corresponds to the product
variable obtained last in the example. The map length of the i18nValue
field corresponding to the value of the name
field of this variable is 5 (the default collection length of the podam factory). I found that the value generated by the custom factory still exists, but podam will fill the remaining length to the default specified length by default.
In the practice just now, I combined AttributeStrategy and annotations to achieve the generated data style I expect。But this annotation cannot be annotated by the PodamAnnotation annotation,Otherwise it will not take effect.
The podam tool is really easy to use, thank you for your team to develop this tool.
As far as I get StringI18n is produced in the type manufacturer by CommonStringI18nGenerateUtil.generateStringI18Default()
and CommonStringI18nGenerateUtil.generateStringI18n()
so if you say i18nValue
has 5 elements, it must be cause of something done in these methods. Since there is no listing for these methods I'm unable to say, why map size is 5.
You are welcome.
Thanks, Daniil
this generate util code is,Logically there are only two:
public class CommonStringI18nGenerateUtil {
public static StringI18n generateStringI18n(PodamStringI18nValue annotationStrategy, Set<Locale> locales) {
StringI18n stringI18n = new StringI18n();
stringI18n.setDefaultValue(generateString(annotationStrategy.stringValueLength()));
if (annotationStrategy.generateI18nMap()) {
if (annotationStrategy.mapKeyGenerateByLocales()) {
List<String> localeString = Arrays.stream(annotationStrategy.locales()).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(localeString)) {
Arrays.stream(annotationStrategy.locales())
.forEach(locale ->
stringI18n.setLocalizedValue(locale, generateString(annotationStrategy.stringValueLength())));
} else {
generateLocaleValueByLocales(locales, stringI18n, annotationStrategy.stringValueLength());
}
}
}
return stringI18n;
}
public static StringI18n generateStringI18Default(int stringLength, Set<Locale> locales) {
StringI18n stringI18n = new StringI18n();
stringI18n.setDefaultValue(CommonStringI18nGenerateUtil.generateString(stringLength));
CommonStringI18nGenerateUtil.generateLocaleValueByLocales(locales, stringI18n, stringLength);
return stringI18n;
}
public static void generateLocaleValueByLocales(Set<Locale> localeSet, StringI18n stringI18n, int stringLength) {
Optional.ofNullable(localeSet)
.filter(CollectionUtils::isNotEmpty)
.map(Collection::stream)
.ifPresent(
localeStream ->
localeStream.forEach(
locale ->
stringI18n.setLocalizedValue(locale.toString(),
generateString(stringLength))
)
);
}
public static String generateString(int length) {
StringBuilder buff = new StringBuilder();
while (buff.length() < length) {
buff.append(PodamUtils.getNiceCharacter());
}
return buff.toString();
}
}
StringI18n add a function:
public void setLocalizedValue(String locale, String localizedValue) {
this.i18nValue.put(locale, localizedValue);
}
Sorry, I lost track of this. From you code it looks like you fill the map based on content of Set<Locale> locales
, which comes from the constructor public StringI18nManufacturerImpl(Set<Locale> locales)
. So if map contains 5 elements, this means that the set also contains five elements.
Question1 :
for example.
I have a Pojo,The definition is as follows,
@Data
is lombok annotation:my map key strategy definition is:
but I find,when podam factory genenrate this pojo data.I found that the size of the map generated is not always a size of 2, but may be 1.
This behavior does not meet my expectations. I thought that when I specify the number of nbrElements, the generated data must be this number. I am not sure if this can be considered a bug.
Question2:
I defined an assembly structure, and then the structure is composed of some simple types. As follows:
I have a pojo ,example:
I defined an annotation as follows:
I write a manufacturer as follows:
I use it for example:
I found that the map in the name field generated by the factory itself has a key length of 2 (in line with my expectations), but in the final generated data, the factory seems to have filled the Map data with additional three that I did not expect. Values.
This does not meet my expectations, and I am not sure whether it is a bug or a problem with my use?