@Test public void testAllowPaymentGateway() { final SystemService systemService = mockery.mock(SystemService.class); mockery.checking(new Expectations() {{ oneOf(systemService).getAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL); will(returnValue("aaa,bbb,ccc,ddd")); oneOf(systemService).updateAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, "aaa,bbb,ccc,ddd,eee"); }}); mockery.checking(new Expectations() {{ oneOf(systemService).getAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL); will(returnValue("aaa,bbb")); }}); mockery.checking(new Expectations() {{ oneOf(systemService).getAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL); will(returnValue("xx,yy,")); oneOf(systemService).updateAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, "xx,yy,zz"); }}); PaymentModulesManager pmm = new PaymentModulesManagerImpl( null, systemService, null); pmm.allowPaymentGateway("eee"); pmm = new PaymentModulesManagerImpl( null, systemService, null); pmm.allowPaymentGateway("aaa"); pmm = new PaymentModulesManagerImpl( null, systemService, null); pmm.allowPaymentGateway("zz"); }
@Override public void allowPaymentGateway(final String label) { final String[] allowed = StringUtils.split(systemService.getAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL), ','); if (allowed == null || allowed.length == 0) { systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, label ); } else if (!Arrays.asList(allowed).contains(label)) { final List<String> updated = new ArrayList<>(Arrays.asList(allowed)); updated.add(label); systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, StringUtils.join(updated, ',') ); } }
PaymentModulesManagerImpl implements PaymentModulesManager { @Override public void allowPaymentGateway(final String label) { final String[] allowed = StringUtils.split(systemService.getAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL), ','); if (allowed == null || allowed.length == 0) { systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, label ); } else if (!Arrays.asList(allowed).contains(label)) { final List<String> updated = new ArrayList<>(Arrays.asList(allowed)); updated.add(label); systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, StringUtils.join(updated, ',') ); } } }
PaymentModulesManagerImpl implements PaymentModulesManager { @Override public void allowPaymentGateway(final String label) { final String[] allowed = StringUtils.split(systemService.getAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL), ','); if (allowed == null || allowed.length == 0) { systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, label ); } else if (!Arrays.asList(allowed).contains(label)) { final List<String> updated = new ArrayList<>(Arrays.asList(allowed)); updated.add(label); systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, StringUtils.join(updated, ',') ); } } PaymentModulesManagerImpl(final ServiceLocator serviceLocator,
                                     final SystemService systemService,
                                     final ShopService shopService); }
PaymentModulesManagerImpl implements PaymentModulesManager { @Override public void allowPaymentGateway(final String label) { final String[] allowed = StringUtils.split(systemService.getAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL), ','); if (allowed == null || allowed.length == 0) { systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, label ); } else if (!Arrays.asList(allowed).contains(label)) { final List<String> updated = new ArrayList<>(Arrays.asList(allowed)); updated.add(label); systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, StringUtils.join(updated, ',') ); } } PaymentModulesManagerImpl(final ServiceLocator serviceLocator,
                                     final SystemService systemService,
                                     final ShopService shopService); @Override Collection<PaymentModule> getPaymentModules(); @Override Collection<PaymentGatewayDescriptor> getPaymentGatewaysDescriptors(final String paymentModuleLabel); @Override void allowPaymentGateway(final String label); @Override void allowPaymentGatewayForShop(final String label, final String shopCode); @Override void disallowPaymentGateway(final String label); @Override void disallowPaymentGatewayForShop(final String label, final String shopCode); @Override List<PaymentGatewayDescriptor> getPaymentGatewaysDescriptors(final boolean includeDisabled, final String shopCode); @Override PaymentGateway getPaymentGateway(final String paymentGatewayLabel, final String shopCode); @Override void register(final PaymentModule paymentModule); }
PaymentModulesManagerImpl implements PaymentModulesManager { @Override public void allowPaymentGateway(final String label) { final String[] allowed = StringUtils.split(systemService.getAttributeValue(AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL), ','); if (allowed == null || allowed.length == 0) { systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, label ); } else if (!Arrays.asList(allowed).contains(label)) { final List<String> updated = new ArrayList<>(Arrays.asList(allowed)); updated.add(label); systemService.updateAttributeValue( AttributeNamesKeys.System.SYSTEM_ACTIVE_PAYMENT_GATEWAYS_LABEL, StringUtils.join(updated, ',') ); } } PaymentModulesManagerImpl(final ServiceLocator serviceLocator,
                                     final SystemService systemService,
                                     final ShopService shopService); @Override Collection<PaymentModule> getPaymentModules(); @Override Collection<PaymentGatewayDescriptor> getPaymentGatewaysDescriptors(final String paymentModuleLabel); @Override void allowPaymentGateway(final String label); @Override void allowPaymentGatewayForShop(final String label, final String shopCode); @Override void disallowPaymentGateway(final String label); @Override void disallowPaymentGatewayForShop(final String label, final String shopCode); @Override List<PaymentGatewayDescriptor> getPaymentGatewaysDescriptors(final boolean includeDisabled, final String shopCode); @Override PaymentGateway getPaymentGateway(final String paymentGatewayLabel, final String shopCode); @Override void register(final PaymentModule paymentModule);  }