List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext stop
@Override public void stop()
From source file:com.nokia.dempsy.mpcluster.TestAllMpClusterImpls.java
private <T, N> void runAllCombinations(Checker<T, N> checker) throws Throwable { for (String clusterManager : clusterManagers) { ClassPathXmlApplicationContext actx = new ClassPathXmlApplicationContext(clusterManager); actx.registerShutdownHook();//from w w w . j a va2 s .c o m @SuppressWarnings("unchecked") MpClusterSessionFactory<T, N> factory = (MpClusterSessionFactory<T, N>) actx .getBean("clusterSessionFactory"); if (checker != null) checker.check("pass for:" + clusterManager, factory); actx.stop(); actx.destroy(); } }
From source file:org.drools.server.CxfRsClientServerTest.java
@org.junit.Test public void test1() throws Exception { ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext( "classpath:beans-test.xml"); String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"message\">\n"; cmd += " <org.drools.server.Message>\n"; cmd += " <text>Hello World</text>\n"; cmd += " </org.drools.server.Message>\n"; cmd += " </insert>\n"; cmd += "</batch-execution>\n"; CamelServerApp test = new CamelServerApp(); String response = test.execute(cmd, (CamelContext) springContext.getBean("camel-client-ctx")); assertTrue(response.contains("execution-results")); assertTrue(response.contains("echo")); springContext.stop(); }
From source file:org.drools.server.CxfSoapClientServerTest.java
@org.junit.Test public void test1() throws Exception { ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext( "classpath:beans-test.xml"); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1"); body.addBodyElement(payloadName);//from w ww.j ava 2 s. c o m String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"message\">\n"; cmd += " <org.drools.server.Message>\n"; cmd += " <text>Helllo World</text>\n"; cmd += " </org.drools.server.Message>\n"; cmd += " </insert>\n"; cmd += "</batch-execution>\n"; body.addTextNode(cmd); CamelServerApp test = new CamelServerApp(); String response = test.execute(soapMessage, (CamelContext) springContext.getBean("camel-client-ctx")); assertTrue(response.contains("execution-results")); assertTrue(response.contains("echo")); springContext.stop(); }
From source file:com.nokia.dempsy.TestDempsy.java
@Test public void testAdaptorThrowsRuntimeOnSetDispatcher() throws Throwable { TestAdaptor.throwExceptionOnSetDispatcher = true; ClassPathXmlApplicationContext actx = null; boolean gotException = false; try {//from w ww.j av a2s . c om actx = new ClassPathXmlApplicationContext("testDempsy/Dempsy.xml", "testDempsy/Transport-PassthroughActx.xml", "testDempsy/ClusterManager-LocalVmActx.xml", "testDempsy/SimpleMultistageApplicationActx.xml"); actx.registerShutdownHook(); } catch (Throwable th) { assertEquals("Forced RuntimeException", th.getCause().getLocalizedMessage()); gotException = true; } finally { TestAdaptor.throwExceptionOnSetDispatcher = false; if (actx != null) { actx.stop(); actx.destroy(); } } assertTrue(gotException); }
From source file:com.nokia.dempsy.TestDempsy.java
public void runAllCombinations(String applicationContext, Checker checker) throws Throwable { int runCount = 0; for (String clusterManager : clusterManagers) { for (String[] alternatingTransports : transports) { // select one of the alternatingTransports String transport = alternatingTransports[runCount % alternatingTransports.length]; // alternate the dempsy configs String dempsyConfig = dempsyConfigs[runCount % dempsyConfigs.length]; if (!badCombos.contains(new ClusterId(clusterManager, transport))) { try { logger.debug("*****************************************************************"); logger.debug(" test: " + (checker == null ? "none" : checker) + " using " + dempsyConfig + "," + clusterManager + "," + transport); logger.debug("*****************************************************************"); DefaultRoutingStrategy.resetOutboundsChecking(); String[] ctx = new String[4]; ctx[0] = dempsyConfig; ctx[1] = clusterManager; ctx[2] = transport;/* w w w . j a va2 s . com*/ ctx[3] = "testDempsy/" + applicationContext; logger.debug("Starting up the appliction context ..."); ClassPathXmlApplicationContext actx = new ClassPathXmlApplicationContext(ctx); actx.registerShutdownHook(); Dempsy dempsy = (Dempsy) actx.getBean("dempsy"); assertTrue(TestUtils.waitForClustersToBeInitialized(baseTimeoutMillis, 20, dempsy)); WaitForShutdown waitingForShutdown = new WaitForShutdown(dempsy); Thread waitingForShutdownThread = new Thread(waitingForShutdown, "Waiting For Shutdown"); waitingForShutdownThread.start(); Thread.yield(); logger.debug("Running test ..."); if (checker != null) checker.check(actx); logger.debug("Done with test, stopping the application context ..."); actx.stop(); actx.destroy(); assertTrue(waitingForShutdown.waitForShutdownDoneLatch.await(baseTimeoutMillis, TimeUnit.MILLISECONDS)); assertTrue(waitingForShutdown.shutdown); logger.debug("Finished this pass."); } catch (AssertionError re) { logger.error("***************** FAILED ON: " + clusterManager + ", " + transport); throw re; } runCount++; } } } }
From source file:com.nokia.dempsy.TestDempsy.java
@Test public void testIndividualClusterStart() throws Throwable { ClassPathXmlApplicationContext actx = new ClassPathXmlApplicationContext( "testDempsy/Dempsy-IndividualClusterStart.xml", "testDempsy/Transport-PassthroughActx.xml", "testDempsy/ClusterManager-LocalVmActx.xml", "testDempsy/SimpleMultistageApplicationActx.xml"); actx.registerShutdownHook();/* w w w . j a v a 2 s .co m*/ Dempsy dempsy = (Dempsy) actx.getBean("dempsy"); assertNotNull(dempsy); Dempsy.Application.Cluster cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster0")); assertNull(cluster); cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster1")); assertNull(cluster); cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster2")); assertNotNull(cluster); assertEquals(1, cluster.getNodes().size()); cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster3")); assertNull(cluster); cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster4")); assertNull(cluster); actx.stop(); actx.destroy(); }
From source file:com.ryantenney.metrics.spring.ReporterTest.java
@Test public void fakeReporters() throws Throwable { ClassPathXmlApplicationContext ctx = null; FakeReporter one = null;//from ww w. j a va 2 s .c o m FakeReporter two = null; try { MetricRegistry registry = new MetricRegistry(); SharedMetricRegistries.add("reporterTestRegistry", registry); ctx = new ClassPathXmlApplicationContext("classpath:fake-reporter-test.xml"); ctx.start(); Thread.sleep(1000); one = ctx.getBean("fakeReporterOne", FakeReporter.class); Assert.assertEquals(registry, one.getRegistry()); Assert.assertEquals("milliseconds", one.getDurationUnit()); Assert.assertEquals("second", one.getRateUnit()); Assert.assertEquals(100000000, one.getPeriod()); Assert.assertEquals(10, one.getCalls()); Assert.assertEquals("[MetricFilter regex=foo]", one.getFilter().toString()); Assert.assertTrue(one.isRunning()); two = ctx.getBean("fakeReporterTwo", FakeReporter.class); Assert.assertEquals(registry, two.getRegistry()); Assert.assertEquals("nanoseconds", two.getDurationUnit()); Assert.assertEquals("hour", two.getRateUnit()); Assert.assertEquals(100000000, two.getPeriod()); Assert.assertEquals(10, one.getCalls()); Assert.assertEquals(ctx.getBean(BarFilter.class), two.getFilter()); Assert.assertTrue(one.isRunning()); } finally { if (ctx != null) { ctx.stop(); ctx.close(); } } if (one != null) { Assert.assertFalse(one.isRunning()); } if (two != null) { Assert.assertFalse(two.isRunning()); } }
From source file:com.alibaba.dubbo.examples.validation.ValidationTest.java
@Test public void testValidation() { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext( ValidationTest.class.getPackage().getName().replace('.', '/') + "/validation-provider.xml"); providerContext.start();/* ww w .j a va 2 s. co m*/ try { ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext( ValidationTest.class.getPackage().getName().replace('.', '/') + "/validation-consumer.xml"); consumerContext.start(); try { ValidationService validationService = (ValidationService) consumerContext .getBean("validationService"); // Save OK ValidationParameter parameter = new ValidationParameter(); parameter.setName("liangfei"); parameter.setEmail("liangfei@liang.fei"); parameter.setAge(50); parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000)); parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000)); validationService.save(parameter); try { parameter = new ValidationParameter(); parameter.setName("l"); parameter.setEmail("liangfei@liang.fei"); parameter.setAge(50); parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000)); parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000)); validationService.save(parameter); Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); Assert.assertNotNull(violations); } // Save Error try { parameter = new ValidationParameter(); validationService.save(parameter); Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); Assert.assertNotNull(violations); } // Delete OK validationService.delete(2, "abc"); // Delete Error try { validationService.delete(2, "a"); Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); Assert.assertNotNull(violations); Assert.assertEquals(1, violations.size()); } // Delete Error try { validationService.delete(0, "abc"); Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); Assert.assertNotNull(violations); Assert.assertEquals(1, violations.size()); } try { validationService.delete(2, null); Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); Assert.assertNotNull(violations); Assert.assertEquals(1, violations.size()); } try { validationService.delete(0, null); Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); Assert.assertNotNull(violations); Assert.assertEquals(2, violations.size()); } } finally { consumerContext.stop(); consumerContext.close(); } } finally { providerContext.stop(); providerContext.close(); } }
From source file:validation.ValidationTest.java
@Test public void testValidation() { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext( ValidationTest.class.getPackage().getName().replace('.', '/') + "/validation-provider.xml"); providerContext.start();//from www .j a v a 2s .co m try { ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext( ValidationTest.class.getPackage().getName().replace('.', '/') + "/validation-consumer.xml"); consumerContext.start(); try { ValidationService validationService = (ValidationService) consumerContext .getBean("validationService"); // Save OK ValidationParameter parameter = new ValidationParameter(); parameter.setName("liangfei"); parameter.setEmail("liangfei@liang.fei"); parameter.setAge(50); parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000)); parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000)); validationService.save(parameter); try { parameter = new ValidationParameter(); parameter.setName("l"); parameter.setEmail(null); parameter.setAge(50); parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000)); parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000)); validationService.save(parameter); // Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); // Assert.assertNotNull(violations); } // Save Error try { parameter = new ValidationParameter(); validationService.save(parameter); // Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); // Assert.assertNotNull(violations); System.out.println(violations); } // Delete OK validationService.delete(2, "abc"); // Delete Error try { validationService.delete(2, "a"); // Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); } // Delete Error try { validationService.delete(0, "abc"); // Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); } try { validationService.delete(2, null); // Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); } try { validationService.delete(0, null); // Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); } try { validationService.delete(0, "0000"); // Assert.fail(); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); } } finally { consumerContext.stop(); consumerContext.close(); } } finally { providerContext.stop(); providerContext.close(); } }