Search in sources :

Example 1 with EventSink

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

the class OwnerResourceTest method testImportManifestFailure.

@Test
public void testImportManifestFailure() 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);
    when(input.getParts()).thenReturn(parts);
    when(part.getHeaders()).thenReturn(mm);
    when(part.getBody(any(GenericType.class))).thenReturn(archive);
    ImporterException expectedException = new ImporterException("Bad import");
    when(manifestManager.importManifest(eq(owner), any(File.class), any(String.class), any(ConflictOverrides.class))).thenThrow(expectedException);
    try {
        thisOwnerResource.importManifest(owner.getKey(), new String[] {}, input);
        fail("Expected IseException was not thrown");
    } catch (IseException ise) {
    // expected, so we catch and go on.
    }
    verify(manifestManager).recordImportFailure(eq(owner), eq(expectedException), eq("test_file.zip"));
}
Also used : ImporterException(org.candlepin.sync.ImporterException) 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) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) IseException(org.candlepin.common.exceptions.IseException) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Example 2 with EventSink

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

the class OwnerResourceTest method testImportManifestSynchronousSuccess.

@Test
public void testImportManifestSynchronousSuccess() 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);
    when(input.getParts()).thenReturn(parts);
    when(part.getHeaders()).thenReturn(mm);
    when(part.getBody(any(GenericType.class))).thenReturn(archive);
    ImportRecord ir = new ImportRecord(owner);
    when(manifestManager.importManifest(eq(owner), any(File.class), eq("test_file.zip"), any(ConflictOverrides.class))).thenReturn(ir);
    ImportRecord response = thisOwnerResource.importManifest(owner.getKey(), new String[] {}, input);
    assertNotNull(response);
    assertEquals(ir, response);
}
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) ImportRecord(org.candlepin.model.ImportRecord) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Example 3 with EventSink

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

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

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

the class ConsumerResourceTest method testIdCertGetsRegenerated.

@Test
public void testIdCertGetsRegenerated() throws Exception {
    // 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);
    SubscriptionServiceAdapter ssa = Mockito.mock(SubscriptionServiceAdapter.class);
    ComplianceRules rules = Mockito.mock(ComplianceRules.class);
    Consumer consumer = createConsumer(createOwner());
    ComplianceStatus status = new ComplianceStatus();
    when(rules.getStatus(any(Consumer.class), any(Date.class), anyBoolean())).thenReturn(status);
    // cert expires today which will trigger regen
    consumer.setIdCert(createIdCert());
    BigInteger origserial = consumer.getIdCert().getSerial().getSerial();
    when(mockIdSvc.regenerateIdentityCert(consumer)).thenReturn(createIdCert());
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, ssa, this.mockOwnerServiceAdapter, null, mockIdSvc, null, null, sink, eventFactory, null, null, null, null, null, mockOwnerCurator, null, null, rules, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    ConsumerDTO c = cr.getConsumer(consumer.getUuid());
    assertFalse(origserial.equals(c.getIdCert().getSerial().getSerial()));
}
Also used : IdentityCertServiceAdapter(org.candlepin.service.IdentityCertServiceAdapter) Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) BigInteger(java.math.BigInteger) EventSink(org.candlepin.audit.EventSink) ComplianceRules(org.candlepin.policy.js.compliance.ComplianceRules) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) Date(java.util.Date) 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