Example #1
0
  @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
  public void shouldReturnFalseFromIsSameIfTheRepositoryInstanceIsDifferent() throws Exception {
    // Set up the store ...
    InMemoryRepositorySource source2 = new InMemoryRepositorySource();
    source2.setName("store");
    Graph store2 = Graph.create(source2, context);
    store2
        .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml"))
        .into("/");
    JcrSession jcrSession2 = mock(JcrSession.class);
    when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes);
    when(jcrSession2.isLive()).thenReturn(true);
    SessionCache cache2 =
        new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2);

    Workspace workspace2 = mock(Workspace.class);
    Repository repository2 = mock(JcrRepository.class);

    when(jcrSession2.getWorkspace()).thenReturn(workspace2);
    when(jcrSession2.getRepository()).thenReturn(repository2);
    when(workspace2.getName()).thenReturn("workspace1");

    // Use the same id and location ...
    javax.jcr.Node prius2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Toyota Prius"));
    assertThat(prius2.isSame(prius), is(false));

    // Check the properties ...
    javax.jcr.Property model = prius.getProperty("vehix:model");
    javax.jcr.Property model2 = prius2.getProperty("vehix:model");
    assertThat(model.isSame(model2), is(false));
  }
  @Test
  public void shouldReturnTrueFromIsSameIfTheNodeUuidAndWorkspaceNameAndRepositoryInstanceAreSame()
      throws Exception {
    // Set up the store ...
    InMemoryRepositorySource source2 = new InMemoryRepositorySource();
    source2.setName("store");
    Graph store2 = Graph.create(source2, context);
    store2
        .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml"))
        .into("/");
    JcrSession jcrSession2 = mock(JcrSession.class);
    when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes);
    when(jcrSession2.isLive()).thenReturn(true);
    SessionCache cache2 =
        new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2);

    Workspace workspace2 = mock(Workspace.class);
    when(jcrSession2.getWorkspace()).thenReturn(workspace2);
    when(jcrSession2.getRepository()).thenReturn(repository);
    when(workspace2.getName()).thenReturn("workspace1");

    WorkspaceLockManager lockManager =
        new WorkspaceLockManager(context, repoLockManager, "workspace2", null);
    JcrLockManager jcrLockManager = new JcrLockManager(jcrSession2, lockManager);
    when(jcrSession2.lockManager()).thenReturn(jcrLockManager);

    // Use the same id and location ...
    javax.jcr.Node prius2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Toyota Prius"));
    prius2.addMixin("mix:referenceable");
    prius.addMixin("mix:referenceable");
    String priusUuid = prius.getIdentifier();
    String priusUuid2 = prius2.getIdentifier();
    assertThat(priusUuid, is(priusUuid2));
    assertThat(prius2.isSame(prius), is(true));

    // Check the properties ...
    javax.jcr.Property model = prius.getProperty("vehix:model");
    javax.jcr.Property model2 = prius2.getProperty("vehix:model");
    javax.jcr.Property year2 = prius2.getProperty("vehix:year");
    assertThat(model.isSame(model2), is(true));
    assertThat(model.isSame(year2), is(false));
  }
  @Test
  public void shouldReturnFalseFromIsSameIfTheNodeUuidIsDifferent() throws Exception {
    // Set up the store ...
    InMemoryRepositorySource source2 = new InMemoryRepositorySource();
    source2.setName("store");
    Graph store2 = Graph.create(source2, context);
    store2
        .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml"))
        .into("/");
    JcrSession jcrSession2 = mock(JcrSession.class);
    when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes);
    when(jcrSession2.isLive()).thenReturn(true);
    SessionCache cache2 =
        new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2);

    Workspace workspace2 = mock(Workspace.class);
    JcrRepository repository2 = mock(JcrRepository.class);
    RepositoryLockManager repoLockManager2 = mock(RepositoryLockManager.class);
    when(jcrSession2.getWorkspace()).thenReturn(workspace2);
    when(jcrSession2.getRepository()).thenReturn(repository2);
    when(workspace2.getName()).thenReturn("workspace1");

    WorkspaceLockManager lockManager =
        new WorkspaceLockManager(context, repoLockManager2, "workspace2", null);
    JcrLockManager jcrLockManager = new JcrLockManager(jcrSession2, lockManager);
    when(jcrSession2.lockManager()).thenReturn(jcrLockManager);

    // Use the same id and location; use 'Nissan Altima'
    // since the UUIDs will be different (cars.xml doesn't define on this node) ...
    javax.jcr.Node altima2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Nissan Altima"));
    altima2.addMixin("mix:referenceable");
    altima.addMixin("mix:referenceable");
    String altimaUuid = altima.getIdentifier();
    String altimaUuid2 = altima2.getIdentifier();
    assertThat(altimaUuid, is(not(altimaUuid2)));
    assertThat(altima2.isSame(altima), is(false));

    // Check the properties ...
    javax.jcr.Property model = altima.getProperty("vehix:model");
    javax.jcr.Property model2 = altima2.getProperty("vehix:model");
    assertThat(model.isSame(model2), is(false));
  }
Example #5
0
  @Test
  public void shouldNotIndexNotQueryableDocument() throws Exception {
    federationManager.createProjection(
        "/testRoot", SOURCE_NAME, MockConnector.NONT_QUERYABLE_DOC_LOCATION, "nonQueryableDoc");

    Workspace workspace = session.getWorkspace();
    workspace.reindex();

    Node externalNode = assertNodeFound("/testRoot/nonQueryableDoc");

    QueryManager queryManager = workspace.getQueryManager();
    Query query =
        queryManager.createQuery(
            "select * FROM [nt:base] WHERE [jcr:path] LIKE '/testRoot/nonQueryableDoc'",
            Query.JCR_SQL2);
    validateQuery().rowCount(0).validate(query, query.execute());

    // change the document and re-run the query
    externalNode.setProperty("test", "a value");
    session.save();
    validateQuery().rowCount(0).validate(query, query.execute());
  }
Example #6
0
  @Test
  public void shouldIndexQueryableBranches() throws Exception {
    Node git = gitNode();
    Workspace workspace = session.getWorkspace();

    // force reindexing of tags and check that they haven't been indexed
    workspace.reindex(git.getPath() + "/tags");
    Query query =
        workspace
            .getQueryManager()
            .createQuery(
                "SELECT * FROM [nt:base] WHERE [jcr:path] LIKE '%/tags/%'", Query.JCR_SQL2);
    assertEquals(0, query.execute().getNodes().getSize());

    // force reindexing of branches and check that they haven't been indexed
    workspace.reindex(git.getPath() + "/branches");
    query =
        workspace
            .getQueryManager()
            .createQuery(
                "SELECT * FROM [nt:base] WHERE [jcr:path] LIKE '%/branches/%'", Query.JCR_SQL2);
    assertEquals(0, query.execute().getNodes().getSize());

    // force reindexing of a file under master/tree and check that it has been indexed
    // (indexing everything under /tree/master is way too expensive)
    workspace.reindex(git.getPath() + "/tree/master/.gitignore");
    query =
        workspace
            .getQueryManager()
            .createQuery(
                "SELECT * FROM [nt:base] WHERE [jcr:path] LIKE '%/tree/master/%'", Query.JCR_SQL2);
    assertTrue(query.execute().getNodes().getSize() > 0);

    // force reindexing of a file under another configured branch and check that it has been indexed
    workspace.reindex(git.getPath() + "/tree/2.x/.gitignore");
    query =
        workspace
            .getQueryManager()
            .createQuery(
                "SELECT * FROM [nt:base] WHERE [jcr:path] LIKE '%/tree/2.x/%'", Query.JCR_SQL2);
    assertTrue(query.execute().getNodes().getSize() > 0);
  }