@Test @FixFor( "MODE-1361" ) public void shouldGenerateCorrectOutputNodePathForCapturingGroup() throws Exception { EditableDocument doc = Schematic.newDocument(); addSequencer(doc, "seq1", TestSequencersHolder.DefaultSequencer.class.getName(), "default://(*.xml)/jcr:content[@jcr:data] => /output/$1"); startRepositoryWithConfiguration(doc); createNodeWithContentFromFile("cars.xml", "cars.xml"); Node outputNode = getOutputNode("/output/cars.xml"); assertNotNull(outputNode); assertNotNull(outputNode.getNode(TestSequencersHolder.DERIVED_NODE_NAME)); } }
/** * Sequencer path expressions are matching expressions, and therefore we cannot verify that they actually represent paths. So, * even though this is an valid path expression, it won't match any real paths. * * @throws Exception */ @Test public void shouldCreateStartRepositoryWithValidButUnusableSequencerPathExpression() throws Exception { EditableDocument doc = Schematic.newDocument(); addSequencer(doc, "seq1", TestSequencersHolder.DefaultSequencer.class.getName(), "## valid but unusable"); startRepositoryWithConfiguration(doc); }
@Test @FixFor( "MODE-1361" ) public void shouldSequenceWithCriteriaAndRegexInputPath() throws Exception { EditableDocument doc = Schematic.newDocument(); addSequencer(doc, "seq1", TestSequencersHolder.DefaultSequencer.class.getName(), "default://(*.foo)[bar/@baz] => /output"); startRepositoryWithConfiguration(doc); Node foo = session.getRootNode().addNode("foo.foo"); Node bar = foo.addNode("bar"); bar.setProperty("baz", "value of baz"); session.save(); Node outputNode = getOutputNode("/output/foo.foo"); assertNotNull(outputNode); assertNotNull(outputNode.getNode(TestSequencersHolder.DERIVED_NODE_NAME)); }
@Test public void shouldNotWreakHavocIfSequencerFails() throws Exception { EditableDocument doc = Schematic.newDocument(); addSequencer(doc, "seq1", TestSequencersHolder.FaultyDuringExecute.class.getName(), "/foo[@bar] => /output"); startRepositoryWithConfiguration(doc); // Now use a session to add a '/foo' node with a 'bar' property ... Node foo = session.getRootNode().addNode("foo"); foo.setProperty("bar", "value of bar"); foo.setProperty("baz", "value of baz"); session.save(); expectSequencingFailure(foo); // Now verify that there is NO output node, since the sequencer should have failed ... assertThat(session.getRootNode().hasNode("output/foo"), is(false)); }
@Override protected void startRepositoryWithConfiguration( Document doc ) throws Exception { stopRepository(); RepositoryConfiguration config = new RepositoryConfiguration(doc, REPO_NAME).with(new TestingEnvironment()); repository = new JcrRepository(config); repository.start(); session = repository.login(); rootNode = session.getRootNode(); addSequencingListeners(session); }
@Test public void shouldSupportVariousPropertyTypes() throws Exception { startRepositoryWithConfigurationFrom("config/repo-config-property-types.json"); session.getRootNode().addNode("shouldTriggerSequencer"); session.save(); assertNotNull(getOutputNode("/shouldTriggerSequencer/" + TestSequencersHolder.DERIVED_NODE_NAME)); }
@Override protected void startRepositoryWithConfiguration( String configContent ) throws Exception { Document doc = Json.read(configContent); startRepositoryWithConfiguration(doc); }
@Test public void shouldAllowSequencerToBeConfiguredWithOnlyInputPath() throws Exception { EditableDocument doc = Schematic.newDocument(); addSequencer(doc, "seq1", TestSequencersHolder.DefaultSequencer.class.getName(), "/foo[@bar]"); startRepositoryWithConfiguration(doc); // Now use a session to add a '/foo' node with a 'bar' property ... Node foo = session.getRootNode().addNode("foo"); foo.setProperty("bar", "value of bar"); foo.setProperty("baz", "value of baz"); session.save(); // Now verify that the test sequencer created a node ... Node derivedNode = getOutputNode("/foo/" + TestSequencersHolder.DERIVED_NODE_NAME); assertNotNull(derivedNode); assertThat(derivedNode.getParent(), is(foo)); }
@Override protected void startRepositoryWithConfiguration( InputStream configInputStream ) throws Exception { stopRepository(); RepositoryConfiguration config = RepositoryConfiguration.read(configInputStream, REPO_NAME).with(new TestingEnvironment()); Problems problems = config.validate(); if (problems.hasProblems()) { System.out.println(problems); fail("Problems encountered during repository startup: " + problems); } repository = new JcrRepository(config); repository.start(); session = repository.login(); rootNode = session.getRootNode(); addSequencingListeners(session); }
@Test public void shouldRemoveSequencerIfItCrashesDuringInitialize() throws Exception { EditableDocument doc = Schematic.newDocument(); addSequencer(doc, "seq1", TestSequencersHolder.FaultyDuringInitialize.class.getName(), "/foo[@bar] => /output"); startRepositoryWithConfiguration(doc); Node foo = session.getRootNode().addNode("foo"); foo.setProperty("bar", "value of bar"); session.save(); Thread.sleep(100L); assertEquals(0, TestSequencersHolder.FaultyDuringInitialize.EXECUTE_CALL_COUNTER.get()); }
@Test public void shouldStartRepositoryWithNoSequencers() throws Exception { startRepositoryWithConfiguration("{}"); }
@Test public void shouldStartRepositoryWithOneSequencer() throws Exception { EditableDocument doc = Schematic.newDocument(); addSequencer(doc, "seq1", TestSequencersHolder.DefaultSequencer.class.getName(), "/foo[@bar] => /output"); startRepositoryWithConfiguration(doc); // Now use a session to add a '/foo' node with a 'bar' property ... Node foo = session.getRootNode().addNode("foo"); foo.setProperty("bar", "value of bar"); foo.setProperty("baz", "value of baz"); session.save(); // Now verify that the test sequencer created a node ... Node fooOutput = getOutputNode("/output/foo"); assertThat(fooOutput, is(notNullValue())); Node derivedNode = session.getNode("/output/foo/" + TestSequencersHolder.DERIVED_NODE_NAME); assertThat(derivedNode, is(notNullValue())); }