killbill-memoizeit

jaxrs: handle trailing = in plugin properties Signed-off-by:

4/21/2015 3:36:56 PM

Details

diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/JaxRsResourceBase.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/JaxRsResourceBase.java
index e5626b2..3e41227 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/JaxRsResourceBase.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/JaxRsResourceBase.java
@@ -348,7 +348,11 @@ public abstract class JaxRsResourceBase implements JaxrsResource {
         for (final String pluginProperty : pluginProperties) {
             final List<String> property = ImmutableList.<String>copyOf(pluginProperty.split("="));
             final String key = property.get(0);
-            final String value = property.size() == 1 ? null : Joiner.on("=").join(property.subList(1, property.size()));
+            // Should we URL decode the value?
+            String value = property.size() == 1 ? null : Joiner.on("=").join(property.subList(1, property.size()));
+            if (pluginProperty.endsWith("=")) {
+                value += "=";
+            }
             properties.add(new PluginProperty(key, value, false));
         }
         for (final PluginProperty cur : additionalProperties) {
diff --git a/jaxrs/src/test/java/org/killbill/billing/jaxrs/resources/TestJaxRsResourceBase.java b/jaxrs/src/test/java/org/killbill/billing/jaxrs/resources/TestJaxRsResourceBase.java
new file mode 100644
index 0000000..01885d8
--- /dev/null
+++ b/jaxrs/src/test/java/org/killbill/billing/jaxrs/resources/TestJaxRsResourceBase.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2015 Groupon, Inc
+ * Copyright 2015 The Billing Project, LLC
+ *
+ * The Billing Project licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.killbill.billing.jaxrs.resources;
+
+import java.util.List;
+
+import org.killbill.billing.jaxrs.JaxrsTestSuiteNoDB;
+import org.killbill.billing.payment.api.PluginProperty;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class TestJaxRsResourceBase extends JaxrsTestSuiteNoDB {
+
+    private final JaxRsResourceBaseTest base = new JaxRsResourceBaseTest();
+
+    @Test(groups = "fast")
+    public void testExtractPluginProperties() throws Exception {
+        final List<String> pluginPropertiesString = ImmutableList.<String>of("payment_cryptogram=EHuWW9PiBkWvqE5juRwDzAUFBAk=",
+                                                                             "cc_number=4111111111111111",
+                                                                             "cc_type=visa",
+                                                                             "cc_expiration_month=09",
+                                                                             "cc_expiration_year=2020");
+        final List<PluginProperty> pluginProperties = ImmutableList.<PluginProperty>copyOf(base.extractPluginProperties(pluginPropertiesString));
+        Assert.assertEquals(pluginProperties.size(), 5);
+        Assert.assertEquals(pluginProperties.get(0).getKey(), "payment_cryptogram");
+        Assert.assertEquals(pluginProperties.get(0).getValue(), "EHuWW9PiBkWvqE5juRwDzAUFBAk=");
+        Assert.assertEquals(pluginProperties.get(1).getKey(), "cc_number");
+        Assert.assertEquals(pluginProperties.get(1).getValue(), "4111111111111111");
+        Assert.assertEquals(pluginProperties.get(2).getKey(), "cc_type");
+        Assert.assertEquals(pluginProperties.get(2).getValue(), "visa");
+        Assert.assertEquals(pluginProperties.get(3).getKey(), "cc_expiration_month");
+        Assert.assertEquals(pluginProperties.get(3).getValue(), "09");
+        Assert.assertEquals(pluginProperties.get(4).getKey(), "cc_expiration_year");
+        Assert.assertEquals(pluginProperties.get(4).getValue(), "2020");
+    }
+
+    private static final class JaxRsResourceBaseTest extends JaxRsResourceBase {
+
+        public JaxRsResourceBaseTest() {
+            super(null, null, null, null, null, null, null, null);
+        }
+    }
+}