Play has a nifty file upload mechanism where uploads can be performed like so:
the model…
import play.db.jpa.Blob;
@Entity
public class User extends Model {
public String name;
public Blob photo;
}
the form…
#{form @addUser(), enctype:'multipart/form-data'}
<input type="file" name="user.photo">
<input type="submit" name="submit" value="Upload">
#{/form}
the controller…
public static void addUser(User user) {
user.save();
index();
}
Which is nice and simple, however I’m stuck on how to write a unit test for the model. How can I test it with a file that doesn’t go through the upload process?
thanks!
You could just create a new Blob();
Open a file on your disk (you could add a file in you project for this test)
And use this method from the play.db.jpa.Blob class to load the file in the blob.
set(InputStream is, String type);
Let me know if it works.