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());
}
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()));
}
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);
}
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());
}
Aggregations