You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/02/23 16:30:39 UTC
svn commit: r915386 - in /sling/trunk/bundles/commons/testing: ./
src/main/java/org/apache/sling/commons/testing/jcr/ src/main/resources/
src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/sling/ src/test/jav...
Author: cziegeler
Date: Tue Feb 23 15:30:38 2010
New Revision: 915386
URL: http://svn.apache.org/viewvc?rev=915386&view=rev
Log:
SLING-1406 : Upgrade to JCR 2.0/Jackrabbit 2.0 and add simple test case for the repository util.
Added:
sling/trunk/bundles/commons/testing/src/test/
sling/trunk/bundles/commons/testing/src/test/java/
sling/trunk/bundles/commons/testing/src/test/java/org/
sling/trunk/bundles/commons/testing/src/test/java/org/apache/
sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/
sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/
sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/
sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/jcr/
sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/jcr/RepositoryUtilTest.java (with props)
Modified:
sling/trunk/bundles/commons/testing/pom.xml
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyDefinition.java
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java
sling/trunk/bundles/commons/testing/src/main/resources/jackrabbit-test-config.xml
Modified: sling/trunk/bundles/commons/testing/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/pom.xml?rev=915386&r1=915385&r2=915386&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/pom.xml (original)
+++ sling/trunk/bundles/commons/testing/pom.xml Tue Feb 23 15:30:38 2010
@@ -60,7 +60,7 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
-
+
<!--
Dependencies required for testing and provided
transitively to modules using this artifact
@@ -80,18 +80,31 @@
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
+ <version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-api</artifactId>
- <version>1.4</version>
+ <version>2.0.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-commons</artifactId>
+ <version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
- <version>1.4.6</version>
+ <version>2.0.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
<scope>compile</scope>
</dependency>
<dependency>
Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java?rev=915386&r1=915385&r2=915386&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java (original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java Tue Feb 23 15:30:38 2010
@@ -18,15 +18,16 @@
*/
package org.apache.sling.commons.testing.jcr;
-import org.apache.jackrabbit.util.ChildrenCollectorFilter;
-
import java.io.InputStream;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.jcr.Binary;
+import javax.jcr.InvalidLifecycleTransitionException;
import javax.jcr.Item;
import javax.jcr.ItemVisitor;
import javax.jcr.Node;
@@ -35,17 +36,21 @@
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import javax.jcr.lock.Lock;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import javax.jcr.version.Version;
import javax.jcr.version.VersionException;
import javax.jcr.version.VersionHistory;
+import org.apache.jackrabbit.util.ChildrenCollectorFilter;
+
// simple mock implementation of a node
public class MockNode implements Node {
@@ -181,7 +186,7 @@
public PropertyIterator getProperties(String namePattern) throws RepositoryException {
PropertyIterator iterator = getProperties();
List<Property> properties = new ArrayList<Property>();
-
+
while (iterator.hasNext()) {
Property p = iterator.nextProperty();
String name = p.getName();
@@ -189,7 +194,7 @@
properties.add(p);
}
}
-
+
return new MockPropertyIterator(properties.iterator());
}
@@ -370,7 +375,7 @@
public Session getSession() {
return this.session;
}
-
+
public void setSession(Session session) {
this.session = session;
}
@@ -396,4 +401,89 @@
public void save() {
}
+ // JCR 2.0 methods
+
+ public void followLifecycleTransition(String transition)
+ throws UnsupportedRepositoryOperationException,
+ InvalidLifecycleTransitionException, RepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String[] getAllowedLifecycleTransistions()
+ throws UnsupportedRepositoryOperationException, RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getIdentifier() throws RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NodeIterator getNodes(String[] nameGlobs) throws RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public PropertyIterator getProperties(String[] nameGlobs)
+ throws RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public PropertyIterator getReferences(String name)
+ throws RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NodeIterator getSharedSet() throws RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public PropertyIterator getWeakReferences() throws RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public PropertyIterator getWeakReferences(String name)
+ throws RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void removeShare() throws VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeSharedSet() throws VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setPrimaryType(String nodeTypeName)
+ throws NoSuchNodeTypeException, VersionException,
+ ConstraintViolationException, LockException, RepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Property setProperty(String name, BigDecimal value)
+ throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Property setProperty(String name, Binary value)
+ throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java?rev=915386&r1=915385&r2=915386&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java (original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java Tue Feb 23 15:30:38 2010
@@ -21,6 +21,7 @@
import javax.jcr.Value;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
import javax.jcr.nodetype.PropertyDefinition;
public class MockNodeType implements NodeType {
@@ -95,4 +96,40 @@
return false;
}
+ // JCR 2.0 methods
+
+ public boolean canRemoveNode(String nodeName) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean canRemoveProperty(String propertyName) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public NodeTypeIterator getDeclaredSubtypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NodeTypeIterator getSubtypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String[] getDeclaredSupertypeNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isAbstract() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isQueryable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java?rev=915386&r1=915385&r2=915386&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java (original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java Tue Feb 23 15:30:38 2010
@@ -19,9 +19,11 @@
package org.apache.sling.commons.testing.jcr;
import java.io.InputStream;
+import java.math.BigDecimal;
import java.util.Calendar;
import javax.jcr.AccessDeniedException;
+import javax.jcr.Binary;
import javax.jcr.InvalidItemStateException;
import javax.jcr.Item;
import javax.jcr.ItemExistsException;
@@ -45,11 +47,11 @@
private Value [] values = {};
private final String name;
-
+
public MockProperty(String name) {
this.name = name;
}
-
+
public boolean getBoolean() throws ValueFormatException, RepositoryException {
if (values.length > 1) {
throw new ValueFormatException();
@@ -245,4 +247,41 @@
NoSuchNodeTypeException, RepositoryException {
}
+ // JCR 2.0 methods
+
+ public Binary getBinary() throws ValueFormatException, RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public BigDecimal getDecimal() throws ValueFormatException,
+ RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Property getProperty() throws ItemNotFoundException,
+ ValueFormatException, RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isMultiple() throws RepositoryException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setValue(BigDecimal value) throws ValueFormatException,
+ VersionException, LockException, ConstraintViolationException,
+ RepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setValue(Binary value) throws ValueFormatException,
+ VersionException, LockException, ConstraintViolationException,
+ RepositoryException {
+ // TODO Auto-generated method stub
+
+ }
}
Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyDefinition.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyDefinition.java?rev=915386&r1=915385&r2=915386&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyDefinition.java (original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyDefinition.java Tue Feb 23 15:30:38 2010
@@ -25,10 +25,10 @@
public class MockPropertyDefinition implements PropertyDefinition {
private boolean multiple;
-
+
public MockPropertyDefinition(boolean multiple) {
this.multiple = multiple;
-
+
}
public Value[] getDefaultValues() {
return null;
@@ -70,4 +70,18 @@
return false;
}
+ // JCR 2.0 methods
+
+ public String[] getAvailableQueryOperators() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public boolean isFullTextSearchable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ public boolean isQueryOrderable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java?rev=915386&r1=915385&r2=915386&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java (original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java Tue Feb 23 15:30:38 2010
@@ -19,8 +19,10 @@
package org.apache.sling.commons.testing.jcr;
import java.io.InputStream;
+import java.math.BigDecimal;
import java.util.Calendar;
+import javax.jcr.Binary;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
@@ -35,15 +37,16 @@
private long longValue;
private InputStream stream;
private int propertyType;
-
+ private BigDecimal decimal;
+
public MockValue() {
}
-
+
public MockValue(String str) {
stringValue = str;
propertyType = PropertyType.STRING;
}
-
+
public boolean getBoolean() throws ValueFormatException, IllegalStateException, RepositoryException {
return booleanValue;
}
@@ -96,4 +99,16 @@
public void setValue(InputStream stream) {
this.stream = stream;
}
+
+ public void setDecimal(BigDecimal value) {
+ this.decimal = value;
+ }
+
+ public Binary getBinary() throws RepositoryException {
+ return null;
+ }
+
+ public BigDecimal getDecimal() throws ValueFormatException, RepositoryException {
+ return decimal;
+ }
}
Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java?rev=915386&r1=915385&r2=915386&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java (original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java Tue Feb 23 15:30:38 2010
@@ -20,7 +20,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Hashtable;
+import java.io.InputStreamReader;
import javax.jcr.Credentials;
import javax.jcr.LoginException;
@@ -29,14 +29,11 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
-import javax.jcr.Workspace;
-import javax.jcr.nodetype.NodeTypeManager;
-import javax.naming.Context;
-import javax.naming.InitialContext;
+import javax.jcr.Value;
import javax.naming.NamingException;
-import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
-import org.apache.jackrabbit.core.jndi.RegistryHelper;
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
import org.apache.sling.jcr.api.SlingRepository;
/**
@@ -45,117 +42,97 @@
*/
public class RepositoryUtil {
- public static final String REPOSITORY_NAME = "repositoryTest";
-
public static final String ADMIN_NAME = "admin";
public static final String ADMIN_PASSWORD = "admin";
- public static final String CONTEXT_FACTORY = "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory";
-
- public static final String PROVIDER_URL = "localhost";
+ public static final String HOME_DIR = "target/repository";
public static final String CONFIG_FILE = "jackrabbit-test-config.xml";
- public static final String HOME_DIR = "target/repository";
+ private static SlingRepository repository;
- protected static InitialContext getInitialContext() throws NamingException {
- final Hashtable<String, String> env = new Hashtable<String, String>();
- env.put(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY);
- env.put(Context.PROVIDER_URL, PROVIDER_URL);
- return new InitialContext(env);
- }
+ private static Session adminSession;
/**
* Start a new repository
*
* @throws RepositoryException when it is not possible to start the
* repository.
- * @throws NamingException
*/
- public static void startRepository() throws RepositoryException,
- NamingException {
-
- // copy the repository configuration file to the repository HOME_DIR
- InputStream ins = RepositoryUtil.class.getClassLoader().getResourceAsStream(
- CONFIG_FILE);
- if (ins == null) {
- throw new RepositoryException("Cannot get " + CONFIG_FILE);
- }
+ public static void startRepository() throws RepositoryException {
+ if ( adminSession == null ) {
+ // copy the repository configuration file to the repository HOME_DIR
+ InputStream ins = RepositoryUtil.class.getClassLoader().getResourceAsStream(
+ CONFIG_FILE);
+ if (ins == null) {
+ throw new RepositoryException("Cannot get " + CONFIG_FILE);
+ }
- File configFile = new File(HOME_DIR, CONFIG_FILE);
- configFile.getParentFile().mkdirs();
+ File configFile = new File(HOME_DIR, "repository.xml");
+ configFile.getParentFile().mkdirs();
- FileOutputStream out = null;
- try {
- out = new FileOutputStream(configFile);
- byte[] buf = new byte[1024];
- int rd;
- while ((rd = ins.read(buf)) >= 0) {
- out.write(buf, 0, rd);
- }
- } catch (IOException ioe) {
- throw new RepositoryException("Cannot copy configuration file to "
- + configFile);
- } finally {
+ FileOutputStream out = null;
try {
- ins.close();
- } catch (IOException ignore) {
- }
- if (out != null) {
+ out = new FileOutputStream(configFile);
+ byte[] buf = new byte[1024];
+ int rd;
+ while ((rd = ins.read(buf)) >= 0) {
+ out.write(buf, 0, rd);
+ }
+ } catch (IOException ioe) {
+ throw new RepositoryException("Cannot copy configuration file to "
+ + configFile);
+ } finally {
try {
- out.close();
+ ins.close();
} catch (IOException ignore) {
}
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException ignore) {
+ }
+ }
}
- }
- // somewhat dirty hack to have the derby.log file in a sensible
- // location, but don't overwrite anything already set
- if (System.getProperty("derby.stream.error.file") == null) {
- String derbyLog = HOME_DIR + "/derby.log";
- System.setProperty("derby.stream.error.file", derbyLog);
- }
+ // somewhat dirty hack to have the derby.log file in a sensible
+ // location, but don't overwrite anything already set
+ if (System.getProperty("derby.stream.error.file") == null) {
+ String derbyLog = HOME_DIR + "/derby.log";
+ System.setProperty("derby.stream.error.file", derbyLog);
+ }
- RegistryHelper.registerRepository(getInitialContext(), REPOSITORY_NAME,
- configFile.getPath(), HOME_DIR, true);
+ final File f = new File(HOME_DIR);
+ repository = new RepositoryWrapper(JcrUtils.getRepository(f.toURI().toString()));
+ adminSession = repository.loginAdministrative(null);
+ }
}
/**
* Stop a repository.
- *
- * @throws NamingException when it is not possible to stop the repository
- * @throws NamingException
*/
public static void stopRepository() throws NamingException {
- RegistryHelper.unregisterRepository(getInitialContext(),
- REPOSITORY_NAME);
+ if ( adminSession != null ) {
+ adminSession.logout();
+ adminSession = null;
+ repository = null;
+ }
}
/**
* Get a repository
*
* @return a JCR repository reference
- * @throws NamingException when it is not possible to get the repository.
- * Before calling this method, the repository has to be
- * registered (@see RepositoryUtil#registerRepository(String,
- * String, String)
- * @throws NamingException
*/
- public static SlingRepository getRepository() throws NamingException {
- return new RepositoryWrapper((Repository) getInitialContext().lookup(
- REPOSITORY_NAME));
+ public static SlingRepository getRepository() {
+ return repository;
}
/**
* Registers node types from the CND file read from the <code>source</code>
* with the node type manager available from the given <code>session</code>.
* <p>
- * The <code>NodeTypeManager</code> returned by the <code>session</code>'s
- * workspace is expected to be of type
- * <code>org.apache.jackrabbit.api.JackrabbitNodeTypeManager</code> for
- * the node type registration to succeed.
- * <p>
* This method is not synchronized. It is up to the calling method to
* prevent paralell execution.
*
@@ -167,36 +144,13 @@
*/
public static boolean registerNodeType(Session session, InputStream source)
throws IOException, RepositoryException {
-
- Workspace workspace = session.getWorkspace();
- NodeTypeManager ntm = workspace.getNodeTypeManager();
- if (ntm instanceof JackrabbitNodeTypeManager) {
- JackrabbitNodeTypeManager jntm = (JackrabbitNodeTypeManager) ntm;
- try {
- jntm.registerNodeTypes(source,
- JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
- return true;
- } catch (RepositoryException re) {
- Throwable t = re.getCause();
- if (t != null
- && t.getClass().getName().endsWith(
- ".InvalidNodeTypeDefException")) {
- // hacky wacky: interpret message to check whether it is for
- // duplicate node type -> very bad, that this is the only
- // way to check !!!
- if (re.getCause().getMessage().indexOf("already exists") >= 0) {
- // alright, node types are already registered, ignore
- // this
- return true;
- }
- }
-
- // get here to rethrow the RepositoryException
- throw re;
- }
+ try {
+ CndImporter.registerNodeTypes(new InputStreamReader(source, "UTF-8"), session);
+ return true;
+ } catch (Exception e) {
+ // ignore
+ return false;
}
-
- return false;
}
public static void registerSlingNodeTypes(Session adminSession) throws IOException, RepositoryException {
@@ -232,7 +186,7 @@
public Session login(Credentials credentials, String workspaceName)
throws LoginException, NoSuchWorkspaceException,
RepositoryException {
- return wrapped.login(credentials, workspaceName);
+ return wrapped.login(credentials, (workspaceName == null ? getDefaultWorkspace() : workspaceName));
}
public Session login(Credentials credentials) throws LoginException,
@@ -242,18 +196,34 @@
public Session login(String workspaceName) throws LoginException,
NoSuchWorkspaceException, RepositoryException {
- return wrapped.login(workspaceName);
+ return wrapped.login((workspaceName == null ? getDefaultWorkspace() : workspaceName));
}
public String getDefaultWorkspace() {
return "default";
}
- public Session loginAdministrative(String workspace)
+ public Session loginAdministrative(String workspaceName)
throws RepositoryException {
final Credentials credentials = new SimpleCredentials(ADMIN_NAME,
ADMIN_PASSWORD.toCharArray());
- return this.login(credentials, workspace);
+ return this.login(credentials, (workspaceName == null ? getDefaultWorkspace() : workspaceName));
+ }
+
+ public Value getDescriptorValue(String key) {
+ return wrapped.getDescriptorValue(key);
+ }
+
+ public Value[] getDescriptorValues(String key) {
+ return wrapped.getDescriptorValues(key);
+ }
+
+ public boolean isSingleValueDescriptor(String key) {
+ return wrapped.isSingleValueDescriptor(key);
+ }
+
+ public boolean isStandardDescriptor(String key) {
+ return wrapped.isStandardDescriptor(key);
}
}
Modified: sling/trunk/bundles/commons/testing/src/main/resources/jackrabbit-test-config.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/resources/jackrabbit-test-config.xml?rev=915386&r1=915385&r2=915386&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/resources/jackrabbit-test-config.xml (original)
+++ sling/trunk/bundles/commons/testing/src/main/resources/jackrabbit-test-config.xml Tue Feb 23 15:30:38 2010
@@ -15,8 +15,16 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.2//EN"
- "http://jackrabbit.apache.org/dtd/repository-1.2.dtd">
+
+<!DOCTYPE Repository
+ PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.0//EN"
+ "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
+
+<!-- Example Repository Configuration File
+ Used by
+ - org.apache.jackrabbit.core.config.RepositoryConfigTest.java
+ -
+-->
<Repository>
<!--
virtual file system where the repository stores global state
@@ -27,20 +35,44 @@
</FileSystem>
<!--
+ data store configuration
+ -->
+ <DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/>
+
+ <!--
security configuration
-->
<Security appName="Jackrabbit">
<!--
+ security manager:
+ class: FQN of class implementing the JackrabbitSecurityManager interface
+ -->
+ <SecurityManager class="org.apache.jackrabbit.core.DefaultSecurityManager" workspaceName="security">
+ <!--
+ workspace access:
+ class: FQN of class implementing the WorkspaceAccessManager interface
+ -->
+ <!-- <WorkspaceAccessManager class="..."/> -->
+ <!-- <param name="config" value="${rep.home}/security.xml"/> -->
+ </SecurityManager>
+
+ <!--
access manager:
class: FQN of class implementing the AccessManager interface
-->
- <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager">
+ <AccessManager class="org.apache.jackrabbit.core.security.DefaultAccessManager">
<!-- <param name="config" value="${rep.home}/access.xml"/> -->
</AccessManager>
- <LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
- <!-- anonymous user name ('anonymous' is the default value) -->
+ <LoginModule class="org.apache.jackrabbit.core.security.authentication.DefaultLoginModule">
+ <!--
+ anonymous user name ('anonymous' is the default value)
+ -->
<param name="anonymousId" value="anonymous"/>
+ <!--
+ administrator user id (default value if param is missing is 'admin')
+ -->
+ <param name="adminId" value="admin"/>
</LoginModule>
</Security>
@@ -52,7 +84,7 @@
workspace configuration template:
used to create the initial workspace if there's no workspace yet
-->
- <Workspace name="Jackrabbit Core">
+ <Workspace name="${wsp.name}">
<!--
virtual file system of the workspace:
class: FQN of class implementing the FileSystem interface
@@ -64,9 +96,9 @@
persistence manager of the workspace:
class: FQN of class implementing the PersistenceManager interface
-->
- <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.DerbyPersistenceManager">
<param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
- <param name="schemaObjectPrefix" value="Jackrabbit Core_"/>
+ <param name="schemaObjectPrefix" value="${wsp.name}_"/>
</PersistenceManager>
<!--
Search index and the file system it uses.
@@ -74,6 +106,7 @@
-->
<SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
<param name="path" value="${wsp.home}/index"/>
+ <param name="supportHighlighting" value="true"/>
</SearchIndex>
</Workspace>
@@ -95,7 +128,7 @@
a 'normal' persistence manager, but this could change in future
implementations.
-->
- <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.DerbyPersistenceManager">
<param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
<param name="schemaObjectPrefix" value="version_"/>
</PersistenceManager>
@@ -107,6 +140,6 @@
-->
<SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
<param name="path" value="${rep.home}/repository/index"/>
+ <param name="supportHighlighting" value="true"/>
</SearchIndex>
</Repository>
-
Added: sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/jcr/RepositoryUtilTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/jcr/RepositoryUtilTest.java?rev=915386&view=auto
==============================================================================
--- sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/jcr/RepositoryUtilTest.java (added)
+++ sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/jcr/RepositoryUtilTest.java Tue Feb 23 15:30:38 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.testing.jcr;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.jcr.Session;
+
+/**
+ * This is a simple test for the repository util. We start
+ * the repository, try to login as admin and anonymous and
+ * then stop the repository.
+ */
+public class RepositoryUtilTest {
+
+ @org.junit.Test public void testRepository() throws Exception {
+ // start the repository
+ RepositoryUtil.startRepository();
+
+ // get admin session
+ final Session adminSession = RepositoryUtil.getRepository().loginAdministrative(null);
+ assertNotNull(adminSession);
+ adminSession.logout();
+
+ // get anonymous session
+ final Session anonSession = RepositoryUtil.getRepository().login();
+ assertNotNull(anonSession);
+ anonSession.logout();
+
+ // stop the repository
+ RepositoryUtil.stopRepository();
+ }
+}
Propchange: sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/jcr/RepositoryUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/jcr/RepositoryUtilTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/bundles/commons/testing/src/test/java/org/apache/sling/commons/testing/jcr/RepositoryUtilTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain