use of javax.jcr.Node in project camel by apache.
the class JcrConsumerTest method testJcrConsumer.
@Test
public void testJcrConsumer() throws Exception {
// start consumer thread first
JcrConsumerThread consumerThread = new JcrConsumerThread();
consumerThread.start();
// wait until the consumer thread has tried to receive event at least once
while (consumerThread.getReceiveTrialTimes() < 1) {
Thread.sleep(10L);
}
// now create a node under the specified event node path
Session session = openSession();
try {
Node folderNode = session.getRootNode();
for (String folderNodeName : absPath.split("\\/")) {
if (!"".equals(folderNodeName)) {
if (folderNode.hasNode(folderNodeName)) {
folderNode.getNode(folderNodeName).remove();
}
folderNode = folderNode.addNode(folderNodeName, "nt:unstructured");
}
}
folderNode.addNode("node", "nt:unstructured");
session.save();
} finally {
if (session != null && session.isLive()) {
session.logout();
}
}
// wait until the consumer thread captures an event
consumerThread.join();
Exchange exchange = consumerThread.getExchange();
assertNotNull(exchange);
Message message = exchange.getIn();
assertNotNull(message);
assertTrue(message instanceof JcrMessage);
EventIterator eventIterator = ((JcrMessage) message).getEventIterator();
assertNotNull(eventIterator);
assertEquals(1, eventIterator.getSize());
List<?> eventList = message.getBody(List.class);
assertEquals(1, eventList.size());
Event event = (Event) eventList.get(0);
assertEquals(Event.NODE_ADDED, event.getType());
assertNotNull(event.getPath());
assertTrue(event.getPath().startsWith(absPath));
}
use of javax.jcr.Node in project camel by apache.
the class JcrGetNodeByIdTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
Session session = openSession();
Node node = session.getRootNode().addNode("home").addNode("test");
node.setProperty("content.approved", APPROVED);
node.setProperty("my.contents.property", CONTENT);
ValueFactory valFact = session.getValueFactory();
Value[] vals = new Value[] { valFact.createValue("value-1"), valFact.createValue("value-2") };
node.setProperty("my.multi.valued", vals);
identifier = node.getIdentifier();
session.save();
session.logout();
}
use of javax.jcr.Node in project camel by apache.
the class JcrNodePathCreationTest method testJcrNodePathCreation.
@Test
public void testJcrNodePathCreation() throws Exception {
Exchange exchange = createExchangeWithBody("<body/>");
Exchange out = template.send("direct:a", exchange);
assertNotNull(out);
String uuid = out.getOut().getBody(String.class);
assertNotNull("Out body was null; expected JCR node UUID", uuid);
Session session = openSession();
try {
Node node = session.getNodeByIdentifier(uuid);
assertNotNull(node);
assertEquals("/home/test/node/with/path", node.getPath());
} finally {
if (session != null && session.isLive()) {
session.logout();
}
}
}
use of javax.jcr.Node in project camel by apache.
the class JcrProducerDifferentWorkspaceTest method testJcrProducer.
@Test
public void testJcrProducer() throws Exception {
Exchange exchange = createExchangeWithBody("<hello>world!</hello>");
Exchange out = template.send("direct:a", exchange);
assertNotNull(out);
String uuid = out.getOut().getBody(String.class);
Session session = openSession(CUSTOM_WORKSPACE_NAME);
try {
Node node = session.getNodeByIdentifier(uuid);
Workspace workspace = session.getWorkspace();
assertEquals(CUSTOM_WORKSPACE_NAME, workspace.getName());
assertNotNull(node);
assertEquals("/home/test/node", node.getPath());
assertEquals("<hello>world!</hello>", node.getProperty("my.contents.property").getString());
} finally {
if (session != null && session.isLive()) {
session.logout();
}
}
}
use of javax.jcr.Node in project camel by apache.
the class JcrProducerTest method testNodeTypeIsSpecified.
@Test
public void testNodeTypeIsSpecified() throws Exception {
Exchange exchange = createExchangeWithBody("Test");
//there is no definition of such property in nt:resource
exchange.getIn().removeHeader("testClass");
exchange.getIn().setHeader(JcrConstants.JCR_NODE_NAME, "typedNode");
exchange.getIn().setHeader(JcrConstants.JCR_NODE_TYPE, "nt:folder");
Exchange out = template.send("direct:a", exchange);
assertNotNull(out);
String uuid = out.getOut().getBody(String.class);
Session session = openSession();
try {
Node node = session.getNodeByIdentifier(uuid);
assertNotNull(node);
assertEquals("/home/test/typedNode", node.getPath());
assertEquals("nt:folder", node.getPrimaryNodeType().getName());
} finally {
if (session != null && session.isLive()) {
session.logout();
}
}
}
Aggregations