示例#1
0
  /**
   * 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 processBeanMetaData(
     final DeploymentUnit deploymentUnit, final EnterpriseBeanMetaData enterpriseBeanMetaData)
     throws DeploymentUnitProcessingException {
   if (enterpriseBeanMetaData.isSession()) {
     assert enterpriseBeanMetaData instanceof SessionBeanMetaData
         : enterpriseBeanMetaData + " is not a SessionBeanMetaData";
     processSessionBeanMetaData(deploymentUnit, (SessionBeanMetaData) enterpriseBeanMetaData);
   }
 }
  private void processSessionBeans(
      final DeploymentUnit deploymentUnit,
      final List<AnnotationInstance> sessionBeanAnnotations,
      final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) {

    final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
    final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();

    // process these session bean annotations and create component descriptions out of it
    for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) {
      final AnnotationTarget target = sessionBeanAnnotation.target();
      if (!(target instanceof ClassInfo)) {
        // Let's just WARN and move on. No need to throw an error
        logger.warn(
            sessionBeanAnnotation.name()
                + " annotation is expected to be applied on class level. "
                + target
                + " is not a class");
        continue;
      }
      final ClassInfo sessionBeanClassInfo = (ClassInfo) target;
      // skip if it's not a valid class for session bean
      if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) {
        continue;
      }
      final String ejbName = sessionBeanClassInfo.name().local();
      final AnnotationValue nameValue = sessionBeanAnnotation.value("name");
      final String beanName =
          nameValue == null || nameValue.asString().isEmpty() ? ejbName : nameValue.asString();
      final EnterpriseBeanMetaData beanMetaData =
          getEnterpriseBeanMetaData(deploymentUnit, beanName);
      final SessionBeanComponentDescription.SessionBeanType sessionBeanType;
      final String beanClassName;
      if (beanMetaData != null && beanMetaData instanceof SessionBeanMetaData) {
        sessionBeanType =
            override(
                annotatedSessionBeanType,
                descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType()));
      } else {
        sessionBeanType = annotatedSessionBeanType;
      }
      if (beanMetaData != null) {
        beanClassName =
            override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass());
      } else {
        beanClassName = sessionBeanClassInfo.name().toString();
      }

      final SessionBeanComponentDescription sessionBeanDescription;
      switch (sessionBeanType) {
        case STATELESS:
          sessionBeanDescription =
              new StatelessComponentDescription(
                  beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName);
          break;
        case STATEFUL:
          sessionBeanDescription =
              new StatefulComponentDescription(
                  beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName);
          break;
        case SINGLETON:
          sessionBeanDescription =
              new SingletonComponentDescription(
                  beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName);
          break;
        default:
          throw new IllegalArgumentException("Unknown session bean type: " + sessionBeanType);
      }

      if (appclient) {
        deploymentUnit.addToAttachmentList(
            Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS, sessionBeanDescription);
      } else {
        // Add this component description to module description
        ejbJarDescription.getEEModuleDescription().addComponent(sessionBeanDescription);
      }
    }

    EjbDeploymentMarker.mark(deploymentUnit);
  }
示例#4
0
  /**
   * 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");
      }
    }
  }