Package org.candlepin.model

Examples of org.candlepin.model.Consumer


        assertTrue(status.getPartialStacks().containsKey(STACK_ID_1));
    }

    @Test
    public void validRangeConsidersInvalidGapBetweenNonStackedAndPartialEntitlement() {
        Consumer c = mockConsumer(PRODUCT_1);

        Calendar cal = Calendar.getInstance();
        Date now = cal.getTime();
        DateRange range1 = rangeRelativeToDate(now, -4, -2);
        DateRange range2 = rangeRelativeToDate(now, -3, 2);
        DateRange range3 = rangeRelativeToDate(now, -1, 4);

        c.addEntitlement(mockEntitlement(c, PRODUCT_1, range1, PRODUCT_1));
        c.addEntitlement(mockStackedEntitlement(c, range3, STACK_ID_1, PRODUCT_1, 1,
            PRODUCT_1));
        c.addEntitlement(mockStackedEntitlement(c, range2, STACK_ID_1, PRODUCT_1, 1,
            PRODUCT_1));

        List<Entitlement> ents = new LinkedList<Entitlement>(c.getEntitlements());
        mockEntCurator(c, ents);

        ComplianceStatus status = compliance.getStatus(c, now);
        ConsumerInstalledProductEnricher calculator =
            new ConsumerInstalledProductEnricher(c, status, compliance);
View Full Code Here


        assertEquals(range2.getEndDate(), validRange.getEndDate());
    }

    @Test
    public void validRangeConsidersInvalidGapBetweenNonStackedEntitlement() {
        Consumer c = mockConsumer(PRODUCT_1);

        Calendar cal = Calendar.getInstance();
        Date now = cal.getTime();
        DateRange range1 = rangeRelativeToDate(now, -4, -2);
        DateRange range2 = rangeRelativeToDate(now, -3, 2);
        DateRange range3 = rangeRelativeToDate(now, -1, 4);

        c.addEntitlement(mockEntitlement(c, PRODUCT_1, range1, PRODUCT_1));
        c.addEntitlement(mockStackedEntitlement(c, range2, STACK_ID_1, PRODUCT_1, 1,
            PRODUCT_1));
        c.addEntitlement(mockEntitlement(c, PRODUCT_1, range3, PRODUCT_1));

        List<Entitlement> ents = new LinkedList<Entitlement>(c.getEntitlements());
        mockEntCurator(c, ents);

        ComplianceStatus status = compliance.getStatus(c, now);
        ConsumerInstalledProductEnricher calculator =
            new ConsumerInstalledProductEnricher(c, status, compliance);
View Full Code Here

        assertEquals(range3.getEndDate(), validRange.getEndDate());
    }

    @Test
    public void validRangeConsidersNonStackingEntNotCoveringMachineSocketsInvalid() {
        Consumer c = mockConsumer(PRODUCT_1);

        Calendar cal = Calendar.getInstance();
        Date now = cal.getTime();
        DateRange range1 = rangeRelativeToDate(now, -4, 4);
        DateRange range2 = rangeRelativeToDate(now, -2, 6);

        Entitlement ent = mockEntitlement(c, PRODUCT_1, range1, PRODUCT_1);
        ent.getPool().setProductAttribute("sockets", "2", PRODUCT_1);
        c.addEntitlement(ent);

        c.addEntitlement(mockEntitlement(c, PRODUCT_1, range2, PRODUCT_1));

        List<Entitlement> ents = new LinkedList<Entitlement>(c.getEntitlements());
        mockEntCurator(c, ents);

        ComplianceStatus status = compliance.getStatus(c, now);
        ConsumerInstalledProductEnricher calculator =
            new ConsumerInstalledProductEnricher(c, status, compliance);
View Full Code Here

        assertEquals(range2.getEndDate(), validRange.getEndDate());
    }

    @Test
    public void validRangeWhenGuestLimitOverridden() {
        Consumer c = mockConsumer(PRODUCT_1);
        for (int i = 0; i < 5; i++) {
            c.addGuestId(new GuestId("" + i, c, getActiveGuestAttrs()));
        }

        Calendar cal = Calendar.getInstance();
        Date now = cal.getTime();
        DateRange range = rangeRelativeToDate(now, -4, 4);

        DateRange hypervisorRange = rangeRelativeToDate(now, -2, 2);

        Entitlement ent = mockStackedEntitlement(c, range, STACK_ID_1, PRODUCT_1, 10, PRODUCT_1);
        ent.getPool().setProductAttribute("guest_limit", "2", PRODUCT_1);
        c.addEntitlement(ent);
        Entitlement hpvsrEnt = mockStackedEntitlement(c, hypervisorRange,
            "other_stack_id", "other", 10, "prod2");
        hpvsrEnt.getPool().setProductAttribute("guest_limit", "-1", "prod2");
        c.addEntitlement(hpvsrEnt);

        List<Entitlement> ents = new LinkedList<Entitlement>(c.getEntitlements());
        mockEntCurator(c, ents);

        ComplianceStatus status = compliance.getStatus(c, now);
        assertEquals("valid", status.getStatus());
        ConsumerInstalledProductEnricher calculator =
View Full Code Here

        return e;
    }

    private Consumer mockConsumer(String ... installedProducts) {
        Consumer c = new Consumer();
        c.setType(new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM));
        for (String pid : installedProducts) {
            c.addInstalledProduct(new ConsumerInstalledProduct(pid, pid));
        }
        c.setFact("cpu.cpu_socket(s)", "4");
        return c;
    }
View Full Code Here

        assertEquals(serial2, certificates.get(1).getSerial().getId());
    }

    @Test
    public void testCreateConsumer() {
        Consumer toSubmit = new Consumer(CONSUMER_NAME, USER_NAME, null,
            standardSystemType);
        toSubmit.getFacts().put(METADATA_NAME, METADATA_VALUE);
        Consumer submitted = consumerResource.create(
            toSubmit,
            new UserPrincipal(someuser.getUsername(), Arrays.asList(new Permission [] {
                new OwnerPermission(owner, Access.ALL) }), false),
            someuser.getUsername(),
            owner.getKey(), null);

        assertNotNull(submitted);
        assertNotNull(consumerCurator.find(submitted.getId()));
        assertEquals(standardSystemType.getLabel(), submitted.getType()
            .getLabel());
        assertEquals(METADATA_VALUE, submitted.getFact(METADATA_NAME));
    }
View Full Code Here

        assertEquals(METADATA_VALUE, submitted.getFact(METADATA_NAME));
    }

    @Test
    public void testCreateConsumerVsDefaultServiceLevelForOwner() {
        Consumer toSubmit = new Consumer(CONSUMER_NAME, USER_NAME, null,
            standardSystemType);
        Consumer submitted = consumerResource.create(
            toSubmit,
            new UserPrincipal(someuser.getUsername(), Arrays.asList(new Permission [] {
                new OwnerPermission(owner, Access.ALL) }), false),
            someuser.getUsername(),
            owner.getKey(), null);

        assertEquals(DEFAULT_SERVICE_LEVEL, submitted.getServiceLevel());

    }
View Full Code Here

    }

    @Test(expected = BadRequestException.class)
    public void testCreateConsumerWithUUID() {
        String uuid = "Jar Jar Binks";
        Consumer toSubmit = new Consumer(CONSUMER_NAME, USER_NAME, null,
            standardSystemType);
        assertNull(toSubmit.getId());
        toSubmit.setUuid(uuid);
        toSubmit.getFacts().put(METADATA_NAME, METADATA_VALUE);

        Consumer submitted = consumerResource.create(toSubmit, principal, null,
                owner.getKey(), null);
        assertNotNull(submitted);
        assertNotNull(submitted.getId());
        assertNotNull(consumerCurator.find(submitted.getId()));
        assertNotNull(consumerCurator.findByUuid(uuid));
        assertEquals(standardSystemType.getLabel(), submitted.getType()
            .getLabel());
        assertEquals(METADATA_VALUE, submitted.getFact(METADATA_NAME));
        assertEquals("The Uuids do not match", uuid, submitted.getUuid());

        // The second post should fail because of constraint failures
        Consumer anotherToSubmit = new Consumer(CONSUMER_NAME, USER_NAME, null,
            standardSystemType);
        anotherToSubmit.setUuid(uuid);
        anotherToSubmit.getFacts().put(METADATA_NAME, METADATA_VALUE);
        anotherToSubmit.setId(null);
        consumerResource.create(anotherToSubmit, principal, null, owner.getKey(), null);
    }
View Full Code Here

        anotherToSubmit.setId(null);
        consumerResource.create(anotherToSubmit, principal, null, owner.getKey(), null);
    }

    public void testDeleteResource() {
        Consumer created = consumerCurator.create(new Consumer(CONSUMER_NAME,
            USER_NAME, owner, standardSystemType));
        consumerResource.deleteConsumer(consumer.getUuid(), principal);

        assertNull(consumerCurator.find(created.getId()));
    }
View Full Code Here

    @Test
    public void testUsername() throws IOException, GeneralSecurityException {

        // not setting the username here - this should be set by
        // examining the user principal
        Consumer consumer = new Consumer("random-consumer", null, null,
            standardSystemType);

        consumer = consumerResource.create(consumer, principal, null, null,
            null);

        assertEquals(USER_NAME, consumer.getUsername());
    }
View Full Code Here

TOP

Related Classes of org.candlepin.model.Consumer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.