use of org.jbpm.services.task.commands.UserGroupCallbackTaskCommand in project jbpm by kiegroup.
the class JaxbTaskSerializationTest method compositeCommandXmlElementsAnnoTest.
@Test
public void compositeCommandXmlElementsAnnoTest() throws Exception {
Field[] comCmdFields = CompositeCommand.class.getDeclaredFields();
for (Field field : comCmdFields) {
XmlElements xmlElemsAnno = field.getAnnotation(XmlElements.class);
if (xmlElemsAnno != null) {
Set<Class<? extends TaskCommand>> taskCmdSubTypes = reflections.getSubTypesOf(TaskCommand.class);
Set<Class<? extends UserGroupCallbackTaskCommand>> userGrpTaskCmdSubTypes = reflections.getSubTypesOf(UserGroupCallbackTaskCommand.class);
taskCmdSubTypes.addAll(userGrpTaskCmdSubTypes);
Class[] exclTaskCmds = { UserGroupCallbackTaskCommand.class, CompositeCommand.class, GetCurrentTxTasksCommand.class };
taskCmdSubTypes.removeAll(Arrays.asList(exclTaskCmds));
for (XmlElement xmlElemAnno : xmlElemsAnno.value()) {
Class xmlElemAnnoType = xmlElemAnno.type();
assertTrue(xmlElemAnnoType.getName() + " does not extend the " + TaskCommand.class.getSimpleName() + " class!", taskCmdSubTypes.contains(xmlElemAnnoType));
}
for (XmlElement xmlElemAnno : xmlElemsAnno.value()) {
Class xmlElemAnnoType = xmlElemAnno.type();
taskCmdSubTypes.remove(xmlElemAnnoType);
}
if (!taskCmdSubTypes.isEmpty()) {
System.out.println("##### " + taskCmdSubTypes.iterator().next().getCanonicalName());
fail("(" + taskCmdSubTypes.iterator().next().getSimpleName() + ") Not all " + TaskCommand.class.getSimpleName() + " sub types have been added to the @XmlElements in the CompositeCommand." + field.getName() + " field.");
}
} else {
assertFalse("TaskCommand fields need to be annotated with @XmlElements annotations!", TaskCommand.class.equals(field.getType()));
if (field.getType().isArray()) {
Class arrElemType = field.getType().getComponentType();
if (arrElemType != null) {
assertFalse("TaskCommand fields (CompositeCommand." + field.getName() + ") need to be annotated with @XmlElements annotations!", TaskCommand.class.equals(arrElemType));
}
} else if (Collection.class.isAssignableFrom(field.getType())) {
ParameterizedType fieldGenericType = (ParameterizedType) field.getGenericType();
Type listType = fieldGenericType.getActualTypeArguments()[0];
if (listType != null) {
assertFalse("TaskCommand fields (CompositeCommand." + field.getName() + ") need to be annotated with @XmlElements annotations!", TaskCommand.class.equals(listType));
}
}
}
}
}
Aggregations