Java Code Examples for org.camunda.spin.DataFormats#loadDataFormats()

The following examples show how to use org.camunda.spin.DataFormats#loadDataFormats() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataFormatLoadingTest.java    From camunda-spin with Apache License 2.0 6 votes vote down vote up
@Test
@PrepareForTest(DataFormats.class)
public void testConfigureDataFormatWithConfiguratorList() {
  // given a custom data format provider that is returned by the service loader API
  mockProviders(new CustomDataFormatProvider());
  mockConfigurators();
  DataFormatConfigurator configurator = new ExampleCustomDataFormatConfigurator();

  // when a list of data format configurators is passed to the "load" method
  DataFormats.loadDataFormats(DataFormats.class.getClassLoader(),
                              Collections.singletonList(configurator));

  // then the configuration was applied
  ExampleCustomDataFormat customFormat = (ExampleCustomDataFormat) DataFormats
      .getDataFormat(CustomDataFormatProvider.NAME);
  assertThat(customFormat.getProperty())
      .isEqualTo(ExampleCustomDataFormatConfigurator.UPDATED_PROPERTY);
}
 
Example 2
Source File: SpringBootSpinProcessEnginePlugin.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
protected void loadSpringBootDataFormats(ClassLoader classloader) {
  List<DataFormatConfigurator> configurators = new ArrayList<>();

  // add the auto-config Jackson Java 8 module configurators
  dataFormatConfiguratorJsr310.ifPresent(configurator -> configurators.add(configurator));
  dataFormatConfiguratorParameterNames.ifPresent(configurator -> configurators.add(configurator));
  dataFormatConfiguratorJdk8.ifPresent(configurator -> configurators.add(configurator));

  // next, add any configurators defined in the spring.factories file
  configurators.addAll(SpringFactoriesLoader.loadFactories(DataFormatConfigurator.class, classloader));

  DataFormats.loadDataFormats(classloader, configurators);
}
 
Example 3
Source File: SpringBootSpinProcessEnginePlugin.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void loadSpringBootDataFormats(ClassLoader classloader) {
  List<DataFormatConfigurator> configurators = new ArrayList<>();

  // add the auto-config Jackson Java 8 module configurators
  dataFormatConfiguratorJsr310.ifPresent(configurator -> configurators.add(configurator));
  dataFormatConfiguratorParameterNames.ifPresent(configurator -> configurators.add(configurator));
  dataFormatConfiguratorJdk8.ifPresent(configurator -> configurators.add(configurator));

  // next, add any configurators defined in the spring.factories file
  configurators.addAll(SpringFactoriesLoader.loadFactories(DataFormatConfigurator.class, classloader));

  DataFormats.loadDataFormats(classloader, configurators);
}
 
Example 4
Source File: SpinProcessEnginePluginTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testPluginDoesNotRegisterXmlSerializerIfNotPresentInClasspath() throws IOException {
  ClassLoader mockClassloader = Mockito.mock(ClassLoader.class);
  Mockito.when(mockClassloader.getResources(Mockito.anyString())).thenReturn(Collections.enumeration(Collections.<URL>emptyList()));
  DataFormats.loadDataFormats(mockClassloader);
  ProcessEngineConfigurationImpl mockConfig = Mockito.mock(ProcessEngineConfigurationImpl.class);
  DefaultVariableSerializers serializers = new DefaultVariableSerializers();
  Mockito.when(mockConfig.getVariableSerializers()).thenReturn(serializers);
  new SpinProcessEnginePlugin().registerSerializers(mockConfig);

  assertTrue(serializers.getSerializerByName(XmlValueType.TYPE_NAME) == null);
}
 
Example 5
Source File: SpinProcessEnginePluginTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testPluginDoesNotRegisterJsonSerializerIfNotPresentInClasspath() throws IOException {
  ClassLoader mockClassloader = Mockito.mock(ClassLoader.class);
  Mockito.when(mockClassloader.getResources(Mockito.anyString())).thenReturn(Collections.enumeration(Collections.<URL>emptyList()));
  DataFormats.loadDataFormats(mockClassloader);
  ProcessEngineConfigurationImpl mockConfig = Mockito.mock(ProcessEngineConfigurationImpl.class);
  DefaultVariableSerializers serializers = new DefaultVariableSerializers();
  Mockito.when(mockConfig.getVariableSerializers()).thenReturn(serializers);
  new SpinProcessEnginePlugin().registerSerializers(mockConfig);

  assertTrue(serializers.getSerializerByName(JsonValueType.TYPE_NAME) == null);
}
 
Example 6
Source File: SpinProcessEnginePluginTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testPluginRegistersXmlSerializerIfPresentInClasspath(){
  DataFormats.loadDataFormats(null);
  ProcessEngineConfigurationImpl mockConfig = Mockito.mock(ProcessEngineConfigurationImpl.class);
  Mockito.when(mockConfig.getVariableSerializers()).thenReturn(processEngineConfiguration.getVariableSerializers());
  new SpinProcessEnginePlugin().registerSerializers(mockConfig);

  assertTrue(processEngineConfiguration.getVariableSerializers().getSerializerByName(XmlValueType.TYPE_NAME) instanceof XmlValueSerializer);
}
 
Example 7
Source File: SpinProcessEnginePluginTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testPluginRegistersJsonSerializerIfPresentInClasspath(){
  DataFormats.loadDataFormats(null);
  ProcessEngineConfigurationImpl mockConfig = Mockito.mock(ProcessEngineConfigurationImpl.class);
  Mockito.when(mockConfig.getVariableSerializers()).thenReturn(processEngineConfiguration.getVariableSerializers());
  new SpinProcessEnginePlugin().registerSerializers(mockConfig);

  assertTrue(processEngineConfiguration.getVariableSerializers().getSerializerByName(JsonValueType.TYPE_NAME) instanceof JsonValueSerializer);
}
 
Example 8
Source File: SpinProcessEnginePlugin.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
  // use classloader which loaded the plugin
  ClassLoader classloader = ClassLoaderUtil.getClassloader(SpinProcessEnginePlugin.class);
  DataFormats.loadDataFormats(classloader);
}