Author: andrew.plotnikov
Date: 2012-01-11 06:22:23 -0500 (Wed, 11 Jan 2012)
New Revision: 5441
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestProperty.java
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestInitRepository.java
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestLocationFactory.java
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSessionDataManager.java
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/name/TestJCRPath.java
Log:
EXOJCR-1703: Writed tests to classes PropertyImpl, SessionDataManager, RepositoryImpl,
LocationFactory
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2012-01-11
10:44:54 UTC (rev 5440)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2012-01-11
11:22:23 UTC (rev 5441)
@@ -189,10 +189,14 @@
public boolean canRemoveWorkspace(String workspaceName) throws
NoSuchWorkspaceException
{
if (repositoryContainer.getWorkspaceEntry(workspaceName) == null)
+ {
throw new NoSuchWorkspaceException("No such workspace " +
workspaceName);
+ }
if (workspaceName.equals(config.getSystemWorkspaceName()))
+ {
return false;
+ }
SessionRegistry sessionRegistry =
(SessionRegistry)repositoryContainer.getComponentInstance(SessionRegistry.class);
@@ -287,8 +291,10 @@
final WorkspaceContainer wsContainer =
repositoryContainer.getWorkspaceContainer(workspaceName);
if (wsContainer == null)
+ {
throw new RepositoryException("Workspace " + workspaceName
+ " is not configured. Use RepositoryImpl.configWorkspace()
method");
+ }
repositoryContainer.getWorkspaceContainer(workspaceName).getWorkspaceInitializer().initWorkspace();
SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
@@ -388,7 +394,9 @@
{
if (getState() == OFFLINE)
+ {
LOG.warn("Repository " + getName() + " is OFFLINE.");
+ }
WorkspaceContainer workspaceContainer =
repositoryContainer.getWorkspaceContainer(workspaceName);
if (workspaceContainer == null ||
!workspaceContainer.getWorkspaceInitializer().isWorkspaceInitialized())
@@ -409,7 +417,9 @@
{
if (getState() == OFFLINE)
+ {
LOG.warn("Repository " + getName() + " is OFFLINE.");
+ }
WorkspaceContainer workspaceContainer =
repositoryContainer.getWorkspaceContainer(workspaceName);
if (workspaceContainer == null ||
!workspaceContainer.getWorkspaceInitializer().isWorkspaceInitialized())
@@ -597,7 +607,9 @@
{
if (getState() == OFFLINE)
+ {
LOG.warn("Repository " + getName() + " is OFFLINE.");
+ }
ConversationState state;
@@ -606,9 +618,13 @@
public ConversationState run() throws Exception
{
if (credentials != null)
+ {
return authenticationPolicy.authenticate(credentials);
+ }
else
+ {
return authenticationPolicy.authenticate();
+ }
}
};
try
@@ -653,12 +669,16 @@
{
workspaceName = config.getDefaultWorkspaceName();
if (workspaceName == null)
+ {
throw new NoSuchWorkspaceException("Both workspace and default-workspace
name are null! ");
+ }
}
if (!isWorkspaceInitialized(workspaceName))
+ {
throw new NoSuchWorkspaceException("Workspace '" + workspaceName +
"' not found. "
+ "Probably is not initialized. If so either Initialize it manually or
turn on the RepositoryInitializer");
+ }
SessionFactory sessionFactory =
repositoryContainer.getWorkspaceContainer(workspaceName).getSessionFactory();
return sessionFactory.createSession(state);
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestProperty.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestProperty.java 2012-01-11
10:44:54 UTC (rev 5440)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestProperty.java 2012-01-11
11:22:23 UTC (rev 5441)
@@ -19,6 +19,7 @@
package org.exoplatform.services.jcr.api.reading;
import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.impl.core.PropertyImpl;
import org.exoplatform.services.jcr.impl.core.value.BinaryValue;
import java.io.ByteArrayInputStream;
@@ -27,12 +28,17 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
+import javax.jcr.ItemExistsException;
import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.VersionException;
/**
* Created by The eXo Platform SAS.
@@ -167,6 +173,16 @@
node.setProperty("long", valueFactory.createValue(15l));
assertEquals(15, node.getProperty("long").getLong());
assertEquals(15, node.getProperty("long").getValue().getLong());
+
+ node.setProperty("noLong", "someText");
+ try
+ {
+ node.getProperty("noLong").getLong();
+ fail();
+ }
+ catch (ValueFormatException e)
+ {
+ }
}
public void testGetDouble() throws RepositoryException
@@ -174,6 +190,7 @@
node.setProperty("double", session.getValueFactory().createValue(15));
assertEquals(15, (int)node.getProperty("double").getDouble());
assertEquals(15,
(int)node.getProperty("double").getValue().getDouble());
+
try
{
node.getProperty("multi").getDouble();
@@ -183,6 +200,15 @@
{
}
+ node.setProperty("noDouble", "someText");
+ try
+ {
+ node.getProperty("noDouble").getDouble();
+ fail();
+ }
+ catch (ValueFormatException e)
+ {
+ }
}
public void testGetDate() throws RepositoryException
@@ -192,6 +218,16 @@
node.setProperty("date",
session.getValueFactory().createValue(calendar));
assertEquals(calendar.getTimeInMillis(),
node.getProperty("date").getDate().getTimeInMillis());
assertEquals(calendar.getTimeInMillis(),
node.getProperty("date").getValue().getDate().getTimeInMillis());
+
+ node.setProperty("noDate", "someText");
+ try
+ {
+ node.getProperty("noDate").getDate();
+ fail();
+ }
+ catch (ValueFormatException e)
+ {
+ }
}
public void testGetBoolean() throws RepositoryException
@@ -293,8 +329,28 @@
assertEquals(refNode.getPath(),
node1.getProperty("reference").getNode().getPath());
refNode.remove();
- node1.remove();
+ node1.setProperty("noNode", "someText");
+ try
+ {
+ node1.getProperty("noNode").getNode();
+ fail();
+ }
+ catch (ValueFormatException e)
+ {
+ }
+ finally
+ {
+ node1.remove();
+ }
}
-}
+ public void testEquals() throws ItemExistsException, PathNotFoundException,
VersionException,
+ ConstraintViolationException, LockException, RepositoryException
+ {
+ Node testNode = root.addNode("testNode");
+ PropertyImpl testProperty =
(PropertyImpl)testNode.setProperty("testProperty", "someText");
+ assertFalse(testProperty.equals(new Object()));
+
+ }
+}
\ No newline at end of file
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestInitRepository.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestInitRepository.java 2012-01-11
10:44:54 UTC (rev 5440)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestInitRepository.java 2012-01-11
11:22:23 UTC (rev 5441)
@@ -22,12 +22,17 @@
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.access.AccessControlList;
import org.exoplatform.services.jcr.access.SystemIdentity;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ExtendedNode;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.security.MembershipEntry;
+import java.util.ArrayList;
+
import javax.jcr.NamespaceRegistry;
+import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -86,7 +91,6 @@
public void testInitRegularWorkspace() throws Exception
{
-
RepositoryService service =
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
RepositoryImpl defRep = (RepositoryImpl)service.getDefaultRepository();
String sysWs = defRep.getSystemWorkspaceName();
@@ -102,7 +106,9 @@
}
}
if (wsName == null)
+ {
fail("not system workspace not found for test!!");
+ }
// TODO
// defRep.initWorkspace(wsName, "nt:unstructured");
@@ -123,7 +129,6 @@
public void testAutoInitRootPermition()
{
-
WorkspaceEntry wsEntry =
(WorkspaceEntry)session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
AccessControlList expectedAcl = new AccessControlList();
@@ -142,6 +147,54 @@
{
fail(e.getLocalizedMessage());
}
+ }
+ public void testCanRemoveWorkspaceWhenWorkspaceNotFound() throws RepositoryException,
+ RepositoryConfigurationException
+ {
+ try
+ {
+ repository.canRemoveWorkspace(" ");
+ fail();
+ }
+ catch (NoSuchWorkspaceException e)
+ {
+ }
}
-}
+
+ public void testCreateWorkspaceWhenWorkspaceHaventConfig()
+ {
+ try
+ {
+ repository.createWorkspace("someWorkspace");
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ }
+ }
+
+ public void testGetSystemSessionWhenWorkspaceNotFound()
+ {
+ try
+ {
+ repository.getSystemSession(" ");
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ }
+ }
+
+ public void testGetDynamicSessionWhenWorkspaceNotFound()
+ {
+ try
+ {
+ repository.getDynamicSession(" ", new
ArrayList<MembershipEntry>());
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ }
+ }
+}
\ No newline at end of file
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestLocationFactory.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestLocationFactory.java 2012-01-11
10:44:54 UTC (rev 5440)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestLocationFactory.java 2012-01-11
11:22:23 UTC (rev 5441)
@@ -20,6 +20,8 @@
import junit.framework.TestCase;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+
import javax.jcr.RepositoryException;
/**
@@ -169,4 +171,42 @@
}
}
-}
+ public void testFormatPathElement() throws RepositoryException
+ {
+ assertEquals("test", factory.formatPathElement(new
QPathEntry("", "test", 0)));
+ }
+
+ public void testParsePathEntryWhenParsNameIsNull()
+ {
+ try
+ {
+ factory.parseJCRName(null);
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ }
+ }
+
+ public void testIsNotLocalName()
+ {
+ try
+ {
+ factory.parseJCRName("");
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ }
+
+ try
+ {
+ factory.parseJCRName(" ");
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ }
+ }
+
+}
\ No newline at end of file
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSessionDataManager.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSessionDataManager.java 2012-01-11
10:44:54 UTC (rev 5440)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSessionDataManager.java 2012-01-11
11:22:23 UTC (rev 5441)
@@ -35,8 +35,14 @@
import java.util.ArrayList;
import java.util.List;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.PathNotFoundException;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.VersionException;
/**
* Created by The eXo Platform SAS.
@@ -378,4 +384,72 @@
assertNotNull(modificationManager.getItemData(QPath.makeChildPath(((NodeImpl)root).getData().getQPath(),
new InternalQName("", "testgetitemNode"))));
}
-}
+
+ public void testIsDeleted() throws ItemExistsException, PathNotFoundException,
VersionException,
+ ConstraintViolationException, LockException, RepositoryException
+ {
+ NodeImpl testNode = (NodeImpl)root.addNode("testNode");
+ String identifier = testNode.getIdentifier();
+ QPath itemPath = testNode.getData().getQPath();
+
+ assertFalse(modificationManager.isDeleted(identifier));
+ assertFalse(modificationManager.isDeleted(itemPath));
+
+ testNode.remove();
+ assertTrue(modificationManager.isDeleted(identifier));
+ assertTrue(modificationManager.isDeleted(itemPath));
+ }
+
+ public void testGetACLWhenNodeIsRoot() throws RepositoryException
+ {
+ NodeImpl rootNode = (NodeImpl)root;
+ assertEquals(rootNode.getACL(),
modificationManager.getACL(rootNode.getData().getQPath()));
+ }
+
+ public void testUpdateWhenStateIsDeleted() throws ItemExistsException,
PathNotFoundException, VersionException,
+ ConstraintViolationException, LockException, RepositoryException
+ {
+ NodeImpl testNode = (NodeImpl)root.addNode("testNode");
+ ItemState state = ItemState.createDeletedState(testNode.getData());
+
+ try
+ {
+ modificationManager.update(state, false);
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ }
+ }
+
+ public void testUpdateStateWhenStateIsDeleted() throws ItemExistsException,
PathNotFoundException, VersionException,
+ ConstraintViolationException, LockException, RepositoryException
+ {
+ NodeImpl testNode = (NodeImpl)root.addNode("testNode");
+ ItemState state = ItemState.createDeletedState(testNode.getData());
+
+ try
+ {
+ modificationManager.updateItemState(state);
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ }
+ }
+
+ public void testRefreshWhenNodeHasModifiedStatus() throws ItemExistsException,
PathNotFoundException,
+ VersionException, ConstraintViolationException, LockException, RepositoryException
+ {
+ NodeImpl testNode = (NodeImpl)root.addNode("testNode");
+
+ try
+ {
+ modificationManager.refresh(testNode.getData());
+ fail();
+ }
+ catch (InvalidItemStateException e)
+ {
+ }
+ }
+}
\ No newline at end of file
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/name/TestJCRPath.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/name/TestJCRPath.java 2012-01-11
10:44:54 UTC (rev 5440)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/name/TestJCRPath.java 2012-01-11
11:22:23 UTC (rev 5441)
@@ -115,4 +115,11 @@
assertEquals("/jcr:node", path.makeAncestorPath(2).getAsString(false));
}
-}
+
+ public void testEquals() throws Exception
+ {
+ JCRPath path = factory.parseAbsPath("/jcr:node/node1[2]/exo:node2");
+ assertFalse(path.equals(null));
+ assertFalse(path.equals(new Object()));
+ }
+}
\ No newline at end of file