Search in sources :

Example 31 with JunitBootstrapProperties

use of com.adaptris.core.stubs.JunitBootstrapProperties in project interlok by adaptris.

the class ConfigurationPreProcessorFactoryTest method testBootstrapProperties_SingleConfiguredPreProcessors.

@Test
public void testBootstrapProperties_SingleConfiguredPreProcessors() throws Exception {
    // Bypass the searching for meta-inf property files
    when(mockPropertyLoader.loadPropertyFile(anyString())).thenReturn(sampleProperties);
    preProcessorFactory.setPropertyLoader(mockPropertyLoader);
    Properties props = new Properties();
    props.put("preProcessors", "testPreProcessor");
    ConfigPreProcessors loaded = preProcessorFactory.load(new JunitBootstrapProperties(props));
    assertEquals(1, loaded.size());
    assertEquals(DummyConfigurationPreProcessor.class.getCanonicalName(), loaded.toArray()[0].getClass().getName());
}
Also used : JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Test(org.junit.Test)

Example 32 with JunitBootstrapProperties

use of com.adaptris.core.stubs.JunitBootstrapProperties in project interlok by adaptris.

the class AdapterRegistryTest method testMultiPreProcessorCalled.

@Test
public void testMultiPreProcessorCalled() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    File filename = deleteLater(adapter);
    DefaultMarshaller.getDefaultMarshaller().marshal(adapter, filename);
    AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
    AdapterBuilder builder = new ArrayList<AdapterBuilder>(myAdapterRegistry.builders()).get(0);
    builder.setConfigurationPreProcessorLoader(mockPreProcessorLoader);
    ConfigPreProcessors preProcessorsList = new ConfigPreProcessors();
    preProcessorsList.add(mockPreProcessor);
    preProcessorsList.add(mockPreProcessor);
    preProcessorsList.add(mockPreProcessor);
    when(mockPreProcessorLoader.load(any(BootstrapProperties.class))).thenReturn(preProcessorsList);
    when(mockPreProcessor.process(any(String.class))).thenReturn(FileUtils.readFileToString(filename));
    myAdapterRegistry.createAdapter(new URLString(filename));
    // Make sure our pre-processors are called - even though our pre-processors do nothing!
    verify(mockPreProcessor, times(3)).process(any(String.class));
}
Also used : ConfigPreProcessors(com.adaptris.core.config.ConfigPreProcessors) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) File(java.io.File) URLString(com.adaptris.util.URLString) Test(org.junit.Test)

Example 33 with JunitBootstrapProperties

use of com.adaptris.core.stubs.JunitBootstrapProperties in project interlok by adaptris.

the class AdapterRegistryTest method testDestroyAdapter_MBean.

@Test
public void testDestroyAdapter_MBean() throws Exception {
    AdapterRegistryMBean myAdapterRegistry = AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
    int expectedCount = myAdapterRegistry.getAdapters().size();
    ObjectName objName = myAdapterRegistry.createAdapter(xml);
    assertNotNull(myAdapterRegistry.getBuilder(objName));
    AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
    manager.requestStart();
    myAdapterRegistry.destroyAdapter(manager);
    try {
        myAdapterRegistry.getBuilder(objName);
        fail();
    } catch (InstanceNotFoundException expected) {
    }
    assertFalse(mBeanServer.isRegistered(objName));
    assertEquals(expectedCount, myAdapterRegistry.getAdapters().size());
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 34 with JunitBootstrapProperties

use of com.adaptris.core.stubs.JunitBootstrapProperties in project interlok by adaptris.

the class AdapterRegistryTest method testAddAdapterMBean.

@Test
public void testAddAdapterMBean() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObjectName = adapterManager.createObjectName();
    adapterManager.registerMBean();
    AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
    int expectedCount = myAdapterRegistry.getAdapters().size() + 1;
    myAdapterRegistry.addAdapter(adapterManager);
    assertEquals(ClosedState.getInstance(), adapterManager.getComponentState());
    assertEquals(expectedCount, myAdapterRegistry.getAdapters().size());
}
Also used : JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 35 with JunitBootstrapProperties

use of com.adaptris.core.stubs.JunitBootstrapProperties in project interlok by adaptris.

the class AdapterRegistryTest method testProxy_DestroyAdapter_ObjectName.

@Test
public void testProxy_DestroyAdapter_ObjectName() throws Exception {
    AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
    int expectedCount = myAdapterRegistry.getAdapters().size();
    ObjectName objName = myAdapterRegistry.createAdapter(xml);
    assertTrue(mBeanServer.isRegistered(objName));
    assertEquals(expectedCount + 1, myAdapterRegistry.getAdapters().size());
    AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
    manager.requestStart();
    myAdapterRegistry.destroyAdapter(objName);
    assertFalse(mBeanServer.isRegistered(objName));
    assertEquals(expectedCount, myAdapterRegistry.getAdapters().size());
}
Also used : JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

JunitBootstrapProperties (com.adaptris.core.stubs.JunitBootstrapProperties)55 Properties (java.util.Properties)55 Test (org.junit.Test)55 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)49 URLString (com.adaptris.util.URLString)43 Adapter (com.adaptris.core.Adapter)39 ObjectName (javax.management.ObjectName)35 File (java.io.File)20 CoreException (com.adaptris.core.CoreException)4 DefaultEventHandler (com.adaptris.core.DefaultEventHandler)2 XStreamJsonMarshaller (com.adaptris.core.XStreamJsonMarshaller)2 ConfigPreProcessors (com.adaptris.core.config.ConfigPreProcessors)2 AdapterShutdownEvent (com.adaptris.core.event.AdapterShutdownEvent)2 StaticMockEventProducer (com.adaptris.core.stubs.StaticMockEventProducer)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 NullConnection (com.adaptris.core.NullConnection)1 DummyConfigurationPreProcessor (com.adaptris.core.config.DummyConfigurationPreProcessor)1 ReformatMetadata (com.adaptris.core.services.metadata.ReformatMetadata)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1