@Test
 @Transactional
 public void testCreateNodeTypeWithProperties() throws Exception {
   Node person = neo4jTemplate.createNodeAs(Node.class, map("name", "name"));
   assertNotNull("created node", person);
   assertEquals("property created", "name", person.getProperty("name"));
 }
 @Test
 public void graphWithOneNodeAndOneNeighbourReturnsNodeAndNeighbour() throws Exception {
   Node node = new Node("1");
   node.addNeighbour(new Node("2"));
   graph.add(node);
   assertEquals("1 2\n", serializeGraph());
 }
Exemple #3
0
 SortBySiblingBlock(Node def) throws RuleBaseException {
   super(def);
   before = def.query().exists("@before");
   String attrName = before ? "@before" : "@after";
   if (!"sibling".equals(def.query().single(attrName).value()))
     throw new RuleBaseException("sort block " + attrName + " must have value 'sibling'");
 }
Exemple #4
0
 @Test(expected = TransformException.class)
 public void resolveOrderBadQuery() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort as='corresponding'>*</sort>");
   Node uc1 = content.query().single("/id('uc1')").node();
   setModBuilderCustomScope(uc1.query());
   block.resolveOrder(modBuilder, uc1);
 }
Exemple #5
0
 private void assertNotContainsNodes(View view, Node... slaves) {
     for (Node slave: slaves) {
         assertFalse(
                 "Filtered executors for " + view.getDisplayName() + " should not contain " + slave.getDisplayName(),
                 view.getComputers().contains(slave.toComputer())
         );
     }
 }
Exemple #6
0
 @Test(expected = TransformException.class)
 public void resolveOrderNotSibling() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort before='sibling'>.//uml:operation</sort>");
   Node cname = content.query().single("/id('cname')").node();
   Node uc1 = content.query().single("/id('uc1')").node();
   setModBuilderCustomScope(uc1.query());
   block.resolveOrder(modBuilder, cname);
 }
Exemple #7
0
 @Test
 public void resolveOrder() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort by='ascending'>@name</sort>");
   Node m1 = content.query().single("/id('m1')").node();
   setModBuilderCustomScope(m1.query());
   supplement();
   block.resolveOrder(modBuilder, m1);
   checkSupplement("<sort-value refid='m1'>start</sort-value>");
 }
 @Test(expected = org.neo4j.graphdb.NotFoundException.class)
 public void testDeleteNode() {
   final Transaction tx = restAPI.beginTx();
   Node n1 = restAPI.createNode(map("name", "node1"));
   n1.delete();
   Node n2 = restAPI.createNode(map("name", "node2"));
   tx.success();
   tx.finish();
   loadRealNode(n1);
 }
Exemple #9
0
 @Test
 public void resolveOrderEmpty() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort before='sibling'>()</sort>");
   Node cname = content.query().single("/id('cname')").node();
   Node uc1 = content.query().single("/id('uc1')").node();
   setModBuilderCustomScope(uc1.query());
   supplement();
   block.resolveOrder(modBuilder, cname);
   checkSupplement("<sort-siblings run-length='0'/>");
 }
Exemple #10
0
 public void resolve(Mod.Builder modBuilder) throws TransformException {
   for (Node node :
       modBuilder.dependOnNearest(NodeTarget.class).unverified().get().targets().nodes()) {
     modBuilder.dependOn(node.document());
     modBuilder.order(node);
     resolveOrder(modBuilder, node);
   }
   modBuilder.dependOn(requiredVariables);
   modBuilder.commit();
 }
 @Test
 public void graphWithTwoNodesAndTwoNeighbours() throws Exception {
   Node node = new Node("1");
   node.addNeighbour(new Node("3"));
   Node node2 = new Node("2");
   node2.addNeighbour(new Node("4"));
   graph.add(node);
   graph.add(node2);
   assertEquals("1 3\n2 4\n", serializeGraph());
 }
Exemple #12
0
 @Test
 public void resolveOrder1() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort after='sibling'>uml:name</sort>");
   Node comp1 = content.query().single("/id('comp1')").node();
   Node uc1 = content.query().single("/id('uc1')").node();
   setModBuilderCustomScope(uc1.query());
   reference(content.query().single("/id('cname')").node());
   supplement();
   block.resolveOrder(modBuilder, comp1);
   checkSupplement("<sort-siblings run-length='1'/>");
 }
Exemple #13
0
 @Test
 public void resolveOrder() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort as='corresponding'>$source</sort>");
   Node um1 = content.query().single("/id('um1')").node();
   Node m1 = content.query().single("/id('m1')").node();
   setModBuilderCustomScope(um1.query().let("$source", m1));
   reference(m1);
   supplement();
   block.resolveOrder(modBuilder, um1);
   checkSupplement("<sort-proxy position='1'/>");
 }
  @Test(expected = RestResultException.class)
  public void testFailingDoubleDelete() throws Exception {
    final Transaction tx = restAPI.beginTx();

    Node n1 = restAPI.createNode(map());
    n1.delete();
    n1.delete();

    tx.success();
    tx.finish();
  }
 @FixFor("MODE-1254")
 @Test
 public void shouldNotIncludeBinaryContentsInToString() throws Exception {
   altima = cache.findJcrNode(null, path("/Cars/Hybrid/Nissan Altima"));
   Node node = rootNode.addNode("nodeWithBinaryProperty", "nt:unstructured");
   String value = "This is the string value";
   Binary binaryValue =
       cache.session().getValueFactory().createBinary(new ByteArrayInputStream(value.getBytes()));
   node.setProperty("binProp", binaryValue);
   String toString = node.toString();
   assertThat(toString.indexOf("**binary-value") > 0, is(true));
 }
Exemple #16
0
  /**
   * The <body/> element of every client request MUST possess a sequential request ID encapsulated
   * via the 'rid' attribute.
   *
   * @param node node to validate
   * @param previous previous node
   */
  private void assertRequestIDSequential(final Node node, final Node previous) {
    String ridStr = node.getBody().getAttribute(Attributes.RID);
    assertNotNull("Request ID attribute not present", ridStr);

    long rid = Long.parseLong(ridStr);
    if (previous != null) {
      String prevRidStr = previous.getBody().getAttribute(Attributes.RID);
      assertNotNull("Previous request ID attribute not present", prevRidStr);
      long prevRid = Long.parseLong(prevRidStr);
      assertEquals("Request ID is not sequential", prevRid + 1, rid);
    }
  }
  @Test
  public void test() {
    Node root = new Node(5, null, null);
    IndexTree myTree = new IndexTree(root);
    myTree.addNode(new Node(4, null, null));
    myTree.addNode(new Node(6, null, null));

    Node elem = myTree.find(3);
    assertEquals(4, elem.getKey());
    assertEquals(myTree.noOfElements, 3);
    assertEquals(elem.cost, 2);
  }
Exemple #18
0
 @Override
 public void restore() throws TransformException {
   ItemList targets = mod.nearest(NodeTarget.class).targets();
   values = new ArrayList<Pair<String, Item>>(targets.size());
   for (Node node : targets.nodes()) {
     ItemList items = query.runOn(mod.scope(node.query()));
     if (items.size() != 1)
       throw new TransformException(
           "sort by value query did not select exactly one item: " + items);
     values.add(Pair.of(node.query().single("@xml:id").value(), items.get(0).toAtomicItem()));
   }
 }
Exemple #19
0
  @Test
  public void getNodes_by_state() {
    Node n0 = Nodes.addNode(new Node("n0"));
    Node n1 = Nodes.addNode(new Node("n1", Node.Type.DATANODE));
    Node n2 = Nodes.addNode(new Node("n2", Node.Type.DATANODE));

    n1.state = Node.State.RUNNING;
    n2.state = Node.State.RUNNING;

    assertEquals(Arrays.asList(n0), Nodes.getNodes(Node.State.IDLE));
    assertEquals(Arrays.asList(n1, n2), Nodes.getNodes(Node.State.RUNNING));
  }
Exemple #20
0
 @AllowAttributes({"priority", "by", "as", "before", "after"})
 @Override
 public Block define(Node def) throws RuleBaseException {
   int numDirectives = def.query().single("count(@by | @as | @before | @after)").intValue();
   if (numDirectives > 1)
     throw new RuleBaseException(
         "sort block specified with more than one of @by, @as, @before and @after");
   if (numDirectives < 1)
     throw new RuleBaseException("sort block specified without any @by, @as, @before or @after");
   if (def.query().exists("@by")) return new SortByValueBlock(def);
   else if (def.query().exists("@as")) return new SortByProxyBlock(def);
   else return new SortBySiblingBlock(def);
 }
 @Test
 public void testCreateNode() {
   final Transaction tx = restAPI.beginTx();
   Node n1 = restAPI.createNode(map("name", "node1"));
   Node n2 = restAPI.createNode(map("name", "node2"));
   final int count = countExistingNodes();
   assertEquals("only reference node", 1, count);
   tx.success();
   tx.finish();
   assertEquals("node1", n1.getProperty("name"));
   assertEquals("node1", loadRealNode(n1).getProperty("name"));
   assertEquals("node2", n2.getProperty("name"));
 }
  @Test
  public void testCompareWithRemovedItem() throws Exception {
    final Collection<String> working = new LinkedList<String>();
    final Collection<String> base = new LinkedList<String>(Arrays.asList("foo"));

    final CollectionNode node = differ.compare(working, base);

    assertThat(node.hasChanges(), is(true));

    final Node child =
        node.getChild(PropertyPath.createBuilder().withRoot().withCollectionItem("foo").build());
    assertThat(child.getState(), is(Node.State.REMOVED));
  }
Exemple #23
0
 @Test
 public void testTTL() throws Exception {
   Config config = new Config();
   FactoryImpl mockFactory = mock(FactoryImpl.class);
   // we mocked the node
   // do not forget to shutdown the connectionManager
   // so that server socket can be released.
   Node node = new Node(mockFactory, config);
   node.serviceThread = Thread.currentThread();
   CMap cmap = new CMap(node.concurrentMapManager, "c:myMap");
   Object key = "1";
   Object value = "istanbul";
   Data dKey = toData(key);
   Data dValue = toData(value);
   Request reqPut = newPutRequest(dKey, dValue);
   reqPut.ttl = 3000;
   cmap.put(reqPut);
   assertTrue(cmap.mapRecords.containsKey(toData(key)));
   Data actualValue = cmap.get(newGetRequest(dKey));
   assertThat(toObject(actualValue), equalTo(value));
   assertEquals(1, cmap.mapRecords.size());
   Record record = cmap.getRecord(dKey);
   assertNotNull(record);
   assertTrue(record.isActive());
   assertTrue(record.isValid());
   assertEquals(1, cmap.size());
   assertNotNull(cmap.get(newGetRequest(dKey)));
   assertEquals(dValue, cmap.get(newGetRequest(dKey)));
   assertTrue(record.getRemainingTTL() > 1000);
   Thread.sleep(1000);
   assertTrue(record.getRemainingTTL() < 2100);
   cmap.put(newPutRequest(dKey, dValue));
   assertTrue(record.getRemainingTTL() > 2001);
   assertTrue(record.isActive());
   assertTrue(record.isValid());
   Thread.sleep(1000);
   assertTrue(record.getRemainingTTL() < 2100);
   cmap.put(newPutRequest(dKey, dValue));
   assertTrue(record.getRemainingTTL() > 2001);
   assertTrue(record.isActive());
   assertTrue(record.isValid());
   Thread.sleep(5000);
   assertEquals(0, cmap.size());
   assertTrue(cmap.evict(newEvictRequest(dKey)));
   assertTrue(cmap.shouldPurgeRecord(record, System.currentTimeMillis() + 10000));
   cmap.removeAndPurgeRecord(record);
   assertEquals(0, cmap.mapRecords.size());
   assertEquals(0, cmap.size());
   assertEquals(0, cmap.mapIndexService.size());
   node.connectionManager.shutdown();
 }
 @Test
 public void testDeleteRelationship() {
   Transaction tx = restAPI.beginTx();
   Node n1 = restAPI.createNode(map("name", "newnode1"));
   Node n2 = restAPI.createNode(map("name", "newnode2"));
   Relationship rel = restAPI.createRelationship(n1, n2, Type.TEST, map("name", "rel"));
   rel.delete();
   tx.success();
   tx.finish();
   Relationship foundRelationship =
       TestHelper.firstRelationshipBetween(
           n1.getRelationships(Type.TEST, Direction.OUTGOING), n1, n2);
   Assert.assertNull("found relationship", foundRelationship);
 }
Exemple #25
0
 @Override
 void resolveOrder(Mod.Builder modBuilder, Node node) throws TransformException {
   ItemList siblings = query.runOn(modBuilder.customScope(node.query().single("..").query()));
   for (Node sibling : siblings.nodes()) {
     if (!node.query().single(".. is $_1/..", sibling).booleanValue())
       throw new TransformException("query selected non-sibling node: " + sibling);
     modBuilder.reference(sibling);
   }
   modBuilder
       .supplement()
       .elem("sort-siblings")
       .attr("run-length", siblings.size())
       .end("sort-siblings");
 }
Exemple #26
0
 @SuppressWarnings("unchecked")
 @Test(expected = TransformException.class)
 public void verifyNotSibling() throws RuleBaseException, TransformException {
   Node uc1 = content.query().single("/id('uc1')").node();
   Node comp1 = content.query().single("/id('comp1')").node();
   Node um1 = content.query().single("/id('um1')").node();
   setModScope(uc1.query());
   SortBySiblingBlock block = define("<sort before='sibling'>.//uml:method</sort>");
   SortBySiblingBlock.SortBySiblingSeg seg =
       (SortBySiblingBlock.SortBySiblingSeg) block.createSeg(mod);
   seg.siblingsByTarget =
       Arrays.<Pair<Node, List<Node>>>asList(new Pair[] {Pair.of(comp1, Arrays.asList(um1))});
   seg.verify();
 }
  @Test
  public void testCreateRelationshipToNodeOutsideofBatch() throws Exception {
    final Node node1 = restAPI.createNode(map());
    final Transaction tx = restAPI.beginTx();

    Node node2 = restAPI.createNode(map());
    final Relationship relationship =
        node1.createRelationshipTo(node2, DynamicRelationshipType.withName("foo"));

    tx.success();
    tx.finish();
    assertEquals("foo", relationship.getType().name());
    assertEquals(
        "foo", getGraphDatabase().getRelationshipById(relationship.getId()).getType().name());
  }
Exemple #28
0
 /**
  * The <body/> element of the first request SHOULD possess the following attributes (they SHOULD
  * NOT be included in any other requests except as specified under Adding Streams To A Session):
  * "to", "xml:lang", "ver", "wait", "hold".
  *
  * @param message number (zero-based)
  * @param request request message
  * @param previous previous request message
  */
 private void validateRequestHeaders(final int idx, final Node request, final Node previous) {
   AbstractBody body = request.getBody();
   if (previous == null) {
     // session creation request
     assertNotNull(
         "to attribute not present in request #" + idx, body.getAttribute(Attributes.TO));
     assertNotNull(
         "xml:lang attribute not present in request #" + idx,
         body.getAttribute(Attributes.XML_LANG));
     assertNotNull(
         "ver attribute not present in request #" + idx, body.getAttribute(Attributes.VER));
     assertNotNull(
         "wait attribute not present in request #" + idx, body.getAttribute(Attributes.WAIT));
     assertNotNull(
         "hold attribute not present in request #" + idx, body.getAttribute(Attributes.HOLD));
   } else {
     // subsequent request
     assertNull("to attribute was present in request #" + idx, body.getAttribute(Attributes.TO));
     assertNull(
         "xml:lang attribute was present in request #" + idx,
         body.getAttribute(Attributes.XML_LANG));
     assertNull("ver attribute was present in request #" + idx, body.getAttribute(Attributes.VER));
     assertNull(
         "wait attribute was present in request #" + idx, body.getAttribute(Attributes.WAIT));
     assertNull(
         "hold attribute was present in request #" + idx, body.getAttribute(Attributes.HOLD));
   }
 }
Exemple #29
0
 /**
  * If the client will be including 'ack' attributes on requests during a session, then it MUST
  * include an 'ack' attribute (set to '1') in its session creation request, and set the 'ack'
  * attribute of requests throughout the session.
  *
  * @param idx message number (zero-based)
  * @param first first message sent
  * @param request message to validate
  */
 private void validateSubsequestRequestAck(final int idx, final Node first, final Node request) {
   if (request == first) {
     // Nothing to check on first request
     return;
   }
   String ack = first.getBody().getAttribute(Attributes.ACK);
   if (ack == null) {
     String subAck = request.getBody().getAttribute(Attributes.ACK);
     assertNull(
         "subsequent request #"
             + idx
             + " can only use acks if "
             + "advertized in session creation request",
         subAck);
   }
 }
Exemple #30
0
 @Override
 void resolveOrder(Mod.Builder modBuilder, Node node) throws TransformException {
   ItemList items = query.runOn(modBuilder.customScope(node.query()));
   if (items.size() != 1)
     throw new TransformException(
         "sort by value must select one value per target, but instead selected "
             + items.size()
             + ": "
             + items);
   modBuilder
       .supplement()
       .elem("sort-value")
       .attr("refid", node.query().single("@xml:id").value())
       .text(items.get(0).value())
       .end("sort-value");
 }