Search in sources :

Example 1 with PriceInfo

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

the class MockCommerceFactory method getCommerceService.

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.getArgumentAt(0, Product.class);
                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

CommerceException (com.adobe.cq.commerce.api.CommerceException)1 CommerceService (com.adobe.cq.commerce.api.CommerceService)1 CommerceSession (com.adobe.cq.commerce.api.CommerceSession)1 PriceInfo (com.adobe.cq.commerce.api.PriceInfo)1 Product (com.adobe.cq.commerce.api.Product)1 PriceFilter (com.adobe.cq.commerce.common.PriceFilter)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)1 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)1