/** * Tests if the deployment initialization from a reflection class with a invalid * @Remote bean annotation throws an exception. * * @return void * @expectedException \Exception */ public function testFromReflectionClassWithInvalidRemoteAnnotation() { // 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()); // create a mock reflection class $reflectionClass = $this->getMockBuilder('AppserverIo\\Lang\\Reflection\\ReflectionClass')->setMethods(array('hasAnnotation'))->setConstructorArgs(array(__CLASS__, array(), $aliases))->getMock(); // mock the methods $reflectionClass->expects($this->exactly(2))->method('hasAnnotation')->withConsecutive(array('Local'), array('Remote'))->willReturnOnConsecutiveCalls(false, true); // mock the methods $this->descriptor->expects($this->once())->method('newAnnotationInstance')->with($reflectionClass)->will($this->returnValue($annotation)); // initialize the descriptor instance $this->descriptor->fromReflectionClass($reflectionClass); }
/** * 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\StatelessSessionBeanDescriptorInterface|null The initialized descriptor instance */ public function fromReflectionClass(ClassInterface $reflectionClass) { // query if we've an enterprise bean with a @Stateless annotation if ($reflectionClass->hasAnnotation(Stateless::ANNOTATION) === false) { // if not, do nothing return; } // set the session type $this->setSessionType(StatelessSessionBeanDescriptor::SESSION_TYPE); // 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 configuration * * @return \AppserverIo\Psr\EnterpriseBeans\Description\SingletonSessionBeanDescriptorInterface|null The initialized descriptor instance */ public function fromReflectionClass(ClassInterface $reflectionClass) { // query if we've an enterprise bean with a @Singleton annotation if ($reflectionClass->hasAnnotation(Singleton::ANNOTATION) === false) { // if not, do nothing return; } // set the session type $this->setSessionType(SingletonSessionBeanDescriptor::SESSION_TYPE); // we've to check for a @PostDetach or @PreAttach annotation foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { // if we found a @PostDetach annotation, invoke the method if ($reflectionMethod->hasAnnotation(PostDetach::ANNOTATION)) { $this->addPostDetachCallback(DescriptorUtil::trim($reflectionMethod->getMethodName())); } // if we found a @PreAttach annotation, invoke the method if ($reflectionMethod->hasAnnotation(PreAttach::ANNOTATION)) { $this->addPreAttachCallback(DescriptorUtil::trim($reflectionMethod->getMethodName())); } } // initialize the descriptor instance parent::fromReflectionClass($reflectionClass); // if we found a bean with @Singleton + @Startup annotation if ($reflectionClass->hasAnnotation(Startup::ANNOTATION)) { // instanciate the bean $this->setInitOnStartup(); } // return the instance return $this; }