/** * Tests if the deployment initialization from a reflection class with a bean annotation * without the name attribute works as expected. * * @return void */ public function testFromReflectionClassWithAnnotationWithoutNameAttribute() { // prepare the annotation values $values = array(); // create a mock annotation implementation $beanAnnotation = $this->getMockBuilder('AppserverIo\\Psr\\EnterpriseBeans\\Annotations\\AbstractBeanAnnotation')->setConstructorArgs(array('Stateless', $values))->getMockForAbstractClass(); // create a mock annotation $annotation = $this->getMockBuilder('AppserverIo\\Lang\\Reflection\\ReflectionAnnotation')->setMethods(array('getAnnotationName', 'getValues', 'newInstance'))->setConstructorArgs(array('Stateless', $values))->getMock(); // mock the ReflectionAnnotation methods $annotation->expects($this->once())->method('getAnnotationName')->will($this->returnValue('Stateless')); $annotation->expects($this->once())->method('getValues')->will($this->returnValue($values)); $annotation->expects($this->once())->method('newInstance')->will($this->returnValue($beanAnnotation)); // initialize the annotation aliases $aliases = array(Resource::ANNOTATION => Resource::__getClass(), EnterpriseBean::ANNOTATION => EnterpriseBean::__getClass(), PersistenceUnit::ANNOTATION => PersistenceUnit::__getClass()); // create a reflection class $reflectionClass = new ReflectionClass(__CLASS__, array(), $aliases); // mock the methods $this->descriptor->expects($this->once())->method('newAnnotationInstance')->with($reflectionClass)->will($this->returnValue($annotation)); // initialize the descriptor instance $this->descriptor->fromReflectionClass($reflectionClass); // check the name parsed from the reflection class $this->assertSame(__CLASS__, $this->descriptor->getClassName()); $this->assertSame('BeanDescriptorTest', $this->descriptor->getName()); $this->assertCount(1, $this->descriptor->getEpbReferences()); $this->assertCount(1, $this->descriptor->getResReferences()); $this->assertCount(1, $this->descriptor->getPersistenceUnitReferences()); $this->assertCount(3, $this->descriptor->getReferences()); }
/** * Initializes the bean descriptor instance from the passed reflection class instance. * * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean configuration * * @return \AppserverIo\Psr\EnterpriseBeans\Description\MessageDrivenBeanDescriptorInterface|null The initialized descriptor instance */ public function fromReflectionClass(ClassInterface $reflectionClass) { // query if we've an enterprise bean with a @MessageDriven annotation if ($reflectionClass->hasAnnotation(MessageDriven::ANNOTATION) === false) { // if not, do nothing return; } // initialize the descriptor instance parent::fromReflectionClass($reflectionClass); // return the instance return $this; }
/** * Initializes the bean descriptor instance from the passed reflection class instance. * * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean description * * @return void * * @throws \Exception */ public function fromReflectionClass(ClassInterface $reflectionClass) { // initialize the bean descriptor parent::fromReflectionClass($reflectionClass); // query whether we've a @Local annotation if ($reflectionClass->hasAnnotation('Local')) { throw new \Exception('@Local annotation not implemented'); } else { $this->setLocal(sprintf('%sLocal', rtrim($this->getName(), 'Bean'))); } // query whether we've a @Remote annotation if ($reflectionClass->hasAnnotation('Remote')) { throw new \Exception('@Remote annotation not implemented'); } else { $this->setRemote(sprintf('%sRemote', rtrim($this->getName(), 'Bean'))); } // we've to check for a @PostConstruct or @PreDestroy annotation foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { // if we found a @PostConstruct annotation, invoke the method if ($reflectionMethod->hasAnnotation(PostConstruct::ANNOTATION)) { $this->addPostConstructCallback(DescriptorUtil::trim($reflectionMethod->getMethodName())); } // if we found a @PreDestroy annotation, invoke the method if ($reflectionMethod->hasAnnotation(PreDestroy::ANNOTATION)) { $this->addPreDestroyCallback(DescriptorUtil::trim($reflectionMethod->getMethodName())); } } }