Author: jboynes Date: Sun Dec 26 19:11:00 2004 New Revision: 123383 URL: http://svn.apache.org/viewcvs?view=rev&rev=123383 Log: tests plus implementation of bits of activation api Added: geronimo/trunk/specs/activation/src/resources/ geronimo/trunk/specs/activation/src/resources/META-INF/ geronimo/trunk/specs/activation/src/resources/META-INF/mimetypes.default geronimo/trunk/specs/activation/src/test/javax/activation/ActivationDataFlavorTest.java geronimo/trunk/specs/activation/src/test/javax/activation/CommandInfoTest.java geronimo/trunk/specs/activation/src/test/javax/activation/MimetypesFileTypeMapTest.java Modified: geronimo/trunk/etc/project.properties geronimo/trunk/specs/activation/src/java/javax/activation/ActivationDataFlavor.java geronimo/trunk/specs/activation/src/java/javax/activation/CommandInfo.java geronimo/trunk/specs/activation/src/java/javax/activation/CommandMap.java geronimo/trunk/specs/activation/src/java/javax/activation/FileDataSource.java geronimo/trunk/specs/activation/src/java/javax/activation/FileTypeMap.java geronimo/trunk/specs/activation/src/java/javax/activation/MimeType.java geronimo/trunk/specs/activation/src/java/javax/activation/MimeTypeParameterList.java geronimo/trunk/specs/activation/src/java/javax/activation/MimetypesFileTypeMap.java geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeParameterListTest.java geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeTest.java
Modified: geronimo/trunk/etc/project.properties Url: http://svn.apache.org/viewcvs/geronimo/trunk/etc/project.properties?view=diff&rev=123383&p1=geronimo/trunk/etc/project.properties&r1=123382&p2=geronimo/trunk/etc/project.properties&r2=123383 ============================================================================== --- geronimo/trunk/etc/project.properties (original) +++ geronimo/trunk/etc/project.properties Sun Dec 26 19:11:00 2004 @@ -75,7 +75,7 @@ tranql_version=1.0-SNAPSHOT tranql_connector_version=1.0-SNAPSHOT -geronimo_spec_activation_version=1.0.2-rc3 +geronimo_spec_activation_version=1.0.2-SNAPSHOT geronimo_spec_ejb_version=2.1-rc3 geronimo_spec_j2ee_version=1.4-rc3 geronimo_spec_j2ee_connector_version=1.5-rc3 Modified: geronimo/trunk/specs/activation/src/java/javax/activation/ActivationDataFlavor.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/java/javax/activation/ActivationDataFlavor.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/java/javax/activation/ActivationDataFlavor.java&r1=123382&p2=geronimo/trunk/specs/activation/src/java/javax/activation/ActivationDataFlavor.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/java/javax/activation/ActivationDataFlavor.java (original) +++ geronimo/trunk/specs/activation/src/java/javax/activation/ActivationDataFlavor.java Sun Dec 26 19:11:00 2004 @@ -23,35 +23,35 @@ * @version $Rev$ $Date$ */ public class ActivationDataFlavor extends DataFlavor { + private String humanPresentableName; + public ActivationDataFlavor(Class representationClass, String mimeType, String humanPresentableName) { - /[EMAIL PROTECTED] implement*/ + this.humanPresentableName = humanPresentableName; } public ActivationDataFlavor(Class representationClass, String humanPresentableName) { - /[EMAIL PROTECTED] implement*/ + this.humanPresentableName = humanPresentableName; } public ActivationDataFlavor(String mimeType, String humanPresentableName) { - /[EMAIL PROTECTED] implement*/ + super(mimeType, humanPresentableName); + this.humanPresentableName = humanPresentableName; } public String getMimeType() { - /[EMAIL PROTECTED] implement*/ - return null; + return super.getMimeType(); } public Class getRepresentationClass() { - /[EMAIL PROTECTED] implement*/ - return null; + return super.getRepresentationClass(); } public String getHumanPresentableName() { - /[EMAIL PROTECTED] implement*/ - return null; + return humanPresentableName; } public void setHumanPresentableName(String humanPresentableName) { - /[EMAIL PROTECTED] implement*/ + this.humanPresentableName = humanPresentableName; } public boolean equals(DataFlavor dataFlavor) { Modified: geronimo/trunk/specs/activation/src/java/javax/activation/CommandInfo.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/java/javax/activation/CommandInfo.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/java/javax/activation/CommandInfo.java&r1=123382&p2=geronimo/trunk/specs/activation/src/java/javax/activation/CommandInfo.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/java/javax/activation/CommandInfo.java (original) +++ geronimo/trunk/specs/activation/src/java/javax/activation/CommandInfo.java Sun Dec 26 19:11:00 2004 @@ -17,28 +17,69 @@ package javax.activation; +import java.beans.Beans; +import java.io.Externalizable; import java.io.IOException; +import java.io.ObjectInputStream; /** * @version $Rev$ $Date$ */ public class CommandInfo { - public CommandInfo(String verb, String className) { - /[EMAIL PROTECTED] implement*/ + private final String commandName; + private final String commandClass; + + /** + * Constructor for a CommandInfo + * + * @param commandName the command name + * @param commandClass the name of the command's implementation class + */ + public CommandInfo(String commandName, String commandClass) { + this.commandName = commandName; + this.commandClass = commandClass; } + /** + * Return the command name. + * + * @return the command name + */ public String getCommandName() { - /[EMAIL PROTECTED] implement*/ - return null; + return commandName; } + /** + * Return the implementation class name. + * + * @return the name of the command's implementation class; may be null + */ public String getCommandClass() { - /[EMAIL PROTECTED] implement*/ - return null; + return commandClass; } + /** + * Instantiate and return a command JavaBean. + * The bean is created using Beans.instantiate(loader, commandClass). + * If the new bean implements CommandObject then its setCommandContext(String, DataHandler) + * method is called. + * Otherwise if it implements Externalizable and the supplied DataHandler is not null + * then its readExternal(ObjectInputStream) method is called with a stream obtained from + * DataHandler.getInputStream(). + * + * @param dh a DataHandler that provides the data to be passed to the command + * @param loader the ClassLoader to be used to instantiate the command + * @return a new command instance + * @throws IOException if there was a problem initializing the command + * @throws ClassNotFoundException if the command class could not be found + */ public Object getCommandObject(DataHandler dh, ClassLoader loader) throws IOException, ClassNotFoundException { - /[EMAIL PROTECTED] implement*/ - return null; + Object bean = Beans.instantiate(loader, commandClass); + if (bean instanceof CommandObject) { + ((CommandObject) bean).setCommandContext(commandName, dh); + } else if (bean instanceof Externalizable && dh != null) { + ((Externalizable) bean).readExternal(new ObjectInputStream(dh.getInputStream())); + } + return bean; } } Modified: geronimo/trunk/specs/activation/src/java/javax/activation/CommandMap.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/java/javax/activation/CommandMap.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/java/javax/activation/CommandMap.java&r1=123382&p2=geronimo/trunk/specs/activation/src/java/javax/activation/CommandMap.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/java/javax/activation/CommandMap.java (original) +++ geronimo/trunk/specs/activation/src/java/javax/activation/CommandMap.java Sun Dec 26 19:11:00 2004 @@ -21,17 +21,32 @@ * @version $Rev$ $Date$ */ public abstract class CommandMap { - public CommandMap() { - /[EMAIL PROTECTED] implement*/ - } + private static CommandMap defaultCommandMap = new MailcapCommandMap(); + /** + * Return the default CommandMap. If this has not been explictly set + * using setDefaultCommandMap() then a MailcapCommandMap is returned. + * @return the default CommandMap + */ public static CommandMap getDefaultCommandMap() { - /[EMAIL PROTECTED] implement*/ - return null; + return defaultCommandMap; } + /** + * Set the default CommandMap. + * + * @param commandMap the new default CommandMap; if null resets to a MailcapCommandMap + * @throws SecurityException if the caller does not have "SetFactory" RuntimePermission + */ public static void setDefaultCommandMap(CommandMap commandMap) { - /[EMAIL PROTECTED] implement*/ + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkSetFactory(); + } + defaultCommandMap = commandMap == null ? new MailcapCommandMap() : commandMap; + } + + public CommandMap() { } public abstract CommandInfo[] getPreferredCommands(String mimeType); Modified: geronimo/trunk/specs/activation/src/java/javax/activation/FileDataSource.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/java/javax/activation/FileDataSource.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/java/javax/activation/FileDataSource.java&r1=123382&p2=geronimo/trunk/specs/activation/src/java/javax/activation/FileDataSource.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/java/javax/activation/FileDataSource.java (original) +++ geronimo/trunk/specs/activation/src/java/javax/activation/FileDataSource.java Sun Dec 26 19:11:00 2004 @@ -28,8 +28,7 @@ * @version $Rev$ $Date$ */ public class FileDataSource implements DataSource { - - private File file; + private final File file; private FileTypeMap fileTypeMap; /** @@ -64,10 +63,11 @@ * Returns the content type of the data source */ public String getContentType() { - if (fileTypeMap == null) + if (fileTypeMap == null) { return FileTypeMap.getDefaultFileTypeMap().getContentType(file); - - return fileTypeMap.getContentType(file); + } else { + return fileTypeMap.getContentType(file); + } } /** Modified: geronimo/trunk/specs/activation/src/java/javax/activation/FileTypeMap.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/java/javax/activation/FileTypeMap.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/java/javax/activation/FileTypeMap.java&r1=123382&p2=geronimo/trunk/specs/activation/src/java/javax/activation/FileTypeMap.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/java/javax/activation/FileTypeMap.java (original) +++ geronimo/trunk/specs/activation/src/java/javax/activation/FileTypeMap.java Sun Dec 26 19:11:00 2004 @@ -25,29 +25,35 @@ * @version $Rev$ $Date$ */ public abstract class FileTypeMap { - - private static FileTypeMap defaultFileTypeMap; - - public FileTypeMap() { - } - - public abstract String getContentType(File file); - - public abstract String getContentType(String filename); + // we use null here rather than a default because + // the constructor for MimetypesFileTypeMap does a lot of I/O + private static FileTypeMap defaultFileTypeMap = null; /** - * Sets the default FileTypeMap for the system + * Sets the default FileTypeMap for the system. + * @param fileMap the new default FileTypeMap + * @throws SecurityException if the caller does not have "SetFactory" RuntimePermission */ - public static void setDefaultFileTypeMap(FileTypeMap map) { - defaultFileTypeMap = map; + public static void setDefaultFileTypeMap(FileTypeMap fileMap) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkSetFactory(); + } + defaultFileTypeMap = fileMap; } /** * Returns the default FileTypeMap + * @return the default FileTYpeMap; if null returns a MimetypesFileTypeMap */ public static FileTypeMap getDefaultFileTypeMap() { - if (defaultFileTypeMap == null) - return new MimetypesFileTypeMap(); - return defaultFileTypeMap; + return defaultFileTypeMap != null ? defaultFileTypeMap : new MimetypesFileTypeMap(); } + + public FileTypeMap() { + } + + public abstract String getContentType(File file); + + public abstract String getContentType(String filename); } Modified: geronimo/trunk/specs/activation/src/java/javax/activation/MimeType.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/java/javax/activation/MimeType.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/java/javax/activation/MimeType.java&r1=123382&p2=geronimo/trunk/specs/activation/src/java/javax/activation/MimeType.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/java/javax/activation/MimeType.java (original) +++ geronimo/trunk/specs/activation/src/java/javax/activation/MimeType.java Sun Dec 26 19:11:00 2004 @@ -31,8 +31,8 @@ private final static String PARAMETER_SEPARATOR = ";"; private final static String STAR_SUB_TYPE = "*"; - private String primaryType = "text"; - private String subType = "plain"; + private String primaryType = "application"; + private String subType = "*"; private MimeTypeParameterList parameterList = new MimeTypeParameterList();; public MimeType() { Modified: geronimo/trunk/specs/activation/src/java/javax/activation/MimeTypeParameterList.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/java/javax/activation/MimeTypeParameterList.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/java/javax/activation/MimeTypeParameterList.java&r1=123382&p2=geronimo/trunk/specs/activation/src/java/javax/activation/MimeTypeParameterList.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/java/javax/activation/MimeTypeParameterList.java (original) +++ geronimo/trunk/specs/activation/src/java/javax/activation/MimeTypeParameterList.java Sun Dec 26 19:11:00 2004 @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; +import java.util.Iterator; /** @@ -97,11 +98,10 @@ } public String toString() { - StringBuffer buf = new StringBuffer(); - for (Enumeration e = getNames(); e.hasMoreElements();) { - buf.append(PARAMETER_SEPARATOR); - String name = (String) e.nextElement(); - buf.append(name).append(NAME_VALUE_SEPARATOR).append(get(name)); + StringBuffer buf = new StringBuffer(_mimeTypeParameterMap.size() << 4); + for (Iterator i = _mimeTypeParameterMap.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + buf.append("; ").append(entry.getKey()).append('=').append(entry.getValue()); } return buf.toString(); } Modified: geronimo/trunk/specs/activation/src/java/javax/activation/MimetypesFileTypeMap.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/java/javax/activation/MimetypesFileTypeMap.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/java/javax/activation/MimetypesFileTypeMap.java&r1=123382&p2=geronimo/trunk/specs/activation/src/java/javax/activation/MimetypesFileTypeMap.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/java/javax/activation/MimetypesFileTypeMap.java (original) +++ geronimo/trunk/specs/activation/src/java/javax/activation/MimetypesFileTypeMap.java Sun Dec 26 19:11:00 2004 @@ -20,34 +20,161 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.FileReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Map; +import java.util.HashMap; +import java.util.StringTokenizer; +import java.util.Enumeration; +import java.net.URL; /** * @version $Rev$ $Date$ */ public class MimetypesFileTypeMap extends FileTypeMap { + private static final String DEFAULT_TYPE = "application/octet-stream"; + + private final Map types = new HashMap(); + public MimetypesFileTypeMap() { - /[EMAIL PROTECTED] implement*/ + // defaults from /META-INF/mimetypes.default + try { + InputStream is = MimetypesFileTypeMap.class.getResourceAsStream("/META-INF/mimetypes.default"); + if (is != null) { + try { + loadStream(is); + } finally { + is.close(); + } + } + } catch (IOException e) { + // ignore + } + + // defaults from resources called /META-INF/mime.types + try { + ClassLoader cl = MimetypesFileTypeMap.class.getClassLoader(); + Enumeration e = cl.getResources("/META-INF/mime.types"); + while (e.hasMoreElements()) { + URL url = (URL) e.nextElement(); + try { + InputStream is = url.openStream(); + try { + loadStream(is); + } finally { + is.close(); + } + } catch (IOException e1) { + continue; + } + } + } catch (SecurityException e) { + // ignore + } catch (IOException e) { + // ignore + } + + // defaults from ${java.home}/lib/mime.types + try { + File file = new File(System.getProperty("java.home"), "lib/mime.types"); + InputStream is = new FileInputStream(file); + try { + loadStream(is); + } finally { + is.close(); + } + } catch (SecurityException e) { + // ignore + } catch (FileNotFoundException e) { + // ignore + } catch (IOException e) { + // ignore + } + + // defaults from ${user.home}/.mime.types + try { + File file = new File(System.getProperty("user.home"), ".mime.types"); + InputStream is = new FileInputStream(file); + try { + loadStream(is); + } finally { + is.close(); + } + } catch (SecurityException e) { + // ignore + } catch (FileNotFoundException e) { + // ignore + } catch (IOException e) { + // ignore + } } public MimetypesFileTypeMap(String mimeTypeFileName) throws IOException { - /[EMAIL PROTECTED] implement*/ + this(); + BufferedReader reader = new BufferedReader(new FileReader(mimeTypeFileName)); + try { + String line; + while ((line = reader.readLine()) != null) { + addMimeTypes(line); + } + reader.close(); + } catch (IOException e) { + try { + reader.close(); + } catch (IOException e1) { + // ignore to allow original cause through + } + throw e; + } } public MimetypesFileTypeMap(InputStream is) { - /[EMAIL PROTECTED] implement*/ + this(); + try { + loadStream(is); + } catch (IOException e) { + // ignore as the spec's signature says we can't throw IOException - doh! + } + } + + private void loadStream(InputStream is) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + String line; + while ((line = reader.readLine()) != null) { + addMimeTypes(line); + } } public synchronized void addMimeTypes(String mime_types) { - /[EMAIL PROTECTED] implement*/ + int hashPos = mime_types.indexOf('#'); + if (hashPos != -1) { + mime_types = mime_types.substring(0, hashPos); + } + StringTokenizer tok = new StringTokenizer(mime_types); + if (!tok.hasMoreTokens()) { + return; + } + String contentType = tok.nextToken(); + while (tok.hasMoreTokens()) { + String fileType = tok.nextToken(); + types.put(fileType, contentType); + } } public String getContentType(File f) { - /[EMAIL PROTECTED] implement*/ - return null; + return getContentType(f.getName()); } public synchronized String getContentType(String filename) { - /[EMAIL PROTECTED] implement*/ - return null; + int index = filename.lastIndexOf('.'); + if (index == -1 || index == filename.length()-1) { + return DEFAULT_TYPE; + } + String fileType = filename.substring(index + 1); + String contentType = (String) types.get(fileType); + return contentType == null ? DEFAULT_TYPE : contentType; } } Added: geronimo/trunk/specs/activation/src/resources/META-INF/mimetypes.default Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/resources/META-INF/mimetypes.default?view=auto&rev=123383 ============================================================================== --- (empty file) +++ geronimo/trunk/specs/activation/src/resources/META-INF/mimetypes.default Sun Dec 26 19:11:00 2004 @@ -0,0 +1,20 @@ +text/html html htm HTML HTM +text/plain txt text TXT TEXT +image/gif gif GIF +image/ief ief +image/jpeg jpeg jpg jpe JPG +image/tiff tiff tif +image/x-xwindowdump xwd +application/postscript ai eps ps +application/rtf rtf +application/x-tex tex +application/x-texinfo texinfo texi +application/x-troff t tr roff +audio/basic au +audio/midi midi mid +audio/x-aifc aifc +audio/x-aiff aif aiff +audio/x-wav wav +video/mpeg mpeg mpg mpe +video/quicktime qt mov +video/x-msvideo avi Added: geronimo/trunk/specs/activation/src/test/javax/activation/ActivationDataFlavorTest.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/test/javax/activation/ActivationDataFlavorTest.java?view=auto&rev=123383 ============================================================================== --- (empty file) +++ geronimo/trunk/specs/activation/src/test/javax/activation/ActivationDataFlavorTest.java Sun Dec 26 19:11:00 2004 @@ -0,0 +1,53 @@ +/** + * + * Copyright 2003-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. + */ + +// +// This source code implements specifications defined by the Java +// Community Process. In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// +package javax.activation; + +import java.io.InputStream; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class ActivationDataFlavorTest extends TestCase { + public void testMimeTypeConstructorWithoutClass() { + ActivationDataFlavor adf = new ActivationDataFlavor("application/*", null); + assertEquals("application/*; class=java.io.InputStream", adf.getMimeType()); + assertEquals(InputStream.class, adf.getRepresentationClass()); + } + + public void testMimeTypeConstructorWithClass() { + ActivationDataFlavor adf = new ActivationDataFlavor("application/x-java-serialized-object; class=java.lang.Object", null); + assertEquals("application/x-java-serialized-object; class=java.lang.Object", adf.getMimeType()); + assertEquals(Object.class, adf.getRepresentationClass()); + } + + public void testHumanName() { + ActivationDataFlavor adf = new ActivationDataFlavor("text/html", "Human Name"); + assertEquals("Human Name", adf.getHumanPresentableName()); + adf.setHumanPresentableName("Name 2"); + assertEquals("Name 2", adf.getHumanPresentableName()); + adf = new ActivationDataFlavor("text/html", null); + assertNull(adf.getHumanPresentableName()); + } +} Added: geronimo/trunk/specs/activation/src/test/javax/activation/CommandInfoTest.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/test/javax/activation/CommandInfoTest.java?view=auto&rev=123383 ============================================================================== --- (empty file) +++ geronimo/trunk/specs/activation/src/test/javax/activation/CommandInfoTest.java Sun Dec 26 19:11:00 2004 @@ -0,0 +1,68 @@ +/** + * + * Copyright 2003-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. + */ + +// +// This source code implements specifications defined by the Java +// Community Process. In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// +package javax.activation; + +import java.io.IOException; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class CommandInfoTest extends TestCase { + public void testAttributes() { + CommandInfo info = new CommandInfo("test", "test.class"); + assertEquals("test", info.getCommandName()); + assertEquals("test.class", info.getCommandClass()); + } + + public void testInvalidClassName() throws IOException { + CommandInfo info = new CommandInfo("test", "test.class"); + try { + info.getCommandObject(null, null); + fail("Expected ClassNotFoundException"); + } catch (ClassNotFoundException e) { + // ok + } + } + + public void testCommandObject() throws IOException, ClassNotFoundException { + CommandInfo info = new CommandInfo("test", MockCommandObject.class.getName()); + DataHandler dh = new DataHandler(null, null); + Object o = info.getCommandObject(dh, MockCommandObject.class.getClassLoader()); + assertTrue(o instanceof MockCommandObject); + MockCommandObject bean = (MockCommandObject) o; + assertEquals("test", bean.verb); + assertSame(dh, bean.dh); + } + + public static class MockCommandObject implements CommandObject { + private String verb; + private DataHandler dh; + + public void setCommandContext(String verb, DataHandler dh) { + this.verb = verb; + this.dh = dh; + } + } +} Modified: geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeParameterListTest.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeParameterListTest.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeParameterListTest.java&r1=123382&p2=geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeParameterListTest.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeParameterListTest.java (original) +++ geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeParameterListTest.java Sun Dec 26 19:11:00 2004 @@ -25,24 +25,8 @@ * @version $Rev$ $Date$ */ public class MimeTypeParameterListTest extends TestCase { - - private String simpleParameterListStr; - private String withWhiteSpacesParameterListStr; - private String longParameterListStr; - private String noNameParameterListStr; - private String noValueParameterListStr; - - public MimeTypeParameterListTest(String name) { - super(name); - } - protected void setUp() throws Exception { super.setUp(); - simpleParameterListStr = ";name=value"; - withWhiteSpacesParameterListStr = "; name= value ; "; - longParameterListStr = "; name1 =value1;; ; name2= value2;name3= value3;name4 =value4;"; - noNameParameterListStr = "; = value"; - noValueParameterListStr = "; name="; } public void testEmptyParameterList() { @@ -51,17 +35,21 @@ } public void testSimpleParameterList() throws MimeTypeParseException { - MimeTypeParameterList parameterList = new MimeTypeParameterList(simpleParameterListStr); - assertEquals(simpleParameterListStr, parameterList.toString()); + MimeTypeParameterList parameterList = new MimeTypeParameterList(";name=value"); + assertEquals(1, parameterList.size()); + assertEquals("name", parameterList.getNames().nextElement()); + assertEquals("value", parameterList.get("name")); } public void testWhiteSpacesParameterList() throws MimeTypeParseException { - MimeTypeParameterList parameterList = new MimeTypeParameterList(withWhiteSpacesParameterListStr); - assertEquals(simpleParameterListStr, parameterList.toString()); + MimeTypeParameterList parameterList = new MimeTypeParameterList("; name= value ; "); + assertEquals(1, parameterList.size()); + assertEquals("name", parameterList.getNames().nextElement()); + assertEquals("value", parameterList.get("name")); } public void testLongParameterList() throws MimeTypeParseException { - MimeTypeParameterList parameterList = new MimeTypeParameterList(longParameterListStr); + MimeTypeParameterList parameterList = new MimeTypeParameterList(";name1=value1; name2 = value2; name3=value3;name4 = value4"); assertEquals(4, parameterList.size()); assertEquals("value1", parameterList.get("name1")); assertEquals("value2", parameterList.get("name2")); @@ -69,24 +57,22 @@ assertEquals("value4", parameterList.get("name4")); } - public void testNoNameParameterList() { - boolean catched = false; + public void testNoValueParameterList() { try { - MimeTypeParameterList parameterList = new MimeTypeParameterList(noNameParameterListStr); + new MimeTypeParameterList("; name="); + fail("Expected MimeTypeParseException"); } catch (MimeTypeParseException mtpEx) { - catched = true; + // ok } - assertTrue(catched); } - public void testNoValueParameterList() { - boolean catched = false; + public void testNoNameParameterList() { try { - MimeTypeParameterList parameterList = new MimeTypeParameterList(noValueParameterListStr); + new MimeTypeParameterList("; = value"); + fail("Expected MimeTypeParseException"); } catch (MimeTypeParseException mtpEx) { - catched = true; + // ok } - assertTrue(catched); } } Modified: geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeTest.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeTest.java?view=diff&rev=123383&p1=geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeTest.java&r1=123382&p2=geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeTest.java&r2=123383 ============================================================================== --- geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeTest.java (original) +++ geronimo/trunk/specs/activation/src/test/javax/activation/MimeTypeTest.java Sun Dec 26 19:11:00 2004 @@ -26,8 +26,8 @@ */ public class MimeTypeTest extends TestCase { - private final static String DEFAULT_PRIMARY_TYPE = "text"; - private final static String DEFAULT_SUB_TYPE = "plain"; + private final static String DEFAULT_PRIMARY_TYPE = "application"; + private final static String DEFAULT_SUB_TYPE = "*"; private String defaultRawdata; private String primary; @@ -40,7 +40,7 @@ public void setUp() throws Exception { super.setUp(); - defaultRawdata = "text/plain;"; + defaultRawdata = "application/*;"; primary = "primary"; sub = "sub"; withParamsRawdata = primary + "/" + sub + "; name1 =value1; name2 = value2;"; Added: geronimo/trunk/specs/activation/src/test/javax/activation/MimetypesFileTypeMapTest.java Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/test/javax/activation/MimetypesFileTypeMapTest.java?view=auto&rev=123383 ============================================================================== --- (empty file) +++ geronimo/trunk/specs/activation/src/test/javax/activation/MimetypesFileTypeMapTest.java Sun Dec 26 19:11:00 2004 @@ -0,0 +1,55 @@ +/** + * + * Copyright 2003-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. + */ + +// +// This source code implements specifications defined by the Java +// Community Process. In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// +package javax.activation; + +import java.util.Map; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class MimetypesFileTypeMapTest extends TestCase { + private MimetypesFileTypeMap typeMap; + + public void testDefault() { + // unmapped + assertEquals("application/octet-stream", typeMap.getContentType("x.foo")); + // from META-INF/mimetypes.default + assertEquals("text/html", typeMap.getContentType("x.html")); + } + + public void testCommentRemoval() { + typeMap.addMimeTypes(" text/foo foo #txt"); + assertEquals("text/foo", typeMap.getContentType("x.foo")); + typeMap.addMimeTypes("#text/foo bar"); + assertEquals("text/foo", typeMap.getContentType("x.foo")); + typeMap.addMimeTypes("text/foo #bar"); + assertEquals("text/foo", typeMap.getContentType("x.foo")); + } + + protected void setUp() throws Exception { + super.setUp(); + typeMap = new MimetypesFileTypeMap(); + } +}