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 String apply(final PluginProperty pluginProperty) { return pluginProperty.getKey(); } })
@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()); }
@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()); }
@Override public boolean apply(final PluginProperty input) { return key.equals(input.getKey()); } });
@Override public boolean apply(final PluginProperty input) { return pluginPropertyName.equals(input.getKey()); } }).orNull();
@Override public boolean apply(final PluginProperty input) { return keyPattern.matcher(input.getKey()).matches(); } });
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 String apply(final PluginProperty pluginProperty) { return pluginProperty.getKey(); } })
@Override public String apply(final PluginProperty pluginProperty) { return pluginProperty.getKey(); } })
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 PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE.equals(input.getKey()); } }).orNull();
@Override public boolean apply(final PluginProperty input) { return input.getKey().equals("name"); } }).orNull();
private static void validate(final Iterable<PluginProperty> properties, final Iterable<PluginProperty> expected) { Assert.assertEquals(Iterables.size(properties), Iterables.size(expected), "Got " + Iterables.size(properties) + "properties" + ", expected " + Iterables.size(expected)); for (final PluginProperty curExpected : expected) { Assert.assertTrue(Iterables.any(properties, new Predicate<PluginProperty>() { @Override public boolean apply(final PluginProperty input) { return input.getKey().equals(curExpected.getKey()) && input.getValue().equals(curExpected.getValue()); } }), "Cannot find expected property" + curExpected.getKey()); } }
@Override public PluginPropertyJson apply(final PluginProperty input) { return new PluginPropertyJson(input.getKey(), input.getValue() == null ? null : input.getValue().toString(), input.getIsUpdatable()); } }));
@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()); }
@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()); }
private void checkProperty(final Iterable<PluginProperty> properties, final PluginProperty expected) { final PluginProperty found = Iterables.tryFind(properties, new Predicate<PluginProperty>() { @Override public boolean apply(final PluginProperty input) { return input.getKey().equals(expected.getKey()); } }).orNull(); assertNotNull(found, "Did not find property key = " + expected.getKey()); assertEquals(found.getValue(), expected.getValue()); }