示例#1
0
  public void testClearingData() {

    Node<Object, Object> rootNode = cache.getRoot();

    rootNode.put("k", "v");
    rootNode.put("k2", "v2");
    assertEquals(2, rootNode.getKeys().size());
    rootNode.clearData();
    assertEquals(0, rootNode.getKeys().size());
    assertTrue(rootNode.getData().isEmpty());
  }
示例#2
0
  public void testClearingDataTx() throws Exception {

    Node<Object, Object> rootNode = cache.getRoot();

    tm.begin();
    rootNode.put("k", "v");
    rootNode.put("k2", "v2");
    assertEquals(2, rootNode.getKeys().size());
    rootNode.clearData();
    assertEquals(0, rootNode.getKeys().size());
    assertTrue(rootNode.getData().isEmpty());
    tm.commit();
    assertTrue(rootNode.getData().isEmpty());
  }
示例#3
0
  public void testDefensiveCopyOfData() {

    Node<Object, Object> rootNode = cache.getRoot();

    rootNode.put("key", "value");
    Map<Object, Object> data = rootNode.getData();
    Set<Object> keys = rootNode.getKeys();

    assert keys.size() == 1;
    assert keys.contains("key");

    assert data.size() == 1;
    assert data.containsKey("key");

    // now change stuff.

    rootNode.put("key2", "value2");

    // assert that the collections we initially got have not changed.
    assert keys.size() == 1;
    assert keys.contains("key");

    assert data.size() == 1;
    assert data.containsKey("key");
  }
  @Override
  public List<OutputContentFile> getImages(
      final String merchantStoreCode, FileContentType imageContentType) throws ServiceException {
    if (cacheManager.getTreeCache() == null) {
      throw new ServiceException(
          "CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
    }
    List<OutputContentFile> images = new ArrayList<OutputContentFile>();
    FileNameMap fileNameMap = URLConnection.getFileNameMap();

    try {

      StringBuilder nodePath = new StringBuilder();
      nodePath.append(merchantStoreCode);

      Node<String, Object> merchantNode = this.getNode(nodePath.toString());

      Set<Node<String, Object>> childs = merchantNode.getChildren();

      Iterator<Node<String, Object>> iterator = childs.iterator();
      // TODO image sizes
      while (iterator.hasNext()) {

        Node<String, Object> node = iterator.next();

        for (String key : node.getKeys()) {

          byte[] imageBytes = (byte[]) merchantNode.get(key);

          OutputContentFile contentImage = new OutputContentFile();

          InputStream input = new ByteArrayInputStream(imageBytes);
          ByteArrayOutputStream output = new ByteArrayOutputStream();
          IOUtils.copy(input, output);

          String contentType = fileNameMap.getContentTypeFor(key);

          contentImage.setFile(output);
          contentImage.setMimeType(contentType);
          contentImage.setFileName(key);

          images.add(contentImage);
        }
      }

    } catch (Exception e) {
      throw new ServiceException(e);
    } finally {

    }

    return images;
  }
  @Override
  public List<OutputContentFile> getImages(Product product) throws ServiceException {

    if (cacheManager.getTreeCache() == null) {
      throw new ServiceException(
          "CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
    }

    List<OutputContentFile> images = new ArrayList<OutputContentFile>();

    try {

      FileNameMap fileNameMap = URLConnection.getFileNameMap();
      StringBuilder nodePath = new StringBuilder();
      nodePath.append(product.getMerchantStore().getCode());

      Node<String, Object> merchantNode = this.getNode(nodePath.toString());

      if (merchantNode == null) {
        return null;
      }

      for (String key : merchantNode.getKeys()) {

        byte[] imageBytes = (byte[]) merchantNode.get(key);

        OutputContentFile contentImage = new OutputContentFile();

        InputStream input = new ByteArrayInputStream(imageBytes);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        IOUtils.copy(input, output);

        String contentType = fileNameMap.getContentTypeFor(key);

        contentImage.setFile(output);
        contentImage.setMimeType(contentType);
        contentImage.setFileName(key);

        images.add(contentImage);
      }

    } catch (Exception e) {
      throw new ServiceException(e);
    } finally {

    }

    return images;
  }
示例#6
0
  public void testImmutabilityOfData() {

    Node<Object, Object> rootNode = cache.getRoot();

    rootNode.put("key", "value");
    Map<Object, Object> m = rootNode.getData();
    try {
      m.put("x", "y");
      fail("Map should be immutable!!");
    } catch (Exception e) {
      // expected
    }

    try {
      rootNode.getKeys().add(new Object());
      fail("Key set should be immutable");
    } catch (Exception e) {
      // expected
    }
  }