Search in sources :

Example 56 with ConsumerType

use of org.candlepin.model.ConsumerType 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);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) UserServiceAdapter(org.candlepin.service.UserServiceAdapter) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 57 with ConsumerType

use of org.candlepin.model.ConsumerType 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);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 58 with ConsumerType

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

the class ConsumerResourceVirtEntitlementTest method setUp.

@Before
public void setUp() {
    List<Subscription> subscriptions = new ArrayList<>();
    subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    manifestType = consumerTypeCurator.create(new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN));
    systemType = consumerTypeCurator.create(new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM));
    owner = ownerCurator.create(new Owner("test-owner"));
    ownerCurator.create(owner);
    manifestConsumer = TestUtil.createConsumer(manifestType, owner);
    consumerCurator.create(manifestConsumer);
    systemConsumer = TestUtil.createConsumer(systemType, owner);
    consumerCurator.create(systemConsumer);
    // create a physical pool with numeric virt_limit
    productLimit = TestUtil.createProduct();
    productLimit.setAttribute(Product.Attributes.VIRT_LIMIT, "10");
    productLimit.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    productLimit = this.createProduct(productLimit, owner);
    Subscription limitSub = TestUtil.createSubscription(owner, productLimit, new HashSet<>());
    limitSub.setId(Util.generateDbUUID());
    limitSub.setQuantity(10L);
    limitSub.setStartDate(TestUtil.createDate(2010, 1, 1));
    limitSub.setEndDate(TestUtil.createDate(2020, 1, 1));
    limitSub.setModified(TestUtil.createDate(2000, 1, 1));
    subscriptions.add(limitSub);
    limitPools = poolManager.createAndEnrichPools(limitSub);
    // create a physical pool with unlimited virt_limit
    productUnlimit = TestUtil.createProduct();
    productUnlimit.setAttribute(Product.Attributes.VIRT_LIMIT, "unlimited");
    productUnlimit.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    productUnlimit = this.createProduct(productUnlimit, owner);
    Subscription unlimitSub = TestUtil.createSubscription(owner, productUnlimit, new HashSet<>());
    unlimitSub.setId(Util.generateDbUUID());
    unlimitSub.setQuantity(10L);
    unlimitSub.setStartDate(TestUtil.createDate(2010, 1, 1));
    unlimitSub.setEndDate(TestUtil.createDate(2020, 1, 1));
    unlimitSub.setModified(TestUtil.createDate(2000, 1, 1));
    subscriptions.add(unlimitSub);
    unlimitPools = poolManager.createAndEnrichPools(unlimitSub);
}
Also used : Owner(org.candlepin.model.Owner) ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) ArrayList(java.util.ArrayList) Subscription(org.candlepin.model.dto.Subscription) ConsumerType(org.candlepin.model.ConsumerType) Before(org.junit.Before)

Example 59 with ConsumerType

use of org.candlepin.model.ConsumerType 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 60 with ConsumerType

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

the class UndoImportsJobTest method testUndoImport.

@Test
public void testUndoImport() throws JobExecutionException, IOException, ImporterException {
    // We need proper curators for this test
    this.poolManager = this.poolManagerBase;
    this.ownerCurator = super.ownerCurator;
    this.exportCurator = this.exportCuratorBase;
    this.undoImportsJob = new UndoImportsJob(this.i18n, this.ownerCurator, this.poolManager, this.subAdapter, this.exportCurator, this.importRecordCurator);
    // Create owner w/upstream consumer
    Owner owner1 = TestUtil.createOwner();
    Owner owner2 = TestUtil.createOwner();
    ConsumerType type = this.createConsumerType();
    UpstreamConsumer uc1 = new UpstreamConsumer("uc1", null, type, "uc1");
    UpstreamConsumer uc2 = new UpstreamConsumer("uc2", null, type, "uc2");
    this.ownerCurator.create(owner1);
    this.ownerCurator.create(owner2);
    owner1.setUpstreamConsumer(uc1);
    owner1.setUpstreamConsumer(uc2);
    this.ownerCurator.merge(owner1);
    this.ownerCurator.merge(owner2);
    // Create metadata
    ExporterMetadata metadata1 = new ExporterMetadata(ExporterMetadata.TYPE_PER_USER, new Date(), owner1);
    ExporterMetadata metadata2 = new ExporterMetadata(ExporterMetadata.TYPE_PER_USER, new Date(), owner2);
    this.exportCurator.create(metadata1);
    this.exportCurator.create(metadata2);
    // Create pools w/upstream pool IDs
    Pool pool1 = this.createPool("pool1", owner1, true, PoolType.NORMAL);
    Pool pool2 = this.createPool("pool2", owner1, true, PoolType.BONUS);
    Pool pool3 = this.createPool("pool3", owner1, false, PoolType.NORMAL);
    Pool pool4 = this.createPool("pool4", owner1, false, PoolType.BONUS);
    Pool pool5 = this.createPool("pool5", owner1, true, PoolType.ENTITLEMENT_DERIVED);
    Pool pool6 = this.createPool("pool6", owner1, false, PoolType.ENTITLEMENT_DERIVED);
    Pool pool7 = this.createPool("pool7", owner2, true, PoolType.NORMAL);
    Pool pool8 = this.createPool("pool8", owner2, true, PoolType.BONUS);
    Pool pool9 = this.createPool("pool9", owner2, true, PoolType.ENTITLEMENT_DERIVED);
    // Create an ueber certificate for the owner.
    UeberCertificate uebercert = ueberCertGenerator.generate(owner1.getKey(), this.setupAdminPrincipal("test_admin"));
    assertNotNull(uebercert);
    // Verify initial state
    assertEquals(Arrays.asList(pool1, pool2, pool3, pool4, pool5, pool6), this.poolManager.listPoolsByOwner(owner1).list());
    assertEquals(Arrays.asList(pool7, pool8, pool9), this.poolManager.listPoolsByOwner(owner2).list());
    assertEquals(metadata1, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner1));
    assertEquals(metadata2, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner2));
    assertEquals(0, this.importRecordCurator.findRecords(owner1).list().size());
    assertEquals(0, this.importRecordCurator.findRecords(owner2).list().size());
    // Execute job
    Principal principal = new UserPrincipal("JarJarBinks", null, true);
    this.jobDataMap.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
    this.jobDataMap.put(JobStatus.TARGET_ID, owner1.getId());
    this.jobDataMap.put(UndoImportsJob.OWNER_KEY, owner1.getKey());
    this.jobDataMap.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
    // since we locking owner we need start transaction
    beginTransaction();
    this.undoImportsJob.toExecute(this.jobContext);
    commitTransaction();
    // Verify deletions -- Ueber pools should not get deleted.
    assertEquals(Arrays.asList(pool3, pool4, pool5, pool6), this.poolManager.listPoolsByOwner(owner1).list());
    assertEquals(Arrays.asList(pool7, pool8, pool9), this.poolManager.listPoolsByOwner(owner2).list());
    assertNull(exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner1));
    assertEquals(metadata2, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner2));
    assertNull(owner1.getUpstreamConsumer());
    List<ImportRecord> records = this.importRecordCurator.findRecords(owner1).list();
    assertEquals(1, records.size());
    assertEquals(ImportRecord.Status.DELETE, records.get(0).getStatus());
    assertEquals(0, this.importRecordCurator.findRecords(owner2).list().size());
}
Also used : Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) ExporterMetadata(org.candlepin.model.ExporterMetadata) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16