Package org.modeshape.jcr.api

Examples of org.modeshape.jcr.api.Session


        Session defaultSession = repository.login("filesystem");
    }
   
    @Test
    public void shouldHaveFileSystemSourceConfigured() throws Exception {
        Session defaultSession = repository.login();
        // predefined
        assertNotNull(defaultSession.getNode("/projection1"));

        // create a new projection
        FederationManager federationManager = defaultSession.getWorkspace().getFederationManager();
        federationManager.createProjection("/", "filesystem_readonly", "/", "testProjection");
        assertNotNull(defaultSession.getNode("/testProjection"));

        Session otherSession = repository.login("other");
        // predefined
        assertNotNull(otherSession.getNode("/projection1"));
    }
View Full Code Here


        assertNotNull(otherSession.getNode("/projection1"));
    }

    @Test
    public void shouldNotAllowWritesIfConfiguredAsReadonly() throws Exception {
        Session defaultSession = repository.login();
        Node projection1 = defaultSession.getNode("/projection1");
        try {
            projection1.addNode("test", "nt:file");
            defaultSession.save();
            fail("Write operation should not be possible if connector is readonly");
        } catch (RepositoryException e) {
            // expected
        }
    }
View Full Code Here

        }
    }

    @Test
    public void shouldCorrectlyWriteFilesToDisk() throws Exception {
        Session session = repository.login();

        // configured via arquillian.xml
        String rootFolderPath = System.getProperty("rootDirectoryPath");
        assertNotNull(rootFolderPath);
        File rootFolder = new File(rootFolderPath);
        assertTrue(rootFolder.isDirectory());
        File subFolder = new File(rootFolder, "sub_folder");
        if (subFolder.exists()) {
            FileUtil.delete(subFolder);
        }
        assertFalse(subFolder.exists());

        // predefined
        Node rootProjection = session.getNode("/root");
        assertNotNull(rootProjection);

        //add a sub-folder
        rootProjection.addNode("sub_folder", "nt:folder");
        session.save();

        //check the newly added folder node was created
        subFolder = new File(rootFolder, "sub_folder");
        assertTrue(subFolder.exists());
        assertTrue(subFolder.isDirectory());

        //now add a file
        ByteArrayInputStream bis = new ByteArrayInputStream("test string".getBytes());
        new JcrTools().uploadFile(session, "/root/sub_folder/file", bis);
        session.save();
        File file = new File(subFolder, "file");
        assertTrue(file.exists());
        assertTrue(file.isFile());
        assertEquals("test string", IoUtil.read(file));
    }
View Full Code Here

        assertEquals("test string", IoUtil.read(file));
    }

    @Test
    public void shouldHaveGitSourceConfigured() throws Exception {
        Session session = repository.login();
        assertNotNull(session.getNode("/modeshape_git"));
        assertNotNull(session.getNode("/modeshape_git/branches"));
        assertNotNull(session.getNode("/modeshape_git/tags"));
        assertNotNull(session.getNode("/modeshape_git/commits"));
    }
View Full Code Here

        assertNotNull(session.getNode("/modeshape_git/commits"));
    }

    @Test
    public void shouldHaveJdbcMetadataSourceConfigured() throws Exception {
        Session defaultSession = repository.login();
        // predefined
        Node dbRoot = defaultSession.getNode("/ModeShapeTestDb");
        assertNotNull(dbRoot);

        assertEquals("nt:unstructured", dbRoot.getPrimaryNodeType().getName());
        assertNotNull(dbRoot.getProperty(JdbcMetadataLexicon.DATABASE_PRODUCT_NAME.toString()));
        assertNotNull(dbRoot.getProperty(JdbcMetadataLexicon.DATABASE_PRODUCT_VERSION.toString()));
View Full Code Here

        RepositoryConfiguration config = RepositoryConfiguration.read(url);
        startRepository(config);

        try {
            // Use a session to load the contents ...
            Session session = repository.login();

            try {
                registerNodeTypes(session, "cnd/fincayra.cnd");
                registerNodeTypes(session, "cnd/magnolia.cnd");
                registerNodeTypes(session, "cnd/notionalTypes.cnd");
                registerNodeTypes(session, "cnd/cars.cnd");
                registerNodeTypes(session, "cnd/validType.cnd");

                InputStream stream = resourceStream("io/cars-system-view.xml");
                try {
                    session.getWorkspace().importXML("/", stream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
                } catch (Throwable t) {
                    t.printStackTrace();
                } finally {
                    stream.close();
                }

                // Create a branch that contains some same-name-siblings ...
                Node other = session.getRootNode().addNode("Other", "nt:unstructured");
                Node a = other.addNode("NodeA", "nt:unstructured");
                a.addMixin("mix:referenceable");
                a.setProperty("something", "value3 quick brown fox");
                a.setProperty("somethingElse", "value2");
                a.setProperty("propA", "value1");
                Node other2 = other.addNode("NodeA", "nt:unstructured");
                other2.addMixin("mix:referenceable");
                other2.setProperty("something", "value2 quick brown cat wearing hat");
                other2.setProperty("propB", "value1");
                other2.setProperty("propC", "value2");
                Node other3 = other.addNode("NodeA", "nt:unstructured");
                other3.addMixin("mix:referenceable");
                other3.setProperty("something", new String[] {"black dog", "white dog"});
                other3.setProperty("propB", "value1");
                other3.setProperty("propC", "value3");
                Value[] refValues = new Value[2];
                refValues[0] = session.getValueFactory().createValue(other2);
                refValues[1] = session.getValueFactory().createValue(other3);
                other3.setProperty("otherNode", a);
                other3.setProperty("otherNodes", refValues);
                Node c = other.addNode("NodeC", "notion:typed");
                c.setProperty("notion:booleanProperty", true);
                c.setProperty("notion:booleanProperty2", false);
                c.setProperty("propD", "value4");
                c.setProperty("propC", "value1");
                c.setProperty("notion:singleReference", a);
                c.setProperty("notion:multipleReferences", refValues);
                Node b = session.getRootNode().addNode("NodeB", "nt:unstructured");
                b.setProperty("myUrl", "http://www.acme.com/foo/bar");
                b.setProperty("pathProperty", a.getPath());
                session.save();

                // // Initialize the nodes count
                // initNodesCount();
                //
                // // Prime creating a first XPath query and SQL query ...
                // session.getWorkspace().getQueryManager().createQuery("//element(*,nt:unstructured)", Query.XPATH);
                // session.getWorkspace().getQueryManager().createQuery("SELECT * FROM [nt:base]", Query.JCR_SQL2);
            } finally {
                session.logout();
            }

            // Prime creating the schemata ...
            // repository.nodeTypeManager().getRepositorySchemata();
        } catch (RuntimeException e) {
View Full Code Here

    @Test
    public void shouldManuallySequence() throws Exception {
        URL url = getClass().getClassLoader().getResource("log4j.properties");
        assertNotNull(url);
        Session session = session();
        tools.uploadFile(session, "/files/log4j.properties", url);

        Node propFile = session.getNode("/files/log4j.properties");
        Property content = propFile.getProperty("jcr:content/jcr:data");
        assertNotNull(content);

        Node output = session.getRootNode().addNode("output");
        assertFalse(output.hasNode(TestSequencersHolder.DERIVED_NODE_NAME));

        session.sequence("Counting sequencer", content, output);
        assertTrue(output.hasNode(TestSequencersHolder.DERIVED_NODE_NAME));

        session.refresh(false);

        assertFalse(session.getRootNode().hasNode("files"));
        assertFalse(session.getRootNode().hasNode("output"));
    }
View Full Code Here

    @BeforeClass
    public static void beforeAll() throws Exception {
        RepositoryConfiguration config = RepositoryConfiguration.read("config/repo-config-git-federation.json");
        startRepository(config);

        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");
    }
View Full Code Here

        initTestDatabase();

        RepositoryConfiguration config = RepositoryConfiguration.read("config/repo-config-jdbc-meta-federation.json");
        startRepository(config);

        Session session = getSession();
        Node testRoot = session.getRootNode().addNode("testRoot");
        session.save();

        FederationManager fedMgr = session.getWorkspace().getFederationManager();
        fedMgr.createProjection(testRoot.getPath(), "jdbc-meta", "/", "database");
    }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.api.Session

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.