This repository has been archived by the owner on Jun 2, 2020. It is now read-only.
/
DeleteNodeTest.java
154 lines (140 loc) · 4.65 KB
/
DeleteNodeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* Copyright (c) 2002-2012 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.geoff.test;
import org.junit.Before;
import org.junit.Test;
import org.neo4j.geoff.Geoff;
import org.neo4j.geoff.Rule;
import org.neo4j.geoff.store.NodeToken;
import org.neo4j.geoff.store.Token;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.test.ImpermanentGraphDatabase;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
public class DeleteNodeTest {
private ImpermanentGraphDatabase db;
@Before
public void setUp() throws Exception {
db = new ImpermanentGraphDatabase();
}
@Test
public void testNodeExclusionRule() throws Exception {
String source = "!(A)";
Rule rule = Rule.from(source);
assertNotNull(rule);
assertEquals("!N", rule.getDescriptor().getPattern());
assertTrue(rule.getDescriptor().getToken(1) instanceof NodeToken);
NodeToken token = (NodeToken) rule.getDescriptor().getToken(1);
assertEquals(Token.Type.NODE, token.getTokenType());
assertTrue(token.hasName());
assertEquals("A", token.getName());
}
@Test
public void canDeleteNode() throws Exception {
// perform call to add and remove node
String source =
"(A) {\"name\": \"Alice\"}\n" +
"!(A)\n" +
"";
Map<String, PropertyContainer> out = Geoff.loadIntoNeo4j(new StringReader(source), db, null);
// check results
assertNotNull(out);
assertEquals(0, out.size());
}
@Test
public void canRemoveAllPropertiesFromNode() throws Exception {
String source =
"(A) {\"name\": \"Alice\", \"age\": 900}\n" +
"!(A) {}\n" +
"";
Map<String, PropertyContainer> out = Geoff.loadIntoNeo4j(new StringReader(source), db, null);
// check results
assertNotNull(out);
Node a = (Node) out.get("(A)");
for (String key : a.getPropertyKeys()) {
assertFalse(true);
}
assertEquals(1, out.size());
}
@Test
public void canRemoveNamedPropertiesFromNode() throws Exception {
String source =
"(A) {\"name\": \"Alice\", \"age\": 900}\n" +
"!(A) {\"name\": null}\n" +
"";
Map<String, PropertyContainer> out = Geoff.loadIntoNeo4j(new StringReader(source), db, null);
// check results
assertNotNull(out);
Node a = (Node) out.get("(A)");
for (String key : a.getPropertyKeys()) {
assertFalse("name".equals(key));
}
assertEquals(1, out.size());
}
@Test
public void canRemoveMatchingPropertiesFromNode() throws Exception {
String source =
"(A) {\"name\": \"Alice\", \"age\": 900}\n" +
"!(A) {\"name\": \"Alice\"}\n" +
"";
Map<String, PropertyContainer> out = Geoff.loadIntoNeo4j(new StringReader(source), db, null);
// check results
assertNotNull(out);
Node a = (Node) out.get("(A)");
for (String key : a.getPropertyKeys()) {
assertFalse("name".equals(key));
}
assertEquals(1, out.size());
}
@Test
public void willNotRemoveNonMatchingPropertiesFromNode() throws Exception {
String source =
"(A) {\"name\": \"Alice\", \"age\": 900}\n" +
"!(A) {\"name\": \"Ada\"}\n" +
"";
Map<String, PropertyContainer> out = Geoff.loadIntoNeo4j(new StringReader(source), db, null);
// check results
assertNotNull(out);
Node a = (Node) out.get("(A)");
assertTrue(a.hasProperty("name"));
assertEquals(1, out.size());
}
@Test
public void testLoadingNodeInclusionRuleWithLoadParameter() throws Exception {
// perform first call to inject node
String source = "(A) {\"name\": \"Alice\"}";
Map<String, PropertyContainer> out = Geoff.loadIntoNeo4j(new StringReader(source), db, null);
assertNotNull(out);
// build params for second call from output of first
Node node = (Node) out.get("(A)");
assertNotNull(node);
Map<String, PropertyContainer> params = new HashMap<String, PropertyContainer>(1);
params.put("A", node);
// make second call to remove node
source = "!(A)";
out = Geoff.loadIntoNeo4j(new StringReader(source), db, params);
// check results
assertNotNull(out);
assertEquals(0, out.size());
}
}