Package org.drools.command

Examples of org.drools.command.SingleSessionCommandService


    public void FIXMEtestPersistenceWorkItems() throws Exception {
      log.info("---> get bean jpaSingleSessionCommandService");
        JPASingleSessionCommandService jpaService = (JPASingleSessionCommandService) ctx.getBean("jpaSingleSessionCommandService");
       
        log.info("---> create new SingleSessionCommandService");
        SingleSessionCommandService service = jpaService.newStatefulKnowledgeSession();
       
        int sessionId = service.getSessionId();
        log.info("---> created SingleSessionCommandService id: " + sessionId);

        StartProcessCommand startProcessCommand = new StartProcessCommand();
        startProcessCommand.setProcessId( "org.drools.test.TestProcess" );
        ProcessInstance processInstance = service.execute( startProcessCommand );
        log.info( "Started process instance {}", processInstance.getId() );

        TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
        WorkItem workItem = handler.getWorkItem();
        assertNotNull( workItem );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = service.execute( getProcessInstanceCommand );
        assertNotNull( processInstance );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
        completeWorkItemCommand.setWorkItemId( workItem.getId() );
        service.execute( completeWorkItemCommand );

        workItem = handler.getWorkItem();
        assertNotNull( workItem );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = service.execute( getProcessInstanceCommand );
        assertNotNull( processInstance );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        completeWorkItemCommand = new CompleteWorkItemCommand();
        completeWorkItemCommand.setWorkItemId( workItem.getId() );
        service.execute( completeWorkItemCommand );

        workItem = handler.getWorkItem();
        assertNotNull( workItem );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = service.execute( getProcessInstanceCommand );
        assertNotNull( processInstance );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        completeWorkItemCommand = new CompleteWorkItemCommand();
        completeWorkItemCommand.setWorkItemId( workItem.getId() );
        service.execute( completeWorkItemCommand );

        workItem = handler.getWorkItem();
        assertNull( workItem );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = service.execute( getProcessInstanceCommand );
        assertNull( processInstance );
        service.dispose();
    }
View Full Code Here


    @Test
    public void testPersistenceWorkItemsUserTransaction() throws Exception {
       
        JPASingleSessionCommandService jpaService = (JPASingleSessionCommandService) ctx.getBean("jpaSingleSessionCommandService");
        SingleSessionCommandService service = jpaService.newStatefulKnowledgeSession();

        int sessionId = service.getSessionId();

        StartProcessCommand startProcessCommand = new StartProcessCommand();
        startProcessCommand.setProcessId( "org.drools.test.TestProcess" );
        ProcessInstance processInstance = service.execute( startProcessCommand );
        log.info( "Started process instance {}", processInstance.getId() );

        TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
        WorkItem workItem = handler.getWorkItem();
        assertNotNull( workItem );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = service.execute( getProcessInstanceCommand );
        assertNotNull( processInstance );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
        completeWorkItemCommand.setWorkItemId( workItem.getId() );
        service.execute( completeWorkItemCommand );

        workItem = handler.getWorkItem();
        assertNotNull( workItem );
        service.dispose();

    service = jpaService.loadStatefulKnowledgeSession(sessionId);
        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = service.execute( getProcessInstanceCommand );
        assertNotNull( processInstance );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        completeWorkItemCommand = new CompleteWorkItemCommand();
        completeWorkItemCommand.setWorkItemId( workItem.getId() );
        service.execute( completeWorkItemCommand );

        workItem = handler.getWorkItem();
        assertNotNull( workItem );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = service.execute( getProcessInstanceCommand );
        assertNotNull( processInstance );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        completeWorkItemCommand = new CompleteWorkItemCommand();
        completeWorkItemCommand.setWorkItemId( workItem.getId() );
        service.execute( completeWorkItemCommand );

        workItem = handler.getWorkItem();
        assertNull( workItem );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = service.execute( getProcessInstanceCommand );
        assertNull( processInstance );
        service.dispose();
    }
View Full Code Here

   
    @Test
    public void testPersistenceSubProcess() {

        JPASingleSessionCommandService jpaService = (JPASingleSessionCommandService) ctx.getBean("jpaSingleSessionCommandService");
        SingleSessionCommandService service = jpaService.newStatefulKnowledgeSession();

        int sessionId = service.getSessionId();

        StartProcessCommand startProcessCommand = new StartProcessCommand();
        startProcessCommand.setProcessId( "org.drools.test.ProcessSubProcess" );
        RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) service.execute( startProcessCommand );
        log.info( "Started process instance {}", processInstance.getId() );
        long processInstanceId = processInstance.getId();

        TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
        WorkItem workItem = handler.getWorkItem();
        assertNotNull( workItem );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstanceId );
        processInstance = (RuleFlowProcessInstance) service.execute( getProcessInstanceCommand );
        assertNotNull( processInstance );

        Collection<NodeInstance> nodeInstances = processInstance.getNodeInstances();
        assertEquals( 1,
                      nodeInstances.size() );
        SubProcessNodeInstance subProcessNodeInstance = (SubProcessNodeInstance) nodeInstances.iterator().next();
        long subProcessInstanceId = subProcessNodeInstance.getProcessInstanceId();
        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( subProcessInstanceId );
        RuleFlowProcessInstance subProcessInstance = (RuleFlowProcessInstance) service.execute( getProcessInstanceCommand );
        assertNotNull( subProcessInstance );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
        completeWorkItemCommand.setWorkItemId( workItem.getId() );
        service.execute( completeWorkItemCommand );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( subProcessInstanceId );
        subProcessInstance = (RuleFlowProcessInstance) service.execute( getProcessInstanceCommand );
        assertNull( subProcessInstance );

        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstanceId );
        processInstance = (RuleFlowProcessInstance) service.execute( getProcessInstanceCommand );
        assertNull( processInstance );
        service.dispose();
    }
View Full Code Here

    public void testPersistenceTimer() throws Exception {
      log.info("---> get bean jpaSingleSessionCommandService");
        JPASingleSessionCommandService jpaService = (JPASingleSessionCommandService) ctx.getBean("jpaSingleSessionCommandService");
       
        log.info("---> create new SingleSessionCommandService");
        SingleSessionCommandService service = jpaService.newStatefulKnowledgeSession();
       
        int sessionId = service.getSessionId();
        log.info("---> created SingleSessionCommandService id: " + sessionId);
           
        StartProcessCommand startProcessCommand = new StartProcessCommand();
        startProcessCommand.setProcessId( "org.drools.test.ProcessTimer" );
        ProcessInstance processInstance = service.execute( startProcessCommand );
        long procId = processInstance.getId();
    log.info( "---> Started ProcessTimer id: {}", procId );
        service.dispose();
        log.info( "---> session disposed" );

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        log.info( "---> load session: " + sessionId);
        GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( procId );
        processInstance = service.execute( getProcessInstanceCommand );
        log.info("---> GetProcessInstanceCommand id: " + procId);
        assertNotNull( processInstance );
        log.info( "---> session disposed" );
        service.dispose();

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        log.info( "---> load session: " + sessionId);
        Thread.sleep( 3000 );
        getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( procId );
        log.info("---> GetProcessInstanceCommand id: " + procId);
        processInstance = service.execute( getProcessInstanceCommand );
        log.info( "---> session disposed" );
        assertNull( processInstance );
    }
View Full Code Here

    }

    @Test
    public void testPersistenceTimer2() throws Exception {
      JPASingleSessionCommandService jpaService = (JPASingleSessionCommandService) ctx.getBean("jpaSingleSessionCommandService");
        SingleSessionCommandService service = jpaService.newStatefulKnowledgeSession();

        int sessionId = service.getSessionId();
       
        StartProcessCommand startProcessCommand = new StartProcessCommand();
        startProcessCommand.setProcessId( "org.drools.test.ProcessTimer2" );
        ProcessInstance processInstance = service.execute( startProcessCommand );
        log.info( "Started process instance {}", processInstance.getId() );

        Thread.sleep( 2000 );

        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = service.execute( getProcessInstanceCommand );
        assertNull( processInstance );
    }
View Full Code Here

    public void testPersistenceVariables() {
      log.info("---> get bean jpaSingleSessionCommandService");
        JPASingleSessionCommandService jpaService = (JPASingleSessionCommandService) ctx.getBean("jpaSingleSessionCommandService");
       
        log.info("---> create new SingleSessionCommandService");
        SingleSessionCommandService service = jpaService.newStatefulKnowledgeSession();
       
        int sessionId = service.getSessionId();
        log.info("---> created SingleSessionCommandService id: " + sessionId);

        StartProcessCommand startProcessCommand = new StartProcessCommand("com.sample.ruleflow");
        log.info("### Starting process ###");
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("x", "SomeString");
        parameters.put("y", new MyEntity("This is a test Entity with annotation in fields"));
        parameters.put("m", new MyEntityMethods("This is a test Entity with annotations in methods"));
        parameters.put("f", new MyEntityOnlyFields("This is a test Entity with annotations in fields and without accesors methods"));
        parameters.put("z", new MyVariableSerializable("This is a test SerializableObject"));
        startProcessCommand.setParameters(parameters);
        WorkflowProcessInstance processInstance = (WorkflowProcessInstance) service.execute( startProcessCommand );
        log.info( "Started process instance {}", processInstance.getId() );
   
        TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
        WorkItem workItem = handler.getWorkItem();
        assertNotNull( workItem );
        service.dispose();
       
        EntityManagerFactory emf = (EntityManagerFactory) ctx.getBean("myEmf");
       
        List<?> result = emf.createEntityManager().createQuery("select i from VariableInstanceInfo i").getResultList();
        assertEquals(5, result.size());
        log.info("### Retrieving process instance ###");
       
        service = jpaService.loadStatefulKnowledgeSession(sessionId);
        GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
        getProcessInstanceCommand.setProcessInstanceId( processInstance.getId() );
        processInstance = (WorkflowProcessInstance) service.execute( getProcessInstanceCommand );
        assertNotNull( processInstance );
       
        assertNotNull( processInstance );
        assertEquals("SomeString", processInstance.getVariable("x"));
        assertEquals("This is a test Entity with annotation in fields", ((MyEntity) processInstance.getVariable("y")).getTest());
        assertEquals("This is a test Entity with annotations in methods", ((MyEntityMethods) processInstance.getVariable("m")).getTest());
        assertEquals("This is a test Entity with annotations in fields and without accesors methods", ((MyEntityOnlyFields) processInstance.getVariable("f")).test);
        assertEquals("This is a test SerializableObject", ((MyVariableSerializable) processInstance.getVariable("z")).getText());
        assertNull(processInstance.getVariable("a"));
        assertNull(processInstance.getVariable("b"));
        assertNull(processInstance.getVariable("c"));
  
        service.dispose();
       
//        log.info("### Completing first work item ###");
//        ksession.getWorkItemManager().completeWorkItem( workItem.getId(), null );
//
//        workItem = handler.getWorkItem();
View Full Code Here

TOP

Related Classes of org.drools.command.SingleSessionCommandService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.