Search in sources :

Example 11 with ManifestFile

use of org.candlepin.sync.file.ManifestFile in project candlepin by candlepin.

the class ManifestManagerTest method testManifestImportAsync.

@Test
public void testManifestImportAsync() throws Exception {
    Owner owner = TestUtil.createOwner();
    File file = mock(File.class);
    String filename = "manifest.zip";
    ConflictOverrides overrides = new ConflictOverrides(Conflict.DISTRIBUTOR_CONFLICT);
    UserPrincipal principal = TestUtil.createOwnerPrincipal();
    when(principalProvider.get()).thenReturn(principal);
    ManifestFile manifest = mock(ManifestFile.class);
    when(fileService.store(ManifestFileType.IMPORT, file, principal.getName(), owner.getKey())).thenReturn(manifest);
    JobDetail job = manager.importManifestAsync(owner, file, filename, overrides);
    JobDataMap jobData = job.getJobDataMap();
    assertEquals(owner.getKey(), jobData.get("owner_id"));
    assertEquals(JobStatus.TargetType.OWNER, jobData.get("target_type"));
    assertEquals(owner.getKey(), jobData.get("target_id"));
    assertEquals(manifest.getId(), jobData.get("stored_manifest_file_id"));
    assertEquals(filename, jobData.get("uploaded_file_name"));
    ConflictOverrides retrievedOverrides = new ConflictOverrides((String[]) jobData.get("conflict_overrides"));
    assertTrue(retrievedOverrides.isForced(Conflict.DISTRIBUTOR_CONFLICT));
    verify(fileService).store(eq(ManifestFileType.IMPORT), eq(file), eq(principal.getName()), eq(owner.getKey()));
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) Owner(org.candlepin.model.Owner) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) UserPrincipal(org.candlepin.auth.UserPrincipal) ManifestFile(org.candlepin.sync.file.ManifestFile) Test(org.junit.Test)

Aggregations

ManifestFile (org.candlepin.sync.file.ManifestFile)11 Consumer (org.candlepin.model.Consumer)8 Test (org.junit.Test)8 File (java.io.File)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Event (org.candlepin.audit.Event)3 UserPrincipal (org.candlepin.auth.UserPrincipal)3 Cdn (org.candlepin.model.Cdn)3 Transactional (com.google.inject.persist.Transactional)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 Entitlement (org.candlepin.model.Entitlement)2 Owner (org.candlepin.model.Owner)2 ConflictOverrides (org.candlepin.sync.ConflictOverrides)2 ExportCreationException (org.candlepin.sync.ExportCreationException)2 ExportResult (org.candlepin.sync.ExportResult)2 ManifestFileServiceException (org.candlepin.sync.file.ManifestFileServiceException)2