You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2009/12/09 21:28:50 UTC

svn commit: r888947 - in /labs/magma/trunk/beans-file: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/magma/ src/main/java/org/apache/magma/beans/ src/main/java/org/apache/magma/conversion/ src/ma...

Author: simoneg
Date: Wed Dec  9 20:28:49 2009
New Revision: 888947

URL: http://svn.apache.org/viewvc?rev=888947&view=rev
Log:
LABS-380 : meta type for uploaded files

Added:
    labs/magma/trunk/beans-file/pom.xml
    labs/magma/trunk/beans-file/src/
    labs/magma/trunk/beans-file/src/main/
    labs/magma/trunk/beans-file/src/main/java/
    labs/magma/trunk/beans-file/src/main/java/org/
    labs/magma/trunk/beans-file/src/main/java/org/apache/
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/beans/
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/beans/MagFile.java
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/conversion/
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/conversion/file/
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/conversion/file/FileConverterToString.java
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/InferConsiderOnFileValidated.aj
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUpload.java
    labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUploadValidator.java
    labs/magma/trunk/beans-file/src/main/resources/
    labs/magma/trunk/beans-file/src/main/resources/META-INF/
    labs/magma/trunk/beans-file/src/main/resources/META-INF/magma.default.properties
    labs/magma/trunk/beans-file/src/test/
    labs/magma/trunk/beans-file/src/test/java/
    labs/magma/trunk/beans-file/src/test/java/org/
    labs/magma/trunk/beans-file/src/test/java/org/apache/
    labs/magma/trunk/beans-file/src/test/java/org/apache/magma/
    labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/
    labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/FileTestUtils.java
    labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/MagFileTest.java
    labs/magma/trunk/beans-file/src/test/resources/
    labs/magma/trunk/beans-file/src/test/resources/testFile.txt

Added: labs/magma/trunk/beans-file/pom.xml
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/pom.xml?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/pom.xml (added)
+++ labs/magma/trunk/beans-file/pom.xml Wed Dec  9 20:28:49 2009
@@ -0,0 +1,32 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>magma-parent</artifactId>
+    <groupId>org.apache.magma</groupId>
+    <version>3</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.magma</groupId>
+  <artifactId>beans-file</artifactId>
+  <packaging>magma</packaging>
+  <version>0.0.3-SNAPSHOT</version>
+  <name>Magma File metatype</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.magma</groupId>
+      <artifactId>foundation-beans</artifactId>
+      <version>0.0.3-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+    	<groupId>org.apache.magma</groupId>
+    	<artifactId>foundation-validation</artifactId>
+    	<version>0.0.3-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+    	<groupId>org.apache.magma.tools</groupId>
+    	<artifactId>magma-test-utilities</artifactId>
+    	<version>0.0.3-SNAPSHOT</version>
+    	<scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+</project>

Added: labs/magma/trunk/beans-file/src/main/java/org/apache/magma/beans/MagFile.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/src/main/java/org/apache/magma/beans/MagFile.java?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/src/main/java/org/apache/magma/beans/MagFile.java (added)
+++ labs/magma/trunk/beans-file/src/main/java/org/apache/magma/beans/MagFile.java Wed Dec  9 20:28:49 2009
@@ -0,0 +1,220 @@
+package org.apache.magma.beans;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.settings.Settings;
+
+
+public class MagFile {
+	
+	protected String originalName;
+	protected String mimeType;
+	protected long length;
+	/**
+	 * Relative file name of this file
+	 */
+	protected String source;
+
+	/**
+	 * Root folder where files are stored
+	 */
+	protected String base = Settings.get("magma.files.store");
+	
+	// Persisting variables
+	protected File temporary;
+	protected boolean modified;
+	
+	protected InputStream stream;
+	
+
+	public MagFile() {
+	}
+	
+	public MagFile(File temporaryFile, String originalName) {
+		this.temporary = temporaryFile;
+		this.originalName = originalName;
+		this.length = this.temporary.length();
+		this.modified = true;
+	}
+		
+	/**
+	 * Parse the string representation of a file.
+	 * 
+	 * Currently two formats are supported : raw relative path and Magma format.
+	 * 
+	 * The raw relative path is simply a path relative to the local file storage. This
+	 * mean that to obtain the file name and length some filesystem operations need to
+	 * be perfomed.
+	 * 
+	 * On the opposite, the magma format contains original name, length and other informations in a packed
+	 * string, not requiring any access to the filesystem.
+	 * 
+	 * @param spec
+	 */
+	public MagFile(String spec) {
+		char fmt = spec.charAt(0);
+		spec = spec.substring(1);
+		if (fmt == '1') {
+			int ios = spec.indexOf('/');
+			if (ios != -1) {
+				spec = spec.substring(0, ios);
+			}
+			String[] split = spec.split("\\*");
+			source = split[0];
+			if (split[1] != "null")
+				originalName = split[1];
+			if (split[2] != "null")
+				mimeType = split[2];
+			if (split[3] != "null")
+				length = Long.parseLong(split[3]);
+		} else {
+			if (fmt != '/') {
+				spec = fmt + spec;
+			}
+			spec = spec.replaceAll("\\\\", "/");
+			while (spec.startsWith("/")) {
+				spec = spec.substring(1);
+			}
+			if (spec.contains("..")) {
+				throw new MagmaException("Cannot accept {0} as a file path cause it contains '..'", spec);
+			}
+			this.source = spec;
+			File f = new File(this.base + this.source);
+			this.originalName = f.getName();
+			if (f.exists()) {
+				this.length = f.length();
+			}
+		}
+		this.modified = false;
+	}
+	
+	public MagFile(InputStream stream) {
+		this.stream = stream;
+		this.modified = false;
+	}
+	
+	public void setInputStream(InputStream stream) {
+		this.stream = stream;
+		this.modified = true;
+	}
+	
+	public String getOriginalName() {
+		return originalName;
+	}
+
+	public void setOriginalName(String originalName) {
+		this.originalName = originalName;
+	}
+
+	public String getMimeType() {
+		return mimeType;
+	}
+
+	public void setMimeType(String mimeType) {
+		this.mimeType = mimeType;
+	}
+
+	public String getSource() {
+		return source;
+	}
+
+	public void setSource(String source) {
+		this.source = source;
+	}
+
+	public long getLength() {
+		return length;
+	}
+
+	public void setLength(long length) {
+		this.length = length;
+	}
+	
+	
+	public String getSpec() {
+		return "1" + this.source + "*" + this.originalName + "*" + this.mimeType + "*" + this.length;
+	}
+
+	public InputStream getInputStream() {
+		if (this.stream != null) return this.stream;
+		if (!base.endsWith("/")) base += "/";
+		try {
+			return new FileInputStream(new File(this.base + this.source));
+		} catch (FileNotFoundException e) {
+			throw new MagmaException(e, "File not found");
+		}
+	}
+	
+	public void persist() {
+		if (!modified) return;
+		if (source == null) {
+			source = Long.toHexString(System.currentTimeMillis()) + Long.toHexString(System.nanoTime()); 
+		}
+		if (this.stream != null) {
+			try {
+				try {
+					persist(this.stream);
+				} finally {
+					this.stream.close();
+				}
+			} catch (IOException e) {
+				throw new MagmaException(e, "Error persisting file");
+			}			
+		} else if (temporary != null) {
+			try {
+				FileInputStream fis = new FileInputStream(temporary);
+				try {
+					persist(fis);
+				} finally {
+					fis.close();
+				}
+			} catch (IOException e) {
+				throw new MagmaException(e, "Error persisting file");
+			}
+		}
+	}
+
+	protected void persist(InputStream fileInputStream) throws IOException {
+		if (!base.endsWith("/")) base += "/";
+		File dest = new File(base + this.source);		
+		FileOutputStream fos = new FileOutputStream(dest);
+		try {
+			byte[] buff = new byte[4096];
+			int len = 0;
+			while ((len = fileInputStream.read(buff)) > 0) {
+				fos.write(buff, 0, len);
+			}
+		} finally {
+			fos.close();
+		}
+	}
+	
+	public String getExtension() {
+		String name = this.originalName;
+		if (name == null) {
+			if (this.temporary != null) name = this.temporary.getName();
+			if (name == null) {
+				name = this.source;
+			}
+		}
+		if (name == null) return "raw";
+		int iop = name.lastIndexOf('.');
+		if (iop == -1) return "raw";
+		return name.substring(iop + 1);
+	}
+
+	public File getTemporaryFile() {
+		return this.temporary;
+	}
+
+	public boolean isModified() {
+		return modified;
+	}
+
+}

Added: labs/magma/trunk/beans-file/src/main/java/org/apache/magma/conversion/file/FileConverterToString.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/src/main/java/org/apache/magma/conversion/file/FileConverterToString.java?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/src/main/java/org/apache/magma/conversion/file/FileConverterToString.java (added)
+++ labs/magma/trunk/beans-file/src/main/java/org/apache/magma/conversion/file/FileConverterToString.java Wed Dec  9 20:28:49 2009
@@ -0,0 +1,54 @@
+package org.apache.magma.conversion.file;
+
+import java.io.File;
+
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.beans.MagFile;
+import org.apache.magma.beans.PropertyInfo;
+import org.apache.magma.conversion.Converter;
+import org.apache.magma.conversion.PropertyAwareConverter;
+import org.apache.magma.conversion.string.BaseConverter;
+import org.apache.magma.settings.Settings;
+
+/**
+ * Converts a MagFile to string and back, using a file system store.
+ * 
+ * The file system directory for storage is taken from the property
+ * magma.files.store .
+ * 
+ * The string format contains the file path in the local store, followed by the original file name and
+ * mime type.
+ *
+ * @author Simone Gianni <si...@apache.org>
+ */
+public class FileConverterToString extends BaseConverter<MagFile> implements PropertyAwareConverter {
+
+	public FileConverterToString() {
+		super(MagFile.class);
+	}
+
+	/**
+	 * Always returns a new instance, cause being a {@link PropertyAwareConverter} means this class is not thread safe. 
+	 */	
+	@Override
+	public Converter<MagFile> build(Class<? extends MagFile> clazz) {
+		return new FileConverterToString();
+	}
+	
+	public MagFile from(String value) {
+		if (value == null || value.length() == 0) return null;
+		MagFile ret = new MagFile(value);
+		return ret;
+	}
+
+	public int getMaximumStringSize() {
+		return 0;
+	}
+
+	public String to(MagFile value) {
+		value.persist();
+		return value.getSpec();
+	}	
+
+
+}

Added: labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/InferConsiderOnFileValidated.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/InferConsiderOnFileValidated.aj?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/InferConsiderOnFileValidated.aj (added)
+++ labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/InferConsiderOnFileValidated.aj Wed Dec  9 20:28:49 2009
@@ -0,0 +1,13 @@
+package org.apache.magma.validation.validators;
+
+import org.apache.magma.beans.Consider;
+import org.apache.magma.beans.MagFile;
+import org.apache.magma.beans.MagmaBeanSupport;
+
+public aspect InferConsiderOnFileValidated {
+
+	// TODO worked around for AspectJ bug
+	declare @method : (@MagUpload !@Consider public * org.apache.magma.beans.*agmaBeanSupport+.get*()) : @Consider(MagFile.class);
+	declare @method : (@MagUpload !@Consider public void org.apache.magma.beans.*agmaBeanSupport+.set*(..)) : @Consider(MagFile.class);
+	
+}

Added: labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUpload.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUpload.java?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUpload.java (added)
+++ labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUpload.java Wed Dec  9 20:28:49 2009
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.magma.validation.validators;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.magma.beans.Consider;
+import org.apache.magma.beans.MagFile;
+import org.apache.magma.validation.ValidationAnnotation;
+
+/**
+ * Validation for fields marked as {@link MagFile} using {@link Consider}.
+ *
+ * @author Simone Gianni <si...@apache.org>
+ */
+@ValidationAnnotation
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface MagUpload {
+
+	/**
+	 * @return The extensions permitted.
+	 */
+	public String[] extensions() default {};
+
+	/**
+	 * @return Maximum length permitted.
+	 */
+	public long maxLength() default Long.MAX_VALUE;
+	
+}

Added: labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUploadValidator.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUploadValidator.java?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUploadValidator.java (added)
+++ labs/magma/trunk/beans-file/src/main/java/org/apache/magma/validation/validators/MagUploadValidator.java Wed Dec  9 20:28:49 2009
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.magma.validation.validators;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.magma.basics.LocalizableString;
+import org.apache.magma.beans.MagFile;
+import org.apache.magma.beans.PropertyInfo;
+import org.apache.magma.validation.Validator;
+
+public class MagUploadValidator implements Validator<MagFile> {
+
+	private String[] extensions;
+	private long maxLength;
+	
+	public List<LocalizableString> validate(Object bean, PropertyInfo property, MagFile value) {
+		if (value == null) return null;
+		List<LocalizableString> messages = null;
+		if (extensions != null && extensions.length > 0) {
+			String name = value.getOriginalName();
+			if (name != null) {
+				boolean found = false;
+				for (String ext : this.extensions) {
+					if (name.endsWith("." + ext)) {
+						found = true;
+						break;
+					}
+				}
+				if (!found) {
+					if (messages == null) messages = new ArrayList<LocalizableString>();
+					messages.add(new LocalizableString("Given file is not correct type, please provide one of {0}", this.extensions));
+				}
+			}
+		}
+		if (value.getLength() != 0) {
+			if (value.getLength() > this.maxLength) {
+				if (messages == null) messages = new ArrayList<LocalizableString>();
+				messages.add(new LocalizableString("File size {0} is too much, please provide a file under {1} bytes", value.getLength(), this.maxLength));
+			}
+		}
+		return messages;
+	}
+
+	public String[] getExtensions() {
+		return extensions;
+	}
+
+	public void setExtensions(String[] extension) {
+		this.extensions = extension;
+	}
+
+	public long getMaxLength() {
+		return maxLength;
+	}
+
+	public void setMaxLength(long maxLength) {
+		this.maxLength = maxLength;
+	}
+
+	public int maxCharacterLength() {
+		return 0;
+	}
+
+}

Added: labs/magma/trunk/beans-file/src/main/resources/META-INF/magma.default.properties
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/src/main/resources/META-INF/magma.default.properties?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/src/main/resources/META-INF/magma.default.properties (added)
+++ labs/magma/trunk/beans-file/src/main/resources/META-INF/magma.default.properties Wed Dec  9 20:28:49 2009
@@ -0,0 +1,15 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more
+#contributor license agreements.  See the NOTICE file distributed with
+#this work for additional information regarding copyright ownership.
+#The ASF licenses this file to You 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.
+org.apache.magma.conversion.Converter.file=org.apache.magma.conversion.file.FileConverterToString

Added: labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/FileTestUtils.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/FileTestUtils.java?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/FileTestUtils.java (added)
+++ labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/FileTestUtils.java Wed Dec  9 20:28:49 2009
@@ -0,0 +1,44 @@
+package org.apache.magma.beans;
+
+import java.io.File;
+
+import org.apache.magma.settings.Settings;
+import org.apache.magma.settings.SettingsHolder;
+
+public class FileTestUtils {
+
+	public File tmpstore = null;
+	
+	public void setup() {
+		String tmpdirstr = System.getProperty("java.io.tmpdir");
+		File tmpdir = new File(tmpdirstr);
+		tmpstore = new File(tmpdir, "testfilestore");
+		tmpstore.mkdir();
+		Settings.ftuModifyEntry("magma.files.store", tmpstore.getAbsolutePath());
+	}
+	
+	static privileged aspect SettingsModifier {
+		
+		public static void Settings.ftuModifyEntry(String key, String value) {
+			holder.override(key, value);
+		}
+		
+	}
+	
+	public void teardown() {
+		recurseDelete(tmpstore);
+	}
+	
+	private void recurseDelete(File f) {
+		if (f.isFile()) {
+			f.delete();
+		} else if (f.isDirectory()) {
+			File[] listFiles = f.listFiles();
+			for (File file : listFiles) {
+				recurseDelete(file);
+			}
+			f.delete();
+		}
+	}
+	
+}

Added: labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/MagFileTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/MagFileTest.java?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/MagFileTest.java (added)
+++ labs/magma/trunk/beans-file/src/test/java/org/apache/magma/beans/MagFileTest.java Wed Dec  9 20:28:49 2009
@@ -0,0 +1,60 @@
+package org.apache.magma.beans;
+
+import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.*;
+import static org.hamcrest.CoreMatchers.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MagFileTest {
+	
+	private FileTestUtils ftu = null;
+	
+	@Before
+	public void setup() {
+		ftu = new FileTestUtils();
+		ftu.setup();
+	}
+	
+	@After
+	public void teardown() {
+		if (ftu != null) ftu.teardown();
+	}
+	
+	@Test
+	public void cyclingTest() throws Exception {
+		URL url = getClass().getResource("/testFile.txt");
+		File f = new File(url.toURI());
+		MagFile mf = new MagFile(f, "textfile.txt");
+		assertThat(mf.getLength(), equalTo(f.length()));
+		mf.persist();
+		String source = mf.getSource();
+		assertNotNull(source);
+		File saved = new File(ftu.tmpstore, source);
+		assertTrue("File not created", saved.exists());
+		assertThat("File size does not match", saved.length(), equalTo(f.length()));
+		
+		String spec = mf.getSpec();
+		assertNotNull("No spec", spec);
+		MagFile mf2 = new MagFile(spec);
+		assertThat(mf2.getOriginalName(), equalTo("textfile.txt"));
+		assertThat(mf2.getLength(), equalTo(f.length()));
+		assertThat(mf2.getSource(), equalTo(source));
+		InputStream inputStream = mf2.getInputStream();
+		assertNotNull(inputStream);
+		byte[] buff = new byte[1024];
+		int len = inputStream.read(buff);
+		assertThat(len, equalTo((int)f.length()));
+		
+	}
+	
+	
+
+}

Added: labs/magma/trunk/beans-file/src/test/resources/testFile.txt
URL: http://svn.apache.org/viewvc/labs/magma/trunk/beans-file/src/test/resources/testFile.txt?rev=888947&view=auto
==============================================================================
--- labs/magma/trunk/beans-file/src/test/resources/testFile.txt (added)
+++ labs/magma/trunk/beans-file/src/test/resources/testFile.txt Wed Dec  9 20:28:49 2009
@@ -0,0 +1 @@
+This is a test file
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org