@Test public void testUeberCertIsRegeneratedOnNextInvocation() throws Exception { EntitlementCertificate firstCert = or.createUeberCertificate(principal, owner.getKey()); Product firstProduct = productCurator.lookupByName(owner, owner.getKey() + UEBER_PRODUCT); EntitlementCertificate secondCert = or.createUeberCertificate(principal, owner.getKey()); Product secondProduct = productCurator.lookupByName(owner, owner.getKey() + UEBER_PRODUCT); // make sure we didn't regenerate the whole thing assertTrue(firstProduct.getUuid() == secondProduct.getUuid()); // only the ueber cert assertFalse(firstCert.getId() == secondCert.getId()); }
@Test public void testUpdateContent() { final String ownerId = "owner"; final String productId = "productId"; final String contentId = "10"; Owner owner = mock(Owner.class); Product product = mock(Product.class); Content content = mock(Content.class); when(product.getId()).thenReturn(productId); when(product.getOwner()).thenReturn(owner); when(content.getId()).thenReturn(contentId); when(content.getOwner()).thenReturn(owner); when(oc.lookupByKey(eq(ownerId))).thenReturn(owner); when(cc.lookupById(eq(owner), eq(contentId))).thenReturn(content); when(cc.createOrUpdate(eq(content))).thenReturn(content); when(productCurator.getProductsWithContent(eq(owner), eq(Arrays.asList(contentId)))) .thenReturn(Arrays.asList(product)); ocr.updateContent(ownerId, contentId, content); verify(cc).lookupById(eq(owner), eq(contentId)); verify(cc).createOrUpdate(eq(content)); verify(productCurator).getProductsWithContent(eq(owner), eq(Arrays.asList(contentId))); verify(poolManager).regenerateCertificatesOf(eq(owner), eq(productId), eq(true)); }
// This exception should mention wrapping a MissingFactException @Test(expected = RuleExecutionException.class) public void testRuleFailsWhenConsumerDoesntHaveFact() { Product product = new Product("a-product", "A product for testing"); product.setAttribute(PRODUCT_CPULIMITED, "2"); productCurator.create(product); when(this.productAdapter.getProductById("a-product")).thenReturn(product); ValidationResult result = enforcer.preEntitlement( TestUtil.createConsumer(), entitlementPoolWithMembersAndExpiration(owner, product, 1, 2, expiryDate(2000, 1, 1)), 1); assertFalse(result.isSuccessful()); assertTrue(result.hasErrors()); assertFalse(result.hasWarnings()); }
@Test public void testUeberProductIsCreated() throws Exception { or.createUeberCertificate(principal, owner.getKey()); assertNotNull(productCurator.lookupByName(owner, owner.getKey() + UEBER_PRODUCT)); }