Search in sources :

Example 1 with XStreamJsonMarshaller

use of com.adaptris.core.XStreamJsonMarshaller in project interlok by adaptris.

the class AdapterRegistryTest method testGetClassDescription.

@Test
public void testGetClassDescription() throws Exception {
    Properties custom = new Properties();
    AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(custom));
    String addMetadataServiceJsonDef = myAdapterRegistry.getClassDefinition("com.adaptris.core.services.metadata.AddMetadataService");
    ClassDescriptor addMetadataServiceDef = (ClassDescriptor) new XStreamJsonMarshaller().unmarshal(addMetadataServiceJsonDef);
    assertEquals("com.adaptris.core.services.metadata.AddMetadataService", addMetadataServiceDef.getClassName());
    assertEquals("add-metadata-service", addMetadataServiceDef.getAlias());
    assertEquals("Add Static Metadata to a Message", addMetadataServiceDef.getSummary());
    assertEquals("service,metadata", addMetadataServiceDef.getTags());
    assertEquals(2, addMetadataServiceDef.getClassDescriptorProperties().size());
    assertEquals("service", addMetadataServiceDef.getClassType());
}
Also used : XStreamJsonMarshaller(com.adaptris.core.XStreamJsonMarshaller) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with XStreamJsonMarshaller

use of com.adaptris.core.XStreamJsonMarshaller in project interlok by adaptris.

the class AdapterRegistryTest method testClassDescriptionGetSubTypes.

@Test
public void testClassDescriptionGetSubTypes() throws Exception {
    Properties custom = new Properties();
    AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(custom));
    String adapterRegistryTestJsonDef = myAdapterRegistry.getClassDefinition(ReformatMetadata.class.getCanonicalName());
    ClassDescriptor adapterRegistryTestDef = (ClassDescriptor) new XStreamJsonMarshaller().unmarshal(adapterRegistryTestJsonDef);
    assertTrue(adapterRegistryTestDef.getSubTypes().size() > 0);
    assertTrue(adapterRegistryTestDef.getSubTypes().contains(ReformatDateService.class.getName()));
}
Also used : XStreamJsonMarshaller(com.adaptris.core.XStreamJsonMarshaller) ReformatMetadata(com.adaptris.core.services.metadata.ReformatMetadata) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with XStreamJsonMarshaller

use of com.adaptris.core.XStreamJsonMarshaller in project interlok by adaptris.

the class AdapterRegistry method getClassDefinition.

@Override
public String getClassDefinition(String className) throws CoreException {
    final ClassDescriptor classDescriptor = new ClassDescriptor(className);
    try {
        Class<?> clazz = Class.forName(className);
        classDescriptor.setClassType(ClassDescriptor.ClassType.getTypeForClass(clazz).name().toLowerCase());
        List<String> displayOrder = new ArrayList<>();
        for (Annotation annotation : clazz.getAnnotations()) {
            if (XStreamAlias.class.isAssignableFrom(annotation.annotationType())) {
                classDescriptor.setAlias(((XStreamAlias) annotation).value());
            } else if (ComponentProfile.class.isAssignableFrom(annotation.annotationType())) {
                classDescriptor.setTags(((ComponentProfile) annotation).tag());
                classDescriptor.setSummary(((ComponentProfile) annotation).summary());
            } else if (DisplayOrder.class.isAssignableFrom(annotation.annotationType())) {
                displayOrder = Arrays.asList(((DisplayOrder) annotation).order());
            }
        }
        for (Field field : clazz.getDeclaredFields()) {
            if ((!Modifier.isStatic(field.getModifiers())) && (field.getDeclaredAnnotation(Transient.class) == null)) {
                // if we're not transient
                ClassDescriptorProperty fieldProperty = new ClassDescriptorProperty();
                fieldProperty.setOrder(displayOrder.contains(field.getName()) ? displayOrder.indexOf(field.getName()) + 1 : 999);
                fieldProperty.setAdvanced(false);
                fieldProperty.setClassName(field.getType().getName());
                fieldProperty.setType(field.getType().getSimpleName());
                fieldProperty.setName(field.getName());
                fieldProperty.setAutoPopulated(field.getDeclaredAnnotation(AutoPopulated.class) != null);
                fieldProperty.setNullAllowed(field.getDeclaredAnnotation(NotNull.class) != null);
                for (Annotation annotation : field.getDeclaredAnnotations()) {
                    if (AdvancedConfig.class.isAssignableFrom(annotation.annotationType())) {
                        fieldProperty.setAdvanced(true);
                    } else if (InputFieldDefault.class.isAssignableFrom(annotation.annotationType())) {
                        fieldProperty.setDefaultValue(((InputFieldDefault) annotation).value());
                    }
                }
                classDescriptor.getClassDescriptorProperties().add(fieldProperty);
            }
        }
        try (ScanResult result = new ClassGraph().enableAllInfo().blacklistPackages(FCS_BLACKLIST).scan()) {
            List<String> subclassNames = result.getSubclasses(className).getNames();
            for (String subclassName : subclassNames) {
                classDescriptor.getSubTypes().add(subclassName);
            }
        }
    } catch (ClassNotFoundException e) {
        throw new CoreException(e);
    }
    return new XStreamJsonMarshaller().marshal(classDescriptor);
}
Also used : ComponentProfile(com.adaptris.annotation.ComponentProfile) InputFieldDefault(com.adaptris.annotation.InputFieldDefault) ScanResult(io.github.classgraph.ScanResult) DisplayOrder(com.adaptris.annotation.DisplayOrder) ClassGraph(io.github.classgraph.ClassGraph) ArrayList(java.util.ArrayList) URLString(com.adaptris.util.URLString) Annotation(java.lang.annotation.Annotation) Field(java.lang.reflect.Field) XStreamJsonMarshaller(com.adaptris.core.XStreamJsonMarshaller) CoreException(com.adaptris.core.CoreException) Transient(java.beans.Transient)

Example 4 with XStreamJsonMarshaller

use of com.adaptris.core.XStreamJsonMarshaller in project interlok by adaptris.

the class ExampleEventHandlerCase method testSetMarshaller.

@Test
public void testSetMarshaller() throws Exception {
    EventHandlerBase eventHandler = applyConfiguration(newEventHandler(getName()));
    XStreamJsonMarshaller marshaller = (XStreamJsonMarshaller) marshallerFactory.createMarshaller(MarshallingOutput.JSON);
    eventHandler.setMarshaller(marshaller);
    assertEquals(marshaller, eventHandler.getMarshaller());
    assertEquals(marshaller, eventHandler.currentMarshaller());
    eventHandler.setMarshaller(null);
    assertEquals(DefaultMarshaller.getDefaultMarshaller(), eventHandler.currentMarshaller());
}
Also used : XStreamJsonMarshaller(com.adaptris.core.XStreamJsonMarshaller) EventHandlerBase(com.adaptris.core.EventHandlerBase) Test(org.junit.Test)

Aggregations

XStreamJsonMarshaller (com.adaptris.core.XStreamJsonMarshaller)4 URLString (com.adaptris.util.URLString)3 Test (org.junit.Test)3 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)2 JunitBootstrapProperties (com.adaptris.core.stubs.JunitBootstrapProperties)2 Properties (java.util.Properties)2 ComponentProfile (com.adaptris.annotation.ComponentProfile)1 DisplayOrder (com.adaptris.annotation.DisplayOrder)1 InputFieldDefault (com.adaptris.annotation.InputFieldDefault)1 CoreException (com.adaptris.core.CoreException)1 EventHandlerBase (com.adaptris.core.EventHandlerBase)1 ReformatMetadata (com.adaptris.core.services.metadata.ReformatMetadata)1 ClassGraph (io.github.classgraph.ClassGraph)1 ScanResult (io.github.classgraph.ScanResult)1 Transient (java.beans.Transient)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1