@Test(groups = "fast") public void testBuildPluginProperties() throws Exception { Assert.assertEquals(pluginProperties1.size(), 2); Assert.assertEquals(pluginProperties1.get(0).getKey(), "foo"); Assert.assertEquals(pluginProperties1.get(0).getValue(), "bar"); Assert.assertFalse(pluginProperties1.get(0).getIsUpdatable()); Assert.assertEquals(pluginProperties1.get(1).getKey(), "baz"); Assert.assertEquals(pluginProperties1.get(1).getValue(), (Long) 12L); Assert.assertFalse(pluginProperties1.get(1).getIsUpdatable()); }
public static List<PluginProperty> buildPluginProperties(@Nullable final Map<String, Object> data) { final ImmutableList.Builder<PluginProperty> propertiesBuilder = ImmutableList.<PluginProperty>builder(); if (data != null) { for (final String key : data.keySet()) { final PluginProperty property = new PluginProperty(key, data.get(key), false); propertiesBuilder.add(property); } } return propertiesBuilder.build(); } }
public static Map<String, Object> toMap(final Iterable<PluginProperty>... propertiesLists) { final Map<String, Object> mergedProperties = new HashMap<String, Object>(); for (final Iterable<PluginProperty> propertiesList : propertiesLists) { for (final PluginProperty pluginProperty : propertiesList) { if (pluginProperty.getKey() != null) { mergedProperties.put(pluginProperty.getKey(), pluginProperty.getValue()); } } } return mergedProperties; }
@Test(groups = "fast", enabled = true) public void testPluginPropertyWithComplexValue() throws PluginPropertySerializerException { final HashMap<String, BigDecimal> something = new HashMap<String, BigDecimal>(); something.put("yoyo", new BigDecimal("0.0")); something.put("what", new BigDecimal("10.0")); final List<PluginProperty> input = new ArrayList<PluginProperty>(); input.add(new PluginProperty("prev", "simple", false)); input.add(new PluginProperty("foo", something, false)); input.add(new PluginProperty("next", "easy", false)); final byte[] serialized = PluginPropertySerializer.serialize(input); final Iterable<PluginProperty> deserialized = PluginPropertySerializer.deserialize(serialized); int i = 0; for (PluginProperty cur : deserialized) { if (i == 0 || i == 2) { Assert.assertEquals(cur, input.get(i)); } else { Assert.assertEquals(cur.getKey(), "foo"); Assert.assertTrue(cur.getValue() instanceof Map); final Map<String, BigDecimal> mappedValue = (Map<String, BigDecimal>) cur.getValue(); Assert.assertTrue(mappedValue.containsKey("yoyo")); Assert.assertTrue(mappedValue.containsKey("what")); Assert.assertTrue(mappedValue.get("yoyo").compareTo(BigDecimal.ZERO) == 0); Assert.assertTrue(mappedValue.get("what").compareTo(BigDecimal.TEN) == 0); } i++; } } }
@Override public String apply(final PluginProperty pluginProperty) { return pluginProperty.getKey(); } })
public static String findPluginPropertyValue(final String pluginPropertyName, @Nullable final Iterable<PluginProperty> properties) { if (properties == null) { return null; } final PluginProperty pluginProperty = Iterables.tryFind(properties, new Predicate<PluginProperty>() { @Override public boolean apply(final PluginProperty input) { return pluginPropertyName.equals(input.getKey()); } }).orNull(); if (pluginProperty == null || pluginProperty.getValue() == null) { return null; } final String pluginPropertyString = String.valueOf(pluginProperty.getValue()); return Strings.isNullOrEmpty(pluginPropertyString) ? null : pluginPropertyString; }
protected Map<String, Object> propertiesToMap(final Iterable<PluginProperty> properties) { final Map<String, Object> propertiesMap = new HashMap<String, Object>(); for (final PluginProperty pluginProperty : properties) { if (pluginProperty.getValue() != null) { propertiesMap.put(pluginProperty.getKey(), pluginProperty.getValue()); } } return propertiesMap; }
@Override public boolean apply(final PluginProperty input) { return pluginPropertyName.equals(input.getKey()); } }).orNull();
@Override public boolean apply(final PaymentTransactionInfoPlugin input) { if (input.getProperties() != null) { for (final PluginProperty cur : input.getProperties()) { if (cur.getValue().equals(searchKey)) { return true; } } } return (input.getKbPaymentId().toString().equals(searchKey)); } }));
@Test(groups = "fast") public void testMerge() throws Exception { final List<PluginProperty> pluginPropertiesRaw = ImmutableList.<PluginProperty>copyOf(PluginProperties.merge(pluginProperties1, pluginProperties2)); final List<PluginProperty> pluginProperties = sort(pluginPropertiesRaw); Assert.assertEquals(pluginProperties.size(), 3); Assert.assertEquals(pluginProperties.get(0).getKey(), "baz"); Assert.assertEquals(pluginProperties.get(0).getValue(), (Long) 12L); Assert.assertFalse(pluginProperties.get(0).getIsUpdatable()); Assert.assertEquals(pluginProperties.get(1).getKey(), "baz2"); Assert.assertEquals(pluginProperties.get(1).getValue(), "something else"); Assert.assertFalse(pluginProperties.get(1).getIsUpdatable()); Assert.assertEquals(pluginProperties.get(2).getKey(), "foo"); Assert.assertEquals(pluginProperties.get(2).getValue(), "override"); Assert.assertFalse(pluginProperties.get(2).getIsUpdatable()); }
public PluginProperty toPluginProperty() { return new PluginProperty(key, value, isUpdatable); }
public static Map<String, Object> toMap(final Iterable<PluginProperty>... propertiesLists) { final Map<String, Object> mergedProperties = new HashMap<String, Object>(); for (final Iterable<PluginProperty> propertiesList : propertiesLists) { for (final PluginProperty pluginProperty : propertiesList) { if (pluginProperty.getKey() != null) { mergedProperties.put(pluginProperty.getKey(), pluginProperty.getValue()); } } } return mergedProperties; }
@Override public boolean apply(final PluginProperty input) { return key.equals(input.getKey()); } });
@Override public boolean apply(final PaymentMethodPlugin input) { if (input.getProperties() != null) { for (PluginProperty cur : input.getProperties()) { if (cur.getValue().equals(searchKey)) { return true; } } } return (input.getKbPaymentMethodId().toString().equals(searchKey)); } }));
public PluginPropertyJson(final PluginProperty pluginProperty) { this(pluginProperty.getKey(), pluginProperty.getValue() == null ? null : pluginProperty.getValue().toString(), pluginProperty.getIsUpdatable()); }
protected List<PluginProperty> propertiesToList(final Map<String, String> propertiesMap) { final List<PluginProperty> properties = new LinkedList<PluginProperty>(); for (final String key : propertiesMap.keySet()) { final PluginProperty property = new PluginProperty(key, propertiesMap.get(key), false); properties.add(property); } return properties; }
public static Map<String, Object> toMap(final Iterable<PluginProperty>... propertiesLists) { final Map<String, Object> mergedProperties = new HashMap<String, Object>(); for (final Iterable<PluginProperty> propertiesList : propertiesLists) { if (propertiesList == null) { continue; } for (final PluginProperty pluginProperty : propertiesList) { if (pluginProperty.getKey() != null && pluginProperty.getValue() != null) { mergedProperties.put(pluginProperty.getKey(), pluginProperty.getValue()); } } } return mergedProperties; }
@Override public boolean apply(final PluginProperty input) { return keyPattern.matcher(input.getKey()).matches(); } });
@Override public OnSuccessPaymentControlResult onSuccessCall(final PaymentControlContext paymentControlContext, final Iterable<PluginProperty> properties) throws PaymentControlApiException { final PluginProperty nameProperty = Iterables.tryFind(properties, new Predicate<PluginProperty>() { @Override public boolean apply(final PluginProperty input) { return input.getKey().equals("name"); } }).orNull(); if (nameProperty != null && nameProperty.getValue().equals(TEST_PAYMENT_WITH_CONTROL)) { final Integer result = calls.get(paymentControlContext.getTransactionType()); calls.put(paymentControlContext.getTransactionType().toString(), result == null ? new Integer(1) : new Integer(result.intValue() + 1)); } return new OnSuccessPaymentControlResult() { @Override public Iterable<PluginProperty> getAdjustedPluginProperties() { return null; } }; }
@Override public PluginPropertyJson apply(final PluginProperty input) { return new PluginPropertyJson(input.getKey(), input.getValue() == null ? null : input.getValue().toString(), input.getIsUpdatable()); } }));