Package org.jboss.cache.optimistic

Source Code of org.jboss.cache.optimistic.NodeInterceptorTransactionTest

/*
* Created on 17-Feb-2005
*
*
*
*/
package org.jboss.cache.optimistic;

import org.jboss.cache.CacheSPI;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;

/**
* @author xenephon
*/
@SuppressWarnings("unchecked")
@Test(groups = "functional")
public class NodeInterceptorTransactionTest extends AbstractOptimisticTestCase
{
   public void testNoTransactionCRUDMethod() throws Exception
   {

      TestListener listener = new TestListener();
      final CacheSPI cache = createCacheWithListener(listener);

      Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
      Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
      MockInterceptor dummy = new MockInterceptor();

      interceptor.setNext(nodeInterceptor);
      nodeInterceptor.setNext(dummy);

      TestingUtil.replaceInterceptorChain(cache, interceptor);

      try
      {
         cache.put("/one/two", "key1", new Object());
         fail();
      }
      catch (Throwable t)
      {

         assertTrue(true);
      }
      assertEquals(null, dummy.getCalled());
      cache.stop();
   }

   public void testNoTransactionGetMethod() throws Exception
   {

      TestListener listener = new TestListener();
      final CacheSPI cache = createCacheWithListener(listener);

      Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
      Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
      MockInterceptor dummy = new MockInterceptor();

      interceptor.setNext(nodeInterceptor);
      nodeInterceptor.setNext(dummy);

      TestingUtil.replaceInterceptorChain(cache, interceptor);

      boolean fail = false;
      try
      {
         assertEquals(null, cache.get("/one/two", "key1"));
      }
      catch (Exception e)
      {
         fail = true;
      }
      assertTrue(fail);
      assertEquals(null, dummy.getCalled());
      cache.stop();
   }


}
TOP

Related Classes of org.jboss.cache.optimistic.NodeInterceptorTransactionTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.