Search in sources :

Example 11 with Owner

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

the class ActivationKeyTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public ActivationKeyDTO populate(ModelTranslator modelTranslator, ActivationKey source, ActivationKeyDTO dest) {
    dest = super.populate(modelTranslator, source, dest);
    dest.setId(source.getId()).setName(source.getName()).setDescription(source.getDescription()).setServiceLevel(source.getServiceLevel()).setAutoAttach(source.isAutoAttach());
    // Process nested objects if we have a model translator to use to the translation...
    if (modelTranslator != null) {
        Owner owner = source.getOwner();
        dest.setOwner(owner != null ? modelTranslator.translate(owner, OwnerDTO.class) : null);
        Set<ActivationKeyPool> pools = source.getPools();
        if (pools != null && !pools.isEmpty()) {
            for (ActivationKeyPool poolEntry : pools) {
                if (poolEntry != null) {
                    dest.addPool(new ActivationKeyDTO.ActivationKeyPoolDTO(poolEntry.getPool().getId(), poolEntry.getQuantity()));
                }
            }
        } else {
            dest.setPools(Collections.<ActivationKeyDTO.ActivationKeyPoolDTO>emptySet());
        }
        Set<Product> products = source.getProducts();
        if (products != null && !products.isEmpty()) {
            for (Product prod : products) {
                if (prod != null) {
                    dest.addProductId(prod.getId());
                }
            }
        } else {
            dest.setProductIds(Collections.<String>emptySet());
        }
        Set<ActivationKeyContentOverride> overrides = source.getContentOverrides();
        if (overrides != null && !overrides.isEmpty()) {
            for (ActivationKeyContentOverride override : overrides) {
                if (override != null) {
                    dest.addContentOverride(new ActivationKeyDTO.ActivationKeyContentOverrideDTO(override.getContentLabel(), override.getName(), override.getValue()));
                }
            }
        } else {
            dest.setContentOverrides(Collections.<ActivationKeyDTO.ActivationKeyContentOverrideDTO>emptySet());
        }
        Release release = source.getReleaseVer();
        if (release != null) {
            dest.setReleaseVersion(release.getReleaseVer());
        }
    }
    return dest;
}
Also used : Owner(org.candlepin.model.Owner) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Product(org.candlepin.model.Product) Release(org.candlepin.model.Release) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride)

Example 12 with Owner

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

the class PinsetterAsyncFilterTest method existingJobMapPrincipal.

@Test
public void existingJobMapPrincipal() {
    List<Permission> permissions = Arrays.asList(new Permission[] { new OwnerPermission(new Owner("test_owner"), Access.ALL) });
    Principal principal = new UserPrincipal("testing", permissions, false);
    when(this.principalProvider.get()).thenReturn(principal);
    JobDataMap map = new JobDataMap();
    map.put("Temp", "something");
    JobDetail detail = newJob(RefreshPoolsJob.class).usingJobData(map).build();
    when(response.getEntity()).thenReturn(detail);
    this.interceptor.postProcess(response);
    Assert.assertSame(principal, detail.getJobDataMap().get(PinsetterJobListener.PRINCIPAL_KEY));
}
Also used : OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Owner(org.candlepin.model.Owner) JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 13 with Owner

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

the class DefaultEntitlementCertServiceAdapterTest method setUp.

@Before
public void setUp() {
    Injector injector = Guice.createInjector(new TestingModules.MockJpaModule(), new TestingModules.ServletEnvironmentModule(), new TestingModules.StandardTest());
    injector.injectMembers(this);
    v3extensionUtil = new X509V3ExtensionUtil(config, entCurator);
    certServiceAdapter = new DefaultEntitlementCertServiceAdapter(mockedPKI, extensionUtil, v3extensionUtil, mock(EntitlementCertificateCurator.class), keyPairCurator, serialCurator, ownerCurator, entCurator, I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK), config, productCurator, this.mockConsumerTypeCurator, this.mockEnvironmentCurator);
    product = TestUtil.createProduct("12345", "a product");
    product.setAttribute(Product.Attributes.VERSION, "version");
    product.setAttribute(Product.Attributes.VARIANT, "variant");
    product.setAttribute(Product.Attributes.TYPE, "SVC");
    product.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
    largeContentProduct = TestUtil.createProduct("67890", "large content product");
    largeContentProduct.setAttribute(Product.Attributes.VERSION, "version");
    largeContentProduct.setAttribute(Product.Attributes.VARIANT, "variant");
    largeContentProduct.setAttribute(Product.Attributes.TYPE, "SVC");
    largeContentProduct.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
    content = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    content.setMetadataExpire(CONTENT_METADATA_EXPIRE);
    content.setRequiredTags(REQUIRED_TAGS);
    kickstartContent = createContent(CONTENT_NAME, CONTENT_ID_KICKSTART, CONTENT_LABEL, CONTENT_TYPE_KICKSTART, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    kickstartContent.setMetadataExpire(CONTENT_METADATA_EXPIRE);
    kickstartContent.setRequiredTags(REQUIRED_TAGS);
    fileContent = createContent(CONTENT_NAME, CONTENT_ID_FILE, CONTENT_LABEL, CONTENT_TYPE_FILE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    fileContent.setMetadataExpire(CONTENT_METADATA_EXPIRE);
    fileContent.setRequiredTags(REQUIRED_TAGS);
    unknownTypeContent = createContent(CONTENT_NAME, CONTENT_ID_UNKNOWN, CONTENT_LABEL, CONTENT_TYPE_UNKNOWN, CONTENT_VENDOR, CONTENT_URL_UNKNOWN_TYPE, CONTENT_GPG_URL, ARCH_LABEL);
    unknownTypeContent.setMetadataExpire(CONTENT_METADATA_EXPIRE);
    unknownTypeContent.setRequiredTags(REQUIRED_TAGS);
    String emptyArches = "";
    noArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, emptyArches);
    superContent = new HashSet<>();
    int index = 0;
    for (String url : testUrls) {
        ++index;
        superContent.add(createContent(CONTENT_NAME + "-" + index, CONTENT_ID + "-" + index, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, url, CONTENT_GPG_URL, ARCH_LABEL));
    }
    largeContent = new HashSet<>();
    index = 0;
    for (String url : largeTestUrls) {
        ++index;
        largeContent.add(createContent(CONTENT_NAME + "-" + index, CONTENT_ID + "-" + index, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, url, CONTENT_GPG_URL, ARCH_LABEL));
    }
    subscription = TestUtil.createSubscription(null, product, new HashSet<>());
    subscription.setId("1");
    subscription.setQuantity(1L);
    largeContentSubscription = TestUtil.createSubscription(null, largeContentProduct, new HashSet<>());
    largeContentSubscription.setId("2");
    largeContentSubscription.setQuantity(1L);
    owner = new Owner();
    owner.setId(TestUtil.randomString());
    when(ownerCurator.findOwnerById(owner.getId())).thenReturn(owner);
    pool = new Pool();
    pool.setQuantity(1L);
    pool.setProduct(product);
    pool.setStartDate(subscription.getStartDate());
    pool.setEndDate(subscription.getEndDate());
    largeContentPool = new Pool();
    largeContentPool.setProduct(largeContentProduct);
    ConsumerType type = new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM);
    type.setId("test-id");
    consumer = new Consumer("Test Consumer", "bob", owner, type);
    consumer.setUuid("test-consumer");
    when(this.mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(type);
    when(this.mockConsumerTypeCurator.find(eq(type.getId()))).thenReturn(type);
    entitlement = new Entitlement();
    entitlement.setQuantity(new Integer(ENTITLEMENT_QUANTITY));
    entitlement.setConsumer(consumer);
    entitlement.setPool(pool);
    entitlement.setOwner(owner);
    largeContentEntitlement = new Entitlement();
    largeContentEntitlement.setQuantity(new Integer(ENTITLEMENT_QUANTITY));
    largeContentEntitlement.setConsumer(consumer);
    largeContentEntitlement.setPool(largeContentPool);
    largeContentEntitlement.setOwner(owner);
    product.addContent(content, false);
    Set empty = new HashSet<String>();
    when(productCurator.getPoolProvidedProductUuids(anyString())).thenReturn(empty);
// when(productAdapter.getProductById(eq(product.getOwner()), eq(product.getId())))
// .thenReturn(product);
// when(productAdapter.getProductById(
// eq(largeContentProduct.getOwner()), eq(largeContentProduct.getId()))
// ).thenReturn(largeContentProduct);
}
Also used : Owner(org.candlepin.model.Owner) Set(java.util.Set) HashSet(java.util.HashSet) Matchers.anyString(org.mockito.Matchers.anyString) TestingModules(org.candlepin.TestingModules) BigInteger(java.math.BigInteger) X509V3ExtensionUtil(org.candlepin.util.X509V3ExtensionUtil) Consumer(org.candlepin.model.Consumer) Injector(com.google.inject.Injector) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 14 with Owner

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

the class DefaultEntitlementCertServiceAdapterTest method createContent.

private Content createContent(String name, String id, String label, String type, String vendor, String url, String gpgUrl, String arches) {
    Owner owner = TestUtil.createOwner("Example-Corporation");
    Content content = TestUtil.createContent(id, name);
    content.setUuid(id + "_uuid");
    content.setLabel(label);
    content.setType(type);
    content.setVendor(vendor);
    content.setContentUrl(url);
    content.setGpgUrl(gpgUrl);
    content.setArches(arches);
    return content;
}
Also used : Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent)

Example 15 with Owner

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

the class DefaultProductServiceAdapterTest method productsByIds.

@Test
public void productsByIds() {
    Owner o = mock(Owner.class);
    List<String> ids = new ArrayList<>();
    CandlepinQuery<Product> ccmock = mock(CandlepinQuery.class);
    ResultIterator<Product> iterator = mock(ResultIterator.class);
    when(opc.getProductsByIds(any(Owner.class), anyCollection())).thenReturn(ccmock);
    when(ccmock.iterate(anyInt(), anyBoolean())).thenReturn(iterator);
    ids.add(someid);
    dpsa.getProductsByIds(o, ids);
    verify(opc).getProductsByIds(eq(o), eq(ids));
}
Also used : Owner(org.candlepin.model.Owner) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Test(org.junit.Test)

Aggregations

Owner (org.candlepin.model.Owner)405 Test (org.junit.Test)254 Product (org.candlepin.model.Product)153 Consumer (org.candlepin.model.Consumer)127 Pool (org.candlepin.model.Pool)79 Date (java.util.Date)72 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)71 ArrayList (java.util.ArrayList)58 Produces (javax.ws.rs.Produces)52 ConsumerType (org.candlepin.model.ConsumerType)52 ApiOperation (io.swagger.annotations.ApiOperation)50 HashSet (java.util.HashSet)44 Entitlement (org.candlepin.model.Entitlement)44 Path (javax.ws.rs.Path)42 HashMap (java.util.HashMap)41 ApiResponses (io.swagger.annotations.ApiResponses)40 Content (org.candlepin.model.Content)39 BadRequestException (org.candlepin.common.exceptions.BadRequestException)37 Subscription (org.candlepin.model.dto.Subscription)32 List (java.util.List)29