Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. package org.jboss.soa.qa.drools.cep;
  2.  
  3. import org.jboss.arquillian.container.test.api.Deployment;
  4. import org.jboss.arquillian.junit.Arquillian;
  5. import org.jboss.shrinkwrap.api.spec.JavaArchive;
  6. import org.jboss.soa.qa.BaseSwitchYardTest;
  7. import org.jboss.soa.qa.audit.auditor.ProviderAuditor;
  8. import org.jboss.soa.qa.runtime.TestSupport;
  9.  
  10. import org.switchyard.bus.camel.audit.Auditor;
  11.  
  12. import org.junit.Assert;
  13. import org.junit.Before;
  14. import org.junit.Test;
  15. import org.junit.runner.RunWith;
  16.  
  17. import java.util.Arrays;
  18.  
  19. @RunWith(Arquillian.class)
  20. public class DroolsCEPServiceTest extends BaseSwitchYardTest {
  21.  
  22. private static final int WAIT_TIME = 2000;
  23.  
  24. private TestDependencies test;
  25.  
  26. @Deployment
  27. public static JavaArchive createDeployment() {
  28. return TestCommons.createDeployment();
  29. }
  30.  
  31. @Before
  32. public void setUp() {
  33. if (test == null) {
  34. test = (TestDependencies) new TestSupport().initCDI(TestDependencies.class);
  35. }
  36. test.getAudit().clear();
  37. test.getEventLogger().clear();
  38. test.getBeatLogger().clear();
  39. test.getAudit().setAuditors(Arrays.<Class<? extends Auditor>>asList(ProviderAuditor.class));
  40. }
  41.  
  42. @Test
  43. public void stream() throws InterruptedException {
  44. callService(test.getStreamService());
  45. }
  46.  
  47. @Test
  48. public void cloud() throws InterruptedException {
  49. callService(test.getCloudService());
  50. }
  51.  
  52. private void callService(CEPService service) throws InterruptedException {
  53. System.out.println("@@@@@@ Calling SwitchYard Service from Groovy test");
  54. final Tick t1 = new Tick().setEventName("heartBeat OK tick 1");
  55. final Tick t2 = new Tick().setEventName("heartBeat OK tick 2");
  56. final Tick t3 = new Tick().setEventName("heartBeat OK tick 3");
  57.  
  58. service.heartBeat(t1);
  59. service.heartBeat(t2);
  60. Thread.sleep(WAIT_TIME);
  61. Assert.assertTrue("Waiting for second beat", test.getBeatLogger().isEmpty());
  62.  
  63. service.tickerBeat(t3);
  64. Thread.sleep(WAIT_TIME);
  65. Assert.assertFalse("Rule firedXXX", test.getBeatLogger().isEmpty());
  66.  
  67. // Listeners called
  68. Assert.assertTrue("Runtime logger called", test.getEventLogger().containsSource("runtime"));
  69. Assert.assertTrue("Agenda logger called", test.getEventLogger().containsSource("agenda"));
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement