Search in sources :

Example 6 with CandlepinCommonTestConfig

use of org.candlepin.config.CandlepinCommonTestConfig in project candlepin by candlepin.

the class ConsumerResourceIntegrationTest method testRegenerateEntitlementCertificateWithValidConsumerByEntitlement.

/**
 * Test verifies that list of certs changes after regeneration
 */
@SuppressWarnings("unchecked")
@Test
public void testRegenerateEntitlementCertificateWithValidConsumerByEntitlement() {
    GuestMigration testMigration = new GuestMigration(consumerCurator);
    Provider<GuestMigration> migrationProvider = Providers.of(testMigration);
    ConsumerResource cr = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, null, null, this.entitlementCurator, null, null, null, null, null, null, null, null, this.poolManager, null, null, null, null, null, null, null, null, new CandlepinCommonTestConfig(), null, null, null, mock(ConsumerBindUtil.class), null, null, null, null, consumerEnricher, migrationProvider, this.modelTranslator);
    Response rsp = consumerResource.bind(consumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
    List<EntitlementDTO> resultList = (List<EntitlementDTO>) rsp.getEntity();
    EntitlementDTO ent = resultList.get(0);
    assertEquals(1, ent.getCertificates().size());
    CertificateDTO entCertBefore = ent.getCertificates().iterator().next();
    cr.regenerateEntitlementCertificates(this.consumer.getUuid(), ent.getId(), false);
    Entitlement entWithRefreshedCerts = entitlementCurator.find(ent.getId());
    ent = this.modelTranslator.translate(entWithRefreshedCerts, EntitlementDTO.class);
    assertEquals(1, ent.getCertificates().size());
    CertificateDTO entCertAfter = ent.getCertificates().iterator().next();
    assertFalse(entCertBefore.equals(entCertAfter));
}
Also used : Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) GuestMigration(org.candlepin.resource.util.GuestMigration) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) ConsumerBindUtil(org.candlepin.resource.util.ConsumerBindUtil) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) List(java.util.List) ArrayList(java.util.ArrayList) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 7 with CandlepinCommonTestConfig

use of org.candlepin.config.CandlepinCommonTestConfig in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method init.

@Before
public void init() throws Exception {
    Configuration config = new CandlepinCommonTestConfig();
    this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    testMigration = new GuestMigration(consumerCurator);
    migrationProvider = Providers.of(testMigration);
    this.translator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
    this.resource = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, this.subscriptionService, this.ownerService, null, this.idCertService, null, this.i18n, this.sink, this.eventFactory, null, null, this.userService, poolManager, null, null, this.activationKeyCurator, this.entitler, this.complianceRules, this.deletedConsumerCurator, this.environmentCurator, null, config, null, null, null, this.consumerBindUtil, null, null, new FactValidator(config, this.i18n), null, consumerEnricher, migrationProvider, this.translator);
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class), any(Boolean.class), any(Boolean.class))).thenReturn(new ComplianceStatus(new Date()));
    when(idCertService.regenerateIdentityCert(any(Consumer.class))).thenReturn(new IdentityCertificate());
    when(consumerEventBuilder.setEventData(any(Consumer.class))).thenReturn(consumerEventBuilder);
    when(eventFactory.getEventBuilder(any(Target.class), any(Type.class))).thenReturn(consumerEventBuilder);
}
Also used : FactValidator(org.candlepin.util.FactValidator) Configuration(org.candlepin.common.config.Configuration) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) StandardTranslator(org.candlepin.dto.StandardTranslator) Date(java.util.Date) GuestMigration(org.candlepin.resource.util.GuestMigration) Target(org.candlepin.audit.Event.Target) Type(org.candlepin.audit.Event.Type) ConsumerType(org.candlepin.model.ConsumerType) Consumer(org.candlepin.model.Consumer) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) IdentityCertificate(org.candlepin.model.IdentityCertificate) Before(org.junit.Before)

Example 8 with CandlepinCommonTestConfig

use of org.candlepin.config.CandlepinCommonTestConfig 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);
}
Also used : SubResource(org.candlepin.auth.SubResource) Owner(org.candlepin.model.Owner) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Access(org.candlepin.auth.Access) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 9 with CandlepinCommonTestConfig

use of org.candlepin.config.CandlepinCommonTestConfig in project candlepin by candlepin.

the class ConsumerResourceTest method setUp.

@Before
public void setUp() {
    this.config = new CandlepinCommonTestConfig();
    this.translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, mockOwnerCurator);
    this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    when(eventBuilder.setEventData(any(Consumer.class))).thenReturn(eventBuilder);
    when(eventFactory.getEventBuilder(any(Target.class), any(Type.class))).thenReturn(eventBuilder);
    this.factValidator = new FactValidator(this.config, this.i18n);
    testMigration = new GuestMigration(mockConsumerCurator);
    migrationProvider = Providers.of(testMigration);
}
Also used : FactValidator(org.candlepin.util.FactValidator) GuestMigration(org.candlepin.resource.util.GuestMigration) Target(org.candlepin.audit.Event.Target) Type(org.candlepin.audit.Event.Type) ConsumerType(org.candlepin.model.ConsumerType) Consumer(org.candlepin.model.Consumer) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 10 with CandlepinCommonTestConfig

use of org.candlepin.config.CandlepinCommonTestConfig in project candlepin by candlepin.

the class ConsumerResourceTest method testValidateShareConsumerRequiresRecipientFact.

@Test
public void testValidateShareConsumerRequiresRecipientFact() {
    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);
    c.setFact("foo", "bar");
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("must specify a recipient org");
    consumerResource.create(c, uap, "test-user", "test-owner", null, false);
}
Also used : SubResource(org.candlepin.auth.SubResource) Owner(org.candlepin.model.Owner) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Access(org.candlepin.auth.Access) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Aggregations

CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)14 Before (org.junit.Before)8 StandardTranslator (org.candlepin.dto.StandardTranslator)5 ConsumerType (org.candlepin.model.ConsumerType)5 GuestMigration (org.candlepin.resource.util.GuestMigration)4 Test (org.junit.Test)4 Date (java.util.Date)3 Target (org.candlepin.audit.Event.Target)3 Type (org.candlepin.audit.Event.Type)3 Configuration (org.candlepin.common.config.Configuration)3 Consumer (org.candlepin.model.Consumer)3 Owner (org.candlepin.model.Owner)3 FactValidator (org.candlepin.util.FactValidator)3 Access (org.candlepin.auth.Access)2 SubResource (org.candlepin.auth.SubResource)2 UserPrincipal (org.candlepin.auth.UserPrincipal)2 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)2 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)2 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)2 ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)2