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));
}
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);
}
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));
}
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));
}
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));
}
Aggregations