use of edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException in project box-c by UNC-Libraries.
the class AddContainerServiceTest method addCollectionToFolderTest.
@Test(expected = TransactionCancelledException.class)
public void addCollectionToFolderTest() {
FolderObject folder = mock(FolderObject.class);
CollectionObject collection = mock(CollectionObject.class);
when(repoObjLoader.getRepositoryObject(eq(parentPid))).thenReturn(folder);
when(repoObjFactory.createCollectionObject(any(PID.class), any(ModelCom.class))).thenReturn(collection);
doThrow(new ObjectTypeMismatchException("")).when(folder).addMember(collection);
try {
service.addContainer(createRequest("collection", false, ResourceType.Collection));
} catch (TransactionCancelledException e) {
assertEquals(ObjectTypeMismatchException.class, e.getCause().getClass());
throw new TransactionCancelledException();
}
}
use of edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException in project box-c by UNC-Libraries.
the class MoveObjectsServiceTest method init.
@Before
public void init() throws Exception {
initMocks(this);
service = new MoveObjectsService();
service.setAclService(aclService);
service.setRepositoryObjectLoader(repositoryObjectLoader);
service.setTransactionManager(transactionManager);
service.setOperationsMessageSender(operationsMessageSender);
service.setObjectPathFactory(objectPathFactory);
sourcePid = makePid();
when(mockParent.getPid()).thenReturn(sourcePid);
destPid = makePid();
when(repositoryObjectLoader.getRepositoryObject(destPid)).thenReturn(mockDestObj);
when(transactionManager.startTransaction()).thenReturn(mockTx);
doAnswer(new Answer<Exception>() {
@Override
public Exception answer(InvocationOnMock invocation) throws Throwable {
throw new TransactionCancelledException("", invocation.getArgumentAt(0, Exception.class));
}
}).when(mockTx).cancel(any(Exception.class));
when(mockQueryExec.execSelect()).thenReturn(mockResultSet);
when(mockResultSet.nextSolution()).thenReturn(mockQuerySolution);
when(mockQuerySolution.getResource("parent")).thenReturn(mockParentResource);
when(mockAgent.getUsername()).thenReturn("user");
when(mockAgent.getPrincipals()).thenReturn(mockAccessSet);
when(destObjPath.toNamePath()).thenReturn(DEST_OBJ_PATH);
when(objectPathFactory.getPath(eq(destPid))).thenReturn(destObjPath);
when(sourceObjPath.toNamePath()).thenReturn(SOURCE_OBJ_PATH);
when(objectPathFactory.getPath(eq(sourcePid))).thenReturn(sourceObjPath);
// Adding retrievable logger for move log
Logger actionLogger = (Logger) LoggerFactory.getLogger("moves");
actionAppender = new ListAppender<>();
actionLogger.setLevel(Level.INFO);
actionLogger.addAppender(actionAppender);
actionAppender.start();
}
use of edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException in project box-c by UNC-Libraries.
the class IngestContentObjectsJobTest method init.
@Before
public void init() throws Exception {
job = new IngestContentObjectsJob();
job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "premisLoggerFactory", mockPremisLoggerFactory);
setField(job, "aclService", aclService);
setField(job, "depositModelManager", depositModelManager);
setField(job, "depositsDirectory", depositsDirectory);
setField(job, "depositStatusFactory", depositStatusFactory);
setField(job, "jobStatusFactory", jobStatusFactory);
setField(job, "metricsClient", metricsClient);
setField(job, "pidMinter", pidMinter);
setField(job, "repoObjLoader", repoObjLoader);
setField(job, "repoObjFactory", repoObjFactory);
setField(job, "fcrepoClient", fcrepoClient);
setField(job, "txManager", txManager);
setField(job, "verificationService", verificationService);
setField(job, "transferService", binaryTransferService);
setField(job, "locationManager", storageLocationManager);
setField(job, "updateDescService", updateDescService);
setField(job, "depositModelManager", depositModelManager);
job.init();
depositPid = job.getDepositPID();
setupDestination();
FileUtils.copyDirectory(new File("src/test/resources/examples"), depositDir);
storageLocPath = tmpFolder.newFolder("storageLoc").toPath();
// Setup logging dependencies
mockPremisEventBuilder = mock(PremisEventBuilder.class, new SelfReturningAnswer());
when(mockPremisLoggerFactory.createPremisLogger(any())).thenReturn(mockPremisLogger);
when(mockPremisLoggerFactory.createPremisLogger(any(PID.class), any(File.class))).thenReturn(mockPremisLogger);
when(mockPremisLogger.buildEvent(any(Resource.class))).thenReturn(mockPremisEventBuilder);
when(mockFileObj.getOriginalFile()).thenReturn(mockBinaryObj);
// Get a writeable model
model = job.getWritableModel();
depBag = model.createBag(depositPid.getRepositoryPath());
when(fcrepoClient.head(any(URI.class))).thenReturn(headBuilder);
when(txManager.startTransaction()).thenReturn(mockTx);
doThrow(new TransactionCancelledException()).when(mockTx).cancel(any(Exception.class));
depBag.addProperty(Cdr.storageLocation, LOC1_ID);
when(storageLocationManager.getStorageLocationById(anyString())).thenReturn(storageLocation);
when(binaryTransferService.getSession(any(StorageLocation.class))).thenReturn(mockTransferSession);
}
use of edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException in project box-c by UNC-Libraries.
the class TransactionalFcrepoClientIT method testPutTriplesWithTx.
@Test
public void testPutTriplesWithTx() throws Exception {
fcrepoClient = TransactionalFcrepoClient.client(BASE_PATH).build();
txManager.setClient(fcrepoClient);
PID pid = PIDs.get(UUID.randomUUID().toString());
Model model = ModelFactory.createDefaultModel();
Resource resc = model.getResource(pid.getRepositoryPath());
resc.addLiteral(DC.title, "My Title");
FedoraTransaction tx = txManager.startTransaction();
createAndVerifyObjectWithBody(pid.getRepositoryUri(), model);
try {
tx.cancel();
} catch (TransactionCancelledException e) {
// Expected
}
// Verify that the created resource went away with transaction
try (FcrepoResponse response = fcrepoClient.get(pid.getRepositoryUri()).perform()) {
assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatusCode());
}
FedoraTransaction tx2 = txManager.startTransaction();
createAndVerifyObjectWithBody(pid.getRepositoryUri(), model);
tx2.close();
try (FcrepoResponse response = fcrepoClient.get(pid.getRepositoryUri()).perform()) {
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}
}
use of edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException in project box-c by UNC-Libraries.
the class AbstractDepositJobTest method initBase.
@Before
public void initBase() throws Exception {
initMocks(this);
TestHelper.setContentBase(FEDORA_BASE);
when(premisLoggerFactory.createPremisLogger(any(PID.class), any(File.class))).thenReturn(premisLogger);
when(premisLoggerFactory.createPremisLogger(any(RepositoryObject.class), any(BinaryTransferSession.class))).thenReturn(premisLogger);
when(premisLogger.buildEvent(any(Resource.class))).thenReturn(premisEventBuilder);
when(premisEventBuilder.addEventDetail(anyString(), Matchers.<Object>anyVararg())).thenReturn(premisEventBuilder);
when(premisEventBuilder.addSoftwareAgent(any(PID.class))).thenReturn(premisEventBuilder);
when(premisEventBuilder.create()).thenReturn(testResource);
tmpFolder.create();
depositsDirectory = tmpFolder.newFolder("deposits");
jobUUID = UUID.randomUUID().toString();
depositUUID = UUID.randomUUID().toString();
depositDir = new File(depositsDirectory, depositUUID);
depositDir.mkdir();
depositPid = PIDs.get(RepositoryPathConstants.DEPOSIT_RECORD_BASE, depositUUID);
depositModelManager = DepositModelManager.inMemoryManager();
when(txManager.startTransaction()).thenReturn(tx);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
throw new TransactionCancelledException("Tx cancelled", invocation.getArgumentAt(0, Exception.class));
}
}).when(tx).cancel(any(Exception.class));
completedIds = new HashSet<>();
when(depositStatusFactory.getState(anyString())).thenReturn(DepositState.running);
doAnswer(invocation -> {
String objId = invocation.getArgumentAt(1, String.class);
completedIds.add(objId);
return null;
}).when(jobStatusFactory).addObjectCompleted(anyString(), anyString());
when(jobStatusFactory.objectIsCompleted(anyString(), anyString())).thenAnswer(invocation -> {
String objId = invocation.getArgumentAt(1, String.class);
return completedIds.contains(objId);
});
}
Aggregations