use of com.adobe.cq.commerce.api.CommerceService 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;
}
use of com.adobe.cq.commerce.api.CommerceService 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;
}
Aggregations