diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/TenantResource.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/TenantResource.java
index d1626c8..af66b29 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/TenantResource.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/TenantResource.java
@@ -64,6 +64,7 @@ import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
@Singleton
@Path(JaxrsResource.TENANTS_PATH)
@@ -140,8 +141,9 @@ public class TenantResource extends JaxRsResourceBase {
@HeaderParam(HDR_CREATED_BY) final String createdBy,
@HeaderParam(HDR_REASON) final String reason,
@HeaderParam(HDR_COMMENT) final String comment,
- @javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
- return insertTenantKey(TenantKey.PUSH_NOTIFICATION_CB, null, notificationCallback, "getPushNotificationCallbacks", createdBy, reason, comment, request);
+ @javax.ws.rs.core.Context final HttpServletRequest request,
+ @javax.ws.rs.core.Context final UriInfo uriInfo) throws TenantApiException {
+ return insertTenantKey(TenantKey.PUSH_NOTIFICATION_CB, null, notificationCallback, uriInfo,"getPushNotificationCallbacks", createdBy, reason, comment, request);
}
@Timed
@@ -169,7 +171,7 @@ public class TenantResource extends JaxRsResourceBase {
@Timed
@POST
@Path("/" + UPLOAD_PLUGIN_CONFIG + "/{pluginName:" + ANYTHING_PATTERN + "}")
- @Consumes(APPLICATION_JSON)
+ @Consumes(TEXT_PLAIN)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add a per tenant configuration for a plugin")
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
@@ -178,8 +180,9 @@ public class TenantResource extends JaxRsResourceBase {
@HeaderParam(HDR_CREATED_BY) final String createdBy,
@HeaderParam(HDR_REASON) final String reason,
@HeaderParam(HDR_COMMENT) final String comment,
- @javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
- return insertTenantKey(TenantKey.PLUGIN_CONFIG_, pluginName, pluginConfig, "getPluginConfiguration", createdBy, reason, comment, request);
+ @javax.ws.rs.core.Context final HttpServletRequest request,
+ @javax.ws.rs.core.Context final UriInfo uriInfo) throws TenantApiException {
+ return insertTenantKey(TenantKey.PLUGIN_CONFIG_, pluginName, pluginConfig, uriInfo, "getPluginConfiguration", createdBy, reason, comment, request);
}
@Timed
@@ -209,6 +212,7 @@ public class TenantResource extends JaxRsResourceBase {
private Response insertTenantKey(final TenantKey key,
@Nullable final String keyPostfix,
final String value,
+ final UriInfo uriInfo,
final String getMethodStr,
final String createdBy,
final String reason,
@@ -217,8 +221,10 @@ public class TenantResource extends JaxRsResourceBase {
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final String tenantKey = keyPostfix != null ? key.toString() + keyPostfix : key.toString();
tenantApi.addTenantKeyValue(tenantKey, value, callContext);
- final URI uri = UriBuilder.fromResource(TenantResource.class).path(TenantResource.class, getMethodStr).build();
- return Response.created(uri).build();
+
+ return uriBuilder.buildResponse(uriInfo, TenantResource.class, getMethodStr, keyPostfix);
+// final URI uri = UriBuilder.fromResource(TenantResource.class).path(TenantResource.class, getMethodStr).build();
+// return Response.created(uri).build();
}
private Response getTenantKey(final TenantKey key,
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPushNotification.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPushNotification.java
index 342305c..76b0e4d 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPushNotification.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPushNotification.java
@@ -31,7 +31,6 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
-import org.killbill.billing.client.JaxrsResource;
import org.killbill.billing.client.model.TenantKey;
import org.killbill.billing.jaxrs.json.NotificationJson;
import org.slf4j.Logger;
@@ -94,7 +93,11 @@ public class TestPushNotification extends TestJaxrsBase {
public void testPushNotification() throws Exception {
// Register tenant for callback
final String callback = "http://127.0.0.1:" + SERVER_PORT + CALLBACK_ENDPPOINT;
- killBillClient.registerCallbackNotificationForTenant(callback, createdBy, reason, comment);
+ final TenantKey result0 = killBillClient.registerCallbackNotificationForTenant(callback, createdBy, reason, comment);
+ Assert.assertEquals(result0.getKey(), org.killbill.billing.tenant.api.TenantKV.TenantKey.PUSH_NOTIFICATION_CB.toString());
+ Assert.assertEquals(result0.getValues().size(), 1);
+ Assert.assertEquals(result0.getValues().get(0), callback);
+
// Create account to trigger a push notification
createAccount();
@@ -107,13 +110,13 @@ public class TestPushNotification extends TestJaxrsBase {
Assert.fail("Assertion during callback failed...");
}
- final TenantKey result = killBillClient.getCallbackNotificationForTenant(createdBy, reason, comment);
+ final TenantKey result = killBillClient.getCallbackNotificationForTenant();
Assert.assertEquals(result.getKey(), org.killbill.billing.tenant.api.TenantKV.TenantKey.PUSH_NOTIFICATION_CB.toString());
Assert.assertEquals(result.getValues().size(), 1);
Assert.assertEquals(result.getValues().get(0), callback);
killBillClient.unregisterCallbackNotificationForTenant(createdBy, reason, comment);
- final TenantKey result2 = killBillClient.getCallbackNotificationForTenant(createdBy, reason, comment);
+ final TenantKey result2 = killBillClient.getCallbackNotificationForTenant();
Assert.assertEquals(result2.getKey(), org.killbill.billing.tenant.api.TenantKV.TenantKey.PUSH_NOTIFICATION_CB.toString());
Assert.assertEquals(result2.getValues().size(), 0);
}
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestTenantKV.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestTenantKV.java
new file mode 100644
index 0000000..54a51cc
--- /dev/null
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestTenantKV.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-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;
+
+import org.killbill.billing.client.model.TenantKey;
+import org.killbill.billing.tenant.api.TenantKV;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.common.io.Resources;
+
+public class TestTenantKV extends TestJaxrsBase {
+
+ @Test(groups = "slow", description = "Upload and retrieve a per plugin config")
+ public void testPerTenantPluginConfig() throws Exception {
+
+ final String pluginName = "PLUGIN_FOO";
+
+ final String pluginPath = Resources.getResource("plugin.yml").getPath();
+ final TenantKey tenantKey0 = killBillClient.registerPluginConfigurationForTenant(pluginName, pluginPath, createdBy, reason, comment);
+ Assert.assertEquals(tenantKey0.getKey(), TenantKV.TenantKey.PLUGIN_CONFIG_.toString() + pluginName);
+
+ final TenantKey tenantKey1 = killBillClient.getPluginConfigurationForTenant(pluginName);
+ Assert.assertEquals(tenantKey1.getKey(), TenantKV.TenantKey.PLUGIN_CONFIG_.toString() + pluginName);
+ Assert.assertEquals(tenantKey1.getValues().size(), 1);
+
+ killBillClient.unregisterPluginConfigurationForTenant(pluginName, createdBy, reason, comment);
+ final TenantKey tenantKey2 = killBillClient.getPluginConfigurationForTenant(pluginName);
+ Assert.assertEquals(tenantKey2.getKey(), TenantKV.TenantKey.PLUGIN_CONFIG_.toString() + pluginName);
+ Assert.assertEquals(tenantKey2.getValues().size(), 0);
+ }
+
+}