Search in sources :

Example 1 with GuestMigration

use of org.candlepin.resource.util.GuestMigration 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 2 with GuestMigration

use of org.candlepin.resource.util.GuestMigration 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 3 with GuestMigration

use of org.candlepin.resource.util.GuestMigration in project candlepin by candlepin.

the class ConsumerResourceTest method testCheckForGuestsMigrationCertList.

@Test
public void testCheckForGuestsMigrationCertList() {
    Consumer consumer = createConsumer(createOwner());
    List<EntitlementCertificate> certificates = createEntitlementCertificates();
    when(mockEntitlementCertServiceAdapter.listForConsumer(consumer)).thenReturn(certificates);
    when(mockConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockEntitlementCurator.listByConsumer(consumer)).thenReturn(new ArrayList<>());
    GuestMigration migrationSpy = Mockito.spy(testMigration);
    migrationProvider = Providers.of(migrationSpy);
    ConsumerResource consumerResource = Mockito.spy(new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, null, null, null, null, null, null, mockPoolManager, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, mockContentAccessCertService, this.factValidator, null, consumerEnricher, migrationProvider, translator));
    Set<Long> serials = new HashSet<>();
    List<CertificateDTO> certs = consumerResource.getEntitlementCertificates(consumer.getUuid(), "123");
    verify(consumerResource).revokeOnGuestMigration(consumer);
}
Also used : GuestMigration(org.candlepin.resource.util.GuestMigration) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) Consumer(org.candlepin.model.Consumer) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with GuestMigration

use of org.candlepin.resource.util.GuestMigration 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 5 with GuestMigration

use of org.candlepin.resource.util.GuestMigration in project candlepin by candlepin.

the class HypervisorUpdateJobTest method init.

@Before
public void init() {
    super.init();
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.READ_PROPERTIES | I18nFactory.FALLBACK);
    owner = mock(Owner.class);
    principal = mock(Principal.class);
    ownerCurator = mock(OwnerCurator.class);
    consumerCurator = mock(ConsumerCurator.class);
    consumerResource = mock(ConsumerResource.class);
    consumerTypeCurator = mock(ConsumerTypeCurator.class);
    subAdapter = mock(SubscriptionServiceAdapter.class);
    complianceRules = mock(ComplianceRules.class);
    when(owner.getId()).thenReturn("joe");
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.HYPERVISOR);
    ctype.setId("test-ctype");
    when(consumerTypeCurator.lookupByLabel(eq(ConsumerTypeEnum.HYPERVISOR.getLabel()))).thenReturn(ctype);
    when(consumerTypeCurator.lookupByLabel(eq(ConsumerTypeEnum.HYPERVISOR.getLabel()), anyBoolean())).thenReturn(ctype);
    when(owner.getKey()).thenReturn("joe");
    when(principal.getUsername()).thenReturn("joe user");
    testMigration = new GuestMigration(consumerCurator);
    migrationProvider = Providers.of(testMigration);
    hypervisorJson = "{\"hypervisors\":" + "[{" + "\"name\" : \"hypervisor_999\"," + "\"hypervisorId\" : {\"hypervisorId\":\"uuid_999\"}," + "\"guestIds\" : [{\"guestId\" : \"guestId_1_999\"}]" + "}]}";
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) GuestMigration(org.candlepin.resource.util.GuestMigration) Owner(org.candlepin.model.Owner) ConsumerTypeCurator(org.candlepin.model.ConsumerTypeCurator) ConsumerResource(org.candlepin.resource.ConsumerResource) ComplianceRules(org.candlepin.policy.js.compliance.ComplianceRules) ConsumerType(org.candlepin.model.ConsumerType) Principal(org.candlepin.auth.Principal) ConsumerCurator(org.candlepin.model.ConsumerCurator) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) Before(org.junit.Before)

Aggregations

GuestMigration (org.candlepin.resource.util.GuestMigration)12 Consumer (org.candlepin.model.Consumer)10 ConsumerType (org.candlepin.model.ConsumerType)6 Before (org.junit.Before)6 StandardTranslator (org.candlepin.dto.StandardTranslator)5 Owner (org.candlepin.model.Owner)5 Date (java.util.Date)4 CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)4 FactValidator (org.candlepin.util.FactValidator)4 HashSet (java.util.HashSet)3 Target (org.candlepin.audit.Event.Target)3 Type (org.candlepin.audit.Event.Type)3 ComplianceStatus (org.candlepin.policy.js.compliance.ComplianceStatus)3 Transactional (com.google.inject.persist.Transactional)2 ApiOperation (io.swagger.annotations.ApiOperation)2 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Produces (javax.ws.rs.Produces)2 Principal (org.candlepin.auth.Principal)2