/** * Tests that a MDB configured for timer through ejb-jar.xml is processed correctly for metadata */ @Test public void testScheduleForMDBInEjbJarXml() throws Exception { EjbJarMetaData jarMetaData = unmarshal(EjbJarMetaData.class, "/org/jboss/metadata/ejb/test/schedule/ejb-jar.xml"); assertNotNull(jarMetaData); EnterpriseBeanMetaData enterpriseBean = jarMetaData.getEnterpriseBean("MDBInEjbJarXml"); assertTrue( "metadata " + enterpriseBean.getClass() + " is not of type " + MessageDrivenBean31MetaData.class, (enterpriseBean instanceof MessageDrivenBean31MetaData)); MessageDrivenBean31MetaData mdb = (MessageDrivenBean31MetaData) enterpriseBean; // get the timers List<TimerMetaData> timers = mdb.getTimers(); // check the metadata for validity Assert.assertNotNull("Timer metadata not found on bean " + mdb.getName(), timers); Assert.assertEquals( "Unexpected number of timers found on bean " + mdb.getName(), 1, timers.size()); TimerMetaData timerMetaData = timers.get(0); Assert.assertEquals( "Unexpected info on timer metadata", "SomeInfoInXml", timerMetaData.getInfo()); Assert.assertFalse("Timer was expected to be persistent", timerMetaData.isPersistent()); // get hold of the schedule and validate it ScheduleMetaData schedule = timerMetaData.getSchedule(); Assert.assertEquals("Unexpected seconds in schedule", "5", schedule.getSecond()); Assert.assertEquals("Unexpected minutes in schedule", "4", schedule.getMinute()); Assert.assertEquals("Unexpected hours in schedule", "3", schedule.getHour()); Assert.assertEquals("Unexpected day of week in schedule", "2", schedule.getDayOfWeek()); Assert.assertEquals("Unexpected day of month in schedule", "1", schedule.getDayOfMonth()); Assert.assertEquals("Unexpected month in schedule", "Jan", schedule.getMonth()); Assert.assertEquals("Unexpected year in schedule", "*", schedule.getYear()); // test the timeout method NamedMethodMetaData timeoutMethod = timerMetaData.getTimeoutMethod(); Assert.assertNotNull("Timeout method is null", timeoutMethod); Assert.assertEquals( "Unexpected timeout method", "dummyMDBMethod", timeoutMethod.getMethodName()); MethodParametersMetaData timeoutMethodParams = timeoutMethod.getMethodParams(); Assert.assertNotNull("Timeout method params are null", timeoutMethodParams); Assert.assertEquals( "Unexpected number of method params for timeout method", 1, timeoutMethodParams.size()); String timeoutMethodParam = timeoutMethodParams.get(0); Assert.assertEquals( "Unexpected method param for timeout method", Timer.class.getName(), timeoutMethodParam); }
/** * Test that {@link MessageDrivenBean31MetaData#merge(MessageDrivenBeanMetaData, * MessageDrivenBeanMetaData)} works as expected for timer metadata */ @Test public void testMDBTimerMerge2() { TimerMetaData persistentTimer = new TimerMetaData(); persistentTimer.setPersistent(true); MessageDrivenBean31MetaData original = new MessageDrivenBean31MetaData(); original.setEjbName("DummyBean"); JBossGenericBeanMetaData overriden = new JBossGenericBeanMetaData(); overriden.setEjbName("DummyBean"); overriden.addTimer(persistentTimer); MessageDrivenBean31MetaData mergedBean = new MessageDrivenBean31MetaData(); mergedBean.merge(overriden, original); List<TimerMetaData> mergedTimers = mergedBean.getTimers(); Assert.assertNotNull("Merged timers is null", mergedTimers); Assert.assertEquals("Unexpected number of timers in merged metadata", 1, mergedTimers.size()); Assert.assertTrue( "Timer in merged metadata is not persistent", mergedTimers.get(0).isPersistent()); }
/** * Test that {@link MessageDrivenBean31MetaData#merge(MessageDrivenBeanMetaData, * MessageDrivenBeanMetaData)} works as expected for timer metadata */ @Test public void testMDBTimerMerge() { TimerMetaData nonPersistentTimer = new TimerMetaData(); nonPersistentTimer.setPersistent(false); TimerMetaData persistentTimer = new TimerMetaData(); persistentTimer.setPersistent(true); MessageDrivenBean31MetaData original = new MessageDrivenBean31MetaData(); original.setEjbName("DummyBean"); original.addTimer(nonPersistentTimer); JBossGenericBeanMetaData overriden = new JBossGenericBeanMetaData(); overriden.setEjbName("DummyBean"); overriden.addTimer(persistentTimer); MessageDrivenBean31MetaData mergedBean = new MessageDrivenBean31MetaData(); mergedBean.merge(overriden, original); List<TimerMetaData> mergedTimers = mergedBean.getTimers(); Assert.assertNotNull("Merged timers is null", mergedTimers); Assert.assertEquals("Unexpected number of timers in merged metadata", 2, mergedTimers.size()); boolean foundPersistentTimer = false; boolean foundNonPersistentTimer = false; for (TimerMetaData timer : mergedTimers) { if (timer.isPersistent()) { foundPersistentTimer = true; } else { foundNonPersistentTimer = true; } } Assert.assertTrue("Persistent timer not found in merged metadata", foundPersistentTimer); Assert.assertTrue("Non-Persistent timer not found in merged metadata", foundNonPersistentTimer); }
/** * Tests that a SLSB which has methods marked as auto timeout methods in ejb-jar.xml is processed * correctly for metadata */ @Test public void testMultipleSchedulesOnSLSBInEjbJarXML() throws Exception { EjbJarMetaData jarMetaData = unmarshal( EjbJarMetaData.class, "/org/jboss/metadata/ejb/test/schedule/ejb-jar-with-multiple-schedules.xml"); assertNotNull(jarMetaData); EnterpriseBeanMetaData enterpriseBean = jarMetaData.getEnterpriseBean("MultipleScheduleSLSBInEjbJarXML"); assertTrue( "metadata " + enterpriseBean.getClass() + " is not of type " + SessionBean31MetaData.class, (enterpriseBean instanceof SessionBean31MetaData)); SessionBean31MetaData sessionBean = (SessionBean31MetaData) enterpriseBean; // get the timers List<TimerMetaData> timers = sessionBean.getTimers(); // check the metadata for validity Assert.assertNotNull("Timer metadata not found on bean " + sessionBean.getName(), timers); Assert.assertEquals( "Unexpected number of timers found on bean " + sessionBean.getName(), 2, timers.size()); for (int i = 0; i < timers.size(); i++) { TimerMetaData timerMetaData = timers.get(i); String info = timerMetaData.getInfo(); Assert.assertNotNull("Info not present on timer metadata", timerMetaData.getInfo()); int infoVal = Integer.parseInt(info); NamedMethodMetaData timeoutMethod = timerMetaData.getTimeoutMethod(); Assert.assertNotNull("Timeout method not present on timer metadata", timeoutMethod); MethodParametersMetaData timeoutMethodParams = timeoutMethod.getMethodParams(); Assert.assertNotNull("Timeout method params are null", timeoutMethodParams); Assert.assertEquals( "Unexpected number of method params for timeout method", 1, timeoutMethodParams.size()); String timeoutMethodParam = timeoutMethodParams.get(0); Assert.assertEquals( "Unexpected method param for timeout method", Timer.class.getName(), timeoutMethodParam); String timeoutMethodName = timeoutMethod.getMethodName(); ScheduleMetaData schedule = timerMetaData.getSchedule(); switch (infoVal) { case 1: Assert.assertEquals("Unexpected timeout method", "dummySLSBMethod", timeoutMethodName); Assert.assertEquals("Unexpected seconds in schedule", "0", schedule.getSecond()); Assert.assertEquals("Unexpected minutes in schedule", "0", schedule.getMinute()); Assert.assertEquals("Unexpected hours in schedule", "0", schedule.getHour()); Assert.assertEquals("Unexpected day of week in schedule", "Wed", schedule.getDayOfWeek()); Assert.assertEquals("Unexpected day of month in schedule", "1", schedule.getDayOfMonth()); Assert.assertEquals("Unexpected month in schedule", "*", schedule.getMonth()); Assert.assertEquals("Unexpected year in schedule", "*", schedule.getYear()); Assert.assertTrue("Timer was expected to be persistent", timerMetaData.isPersistent()); break; case 2: Assert.assertEquals("Unexpected timeout method", "anotherDummyMethod", timeoutMethodName); Assert.assertEquals("Unexpected seconds in schedule", "0", schedule.getSecond()); Assert.assertEquals("Unexpected minutes in schedule", "0", schedule.getMinute()); Assert.assertEquals("Unexpected hours in schedule", "0", schedule.getHour()); Assert.assertEquals("Unexpected day of week in schedule", "*", schedule.getDayOfWeek()); Assert.assertEquals("Unexpected day of month in schedule", "*", schedule.getDayOfMonth()); Assert.assertEquals("Unexpected month in schedule", "*", schedule.getMonth()); Assert.assertEquals("Unexpected year in schedule", "*", schedule.getYear()); Assert.assertTrue("Timer was expected to be persistent", timerMetaData.isPersistent()); break; default: Assert.fail("Unexpected info " + info + " on timer metadata"); } } }