Author: reinhard Date: Sun Apr 24 05:07:22 2005 New Revision: 164469 URL: http://svn.apache.org/viewcvs?rev=164469&view=rev Log: work on actual block deployment: create wiring information; fix object/xml-mapping when namespaces are used; testcases
Added: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/descriptor/deployment/ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/descriptor/deployment/DeploymentProperty.java cocoon/whiteboard/block-deployer/test/sample-descriptors/block_001.xml cocoon/whiteboard/block-deployer/test/sample-descriptors/deploy_001.xml - copied unchanged from r159025, cocoon/whiteboard/block-deployer/test/sample-descriptors/sample-deploy.xml cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_001.xml cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_002.xml Removed: cocoon/whiteboard/block-deployer/test/sample-descriptors/sample-block.xml cocoon/whiteboard/block-deployer/test/sample-descriptors/sample-deploy.xml cocoon/whiteboard/block-deployer/test/sample-descriptors/sample-wiring.xml Modified: cocoon/whiteboard/block-deployer/.classpath cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockFactory.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10-mapping.xml cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/descriptor/Cob10Descriptor.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml Modified: cocoon/whiteboard/block-deployer/.classpath URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/.classpath?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/.classpath (original) +++ cocoon/whiteboard/block-deployer/.classpath Sun Apr 24 05:07:22 2005 @@ -68,10 +68,6 @@ <attributes> </attributes> </classpathentry> - <classpathentry kind="lib" path="lib/castor-0.9.6-xml.jar"> - <attributes> - </attributes> - </classpathentry> <classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"> <attributes> </attributes> @@ -85,6 +81,10 @@ </attributes> </classpathentry> <classpathentry kind="lib" path="build/CocoonBlockDeployer-generated-0.1dev.jar"> + <attributes> + </attributes> + </classpathentry> + <classpathentry kind="lib" path="lib/castor-0.9.6-xml.jar"> <attributes> </attributes> </classpathentry> Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java (original) +++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java Sun Apr 24 05:07:22 2005 @@ -61,4 +61,9 @@ */ public BlockDeploymentData getBlockDeploymentData(); + /** + * @param set BlockDeploymentData + */ + public void setBlockDeploymentData(BlockDeploymentData data); + } Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java (original) +++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java Sun Apr 24 05:07:22 2005 @@ -17,7 +17,7 @@ import java.util.Iterator; -import org.apache.cocoon.blockdeployer.block.descriptor.BlockProperty; +import org.apache.cocoon.blockdeployer.block.descriptor.deployment.DeploymentProperty; public interface BlockDeploymentData { @@ -44,6 +44,6 @@ * @param name of the property * @return returns a BlockProperty object containing the property information */ - public BlockProperty getProperty(String name); + public DeploymentProperty getProperty(String name); } Added: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/descriptor/deployment/DeploymentProperty.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/descriptor/deployment/DeploymentProperty.java?rev=164469&view=auto ============================================================================== --- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/descriptor/deployment/DeploymentProperty.java (added) +++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/descriptor/deployment/DeploymentProperty.java Sun Apr 24 05:07:22 2005 @@ -0,0 +1,24 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.blockdeployer.block.descriptor.deployment; + +public interface DeploymentProperty { + + public String getName(); + + public String getValue(); + +} Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockFactory.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockFactory.java?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockFactory.java (original) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockFactory.java Sun Apr 24 05:07:22 2005 @@ -15,7 +15,6 @@ */ package org.apache.cocoon.blockdeployer.block; -import java.io.IOException; import java.io.InputStream; import org.apache.cocoon.blockdeployer.block.descriptor.Cob10Descriptor; @@ -25,9 +24,7 @@ import org.exolab.castor.xml.Unmarshaller; import org.w3c.dom.Document; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.InputSource; -import org.xml.sax.SAXException; /** * This factory class creates RemoteBlocks based on the descriptor @@ -51,7 +48,7 @@ /* * FIXME the descriptor should be analyzed whether it is correct - otherwise raise an exception */ - public static Block getRemoteBlock(InputStream descriptor, Locator locator) { + public static Block createBlock(InputStream descriptor, Locator locator) { if(descriptor == null) { throw new NullPointerException("The descriptor mustn't be null."); } @@ -66,18 +63,8 @@ } catch (Exception e) { throw new RuntimeException("Block descriptor can't be read."); } - Document descriptorDocument = parser.getDocument(); - NodeList rootNodeList = descriptorDocument.getChildNodes(); - String namespace = null; - for(int i = 0; i <= rootNodeList.getLength() && i <= 1; i++ ) { - Node rootChildNode = rootNodeList.item(i); - if(rootChildNode.getNodeType() == Node.ELEMENT_NODE) { - namespace = rootChildNode.getNamespaceURI(); - System.out.println("namespace: " + namespace); - } - } - - if(Cob10.NAMESPACE.equals(namespace)) { + Document descriptorDocument = parser.getDocument(); + if(Cob10.NAMESPACE.equals(descriptorDocument.getDocumentElement().getNamespaceURI())) { // it's a Cob10 ... Cob10 cob10 = new Cob10(); cob10.setBlockDescriptor(createCOB10Descriptor(descriptorDocument)); Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10-mapping.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10-mapping.xml?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10-mapping.xml (original) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10-mapping.xml Sun Apr 24 05:07:22 2005 @@ -16,41 +16,28 @@ --> <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN" "http://castor.exolab.org/mapping.dtd"> -<mapping> +<mapping xmlns:b="http://apache.org/cocoon/blocks/cob/1.0"> <class name="org.apache.cocoon.blockdeployer.block.descriptor.Cob10Descriptor"> - <map-to xml="block" ns-uri="http://apache.org/cocoon/blocks/cob/1.0"/> - <field name="name" type="string" > - <bind-xml name="name" node="element" /> - </field> - <field name="blockId" type="string"> + <map-to xml="b:block"/> + <field name="blockId"> <bind-xml name="id" node="attribute"/> - </field> - <field name="properties" type="org.apache.cocoon.blockdeployer.block.descriptor.Cob10Property" collection="collection" > - <bind-xml name="property" node="element" location="properties"/> - </field> - <field name="requirements" type="org.apache.cocoon.blockdeployer.block.descriptor.Cob10Requirement" collection="collection" > - <bind-xml name="requires" node="element" location="requirements"/> - </field> + </field> + <field name="name"> + <bind-xml name="b:name" node="element" /> + </field> + <field name="properties" type="org.apache.cocoon.blockdeployer.block.descriptor.Cob10Property" collection="collection"> + <bind-xml name="b:property" node="element" location="properties"/> + </field> </class> <class name="org.apache.cocoon.blockdeployer.block.descriptor.Cob10Property"> - <map-to ns-uri="http://apache.org/cocoon/blocks/cob/1.0"/> - <field name="name" type="string"> - <bind-xml name="name" node="attribute"/> - </field> - <field name="description" type="string" > - <bind-xml name="description" node="element" /> - </field> - <field name="defaultValue" type="string" > - <bind-xml name="default" node="element" /> + <field name="name"> + <bind-xml name="b:name" node="attribute"/> </field> - </class> - <class name="org.apache.cocoon.blockdeployer.block.descriptor.Cob10Requirement"> - <map-to ns-uri="http://apache.org/cocoon/blocks/cob/1.0"/> - <field name="name" type="string"> - <bind-xml name="name" node="attribute"/> - </field> - <field name="blockId" type="string" > - <bind-xml name="block" node="element" /> - </field> - </class> + <field name="defaultValue"> + <bind-xml name="b:default"/> + </field> + <field name="description"> + <bind-xml name="b:description"/> + </field> + </class> </mapping> Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java (original) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java Sun Apr 24 05:07:22 2005 @@ -30,9 +30,10 @@ public final static String NAMESPACE = "http://apache.org/cocoon/blocks/cob/1.0"; - private Locator locator; - private BlockDescriptor blockDescriptor; - private String blockId; + protected Locator locator; + protected BlockDescriptor blockDescriptor; + protected String blockId; + protected BlockDeploymentData blockDeploymentData; public Locator getLocator() { return this.locator; @@ -75,7 +76,11 @@ } public BlockDeploymentData getBlockDeploymentData() { - return null; + return this.blockDeploymentData; + } + + public void setBlockDeploymentData(BlockDeploymentData data) { + this.blockDeploymentData = data; } } Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/descriptor/Cob10Descriptor.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/descriptor/Cob10Descriptor.java?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/descriptor/Cob10Descriptor.java (original) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/descriptor/Cob10Descriptor.java Sun Apr 24 05:07:22 2005 @@ -42,7 +42,7 @@ private String sitemap; private List dependencies; private Collection properties = new ArrayList(); - private Map propertiesMap = new HashMap(); + private Map propertiesMap = null; private Collection requirements = new ArrayList(); // **************** base meta information ******************** @@ -132,19 +132,23 @@ // **************** properties ******************** public Iterator getPropertyNames() { - Iterator propertiesIt = this.properties.iterator(); - while( propertiesIt.hasNext() ) { - BlockProperty bp = (BlockProperty) propertiesIt.next(); - this.propertiesMap.put(bp.getName(), bp); - } + if(this.propertiesMap == null) setupPropertyNames(); return this.propertiesMap.keySet().iterator(); } - + public BlockProperty getProperty(String name) { + if(this.propertiesMap == null) setupPropertyNames(); return (BlockProperty) this.propertiesMap.get(name); } + protected void setupPropertyNames() { + this.propertiesMap = new HashMap(); + for(Iterator it = this.properties.iterator(); it.hasNext();) { + BlockProperty bp = (BlockProperty) it.next(); + this.propertiesMap.put(bp.getName(), bp); + } + } public Collection getProperties() { return this.properties; Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java (original) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java Sun Apr 24 05:07:22 2005 @@ -20,15 +20,21 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; +import java.util.Iterator; import java.util.zip.ZipInputStream; import org.apache.cocoon.blockdeployer.block.Block; +import org.apache.cocoon.blockdeployer.block.descriptor.BlockDescriptor; +import org.apache.cocoon.blockdeployer.block.descriptor.BlockProperty; +import org.apache.cocoon.blockdeployer.block.descriptor.deployment.DeploymentProperty; import org.apache.cocoon.blockdeployer.locking.Lock; import org.apache.cocoon.blockdeployer.locking.LockingException; import org.apache.cocoon.blockdeployer.logging.LoggerFacade; import org.apache.cocoon.blockdeployer.utils.CommonsTransactionLogger; import org.apache.cocoon.blockdeployer.utils.LocatorUtils; import org.apache.cocoon.blockdeployer.wiring.wiring10.Mount; +import org.apache.cocoon.blockdeployer.wiring.wiring10.Properties; +import org.apache.cocoon.blockdeployer.wiring.wiring10.Property; import org.apache.cocoon.blockdeployer.wiring.wiring10.Wiring; import org.apache.commons.transaction.file.FileResourceManager; import org.apache.commons.transaction.file.ResourceManagerException; @@ -72,8 +78,8 @@ try { this.wiring10 = readWiring(new File(this.deploymentDir, WIRING_XML), this.logger); } catch (Exception ex) { - String msg = "The application server's wiring.xml can't be read."; - logger.error(ApplicationServer22Locator.class, msg); + String msg = "The application server's wiring.xml can't be read. (probably a Castor mapping error --> see the logs)"; + logger.error(ApplicationServer22Locator.class, msg, ex); throw new NullPointerException(msg); } @@ -106,7 +112,7 @@ this.logger.debug(this.getClass(), "Block [" + block.getBlockId() + "] to be deployed in " + nextDir); LocatorUtils.writeZip(new ZipInputStream(block.getStream()), this.frm, this.txId, nextDir); } - this.updateWiring(block); + updateWiring(block, wiring10); } catch(Exception ex) { throw new DeploymentException("Block " + block.getBlockId() + " couldn't be deployed.", ex); } @@ -219,7 +225,7 @@ // ------- wiring and block helper methods --------------------------------------- - private static Wiring readWiring(File wiringDescriptor, LoggerFacade logger) throws Exception { + protected static Wiring readWiring(File wiringDescriptor, LoggerFacade logger) throws Exception { // read the wiring information (currently we have to support only // http://apache.org/cocoon/blocks/wiring/1.0) Wiring wiring10 = null; @@ -250,19 +256,39 @@ } - protected void updateWiring(Block block) { + protected static void updateWiring(Block block, Wiring wiring10) { org.apache.cocoon.blockdeployer.wiring.wiring10.Block wiredBlock = new org.apache.cocoon.blockdeployer.wiring.wiring10.Block(); + BlockDescriptor descriptor = block.getBlockDescriptor(); + // id wiredBlock.setId(block.getBlockId()); + // mount path Mount mount = new Mount(); mount.setPath(block.getBlockDeploymentData().getMountPath()); wiredBlock.setMount(mount); + + //properties + Properties wiredProperties = new Properties(); + for(Iterator it = descriptor.getPropertyNames(); it.hasNext();) { + BlockProperty descriptorProperty = descriptor.getProperty((String) it.next()); + DeploymentProperty deploymentProperty = block.getBlockDeploymentData().getProperty(descriptorProperty.getName()); + Property wiredProperty = new Property(); + wiredProperty.setName(descriptorProperty.getName()); + if(deploymentProperty != null) { + wiredProperty.setValue(deploymentProperty.getValue()); + } else { + wiredProperty.setValue(descriptorProperty.getDefaultValue()); + } + wiredProperties.addProperty(wiredProperty); + } + wiredBlock.setProperties(wiredProperties); // add block to wiring - this.wiring10.addBlock(wiredBlock); + wiring10.addBlock(wiredBlock); + } protected boolean blockExists(Wiring wiring10, String blockId) { Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java (original) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java Sun Apr 24 05:07:22 2005 @@ -91,7 +91,7 @@ if(descriptorInputStream == null) { throw new BlockNotFoundException("Block " + blockUri + " not found."); } - return BlockFactory.getRemoteBlock(descriptorInputStream, this); + return BlockFactory.createBlock(descriptorInputStream, this); } public Block[] browse() throws IOException { Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java (original) +++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java Sun Apr 24 05:07:22 2005 @@ -43,8 +43,13 @@ public static final String UNAVAILABLE_INVALID_BLOCKPATH = "/mycompany.com/invalid/1.0.0"; public static final String UNAVAILABLE_INVALID_BLOCKFILE = "invalid.cob"; - // sample wiring - public static final String WIRING_FILE = "test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml"; + // sample wiring files + public static final String WIRING_001 = "test/sample-descriptors/wiring_001.xml"; + public static final String WIRING_002 = "test/sample-descriptors/wiring_002.xml"; + + // sample block descriptors + public static final String BLOCK_001 = "test/sample-descriptors/block_001.xml"; + } Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java (original) +++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java Sun Apr 24 05:07:22 2005 @@ -17,7 +17,9 @@ import java.io.File; import java.io.FileInputStream; +import java.io.FileReader; import java.io.InputStream; +import java.util.ArrayList; import jodd.file.FileUtil; @@ -25,24 +27,29 @@ import org.apache.cocoon.blockdeployer.LogEnabledTestCase; import org.apache.cocoon.blockdeployer.block.Block; import org.apache.cocoon.blockdeployer.block.BlockDeploymentData; +import org.apache.cocoon.blockdeployer.block.BlockFactory; import org.apache.cocoon.blockdeployer.block.descriptor.BlockDescriptor; +import org.apache.cocoon.blockdeployer.block.descriptor.deployment.DeploymentProperty; +import org.apache.cocoon.blockdeployer.wiring.wiring10.Property; import org.apache.cocoon.blockdeployer.wiring.wiring10.Wiring; import org.easymock.MockControl; /** * @since 0.1 + * + * TODO continue with setting of "connections | connection" (needs revisiting Cob10.java as it doesn't reflect the + * latest changes (block.xml only contains "contracts" and default implementations. Concrete implementation + * set during deployment in deploy.xml --> object BlockDeploymentData!!!) + * */ public class ApplicationServer22LocatorTest extends LogEnabledTestCase { private final static String ASL = Constants.TMP_VALID_ASL_1; - private void setupExamples() { - FileUtil.deleteDir(ASL); - if((new File(ASL).exists())) fail("Error: Directory mustn't exist (test isolation not guaranteed!"); - FileUtil.mkdirs(ASL); - FileUtil.copyDir(Constants.VALID_ASL_1, ASL); - } - + /** + * test transaction management - ApplicationServer22Locator should only work with started transaction + * @throws Exception + */ public void testTransactionManagement() throws Exception { setupExamples(); ApplicationServer22Locator asl = new ApplicationServer22Locator(new File(ASL), this.logger); @@ -79,71 +86,183 @@ assertNotNull(asl.wiring10); } - public void testDeploySingleBlock() throws Exception { + /** + * Test the extraction of the block into the target directory. + * @throws Exception + */ + public void testBlockExtraction() throws Exception { setupExamples(); - // create locator, use transaction mgmt, deploy block ApplicationServer22Locator asl = new ApplicationServer22Locator(new File(ASL), this.logger); asl.startTransaction(); - // create block metadata - MockControl bddCtrl = MockControl.createControl(BlockDeploymentData.class); - BlockDeploymentData bdd = (BlockDeploymentData) bddCtrl.getMock(); + String blockId = "http://bla"; + Block b = createBinaryBlockMockWithoutDeploymentData(blockId); - String mountPath = "/mountPath"; + MockControl bddCtrl = MockControl.createControl(BlockDeploymentData.class); + BlockDeploymentData bdd = (BlockDeploymentData) bddCtrl.getMock(); + // mountPath bdd.getMountPath(); - bddCtrl.setReturnValue(mountPath); + bddCtrl.setReturnValue(null); + // properties + bdd.getPropertyNames(); + bddCtrl.setReturnValue((new ArrayList()).iterator()); - bddCtrl.replay(); + bddCtrl.replay(); + b.setBlockDeploymentData(bdd); - String blockId = "http://bla"; - Block b = createBlockMock(blockId, bdd); asl.deploy(b); asl.commitTransaction(); - // test that the block is extracted correctly by checking whether the - // COB_INF and the block.xml are available + // test that the block is extracted correctly File descriptor = new File(ASL + "/WEB-INF/blocks/000001/block.xml"); + File unavailableDescriptor = new File(ASL + "/WEB-INF/blocks/000002"); assertTrue(descriptor.exists()); - - Wiring wiring = asl.wiring10; - - org.apache.cocoon.blockdeployer.wiring.wiring10.Block wiredBlock = null; - for(int i = 0; i < wiring.getBlockCount(); i++) { - org.apache.cocoon.blockdeployer.wiring.wiring10.Block locBlock = wiring.getBlock(i); - if(blockId.equals(locBlock.getId())) { - wiredBlock = locBlock; - break; - } + assertFalse(unavailableDescriptor.exists()); + } + + /** + * Test whether NullPointException is thrown correctly if DeploymentData are missing + * @throws Exception + */ + public void testDeploymentDataMapping1() throws Exception { + Block block = createBlockWithDeploymentDataOnly(new File(Constants.BLOCK_001)); + Wiring wiring = createWiring(new File(Constants.WIRING_001)); + try { + ApplicationServer22Locator.updateWiring(block, wiring); + fail("There are no deployment metadata set. This should lead to a NullPointerException!"); + } catch(NullPointerException npe) { + // correct behaviour } - assertNotNull("The installed block must be added to the wiring.", wiredBlock); - assertEquals(mountPath, wiredBlock.getMount().getPath()); - } - /* - public void testAddBlockToWiring() throws Exception { - ApplicationServer22Locator asl = new ApplicationServer22Locator( - new File(ASL), this.logger); - String blockId = "http://bla"; - Block block = createBlockMock(blockId, null); - Wiring wiring = new Wiring(); - asl.addBlockToWiring(wiring, block); + /** + * Test working scenario: use properties + */ + public void testDeploymentDataMapping2() throws Exception { + Block block = createBlockWithDeploymentDataOnly(new File(Constants.BLOCK_001)); + Wiring wiring = createWiring(new File(Constants.WIRING_002)); + + MockControl bddCtrl = MockControl.createControl(BlockDeploymentData.class); + BlockDeploymentData bdd = (BlockDeploymentData) bddCtrl.getMock(); - // check that only one block is set - int blockCount = wiring.getBlockCount(); - // assertEquals(blockCount, 1); + // mountPath + String mountPath = "/mountPath"; + bdd.getMountPath(); + bddCtrl.setReturnValue(mountPath); + // properties + bdd.getProperty("prop1"); + bddCtrl.setReturnValue(null); + bdd.getProperty("prop2"); + bddCtrl.setReturnValue(null); - // check that the right number of connections is set - Connections connections = wiring.getBlock(0).getConnections(); - int connectionsCount = connections.getConnectionCount(); - // assertEquals(connectionsCount, 1); + bddCtrl.replay(); + block.setBlockDeploymentData(bdd); + + ApplicationServer22Locator.updateWiring(block, wiring); + + // test object construction + org.apache.cocoon.blockdeployer.wiring.wiring10.Block wiredBlock = + wiring.getBlock(0); + assertNotNull(wiredBlock); + // test mountPath + assertEquals(mountPath, wiredBlock.getMount().getPath()); + // test properties + Property wiredProperty1 = wiredBlock.getProperties().getProperty(0); + assertEquals(wiredProperty1.getName(), "prop1"); + assertEquals(wiredProperty1.getValue(), "1"); + Property wiredProperty2 = wiredBlock.getProperties().getProperty(1); + assertEquals(wiredProperty2.getName(), "prop2"); + assertEquals(wiredProperty2.getValue(), null); + } + + /** + * Test if the DeploymentData overrides the default values! + */ + public void testDeploymentDataMapping3() throws Exception { + Block block = createBlockWithDeploymentDataOnly(new File(Constants.BLOCK_001)); + Wiring wiring = createWiring(new File(Constants.WIRING_002)); + + MockControl bddCtrl = MockControl.createControl(BlockDeploymentData.class); + BlockDeploymentData bdd = (BlockDeploymentData) bddCtrl.getMock(); + + // mountPath + String mountPath = "/mountPath"; + bdd.getMountPath(); + bddCtrl.setReturnValue(mountPath); + // properties + // prop1 + MockControl prop1Ctrl = MockControl.createControl(DeploymentProperty.class); + DeploymentProperty prop1 = (DeploymentProperty) prop1Ctrl.getMock(); + prop1.getName(); + prop1Ctrl.setReturnValue("prop1"); + String prop1Value = "prop1_value"; + prop1.getValue(); + prop1Ctrl.setReturnValue(prop1Value); + prop1Ctrl.replay(); + bdd.getProperty("prop1"); + bddCtrl.setReturnValue(prop1); + // prop2 + MockControl prop2Ctrl = MockControl.createControl(DeploymentProperty.class); + DeploymentProperty prop2 = (DeploymentProperty) prop2Ctrl.getMock(); + prop2.getName(); + prop2Ctrl.setReturnValue("prop2"); + String prop2Value = "prop2_value"; + prop2.getValue(); + prop2Ctrl.setReturnValue(prop2Value); + prop2Ctrl.replay(); + bdd.getProperty("prop2"); + bddCtrl.setReturnValue(prop2); - // check that the right connection is set - Connection connection = connections.getConnection(0); - // assertEquals(connection.getBlock(), blockId); + bddCtrl.replay(); + block.setBlockDeploymentData(bdd); + + ApplicationServer22Locator.updateWiring(block, wiring); + + // test object construction + org.apache.cocoon.blockdeployer.wiring.wiring10.Block wiredBlock = + wiring.getBlock(0); + + // test properties + Property wiredProperty1 = wiredBlock.getProperties().getProperty(0); + assertEquals(wiredProperty1.getName(), "prop1"); + assertEquals(prop1Value, wiredProperty1.getValue()); + Property wiredProperty2 = wiredBlock.getProperties().getProperty(1); + assertEquals(wiredProperty2.getName(), "prop2"); + assertEquals(prop2Value, wiredProperty2.getValue()); + } + + // **************************************** helper methods ***************************************** + + /** + * Helper method to create a wiring out of an XML file + */ + public static Wiring createWiring(File wiringFile) throws Exception { + return (Wiring) Wiring.unmarshal(new FileReader(wiringFile)); } - */ + + /** + * Helper method to create a block out of an XML file + */ + public static Block createBlockWithDeploymentDataOnly(File descriptor) throws Exception { + MockControl locatorCtrl = MockControl.createNiceControl(Locator.class); + Locator locator = (Locator) locatorCtrl.getMock(); + locatorCtrl.replay(); + return BlockFactory.createBlock(new FileInputStream(descriptor), locator); + } + + /** + * Helper method to setup examples, also checks whether isolation is guaranteed + */ + private void setupExamples() { + FileUtil.deleteDir(ASL); + if((new File(ASL).exists())) fail("Error: Directory mustn't exist (test isolation not guaranteed!"); + FileUtil.mkdirs(ASL); + FileUtil.copyDir(Constants.VALID_ASL_1, ASL); + } - private Block createBlockMock(String id, BlockDeploymentData deployData) throws Exception { + /** + * create a block that also returns a binary + */ + private Block createBinaryBlockMockWithoutDeploymentData(String id) throws Exception { // create the Block MockControl blockControl = MockControl.createNiceControl(Block.class); Block block = (Block) blockControl.getMock(); @@ -158,7 +277,10 @@ // create the deployment meta information block.getBlockDeploymentData(); - blockControl.setReturnValue(deployData); + MockControl bddCtrl = MockControl.createNiceControl(BlockDeploymentData.class); + BlockDeploymentData bdd = (BlockDeploymentData) bddCtrl.getMock(); + bddCtrl.replay(); + blockControl.setReturnValue(bdd); // create the Inputstream containing block as binary block.getStream(); @@ -172,7 +294,9 @@ return block; } - + /** + * create the BlockDescriptorMock, only sets the block ID + */ private BlockDescriptor createBlockDescriptorMock(String id) { MockControl descriptorControl = MockControl.createControl(BlockDescriptor.class); BlockDescriptor descriptor = (BlockDescriptor) descriptorControl.getMock(); @@ -180,8 +304,105 @@ descriptor.getBlockId(); descriptorControl.setReturnValue(id); + descriptor.getPropertyNames(); + descriptorControl.setReturnValue((new ArrayList()).iterator()); + descriptorControl.replay(); return descriptor; } + + /* + public void testDeploySingleBlock() throws Exception { + setupExamples(); + // create locator, use transaction mgmt, deploy block + // ------------------------------------------------------------------------- + ApplicationServer22Locator asl = new ApplicationServer22Locator(new File(ASL), this.logger); + asl.startTransaction(); + + // create block metadata + // ------------------------------------------------------------------------- + MockControl bddCtrl = MockControl.createControl(BlockDeploymentData.class); + BlockDeploymentData blockDeploymentData = (BlockDeploymentData) bddCtrl.getMock(); + // mountPath + String mountPath = "/mountPath"; + blockDeploymentData.getMountPath(); + bddCtrl.setReturnValue(mountPath); + // properties + List properties = new ArrayList(); + // property1 + MockControl blockProperty1Ctrl = MockControl.createControl(BlockProperty.class); + BlockProperty blockProperty1 = (BlockProperty) blockProperty1Ctrl.getMock(); + String property1_name = "prop1"; + String property1_value = "value1"; + blockProperty1.getName(); + properties.add(property1_name); + blockDeploymentData.getProperty(property1_name); + bddCtrl.setReturnValue(blockProperty1); + blockProperty1Ctrl.setReturnValue(property1_name); + + + + blockDeploymentData.getPropertyNames(); + bddCtrl.setReturnValue(properties.iterator()); + + + bddCtrl.replay(); + + String blockId = "http://bla"; + Block b = createBlockMock(blockId, blockDeploymentData); + + // test + // ------------------------------------------------------------------------- + asl.deploy(b); + asl.commitTransaction(); + // test that the block is extracted correctly by checking whether the + // COB_INF and the block.xml are available + File descriptor = new File(ASL + "/WEB-INF/blocks/000001/block.xml"); + assertTrue(descriptor.exists()); + + Wiring wiring = asl.wiring10; + + org.apache.cocoon.blockdeployer.wiring.wiring10.Block wiredBlock = null; + for(int i = 0; i < wiring.getBlockCount(); i++) { + org.apache.cocoon.blockdeployer.wiring.wiring10.Block locBlock = wiring.getBlock(i); + if(blockId.equals(locBlock.getId())) { + wiredBlock = locBlock; + break; + } + } + assertNotNull("The installed block must be added to the wiring.", wiredBlock); + assertEquals(mountPath, wiredBlock.getMount().getPath()); + + Properties wiredProperties = wiredBlock.getProperties(); + // for(int i = 0; i < wiredProperties.getPropertyCount(); i++) { + + // } + // assertTrue(properties.isEmpty()); + } + */ + + /* + public void testAddBlockToWiring() throws Exception { + ApplicationServer22Locator asl = new ApplicationServer22Locator( + new File(ASL), this.logger); + String blockId = "http://bla"; + Block block = createBlockMock(blockId, null); + Wiring wiring = new Wiring(); + asl.addBlockToWiring(wiring, block); + + // check that only one block is set + int blockCount = wiring.getBlockCount(); + // assertEquals(blockCount, 1); + + // check that the right number of connections is set + Connections connections = wiring.getBlock(0).getConnections(); + int connectionsCount = connections.getConnectionCount(); + // assertEquals(connectionsCount, 1); + + // check that the right connection is set + Connection connection = connections.getConnection(0); + // assertEquals(connection.getBlock(), blockId); + } + */ } Added: cocoon/whiteboard/block-deployer/test/sample-descriptors/block_001.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/sample-descriptors/block_001.xml?rev=164469&view=auto ============================================================================== --- cocoon/whiteboard/block-deployer/test/sample-descriptors/block_001.xml (added) +++ cocoon/whiteboard/block-deployer/test/sample-descriptors/block_001.xml Sun Apr 24 05:07:22 2005 @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + Copyright 1999-2004 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<block xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://apache.org/cocoon/blocks/cob/1.0 ../../src/schema/cob-schema-1.0.xsd" + xmlns="http://apache.org/cocoon/blocks/cob/1.0" id="http://mycompany.com/webmail/1.3.43"> + + <name>block.xml for test cases [001]</name> + <description href="http://testcase">testcase</description> + <license href="http://www.mycompany.com/license/1.3">BSD-style License</license> + <author href="http://www.mycompany.com/">MyCompany Inc.</author> + <sitemap src="webmail.xmap"/> + <state href="" community="committed" interfaces="stable" implementation="stable"/> + + <properties> + <property name="prop1"> + <default>1</default> + <description>test property with default value</description> + </property> + <property name="prop2"> + <description>test property without default value</description> + </property> + </properties> + +</block> Added: cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_001.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_001.xml?rev=164469&view=auto ============================================================================== --- cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_001.xml (added) +++ cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_001.xml Sun Apr 24 05:07:22 2005 @@ -0,0 +1,38 @@ +<!-- + Copyright 1999-2004 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<wiring xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://apache.org/cocoon/blocks/wiring/1.0 ../../src/schema/wiring-schema-1.0.xsd" + xmlns="http://apache.org/cocoon/blocks/wiring/1.0"> + <block id="http://mycompany.com/webmail/1.3.43" location="000001"> + <mount path="/mail/"/> + <connections> + <connection name="external-skin" block="http://yetanothercompany.com/skins/fancy/1.2.2"/> + <connection name="internal-skin" block="http://mycompany.com/skins/corporate/34.3.345"/> + <connection name="repository" block="http://mycompany.com/repositories/email/exchange/3.2.1"/> + </connections> + <properties> + <property name="user" value="guest"/> + <property name="password" value="sj3u493"/> + </properties> + </block> + <block id="http://mycompany.com/repositories/email/exchange/3.2.1" location="000002"> + <properties> + <property name="host" value="mail.blah.org"/> + </properties> + </block> + <block id="http://yetanothercompany.com/skins/fancy/1.2.2" location="000003"/> + <block id="http://mycompany.com/skins/corporate/34.3.345" location="000004"/> +</wiring> Added: cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_002.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_002.xml?rev=164469&view=auto ============================================================================== --- cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_002.xml (added) +++ cocoon/whiteboard/block-deployer/test/sample-descriptors/wiring_002.xml Sun Apr 24 05:07:22 2005 @@ -0,0 +1,20 @@ +<!-- + Copyright 1999-2004 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<wiring xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://apache.org/cocoon/blocks/wiring/1.0 ../../src/schema/wiring-schema-1.0.xsd" + xmlns="http://apache.org/cocoon/blocks/wiring/1.0"> + +</wiring> \ No newline at end of file Modified: cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml?rev=164469&r1=164468&r2=164469&view=diff ============================================================================== --- cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml (original) +++ cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml Sun Apr 24 05:07:22 2005 @@ -18,34 +18,4 @@ xsi:schemaLocation="http://apache.org/cocoon/blocks/wiring/1.0 wiring-schema-1.0.xsd" > - <block id="http://mycompany.com/webmail/1.3.43" - location="WEB-INF/blocks/384938958499"> - <mount path="/mail/"/> - <connections> - <connection name="external-skin" - block="http://yetanothercompany.com/skins/fancy/1.2.2"/> - <connection name="internal-skin" - block="http://mycompany.com/skins/corporate/34.3.345"/> - <connection name="repository" - block="http://mycompany.com/repositories/email/exchange/3.2.1"/> - </connections> - <properties> - <property name="user" value="guest"/> - <property name="password" value="sj3u493"/> - </properties> - </block> - - <block id="http://mycompany.com/repositories/email/exchange/3.2.1" - location="WEB-INF/blocks/394781274834"> - <properties> - <property name="host" value="mail.blah.org"/> - </properties> - </block> - - <block id="http://yetanothercompany.com/skins/fancy/1.2.2" - location="WEB-INF/blocks/947384127832"/> - - <block id="http://mycompany.com/skins/corporate/34.3.345" - location="WEB-INF/blocks/746394782637"/> - </wiring>