/*
 *
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package org.jboss.ejb3.test.lob.unit;

//import java.rmi.*;


import junit.framework.Test;
import org.jboss.ejb3.test.lob.LobTester;
import org.jboss.ejb3.test.lob.BlobEntity2;
import org.jboss.test.JBossTestCase;

import java.util.HashMap;
import java.util.Map;
import java.io.ObjectInputStream;
import java.io.ByteArrayInputStream;

/**
 * Sample client for the jboss container.
 *
 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
 * @version $Id: BlobUnitTestCase.java,v 1.2.2.4 2005/09/14 22:19:10 bill Exp $
 */

public class BlobUnitTestCase
extends JBossTestCase
{
   org.apache.log4j.Category log = getLog();

   static boolean deployed = false;
   static int test = 0;

   public BlobUnitTestCase(String name)
   {

      super(name);

   }

   public void testBlob() throws Exception
   {
      LobTester test = (LobTester) this.getInitialContext().lookup(LobTester.class.getName());
      long blobId = test.create();
      HashMap map = test.findBlob(blobId);
      assertEquals("world", map.get("hello"));
      String str = test.findClob(blobId);
      assertTrue(str.startsWith("This is a very long string"));
   }

   public void testBlob2() throws Exception
   {
      LobTester test = (LobTester) this.getInitialContext().lookup(LobTester.class.getName());
      long blobId = test.create2();
      BlobEntity2 blob = test.findBlob2(blobId);
      ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(blob.getBlobby()));
      Map map = (HashMap) ois.readObject();

      assertEquals("world", map.get("hello"));
      assertTrue(blob.getClobby().startsWith("This is a very long string"));
   }

   public static Test suite() throws Exception
   {
      return getDeploySetup(BlobUnitTestCase.class, "lob-test.ejb3");
   }

}
