Search in sources :

Example 6 with EventSink

use of org.candlepin.audit.EventSink in project candlepin by candlepin.

the class ConsumerResourceTest method testRegenerateIdCerts.

@Test
public void testRegenerateIdCerts() throws GeneralSecurityException, IOException {
    // using lconsumer simply to avoid hiding consumer. This should
    // get renamed once we refactor this test suite.
    IdentityCertServiceAdapter mockIdSvc = Mockito.mock(IdentityCertServiceAdapter.class);
    EventSink sink = Mockito.mock(EventSinkImpl.class);
    Consumer consumer = createConsumer(createOwner());
    consumer.setIdCert(createIdCert());
    IdentityCertificate ic = consumer.getIdCert();
    assertNotNull(ic);
    when(mockIdSvc.regenerateIdentityCert(consumer)).thenReturn(createIdCert());
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, mockIdSvc, null, null, sink, eventFactory, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    ConsumerDTO fooc = cr.regenerateIdentityCertificates(consumer.getUuid());
    assertNotNull(fooc);
    CertificateDTO ic1 = fooc.getIdCert();
    assertNotNull(ic1);
    assertFalse(ic.getId().equals(ic1.getId()));
}
Also used : IdentityCertServiceAdapter(org.candlepin.service.IdentityCertServiceAdapter) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) EventSink(org.candlepin.audit.EventSink) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 7 with EventSink

use of org.candlepin.audit.EventSink in project candlepin by candlepin.

the class OwnerResourceTest method testImportManifestAsyncSuccess.

@Test
public void testImportManifestAsyncSuccess() throws IOException, ImporterException {
    ManifestManager manifestManager = mock(ManifestManager.class);
    EventSink es = mock(EventSink.class);
    OwnerResource thisOwnerResource = new OwnerResource(ownerCurator, productCurator, null, null, i18n, es, eventFactory, null, null, manifestManager, null, null, null, null, importRecordCurator, null, null, null, null, null, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
    MultipartInput input = mock(MultipartInput.class);
    InputPart part = mock(InputPart.class);
    File archive = mock(File.class);
    List<InputPart> parts = new ArrayList<>();
    parts.add(part);
    MultivaluedMap<String, String> mm = new MultivaluedMapImpl<>();
    List<String> contDis = new ArrayList<>();
    contDis.add("form-data; name=\"upload\"; filename=\"test_file.zip\"");
    mm.put("Content-Disposition", contDis);
    JobDetail job = mock(JobDetail.class);
    when(input.getParts()).thenReturn(parts);
    when(part.getHeaders()).thenReturn(mm);
    when(part.getBody(any(GenericType.class))).thenReturn(archive);
    when(manifestManager.importManifestAsync(eq(owner), any(File.class), eq("test_file.zip"), any(ConflictOverrides.class))).thenReturn(job);
    JobDetail response = thisOwnerResource.importManifestAsync(owner.getKey(), new String[] {}, input);
    assertNotNull(response);
    assertEquals(job, response);
    verify(manifestManager, never()).importManifest(eq(owner), any(File.class), any(String.class), any(ConflictOverrides.class));
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) GenericType(org.jboss.resteasy.util.GenericType) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ArrayList(java.util.ArrayList) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Matchers.anyString(org.mockito.Matchers.anyString) ManifestManager(org.candlepin.controller.ManifestManager) JobDetail(org.quartz.JobDetail) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Example 8 with EventSink

use of org.candlepin.audit.EventSink 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 9 with EventSink

use of org.candlepin.audit.EventSink 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 10 with EventSink

use of org.candlepin.audit.EventSink 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

EventSink (org.candlepin.audit.EventSink)10 Test (org.junit.Test)10 ImportRecord (org.candlepin.model.ImportRecord)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 HashMap (java.util.HashMap)5 ImportRecordCurator (org.candlepin.model.ImportRecordCurator)5 Owner (org.candlepin.model.Owner)5 Subscription (org.candlepin.model.dto.Subscription)5 File (java.io.File)3 ManifestManager (org.candlepin.controller.ManifestManager)3 ConflictOverrides (org.candlepin.sync.ConflictOverrides)3 InputPart (org.jboss.resteasy.plugins.providers.multipart.InputPart)3 MultipartInput (org.jboss.resteasy.plugins.providers.multipart.MultipartInput)3 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)3 GenericType (org.jboss.resteasy.util.GenericType)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)2 Consumer (org.candlepin.model.Consumer)2 IdentityCertServiceAdapter (org.candlepin.service.IdentityCertServiceAdapter)2