Search in sources :

Example 1 with ImportRecordCurator

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

the class ImporterTest method testRecordImportIgnoresUpstreamConsumerIfNotSetOnOwner.

@Test
public void testRecordImportIgnoresUpstreamConsumerIfNotSetOnOwner() {
    String expectedOwnerKey = "TEST_OWNER";
    Owner owner = new Owner(expectedOwnerKey);
    EventSink eventSinkMock = mock(EventSink.class);
    ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
    Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
    Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
    Map<String, Object> data = new HashMap<>();
    data.put("meta", meta);
    data.put("subscriptions", new ArrayList<Subscription>());
    ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
    assertNull(record.getUpstreamConsumer());
    verify(importRecordCurator).create(eq(record));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 2 with ImportRecordCurator

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

the class ImporterTest method testRecordImportSuccess.

@Test
public void testRecordImportSuccess() {
    String expectedOwnerKey = "TEST_OWNER";
    Owner owner = new Owner(expectedOwnerKey);
    EventSink eventSinkMock = mock(EventSink.class);
    ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
    Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
    Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
    List<Subscription> subscriptions = new ArrayList<>();
    Subscription subscription = new Subscription();
    subscriptions.add(subscription);
    Map<String, Object> data = new HashMap<>();
    data.put("meta", meta);
    data.put("subscriptions", subscriptions);
    ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
    assertEquals(meta.getPrincipalName(), record.getGeneratedBy());
    assertEquals(meta.getCreated(), record.getGeneratedDate());
    assertEquals(ImportRecord.Status.SUCCESS, record.getStatus());
    assertEquals(owner.getKey() + " file imported successfully.", record.getStatusMessage());
    assertEquals("test.zip", record.getFileName());
    verify(importRecordCurator).create(eq(record));
    verify(eventSinkMock, never()).emitSubscriptionExpired(subscription);
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 3 with ImportRecordCurator

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

the class ImporterTest method testRecordImportNoActiveSubsFound.

@Test
public void testRecordImportNoActiveSubsFound() {
    String expectedOwnerKey = "TEST_OWNER";
    Owner owner = new Owner(expectedOwnerKey);
    EventSink eventSinkMock = mock(EventSink.class);
    ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
    Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
    Map<String, Object> data = new HashMap<>();
    data.put("subscriptions", new ArrayList<Subscription>());
    ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
    assertEquals(ImportRecord.Status.SUCCESS_WITH_WARNING, record.getStatus());
    assertEquals(owner.getKey() + " file imported successfully." + "No active subscriptions found in the file.", record.getStatusMessage());
    verify(eventSinkMock, never()).emitSubscriptionExpired(any(Subscription.class));
    verify(importRecordCurator).create(eq(record));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) ImportRecord(org.candlepin.model.ImportRecord) Test(org.junit.Test)

Example 4 with ImportRecordCurator

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

the class ImporterTest method testRecordImportExpiredSubsFound.

@Test
public void testRecordImportExpiredSubsFound() {
    String expectedOwnerKey = "TEST_OWNER";
    Owner owner = new Owner(expectedOwnerKey);
    EventSink eventSinkMock = mock(EventSink.class);
    ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
    Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
    Map<String, Object> data = new HashMap<>();
    List<Subscription> subscriptions = new ArrayList<>();
    Subscription subscription1 = new Subscription();
    // expires tomorrow
    subscription1.setEndDate(new Date((new Date()).getTime() + (1000 * 60 * 60 * 24)));
    subscriptions.add(subscription1);
    Subscription subscription2 = new Subscription();
    // expires yesterday
    subscription2.setEndDate(new Date((new Date()).getTime() - (1000 * 60 * 60 * 24)));
    subscriptions.add(subscription2);
    data.put("subscriptions", subscriptions);
    ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
    assertEquals(ImportRecord.Status.SUCCESS_WITH_WARNING, record.getStatus());
    assertEquals(owner.getKey() + " file imported successfully." + "One or more inactive subscriptions found in the file.", record.getStatusMessage());
    verify(eventSinkMock, never()).emitSubscriptionExpired(subscription1);
    verify(eventSinkMock).emitSubscriptionExpired(subscription2);
    verify(importRecordCurator).create(eq(record));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 5 with ImportRecordCurator

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

the class ImporterTest method testRecordImportSetsUpstreamConsumerFromOwner.

@Test
public void testRecordImportSetsUpstreamConsumerFromOwner() {
    String expectedOwnerKey = "TEST_OWNER";
    Owner owner = new Owner(expectedOwnerKey);
    UpstreamConsumer uc = new UpstreamConsumer("uc", owner, new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN), "uuid");
    uc.setContentAccessMode("mode");
    owner.setUpstreamConsumer(uc);
    EventSink eventSinkMock = mock(EventSink.class);
    ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
    Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
    Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
    Map<String, Object> data = new HashMap<>();
    data.put("meta", meta);
    data.put("subscriptions", new ArrayList<Subscription>());
    ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
    ImportUpstreamConsumer iuc = record.getUpstreamConsumer();
    assertNotNull(iuc);
    assertEquals(uc.getOwnerId(), iuc.getOwnerId());
    assertEquals(uc.getName(), iuc.getName());
    assertEquals(uc.getUuid(), iuc.getUuid());
    assertEquals(uc.getType(), iuc.getType());
    assertEquals(uc.getWebUrl(), iuc.getWebUrl());
    assertEquals(uc.getApiUrl(), iuc.getApiUrl());
    assertEquals(uc.getContentAccessMode(), iuc.getContentAccessMode());
    verify(importRecordCurator).create(eq(record));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ImportUpstreamConsumer(org.candlepin.model.ImportUpstreamConsumer) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ImportUpstreamConsumer(org.candlepin.model.ImportUpstreamConsumer) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) ConsumerType(org.candlepin.model.ConsumerType) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)5 EventSink (org.candlepin.audit.EventSink)5 ImportRecord (org.candlepin.model.ImportRecord)5 ImportRecordCurator (org.candlepin.model.ImportRecordCurator)5 Owner (org.candlepin.model.Owner)5 Subscription (org.candlepin.model.dto.Subscription)5 Test (org.junit.Test)5 Date (java.util.Date)4 ArrayList (java.util.ArrayList)2 ConsumerType (org.candlepin.model.ConsumerType)1 ImportUpstreamConsumer (org.candlepin.model.ImportUpstreamConsumer)1 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)1