Package org.jboss.dna.graph.connector.map

Examples of org.jboss.dna.graph.connector.map.MapWorkspace


    @Test
    public void shouldCreateWorkspaceWithUniqueNameIfSpecifiedNameIsAlreadyUsedAndConflictOptionIsToCreateWithAdjustedName() {
        String workspaceName = "New Workspace";
        assertThat(repository.createWorkspace(context, workspaceName, CreateConflictBehavior.DO_NOT_CREATE), is(notNullValue()));
        assertThat(repository.getWorkspaceNames(), hasItems(workspaceName));
        MapWorkspace secondWorkspace = repository.createWorkspace(context,
                                                               workspaceName,
                                                               CreateConflictBehavior.CREATE_WITH_ADJUSTED_NAME);
        assertThat(secondWorkspace, is(notNullValue()));
        assertThat(repository.getWorkspaceNames(), hasItems(workspaceName, secondWorkspace.getName()));
    }
View Full Code Here


    }

    @Test
    public void shouldCloneWorkspaceAndCopyContentsIfWorkspaceWithSpecifiedNameExists() {
        String workspaceName = "Original Workspace";
        MapWorkspace workspace = repository.createWorkspace(context, workspaceName, CreateConflictBehavior.DO_NOT_CREATE);
        assertThat(workspace, is(notNullValue()));
        assertThat(repository.getWorkspaceNames(), hasItems(workspaceName));

        // Populate the workspace with a few nodes ...
        MapNode root = workspace.getRoot();
        MapNode node_a = workspace.createNode(context, root, nameFactory.create("a"), null);
        MapNode node_b = workspace.createNode(context, node_a, nameFactory.create("b"), null);
        MapNode node_c = workspace.createNode(context, node_b, nameFactory.create("c"), null);
        MapNode node_d = workspace.createNode(context, root, nameFactory.create("d"), null);
        MapNode node_e = workspace.createNode(context, node_d, nameFactory.create("e"), null);
        MapNode node_b2 = workspace.createNode(context, node_d, nameFactory.create("b"), null);

        ValueFactory<String> stringFactory = context.getValueFactories().getStringFactory();
        Name propertyName = nameFactory.create("something");
        Property property = propertyFactory.create(propertyName, stringFactory.create("Worth the wait"));
        node_b.setProperty(property);

        assertThat(((InMemoryRepository.Workspace) workspace).size(), is(7));
        assertThat(workspace.getNode(pathFactory.create("/")), is(sameInstance(workspace.getRoot())));
        assertThat(workspace.getNode(pathFactory.create("/a")), is(sameInstance(node_a)));
        assertThat(workspace.getNode(pathFactory.create("/a/b")), is(sameInstance(node_b)));
        assertThat(workspace.getNode(pathFactory.create("/a/b/c")), is(sameInstance(node_c)));
        assertThat(workspace.getNode(pathFactory.create("/d")), is(sameInstance(node_d)));
        assertThat(workspace.getNode(pathFactory.create("/d/e")), is(sameInstance(node_e)));
        assertThat(workspace.getNode(pathFactory.create("/d/b")), is(sameInstance(node_b2)));
        assertThat(workspace.getNode(pathFactory.create("/a/b")).getProperty(propertyName), is(property));

        // Now clone the workspace ...
        String newWorkspaceName = "New Workspace";
        MapWorkspace new_workspace = repository.createWorkspace(context,
                                                             newWorkspaceName,
                                                             CreateConflictBehavior.DO_NOT_CREATE,
                                                             workspaceName);
        assertThat(new_workspace, is(notNullValue()));
        assertThat(repository.getWorkspaceNames(), hasItems(workspaceName, newWorkspaceName));

        // Now check that the original workspace still has its content ...
        assertThat(((InMemoryRepository.Workspace) workspace).size(), is(7));
        assertThat(workspace.getNode(pathFactory.create("/")), is(sameInstance(workspace.getRoot())));
        assertThat(workspace.getNode(pathFactory.create("/a")), is(sameInstance(node_a)));
        assertThat(workspace.getNode(pathFactory.create("/a/b")), is(sameInstance(node_b)));
        assertThat(workspace.getNode(pathFactory.create("/a/b/c")), is(sameInstance(node_c)));
        assertThat(workspace.getNode(pathFactory.create("/d")), is(sameInstance(node_d)));
        assertThat(workspace.getNode(pathFactory.create("/d/e")), is(sameInstance(node_e)));
        assertThat(workspace.getNode(pathFactory.create("/d/b")), is(sameInstance(node_b2)));
        assertThat(workspace.getNode(pathFactory.create("/a/b")).getProperty(propertyName), is(property));

        // Now check that the new workspace has its content ...
        assertThat(((InMemoryRepository.Workspace) new_workspace).size(), is(7));

        // Since we cloned workspaces, the UUIDs should be the same in each workspace ...
        assertThat(workspace.getNode(pathFactory.create("/")).getUuid(),
                   is(new_workspace.getNode(pathFactory.create("/")).getUuid()));
        assertThat(workspace.getNode(pathFactory.create("/a")).getUuid(),
                   is(new_workspace.getNode(pathFactory.create("/a")).getUuid()));
        assertThat(workspace.getNode(pathFactory.create("/a/b")).getUuid(),
                   is(new_workspace.getNode(pathFactory.create("/a/b")).getUuid()));
        assertThat(workspace.getNode(pathFactory.create("/a/b/c")).getUuid(),
                   is(new_workspace.getNode(pathFactory.create("/a/b/c")).getUuid()));
        assertThat(workspace.getNode(pathFactory.create("/d")).getUuid(),
                   is(new_workspace.getNode(pathFactory.create("/d")).getUuid()));
        assertThat(workspace.getNode(pathFactory.create("/d/e")).getUuid(),
                   is(new_workspace.getNode(pathFactory.create("/d/e")).getUuid()));
        assertThat(workspace.getNode(pathFactory.create("/d/b")).getUuid(),
                   is(new_workspace.getNode(pathFactory.create("/d/b")).getUuid()));
    }
View Full Code Here

    }

    @Test
    public void shouldCloneWorkspaceButShouldNotCopyContentsIfWorkspaceWithSpecifiedNameDoesNotExist() {
        String workspaceName = "Original Workspace";
        MapWorkspace workspace = repository.createWorkspace(context, workspaceName, CreateConflictBehavior.DO_NOT_CREATE);
        assertThat(workspace, is(notNullValue()));
        assertThat(repository.getWorkspaceNames(), hasItems(workspaceName));

        // Populate the workspace with a few nodes ...
        MapNode root = workspace.getRoot();
        MapNode node_a = workspace.createNode(context, root, nameFactory.create("a"), null);
        MapNode node_b = workspace.createNode(context, node_a, nameFactory.create("b"), null);
        MapNode node_c = workspace.createNode(context, node_b, nameFactory.create("c"), null);
        MapNode node_d = workspace.createNode(context, root, nameFactory.create("d"), null);
        MapNode node_e = workspace.createNode(context, node_d, nameFactory.create("e"), null);
        MapNode node_b2 = workspace.createNode(context, node_d, nameFactory.create("b"), null);

        ValueFactory<String> stringFactory = context.getValueFactories().getStringFactory();
        Name propertyName = nameFactory.create("something");
        Property property = propertyFactory.create(propertyName, stringFactory.create("Worth the wait"));
        node_b.setProperty(property);

        assertThat(((InMemoryRepository.Workspace) workspace).size(), is(7));
        assertThat(workspace.getNode(pathFactory.create("/")), is(sameInstance(workspace.getRoot())));
        assertThat(workspace.getNode(pathFactory.create("/a")), is(sameInstance(node_a)));
        assertThat(workspace.getNode(pathFactory.create("/a/b")), is(sameInstance(node_b)));
        assertThat(workspace.getNode(pathFactory.create("/a/b/c")), is(sameInstance(node_c)));
        assertThat(workspace.getNode(pathFactory.create("/d")), is(sameInstance(node_d)));
        assertThat(workspace.getNode(pathFactory.create("/d/e")), is(sameInstance(node_e)));
        assertThat(workspace.getNode(pathFactory.create("/d/b")), is(sameInstance(node_b2)));
        assertThat(workspace.getNode(pathFactory.create("/a/b")).getProperty(propertyName), is(property));

        // Now clone the workspace ...
        String newWorkspaceName = "New Workspace";
        MapWorkspace new_workspace = repository.createWorkspace(context,
                                                             newWorkspaceName,
                                                             CreateConflictBehavior.DO_NOT_CREATE,
                                                             "non-existant workspace");
        assertThat(new_workspace.getRoot(), is(notNullValue()));
        assertThat(new_workspace.getRoot().getUuid(), is(rootUuid));
        assertThat(new_workspace.getRoot().getChildren().isEmpty(), is(true));
    }
View Full Code Here

TOP

Related Classes of org.jboss.dna.graph.connector.map.MapWorkspace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.