<commit_before>package com.braintreegateway.integrationtest;

import com.braintreegateway.*;
import com.braintreegateway.SandboxValues.TransactionAmount;
import com.braintreegateway.Subscription.Status;
import com.braintreegateway.exceptions.NotFoundException;
import com.braintreegateway.testhelpers.MerchantAccountTestConstants;
import com.braintreegateway.testhelpers.TestHelper;
import com.braintreegateway.util.Http;
import com.braintreegateway.util.NodeWrapper;
import com.braintreegateway.util.NodeWrapperFactory;
import org.junit.Before;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.*;

import static org.junit.Assert.*;

public class SubscriptionIT implements MerchantAccountTestConstants {

    private BraintreeGateway gateway;
    private Customer customer;
    private CreditCard creditCard;

    @Before
    public void createGateway() {
        this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key");
        CustomerRequest request = new CustomerRequest();
        request.
                creditCard().
                cardholderName("<NAME>").
                number("5105105105105100").
                expirationDate("05/12").
                done();

        Result<Customer> result = gateway.customer().create(request);
        assertTrue(result.isSuccess());
        this.customer = result.getTarget();
        this.creditCard = customer.getCreditCards().get(0);
    }

    @SuppressWarnings("deprecation")
    @Test
    public void createSimpleSubscriptionWithoutTrial() {
        Plan plan = PlanFixture.PLAN_WITHOUT_TRIAL;
        SubscriptionRequest request = new SubscriptionRequest().
                paymentMethodToken(creditCard.getToken()).
                planId(plan.getId());

        Result<Subscription> createResult = gateway.subscription().create(request);
        assertTrue(createResult.isSuccess());
        Subscription subscription = createResult.getTarget();

        Calendar expectedBillingPeriodEndDate = Calendar.getInstance();
        expectedBillingPeriodEndDate.setTimeZone(TimeZone.getTimeZone("US/Mountain"));
        expectedBillingPeriodEndDate.add(Calendar.MONTH, plan.getBillingFrequency());
        expectedBillingPeriodEndDate.add(Calendar.DAY_OF_MONTH, -1);
        Calendar expectedNextBillingDate = Calendar.getInstance();
        expectedNextBillingDate.setTimeZone(TimeZone.getTimeZone("US/Mountain"));
        expectedNextBillingDate.add(Calendar.MONTH, plan.getBillingFrequency());
        Calendar expectedBillingPeriodStartDate = Calendar.getInstance();
        expectedBillingPeriodStartDate.setTimeZone(TimeZone.getTimeZone("US/Mountain"));
        Calendar expectedFirstDate = Calendar.getInstance();
        expectedFirstDate.setTimeZone(TimeZone.getTimeZone("US/Mountain"));

        assertEquals(creditCard.getToken(), subscription.getPaymentMethodToken());
        assertEquals(plan.getId(), subscription.getPlanId());
        assertEquals(plan.getPrice(), subscription.getPrice());
        assertEquals(new BigDecimal("0.00"), subscription.getBalance());
        assertEquals(new Integer(1), subscription.getCurrentBillingCycle());
        assertEquals(new BigDecimal("12.34"), subscription.getNextBillAmount());
        assertEquals(new BigDecimal("12.34"), subscription.getNextBillingPeriodAmount());
        assertTrue(subscription.getId().matches("^\\w{6}$"));
        assertEquals(Subscription.Status.ACTIVE, subscription.getStatus());
        assertEquals(new Integer(0), subscription.getFailureCount());
        assertEquals(false, subscription.hasTrialPeriod());
        assertEquals(DEFAULT_MERCHANT_ACCOUNT_ID, subscription.getMerchantAccountId());

        Calendar expectedCreateUpdateDate = Calendar.getInstance();
        expectedCreateUpdateDate.add(Calendar.HOUR, -1);
        assertTrue(expectedCreateUpdateDate.compareTo(subscription.getCreatedAt()) < 0);
        assertTrue(expectedCreateUpdateDate.compareTo(subscription.getUpdatedAt()) < 0);

        assertEquals(Subscription.Status.ACTIVE, subscription.getStatusHistory().get(0).getStatus());
        assertEquals(new BigDecimal("12.34"), subscription.getStatusHistory().get(0).getPrice());
        assertEquals(new BigDecimal("0.00"), subscription.getStatusHistory().get(0).getBalance());

        TestHelper.assertDatesEqual(expectedBillingPeriodEndDate, subscription.getBillingPeriodEndDate());
        TestHelper.assertDatesEqual(expectedBillingPeriodStartDate, subscription.getBillingPeriodStartDate());
        TestHelper.assertDatesEqual(expectedBillingPeriodEndDate, subscription.getPaidThroughDate());
        TestHelper.assertDatesEqual(expectedNextBillingDate, subscription.getNextBillingDate());
        TestHelper.assertDatesEqual(expectedFirstDate, subscription.getFirstBillingDate());
    }

    @SuppressWarnings("deprecation")<commit_msg>Revert "Revert "interruptions 6db1UNR6 - Test subscription status event source.""<commit_after>package com.braintreegateway.integrationtest;

import com.braintreegateway.*;
import com.braintreegateway.SandboxValues.TransactionAmount;
import com.braintreegateway.Subscription.Status;
import com.braintreegateway.exceptions.NotFoundException;
import com.braintreegateway.testhelpers.MerchantAccountTestConstants;
import com.braintreegateway.testhelpers.TestHelper;
import com.braintreegateway.util.Http;
import com.braintreegateway.util.NodeWrapper;
import com.braintreegateway.util.NodeWrapperFactory;
import org.junit.Before;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.*;

import static org.junit.Assert.*;

public class SubscriptionIT implements MerchantAccountTestConstants {

    private BraintreeGateway gateway;
    private Customer customer;
    private CreditCard creditCard;

    @Before
    public void createGateway() {
        this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key");
        CustomerRequest request = new CustomerRequest();
        request.
                creditCard().
                cardholderName("<NAME>").
                number("5105105105105100").
                expirationDate("05/12").
                done();

        Result<Customer> result = gateway.customer().create(request);
        assertTrue(result.isSuccess());
        this.customer = result.getTarget();
        this.creditCard = customer.getCreditCards().get(0);
    }

    @SuppressWarnings("deprecation")
    @Test
    public void createSimpleSubscriptionWithoutTrial() {
        Plan plan = PlanFixture.PLAN_WITHOUT_TRIAL;
        SubscriptionRequest request = new SubscriptionRequest().
                paymentMethodToken(creditCard.getToken()).
                planId(plan.getId());

        Result<Subscription> createResult = gateway.subscription().create(request);
        assertTrue(createResult.isSuccess());
        Subscription subscription = createResult.getTarget();

        Calendar expectedBillingPeriodEndDate = Calendar.getInstance();
        expectedBillingPeriodEndDate.setTimeZone(TimeZone.getTimeZone("US/Mountain"));
        expectedBillingPeriodEndDate.add(Calendar.MONTH, plan.getBillingFrequency());
        expectedBillingPeriodEndDate.add(Calendar.DAY_OF_MONTH, -1);
        Calendar expectedNextBillingDate = Calendar.getInstance();
        expectedNextBillingDate.setTimeZone(TimeZone.getTimeZone("US/Mountain"));
        expectedNextBillingDate.add(Calendar.MONTH, plan.getBillingFrequency());
        Calendar expectedBillingPeriodStartDate = Calendar.getInstance();
        expectedBillingPeriodStartDate.setTimeZone(TimeZone.getTimeZone("US/Mountain"));
        Calendar expectedFirstDate = Calendar.getInstance();
        expectedFirstDate.setTimeZone(TimeZone.getTimeZone("US/Mountain"));

        assertEquals(creditCard.getToken(), subscription.getPaymentMethodToken());
        assertEquals(plan.getId(), subscription.getPlanId());
        assertEquals(plan.getPrice(), subscription.getPrice());
        assertEquals(new BigDecimal("0.00"), subscription.getBalance());
        assertEquals(new Integer(1), subscription.getCurrentBillingCycle());
        assertEquals(new BigDecimal("12.34"), subscription.getNextBillAmount());
        assertEquals(new BigDecimal("12.34"), subscription.getNextBillingPeriodAmount());
        assertTrue(subscription.getId().matches("^\\w{6}$"));
        assertEquals(Subscription.Status.ACTIVE, subscription.getStatus());
        assertEquals(new Integer(0), subscription.getFailureCount());
        assertEquals(false, subscription.hasTrialPeriod());
        assertEquals(DEFAULT_MERCHANT_ACCOUNT_ID, subscription.getMerchantAccountId());

        Calendar expectedCreateUpdateDate = Calendar.getInstance();
        expectedCreateUpdateDate.add(Calendar.HOUR, -1);
        assertTrue(expectedCreateUpdateDate.compareTo(subscription.getCreatedAt()) < 0);
        assertTrue(expectedCreateUpdateDate.compareTo(subscription.getUpdatedAt()) < 0);

        assertEquals(Subscription.Status.ACTIVE, subscription.getStatusHistory().get(0).getStatus());
        assertEquals(Subscription.Source.API, subscription.getStatusHistory().get(0).getSource());
        assertEquals(new BigDecimal("12.34"), subscription.getStatusHistory().get(0).getPrice());
        assertEquals(new BigDecimal("0.00"), subscription.getStatusHistory().get(0).getBalance());

        TestHelper.assertDatesEqual(expectedBillingPeriodEndDate, subscription.getBillingPeriodEndDate());
        TestHelper.assertDatesEqual(expectedBillingPeriodStartDate, subscription.getBillingPeriodStartDate());
        TestHelper.assertDatesEqual(expectedBillingPeriodEndDate, subscription.getPaidThroughDate());
        TestHelper.assertDatesEqual(expectedNextBillingDate, subscription.getNextBillingDate());
        TestHelper.assertDatesEqual(expectedFirstDate, subscription.getFirstBillingDate());
    }

    @SuppressWarnings("deprecation")
{'fraction_non_alphanumeric': 0.10831083108310831, 'fraction_numerical': 0.0102010201020102, 'mean_word_length': 4.583472920156337, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7488879', 'n_tokens_mistral': 2629, 'n_tokens_neox': 2532, 'n_words': 353}