@Override public Session call() throws Exception { return repository.login(); } });
@Override public Session impersonate( Credentials credentials ) throws LoginException, RepositoryException { checkLive(); return repository.login(credentials, workspaceName()); }
@Override public Session impersonate( Credentials credentials ) throws LoginException, RepositoryException { checkLive(); return repository.login(credentials, workspaceName()); }
protected void createWorkspace( String workspaceName ) throws Exception { Session session = repository.login(); try { session.getWorkspace().createWorkspace(workspaceName); } finally { session.logout(); } }
protected void cloneWorkspace( String sourceWorkspace, String targetWorkspace, boolean removeExisting ) throws Exception { Session session = repository.login(targetWorkspace); try { session.getWorkspace().clone(sourceWorkspace, "/", "/", removeExisting); } finally { session.logout(); } }
protected JcrSession login( String workspaceName ) throws RepositoryException { Session session = repository.login(new SimpleCredentials(USER_ID, USER_ID.toCharArray()), workspaceName); assertTrue(session != this.session); return (JcrSession)session; }
private void assertProjection(String workspaceName, String projectionPath) throws RepositoryException { Session session = repository.login(workspaceName); assertNotNull(session.getNode(projectionPath)); } }
@Before @Override public void beforeEach() throws Exception { super.beforeEach(); // create a new session for each test ... session = repository.login(); }
@Test public void shouldAllowCreationOfSessionForDefaultWorkspaceWithoutUsingCredentials() throws Exception { JcrSession session1 = repository.login(); assertThat(session1.isLive(), is(true)); }
@Test public void shouldReturnPropertyAttributeValueGivenNameOfExistingAttribute() throws Exception { session = repository.login(new AnonymousCredentials("attribute1", "value1")); assertThat(session.getAttribute("attribute1"), is((Object)"value1")); }
@Test( expected = javax.jcr.LoginException.class ) public void shouldNotAllowLoginIfCredentialsDoNotProvideJaasMethod() throws Exception { String repoName = REPO_NAME; String jaasPolicyName = "modeshape-jcr"; String[] anonRoleNames = {}; Document config = createRepositoryConfiguration(repoName, jaasPolicyName, anonRoleNames); startRepositoryWith(config, repoName); repository.login(new Credentials() { private static final long serialVersionUID = 1L; }); }
@Test public void shouldProvideAttributeNames() throws Exception { session = repository.login(new AnonymousCredentials("attribute1", "value1")); String[] names = session.getAttributeNames(); assertThat(names, notNullValue()); assertThat(names.length, is(1)); assertThat(names[0], is("attribute1")); }
@Test @FixFor( "MODE-2049" ) public void shouldStartAndStopRepositoryWithoutMonitoringConfigured() throws Exception { startRunStop(repository -> repository.login().logout(), "config/repo-config-inmemory-local-environment-no-monitoring.json"); }
private void queryContentInWorkspace( JcrRepository newRepository, String workspaceName ) throws RepositoryException { JcrSession session = newRepository.login(); try { String statement = "SELECT [car:model], [car:year], [car:msrp] FROM [car:Car] AS car"; Query query = session.getWorkspace().getQueryManager().createQuery(statement, Query.JCR_SQL2); QueryResult results = query.execute(); assertThat(results.getRows().getSize(), is(13L)); } finally { session.logout(); } }
protected static void startRepository( RepositoryConfiguration configuration ) throws Exception { TestingEnvironment environment = new TestingEnvironment(); RepositoryConfiguration config = configuration != null ? new RepositoryConfiguration(configuration.getDocument(), configuration.getName(), environment) : new RepositoryConfiguration(REPO_NAME, environment); repository = new JcrRepository(config); repository.start(); session = repository.login(); }
@Test public void shouldLogInAsAnonymousUsingNoCredentials() throws Exception { String repoName = REPO_NAME; String jaasPolicyName = "modeshape-jcr-non-existant"; String[] anonRoleNames = {ModeShapeRoles.READWRITE}; Document config = createRepositoryConfiguration(repoName, jaasPolicyName, anonRoleNames); startRepositoryWith(config, repoName); session = repository.login(); session.getRootNode().getPath(); session.getRootNode().addNode("someNewNode"); }
@Test public void shouldLogInAsUserWithReadWriteRole() throws Exception { String repoName = REPO_NAME; String jaasPolicyName = "modeshape-jcr"; String[] anonRoleNames = {}; Document config = createRepositoryConfiguration(repoName, jaasPolicyName, anonRoleNames); startRepositoryWith(config, repoName); session = repository.login(new SimpleCredentials("readwrite", "readwrite".toCharArray())); session.getRootNode().getPath(); session.getRootNode().getDefinition(); session.getRootNode().addNode("someNewNode"); }
private void restoreBackup() throws Exception { startRepositoryWithConfiguration(resourceStream("config/backup-repo-config.json")); JcrSession session = repository().login(); Problems problems = session.getWorkspace().getRepositoryManager().restoreRepository(backupDirectory); assertNoProblems(problems); session.logout(); }
private void addNodeAndAssertIndexUsed(JcrRepository repository) throws RepositoryException, InterruptedException { JcrSession session = repository.login(); session.getRootNode().addNode("testRoot"); session.save(); Thread.sleep(100); String sql = "select [jcr:path] from [nt:unstructured] where [jcr:name] = 'testRoot'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); ValidateQuery.validateQuery().rowCount(1).useIndex("nodesByName").validate(query, query.execute()); session.logout(); }
@Before public void beforeEach() throws Exception { config = new RepositoryConfiguration("repoName").with(new TestingEnvironment()); repository = new JcrRepository(config); repository.start(); context = repository.runningState().context(); repoTypeManager = repository.nodeTypeManager(); session = repository.login(); }