Search in sources :

Example 36 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.

the class GuestIdResource method updateGuests.

@ApiOperation(notes = "Updates the List of Guests on a Consumer This method should work " + "just like updating the consumer, except that it only updates GuestIds. " + " Eventually we should move All the logic here, and depricate updating guests " + "through the consumer update.", value = "updateGuests")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public void updateGuests(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @ApiParam(name = "guestIds", required = true) List<GuestIdDTO> guestIdDTOs) {
    Consumer toUpdate = consumerCurator.findByUuid(consumerUuid);
    // Create a skeleton consumer for consumerResource.performConsumerUpdates
    ConsumerDTO consumer = new ConsumerDTO();
    consumer.setGuestIds(guestIdDTOs);
    Set<String> allGuestIds = new HashSet<>();
    for (GuestIdDTO gid : consumer.getGuestIds()) {
        allGuestIds.add(gid.getGuestId());
    }
    VirtConsumerMap guestConsumerMap = consumerCurator.getGuestConsumersMap(toUpdate.getOwnerId(), allGuestIds);
    GuestMigration guestMigration = migrationProvider.get().buildMigrationManifest(consumer, toUpdate);
    if (consumerResource.performConsumerUpdates(consumer, toUpdate, guestMigration)) {
        if (guestMigration.isMigrationPending()) {
            guestMigration.migrate();
        } else {
            consumerCurator.update(toUpdate);
        }
    }
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) GuestMigration(org.candlepin.resource.util.GuestMigration) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 37 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testIdCertDoesNotRegenerate.

@Test
public void testIdCertDoesNotRegenerate() throws Exception {
    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);
    consumer.setIdCert(createIdCert(TestUtil.createDate(2025, 6, 9)));
    BigInteger origserial = consumer.getIdCert().getSerial().getSerial();
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, ssa, this.mockOwnerServiceAdapter, null, null, null, null, null, null, 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());
    assertEquals(origserial, c.getIdCert().getSerial().getSerial());
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) BigInteger(java.math.BigInteger) ComplianceRules(org.candlepin.policy.js.compliance.ComplianceRules) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) Date(java.util.Date) Test(org.junit.Test)

Example 38 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testFetchAllConsumersForSomeUUIDs.

@Test
public void testFetchAllConsumersForSomeUUIDs() {
    ModelTranslator mockTranslator = mock(ModelTranslator.class);
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, this.config, null, null, null, null, null, null, this.factValidator, new ConsumerTypeValidator(null, null), consumerEnricher, migrationProvider, mockTranslator);
    ArrayList<Consumer> consumers = new ArrayList<>();
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(consumers);
    when(cqmock.iterator()).thenReturn(consumers.iterator());
    when(mockConsumerCurator.searchOwnerConsumers(any(Owner.class), anyString(), (java.util.Collection<ConsumerType>) any(Collection.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class))).thenReturn(cqmock);
    when(mockTranslator.translateQuery(eq(cqmock), eq(ConsumerDTO.class))).thenReturn(cqmock);
    List<String> uuids = new ArrayList<>();
    uuids.add("swiftuuid");
    List<ConsumerDTO> result = cr.list(null, null, null, uuids, null, null, null).list();
    assertEquals(consumers, result);
}
Also used : Owner(org.candlepin.model.Owner) ArrayList(java.util.ArrayList) CandlepinQuery(org.candlepin.model.CandlepinQuery) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerTypeValidator(org.candlepin.resource.util.ConsumerTypeValidator) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) List(java.util.List) ModelTranslator(org.candlepin.dto.ModelTranslator) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Example 39 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testCreatePersonConsumerWithActivationKey.

@Test(expected = BadRequestException.class)
public void testCreatePersonConsumerWithActivationKey() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
    ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
    Owner owner = this.createOwner();
    Consumer consumer = this.createConsumer(owner, ctype);
    ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
    ActivationKey ak = mock(ActivationKey.class);
    NoAuthPrincipal nap = mock(NoAuthPrincipal.class);
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    ConsumerContentOverrideCurator ccoc = mock(ConsumerContentOverrideCurator.class);
    when(ak.getId()).thenReturn("testKey");
    when(akc.lookupForOwner(eq(owner.getKey()), eq(owner))).thenReturn(ak);
    ConsumerResource cr = new ConsumerResource(null, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, akc, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    cr.create(consumerDto, nap, null, owner.getKey(), "testKey", true);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerContentOverrideCurator(org.candlepin.model.ConsumerContentOverrideCurator) ConsumerType(org.candlepin.model.ConsumerType) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 40 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO 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)

Aggregations

Test (org.junit.Test)70 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)64 Consumer (org.candlepin.model.Consumer)37 UserPrincipal (org.candlepin.auth.UserPrincipal)19 Owner (org.candlepin.model.Owner)19 ConsumerType (org.candlepin.model.ConsumerType)16 HashSet (java.util.HashSet)15 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)15 Principal (org.candlepin.auth.Principal)14 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)13 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)12 Set (java.util.Set)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 TestUtil.createConsumerDTO (org.candlepin.test.TestUtil.createConsumerDTO)8 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)7 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)7 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)7 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)7 Entitlement (org.candlepin.model.Entitlement)5