1 package org.mmbase.bridge.tests; 2 3 import org.mmbase.bridge.*; 4 import java.io.*; 5 6 import org.mmbase.util.functions.Function; 7 import org.mmbase.util.functions.Parameters; 8 9 15 public class ConvertImageTest extends org.mmbase.tests.BridgeTest { 16 17 private final static String JPG_IMAGE_NAME = "testimage.jpg"; 18 19 public void testImportedJpegImage() { 20 Cloud cloud = getCloud(); 21 Node node = cloud.getNode("jpeg.test.image"); 22 node.getByteValue("handle"); 23 assertTrue("MMBase failed to determine mime-type properly (magicfile problem?)", node.getStringValue("itype").equals("jpeg")); 24 } 26 27 30 public void testGetInvalueCachedImage() { 31 Cloud cloud = getCloud(); 32 Node node = cloud.getNode("jpeg.test.image"); 33 node.getIntValue("cache(s(30x30))"); 34 } 35 36 40 public void testFunctionValueCachedImage() { 41 Cloud cloud = getCloud(); 42 Node node = cloud.getNode("jpeg.test.image"); 43 Function f = node.getFunction("cache"); 44 Parameters p = f.createParameters(); 45 p.set("template","s(30x30)"); 46 f.getFunctionValue(p); 47 } 48 49 52 public void setUp() throws Exception { 53 startMMBase(); 54 startLogging(); 55 Cloud cloud = getCloud(); 56 NodeManager nodeManager = cloud.getNodeManager("images"); 57 Node jpegNode = nodeManager.createNode(); 58 jpegNode.setStringValue("title", JPG_IMAGE_NAME); 59 byte[] bytes = getTextImageBytes(JPG_IMAGE_NAME); 60 jpegNode.setByteValue("handle", bytes); 61 jpegNode.commit(); 62 jpegNode.createAlias("jpeg.test.image"); 63 } 64 65 66 69 protected void tearDown() throws Exception { 70 Cloud cloud = getCloud(); 71 Node node = cloud.getNode("jpeg.test.image"); 72 node.delete(); 73 } 74 79 private byte[] getTextImageBytes(String name) { 80 try { 81 InputStream in = this.getClass().getResourceAsStream(name); 82 83 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 84 85 byte[] buffer = new byte[200]; 86 int readSize = 0; 87 while ((readSize = in.read(buffer)) > 0) { 88 baos.write(buffer, 0, readSize); 89 } 90 return baos.toByteArray(); 91 } catch (IOException ioe) { 92 fail("did not find image to load " + this.getClass().getResource(name)); 93 } 94 return null; 95 } 96 } 97 | Popular Tags |