-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Danillo Souza
committed
Jul 5, 2015
1 parent
68e40bc
commit b1608ff
Showing
16 changed files
with
326 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/sdk/jassinaturas/clients/attributes/CouponStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sdk.jassinaturas.clients.attributes; | ||
|
||
public enum CouponStatus { | ||
ACTIVE, INACTIVE | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/sdk/jassinaturas/clients/attributes/Discount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/sdk/jassinaturas/clients/attributes/DiscountType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sdk.jassinaturas.clients.attributes; | ||
|
||
public enum DiscountType { | ||
PERCENT, AMOUNT | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/sdk/jassinaturas/clients/attributes/Duration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/sdk/jassinaturas/clients/attributes/DurationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sdk.jassinaturas.clients.attributes; | ||
|
||
public enum DurationType { | ||
REPEATING, ONCE, FOREVER | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/test/java/sdk/jassinaturas/clients/CouponClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package sdk.jassinaturas.clients; | ||
|
||
import co.freeside.betamax.Betamax; | ||
import co.freeside.betamax.MatchRule; | ||
import co.freeside.betamax.Recorder; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import sdk.jassinaturas.Assinaturas; | ||
import sdk.jassinaturas.clients.attributes.Authentication; | ||
import sdk.jassinaturas.clients.attributes.Coupon; | ||
import sdk.jassinaturas.clients.attributes.CouponStatus; | ||
import sdk.jassinaturas.clients.attributes.Discount; | ||
import sdk.jassinaturas.clients.attributes.DiscountType; | ||
import sdk.jassinaturas.clients.attributes.Duration; | ||
import sdk.jassinaturas.clients.attributes.DurationType; | ||
import sdk.jassinaturas.clients.attributes.ExpirationDate; | ||
import sdk.jassinaturas.clients.attributes.Month; | ||
import sdk.jassinaturas.communicators.SandboxCommunicator; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
public class CouponClientTest { | ||
|
||
private final Assinaturas assinaturas = new Assinaturas(new Authentication("SGPA0K0R7O0IVLRPOVLJDKAWYBO1DZF3", | ||
"QUJESGM9JU175OGXRFRJIYM0SIFOMIFUYCBWH9WA"), new SandboxCommunicator()); | ||
|
||
@Rule | ||
public Recorder recorder = new Recorder(); | ||
|
||
@Betamax(tape = "ACTIVATE_COUPON", match = { MatchRule.method, MatchRule.uri }) | ||
@Test | ||
public void shouldActivateCoupon() throws Exception { | ||
Coupon coupon = assinaturas.coupons().activate("jassinaturas_coupon_01"); | ||
|
||
assertEquals(CouponStatus.ACTIVE, coupon.getStatus()); | ||
} | ||
|
||
@Betamax(tape = "INACTIVATE_COUPON", match = { MatchRule.method, MatchRule.uri }) | ||
@Test | ||
public void shouldInactivateCoupon() throws Exception { | ||
Coupon coupon = assinaturas.coupons().activate("jassinaturas_coupon_01"); | ||
|
||
assertEquals(CouponStatus.INACTIVE, coupon.getStatus()); | ||
} | ||
|
||
@Betamax(tape = "CREATE_COUPON", match = { MatchRule.body, MatchRule.method, MatchRule.uri }) | ||
@Test | ||
public void createCoupon() { | ||
Coupon toBeCreated = new Coupon(); | ||
|
||
toBeCreated.withCode("jassinaturas_coupon_01") | ||
.withName("JAssinaturas") | ||
.withDescription("Coupon for test control") | ||
.withDiscount(new Discount() | ||
.withValue(1000) | ||
.withType(DiscountType.PERCENT)) | ||
.withStatus(CouponStatus.ACTIVE) | ||
.withDuration(new Duration() | ||
.withType(DurationType.REPEATING) | ||
.withOccurrences(1)) | ||
.withExpirationDate(new ExpirationDate() | ||
.withDay(10) | ||
.withMonth(Month.OCTOBER) | ||
.withYear(2020)) | ||
.withMaxRedemptions(1000); | ||
|
||
Coupon coupon = assinaturas.coupons().create(toBeCreated); | ||
|
||
assertEquals("jassinaturas_coupon_01", coupon.getCode()); | ||
assertEquals("JAssinaturas", coupon.getName()); | ||
assertEquals("Coupon for test control", coupon.getDescription()); | ||
assertEquals(1000, coupon.getDiscount().getValue()); | ||
assertEquals(DiscountType.PERCENT, coupon.getDiscount().getType()); | ||
assertEquals(CouponStatus.ACTIVE, coupon.getStatus()); | ||
assertEquals(DurationType.REPEATING, coupon.getDuration().getType()); | ||
assertEquals(1, coupon.getDuration().getOccurrences()); | ||
assertEquals(10, coupon.getExpirationDate().getDay()); | ||
assertEquals(Month.OCTOBER, coupon.getExpirationDate().getMonth()); | ||
assertEquals(2020, coupon.getExpirationDate().getYear()); | ||
assertEquals(1000, coupon.getMaxRedemptions().intValue()); | ||
assertFalse(coupon.inUse()); | ||
assertEquals(21, coupon.getCreationDate().getDay()); | ||
assertEquals(Month.JUNE, coupon.getCreationDate().getMonth()); | ||
assertEquals(2015, coupon.getCreationDate().getYear()); | ||
assertEquals(21, coupon.getCreationDate().getHour()); | ||
assertEquals(51, coupon.getCreationDate().getMinute()); | ||
assertEquals(43, coupon.getCreationDate().getSecond()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import sdk.jassinaturas.clients.attributes.BillingInfo; | ||
import sdk.jassinaturas.clients.attributes.Birthdate; | ||
import sdk.jassinaturas.clients.attributes.Country; | ||
import sdk.jassinaturas.clients.attributes.Coupon; | ||
import sdk.jassinaturas.clients.attributes.CreditCard; | ||
import sdk.jassinaturas.clients.attributes.Customer; | ||
import sdk.jassinaturas.clients.attributes.Invoice; | ||
|
@@ -263,4 +264,19 @@ public void shouldGetResultFromToString() { | |
"Subscription [amount=100, code=subscription00001, creationDate=CreationDate [day=21, hour=23, minute=0, month=1, second=40, year=2014], customer=Customer [address=null, billingInfo=null, birthdate=null, code=customer000000001, cpf=null, customers=null, [email protected], fullname=Danillo Souza, message=null, phoneAreaCode=null, phoneNumber=null, birthdateDay=0, birthdateMonth=0, birthdateYear=0], expirationDate=ExpirationDate [day=17, month=OCTOBER, year=2016], invoice=null, invoices=null, message=null, nextInvoiceDate=NextInvoiceDate [day=1, month=5, year=2014], plan=Plan [alerts=null, amount=0, billingCycles=0, code=plan001, description=null, interval=null, maxQty=0, message=null, name=Plano de Teste Atualizado, plans=null, setupFee=0, status=null, trial=null], status=OVERDUE, subscriptions=null, coupon=null]", | ||
subscription); | ||
} | ||
|
||
@Betamax(tape = "UPDATE_SUBSCRIPTION_ADDING_COUPON", match = { MatchRule.method, MatchRule.uri }) | ||
@Test | ||
public void addingCouponToASubscription() { | ||
Subscription toUpdate = new Subscription(); | ||
toUpdate.withCode("assinatura46").withPlan(new Plan().withCode("plano01")).withAmount(990) | ||
.withNextInvoiceDate(new NextInvoiceDate().withDay(20).withMonth(Month.OCTOBER).withYear(2015)) | ||
.withCoupon(new Coupon().withCode("jassinaturas_coupon_01")); | ||
|
||
Subscription subscription = assinaturas.subscriptions().update(toUpdate); | ||
|
||
// There isn't any response from Moip Assinaturas when subscription is | ||
// updated | ||
// So, I didn't do any assert | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
!tape | ||
name: ACTIVATE_COUPON | ||
interactions: | ||
- recorded: 2015-06-22T01:12:44.107Z | ||
request: | ||
method: PUT | ||
uri: https://sandbox.moip.com.br/assinaturas/v1/coupons/jassinaturas_coupon_01/active | ||
headers: | ||
Accept: application/json | ||
Accept-Charset: utf-8 | ||
Accept-Encoding: utf-8 | ||
Authorization: Basic U0dQQTBLMFI3TzBJVkxSUE9WTEpES0FXWUJPMURaRjM6UVVKRVNHTTlKVTE3NU9HWFJGUkpJWU0wU0lGT01JRlVZQ0JXSDlXQQ== | ||
Connection: keep-alive | ||
Content-Type: application/json; charset=utf-8 | ||
Host: sandbox.moip.com.br | ||
User-Agent: Java/1.7.0_45 | ||
response: | ||
status: 200 | ||
headers: | ||
Content-Type: application/json | ||
Date: Mon, 22 Jun 2015 01:12:44 GMT | ||
Server: nginx | ||
Status: 200 OK | ||
X-Content-Type-Options: nosniff | ||
vary: Accept-Encoding | ||
x-newrelic-app-data: PxQFUlBXAQoTVlhbAwEOVUYdFGQHBDcQUQxLA1tMXV1dORYzVBJHNQFUZAQUFVFQVThOFAZtGAULREZcDBU/TUsBVxdIV1pxXAFcHG1OUgEQX0EERktoZmRNQ04HHwdKVB8EAlNSU1IEVxRSFBoCAwEGCAQEVVBXAgQFBVECGm4= | ||
body: '{"code":"jassinaturas_coupon_01","name":"JAssinaturas","description":"Coupon for test control","discount":{"value":1000,"type":"PERCENT"},"status":"ACTIVE","duration":{"type":"REPEATING","occurrences":1},"expiration_date":{"day":10,"month":10,"year":2020},"max_redemptions":1000,"in_use":false,"creation_date":{"day":21,"month":6,"year":2015,"hour":21,"minute":51,"second":43}}' |
Oops, something went wrong.