@Before public void setUp() throws Exception { eqs.createEventQueue(pathQueue1); eqs.createEventQueue(pathQueue2); notification.register("/profiles/.*", "greeting.name.say-hello", "/m2log.*", pathQueue1); assertTrue( "SetUp : failed during notification.register(/profiles/.*, greeting.name.say-hello,/m2log.*, pathQueue1)", notification.list().length == 1); notification.register("/profiles/.*", "greeting.name.read", "/m2log.*", pathQueue2); Rule[] t = notification.list(); Rule r = t[0]; assertTrue( "SetUp : failed during notification.register(/profiles/.*, greeting.name.read,/m2log.*, pathQueue2) " + r.getQueuePath() + " " + r.getObjectre() + " " + r.getSubjectre() + " " + r.getTargetre() + " " + notification.list().length, notification.list().length == 2); greeting.createName(pathResource, valueResource); }
@After public void tearDown() throws Exception { notification.unregister("/profiles/.*", "greeting.name.say-hello", "/m2log.*", pathQueue1); notification.unregister("/profiles/.*", "greeting.name.read", "/m2log.*", pathQueue2); eqs.removeQueue(pathQueue1); eqs.removeQueue(pathQueue2); greeting.deleteName(pathResource); }
/** * Test Right Throw one event matching by 0 queue * * @throws InterruptedException * @throws GreetingServiceException * @throws EventQueueServiceException * @throws NotificationServiceException */ @Test(timeout = 20000) public void testNotificationEventNotMatching() throws InterruptedException, GreetingServiceException, EventQueueServiceException, NotificationServiceException { logger.info("testNotificationEventNotMatching() called"); greeting.createName("/eventNotMatching", "eventNotMatching"); greeting.deleteName("/eventNotMatching"); Thread.sleep(1000); assertEquals( "TestNotificationEventNotMatching : expected 0 event into queue1(" + pathQueue1 + ") but found " + eqs.getEvents(pathQueue1).length, eqs.getEvents(pathQueue1).length, 0); assertEquals( "TestNotificationEventNotMatching : expected 0 event into queue1(" + pathQueue2 + ") but found " + eqs.getEvents(pathQueue2).length, eqs.getEvents(pathQueue2).length, 0); }
/** * Test Right Throw one event into one queue and assert the event is inserted only in one queue * the test assert too that no other event appears into the queue * * @throws Exception */ @Test(timeout = 30000) public void testNotificationSimple() throws Exception { logger.info("testNotificationSimple() called"); String caller = membership.getProfilePathForConnectedIdentifier(); greeting.sayHello(pathResource); Event[] lEvent1 = new Event[] {}; // wait that an event appears into the queue while (lEvent1.length == 0) { lEvent1 = eqs.getEvents(pathQueue1); } assertTrue(lEvent1.length == 1); Event e = lEvent1[0]; assertEquals( "TestNotification1 : event resource expected /name but found " + e.getFromResource(), e.getFromResource(), pathResource); assertEquals( "TestNotification1 : event type expected greeting.name.create but found " + e.getEventType(), e.getEventType(), "greeting.name.say-hello"); assertEquals( "TestNotification1 : event throwedBy expected " + caller + " but found" + e.getThrowedBy(), e.getThrowedBy(), caller); Event[] lEvent2 = eqs.getEvents(pathQueue2); assertTrue( "TestNotification1 : expected 0 event into queue2(" + pathQueue2 + ") but found " + lEvent2.length, lEvent2.length == 0); Thread.sleep(10); // assert that no other events happen lEvent1 = eqs.getEvents(pathQueue1); assertTrue( "TestNotification1 : expected 0 event into queue1(" + pathQueue1 + ") but found " + lEvent1.length, lEvent1.length == 1); }
/** * Test Boundary Throw a null event * * @throws NotificationServiceException */ @Test(expected = NotificationServiceException.class) public void testNotificationThrowNull() throws NotificationServiceException { logger.info("testNotificationThrowNull() called"); greeting.throwNullEvent(); }
/** * Test Right Throw 2 events matching by one queue, but user can read only one event * * @throws MembershipServiceException * @throws GreetingServiceException * @throws EventQueueServiceException * @throws InterruptedException * @throws LoginException */ @Test(timeout = 50000) public void testNotificationRightEvent() throws MembershipServiceException, GreetingServiceException, EventQueueServiceException, InterruptedException, LoginException { logger.info("testNotificationRightEvent() called"); String caller = membership.getProfilePathForConnectedIdentifier(); // root permit to kermit to create something on / greeting.giveAutorization("/", "/profiles/kermit", new String[] {"create"}); loginContext.logout(); // login kermit UsernamePasswordHandler uph = new UsernamePasswordHandler("kermit", "thefrog"); loginContext = new LoginContext("qualipso", uph); loginContext.login(); // kermit create a folder and a resource on this folder and // create a read event on this name greeting.createFolder("/kermitFolder", "kermitFolder"); greeting.createName("/kermitFolder/kermitName", "kermitName"); greeting.readName("/kermitFolder/kermitName"); greeting.deleteName("/kermitFolder/kermitName"); greeting.deleteFolder("/kermitFolder"); loginContext.logout(); uph = new UsernamePasswordHandler("root", AllTests.ROOT_ACCOUNT_PASS); loginContext = new LoginContext("qualipso", uph); loginContext.login(); greeting.readName(pathResource); Event[] lEvent2 = new Event[] {}; while (lEvent2.length < 1) { lEvent2 = eqs.getEvents(pathQueue2); } assertTrue( "TestNotificationRighEvent : expected 1 events into queue2(" + pathQueue2 + ") but found " + lEvent2.length, lEvent2.length == 1); Event e = lEvent2[0]; assertEquals( "TestNotificationRighEvent : event resource expected " + pathResource + " but found " + e.getFromResource(), e.getFromResource(), pathResource); assertEquals( "TestNotificationRighEvent : event type expected greeting.name.create but found " + e.getEventType(), e.getEventType(), "greeting.name.read"); assertEquals( "TestNotificationRighEvent : event throwedBy expected " + caller + " but found" + e.getThrowedBy(), e.getThrowedBy(), caller); Thread.sleep(60); assertTrue( "TestNotificationRighEvent : expected 1 event into queue1 but found " + eqs.getEvents(pathQueue2).length, eqs.getEvents(pathQueue2).length == 1); }