Search in sources :

Example 6 with TaskManager

use of org.apache.synapse.task.TaskManager in project wso2-synapse by wso2.

the class TaskManagerFactoryTest method testCreateTaskManager2.

/**
 * test createTaskManager with parameter specified for OMElement
 *
 * @throws XMLStreamException - XMLStreamException.
 */
@Test
public void testCreateTaskManager2() throws XMLStreamException {
    String inputXML = "<taskManager provider=\"org.apache.synapse.startup.quartz.QuartzTaskManager\">" + "<parameter xmlns=\"http://ws.apache.org/ns/synapse\"  name =\"test\"> test </parameter>" + "</taskManager>";
    OMElement element = AXIOMUtil.stringToOM(inputXML);
    TaskManager taskManager = TaskManagerFactory.createTaskManager(element, null);
    Assert.assertTrue("TaskManager is not created.", taskManager instanceof QuartzTaskManager);
}
Also used : QuartzTaskManager(org.apache.synapse.startup.quartz.QuartzTaskManager) TaskManager(org.apache.synapse.task.TaskManager) QuartzTaskManager(org.apache.synapse.startup.quartz.QuartzTaskManager) OMElement(org.apache.axiom.om.OMElement) Test(org.junit.Test)

Example 7 with TaskManager

use of org.apache.synapse.task.TaskManager in project wso2-synapse by wso2.

the class TaskManagerSerializerTest method testCase.

/**
 * Test serializetaskManager method by asserting resulting OMElement.
 *
 * @throws XMLStreamException
 */
@Test
public void testCase() throws XMLStreamException {
    String input = "<template xmlns=\"http://ws.apache.org/ns/synapse\" name=\"HelloWordLogger\">\n" + "   <sequence>\n" + "      <log level=\"full\">\n" + "         <property xmlns:ns2=\"http://org.apache.synapse/xsd\" name=\"message\" " + "expression=\"$func:message\"></property>\n" + "      </log>\n" + "   </sequence>\n" + "</template>";
    OMElement element = AXIOMUtil.stringToOM(input);
    TaskManager taskManager = new QuartzTaskManager();
    Properties properties = new Properties();
    properties.setProperty("name", "testName");
    taskManager.setConfigurationProperties(properties);
    OMElement omElement = TaskManagerSerializer.serializetaskManager(element, taskManager);
    Assert.assertEquals("asserting localName inserted by the method", "taskManager", omElement.getLocalName());
    Iterator iter = omElement.getChildElements();
    while (iter.hasNext()) {
        OMElementImpl impl = (OMElementImpl) iter.next();
        Assert.assertEquals("asserting localName inserted by the method", "parameter", impl.getLocalName());
    }
}
Also used : QuartzTaskManager(org.apache.synapse.startup.quartz.QuartzTaskManager) TaskManager(org.apache.synapse.task.TaskManager) OMElementImpl(org.apache.axiom.om.impl.llom.OMElementImpl) Iterator(java.util.Iterator) QuartzTaskManager(org.apache.synapse.startup.quartz.QuartzTaskManager) OMElement(org.apache.axiom.om.OMElement) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with TaskManager

use of org.apache.synapse.task.TaskManager in project wso2-synapse by wso2.

the class TaskSchedulerTest method testScheduleTask.

@Test()
public void testScheduleTask() throws Exception {
    String path = this.getClass().getClassLoader().getResource("task/task_TestScheduler.xml").getFile();
    OMElement taskOme = loadOMElement(path);
    TaskDescription taskDescription = TaskDescriptionFactory.createTaskDescription(taskOme, SYNAPSE_OMNAMESPACE);
    TaskManager quartzTaskManager = Mockito.mock(TaskManager.class);
    Mockito.when(quartzTaskManager.schedule(taskDescription)).thenReturn(true);
    org.apache.synapse.task.TaskScheduler taskScheduler = new org.apache.synapse.task.TaskScheduler("task");
    Assert.assertFalse("Task cannot be scheduled before initialization.", taskScheduler.scheduleTask(taskDescription));
    taskScheduler.init(new Properties(), quartzTaskManager);
    Assert.assertTrue("Task at file task_TestScheduler.xml not " + "scheduled even after initializing the scheduler.", taskScheduler.scheduleTask(taskDescription));
}
Also used : TaskManager(org.apache.synapse.task.TaskManager) TaskDescription(org.apache.synapse.task.TaskDescription) OMElement(org.apache.axiom.om.OMElement) Properties(java.util.Properties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with TaskManager

use of org.apache.synapse.task.TaskManager in project wso2-synapse by wso2.

the class TaskSchedulerTest method testInitialization.

@Test()
public void testInitialization() {
    Properties properties = new Properties();
    TaskManager quartzTaskManager = Mockito.mock(TaskManager.class);
    Mockito.when(quartzTaskManager.isInitialized()).thenReturn(true);
    org.apache.synapse.task.TaskScheduler taskScheduler = new org.apache.synapse.task.TaskScheduler("CheckPrice");
    taskScheduler.init(properties, quartzTaskManager);
    Assert.assertTrue("Task Scheduler not initialized.", taskScheduler.isInitialized());
}
Also used : TaskManager(org.apache.synapse.task.TaskManager) Properties(java.util.Properties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

TaskManager (org.apache.synapse.task.TaskManager)9 Test (org.junit.Test)6 Properties (java.util.Properties)4 OMElement (org.apache.axiom.om.OMElement)4 QuartzTaskManager (org.apache.synapse.startup.quartz.QuartzTaskManager)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElementImpl (org.apache.axiom.om.impl.llom.OMElementImpl)1 SynapseException (org.apache.synapse.SynapseException)1 SynapseTaskManager (org.apache.synapse.task.SynapseTaskManager)1 TaskDescription (org.apache.synapse.task.TaskDescription)1 TaskDescriptionRepository (org.apache.synapse.task.TaskDescriptionRepository)1 TaskScheduler (org.apache.synapse.task.TaskScheduler)1