Search in sources :

Example 36 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class BrokerManager method start.

/**
 * Starting the broker
 */
public static void start() {
    try {
        StartupContext startupContext = new StartupContext();
        initConfigProvider(startupContext);
        BrokerConfigProvider service = startupContext.getService(BrokerConfigProvider.class);
        BrokerConfiguration brokerConfiguration = service.getConfigurationObject(BrokerConfiguration.NAMESPACE, BrokerConfiguration.class);
        DataSource dataSource = getDataSource(brokerConfiguration.getDataSource());
        startupContext.registerService(DataSource.class, dataSource);
        restServer = new BrokerRestServer(startupContext);
        broker = new Broker(startupContext);
        broker.startMessageDelivery();
        amqpServer = new Server(startupContext);
        amqpServer.start();
        restServer.start();
        loadUsers();
    } catch (Exception e) {
        log.error("Error while starting broker", e);
    }
}
Also used : StartupContext(org.wso2.broker.common.StartupContext) BrokerRestServer(org.wso2.broker.rest.BrokerRestServer) Broker(org.wso2.broker.core.Broker) Server(org.wso2.broker.amqp.Server) BrokerRestServer(org.wso2.broker.rest.BrokerRestServer) BrokerConfiguration(org.wso2.broker.core.configuration.BrokerConfiguration) BrokerConfigProvider(org.wso2.broker.common.BrokerConfigProvider) ConfigurationException(org.wso2.carbon.config.ConfigurationException) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource)

Example 37 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testDeleteAPIForException.

@Test(expected = GatewayException.class)
public void testDeleteAPIForException() throws GatewayException, ContainerBasedGatewayException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    Broker broker = Mockito.mock(BrokerImpl.class, Mockito.RETURNS_DEEP_STUBS);
    BrokerUtil.initialize(broker);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    Mockito.doThrow(ContainerBasedGatewayException.class).when(containerBasedGatewayGenerator).removeContainerBasedGateway(Mockito.any(), Mockito.any());
    List<String> labels = new ArrayList<>();
    labels.add("label");
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(labels).build();
    apiGatewayPublisher.deleteAPI(api);
}
Also used : Broker(org.wso2.carbon.apimgt.core.api.Broker) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 38 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testDeleteAPIWhenLabelAreEmpty.

@Test
public void testDeleteAPIWhenLabelAreEmpty() throws GatewayException, ContainerBasedGatewayException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    Broker broker = Mockito.mock(BrokerImpl.class, Mockito.RETURNS_DEEP_STUBS);
    BrokerUtil.initialize(broker);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    List<String> labels = new ArrayList<>();
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(labels).build();
    apiGatewayPublisher.deleteAPI(api);
    Mockito.verify(containerBasedGatewayGenerator, Mockito.times(0)).removeContainerBasedGateway("label", api);
}
Also used : Broker(org.wso2.carbon.apimgt.core.api.Broker) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 39 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testDeleteAPIWhenAPIHasOwnGateway.

@Test
public void testDeleteAPIWhenAPIHasOwnGateway() throws GatewayException, ContainerBasedGatewayException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    Broker broker = Mockito.mock(BrokerImpl.class, Mockito.RETURNS_DEEP_STUBS);
    BrokerUtil.initialize(broker);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    List<String> labels = new ArrayList<>();
    labels.add("label");
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(labels).build();
    apiGatewayPublisher.deleteAPI(api);
    Mockito.verify(containerBasedGatewayGenerator, Mockito.times(1)).removeContainerBasedGateway("label", api);
}
Also used : Broker(org.wso2.carbon.apimgt.core.api.Broker) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 40 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method deleteApplication.

@Override
public void deleteApplication(String applicationId) throws GatewayException {
    if (applicationId != null) {
        ApplicationEvent applicationEvent = new ApplicationEvent(APIMgtConstants.GatewayEventTypes.APPLICATION_DELETE);
        applicationEvent.setApplicationId(applicationId);
        publishToStoreTopic(applicationEvent);
        if (log.isDebugEnabled()) {
            log.debug("Application : " + applicationId + " deleted event has been successfully published " + "to broker");
        }
    }
}
Also used : ApplicationEvent(org.wso2.carbon.apimgt.core.models.events.ApplicationEvent)

Aggregations

Test (org.testng.annotations.Test)19 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)19 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)16 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)16 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)16 Environment (org.wso2.carbon.apimgt.api.model.Environment)15 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)13 ArrayList (java.util.ArrayList)11 SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)9 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 DeployerException (org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException)7 NotifierException (org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)7 IOException (java.io.IOException)6 Broker (org.wso2.carbon.apimgt.core.api.Broker)6 Test (org.junit.Test)5 API (org.wso2.carbon.apimgt.core.models.API)5 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4 ExternalGatewayDeployer (org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer)4 JsonParser (com.google.gson.JsonParser)3