Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for unversioned fedora nodes. #160

Merged
merged 1 commit into from Nov 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,12 +39,15 @@ public class VersionService extends RepositoryService {

private static final Logger logger = getLogger(VersionService.class);

protected static final String VERSIONABLE = "mix:versionable";

@Autowired
TransactionService txService;

/**
* Creates a version checkpoint for the given path. This is the equivalent
* of VersionManager#checkpoint(path), except that it is aware of
* Creates a version checkpoint for the given path if versioning is enabled
* for that node type. When versioning is enabled this is the equivalent of
* VersionManager#checkpoint(path), except that it is aware of
* TxSessions and queues these operations accordingly.
*
* @param session
Expand All @@ -53,14 +56,18 @@ public class VersionService extends RepositoryService {
* @throws RepositoryException
*/
public void checkpoint(final Session session, String absPath) throws RepositoryException {
logger.trace("Setting checkpoint for {}", absPath);
if (session.getNode(absPath).isNodeType(VERSIONABLE)) {
logger.trace("Setting checkpoint for {}", absPath);

String txId = TransactionService.getCurrentTransactionId(session);
if (txId != null) {
Transaction tx = txService.getTransaction(txId);
tx.addPathToVersion(absPath);
String txId = TransactionService.getCurrentTransactionId(session);
if (txId != null) {
Transaction tx = txService.getTransaction(txId);
tx.addPathToVersion(absPath);
} else {
session.getWorkspace().getVersionManager().checkpoint(absPath);
}
} else {
session.getWorkspace().getVersionManager().checkpoint(absPath);
logger.trace("No checkpoint set for unversionable {}", absPath);
}
}
}
Expand Up @@ -19,7 +19,9 @@
import org.fcrepo.kernel.Transaction;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.Workspace;
import javax.jcr.version.VersionManager;
Expand All @@ -41,53 +43,90 @@ public class VersionServiceTest {

private TransactionService txService;

@Mock
private Session s;

@Mock
private VersionManager mockVM;

@Before
public void setup() throws Exception {
txService = new TransactionService();
initMocks(this);
testObj = new VersionService();
testObj.txService = txService;
}

@Test
public void testCheckpoint() throws Exception {
Session s = mock(Session.class);
s = mock(Session.class);
final Workspace mockWorkspace = mock(Workspace.class);
when(mockWorkspace.getName()).thenReturn("default");
when(s.getWorkspace()).thenReturn(mockWorkspace);
final VersionManager mockVM = mock(VersionManager.class);
mockVM = mock(VersionManager.class);
when(mockWorkspace.getVersionManager()).thenReturn(mockVM);

// add a node that's versioned
Node versionedNode = mock(Node.class);
when(versionedNode.isNodeType(VersionService.VERSIONABLE)).thenReturn(true);
when(s.getNode("/example-versioned")).thenReturn(versionedNode);

// add a node that's unversioned
Node unversionedNode = mock(Node.class);
when(unversionedNode.isNodeType(VersionService.VERSIONABLE)).thenReturn(false);
when(s.getNode("/example-unversioned")).thenReturn(unversionedNode);
}

@Test
public void testCheckpoint() throws Exception {
// request a version be created
testObj.checkpoint(s, "/example-versioned");

// ensure that it was
verify(mockVM, only()).checkpoint("/example-versioned");
}

@Test
public void testCheckpointUnversioned() throws Exception {
// request a version be created
testObj.checkpoint(s, "/example");
testObj.checkpoint(s, "/example-unversioned");

// ensure that it was
verify(mockVM, only()).checkpoint("/example");
verify(mockVM, never()).checkpoint("/example-unversioned");
}

@Test
public void testDeferredCheckpoint() throws Exception {
Session s = mock(Session.class);
final Workspace mockWorkspace = mock(Workspace.class);
when(mockWorkspace.getName()).thenReturn("default");
when(s.getWorkspace()).thenReturn(mockWorkspace);
final VersionManager mockVM = mock(VersionManager.class);
when(mockWorkspace.getVersionManager()).thenReturn(mockVM);
// start a transaction
Transaction t = txService.beginTransaction(s);
s = t.getSession();

// request a version be created
testObj.checkpoint(s, "/example-versioned");

// ensure that no version was created (because the transaction is still open)
verify(mockVM, never()).checkpoint("/example-versioned");

// close the transaction
txService.commit(t.getId());

// ensure that the version was made
verify(mockVM, only()).checkpoint("/example-versioned");
}

@Test
public void testDeferredCheckpointUnversioned() throws Exception {
// start a transaction
Transaction t = txService.beginTransaction(s);
s = t.getSession();

// request a version be created
testObj.checkpoint(s, "/example");
testObj.checkpoint(s, "/example-unversioned");

// ensure that no version was created (because the transaction is still open)
verify(mockVM, never()).checkpoint("/example");
verify(mockVM, never()).checkpoint("/example-unversioned");

// close the transaction
txService.commit(t.getId());

// ensure that the version was made
verify(mockVM, only()).checkpoint("/example");
verify(mockVM, never()).checkpoint("/example-unversioned");
}
}