use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method multiEntGreenNowYellowFutureWithOverlap.
@Test
public void multiEntGreenNowYellowFutureWithOverlap() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, 12);
DateRange range2 = this.rangeRelativeToDate(now, 11, 24);
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range2, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range1.getStartDate(), cip.getStartDate());
assertEquals(range1.getEndDate(), cip.getEndDate());
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeIgnoresFutureBackToBack.
@Test
public void validRangeIgnoresFutureBackToBack() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, 12, 24);
DateRange range2 = this.rangeRelativeToDate(now, 0, 12);
consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range2, product));
consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range2.getStartDate(), cip.getStartDate());
assertEquals(range1.getEndDate(), cip.getEndDate());
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeCorrectPartialEntitlementNoGap.
@Test
public void validRangeCorrectPartialEntitlementNoGap() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, 4);
DateRange range2 = this.rangeRelativeToDate(now, 4, 9);
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range2, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range1.getStartDate(), cip.getStartDate());
assertEquals(range2.getEndDate(), cip.getEndDate());
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeEndDateSetToFirstDateOfLosingValidStatus.
@Test
public void validRangeEndDateSetToFirstDateOfLosingValidStatus() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, 4);
DateRange range2 = this.rangeRelativeToDate(now, -2, 10);
DateRange range3 = this.rangeRelativeToDate(now, -3, -1);
DateRange range4 = this.rangeRelativeToDate(range1.getEndDate(), 0, 10);
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range2, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range3, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range4, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range3.getStartDate(), cip.getStartDate());
assertEquals(range2.getEndDate(), cip.getEndDate());
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class VerifyAuthorizationFilterTest method noAccessToOtherConsumer.
@Test(expected = ForbiddenException.class)
public void noAccessToOtherConsumer() throws Exception {
mockReq = MockHttpRequest.create("POST", "http://localhost/candlepin/fake/123");
ResteasyProviderFactory.pushContext(HttpRequest.class, mockReq);
mockReq.setAttribute(ResteasyProviderFactory.class.getName(), ResteasyProviderFactory.getInstance());
Consumer c = createConsumer(createOwner());
Consumer c2 = createConsumer(createOwner());
methodInjector.setArguments(new Object[] { c2.getUuid() });
X500Principal dn = new X500Principal("CN=" + c.getUuid() + ", C=US, L=Raleigh");
// create mock certs to trigger SSLAuth provider
X509Certificate[] certs = new X509Certificate[1];
X509Certificate cert = mock(X509Certificate.class);
when(cert.getSubjectX500Principal()).thenReturn(dn);
certs[0] = cert;
mockReq.setAttribute("javax.servlet.request.X509Certificate", certs);
Principal p = sslAuth.getPrincipal(mockReq);
when(mockSecurityContext.getUserPrincipal()).thenReturn(p);
interceptor.filter(mockRequestContext);
}
Aggregations