Exemplo n.º 1
0
  public void testDefensiveCopyOfChildren() {

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

    Fqn childFqn = Fqn.fromString("/child");
    rootNode.addChild(childFqn).put("k", "v");
    Set<Node<Object, Object>> children = rootNode.getChildren();
    Set<Object> childrenNames = rootNode.getChildrenNames();

    assert childrenNames.size() == 1;
    assert childrenNames.contains(childFqn.getLastElement());

    assert children.size() == 1;
    assert children.iterator().next().getFqn().equals(childFqn);

    // now change stuff.

    rootNode.addChild(Fqn.fromString("/child2"));

    // assert that the collections we initially got have not changed.
    assert childrenNames.size() == 1;
    assert childrenNames.contains(childFqn.getLastElement());

    assert children.size() == 1;
    assert children.iterator().next().getFqn().equals(childFqn);
  }
  @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;
  }
Exemplo n.º 3
0
  public void testImmutabilityOfChildren() {

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

    rootNode.addChild(A);

    try {
      rootNode.getChildren().clear();
      fail("Collection of child nodes returned in getChildren() should be immutable");
    } catch (Exception e) {
      // expected
    }
  }
Exemplo n.º 4
0
  /** Remember, Fqns are relative!! */
  public void testParentsAndChildren() {

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

    Node<Object, Object> nodeA = rootNode.addChild(A);
    Node<Object, Object> nodeB = nodeA.addChild(B);
    Node<Object, Object> nodeC = nodeA.addChild(C);
    Node<Object, Object> nodeD = rootNode.addChild(D);

    assertEquals(rootNode, nodeA.getParent());
    assertEquals(nodeA, nodeB.getParent());
    assertEquals(nodeA, nodeC.getParent());
    assertEquals(rootNode, nodeD.getParent());

    assertTrue(rootNode.hasChild(A));
    assertFalse(rootNode.hasChild(B));
    assertFalse(rootNode.hasChild(C));
    assertTrue(rootNode.hasChild(D));

    assertTrue(nodeA.hasChild(B));
    assertTrue(nodeA.hasChild(C));

    assertEquals(nodeA, rootNode.getChild(A));
    assertEquals(nodeD, rootNode.getChild(D));
    assertEquals(nodeB, nodeA.getChild(B));
    assertEquals(nodeC, nodeA.getChild(C));

    assertTrue(nodeA.getChildren().contains(nodeB));
    assertTrue(nodeA.getChildren().contains(nodeC));
    assertEquals(2, nodeA.getChildren().size());

    assertTrue(rootNode.getChildren().contains(nodeA));
    assertTrue(rootNode.getChildren().contains(nodeD));
    assertEquals(2, rootNode.getChildren().size());

    assertEquals(true, rootNode.removeChild(A));
    assertFalse(rootNode.getChildren().contains(nodeA));
    assertTrue(rootNode.getChildren().contains(nodeD));
    assertEquals(1, rootNode.getChildren().size());

    assertEquals("double remove", false, rootNode.removeChild(A));
    assertEquals("double remove", false, rootNode.removeChild(A.getLastElement()));
  }