Search in sources :

Example 1 with UserGroupCallbackTaskCommand

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));
                }
            }
        }
    }
}
Also used : UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) XmlElements(javax.xml.bind.annotation.XmlElements) Type(java.lang.reflect.Type) AccessType(org.kie.internal.task.api.model.AccessType) TestType(org.jbpm.services.task.jaxb.AbstractTaskSerializationTest.TestType) ParameterizedType(java.lang.reflect.ParameterizedType) XmlElement(javax.xml.bind.annotation.XmlElement) Collection(java.util.Collection) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) TaskCommand(org.jbpm.services.task.commands.TaskCommand) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Collection (java.util.Collection)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlElements (javax.xml.bind.annotation.XmlElements)1 TaskCommand (org.jbpm.services.task.commands.TaskCommand)1 UserGroupCallbackTaskCommand (org.jbpm.services.task.commands.UserGroupCallbackTaskCommand)1 TestType (org.jbpm.services.task.jaxb.AbstractTaskSerializationTest.TestType)1 Test (org.junit.Test)1 AccessType (org.kie.internal.task.api.model.AccessType)1