@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));
 }
  /** Creates some attachments and assigns them to the test workflow. */
  @Test
  public void testAttachments() {
    final CatalogVersionModel testCv =
        catalogVersionService.getCatalogVersion("DefaultTestCatalog", "Online");
    assertNotNull(testCv);

    final PK workflowPk = testWorkflow.getPk();
    // create product attachment
    final ProductModel product = modelService.create(ProductModel.class);
    product.setCode("abc");

    product.setCatalogVersion(testCv);

    modelService.save(product);
    assertNotNull("Product not null", product);

    final WorkflowItemAttachmentModel attachProduct =
        createAttachment("productTest", product, testWorkflow);
    assertNotNull("Attachment not null", attachProduct);

    // create category attachment
    final CategoryModel category = modelService.create(CategoryModel.class);
    category.setCode("abc");
    category.setCatalogVersion(testCv);
    assertNotNull("Category not null", category);

    final WorkflowItemAttachmentModel attachCategory =
        createAttachment("categoryTest", category, testWorkflow);
    assertNotNull("Attachment not null", attachCategory);

    final WorkflowActionModel action1 = getAction(ACTIONCODES.ACTION1.name());
    action1.setAttachments(
        Arrays.asList(new WorkflowItemAttachmentModel[] {attachProduct, attachCategory}));

    clearCache();

    // check attachments
    final WorkflowModel found = modelService.get(workflowPk);
    assertEquals("Excpected number of attachments", 2, found.getAttachments().size());
    final WorkflowActionModel foundAction = getAction(ACTIONCODES.ACTION1.name());
    assertEquals(
        "Excpected number of attachments of action 1", 2, foundAction.getAttachments().size());
  }