Search in sources :

Example 6 with Product

use of com.adobe.cq.commerce.api.Product in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class MockCommerceFactory method getCommerceService.

@SuppressWarnings("squid:S00112")
public static CommerceService getCommerceService(Resource resource) {
    CommerceService commerceService = mock(CommerceService.class);
    try {
        when(commerceService.login(any(SlingHttpServletRequest.class), any(SlingHttpServletResponse.class))).then(invocationOnMock -> {
            CommerceSession commerceSession = mock(CommerceSession.class);
            when(commerceSession.getProductPriceInfo(any(Product.class), any(PriceFilter.class))).then(invocation -> {
                Product product = invocation.getArgument(0);
                if (product.getPath().equals(resource.getPath())) {
                    return new ArrayList<PriceInfo>() {

                        {
                            add(new PriceInfo(UNIVERSAL_PRICE, new Locale("en", "US")));
                        }
                    };
                }
                return null;
            });
            return commerceSession;
        });
    } catch (CommerceException e) {
        throw new RuntimeException("Unable to mock CommerceService.");
    }
    return commerceService;
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) Locale(java.util.Locale) CommerceSession(com.adobe.cq.commerce.api.CommerceSession) PriceFilter(com.adobe.cq.commerce.common.PriceFilter) CommerceService(com.adobe.cq.commerce.api.CommerceService) ArrayList(java.util.ArrayList) Product(com.adobe.cq.commerce.api.Product) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) CommerceException(com.adobe.cq.commerce.api.CommerceException) PriceInfo(com.adobe.cq.commerce.api.PriceInfo)

Aggregations

Product (com.adobe.cq.commerce.api.Product)6 CommerceException (com.adobe.cq.commerce.api.CommerceException)2 CommerceService (com.adobe.cq.commerce.api.CommerceService)2 CommerceSession (com.adobe.cq.commerce.api.CommerceSession)2 PriceInfo (com.adobe.cq.commerce.api.PriceInfo)2 PriceFilter (com.adobe.cq.commerce.common.PriceFilter)2 ExperienceFragmentSocialVariation (com.adobe.cq.xf.social.ExperienceFragmentSocialVariation)2 ImageResource (com.day.cq.commons.ImageResource)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)2 Resource (org.apache.sling.api.resource.Resource)2