Search in sources :

Example 16 with OwnerCurator

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

the class ImporterTest method testImportNoProductDir.

@Test
public void testImportNoProductDir() throws IOException, ImporterException {
    RulesImporter ri = mock(RulesImporter.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    Importer i = new Importer(null, null, ri, oc, null, null, null, null, config, null, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    Owner owner = mock(Owner.class);
    ConflictOverrides co = mock(ConflictOverrides.class);
    Map<String, File> importFiles = getTestImportFiles();
    File ruleDir = mock(File.class);
    File[] rulesFiles = createMockJsFile(mockJsPath);
    when(ruleDir.listFiles()).thenReturn(rulesFiles);
    File actualmeta = createFile("meta.json", "0.0.3", new Date(), "test_user", "prefix");
    // this is the hook to stop testing. we confirm that the archive component tests
    // are passed and then jump out instead of trying to fake the actual file
    // processing.
    doThrow(new RuntimeException("Done with the test")).when(ri).importObject(any(Reader.class));
    importFiles.put(ImportFile.META.fileName(), actualmeta);
    importFiles.put(ImportFile.RULES_FILE.fileName(), rulesFiles[0]);
    importFiles.put(ImportFile.PRODUCTS.fileName(), null);
    importFiles.put(ImportFile.ENTITLEMENTS.fileName(), null);
    importFiles.put(ImportFile.UPSTREAM_CONSUMER.fileName(), mock(File.class));
    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) Reader(java.io.Reader) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 17 with OwnerCurator

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

the class ImporterTest method testImportProductNoEntitlementDir.

@Test
public void testImportProductNoEntitlementDir() throws IOException, ImporterException {
    OwnerCurator oc = mock(OwnerCurator.class);
    Importer i = new Importer(null, null, null, oc, null, null, null, null, config, null, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    Owner owner = mock(Owner.class);
    ConflictOverrides co = mock(ConflictOverrides.class);
    Map<String, File> importFiles = getTestImportFiles();
    importFiles.put(ImportFile.ENTITLEMENTS.fileName(), null);
    String m = i18n.tr("The archive does not contain the " + "required entitlements directory");
    ee.expect(ImporterException.class);
    ee.expectMessage(m);
    i.importObjects(owner, importFiles, co);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Example 18 with OwnerCurator

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

the class ProductExporterTest method testProductExport.

@Test
public void testProductExport() throws IOException {
    ObjectMapper mapper = TestSyncUtils.getTestSyncUtils(new MapConfiguration(new HashMap<String, String>() {

        {
            put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false");
        }
    }));
    ProductExporter exporter = new ProductExporter(new StandardTranslator(new ConsumerTypeCurator(), new EnvironmentCurator(), new OwnerCurator()));
    StringWriter writer = new StringWriter();
    Owner owner = TestUtil.createOwner("Example-Corporation");
    Product product = TestUtil.createProduct("my-id", "product name");
    exporter.export(mapper, writer, product);
    String s = writer.toString();
    assertTrue(s.contains("\"name\":\"product name\""));
    assertTrue(s.contains("\"id\":\"my-id\""));
    assertTrue(s.contains("\"productContent\":[]"));
    assertTrue(s.contains("\"attributes\":[]"));
    assertTrue(s.contains("\"multiplier\":1"));
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ConsumerTypeCurator(org.candlepin.model.ConsumerTypeCurator) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) Product(org.candlepin.model.Product) EnvironmentCurator(org.candlepin.model.EnvironmentCurator) StandardTranslator(org.candlepin.dto.StandardTranslator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 19 with OwnerCurator

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

the class SubscriptionReconcilerTest method init.

@Before
public void init() {
    this.owner = new Owner();
    this.reconciler = new SubscriptionReconciler(this.poolCurator);
    this.translator = new StandardTranslator(new ConsumerTypeCurator(), new EnvironmentCurator(), new OwnerCurator());
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    this.importer = new EntitlementImporter(certSerialCurator, cdnCurator, i18n, pc, ec, translator);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ConsumerTypeCurator(org.candlepin.model.ConsumerTypeCurator) EnvironmentCurator(org.candlepin.model.EnvironmentCurator) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 20 with OwnerCurator

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

the class OwnerProductResourceTest method testDeleteProductWithSubscriptions.

@Test(expected = BadRequestException.class)
public void testDeleteProductWithSubscriptions() {
    OwnerCurator oc = mock(OwnerCurator.class);
    OwnerProductCurator opc = mock(OwnerProductCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    I18n i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    OwnerProductResource pr = new OwnerProductResource(config, i18n, oc, null, opc, null, pc, null, this.modelTranslator);
    Owner o = mock(Owner.class);
    Product p = mock(Product.class);
    when(oc.lookupByKey(eq("owner"))).thenReturn(o);
    when(opc.getProductById(eq(o), eq("10"))).thenReturn(p);
    Set<Subscription> subs = new HashSet<>();
    Subscription s = mock(Subscription.class);
    subs.add(s);
    when(pc.productHasSubscriptions(eq(o), eq(p))).thenReturn(true);
    pr.deleteProduct("owner", "10");
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) OwnerProductCurator(org.candlepin.model.OwnerProductCurator) ProductCurator(org.candlepin.model.ProductCurator) Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription) OwnerProductCurator(org.candlepin.model.OwnerProductCurator) I18n(org.xnap.commons.i18n.I18n) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

OwnerCurator (org.candlepin.model.OwnerCurator)21 Owner (org.candlepin.model.Owner)20 Test (org.junit.Test)19 ProductCurator (org.candlepin.model.ProductCurator)9 File (java.io.File)8 ImportFile (org.candlepin.sync.Importer.ImportFile)8 Principal (org.candlepin.auth.Principal)4 Date (java.util.Date)3 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)3 UserPrincipal (org.candlepin.auth.UserPrincipal)3 CandlepinPoolManager (org.candlepin.controller.CandlepinPoolManager)3 ActivationKeyDTO (org.candlepin.dto.api.v1.ActivationKeyDTO)3 ConsumerCurator (org.candlepin.model.ConsumerCurator)3 ConsumerType (org.candlepin.model.ConsumerType)3 ConsumerTypeCurator (org.candlepin.model.ConsumerTypeCurator)3 Product (org.candlepin.model.Product)3 Reader (java.io.Reader)2 HashMap (java.util.HashMap)2 StandardTranslator (org.candlepin.dto.StandardTranslator)2 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)2