use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.
the class SessionImplTest method testCreateSession.
/**
* JCR-2595: SessionImpl.createSession uses same Subject/LoginContext
*
* @see <a href="https://issues.apache.org/jira/browse/JCR-2595">JCR-2595</a>
*/
public void testCreateSession() throws RepositoryException, NotExecutableException {
if (!(superuser instanceof SessionImpl)) {
throw new NotExecutableException();
}
String currentWsp = superuser.getWorkspace().getName();
String otherWsp = null;
for (String wsp : superuser.getWorkspace().getAccessibleWorkspaceNames()) {
if (!wsp.equals(currentWsp)) {
otherWsp = wsp;
break;
}
}
SessionImpl sImpl = (SessionImpl) superuser;
Subject subject = sImpl.getSubject();
Session s1 = sImpl.createSession(currentWsp);
try {
assertFalse(s1 == sImpl);
assertFalse(subject == ((SessionImpl) s1).getSubject());
assertEquals(subject, ((SessionImpl) s1).getSubject());
assertEquals(currentWsp, s1.getWorkspace().getName());
} finally {
s1.logout();
assertFalse(subject.getPrincipals().isEmpty());
assertFalse(subject.getPublicCredentials().isEmpty());
}
Session s2 = sImpl.createSession(otherWsp);
try {
assertFalse(s2 == sImpl);
assertFalse(subject == ((SessionImpl) s2).getSubject());
assertEquals(subject, ((SessionImpl) s2).getSubject());
assertEquals(otherWsp, s2.getWorkspace().getName());
} finally {
s2.logout();
assertFalse(subject.getPrincipals().isEmpty());
assertFalse(subject.getPublicCredentials().isEmpty());
}
Session s3 = sImpl.createSession(null);
try {
assertFalse(s3 == sImpl);
assertFalse(subject == ((SessionImpl) s3).getSubject());
assertEquals(subject, ((SessionImpl) s3).getSubject());
assertEquals(((RepositoryImpl) sImpl.getRepository()).getConfig().getDefaultWorkspaceName(), s3.getWorkspace().getName());
} finally {
s3.logout();
assertFalse(subject.getPrincipals().isEmpty());
assertFalse(subject.getPublicCredentials().isEmpty());
}
}
use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.
the class IndexingQueueTest method testInitialIndex.
public void testInitialIndex() throws Exception {
BlockingParser.block();
File indexDir = new File(getSearchIndex().getPath());
// fill workspace
Node testFolder = testRootNode.addNode("folder", "nt:folder");
int num = createFiles(testFolder, 10, 2, 0);
session.save();
// shutdown workspace
RepositoryImpl repo = (RepositoryImpl) session.getRepository();
session.logout();
session = null;
superuser.logout();
superuser = null;
TestHelper.shutdownWorkspace(getWorkspaceName(), repo);
// delete index
try {
FileUtil.delete(indexDir);
} catch (IOException e) {
fail("Unable to delete index directory");
}
int initialNumExtractorFiles = getNumExtractorFiles();
BlockingParser.unblock();
Thread t = new Thread(new Runnable() {
public void run() {
try {
session = getHelper().getSuperuserSession(getWorkspaceName());
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
});
t.start();
while (t.isAlive()) {
// there must not be more than 20 extractor files, because:
// - initial index creation checks indexing queue every 10 nodes
// - there is an aggregate definition on the workspace that causes
// 2 extractor jobs per nt:resource
// => 2 * 10 = 20
int numFiles = getNumExtractorFiles() - initialNumExtractorFiles;
assertTrue(numFiles <= 20);
Thread.sleep(50);
}
qm = session.getWorkspace().getQueryManager();
waitForTextExtractionTasksToFinish();
String stmt = testPath + "//element(*, nt:resource)[jcr:contains(., 'fox')] order by @jcr:score descending";
Query q = qm.createQuery(stmt, Query.XPATH);
assertEquals(num, q.execute().getNodes().getSize());
}
use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.
the class UserAccessControlProviderTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
RepositoryImpl repo = (RepositoryImpl) superuser.getRepository();
String wspName = repo.getConfig().getSecurityConfig().getSecurityManagerConfig().getWorkspaceName();
s = getHelper().getSuperuserSession(wspName);
provider = new UserAccessControlProvider();
provider.init(s, Collections.emptyMap());
}
use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.
the class BackwardsCompatibilityIT method checkJackrabbitRepository.
private void checkJackrabbitRepository(File directory) throws Exception {
File configuration = new File(directory, "repository.xml");
try {
RepositoryConfig config = RepositoryConfig.create(configuration.getPath(), directory.getPath());
RepositoryImpl repository = RepositoryImpl.create(config);
try {
checkRepositoryContent(repository);
} finally {
repository.shutdown();
}
} catch (RepositoryException e) {
String message = "Unable to access repository " + directory;
log.error(message, e);
fail(message);
}
}
use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.
the class AbstractRepositoryTest method doCreateRepository.
/**
* Creates a named test repository with the given configuration file.
*
* @param name name of the repository
* @param xml input stream for reading the repository configuration
* @throws Exception if the repository could not be created
*/
protected void doCreateRepository(String name, InputStream xml) throws Exception {
File directory = new File(new File("target", "repository"), name);
File configuration = new File(directory, "repository.xml");
// Copy the configuration file into the repository directory
try {
OutputStream output = FileUtils.openOutputStream(configuration);
try {
IOUtils.copy(xml, output);
} finally {
output.close();
}
} finally {
xml.close();
}
// Create the repository
try {
RepositoryConfig config = RepositoryConfig.create(configuration.getPath(), directory.getPath());
RepositoryImpl repository = RepositoryImpl.create(config);
try {
Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
try {
createTestData(session);
} finally {
session.logout();
}
} finally {
repository.shutdown();
}
} catch (RepositoryException e) {
e.printStackTrace();
fail("Create repository " + name);
}
}
Aggregations