Search in sources :

Example 6 with ExporterMetadataCurator

use of org.candlepin.model.ExporterMetadataCurator in project candlepin by candlepin.

the class ImporterTest method firstRun.

@Test
public void firstRun() throws Exception {
    File f = createFile("meta", "0.0.3", new Date(), "test_user", "prefix");
    File actualmeta = createFile("meta.json", "0.0.3", new Date(), "test_user", "prefix");
    ExporterMetadataCurator emc = mock(ExporterMetadataCurator.class);
    when(emc.lookupByType(ExporterMetadata.TYPE_SYSTEM)).thenReturn(null);
    Importer i = new Importer(null, null, null, null, null, null, null, null, null, emc, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    i.validateMetadata(ExporterMetadata.TYPE_SYSTEM, null, actualmeta, new ConflictOverrides());
    assertTrue(f.delete());
    assertTrue(actualmeta.delete());
    verify(emc).create(any(ExporterMetadata.class));
}
Also used : ExporterMetadataCurator(org.candlepin.model.ExporterMetadataCurator) ExporterMetadata(org.candlepin.model.ExporterMetadata) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 7 with ExporterMetadataCurator

use of org.candlepin.model.ExporterMetadataCurator in project candlepin by candlepin.

the class ImporterTest method sameImport.

@Test
public void sameImport() throws Exception {
    // actualmeta is the mock for the import itself
    Date date = getDateBeforeDays(10);
    File actualmeta = createFile("meta.json", "0.0.3", date, "test_user", "prefix");
    ExporterMetadataCurator emc = mock(ExporterMetadataCurator.class);
    // emc is the mock for lastrun (i.e., the most recent import in CP)
    ExporterMetadata em = new ExporterMetadata();
    // exact same date = assumed same manifest
    em.setExported(date);
    em.setId("42");
    em.setType(ExporterMetadata.TYPE_SYSTEM);
    when(emc.lookupByType(ExporterMetadata.TYPE_SYSTEM)).thenReturn(em);
    Importer i = new Importer(null, null, null, null, null, null, null, null, null, emc, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    try {
        i.validateMetadata(ExporterMetadata.TYPE_SYSTEM, null, actualmeta, new ConflictOverrides());
        fail();
    } catch (ImportConflictException e) {
        assertFalse(e.message().getConflicts().isEmpty());
        assertEquals(1, e.message().getConflicts().size());
        assertTrue(e.message().getConflicts().contains(Importer.Conflict.MANIFEST_SAME));
    }
}
Also used : ExporterMetadataCurator(org.candlepin.model.ExporterMetadataCurator) ExporterMetadata(org.candlepin.model.ExporterMetadata) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 8 with ExporterMetadataCurator

use of org.candlepin.model.ExporterMetadataCurator in project candlepin by candlepin.

the class ImporterTest method testImportNoDistributorVersions.

@Test
public void testImportNoDistributorVersions() throws IOException, ImporterException {
    RulesImporter ri = mock(RulesImporter.class);
    doNothing().when(ri).importObject(any(Reader.class));
    ExporterMetadataCurator emc = mock(ExporterMetadataCurator.class);
    // this is the hook to stop testing. we confirm that the dist version null test
    // is passed and then jump out instead of trying to fake the actual file
    // processing.
    doThrow(new RuntimeException("Done with the test")).when(emc).lookupByTypeAndOwner(any(String.class), any(Owner.class));
    OwnerCurator oc = mock(OwnerCurator.class);
    Owner owner = mock(Owner.class);
    ConflictOverrides co = mock(ConflictOverrides.class);
    Map<String, File> importFiles = createAndSetImportFiles();
    Importer i = new Importer(null, null, ri, oc, null, null, null, null, config, emc, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    ee.expect(RuntimeException.class);
    ee.expectMessage("Done with the test");
    i.importObjects(owner, importFiles, co);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ExporterMetadataCurator(org.candlepin.model.ExporterMetadataCurator) Reader(java.io.Reader) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)8 ExporterMetadataCurator (org.candlepin.model.ExporterMetadataCurator)8 ImportFile (org.candlepin.sync.Importer.ImportFile)8 Test (org.junit.Test)8 Date (java.util.Date)6 ExporterMetadata (org.candlepin.model.ExporterMetadata)6 Owner (org.candlepin.model.Owner)2 OwnerCurator (org.candlepin.model.OwnerCurator)2 Reader (java.io.Reader)1 HashMap (java.util.HashMap)1 PoolManager (org.candlepin.controller.PoolManager)1 Refresher (org.candlepin.controller.Refresher)1 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)1 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)1 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)1 ConsumerType (org.candlepin.model.ConsumerType)1 Entitlement (org.candlepin.model.Entitlement)1 Pool (org.candlepin.model.Pool)1 Product (org.candlepin.model.Product)1 Subscription (org.candlepin.model.dto.Subscription)1