Search in sources :

Example 1 with TransactionCancelledException

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();
    }
}
Also used : CollectionObject(edu.unc.lib.boxc.model.api.objects.CollectionObject) TransactionCancelledException(edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException) ObjectTypeMismatchException(edu.unc.lib.boxc.model.api.exceptions.ObjectTypeMismatchException) PID(edu.unc.lib.boxc.model.api.ids.PID) FolderObject(edu.unc.lib.boxc.model.api.objects.FolderObject) ModelCom(org.apache.jena.rdf.model.impl.ModelCom) Test(org.junit.Test)

Example 2 with 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();
}
Also used : TransactionCancelledException(edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Logger(ch.qos.logback.classic.Logger) TransactionCancelledException(edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException) AccessRestrictionException(edu.unc.lib.boxc.auth.api.exceptions.AccessRestrictionException) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before)

Example 3 with TransactionCancelledException

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);
}
Also used : TransactionCancelledException(edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException) IngestContentObjectsJob(edu.unc.lib.boxc.deposit.fcrepo4.IngestContentObjectsJob) SelfReturningAnswer(edu.unc.lib.boxc.common.test.SelfReturningAnswer) Resource(org.apache.jena.rdf.model.Resource) PID(edu.unc.lib.boxc.model.api.ids.PID) StorageLocation(edu.unc.lib.boxc.persist.api.storage.StorageLocation) File(java.io.File) URI(java.net.URI) TransactionCancelledException(edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException) JobInterruptedException(edu.unc.lib.boxc.deposit.work.JobInterruptedException) FedoraException(edu.unc.lib.boxc.model.api.exceptions.FedoraException) AccessRestrictionException(edu.unc.lib.boxc.auth.api.exceptions.AccessRestrictionException) ChecksumMismatchException(edu.unc.lib.boxc.fcrepo.exceptions.ChecksumMismatchException) JobFailedException(edu.unc.lib.boxc.deposit.work.JobFailedException) FcrepoOperationFailedException(org.fcrepo.client.FcrepoOperationFailedException) PremisEventBuilder(edu.unc.lib.boxc.operations.api.events.PremisEventBuilder) Before(org.junit.Before)

Example 4 with TransactionCancelledException

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());
    }
}
Also used : TransactionCancelledException(edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException) FcrepoResponse(org.fcrepo.client.FcrepoResponse) FedoraTransaction(edu.unc.lib.boxc.fcrepo.utils.FedoraTransaction) Model(org.apache.jena.rdf.model.Model) RDFModelUtil.createModel(edu.unc.lib.boxc.model.api.rdf.RDFModelUtil.createModel) Resource(org.apache.jena.rdf.model.Resource) ResourceFactory.createResource(org.apache.jena.rdf.model.ResourceFactory.createResource) PID(edu.unc.lib.boxc.model.api.ids.PID) Test(org.junit.Test)

Example 5 with TransactionCancelledException

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);
    });
}
Also used : RepositoryObject(edu.unc.lib.boxc.model.api.objects.RepositoryObject) BinaryTransferSession(edu.unc.lib.boxc.persist.api.transfer.BinaryTransferSession) Resource(org.apache.jena.rdf.model.Resource) PID(edu.unc.lib.boxc.model.api.ids.PID) Matchers.anyString(org.mockito.Matchers.anyString) TransactionCancelledException(edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException) TransactionCancelledException(edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) Before(org.junit.Before)

Aggregations

TransactionCancelledException (edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException)7 PID (edu.unc.lib.boxc.model.api.ids.PID)6 Before (org.junit.Before)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 SelfReturningAnswer (edu.unc.lib.boxc.common.test.SelfReturningAnswer)3 PremisEventBuilder (edu.unc.lib.boxc.operations.api.events.PremisEventBuilder)3 Resource (org.apache.jena.rdf.model.Resource)3 AccessRestrictionException (edu.unc.lib.boxc.auth.api.exceptions.AccessRestrictionException)2 CollectionObject (edu.unc.lib.boxc.model.api.objects.CollectionObject)2 FolderObject (edu.unc.lib.boxc.model.api.objects.FolderObject)2 WorkObject (edu.unc.lib.boxc.model.api.objects.WorkObject)2 File (java.io.File)2 Test (org.junit.Test)2 Logger (ch.qos.logback.classic.Logger)1 IngestContentObjectsJob (edu.unc.lib.boxc.deposit.fcrepo4.IngestContentObjectsJob)1 JobFailedException (edu.unc.lib.boxc.deposit.work.JobFailedException)1 JobInterruptedException (edu.unc.lib.boxc.deposit.work.JobInterruptedException)1 ChecksumMismatchException (edu.unc.lib.boxc.fcrepo.exceptions.ChecksumMismatchException)1 FedoraTransaction (edu.unc.lib.boxc.fcrepo.utils.FedoraTransaction)1 FedoraException (edu.unc.lib.boxc.model.api.exceptions.FedoraException)1