@Test @FixFor("MODE-1977") public void shouldNotAllowMoveIfSourceOrTargetIsProjection() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "fed2"); try { session.move("/testRoot/fed2/federated3", "/testRoot/fed1"); fail("Should not allow move if target is projection"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } try { session.move("/testRoot/fed2", "/testRoot/fed1"); fail("Should not allow move if source is projection"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Test public void removingInternalNodeShouldNotRemoveExternalNodes() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "federated2"); Node internalNode1 = testRoot.addNode("internalNode1"); session.save(); federationManager.createProjection( "/testRoot/internalNode1", SOURCE_NAME, MockConnector.DOC2_LOCATION, "federated2"); // remove the federated node directly assertNodeFound("/testRoot/internalNode1/federated2/federated3"); internalNode1.remove(); session.save(); // check external nodes are still there assertNodeFound("/testRoot/federated2/federated3"); testRoot.addNode("internalNode2").addNode("internalNode2_1"); session.save(); federationManager.createProjection( "/testRoot/internalNode2/internalNode2_1", SOURCE_NAME, MockConnector.DOC2_LOCATION, "federated2"); // remove an ancestor of the federated node assertNodeFound("/testRoot/internalNode2/internalNode2_1/federated2/federated3"); ((Node) session.getNode("/testRoot/internalNode2")).remove(); session.save(); // check external nodes are still there assertNodeFound("/testRoot/federated2/federated3"); }
@Test public void shouldCreateProjectionWithAlias() throws Exception { // add an internal node testRoot.addNode("node1"); session.save(); // link the first external document federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); assertEquals(2, testRoot.getNodes().getSize()); Node doc1Federated = assertNodeFound("/testRoot/federated1"); assertEquals(testRoot.getIdentifier(), doc1Federated.getParent().getIdentifier()); assertEquals("a string", doc1Federated.getProperty("federated1_prop1").getString()); assertEquals(12, doc1Federated.getProperty("federated1_prop2").getLong()); // link a second external document with a sub-child federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "federated2"); assertEquals(3, testRoot.getNodes().getSize()); Node doc2Federated = assertNodeFound("/testRoot/federated2"); assertEquals(testRoot.getIdentifier(), doc2Federated.getParent().getIdentifier()); assertEquals("another string", doc2Federated.getProperty("federated2_prop1").getString()); assertEquals(false, doc2Federated.getProperty("federated2_prop2").getBoolean()); Node doc2FederatedChild = assertNodeFound("/testRoot/federated2/federated3"); assertEquals( "yet another string", doc2FederatedChild.getProperty("federated3_prop1").getString()); }
@Test public void removeProjectionViaFederationManagerShouldNotDeleteExternalNode() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "projection1"); federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "projection2"); federationManager.removeProjection("/testRoot/projection1"); assertNodeFound("/testRoot/projection2/federated3"); }
@Test @FixFor("MODE-1976") public void shouldAllowCopyWithinSameSource() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "fed2"); jcrSession().getWorkspace().copy("/testRoot/fed1", "/testRoot/fed2/fed1"); assertNodeFound("/testRoot/fed2/fed1"); assertNodeFound("/testRoot/fed2/federated3"); }
@Test public void removingProjectionViaNodeRemoveShouldDeleteExternalNodes() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "projection1"); federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "projection2"); Node projection1 = assertNodeFound("/testRoot/projection1/federated3"); assertNodeFound("/testRoot/projection2/federated3"); projection1.remove(); session.save(); assertNodeNotFound("/testRoot/projection2/federated3"); }
@Test public void shouldNotAllowInternalNodesAsReferrers() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); Node externalNode = doc1Federated.addNode("federated1_1", null); externalNode.addMixin("mix:referenceable"); session.save(); Value weakRef = session.getValueFactory().createValue(externalNode, true); testRoot.setProperty("weakRef", weakRef); try { session.save(); fail( "It should not be possible to create weak references from internal nodes to external nodes"); } catch (RepositoryException e) { assertTrue(e.getCause() instanceof ConnectorException); } Value strongRef = session.getValueFactory().createValue(externalNode, false); testRoot.setProperty("strongRef", strongRef); try { session.save(); fail( "It should not be possible to create strong references from internal nodes to external nodes"); } catch (RepositoryException e) { assertTrue(e.getCause() instanceof ConnectorException); } }
@Test @FixFor("MODE-2147") public void shouldNotAllowVersionableMixinOnExternalNodes() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "fed1"); Node projectionRoot = session.getNode("/testRoot/fed1"); try { projectionRoot.addMixin("mix:versionable"); fail("Should not allow versionable mixin on external nodes"); } catch (ConstraintViolationException e) { // expected } try { Node externalChild = projectionRoot.addNode("child"); externalChild.addMixin("mix:versionable"); session.save(); fail("Should not allow versionable mixin on external nodes"); } catch (ConstraintViolationException e) { // expected } Node externalChild = projectionRoot.addNode("child"); assertThat(externalChild, is(notNullValue())); session.save(); try { ((Node) session.getNode("/testRoot/child")).addMixin("mix:versionable"); fail("Should not allow versionable mixin on external nodes"); } catch (RepositoryException e) { // expected } }
@Test public void shouldUpdateExternalNodeChildren() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); doc1Federated.addNode("federated1_1", null); session.save(); String externalNodePath = "/testRoot/federated1/federated1_1"; assertExternalNodeHasChildren(externalNodePath); Node externalNode = session.getNode(externalNodePath); externalNode.addNode("child1"); externalNode.addNode("child2"); session.save(); assertExternalNodeHasChildren(externalNodePath, "child1", "child2"); externalNode = session.getNode(externalNodePath); externalNode.getNode("child1").remove(); externalNode.getNode("child2").remove(); externalNode.addNode("child3"); session.save(); assertExternalNodeHasChildren(externalNodePath, "child3"); }
@Test @FixFor("MODE-1976") public void shouldCopyFromFederatedSourceToNonFederatedTargetSameWs() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); Node federated1 = jcrSession().getNode("/testRoot/fed1").addNode("federated1"); federated1.setProperty("prop", "value"); jcrSession().getRootNode().addNode("testRoot2"); jcrSession().save(); jcrSession().getWorkspace().copy("/testRoot/fed1", "/testRoot2/fed1"); assertNodeFound("/testRoot2/fed1"); Node federated1Copy = assertNodeFound("/testRoot2/fed1/federated1"); federated1Copy.remove(); jcrSession().save(); assertNodeFound("/testRoot/fed1/federated1"); jcrSession().getRootNode().addNode("testRoot3"); jcrSession().save(); jcrSession().getWorkspace().copy("/testRoot/fed1/federated1", "/testRoot3"); federated1Copy = assertNodeFound("/testRoot3[2]"); assertNotNull(federated1Copy.getProperty("prop")); }
@Test public void shouldUpdateExternalNodeProperties() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); Node externalNode1 = doc1Federated.addNode("federated1_1", null); externalNode1.setProperty("prop1", "a value"); externalNode1.setProperty("prop2", "a value 2"); session.save(); externalNode1.setProperty("prop1", "edited value"); assertEquals("a value 2", externalNode1.getProperty("prop2").getString()); externalNode1.getProperty("prop2").remove(); externalNode1.setProperty("prop3", "a value 3"); session.save(); Node federated1_1 = doc1Federated.getNode("federated1_1"); assertEquals("edited value", federated1_1.getProperty("prop1").getString()); assertEquals("a value 3", federated1_1.getProperty("prop3").getString()); try { federated1_1.getProperty("prop2"); fail("Property was not removed from external node"); } catch (PathNotFoundException e) { // expected } }
@Test @FixFor("MODE-1977") public void shouldNotAllowMoveIfSourceIsFederatedAndTargetIsNot() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); ((Node) session.getRootNode()).addNode("testRoot2"); session.save(); try { session.move("/testRoot", "/testRoot2"); fail("Should not allow move is source is federated is target is not."); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } try { session.move("/testRoot/fed1", "/testRoot2"); fail("Should not allow move is source is federated is target is not."); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Test public void shouldNotIndexNotQueryableConnector() throws Exception { federationManager.createProjection( "/testRoot", "mock-source-non-queryable", MockConnector.DOC2_LOCATION, "federated2"); Workspace workspace = session.getWorkspace(); workspace.reindex(); QueryManager queryManager = workspace.getQueryManager(); Query query = queryManager.createQuery( "select * FROM [nt:base] WHERE [jcr:path] LIKE '/testRoot/federated2'", Query.JCR_SQL2); assertEquals(0, query.execute().getNodes().getSize()); query = queryManager.createQuery( "select * FROM [nt:base] WHERE [jcr:path] LIKE '/testRoot/federated2/federated3'", Query.JCR_SQL2); assertEquals(0, query.execute().getNodes().getSize()); Node externalNode = session.getNode("/testRoot/federated2/federated3"); externalNode.setProperty("test", "a value"); session.save(); query = queryManager.createQuery( "select * FROM [nt:base] as a WHERE a.test='a value'", Query.JCR_SQL2); assertEquals(0, query.execute().getNodes().getSize()); }
@Test @FixFor("MODE-1977") public void shouldNotAllowMoveIfSourceAndTargetBelongToDifferentSources() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); federationManager.createProjection( "/testRoot", "mock-source-non-queryable", MockConnector.DOC2_LOCATION, "fed2"); try { session.move("/testRoot/fed1", "/testRoot/fed2"); fail("Should not allow move if source and target don't belong to the same source"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Test @FixFor("MODE-1976") public void shouldNotCopyIfSourceAndTargetSourcesDoNotMatch() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); federationManager.createProjection( "/testRoot", "mock-source-non-queryable", MockConnector.DOC2_LOCATION, "fed2"); try { jcrSession().getWorkspace().copy("/testRoot/fed1", "/testRoot/fed2/fed1"); fail("Should not allow copy if source and target don't belong to the same source"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Test public void shouldRemoveProjectionViaFederationManager() throws Exception { testRoot.addNode("child1"); session.save(); federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "federated2"); federationManager.removeProjection("/testRoot/federated2"); assertNodeFound("/testRoot/federated1"); assertNodeFound("/testRoot/child1"); assertNodeNotFound("/testRoot/federated2"); federationManager.removeProjection("/testRoot/federated1"); assertNodeNotFound("/testRoot/federation1"); assertNodeFound("/testRoot/child1"); }
@Test(expected = RepositoryException.class) public void shouldNotAllowWritesIfReadonly() throws Exception { federationManager.createProjection( "/testRoot", "mock-source-readonly", MockConnector.DOC1_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); Node externalNode1 = doc1Federated.addNode("federated1_1", null); externalNode1.addNode("federated1_1_1", null); session.save(); }
@Test public void shouldCreateProjectionWithoutAlias() throws Exception { // link the first external document federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, null); assertEquals(1, testRoot.getNodes().getSize()); Node doc1Federated = assertNodeFound("/testRoot" + MockConnector.DOC1_LOCATION); assertEquals(testRoot.getIdentifier(), doc1Federated.getParent().getIdentifier()); assertEquals("a string", doc1Federated.getProperty("federated1_prop1").getString()); assertEquals(12, doc1Federated.getProperty("federated1_prop2").getLong()); }
@Test @FixFor("MODE-1977") public void shouldAllowMoveWithSameSource() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); ((Node) session.getNode("/testRoot/fed1")).addNode("federated1"); session.save(); assertNodeFound("/testRoot/fed1/federated1"); federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "fed2"); assertNodeFound("/testRoot/fed2/federated3"); session.move("/testRoot/fed1/federated1", "/testRoot/fed2/federated3"); session.save(); assertNodeFound("/testRoot/fed2/federated3[1]"); assertNodeFound("/testRoot/fed2/federated3[2]"); assertNodeNotFound("/testRoot/fed1/federated1"); }
@Test public void shouldValidatePermissionsForReadonlyProjections() throws Exception { federationManager.createProjection( "/testRoot", "mock-source-readonly", MockConnector.DOC1_LOCATION, "fed1"); federationManager.createProjection( "/testRoot", "mock-source-readonly", MockConnector.DOC2_LOCATION, "fed2"); assertPermission(true, "/testRoot", ModeShapePermissions.ADD_NODE); assertPermission(true, "/testRoot", ModeShapePermissions.ADD_NODE, ModeShapePermissions.READ); assertPermission(true, "/testRoot", ModeShapePermissions.READ); assertPermission(false, "/testRoot/fed1", ModeShapePermissions.ADD_NODE); assertPermission( false, "/testRoot/fed1", ModeShapePermissions.ADD_NODE, ModeShapePermissions.READ); assertPermission(true, "/testRoot/fed1", ModeShapePermissions.READ); assertPermission(true, "/testRoot/fed1", ModeShapePermissions.INDEX_WORKSPACE); assertPermission( true, "/testRoot/fed1", ModeShapePermissions.INDEX_WORKSPACE, ModeShapePermissions.READ); assertPermission(false, "/testRoot/fed2", ModeShapePermissions.ADD_NODE); assertPermission( false, "/testRoot/fed2", ModeShapePermissions.ADD_NODE, ModeShapePermissions.READ); assertPermission(true, "/testRoot/fed2", ModeShapePermissions.READ); assertPermission(true, "/testRoot/fed2", ModeShapePermissions.INDEX_WORKSPACE); assertPermission( true, "/testRoot/fed2", ModeShapePermissions.INDEX_WORKSPACE, ModeShapePermissions.READ); assertPermission(false, "/testRoot/fed2/federated3", ModeShapePermissions.ADD_NODE); assertPermission( false, "/testRoot/fed2/federated3", ModeShapePermissions.ADD_NODE, ModeShapePermissions.READ); assertPermission(true, "/testRoot/fed2/federated3", ModeShapePermissions.READ); assertPermission(true, "/testRoot/fed2/federated3", ModeShapePermissions.INDEX_WORKSPACE); assertPermission( true, "/testRoot/fed2/federated3", ModeShapePermissions.INDEX_WORKSPACE, ModeShapePermissions.READ); }
@Test @FixFor("MODE-1977") public void shouldAllowMoveIfSourceIsNotFederatedAndTargetIsNotFederated() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); ((Node) session.getRootNode()).addNode("testRoot2").addNode("a"); session.save(); session.move("/testRoot2", "/testRoot"); session.save(); assertNodeFound("/testRoot[1]/fed1"); assertNodeFound("/testRoot[2]/a"); }
@Test public void shouldRemoveExternalNode() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); doc1Federated.addNode("federated1_1", null); session.save(); Node externalNode = session.getNode("/testRoot/federated1/federated1_1"); externalNode.remove(); session.save(); assertNodeNotFound("/testRoot/federated1/federated1_1"); }
@Test public void shouldNavigateChildrenFromPagedConnector() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.PAGED_DOC_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); NodeIterator nodesIterator = doc1Federated.getNodes(); assertEquals(3, nodesIterator.getSize()); List<String> childrenNames = new ArrayList<String>(3); while (nodesIterator.hasNext()) { childrenNames.add(nodesIterator.nextNode().getName()); } assertEquals(Arrays.asList("federated4", "federated5", "federated6"), childrenNames); }
@BeforeClass public static void beforeAll() throws Exception { RepositoryConfiguration config = RepositoryConfiguration.read("config/repo-config-git-federation.json"); startRepository(config); // registerNodeTypes("cnd/flex.cnd"); Session session = getSession(); Node testRoot = session.getRootNode().addNode("repos"); session.save(); FederationManager fedMgr = session.getWorkspace().getFederationManager(); fedMgr.createProjection(testRoot.getPath(), "local-git-repo", "/", "git-modeshape"); }
@Test public void shouldNotAllowACLsOnExternalNodes() throws Exception { AccessControlManager acm = session.getAccessControlManager(); federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "fed1"); session.getNode("/testRoot/fed1"); AccessControlList acl = acl("/testRoot/fed1"); try { acm.setPolicy("/testRoot/fed1", acl); fail("Should not allow ACLs on external nodes"); } catch (RepositoryException e) { // expected } }
@Test @FixFor("MODE-1976") public void shouldCopyFromNonFederatedSourceToFederatedTargetSameWs() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); jcrSession().getNode("/testRoot/fed1").addNode("federated1"); jcrSession().getRootNode().addNode("testRoot2").addNode("nonFederated2"); jcrSession().save(); jcrSession().getWorkspace().copy("/testRoot2", "/testRoot/fed1/federated2"); assertNodeFound("/testRoot/fed1/federated2"); assertNodeFound("/testRoot/fed1/federated2/nonFederated2"); assertEquals(2, jcrSession().getNode("/testRoot/fed1").getNodes().getSize()); }
@Test public void shouldReorderExternalNodes() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); Node parent1 = doc1Federated.addNode("parent1", null); parent1.addNode("child1"); parent1.addNode("child2"); parent1.addNode("child3"); session.save(); assertExternalNodeHasChildren("/testRoot/federated1/parent1", "child1", "child2", "child3"); parent1.orderBefore("child1", "child2"); session.save(); assertExternalNodeHasChildren("/testRoot/federated1/parent1", "child2", "child1", "child3"); }
@Test @FixFor("MODE-1975") public void shouldNotAllowCloneWithinTheSameWs() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); try { jcrSession() .getWorkspace() .clone(jcrSession().getWorkspace().getName(), "/testRoot", "/testRoot1", false); fail("Should not be able to clone in the same ws if external nodes are involved"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Test @FixFor("MODE-1964") public void shouldSendRemovedPropertiesToConnector() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); Property doc1FederatedProperty = doc1Federated.getProperty("federated1_prop2"); doc1FederatedProperty.remove(); session.save(); try { ((Node) session.getNode("/testRoot/federated1")).getProperty("federated1_prop2"); fail("Property was not removed by connector"); } catch (PathNotFoundException e) { // exception } }
@Test @FixFor("MODE-1975") public void shouldAllowCloneOnlyIfEntireWsAreUsed() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); Session ws1Session = jcrSessionTo("ws1"); try { ws1Session.getWorkspace().clone("default", "/testRoot", "/testRoot", true); fail("Should only be able to clone between workspaces if the entire workspace is used"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } finally { ws1Session.logout(); } }