コード例 #1
0
  @Override
  public Collection<CatalogVersionModel> findCatalogVersions(
      final String catalogId, final String version) {
    if (catalogId.equals(CATALOG_ID) && version.equals(CATALOGVERSION_ONE)) {
      final List<CatalogVersionModel> catalogVersions = new ArrayList<CatalogVersionModel>();

      final CatalogModel catalog = new CatalogModel();
      catalog.setId(CATALOG_ID);
      final CatalogVersionModel catalogVersion = new CatalogVersionModel();
      catalogVersion.setCatalog(catalog);
      catalogVersion.setVersion(CATALOGVERSION_ONE);
      catalogVersions.add(catalogVersion);

      return catalogVersions;
    } else if (catalogId.equals(CATALOG_ID) && version.equals(CATALOGVERSION_TWO)) {
      final List<CatalogVersionModel> catalogVersions = new ArrayList<CatalogVersionModel>();

      final CatalogModel catalog = new CatalogModel();
      catalog.setId(CATALOG_ID);
      final CatalogVersionModel catalogVersion1 = new CatalogVersionModel();
      catalogVersion1.setCatalog(catalog);
      catalogVersion1.setVersion(CATALOGVERSION_TWO);

      final CatalogVersionModel catalogVersion2 = new CatalogVersionModel();
      catalogVersion2.setCatalog(catalog);
      catalogVersion2.setVersion(CATALOGVERSION_TWO);

      catalogVersions.add(catalogVersion1);
      catalogVersions.add(catalogVersion2);
      return catalogVersions;
    }
    return Collections.EMPTY_LIST;
  }
コード例 #2
0
 @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));
 }
コード例 #3
0
  /** @return */
  private CatalogVersionModel prepareCatalogVersion(final String version, final String catalogId) {
    final CatalogModel cat = new CatalogModel();
    cat.setId(catalogId);
    final CatalogVersionModel templateCatalogVersion = new CatalogVersionModel();
    templateCatalogVersion.setVersion(version);
    templateCatalogVersion.setCatalog(cat);

    return templateCatalogVersion;
  }
  private CatalogVersionModel setUpCatalog(final String catId) {
    final CatalogModel catalog = modelService.create(CatalogModel.class);
    catalog.setId(catId);

    final CatalogVersionModel cv = modelService.create(CatalogVersionModel.class);
    cv.setVersion(catId + "Version");
    cv.setCatalog(catalog);

    modelService.saveAll(catalog, cv);

    return cv;
  }