/** * Tests if the merge method works successfully. * * @return void */ public function testMergeSuccessful() { // initialize the configuration $node = new SessionNode(); $node->initFromFile(__DIR__ . '/_files/dd-sessionbean.xml'); // initialize the descriptor from the nodes data $this->descriptor->fromConfiguration($node); // initialize the descriptor to merge $descriptorToMerge = $this->getMockForAbstractClass('AppserverIo\\Description\\SessionBeanDescriptor'); // initialize the configuration of the descriptor to be merged $nodeToMerge = new SessionNode(); $nodeToMerge->initFromFile(__DIR__ . '/_files/dd-sessionbean-to-merge.xml'); $descriptorToMerge->fromConfiguration($nodeToMerge); // merge the descriptors $this->descriptor->merge($descriptorToMerge); // check if all values have been merged $this->assertSame('SampleProcessor', $this->descriptor->getName()); $this->assertSame('AppserverIo\\Apps\\Example\\Services\\SampleProcessor', $this->descriptor->getClassName()); $this->assertSame('Stateless', $this->descriptor->getSessionType()); $this->assertCount(2, $this->descriptor->getEpbReferences()); $this->assertCount(3, $this->descriptor->getResReferences()); $this->assertCount(2, $this->descriptor->getPersistenceUnitReferences()); $this->assertCount(7, $this->descriptor->getReferences()); // check for initialized lifecycle callbacks $this->assertContains('initialize', $this->descriptor->getPostConstructCallbacks()); $this->assertContains('initializeIt', $this->descriptor->getPostConstructCallbacks()); $this->assertContains('destroy', $this->descriptor->getPreDestroyCallbacks()); $this->assertContains('destroyIt', $this->descriptor->getPreDestroyCallbacks()); }
/** * Initializes a bean descriptor instance from the passed configuration node. * * @param \AppserverIo\Description\Configuration\ConfigurationInterface $configuration The configuration node with the bean configuration * * @return \AppserverIo\Psr\EnterpriseBeans\Description\StatelessSessionBeanDescriptorInterface|null The initialized descriptor instance */ public function fromConfiguration(ConfigurationInterface $configuration) { // query whether or not we've a session bean configuration if (!$configuration instanceof SessionConfigurationInterface) { return; } // query wheter or not the session type matches if ((string) $configuration->getSessionType() !== StatelessSessionBeanDescriptor::SESSION_TYPE) { return; } // initialize the descriptor instance parent::fromConfiguration($configuration); // return the instance return $this; }
/** * Merges the passed configuration into this one. Configuration values * of the passed configuration will overwrite the this one. * * @param \AppserverIo\Psr\EnterpriseBeans\Description\BeanDescriptorInterface $beanDescriptor The configuration to merge * * @return void */ public function merge(BeanDescriptorInterface $beanDescriptor) { // only merge the more special configuration fields if the desciptor has the right type if (!$beanDescriptor instanceof SingletonSessionBeanDescriptorInterface) { return; } // merge the default bean members by invoking the parent method parent::merge($beanDescriptor); // merge the post detach callback method names foreach ($beanDescriptor->getPostDetachCallbacks() as $postDetachCallback) { if (in_array($postDetachCallback, $this->getPostDetachCallbacks()) === false) { $this->addPostDetachCallback($postDetachCallback); } } // merge the pre attach callback method names foreach ($beanDescriptor->getPreAttachCallbacks() as $preAttachCallback) { if (in_array($preAttachCallback, $this->getPreAttachCallbacks()) === false) { $this->addPreAttachCallback($preAttachCallback); } } // merge the startup flag $this->setInitOnStartup($beanDescriptor->isInitOnStartup()); }
/** * Merges the passed configuration into this one. Configuration values * of the passed configuration will overwrite the this one. * * @param \AppserverIo\Psr\EnterpriseBeans\Description\BeanDescriptorInterface $beanDescriptor The configuration to merge * * @return void */ public function merge(BeanDescriptorInterface $beanDescriptor) { // only merge the more special configuration fields if the desciptor has the right type if (!$beanDescriptor instanceof StatefulSessionBeanDescriptorInterface) { return; } // merge the default bean members by invoking the parent method parent::merge($beanDescriptor); // merge the post detach callback method names foreach ($beanDescriptor->getPostDetachCallbacks() as $postDetachCallback) { if (in_array($postDetachCallback, $this->getPostDetachCallbacks()) === false) { $this->addPostDetachCallback($postDetachCallback); } } // merge the pre attach callback method names foreach ($beanDescriptor->getPreAttachCallbacks() as $preAttachCallback) { if (in_array($preAttachCallback, $this->getPreAttachCallbacks()) === false) { $this->addPreAttachCallback($preAttachCallback); } } // merge the post activate callback method names foreach ($beanDescriptor->getPostActivateCallbacks() as $postActivateCallback) { if (in_array($postActivateCallback, $this->getPostActivateCallbacks()) === false) { $this->addPostActivateCallback($postActivateCallback); } } // merge the pre passivate callback method names foreach ($beanDescriptor->getPrePassivateCallbacks() as $prePassivateCallback) { if (in_array($prePassivateCallback, $this->getPrePassivateCallbacks()) === false) { $this->addPrePassivateCallback($prePassivateCallback); } } // merge the pre attach callback method names foreach ($beanDescriptor->getRemoveMethods() as $removeMethod) { if (in_array($removeMethod, $this->getRemoveMethods()) === false) { $this->addRemoveMethod($removeMethod); } } }