Package org.springframework.cache

Examples of org.springframework.cache.Cache


  }

  @Test
  public void earlyPutWithException() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    assertNull(cache.get(key));

    try {
      service.earlyPutWithException(keyItem, value, true);
      fail("Should have thrown an exception");
    }
    catch (UnsupportedOperationException e) {
      // This is what we expect
    }

    Cache.ValueWrapper result = cache.get(key);
    assertNotNull(result);
    assertEquals(value, result.get());
  }
View Full Code Here


  }

  @Test
  public void earlyPutWithExceptionVetoPut() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    assertNull(cache.get(key));

    try {
      service.earlyPutWithException(keyItem, value, false);
      fail("Should have thrown an exception");
    }
    catch (NullPointerException e) {
      // This is what we expect
    }
    // This will be cached anyway as the earlyPut has updated the cache before
    Cache.ValueWrapper result = cache.get(key);
    assertNotNull(result);
    assertEquals(value, result.get());
  }
View Full Code Here

  }

  @Test
  public void remove() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    cache.put(key, value);

    service.remove(keyItem);

    assertNull(cache.get(key));
  }
View Full Code Here

  }

  @Test
  public void removeWithException() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    cache.put(key, value);

    try {
      service.removeWithException(keyItem, true);
      fail("Should have thrown an exception");
    }
    catch (UnsupportedOperationException e) {
      // This is what we expect
    }

    assertNull(cache.get(key));
  }
View Full Code Here

  }

  @Test
  public void removeWithExceptionVetoRemove() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    cache.put(key, value);

    try {
      service.removeWithException(keyItem, false);
      fail("Should have thrown an exception");
    }
    catch (NullPointerException e) {
      // This is what we expect
    }
    Cache.ValueWrapper wrapper = cache.get(key);
    assertNotNull(wrapper);
    assertEquals(value, wrapper.get());
  }
View Full Code Here

  }

  @Test
  public void earlyRemove() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    cache.put(key, value);

    service.earlyRemove(keyItem);

    assertNull(cache.get(key));
  }
View Full Code Here

  }

  @Test
  public void earlyRemoveWithException() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    cache.put(key, value);

    try {
      service.earlyRemoveWithException(keyItem, true);
      fail("Should have thrown an exception");
    }
    catch (UnsupportedOperationException e) {
      // This is what we expect
    }
    assertNull(cache.get(key));
  }
View Full Code Here

      return new SimpleService();
    }

    @Bean
    public Cache mockCache() {
      Cache cache = mock(Cache.class);
      given(cache.getName()).willReturn("test");
      return cache;
    }
View Full Code Here

  }

  @Test
  public void earlyRemoveWithExceptionVetoRemove() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    cache.put(key, value);

    try {
      service.earlyRemoveWithException(keyItem, false);
      fail("Should have thrown an exception");
    }
    catch (NullPointerException e) {
      // This is what we expect
    }
    // This will be remove anyway as the earlyRemove has removed the cache before
    assertNull(cache.get(key));
  }
View Full Code Here

    assertNull(cache.get(key));
  }

  @Test
  public void removeAll() {
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(name.getMethodName());
    cache.put(key, new Object());

    service.removeAll();

    assertTrue(isEmpty(cache));
  }
View Full Code Here

TOP

Related Classes of org.springframework.cache.Cache

Copyright © 2018 www.massapicom. 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.