Skip to content

Commit

Permalink
jaxrs, profile: Update api for swagger generation. Warning: change pa…
Browse files Browse the repository at this point in the history
…th for

* Rename TenantKeyJson (swagger name TenantKey) -> TenantKeyValueJson (swagger name TenantKeyValue) so as to not conflict with api enum TenantKey
* Modify subscription api name Entitlement -> Subscription (e.g createEntitlement -> createSubscription)
  • Loading branch information
sbrossie committed Mar 24, 2018
1 parent 840bc5e commit f27137c
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 96 deletions.
Expand Up @@ -22,15 +22,15 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;

@ApiModel(value="TenantKey")
public class TenantKeyJson {
@ApiModel(value="TenantKeyValue")
public class TenantKeyValueJson {

private final String key;
private final List<String> values;

@JsonCreator
public TenantKeyJson(@JsonProperty("key") final String key,
@JsonProperty("values") final List<String> values) {
public TenantKeyValueJson(@JsonProperty("key") final String key,
@JsonProperty("values") final List<String> values) {
this.key = key;
this.values = values;
}
Expand Down
Expand Up @@ -37,14 +37,13 @@
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import org.joda.time.DateTime;
import org.killbill.billing.ObjectType;
import org.killbill.billing.account.api.AccountUserApi;
import org.killbill.billing.callcontext.DefaultCallContext;
import org.killbill.billing.catalog.api.CatalogApiException;
import org.killbill.billing.catalog.api.CatalogUserApi;
import org.killbill.billing.jaxrs.json.TenantJson;
import org.killbill.billing.jaxrs.json.TenantKeyJson;
import org.killbill.billing.jaxrs.json.TenantKeyValueJson;
import org.killbill.billing.jaxrs.util.Context;
import org.killbill.billing.jaxrs.util.JaxrsUriBuilder;
import org.killbill.billing.payment.api.PaymentApi;
Expand Down Expand Up @@ -153,7 +152,7 @@ public Response createTenant(final TenantJson json,
@Path("/" + REGISTER_NOTIFICATION_CALLBACK)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Create a push notification", response = TenantKeyJson.class)
@ApiOperation(value = "Create a push notification", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response registerPushNotificationCallback(@QueryParam(QUERY_NOTIFICATION_CALLBACK) final String notificationCallback,
@HeaderParam(HDR_CREATED_BY) final String createdBy,
Expand All @@ -168,7 +167,7 @@ public Response registerPushNotificationCallback(@QueryParam(QUERY_NOTIFICATION_
@GET
@Path("/" + REGISTER_NOTIFICATION_CALLBACK)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a push notification", response = TenantKeyJson.class)
@ApiOperation(value = "Retrieve a push notification", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response getPushNotificationCallbacks(@javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
return getTenantKey(TenantKey.PUSH_NOTIFICATION_CB, null, request);
Expand All @@ -191,7 +190,7 @@ public Response deletePushNotificationCallbacks(@HeaderParam(HDR_CREATED_BY) fin
@Path("/" + UPLOAD_PLUGIN_CONFIG + "/{pluginName:" + ANYTHING_PATTERN + "}")
@Consumes(TEXT_PLAIN)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add a per tenant configuration for a plugin", response = TenantKeyJson.class)
@ApiOperation(value = "Add a per tenant configuration for a plugin", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response uploadPluginConfiguration(final String pluginConfig,
@PathParam("pluginName") final String pluginName,
Expand All @@ -209,7 +208,7 @@ public Response uploadPluginConfiguration(final String pluginConfig,
@GET
@Path("/" + UPLOAD_PLUGIN_CONFIG + "/{pluginName:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a per tenant configuration for a plugin", response = TenantKeyJson.class)
@ApiOperation(value = "Retrieve a per tenant configuration for a plugin", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response getPluginConfiguration(@PathParam("pluginName") final String pluginName,
@javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
Expand All @@ -234,16 +233,16 @@ public Response deletePluginConfiguration(@PathParam("pluginName") final String
@GET
@Path("/" + UPLOAD_PER_TENANT_CONFIG + "/{keyPrefix:" + ANYTHING_PATTERN + "}" + "/" + SEARCH)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a per tenant key value based on key prefix", response = TenantKeyJson.class)
@ApiOperation(value = "Retrieve a per tenant key value based on key prefix", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response getAllPluginConfiguration(@PathParam("keyPrefix") final String keyPrefix,
@javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {

final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
final Map<String, List<String>> apiResult = tenantApi.searchTenantKeyValues(keyPrefix, tenantContext);
final List<TenantKeyJson> result = new ArrayList<TenantKeyJson>();
final List<TenantKeyValueJson> result = new ArrayList<TenantKeyValueJson>();
for (final String cur : apiResult.keySet()) {
result.add(new TenantKeyJson(cur, apiResult.get(cur)));
result.add(new TenantKeyValueJson(cur, apiResult.get(cur)));
}
return Response.status(Status.OK).entity(result).build();
}
Expand All @@ -254,7 +253,7 @@ public Response getAllPluginConfiguration(@PathParam("keyPrefix") final String k
@Path("/" + UPLOAD_PER_TENANT_CONFIG)
@Consumes(TEXT_PLAIN)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add a per tenant configuration (system properties)", response = TenantKeyJson.class)
@ApiOperation(value = "Add a per tenant configuration (system properties)", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response uploadPerTenantConfiguration(final String perTenantConfig,
@HeaderParam(HDR_CREATED_BY) final String createdBy,
Expand All @@ -269,7 +268,7 @@ public Response uploadPerTenantConfiguration(final String perTenantConfig,
@GET
@Path("/" + UPLOAD_PER_TENANT_CONFIG)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a per tenant configuration (system properties)", response = TenantKeyJson.class)
@ApiOperation(value = "Retrieve a per tenant configuration (system properties)", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response getPerTenantConfiguration(@javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
return getTenantKey(TenantKey.PER_TENANT_CONFIG, null, request);
Expand All @@ -292,7 +291,7 @@ public Response deletePerTenantConfiguration(@HeaderParam(HDR_CREATED_BY) final
@Path("/" + UPLOAD_PLUGIN_PAYMENT_STATE_MACHINE_CONFIG + "/{pluginName:" + ANYTHING_PATTERN + "}")
@Consumes(TEXT_PLAIN)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add a per tenant payment state machine for a plugin", response = TenantKeyJson.class)
@ApiOperation(value = "Add a per tenant payment state machine for a plugin", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response uploadPluginPaymentStateMachineConfig(final String paymentStateMachineConfig,
@PathParam("pluginName") final String pluginName,
Expand All @@ -308,7 +307,7 @@ public Response uploadPluginPaymentStateMachineConfig(final String paymentStateM
@GET
@Path("/" + UPLOAD_PLUGIN_PAYMENT_STATE_MACHINE_CONFIG + "/{pluginName:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a per tenant payment state machine for a plugin", response = TenantKeyJson.class)
@ApiOperation(value = "Retrieve a per tenant payment state machine for a plugin", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response getPluginPaymentStateMachineConfig(@PathParam("pluginName") final String pluginName,
@javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
Expand All @@ -333,7 +332,7 @@ public Response deletePluginPaymentStateMachineConfig(@PathParam("pluginName") f
@Path("/" + USER_KEY_VALUE + "/{keyName:" + ANYTHING_PATTERN + "}")
@Consumes(TEXT_PLAIN)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add a per tenant user key/value", response = TenantKeyJson.class)
@ApiOperation(value = "Add a per tenant user key/value", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response insertUserKeyValue(@PathParam("keyName") final String key,
final String value,
Expand All @@ -351,13 +350,13 @@ public Response insertUserKeyValue(@PathParam("keyName") final String key,
@GET
@Path("/" + USER_KEY_VALUE + "/{keyName:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a per tenant user key/value", response = TenantKeyJson.class)
@ApiOperation(value = "Retrieve a per tenant user key/value", response = TenantKeyValueJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tenantId supplied")})
public Response getUserKeyValue(@PathParam("keyName") final String key,
@javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
final List<String> values = tenantApi.getTenantValuesForKey(key, tenantContext);
final TenantKeyJson result = new TenantKeyJson(key, values);
final TenantKeyValueJson result = new TenantKeyValueJson(key, values);
return Response.status(Status.OK).entity(result).build();
}

Expand Down Expand Up @@ -403,7 +402,7 @@ private Response getTenantKey(final TenantKey key,
final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
final String tenantKey = keyPostfix != null ? key.toString() + keyPostfix : key.toString();
final List<String> values = tenantApi.getTenantValuesForKey(tenantKey, tenantContext);
final TenantKeyJson result = new TenantKeyJson(tenantKey, values);
final TenantKeyValueJson result = new TenantKeyValueJson(tenantKey, values);
return Response.status(Status.OK).entity(result).build();
}

Expand Down
Expand Up @@ -80,7 +80,7 @@ public abstract class KillbillClient extends GuicyKillbillTestSuiteWithEmbeddedD



protected final int DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC = 10;
protected final long DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC = 10;

protected static final String PLUGIN_NAME = "noop";

Expand Down Expand Up @@ -195,7 +195,7 @@ protected Account createAccount(final UUID parentAccountId) throws Exception {
return accountApi.createAccount(input, requestOptions);
}

protected Subscription createEntitlement(final UUID accountId, final String bundleExternalKey, final String productName,
protected Subscription createSubscription(final UUID accountId, final String bundleExternalKey, final String productName,
final ProductCategory productCategory, final BillingPeriod billingPeriod, final boolean waitCompletion) throws Exception {
final Subscription input = new Subscription();
input.setAccountId(accountId);
Expand All @@ -204,15 +204,15 @@ protected Subscription createEntitlement(final UUID accountId, final String bund
input.setProductCategory(productCategory);
input.setBillingPeriod(billingPeriod);
input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
return subscriptionApi.createEntitlement(input, null, null, true, false, null, waitCompletion, waitCompletion ? DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC : -1L, NULL_PLUGIN_PROPERTIES, requestOptions);
return subscriptionApi.createSubscription(input, null, null, true, false, null, waitCompletion, waitCompletion ? DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC : -1L, NULL_PLUGIN_PROPERTIES, requestOptions);
}

protected Account createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice() throws Exception {
final Account accountJson = createAccountWithDefaultPaymentMethod();
assertNotNull(accountJson);

// Add a bundle, subscription and move the clock to get the first invoice
final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
ProductCategory.BASE, BillingPeriod.MONTHLY, true);
assertNotNull(subscriptionJson);
clock.addDays(32);
Expand All @@ -230,7 +230,7 @@ protected Account createAccountWithExternalPMBundleAndSubscriptionAndManualPayTa
assertEquals(accountTag.get(0).getTagDefinitionId(), ControlTagType.MANUAL_PAY.getId());

// Add a bundle, subscription and move the clock to get the first invoice
final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
ProductCategory.BASE, BillingPeriod.MONTHLY, true);
assertNotNull(subscriptionJson);
clock.addDays(32);
Expand All @@ -245,7 +245,7 @@ protected Account createAccountNoPMBundleAndSubscription() throws Exception {
assertNotNull(accountJson);

// Add a bundle, subscription and move the clock to get the first invoice
final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
ProductCategory.BASE, BillingPeriod.MONTHLY, true);
assertNotNull(subscriptionJson);

Expand All @@ -258,7 +258,7 @@ protected Account createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice()
assertNotNull(accountJson);

// Add a bundle, subscription and move the clock to get the first invoice
final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
ProductCategory.BASE, BillingPeriod.MONTHLY, true);
assertNotNull(subscriptionJson);
clock.addMonths(1);
Expand Down
Expand Up @@ -21,8 +21,8 @@
import java.util.List;
import java.util.UUID;

import org.killbill.billing.client.model.Account;
import org.killbill.billing.client.model.AccountEmail;
import org.killbill.billing.client.model.gen.Account;
import org.killbill.billing.client.model.gen.AccountEmail;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -35,44 +35,44 @@ public void testAddAndRemoveAccountEmail() throws Exception {

final String email1 = UUID.randomUUID().toString();
final String email2 = UUID.randomUUID().toString();
final AccountEmail accountEmailJson1 = new AccountEmail(accountId, email1);
final AccountEmail accountEmailJson2 = new AccountEmail(accountId, email2);
final AccountEmail accountEmailJson1 = new AccountEmail(accountId, email1, null);
final AccountEmail accountEmailJson2 = new AccountEmail(accountId, email2, null);

// Verify the initial state
final List<AccountEmail> firstEmails = killBillClient.getEmailsForAccount(accountId);
final List<AccountEmail> firstEmails = accountApi.getEmails(accountId, requestOptions);
Assert.assertEquals(firstEmails.size(), 0);

// Add an email
killBillClient.addEmailToAccount(accountEmailJson1, createdBy, reason, comment);
accountApi.addEmail(accountEmailJson1, accountId, requestOptions);

// Verify we can retrieve it
final List<AccountEmail> secondEmails = killBillClient.getEmailsForAccount(accountId);
final List<AccountEmail> secondEmails = accountApi.getEmails(accountId, requestOptions);
Assert.assertEquals(secondEmails.size(), 1);
Assert.assertEquals(secondEmails.get(0).getAccountId(), accountId);
Assert.assertEquals(secondEmails.get(0).getEmail(), email1);

// Add another email
killBillClient.addEmailToAccount(accountEmailJson2, createdBy, reason, comment);
accountApi.addEmail(accountEmailJson2, accountId, requestOptions);

// Verify we can retrieve both
final List<AccountEmail> thirdEmails = killBillClient.getEmailsForAccount(accountId);
final List<AccountEmail> thirdEmails = accountApi.getEmails(accountId, requestOptions);
Assert.assertEquals(thirdEmails.size(), 2);
Assert.assertEquals(thirdEmails.get(0).getAccountId(), accountId);
Assert.assertEquals(thirdEmails.get(1).getAccountId(), accountId);
Assert.assertTrue(thirdEmails.get(0).getEmail().equals(email1) || thirdEmails.get(0).getEmail().equals(email2));
Assert.assertTrue(thirdEmails.get(1).getEmail().equals(email1) || thirdEmails.get(1).getEmail().equals(email2));

// Delete the first email
killBillClient.removeEmailFromAccount(accountEmailJson1, createdBy, reason, comment);
accountApi.removeEmail(accountId, accountEmailJson1.getEmail(), requestOptions);

// Verify it has been deleted
final List<AccountEmail> fourthEmails = killBillClient.getEmailsForAccount(accountId);
final List<AccountEmail> fourthEmails = accountApi.getEmails(accountId, requestOptions);
Assert.assertEquals(fourthEmails.size(), 1);
Assert.assertEquals(fourthEmails.get(0).getAccountId(), accountId);
Assert.assertEquals(fourthEmails.get(0).getEmail(), email2);

// Try to add the same email
killBillClient.addEmailToAccount(accountEmailJson2, createdBy, reason, comment);
Assert.assertEquals(killBillClient.getEmailsForAccount(accountId), fourthEmails);
accountApi.addEmail(accountEmailJson2, accountId, requestOptions);
Assert.assertEquals(accountApi.getEmails(accountId, requestOptions), fourthEmails);
}
}

0 comments on commit f27137c

Please sign in to comment.