use of org.candlepin.dto.rules.v1.ConsumerDTO 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()));
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceTest method testValidateShareConsumerRequiresRecipientPermissions.
@Test
public void testValidateShareConsumerRequiresRecipientPermissions() {
ConsumerType share = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SHARE));
ConsumerTypeDTO shareDto = this.translator.translate(share, ConsumerTypeDTO.class);
OwnerDTO ownerDto = new OwnerDTO().setDisplayName("Test Owner");
ConsumerDTO c = createConsumerDTO("test-consumer", "test-user", ownerDto, shareDto);
ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, i18n, null, null, null, null, null, mockPoolManager, null, mockOwnerCurator, null, null, null, null, null, null, new CandlepinCommonTestConfig(), null, null, null, consumerBindUtil, null, null, factValidator, null, consumerEnricher, migrationProvider, translator);
UserPrincipal uap = mock(UserPrincipal.class);
when(uap.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(Boolean.TRUE);
Owner o = mock(Owner.class);
when(mockOwnerCurator.lookupByKey(any(String.class))).thenReturn(o);
Owner o2 = mock(Owner.class);
c.setRecipientOwnerKey("o2");
when(mockOwnerCurator.lookupByKey(eq("o2"))).thenReturn(o2);
when(uap.canAccess(eq(o2), eq(SubResource.ENTITLEMENTS), eq(Access.CREATE))).thenReturn(Boolean.FALSE);
thrown.expect(NotFoundException.class);
thrown.expectMessage("owner with key");
consumerResource.create(c, uap, "test-user", "test-owner", null, false);
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceTest method testFetchAllConsumersForUser.
@Test
public void testFetchAllConsumersForUser() {
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<ConsumerDTO> result = cr.list("TaylorSwift", null, null, null, null, null, null).list();
assertEquals(consumers, result);
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceTest method testNullPerson.
@Test(expected = NotFoundException.class)
public void testNullPerson() {
Owner owner = this.createOwner();
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
Consumer consumer = this.createConsumer(owner, ctype);
ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
UserServiceAdapter usa = mock(UserServiceAdapter.class);
UserPrincipal up = mock(UserPrincipal.class);
when(up.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
// usa.findByLogin() will return null by default no need for a when
ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, usa, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
cr.create(consumerDto, up, null, owner.getKey(), null, true);
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceTest method testCreateConsumerShouldFailOnMaxLengthOfName.
@Test
public void testCreateConsumerShouldFailOnMaxLengthOfName() {
thrown.expect(BadRequestException.class);
thrown.expectMessage(String.format("Name of the consumer " + "should be shorter than %d characters.", Consumer.MAX_LENGTH_OF_CONSUMER_NAME + 1));
Owner owner = this.createOwner();
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
Consumer consumer = this.createConsumer(owner, ctype);
consumer.setName(RandomStringUtils.randomAlphanumeric(Consumer.MAX_LENGTH_OF_CONSUMER_NAME + 1));
ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
UserPrincipal up = mock(UserPrincipal.class);
ConsumerResource consumerResource = createConsumerResource(mockOwnerCurator);
when(up.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
consumerResource.create(consumerDto, up, null, owner.getKey(), null, false);
}
Aggregations