Search in sources :

Example 1 with FakeConnectorServiceFactory

use of org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorServiceFactory in project activemq-artemis by apache.

the class ConnectorsServiceTest method testConnectorsServiceUsesInjectedConnectorServiceFactory.

/**
 * Test that the connectors added via the service registry are added to the connectorsService,
 *
 * @throws Exception
 */
@Test
public void testConnectorsServiceUsesInjectedConnectorServiceFactory() throws Exception {
    ConnectorServiceConfiguration connectorServiceConfiguration = new ConnectorServiceConfiguration().setFactoryClassName(null).setParams(new HashMap<String, Object>()).setName("myfact");
    // Creates a fake connector service factory that returns the fake connector service object
    ConnectorService connectorService = new FakeConnectorService();
    FakeConnectorServiceFactory connectorServiceFactory = new FakeConnectorServiceFactory();
    serviceRegistry.addConnectorService(connectorServiceFactory, connectorServiceConfiguration);
    ConnectorsService connectorsService = new ConnectorsService(configuration, null, null, null, serviceRegistry);
    connectorsService.start();
    assertTrue(connectorsService.getConnectors().size() == 1);
    assertTrue(connectorsService.getConnectors().values().contains(connectorServiceFactory.getConnectorService()));
}
Also used : FakeConnectorServiceFactory(org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorServiceFactory) HashMap(java.util.HashMap) FakeConnectorService(org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorService) ConnectorServiceConfiguration(org.apache.activemq.artemis.core.config.ConnectorServiceConfiguration) ConnectorsService(org.apache.activemq.artemis.core.server.impl.ConnectorsService) FakeConnectorService(org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorService) ConnectorService(org.apache.activemq.artemis.core.server.ConnectorService) Test(org.junit.Test)

Example 2 with FakeConnectorServiceFactory

use of org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorServiceFactory in project activemq-artemis by apache.

the class ConnectorsServiceTest method testConnectorServiceUsedDirectly.

/**
 * Test that connectors can be created and destroyed directly.
 *
 * @throws Exception
 */
@Test
public void testConnectorServiceUsedDirectly() throws Exception {
    // Initial setup with existing connector service
    ConnectorServiceConfiguration connectorServiceConfiguration = new ConnectorServiceConfiguration().setFactoryClassName(FakeConnectorServiceFactory.class.getCanonicalName()).setParams(new HashMap<String, Object>()).setName("myfact");
    configuration.setConnectorServiceConfigurations(Arrays.asList(connectorServiceConfiguration));
    ConnectorsService connectorsService = new ConnectorsService(configuration, null, null, null, serviceRegistry);
    connectorsService.start();
    assertEquals(1, connectorsService.getConnectors().size());
    // Add with same name
    FakeConnectorServiceFactory connectorServiceFactory = new FakeConnectorServiceFactory();
    try {
        connectorsService.createService(connectorServiceConfiguration, connectorServiceFactory);
        assertTrue("Expected exception when creating service with same name", false);
    } catch (Exception e) {
    }
    // Add unique with same factory
    ConnectorServiceConfiguration additionalServiceConfiguration = new ConnectorServiceConfiguration().setFactoryClassName(FakeConnectorServiceFactory.class.getCanonicalName()).setParams(new HashMap<String, Object>()).setName("myfact2");
    connectorsService.createService(additionalServiceConfiguration, connectorServiceFactory);
    assertEquals(2, connectorsService.getConnectors().size());
    // Destroy existing connector services
    connectorsService.destroyService("myfact");
    assertEquals(1, connectorsService.getConnectors().size());
    connectorsService.destroyService("myfact2");
    assertEquals(0, connectorsService.getConnectors().size());
    // Destroy non-existing connector service
    try {
        connectorsService.destroyService("myfact");
        assertTrue("Expected exception when destroying non-existing service", false);
    } catch (Exception e) {
    }
}
Also used : FakeConnectorServiceFactory(org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorServiceFactory) HashMap(java.util.HashMap) ConnectorServiceConfiguration(org.apache.activemq.artemis.core.config.ConnectorServiceConfiguration) ConnectorsService(org.apache.activemq.artemis.core.server.impl.ConnectorsService) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 ConnectorServiceConfiguration (org.apache.activemq.artemis.core.config.ConnectorServiceConfiguration)2 ConnectorsService (org.apache.activemq.artemis.core.server.impl.ConnectorsService)2 FakeConnectorServiceFactory (org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorServiceFactory)2 Test (org.junit.Test)2 ConnectorService (org.apache.activemq.artemis.core.server.ConnectorService)1 FakeConnectorService (org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorService)1