protected void assertNamedMethod( String prefix, int size, NamedMethodMetaData namedMethodMetaData) { assertNotNull(namedMethodMetaData); assertId(prefix, namedMethodMetaData); assertEquals(prefix, namedMethodMetaData.getMethodName()); if (size > 0) assertMethodParams(prefix, size, namedMethodMetaData.getMethodParams()); }
private void assertQueryMethod( String ejbName, int size, NamedMethodMetaData queryMethodMetaData) { assertNotNull(queryMethodMetaData); assertId(ejbName + "QueryMethod", queryMethodMetaData); assertEquals(ejbName + "QueryMethod", queryMethodMetaData.getMethodName()); if (size > 0) assertMethodParams(ejbName + "QueryMethod", size, queryMethodMetaData.getMethodParams()); }
/** * 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); }
@Override protected void processElement( NamedMethodMetaData metaData, XMLStreamReader reader, PropertyReplacer propertyReplacer) throws XMLStreamException { final EjbJarElement ejbJarElement = EjbJarElement.forName(reader.getLocalName()); switch (ejbJarElement) { case METHOD_NAME: metaData.setMethodName(getElementText(reader, propertyReplacer)); return; case METHOD_PARAMS: metaData.setMethodParams( MethodParametersMetaDataParser.INSTANCE.parse(reader, propertyReplacer)); return; } super.processElement(metaData, reader, propertyReplacer); }
/** * 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"); } } }