@Override public Object compute(final String key, final CacheLoaderArgument cacheLoaderArgument) { final String[] parts = key.split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR); final String rawKey = parts[0]; final Matcher matcher = PATTERN.matcher(rawKey); if (!matcher.matches()) { throw new IllegalArgumentException("Unexpected key " + rawKey); } final String pluginName = matcher.group(1); final String tenantRecordId = parts[1]; final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final InternalTenantContext internalTenantContext = new InternalTenantContext(Long.valueOf(tenantRecordId)); final String stateMachineConfigXML = tenantApi.getPluginPaymentStateMachineConfig(pluginName, internalTenantContext); if (stateMachineConfigXML == null) { return null; } try { log.info("Loading config state machine cache for pluginName='{}', tenantRecordId='{}'", pluginName, internalTenantContext.getTenantRecordId()); return callback.loadStateMachineConfig(stateMachineConfigXML); } catch (final PaymentApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize state machine config for tenantRecordId='%s'", internalTenantContext.getTenantRecordId()), e); } }
@Override public Object compute(final String key, final CacheLoaderArgument cacheLoaderArgument) { final String[] parts = key.split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR); final String rawKey = parts[0]; final Matcher matcher = PATTERN.matcher(rawKey); if (!matcher.matches()) { throw new IllegalArgumentException("Unexpected key " + rawKey); } final String pluginName = matcher.group(1); final String tenantRecordId = parts[1]; final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final InternalTenantContext internalTenantContext = new InternalTenantContext(Long.valueOf(tenantRecordId)); final String stateMachineConfigXML = tenantApi.getPluginPaymentStateMachineConfig(pluginName, internalTenantContext); if (stateMachineConfigXML == null) { return null; } try { log.info("Loading config state machine cache for pluginName='{}', tenantRecordId='{}'", pluginName, internalTenantContext.getTenantRecordId()); return callback.loadStateMachineConfig(stateMachineConfigXML); } catch (final PaymentApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize state machine config for tenantRecordId='%s'", internalTenantContext.getTenantRecordId()), e); } }
Mockito.when(tenantInternalApi.getPluginPaymentStateMachineConfig(Mockito.eq(pluginName), Mockito.any(InternalTenantContext.class))).thenAnswer(new Answer<String>() { @Override public String answer(final InvocationOnMock invocation) throws Throwable {
final Long otherMultiTenantRecordId = otherMultiTenantContext.getTenantRecordId(); Mockito.when(tenantInternalApi.getPluginPaymentStateMachineConfig(Mockito.eq(pluginName), Mockito.any(InternalTenantContext.class))).thenAnswer(new Answer<String>() { @Override public String answer(final InvocationOnMock invocation) throws Throwable {