Search in sources :

Example 1 with ConsumerCurator

use of org.candlepin.model.ConsumerCurator in project candlepin by candlepin.

the class OwnerResourceTest method testCreateUeberCertificateFromScratch.

@Test
public void testCreateUeberCertificateFromScratch() {
    Principal principal = setupPrincipal(owner, Access.ALL);
    Owner owner = TestUtil.createOwner();
    UeberCertificate entCert = mock(UeberCertificate.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    EntitlementCurator ec = mock(EntitlementCurator.class);
    CandlepinPoolManager cpm = mock(CandlepinPoolManager.class);
    EntitlementCertificateCurator ecc = mock(EntitlementCertificateCurator.class);
    UeberCertificateCurator uc = mock(UeberCertificateCurator.class);
    UeberCertificateGenerator ucg = mock(UeberCertificateGenerator.class);
    OwnerResource resource = new OwnerResource(oc, pc, null, cc, i18n, null, null, null, null, null, cpm, null, null, null, null, null, ecc, ec, uc, ucg, null, null, null, null, null, null, null, null, null, this.modelTranslator);
    when(oc.lookupByKey(eq("admin"))).thenReturn(owner);
    when(ucg.generate(eq(owner.getKey()), eq(principal))).thenReturn(entCert);
    UeberCertificate result = resource.createUeberCertificate(principal, owner.getKey());
    assertEquals(entCert, result);
}
Also used : EntitlementCurator(org.candlepin.model.EntitlementCurator) OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) ProductCurator(org.candlepin.model.ProductCurator) UeberCertificateCurator(org.candlepin.model.UeberCertificateCurator) EntitlementCertificateCurator(org.candlepin.model.EntitlementCertificateCurator) UeberCertificateGenerator(org.candlepin.model.UeberCertificateGenerator) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) ConsumerCurator(org.candlepin.model.ConsumerCurator) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) Test(org.junit.Test)

Example 2 with ConsumerCurator

use of org.candlepin.model.ConsumerCurator 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)

Example 3 with ConsumerCurator

use of org.candlepin.model.ConsumerCurator in project candlepin by candlepin.

the class ConsumerResourceTest method unbindByInvalidSerialShouldFail.

@Test(expected = NotFoundException.class)
public void unbindByInvalidSerialShouldFail() {
    Consumer consumer = createConsumer(createOwner());
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    when(consumerCurator.verifyAndLookupConsumer(eq("fake uuid"))).thenReturn(consumer);
    when(mockEntitlementCurator.find(any(Serializable.class))).thenReturn(null);
    ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    consumerResource.unbindBySerial("fake uuid", Long.valueOf(1234L));
}
Also used : Serializable(java.io.Serializable) Consumer(org.candlepin.model.Consumer) ConsumerCurator(org.candlepin.model.ConsumerCurator) Test(org.junit.Test)

Example 4 with ConsumerCurator

use of org.candlepin.model.ConsumerCurator in project candlepin by candlepin.

the class ConsumerResourceTest method futureHealing.

@Test
public void futureHealing() throws Exception {
    Owner o = createOwner();
    o.setId(TestUtil.randomString());
    Consumer c = createConsumer(o);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    Entitler e = mock(Entitler.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    ConsumerInstalledProduct cip = mock(ConsumerInstalledProduct.class);
    Set<ConsumerInstalledProduct> products = new HashSet<>();
    products.add(cip);
    when(mockOwnerCurator.findOwnerById(eq(o.getId()))).thenReturn(o);
    when(cip.getProductId()).thenReturn("product-foo");
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq(c.getUuid()))).thenReturn(c);
    ConsumerResource cr = new ConsumerResource(cc, mockConsumerTypeCurator, null, sa, this.mockOwnerServiceAdapter, null, null, null, null, null, null, null, null, null, null, null, mockOwnerCurator, null, e, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    String dtStr = "2011-09-26T18:10:50.184081+00:00";
    Date dt = ResourceDateParser.parseDateString(dtStr);
    cr.bind(c.getUuid(), null, null, null, null, null, false, dtStr, null);
    AutobindData data = AutobindData.create(c, o).on(dt);
    verify(e).bindByProducts(eq(data));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) AutobindData(org.candlepin.resource.dto.AutobindData) Matchers.anyString(org.mockito.Matchers.anyString) Entitler(org.candlepin.controller.Entitler) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) ConsumerCurator(org.candlepin.model.ConsumerCurator) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ConsumerCurator

use of org.candlepin.model.ConsumerCurator in project candlepin by candlepin.

the class ConsumerResourceTest method testProductNoPool.

@Test
public void testProductNoPool() throws Exception {
    Owner o = createOwner();
    o.setId(TestUtil.randomString());
    Consumer c = createConsumer(o);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    Entitler e = mock(Entitler.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    String[] prodIds = { "notthere" };
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(c);
    when(e.bindByProducts(any(AutobindData.class))).thenReturn(null);
    when(mockOwnerCurator.findOwnerById(eq(o.getId()))).thenReturn(o);
    ConsumerResource cr = new ConsumerResource(cc, mockConsumerTypeCurator, null, sa, this.mockOwnerServiceAdapter, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, null, e, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    Response r = cr.bind("fakeConsumer", null, prodIds, null, null, null, false, null, null);
    assertEquals(null, r.getEntity());
}
Also used : Response(javax.ws.rs.core.Response) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) AutobindData(org.candlepin.resource.dto.AutobindData) Matchers.anyString(org.mockito.Matchers.anyString) Entitler(org.candlepin.controller.Entitler) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) ConsumerCurator(org.candlepin.model.ConsumerCurator) Test(org.junit.Test)

Aggregations

ConsumerCurator (org.candlepin.model.ConsumerCurator)7 Test (org.junit.Test)6 Owner (org.candlepin.model.Owner)5 Consumer (org.candlepin.model.Consumer)4 Principal (org.candlepin.auth.Principal)3 EntitlementCurator (org.candlepin.model.EntitlementCurator)3 OwnerCurator (org.candlepin.model.OwnerCurator)3 SubscriptionServiceAdapter (org.candlepin.service.SubscriptionServiceAdapter)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)2 UserPrincipal (org.candlepin.auth.UserPrincipal)2 CandlepinPoolManager (org.candlepin.controller.CandlepinPoolManager)2 Entitler (org.candlepin.controller.Entitler)2 EntitlementCertificateCurator (org.candlepin.model.EntitlementCertificateCurator)2 ProductCurator (org.candlepin.model.ProductCurator)2 UeberCertificate (org.candlepin.model.UeberCertificate)2 UeberCertificateCurator (org.candlepin.model.UeberCertificateCurator)2 UeberCertificateGenerator (org.candlepin.model.UeberCertificateGenerator)2 AutobindData (org.candlepin.resource.dto.AutobindData)2 Serializable (java.io.Serializable)1