@Test public void searchRestrictionTest() { final UserGroupModel group = new UserGroupModel(); group.setUid("customergroup"); modelService.save(group); // create test user final UserModel user = new UserModel(); user.setUid(TEST_USER); // assign user to customergroup user.setGroups(Collections.singleton((PrincipalGroupModel) group)); modelService.save(user); // create test catalog final CatalogModel catalog = new CatalogModel(); catalog.setId(TEST_CATALOG); modelService.save(catalog); // create test catalog version final CatalogVersionModel catalogVersion = new CatalogVersionModel(); catalogVersion.setCatalog(catalog); catalogVersion.setVersion(TEST_VERSION); modelService.save(catalogVersion); // create test product final ProductModel product = new ProductModel(); product.setCode(TEST_PRODUCT); product.setCatalogVersion(catalogVersion); modelService.save(product); // set current user userService.setCurrentUser(user); // create search restriction commonI18NService.setCurrentLanguage(commonI18NService.getLanguage(LANG_EN)); final Map<String, String[]> params = new HashMap<String, String[]>(); params.put("customerreview.searchrestrictions.create", new String[] {"true"}); final SystemSetupContext ctx = new SystemSetupContext(params, Type.ESSENTIAL, Process.ALL, "customerreview"); customerReviewSystemSetup.createSearchRestrictions(ctx); // enable search restrictions searchRestrictionService.enableSearchRestrictions(); // make sure that number of customer reviews is 0 assertEquals( INVALID_NUMBER_OF_CUSTOMER_REVIEWS, Integer.valueOf(0), customerReviewService.getNumberOfReviews(product)); // create restricted customer review createCustomerReview(null, user, product, CustomerReviewApprovalType.PENDING); // create valid customer review createCustomerReview("headline", user, product, CustomerReviewApprovalType.APPROVED); // make sure that number of customer reviews is 1 assertEquals( INVALID_NUMBER_OF_CUSTOMER_REVIEWS, Integer.valueOf(1), customerReviewService.getNumberOfReviews(product)); // disable search restrictions searchRestrictionService.disableSearchRestrictions(); // make sure that number of customer reviews is 2 assertEquals( INVALID_NUMBER_OF_CUSTOMER_REVIEWS, Integer.valueOf(2), customerReviewService.getNumberOfReviews(product)); }
private void createCustomerReview( final String headline, final UserModel user, final ProductModel product, final CustomerReviewApprovalType approvalStatus) { final CustomerReviewModel review = customerReviewService.createCustomerReview( Double.valueOf(3.0), headline, COMMENT, user, product); review.setApprovalStatus(approvalStatus); review.setLanguage(commonI18NService.getCurrentLanguage()); modelService.save(review); }