/** * Tests if the merge method works successfully. * * @return void */ public function testMergeSuccessful() { // initialize the configuration $node = new PersistenceUnitRefNode(); $node->initFromFile(__DIR__ . '/_files/dd-persistence-unit-ref.xml'); // initialize the descriptor from the nodes data $this->descriptor->fromConfiguration($node); // initialize the descriptor to merge $descriptorToMerge = $this->getMockForAbstractClass('AppserverIo\\Description\\PersistenceUnitReferenceDescriptor'); // initialize the configuration of the descriptor to be merged $nodeToMerge = new PersistenceUnitRefNode(); $nodeToMerge->initFromFile(__DIR__ . '/_files/dd-persistence-unit-ref-to-merge.xml'); $descriptorToMerge->fromConfiguration($nodeToMerge); // merge the descriptors $this->descriptor->merge($descriptorToMerge); // check if all values have been initialized $this->assertSame('env/persistence/ReferenceToMyNewPersistenceUnit', $this->descriptor->getName()); $this->assertSame('MyNewPersistenceUnit', $this->descriptor->getUnitName()); $this->assertInstanceOf('AppserverIo\\Description\\InjectionTargetDescriptor', $injectTarget = $this->descriptor->getInjectionTarget()); $this->assertSame('AppserverIo\\Apps\\Example\\Services\\NewSampleProcessor', $injectTarget->getTargetClass()); $this->assertSame('injectMyNewPersistenceUnit', $injectTarget->getTargetMethod()); }
/** * Tests the static newDescriptorInstance() method. * * @return void */ public function testNewDescriptorInstance() { $this->assertInstanceOf('AppserverIo\\Description\\PersistenceUnitReferenceDescriptor', PersistenceUnitReferenceDescriptor::newDescriptorInstance()); }
/** * Initializes the bean configuration instance with the references of the passed reflection class instance. * * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean configuration * * @return void */ public function referencesFromReflectionClass(ClassInterface $reflectionClass) { // we've to check for property annotations that references EPB or resources foreach ($reflectionClass->getProperties() as $reflectionProperty) { // load the EPB references if ($epbReference = EpbReferenceDescriptor::newDescriptorInstance()->fromReflectionProperty($reflectionProperty)) { $this->addEpbReference($epbReference); } // load the resource references if ($resReference = ResReferenceDescriptor::newDescriptorInstance()->fromReflectionProperty($reflectionProperty)) { $this->addResReference($resReference); } // load the persistence unit references if ($persistenceUnitReference = PersistenceUnitReferenceDescriptor::newDescriptorInstance()->fromReflectionProperty($reflectionProperty)) { $this->addPersistenceUnitReference($persistenceUnitReference); } } // we've to check for method annotations that references EPB or resources foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { // load the EPB references if ($epbReference = EpbReferenceDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)) { $this->addEpbReference($epbReference); } // load the resource references if ($resReference = ResReferenceDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)) { $this->addResReference($resReference); } // load the persistence unit references if ($persistenceUnitReference = PersistenceUnitReferenceDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)) { $this->addPersistenceUnitReference($persistenceUnitReference); } } }