Example #1
0
  public void testAlias() {
    Cloud cloud = getCloud();
    {
      Node node = cloud.getNode(newNode2);
      node.setStringValue("title", "abcdef");
      node.commit();
      assertEquals("abcdef", node.getStringValue("title"));
      node = cloud.getNode("test.news." + seq);
      assertEquals("abcdef", node.getStringValue("title"));
    }

    {
      Transaction t = cloud.getTransaction("bar12");

      Node node = t.getNode(newNode2);
      node.setStringValue("title", "abcdefg");
      node.commit();
      assertEquals("abcdefg", node.getStringValue("title"));
      t.commit();
      assertEquals("abcdefg", node.getStringValue("title"));

      node = cloud.getNode("test.news." + seq);
      assertEquals("abcdefg", node.getStringValue("title"));

      node = cloud.getNode(newNode2);
      assertEquals("abcdefg", node.getStringValue("title"));
    }
  }
Example #2
0
 public void testAddToResultCreateOneRelation() {
   Node mag = getCloud().getNodeManager("mags").createNode();
   mag.commit();
   Node news = getCloud().getNodeManager("news").createNode();
   news.commit();
   NodeQuery q =
       Queries.createRelatedNodesQuery(
           mag, getCloud().getNodeManager("news"), "posrel", "destination");
   NodeList result = Queries.addToResult(q, news);
   assertEquals(1, result.size());
 }
Example #3
0
 public void testAddToResultCreateTwoRelations() {
   Node mag = getCloud().getNodeManager("mags").createNode();
   mag.commit();
   Node news = getCloud().getNodeManager("news").createNode();
   news.commit();
   Node url = getCloud().getNodeManager("urls").createNode();
   url.commit();
   NodeQuery q =
       Queries.createRelatedNodesQuery(
           mag, getCloud().getNodeManager("news"), "posrel", "destination");
   Queries.addPath(q, "posrel,urls", "destination");
   Queries.addStartNodes(q, "" + url.getNumber());
   NodeList result = Queries.addToResult(q, news);
   assertEquals(2, result.size());
 }
Example #4
0
  public void testCreateAndDelete2() {
    // Create new node. Request the node again. Delete  that. Commit the transaction.
    // The new node must not exist.

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());

    Transaction t = cloud.getTransaction("testcreateandelete");
    Node url = t.getNodeManager("urls").createNode();
    url.commit();
    assertEquals(1, t.getNodes().size());

    Node reurl = t.getNode(url.getNumber());
    reurl.delete();

    assertEquals(
        1,
        t.getNodes()
            .size()); // 0 would also be an option, but the node remaisn in the transaction as
                      // 'NOLONGER'

    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());

    assertEquals(urlCount, urlCountAfter);
  }
Example #5
0
  // MMB-1889
  public void testCreateRelationAndDeleteNode() {
    // Make a relation to an existing node. Then delete that node with the 'delete relations'
    // option'. Commit the transaction.
    // The new relations should not exist, since the node was deleted.
    // No errors.

    Cloud cloud = getCloud();

    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());
    int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery());

    Node url = cloud.getNodeManager("urls").createNode();
    url.commit();

    Transaction t = cloud.getTransaction("relatedandelete");

    Node turl = t.getNode(url.getNumber());
    Node news = t.getNode(newNode);
    RelationManager rm = t.getRelationManager("urls", "news", "posrel");
    Relation r = turl.createRelation(news, rm);
    r.commit();
    turl.delete(true);
    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());
    assertEquals(urlCount, urlCountAfter);
    int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery());
    assertEquals(relCount, relCountAfter);
  }
Example #6
0
  // MMB-1893
  public void testDeleteNodeWitRelationsAndCancel() {
    Cloud cloud = getCloud();

    int urlCount0 = Queries.count(cloud.getNodeManager("urls").createQuery());
    int relCount0 = Queries.count(cloud.getNodeManager("insrel").createQuery());

    Node url = cloud.getNodeManager("urls").createNode();
    url.commit();
    Node news = cloud.getNode(newNode);
    RelationManager rm = cloud.getRelationManager("urls", "news", "posrel");
    Relation r = url.createRelation(news, rm);
    r.commit();

    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());
    int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery());

    assertEquals(urlCount0 + 1, urlCount);
    assertEquals(relCount0 + 1, relCount);

    Transaction t = cloud.getTransaction("deletewithrelationsandcancel");

    Node turl = t.getNode(url.getNumber());
    turl.delete(true);

    t.cancel();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());
    assertEquals(urlCount, urlCountAfter);

    int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery());
    assertEquals(relCount, relCountAfter); // MMB-1893
  }
Example #7
0
  // MMB-1860 (4)
  public void testRelateAndDeleteRelation() {

    //  Make a relation between two nodes. Delete the relation again. Commit the transaction.
    // Te relation shouldn't exist

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());
    int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery());

    Node newUrl = cloud.getNodeManager("urls").createNode();
    newUrl.commit();

    Transaction t = cloud.getTransaction("testrelateandeleterelation");

    Node news = t.getNode(newNode);
    Node url = t.getNode(newUrl.getNumber());
    RelationManager rm = t.getRelationManager("urls", "news", "posrel");
    Relation r = url.createRelation(news, rm);
    r.commit();

    r.delete();

    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());

    assertEquals(urlCount + 1, urlCountAfter);

    // But the relation should not exist, because it was deleted angain

    int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery());

    assertEquals(relCount, relCountAfter);
  }
Example #8
0
 public boolean save() {
   Node node = ForumManager.getCloud().getNode(id);
   node.setValue("mode", mode);
   node.setValue("body", body);
   node.setValue("encoding", encoding);
   node.commit();
   return true;
 }
Example #9
0
 public void setUp() {
   seq++;
   // Create some test nodes
   Cloud cloud = getCloud();
   {
     Node node = cloud.getNodeManager("news").createNode();
     node.setStringValue("title", "foo");
     node.commit();
     newNode = node.getNumber();
   }
   {
     Node node = cloud.getNodeManager("news").createNode();
     node.setStringValue("title", "foo");
     node.createAlias("test.news." + seq);
     node.setContext("default");
     node.commit();
     newNode2 = node.getNumber();
   }
 }
Example #10
0
  public void testCancel() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("cancel1");
    Node node = t.getNode(newNode);
    node.setStringValue("title", "xxxxx");
    node.commit();
    t.cancel();

    node = cloud.getNode(newNode);

    assertEquals("foo", node.getStringValue("title"));
  }
Example #11
0
  public void testCommit() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("bar3");
    Node node = t.getNode(newNode);
    node.setStringValue("title", "yyyyy");
    node.commit();
    t.commit();

    node = cloud.getNode(newNode);

    assertEquals("yyyyy", node.getStringValue("title"));
  }
Example #12
0
 public void testReuseTransaction() {
   Cloud cloud = getCloud();
   {
     Node node = cloud.getNode(newNode);
     node.setStringValue("title", "zzyyxx");
     node.commit();
     assertEquals("zzyyxx", cloud.getNode(newNode).getStringValue("title"));
   }
   {
     Transaction t = cloud.getTransaction("bar4");
     assertEquals(0, t.getNodes().size());
     Node node = t.getNode(newNode);
     assertEquals("zzyyxx", node.getStringValue("title"));
     assertEquals(1, t.getNodes().size());
     node.setStringValue("title", "wwwwww");
     node.commit();
     assertEquals("wwwwww", node.getStringValue("title"));
     t.cancel();
     assertEquals("zzyyxx", cloud.getNode(newNode).getStringValue("title"));
   }
   assertEquals("zzyyxx", cloud.getNode(newNode).getStringValue("title"));
 }
Example #13
0
 public void testMMB1546() {
   Cloud cloud = getCloud();
   Transaction t = cloud.getTransaction("test0");
   Node nt = t.getNode(newNode);
   nt.setValue("title", "bla");
   // t.cancel(); _DONT_ cancel
   Node nc = cloud.getNode(newNode);
   nc.setValue("title", "bloe");
   nc.commit();
   assertEquals("bloe", nc.getStringValue("title"));
   assertEquals("bloe", cloud.getNode(newNode).getStringValue("title"));
   t.cancel();
   assertEquals("bloe", cloud.getNode(newNode).getStringValue("title"));
 }
Example #14
0
  // MMB-1857
  public void testGetNodes() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("testgetnodes");
    Node n = t.getNode(newNode);
    Node url = t.getNodeManager("urls").createNode();
    RelationManager rm = t.getRelationManager("urls", "news", "posrel");
    Relation r = url.createRelation(n, rm);

    {
      // should not give NPE's or so
      n.commit();
      url.commit();
      r.commit();
    }

    assertEquals(3, t.getNodes().size()); // 2 nodes and one relation

    for (Node rn : t.getNodes()) {
      // should occur no exceptions
      rn.commit(); // should have little effect in trans
    }
    t.cancel();
  }
Example #15
0
  public void testGetNode() {
    // Create new node. Request the node again.
    // Should work

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());

    Transaction t = cloud.getTransaction("testgetnode");
    Node url = t.getNodeManager("urls").createNode();
    url.setStringValue("url", "http://bla");
    url.commit();

    Node reurl = t.getNode(url.getNumber());

    assertEquals("http://bla", reurl.getStringValue("url"));
  }
Example #16
0
  public void testEditNodeOutsideTransaction2() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("bar10");
    Node nodeInTransaction = t.getNode(newNode2);
    nodeInTransaction.setStringValue("title", "foo2");
    Node nodeOutTransaction = cloud.getNode(newNode2);
    nodeOutTransaction.setStringValue("title", "bar2");

    t.commit();
    nodeOutTransaction.commit();

    // transaction was committed _earlier_ so the commit of the node must have won
    assertEquals("bar2", cloud.getNode(newNode2).getStringValue("title"));
    // assertEquals("bar2", nodeInTransaction.getStringValue("title"));// not sure what this should
    // have done, but anyhow, it now fails
    assertEquals("bar2", nodeOutTransaction.getStringValue("title"));
  }
Example #17
0
  // Test for http://www.mmbase.org/jira/browse/MMB-1621
  public void testGetValue() {
    Cloud cloud = getCloud();

    String value = cloud.getNode(newNode).getStringValue("title");
    assertFalse("zzzzz".equals(value));

    Transaction t = cloud.getTransaction("bar4");
    System.out.println("Transaction now " + t);
    Node node = t.getNode(newNode);
    assertEquals(1, t.getNodes().size());
    node.setStringValue("title", "zzzzz");
    assertEquals("zzzzz", node.getStringValue("title"));
    node.commit(); // committing inside transaction

    assertEquals("zzzzz", node.getStringValue("title"));
    assertEquals(value, cloud.getNode(newNode).getStringValue("title"));

    t.commit();
    assertEquals("zzzzz", cloud.getNode(newNode).getStringValue("title"));
  }
Example #18
0
 public void testGetNodeTwiceWhileChanged() {
   Cloud cloud1 = getCloud();
   String originalTitleValue = cloud1.getNode(newNode2).getStringValue("title");
   {
     Node node = cloud1.getNode(newNode2);
     String title1 = node.getStringValue("title");
     node.setStringValue("title", "bla bla");
     // don't commit
   }
   // now change something by someone else
   {
     Cloud cloud2 = getCloud("foo");
     assertTrue(cloud1 != cloud2);
     Node node = cloud2.getNode(newNode2);
     node.setStringValue("title", "new title value");
     node.commit();
   }
   // now look to the original cloud
   {
     Node node = cloud1.getNode(newNode2);
     assertEquals("new title value", node.getStringValue("title"));
   }
 }
Example #19
0
  private Boolean sendMail(HttpServletRequest req, Node node, String email) {
    boolean send = false;

    Cloud cloud = node.getCloud();
    String emailbuilder = "email";
    try {
      Module sendmail = cloud.getCloudContext().getModule("sendmail");
      emailbuilder = sendmail.getProperty("emailbuilder");
    } catch (NotFoundException nfe) {
      log.warn("No email module " + nfe);
    }

    if (cloud.hasNodeManager(emailbuilder)) {

      NodeManager nm = cloud.getNodeManager(emailbuilder);
      Node message = nm.createNode();

      String host = req.getHeader("host");
      if (host == null || "".equals(host)) {
        try {
          host = java.net.InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException uhe) {
          log.warn("No host: " + uhe);
        }
      }
      String from = "[email protected]" + host;
      // do a quick check if we've got something more or less valid
      Pattern p = Pattern.compile("[email protected]+\\.[a-z]+");
      Matcher m = p.matcher(from);
      if (!m.matches()) {
        from = "[email protected]";
      }

      String mediaTitle = node.getStringValue("title");
      String mediaUrl = getProperty(node, URL_KEY);
      StringBuilder body = new StringBuilder();

      body.append("*This is an automated message / Dit is een geautomatiseerd bericht*");
      body.append("\n\n*English*");
      body.append("\n\nDear,");
      body.append("\n\nWe have received your file belonging to media item titled '")
          .append(mediaTitle)
          .append("'. ");
      body.append("In about 1 hour, you can find your submission at: ");
      body.append("http://").append(host).append("/media/").append(node.getNumber());
      body.append("\n\nKind regards,");
      body.append("\n\n").append(host);

      body.append("\n\n\n*Nederlands*");
      body.append("\n\nBeste,");
      body.append("\n\nWe hebben je bestand voor het media item met de titel '")
          .append(mediaTitle)
          .append("' ontvangen. ");
      body.append("Je kunt je bijdrage hier over circa een uur terugvinden: ");
      body.append("http://").append(host).append("/media/").append(node.getNumber());
      body.append("\n\nMet vriendelijke groet,");
      body.append("\n\n").append(host);

      message.setValue("from", from);
      message.setValue("to", email);
      message.setValue("subject", "Download complete / Download voltooid");
      message.setValue("body", body.toString());
      message.commit();

      Function mail = message.getFunction("mail");
      Parameters mail_params = mail.createParameters();
      mail_params.set("type", "oneshot");
      mail.getFunctionValue(mail_params);

      if (log.isDebugEnabled()) {
        log.debug("Message download ready send to: " + email);
      }
      send = true;
    } else {
      log.warn("Can not send message - no emailbuilder installed.");
    }

    return send;
  }