You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2004/10/11 10:02:29 UTC
svn commit: rev 54515 - in cocoon/whiteboard/block-deployer: src/api/org/apache/cocoon/blockdeployer/block src/api/org/apache/cocoon/blockdeployer/repository src/impl/org/apache/cocoon/blockdeployer/block src/impl/org/apache/cocoon/blockdeployer/repository test/junit/org/apache/cocoon/blockdeployer/repository
Author: reinhard
Date: Mon Oct 11 01:02:28 2004
New Revision: 54515
Added:
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/BlockNotFoundException.java
- copied, changed from rev 47196, cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/UnavailableBlockException.java
Removed:
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/UnavailableBlockException.java
Modified:
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RemoteBlock.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Locator.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RealRemoteBlock.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocator.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocatorTest.java
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java
Log:
work on Exception handling and Javadocs
Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RemoteBlock.java
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RemoteBlock.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RemoteBlock.java Mon Oct 11 01:02:28 2004
@@ -15,6 +15,7 @@
*/
package org.apache.cocoon.blockdeployer.block;
+import java.io.IOException;
import java.io.InputStream;
import org.apache.cocoon.blockdeployer.block.descriptor.BlockDescriptor;
@@ -42,8 +43,9 @@
* This method executes the call that reads the complete block as stream.
*
* @return returns an @link InputStream of the Block
+ * @throws throws IOException if block can't be read by its locator
*/
- public InputStream getStream() throws Exception;
+ public InputStream getStream() throws IOException;
/**
Copied: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/BlockNotFoundException.java (from rev 47196, cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/UnavailableBlockException.java)
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/UnavailableBlockException.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/BlockNotFoundException.java Mon Oct 11 01:02:28 2004
@@ -18,13 +18,13 @@
/**
* @since 0.1
*/
-public class UnavailableBlockException extends Exception {
+public class BlockNotFoundException extends Exception {
- public UnavailableBlockException() {
+ public BlockNotFoundException() {
super();
}
- public UnavailableBlockException(String s) {
+ public BlockNotFoundException(String s) {
super(s);
}
Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java Mon Oct 11 01:02:28 2004
@@ -15,6 +15,8 @@
*/
package org.apache.cocoon.blockdeployer.repository;
+import java.io.IOException;
+
import org.apache.cocoon.blockdeployer.block.RemoteBlock;
/**
@@ -31,8 +33,10 @@
*
* @param an array of blocks
* @return true if deployment was successfull, false if not
- * @throws @link UnsupportedBlockException
+ * @throws @link UnsupportedBlockException if the block version is not supported
+ * @throws @link IOException if the block can't be deployed in the target filesystem
*/
- public boolean deploy(RemoteBlock[] blocks) throws Exception;
+ public boolean deploy(RemoteBlock[] blocks)
+ throws UnsupportedBlockException, IOException;
}
Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Locator.java
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Locator.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Locator.java Mon Oct 11 01:02:28 2004
@@ -15,6 +15,7 @@
*/
package org.apache.cocoon.blockdeployer.repository;
+import java.io.IOException;
import java.io.InputStream;
import org.apache.cocoon.blockdeployer.block.RemoteBlock;
@@ -29,10 +30,31 @@
public static final String COB_INF_BLOCK_XML = "COB-INF/block.xml";
- public RemoteBlock getRemoteBlock(String blockId) throws Exception;
+ /**
+ * Get a block by its id (e.g. http://mycompany.com/webmail/1.3.43). The Locator
+ * implementation "knows" where to look for this block.
+ *
+ * @param Get a block by its id.
+ * @return A @link RemoteBlock object representing a block
+ * @throws BlockNotFoundException if the locator can't find the requested block
+ * @throws IOException in the case that the block can be found but there are problems
+ * when accessing its meta data
+ */
+ public RemoteBlock getRemoteBlock(String blockId) throws BlockNotFoundException, IOException;
+ /**
+ * @return returns the unique identifier of this locator
+ */
public String getIdentifier();
- public InputStream getBlockAsStream(String blockId) throws Exception;
+ /**
+ * Access the block as @link InputStream
+ *
+ * @param blockId
+ * @return
+ * @throws IOException if there is a problem while creating a stream
+ * @throws BlockNotFoundException if the block can't be reached at all
+ */
+ public InputStream getBlockAsStream(String blockId) throws IOException, BlockNotFoundException;
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RealRemoteBlock.java
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RealRemoteBlock.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RealRemoteBlock.java Mon Oct 11 01:02:28 2004
@@ -15,6 +15,7 @@
*/
package org.apache.cocoon.blockdeployer.block;
+import java.io.IOException;
import java.io.InputStream;
import org.apache.cocoon.blockdeployer.block.RemoteBlock;
@@ -46,7 +47,7 @@
this.blockDescriptor = blockDescriptor;
}
- public InputStream getStream() throws Exception {
+ public InputStream getStream() throws IOException {
return null;
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java Mon Oct 11 01:02:28 2004
@@ -46,7 +46,13 @@
* implementation is used
* FIXME the descriptor should be analyzed whether it is correct - otherwise raise an exception
*/
- public static RemoteBlock getRemoteBlock(InputStream descriptor, Locator locator) throws Exception {
+ public static RemoteBlock getRemoteBlock(InputStream descriptor, Locator locator) {
+ if(descriptor == null) {
+ throw new NullPointerException("The descriptor mustn't be null.");
+ }
+ if(locator == null) {
+ throw new NullPointerException("The locator mustn't be null.");
+ }
// analyse the descriptor and decide which RemoteBlock implementation should be used
// it's a RealRemoteBlock ...
@@ -58,16 +64,21 @@
return realRemoteBlock;
}
- private static RealBlockDescriptor createCOB10Descriptor(InputStream descriptor) throws Exception {
- Mapping mapping = new Mapping();
- mapping.loadMapping("mapping/block.xml-mapping.xml");
-
- Unmarshaller unmarshaller = new Unmarshaller(RealBlockDescriptor.class);
- unmarshaller.setMapping(mapping);
- unmarshaller.setIgnoreExtraAttributes(true);
- unmarshaller.setIgnoreExtraElements(true);
- // unmarshaller.setDebug(true);
- RealBlockDescriptor realBlockDescriptor = (RealBlockDescriptor)unmarshaller.unmarshal(new InputStreamReader(descriptor));
+ private static RealBlockDescriptor createCOB10Descriptor(InputStream descriptor) {
+ RealBlockDescriptor realBlockDescriptor = null;
+ try {
+ Mapping mapping = new Mapping();
+ mapping.loadMapping("mapping/block.xml-mapping.xml");
+
+ Unmarshaller unmarshaller = new Unmarshaller(RealBlockDescriptor.class);
+ unmarshaller.setMapping(mapping);
+ unmarshaller.setIgnoreExtraAttributes(true);
+ unmarshaller.setIgnoreExtraElements(true);
+ // unmarshaller.setDebug(true);
+ realBlockDescriptor = (RealBlockDescriptor)unmarshaller.unmarshal(new InputStreamReader(descriptor));
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
return realBlockDescriptor;
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocator.java
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocator.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocator.java Mon Oct 11 01:02:28 2004
@@ -17,6 +17,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
@@ -76,10 +77,9 @@
throw new IllegalArgumentException(
"The specified base dir is not writeable!");
}
- // FIXME enable check again (as soon as test provides a Wiring object)
+
if (wiring == null) {
- // throw new IllegalArgumentException("The wiring mustn't be
- // null!");
+ throw new NullPointerException("The wiring mustn't be null!");
}
this.basedir = basedir;
this.wiring = wiring;
@@ -101,7 +101,7 @@
* FIXME throw appropriate exceptions if problem(s) occur(s) FIXME currently
* only hacked so that it works - needs some refactoring to clean up code
*/
- public boolean deploy(RemoteBlock[] blocks) throws Exception {
+ public boolean deploy(RemoteBlock[] blocks) throws UnsupportedBlockException, IOException {
// create the workdir
// FIXME workdir has to be configurable
String workDir = "WORK";
@@ -128,6 +128,10 @@
// loop over all blocks and deploy them using the file resource
// manager
for (int i = 0; i < blocks.length; i++) {
+ // check if the block can be deployed
+ if(false) {
+ throw new UnsupportedBlockException("Deploying a block of this type is not supported!");
+ }
// create random string as base directory for the block to be deployer
String randDir = LocatorUtils.createRandomString();
// write block
@@ -164,7 +168,6 @@
}
} while (document != null);
} finally {
- // closes stream
zis.close();
}
// add new blocks to wiring object
@@ -184,15 +187,17 @@
} catch (ResourceManagerException rme1) {
rme1.printStackTrace();
}
- throw rme;
+ // FIXME provide exception explanation
+ throw new IOException("");
} finally {
try {
frm.stop(FileResourceManager.SHUTDOWN_MODE_NORMAL);
} catch (ResourceManagerSystemException e) {
- throw e;
+ // FIXME provide explanation (at this point the blocks have been
+ // deployed successfully but FileResourceManager couldn't have been stopped.
+ throw new IOException("");
}
}
-
return true;
}
@@ -200,8 +205,10 @@
try {
return this.basedir.toURL().toString();
} catch (MalformedURLException e) {
+ // if a MalformedURLException occurs this indicates a problem (maybe in the
+ // BlockFactory
+ throw new IllegalStateException("The block doesn't have a valid ID.");
}
- return null;
}
/**
@@ -219,10 +226,6 @@
return wrbd;
}
- public InputStream getBlockAsStream(String blockId) throws Exception {
- return null;
- }
-
public void setLock(Lock lock) throws LockingException {
}
@@ -233,6 +236,10 @@
public boolean removeLock() throws LockingException {
return false;
+ }
+
+ public InputStream getBlockAsStream(String blockId) throws IOException, BlockNotFoundException {
+ return null;
}
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java
==============================================================================
--- 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 Mon Oct 11 01:02:28 2004
@@ -18,6 +18,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.zip.ZipInputStream;
@@ -51,55 +52,36 @@
return null;
}
- public InputStream getBlockAsStream(String blockUri) throws Exception {
+ public InputStream getBlockAsStream(String blockUri) throws IOException, BlockNotFoundException {
return new FileInputStream(getBlockAsFile(blockUri));
}
- protected InputStream getBlockDescriptorAsStream(String blockUri) throws Exception {
-
- File cobFile = getBlockAsFile(blockUri);
- if(cobFile == null) {
- return null;
+ protected InputStream getBlockDescriptorAsStream(String blockUri) throws IOException, BlockNotFoundException {
+ File cobFile = null;
+ try {
+ cobFile = getBlockAsFile(blockUri);
+ } catch(FileNotFoundException fnfe) {
+ throw new BlockNotFoundException("Block " + blockUri + " at locator " + this.getIdentifier() + " not available.");
}
-
- // read the descriptor from the ZIP file
InputStream descriptorInputStream = null;
- try {
- descriptorInputStream = LocatorUtils.getDescriptorInputStream(new ZipInputStream(new FileInputStream(cobFile)));
- } catch (Exception e) {
- throw new Exception("Can't read block from " + cobFile.getAbsolutePath());
- }
-
- return descriptorInputStream;
+ return LocatorUtils.getDescriptorInputStream(new ZipInputStream(new FileInputStream(cobFile)));
}
- protected File getBlockAsFile(String blockUri) throws Exception {
+ protected File getBlockAsFile(String blockUri) throws FileNotFoundException {
// strip schema to get the path
if(!LocatorUtils.checkUri(blockUri)) {
throw new IllegalArgumentException("Can't find the requested block " + blockUri +
". Wrong schema, only http:// block uris are allowed.");
}
- File cobFile = null;
- try {
- cobFile = LocatorUtils.getBlockAsFile(this.basedir, blockUri.substring("http:/".length()));
- } catch(FileNotFoundException fnfe) {
- String cobFilePath = null;
- if(cobFile != null) {
- cobFilePath = cobFile.getAbsolutePath();
- }
- else {
- return null;
- }
- }
- return cobFile;
+ return LocatorUtils.getBlockAsFile(this.basedir, blockUri.substring("http:/".length()));
}
- public RemoteBlock getRemoteBlock(String blockUri) throws Exception {
+ public RemoteBlock getRemoteBlock(String blockUri) throws IOException, BlockNotFoundException {
// get the RemoteBlock from the factory
- InputStream descriptorInputStream = getBlockDescriptorAsStream(blockUri);
+ InputStream descriptorInputStream = this.getBlockDescriptorAsStream(blockUri);
if(descriptorInputStream == null) {
- return null;
+ throw new BlockNotFoundException("Block " + blockUri + " not found.");
}
return RemoteBlockFactory.getRemoteBlock(descriptorInputStream, this);
}
Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocatorTest.java
==============================================================================
--- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocatorTest.java (original)
+++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocatorTest.java Mon Oct 11 01:02:28 2004
@@ -21,6 +21,7 @@
import org.apache.cocoon.blockdeployer.Constants;
import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.wiring.Wiring;
import org.easymock.MockControl;
import junit.framework.TestCase;
@@ -30,8 +31,25 @@
*/
public class ApplicationServerLocatorTest extends TestCase {
+ private static final String EXAMPLES_DIR = "build/junit/aslt";
+
+ private void setupExamples() {
+ File examplesDir = new File(Constants.VALID_LOCATION_1);
+ // copy all files to examples dir
+
+ }
+
+ private void removeExamples() {
+
+ }
+
public void testDeploy() throws Exception {
- ApplicationServerLocator asl = new ApplicationServerLocator(new File(Constants.VALID_ASL_1), null);
+ // create a wiring
+ MockControl blockControl = MockControl.createControl(Wiring.class);
+ Wiring wiring = (Wiring) blockControl.getMock();
+
+ // first hack to run the deploy method
+ ApplicationServerLocator asl = new ApplicationServerLocator(new File(Constants.VALID_ASL_1), wiring);
RemoteBlock b[] = new RemoteBlock[1];
b[0] = createBlockMock(null);
asl.deploy(b);
Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java
==============================================================================
--- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java (original)
+++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java Mon Oct 11 01:02:28 2004
@@ -30,7 +30,7 @@
/**
* Test removing a locator
*/
- public void testLocatorAddingAndRemoving() {
+ public void testLocatorAddingAndRemoving() throws Exception {
String locator1Name = "locator1";
String locator2Name = "locator2";
String locator3Name = "locator3";
@@ -40,10 +40,10 @@
DefaultRepository defaultRepository = new DefaultRepository();
// fill the repository with blocks
- defaultRepository.addLocator(createMockLocator(locator1Name, allAvailableBlocks, new String[] {"myBlock"}));
- Locator locator2 = createMockLocator(locator2Name, allAvailableBlocks, new String[] {"myBlock"});
+ defaultRepository.addLocator(createMockLocator(locator1Name, allAvailableBlocks, new String[0], new String[] {"myBlock"}));
+ Locator locator2 = createMockLocator(locator2Name, allAvailableBlocks, new String[0], new String[] {"myBlock"});
defaultRepository.addLocator(locator2);
- defaultRepository.addLocator(createMockLocator(locator3Name, allAvailableBlocks, new String[] {"myBlock"}));
+ defaultRepository.addLocator(createMockLocator(locator3Name, allAvailableBlocks, new String[0], new String[] {"myBlock"}));
// test that all locators return the block
RemoteBlock[] resultRemoteBlock = defaultRepository.lookupBlock("myBlock");
@@ -76,7 +76,7 @@
/**
* Test whether the DefaultRepository returns the correct blocks in the correct order.
*/
- public void testBlockLookup() {
+ public void testBlockLookup() throws Exception {
String locator1Name = "locator1";
String locator2Name = "locator2";
@@ -88,11 +88,11 @@
// fill the repository with blocks
defaultRepository.addLocator(
- createMockLocator(locator1Name, allAvailableBlocks, new String[] {"myBlock4"}));
+ createMockLocator(locator1Name, allAvailableBlocks, new String[0], new String[] {"myBlock4"}));
defaultRepository.addLocator(
- createMockLocator(locator2Name, allAvailableBlocks, new String[] {"myBlock3", "myBlock2"}));
+ createMockLocator(locator2Name, allAvailableBlocks, new String[0], new String[] {"myBlock3", "myBlock2"}));
defaultRepository.addLocator(
- createMockLocator(locator3Name, allAvailableBlocks, new String[] {"myBlock1", "myBlock4", "myBlock3"}));
+ createMockLocator(locator3Name, allAvailableBlocks, new String[0], new String[] {"myBlock1", "myBlock4", "myBlock3"}));
// test that myBlock3 is returned twice, having the locators locator2 and locator3
RemoteBlock[] resultRemoteBlock = defaultRepository.lookupBlock("myBlock3");
@@ -109,8 +109,15 @@
resultRemoteBlock = defaultRepository.lookupBlock("myBlock4");
assertEquals(resultRemoteBlock[0].getLocator().getIdentifier(), locator1Name);
assertEquals(resultRemoteBlock[1].getLocator().getIdentifier(), locator3Name);
- assertEquals(resultRemoteBlock.length, 2);
-
+ assertEquals(resultRemoteBlock.length, 2);
+ }
+
+ public void testUnavailableBlockLookup() throws Exception {
+ DefaultRepository defaultRepository = new DefaultRepository();
+ String[] allUnavailableBlocks = {"myBlock1"};
+ String locator1Name = "locator1";
+ defaultRepository.addLocator(
+ createMockLocator(locator1Name, new String[0], allUnavailableBlocks, new String[] {"myBlock4"}));
}
/**
@@ -122,7 +129,8 @@
* @param locatorBlocks - all blocks that the locator should return (not null)
* @return returns a mock locator
*/
- private Locator createMockLocator(String name, String[] allAvailableBlocks, String[] locatorBlocks) {
+ private Locator createMockLocator(String name, String[] allAvailableBlocks, String[] allUnavailableBlocks, String[] locatorBlocks) throws Exception {
+
// create a mock for a RemoteBlock
MockControl blockControl = MockControl.createControl(RemoteBlock.class);
RemoteBlock remoteBlock = (RemoteBlock) blockControl.getMock();
@@ -134,17 +142,20 @@
// give the locator mock behaviour (setting available blocks, identifier)
locator.getIdentifier();
control1.setReturnValue(name, MockControl.ZERO_OR_MORE);
- try {
- for(int i = 0; i < allAvailableBlocks.length; i++) {
- locator.getRemoteBlock(allAvailableBlocks[i]);
- if(hasItem(locatorBlocks, allAvailableBlocks[i])) {
- control1.setReturnValue(remoteBlock, MockControl.ZERO_OR_MORE);
- }
- else {
- control1.setReturnValue(null, MockControl.ZERO_OR_MORE);
- }
+ for(int i = 0; i < allAvailableBlocks.length; i++) {
+ locator.getRemoteBlock(allAvailableBlocks[i]);
+ if(hasItem(locatorBlocks, allAvailableBlocks[i])) {
+ control1.setReturnValue(remoteBlock, MockControl.ZERO_OR_MORE);
+ }
+ else {
+ control1.setReturnValue(null, MockControl.ZERO_OR_MORE);
}
- } catch (Exception e) {
+ }
+
+ // add mock behaviour for unavailable blocks (have to throw BlockNotFoundException)
+ for(int i = 0; i < allUnavailableBlocks.length; i++) {
+ locator.getRemoteBlock(allUnavailableBlocks[i]);
+ control1.setThrowable(new BlockNotFoundException());
}
// activate the locator mock
Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java
==============================================================================
--- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java (original)
+++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java Mon Oct 11 01:02:28 2004
@@ -18,6 +18,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipInputStream;
@@ -86,12 +87,12 @@
RemoteBlock remoteBlock = null;
try {
remoteBlock = filesystemLocator.getRemoteBlock(Constants.AVAILABLE_INVALID_SAMPLE_BLOCKID);
- } catch (Exception e) {
- fail("The block URI is valid but at this place there is no block. This returns null and doesn't raise an exception.");
- }
- if(remoteBlock != null) {
- fail("Tried to access a block that doesn't exist - this should raise an Exception!");
- }
+ fail("The block URI is valid but at this place there is no block. An exception should be raised.");
+ } catch (BlockNotFoundException e) {
+ // correct behaviour
+ } catch(IOException ioe) {
+ fail("The block is not available and this shouldn't raise an IOException");
+ }
}
public final void testReadingDescriptor() {