List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:org.drools.container.spring.SpringDroolsTest.java
@Test public void testConfiguration() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/drools/container/spring/session-conf-beans.xml"); KnowledgeBaseImpl kbase1 = (KnowledgeBaseImpl) context.getBean("kbase1"); RuleBaseConfiguration rconf = ((InternalRuleBase) kbase1.getRuleBase()).getConfiguration(); assertTrue(rconf.isAdvancedProcessRuleIntegration()); assertFalse(rconf.isMultithreadEvaluation()); assertEquals(EventProcessingOption.STREAM, rconf.getEventProcessingMode()); assertEquals(AssertBehaviour.IDENTITY, rconf.getAssertBehaviour()); assertEquals("org.drools.container.spring.MockConsequenceExceptionHandler", rconf.getConsequenceExceptionHandler()); KnowledgeBaseImpl kbase2 = (KnowledgeBaseImpl) context.getBean("kbase2"); rconf = ((InternalRuleBase) kbase2.getRuleBase()).getConfiguration(); assertFalse(rconf.isAdvancedProcessRuleIntegration()); assertFalse(rconf.isMultithreadEvaluation()); assertEquals(3, rconf.getMaxThreads()); assertEquals(EventProcessingOption.CLOUD, rconf.getEventProcessingMode()); assertEquals(AssertBehaviour.EQUALITY, rconf.getAssertBehaviour()); StatefulKnowledgeSessionImpl ksession1 = (StatefulKnowledgeSessionImpl) context.getBean("ksession1"); SessionConfiguration sconf = ksession1.session.getSessionConfiguration(); assertTrue(sconf.isKeepReference()); assertEquals(ClockType.REALTIME_CLOCK, sconf.getClockType()); Map<String, WorkItemHandler> wih = sconf.getWorkItemHandlers(); assertEquals(4, wih.size());/* ww w . ja v a 2s . c o m*/ assertTrue(wih.containsKey("wih1")); assertTrue(wih.containsKey("wih2")); assertTrue(wih.containsKey("Human Task")); assertTrue(wih.containsKey("MyWork")); assertNotSame(wih.get("wih1"), wih.get("wih2")); assertEquals(HumanTaskHandler.class, wih.get("wih1").getClass()); assertEquals(HumanTaskHandler.class, wih.get("wih2").getClass()); StatefulKnowledgeSessionImpl ksession2 = (StatefulKnowledgeSessionImpl) context.getBean("ksession2"); sconf = ksession2.session.getSessionConfiguration(); assertFalse(sconf.isKeepReference()); assertEquals(ClockType.PSEUDO_CLOCK, sconf.getClockType()); }
From source file:com.hivemq.plugin.springexample.ExamplePluginModule.java
/** * This method is provided to execute some custom plugin configuration stuff. Is is the place * to execute Google Guice bindings,etc if needed. *//*from w ww . j av a 2 s . c o m*/ @Override protected void configurePlugin() { ClassPathXmlApplicationContext ctx = getApplicationContext(); //Make all instances managed by Spring known to Guice SpringIntegration.bindAll(binder(), ctx.getBeanFactory()); //Make Spring's ApplicationContext known to Guice bind(ApplicationContext.class).toInstance(ctx); //Tell Guice to inject into the StartCallback instance, which is managed by Spring requestInjection(ctx.getBeanFactory().getBean("startCallback")); }
From source file:gr.seab.r2rml.test.ComplianceTests.java
@Test public void testSingle() { log.info("test single. Careful, database 'test' will be erased and re-created!"); String folder = "src/test/resources/postgres/D014-3tables1primarykey1foreignkey/"; initialiseSourceDatabase(folder + "create.sql"); //Load property file try {// w w w .j a v a 2s . c o m properties.load(new FileInputStream("src/test/resources/test.properties")); } catch (Exception e) { e.printStackTrace(); } //Override certain properties properties.setProperty("mapping.file", folder + "r2rmla.ttl"); properties.setProperty("jena.destinationFileName", folder + "r2rmla.nq"); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("test-context.xml"); Database db = (Database) context.getBean("db"); db.setProperties(properties); Parser parser = (Parser) context.getBean("parser"); parser.setProperties(properties); MappingDocument mappingDocument = parser.parse(); Generator generator = (Generator) context.getBean("generator"); generator.setProperties(parser.getProperties()); generator.setResultModel(parser.getResultModel()); generator.createTriples(mappingDocument); context.close(); }
From source file:org.drools.container.spring.SpringDroolsTest.java
@Test public void testResourceAuthenication() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/drools/container/spring/beans.xml"); //Secure Resource DroolsResourceAdapter resourceAdapter = (DroolsResourceAdapter) context.getBean("secureResource"); assertNotNull(resourceAdapter);/* w w w .ja va2 s . c om*/ Resource resource = resourceAdapter.getDroolsResource(); assertTrue(resource instanceof UrlResource); UrlResource ur = (UrlResource) resource; assertEquals("enabled", ur.getBasicAuthentication()); assertEquals("someUser", ur.getUsername()); assertEquals("somePassword", ur.getPassword()); //Insecure Resource resourceAdapter = (DroolsResourceAdapter) context.getBean("insecureResource"); assertNotNull(resourceAdapter); resource = resourceAdapter.getDroolsResource(); assertTrue(resource instanceof UrlResource); ur = (UrlResource) resource; assertEquals("disabled", ur.getBasicAuthentication()); assertEquals("", ur.getUsername()); assertEquals("", ur.getPassword()); }
From source file:org.activiti.crystalball.simulator.OptimizeBottleneckTest.java
@Test public void testUser2OverLoadedWithHelp3() throws Exception { System.setProperty("liveDB", LIVE_DB); System.setProperty("_SIM_DB_PATH", tempDir + "/simulationRunDB-SimulateBottleNeck-Overload3-" + Thread.currentThread().getId()); FileUtils.copyFile(new File(LIVE_DB + ".h2.db"), new File(tempDir + "/simulationRunDB-SimulateBottleNeck-Overload3-" + Thread.currentThread().getId() + ".h2.db")); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/SimEngine-simulateBottleneck-h2-context.xml"); ProcessEngine processEngine = (ProcessEngine) appContext.getBean("simProcessEngine"); // increase frequency of process starts to 45 mins (default is 1 hour) StartProcessEventHandler startProcessEventHandler = appContext.getBean(StartProcessEventHandler.class); startProcessEventHandler.setPeriod(2700000); // add User3 to the Group2 to help user2 IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService"); identityService.createMembership("user3", "Group2"); runSimulation(appContext, tempDir + "/OptimizeBottleneckTest3.png", tempDir + "/OptimizeBottleneckTest3-dueDate.png"); processEngine.close();//from ww w . ja v a 2 s . c om appContext.close(); File expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest3.png"); File generated = new File(tempDir + "/OptimizeBottleneckTest3.png"); assertTrue(FileUtils.contentEquals(expected, generated)); expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest3-dueDate.png"); generated = new File(tempDir + "/OptimizeBottleneckTest3-dueDate.png"); assertTrue(FileUtils.contentEquals(expected, generated)); // delete database file File f = new File(System.getProperty("_SIM_DB_PATH") + ".h2.db"); if (!f.delete()) System.err.println("unable to delete file"); }
From source file:org.activiti.crystalball.simulator.OptimizeBottleneckTest.java
@Test public void testUser2OverLoadedWithHelp4() throws Exception { System.setProperty("liveDB", LIVE_DB); System.setProperty("_SIM_DB_PATH", tempDir + "/simulationRunDB-SimulateBottleNeck-Overload4-" + Thread.currentThread().getId()); FileUtils.copyFile(new File(LIVE_DB + ".h2.db"), new File(tempDir + "/simulationRunDB-SimulateBottleNeck-Overload4-" + Thread.currentThread().getId() + ".h2.db")); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/SimEngine-simulateBottleneck-h2-context.xml"); ProcessEngine processEngine = (ProcessEngine) appContext.getBean("simProcessEngine"); // increase frequency of process starts to 45 mins (default is 1 hour) StartProcessEventHandler startProcessEventHandler = appContext.getBean(StartProcessEventHandler.class); startProcessEventHandler.setPeriod(2700000); // add user4 to the Group2 to help user2 IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService"); identityService.createMembership("user4", "Group2"); runSimulation(appContext, tempDir + "/OptimizeBottleneckTest4.png", tempDir + "/OptimizeBottleneckTest4-dueDate.png"); processEngine.close();//from w ww . jav a 2s . co m appContext.close(); File expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest4.png"); File generated = new File(tempDir + "/OptimizeBottleneckTest4.png"); assertTrue(FileUtils.contentEquals(expected, generated)); expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest4-dueDate.png"); generated = new File(tempDir + "/OptimizeBottleneckTest4-dueDate.png"); assertTrue(FileUtils.contentEquals(expected, generated)); // delete database file File f = new File(System.getProperty("_SIM_DB_PATH") + ".h2.db"); if (!f.delete()) System.err.println("unable to delete file"); }
From source file:org.activiti.crystalball.simulator.OptimizeBottleneckTest.java
@Test public void testUser2OverLoadedWithHelp5() throws Exception { System.setProperty("liveDB", LIVE_DB); System.setProperty("_SIM_DB_PATH", tempDir + "/simulationRunDB-SimulateBottleNeck-Overload5-" + Thread.currentThread().getId()); FileUtils.copyFile(new File(LIVE_DB + ".h2.db"), new File(tempDir + "/simulationRunDB-SimulateBottleNeck-Overload5-" + Thread.currentThread().getId() + ".h2.db")); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/SimEngine-simulateBottleneck-h2-context.xml"); ProcessEngine processEngine = (ProcessEngine) appContext.getBean("simProcessEngine"); // increase frequency of process starts to 45 mins (default is 1 hour) StartProcessEventHandler startProcessEventHandler = appContext.getBean(StartProcessEventHandler.class); startProcessEventHandler.setPeriod(2700000); // add new user5 to the Group2 to help user2 IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService"); identityService.saveUser(identityService.newUser("user5")); identityService.createMembership("user5", "Group2"); runSimulation(appContext, tempDir + "/OptimizeBottleneckTest5.png", tempDir + "/OptimizeBottleneckTest5-dueDate.png"); processEngine.close();/* w ww .j av a2s .com*/ appContext.close(); File expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest5.png"); File generated = new File(tempDir + "/OptimizeBottleneckTest5.png"); assertTrue(FileUtils.contentEquals(expected, generated)); expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest5-dueDate.png"); generated = new File(tempDir + "/OptimizeBottleneckTest5-dueDate.png"); assertTrue(FileUtils.contentEquals(expected, generated)); // delete database file File f = new File(System.getProperty("_SIM_DB_PATH") + ".h2.db"); if (!f.delete()) System.err.println("unable to delete file"); }
From source file:org.activiti.crystalball.simulator.OptimizeBottleneckTest.java
@Test public void testUser2OverLoadedWithHelp45() throws Exception { System.setProperty("liveDB", LIVE_DB); System.setProperty("_SIM_DB_PATH", tempDir + "/simulationRunDB-SimulateBottleNeck-Overload45-" + Thread.currentThread().getId()); FileUtils.copyFile(new File(LIVE_DB + ".h2.db"), new File(tempDir + "/simulationRunDB-SimulateBottleNeck-Overload45-" + Thread.currentThread().getId() + ".h2.db")); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/SimEngine-simulateBottleneck-h2-context.xml"); ProcessEngine processEngine = (ProcessEngine) appContext.getBean("simProcessEngine"); // increase frequency of process starts to 45 mins (default is 1 hour) StartProcessEventHandler startProcessEventHandler = appContext.getBean(StartProcessEventHandler.class); startProcessEventHandler.setPeriod(2700000); // add new user5 to the Group2 to help user2 and to Group4 to help user4 IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService"); identityService.saveUser(identityService.newUser("user5")); identityService.createMembership("user5", "Group2"); identityService.createMembership("user5", "Group4"); runSimulation(appContext, tempDir + "/OptimizeBottleneckTest45.png", tempDir + "/OptimizeBottleneckTest45-dueDate.png"); processEngine.close();/*w w w. j a va 2 s . c om*/ appContext.close(); File expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest45.png"); File generated = new File(tempDir + "/OptimizeBottleneckTest45.png"); assertTrue(FileUtils.contentEquals(expected, generated)); expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest45-dueDate.png"); generated = new File(tempDir + "/OptimizeBottleneckTest45-dueDate.png"); assertTrue(FileUtils.contentEquals(expected, generated)); // delete database file File f = new File(System.getProperty("_SIM_DB_PATH") + ".h2.db"); if (!f.delete()) System.err.println("unable to delete file"); }
From source file:org.activiti.crystalball.simulator.PlaybackTest.java
/** * repeat playback 2 times + 2 seconds (2 new processes are started0 * @throws Exception /* w w w . j a va 2 s . c o m*/ */ @Test public void testPlayback2Run() throws Exception { System.setProperty("_SIM_DB_PATH", System.getProperty("tempDir", "target") + "/Playback-test2"); System.setProperty("liveDB", "target/Playback"); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/PlaybackSimEngine-h2-context.xml"); // deploy processes RepositoryService simRepositoryService = (RepositoryService) appContext.getBean("simRepositoryService"); simRepositoryService.createDeployment() .addClasspathResource("org/activiti/crystalball/simulator/Playback.bpmn").deploy(); HistoryService historyService = (HistoryService) appContext.getBean("simHistoryService"); // init identity service IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService"); identityService.saveGroup(identityService.newGroup("Group1")); identityService.saveUser(identityService.newUser("user1")); identityService.createMembership("user1", "Group1"); SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class); PlaybackScheduleStartProcessEventHandler schedule = (PlaybackScheduleStartProcessEventHandler) appContext .getBean("scheduleProcessEventHandler"); schedule.setRepeatPlayback(true); Calendar c = Calendar.getInstance(); c.clear(); c.set(2013, 3, 3); Date startDate = c.getTime(); c.add(Calendar.SECOND, 12); Date finishDate = c.getTime(); // run simulation for 12 seconds simRun.execute(startDate, finishDate); assertEquals(8, historyService.createHistoricProcessInstanceQuery().count()); List<HistoricProcessInstance> processInstances = historyService.createHistoricProcessInstanceQuery() .orderByProcessInstanceStartTime().asc().list(); HistoricProcessInstance processInstance = processInstances.get(0); HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(1); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(2, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(2); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(3); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(4); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(2, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(5); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(6); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); //user task was not finished yet assertEquals(1, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(7); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(2, ((Integer) variableInstance.getValue()).intValue()); appContext.close(); }
From source file:org.drools.container.spring.SpringDroolsTest.java
@Test public void testSimpleKSessions() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/drools/container/spring/beans.xml"); List<String> list = new ArrayList<String>(); StatelessKnowledgeSession kstateless = (StatelessKnowledgeSession) context.getBean("ksession1"); kstateless.setGlobal("list", list); kstateless.execute(new Person("Darth", "Cheddar", 50)); assertEquals(2, list.size());/*w ww. j a va 2 s .c om*/ list = new ArrayList<String>(); StatefulKnowledgeSession kstateful = ((StatefulKnowledgeSession) context.getBean("ksession2")); kstateful.setGlobal("list", list); kstateful.insert(new Person("Darth", "Cheddar", 50)); kstateful.fireAllRules(); assertEquals(2, list.size()); }