storeManager.addProduct(prod, "FISH", null);
}
@Test
public void addProduct() throws Exception {
Product prod = new Product();
final File srcfile = new File(srcdir, "resources.xml");
prod.setProductId("myfish");
prod.setDescription("My fish");
prod.setName("my fish");
FileItem fi = createMock(FileItem.class);
expect(fi.getName()).andReturn("c:\\test\\pic.gif");
expect(fi.getInputStream()).andAnswer(new IAnswer<InputStream>() {
public InputStream answer() throws Throwable {
return new FileInputStream(srcfile);
}
});
replay(fi);
storeManager.addProduct(prod, "FISH", fi);
prod = productDao.getProductById("myfish");
assertEquals("myfish", prod.getProductId());
assertEquals("my fish", prod.getName());
assertEquals("My fish", prod.getDescription());
assertEquals("FISH", prod.getCategoryId());
assertTrue(prod.getLogo().startsWith("image_"));
assertTrue(prod.getLogo().endsWith(".gif"));
File f = new File(destdir, "upload/" + prod.getLogo());
assertTrue(f.exists());
assertEquals(StreamUtil.readText(new FileInputStream(srcfile), "8859_1", true),
StreamUtil.readText(new FileInputStream(f), "8859_1", true));
}