Search in sources :

Example 6 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class ManifestManagerTest method testManifestImport.

@Test
public void testManifestImport() throws Exception {
    Owner owner = TestUtil.createOwner();
    File file = mock(File.class);
    String filename = "manifest.zip";
    ConflictOverrides overrides = new ConflictOverrides(Conflict.DISTRIBUTOR_CONFLICT);
    manager.importManifest(owner, file, filename, overrides);
    verify(importer).loadExport(eq(owner), eq(file), eq(overrides), eq(filename));
    verifyNoMoreInteractions(fileService);
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) Owner(org.candlepin.model.Owner) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) Test(org.junit.Test)

Example 7 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class ManifestManagerTest method testImportStoredManifestThrowsBadRequestWhenManifestNotFound.

@Test(expected = BadRequestException.class)
public void testImportStoredManifestThrowsBadRequestWhenManifestNotFound() throws Exception {
    Owner owner = TestUtil.createOwner();
    String fileId = "1234";
    String filename = "manifest.zip";
    ConflictOverrides overrides = new ConflictOverrides(Conflict.DISTRIBUTOR_CONFLICT);
    when(fileService.get(eq(fileId))).thenReturn(null);
    manager.importStoredManifest(owner, fileId, overrides, filename);
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) Owner(org.candlepin.model.Owner) Test(org.junit.Test)

Example 8 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class ImportJob method toExecute.

@Override
public void toExecute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap map = context.getMergedJobDataMap();
    String ownerKey = (String) map.get(JobStatus.TARGET_ID);
    ConflictOverrides overrides = new ConflictOverrides((String[]) map.get(CONFLICT_OVERRIDES));
    String storedFileId = (String) map.get(STORED_FILE_ID);
    String uploadedFileName = (String) map.get(UPLOADED_FILE_NAME);
    Throwable caught = null;
    Owner targetOwner = null;
    try {
        targetOwner = ownerCurator.lookupByKey(ownerKey);
        if (targetOwner == null) {
            throw new NotFoundException(String.format("Owner %s was not found.", ownerKey));
        }
        ImportRecord importRecord = manifestManager.importStoredManifest(targetOwner, storedFileId, overrides, uploadedFileName);
        context.setResult(importRecord);
    }// info about the exception that was thrown (CandlepinException).
     catch (SyncDataFormatException e) {
        caught = new BadRequestException(e.getMessage(), e);
    } catch (ImporterException e) {
        caught = new IseException(e.getMessage(), e);
    } catch (Exception e) {
        caught = e;
    }
    if (caught != null) {
        log.error("ImportJob encountered a problem.", caught);
        manifestManager.recordImportFailure(targetOwner, caught, uploadedFileName);
        context.setResult(caught.getMessage());
        // If an exception was thrown, the importer's transaction was rolled
        // back. We want to make sure that the file gets deleted so that it
        // doesn't take up disk space. It may be possible that the file was
        // already deleted, but we attempt it anyway.
        manifestManager.deleteStoredManifest(storedFileId);
        throw new JobExecutionException(caught.getMessage(), caught, false);
    }
}
Also used : ImporterException(org.candlepin.sync.ImporterException) ConflictOverrides(org.candlepin.sync.ConflictOverrides) JobDataMap(org.quartz.JobDataMap) Owner(org.candlepin.model.Owner) SyncDataFormatException(org.candlepin.sync.SyncDataFormatException) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ImportRecord(org.candlepin.model.ImportRecord) NotFoundException(org.candlepin.common.exceptions.NotFoundException) SyncDataFormatException(org.candlepin.sync.SyncDataFormatException) JobExecutionException(org.quartz.JobExecutionException) IseException(org.candlepin.common.exceptions.IseException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ImporterException(org.candlepin.sync.ImporterException) JobExecutionException(org.quartz.JobExecutionException) IseException(org.candlepin.common.exceptions.IseException) BadRequestException(org.candlepin.common.exceptions.BadRequestException)

Example 9 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class ImportJobTest method ensureJobExceptionThrownIfOwnerNotFound.

@Test
public void ensureJobExceptionThrownIfOwnerNotFound() throws Exception {
    String archiveFilePath = "/path/to/some/file.zip";
    ConflictOverrides co = new ConflictOverrides();
    String uploadedFileName = "test.zip";
    String expectedMessage = String.format("Owner %s was not found.", owner.getKey());
    JobDetail detail = job.scheduleImport(owner, archiveFilePath, uploadedFileName, co);
    when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(null);
    try {
        job.execute(ctx);
        fail("Expected exception not thrown");
    } catch (JobExecutionException je) {
        Throwable cause = je.getCause();
        assertTrue(cause instanceof NotFoundException);
    }
    verify(ctx).setResult(eq(expectedMessage));
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) JobDetail(org.quartz.JobDetail) JobExecutionException(org.quartz.JobExecutionException) NotFoundException(org.candlepin.common.exceptions.NotFoundException) Test(org.junit.Test)

Example 10 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class ImportJobTest method enusureJobSuccess.

@Test
public void enusureJobSuccess() throws JobExecutionException, ImporterException, IOException {
    String archiveFilePath = "/path/to/some/file.zip";
    ConflictOverrides co = new ConflictOverrides();
    ImportRecord record = new ImportRecord(owner);
    String uploadedFileName = "test.zip";
    JobDetail detail = job.scheduleImport(owner, archiveFilePath, uploadedFileName, co);
    when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(manifestManager.importStoredManifest(eq(owner), any(String.class), any(ConflictOverrides.class), eq(uploadedFileName))).thenReturn(record);
    job.execute(ctx);
    verify(ctx).setResult(eq(record));
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) JobDetail(org.quartz.JobDetail) ImportRecord(org.candlepin.model.ImportRecord) Test(org.junit.Test)

Aggregations

ConflictOverrides (org.candlepin.sync.ConflictOverrides)11 Test (org.junit.Test)8 Owner (org.candlepin.model.Owner)7 JobDetail (org.quartz.JobDetail)5 IseException (org.candlepin.common.exceptions.IseException)3 ImporterException (org.candlepin.sync.ImporterException)3 ManifestFile (org.candlepin.sync.file.ManifestFile)3 JobDataMap (org.quartz.JobDataMap)3 JobExecutionException (org.quartz.JobExecutionException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 File (java.io.File)2 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 CandlepinException (org.candlepin.common.exceptions.CandlepinException)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2