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);
}
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);
}
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);
}
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\"}]" + "}]}";
}
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());
}
Aggregations