com.skplanet.syruppay.token.SyrupPayTokenBuilderTest.java Source code

Java tutorial

Introduction

Here is the source code for com.skplanet.syruppay.token.SyrupPayTokenBuilderTest.java

Source

/*
 * Syrup Pay Token Library
 *
 * Copyright (C) 2015 SK PLANET. ALL Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the SK PLANET., Bundang-gu, 264,
 * Pangyo-ro The Planet SK planet co., Ltd., Seongnam-si, Gyeonggi-do, Korea
 * or see https://www.syruppay.co.kr/
 */

/*
 * Syrup Pay Token Library
 *
 * Copyright (C) 2015 SK PLANET. ALL Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the SK PLANET., Bundang-gu, 264,
 * Pangyo-ro The Planet SK planet co., Ltd., Seongnam-si, Gyeonggi-do, Korea
 * or see https://www.syruppay.co.kr/
 */

/*
 * Syrup Pay Token Library
 *
 * Copyright (C) 2015 SK PLANET. ALL Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the SK PLANET., Bundang-gu, 264,
 * Pangyo-ro The Planet SK planet co., Ltd., Seongnam-si, Gyeonggi-do, Korea
 * or see https://www.syruppay.co.kr/
 */

package com.skplanet.syruppay.token;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.skplanet.jose.Jose;
import com.skplanet.jose.JoseBuilders;
import com.skplanet.syruppay.token.claims.MapToSyrupPayUserConfigurer;
import com.skplanet.syruppay.token.claims.PayConfigurer;
import com.skplanet.syruppay.token.claims.SubscriptionConfigurer;
import com.skplanet.syruppay.token.domain.Mocks;
import com.skplanet.syruppay.token.domain.TokenHistories;
import com.skplanet.syruppay.token.jwt.SyrupPayToken;
import com.skplanet.syruppay.token.jwt.Token;
import org.apache.commons.codec.binary.Base64;
import org.junit.Before;
import org.junit.Test;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.security.spec.KeySpec;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;

public class SyrupPayTokenBuilderTest {
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
    SyrupPayTokenBuilder syrupPayTokenBuilder;

    @Before
    public void setUp() throws Exception {
        syrupPayTokenBuilder = new SyrupPayTokenBuilder();
    }

@Test
public void ??_()throws Exception
    {
        // Give
        SyrupPayTokenBuilder t = new SyrupPayTokenBuilder();

        // When

        // Then
        assertThat(t, is(notNullValue()));
        assertThat(t.getClass().getName(), is(SyrupPayTokenBuilder.class.getName()));
    }

    @Test
    public void MctAccToken_?_?_?_?()throws Exception
    {
        // Give
        syrupPayTokenBuilder.of("?");

        // When
        String s = syrupPayTokenBuilder.generateTokenBy("keys");

        // Then
        assertThat(s, is(notNullValue()));
        assertThat(s.length(), is(not(0)));
    }

    @Test
    public void MctAccToken_?_?_?_?()throws Exception
    {
        // Give
        syrupPayTokenBuilder.of("?").login().withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId(
                        "? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ");

        // When
        String s = syrupPayTokenBuilder.generateTokenBy("keys");

        // Then
        assertThat(s, is(notNullValue()));
        assertThat(s.length(), is(not(0)));
    }

@Test(expected = IllegalArgumentException.class)
public void iss___() throws Exception {
    // Give
    SyrupPayTokenBuilder t = new SyrupPayTokenBuilder();

    // When
    t.build();

    // Then
}

    @Test
    public void ____10__?()throws Exception
    {
        // Give
        syrupPayTokenBuilder.of("test");

        // When

        // Then
        Token t = OBJECT_MAPPER.readValue(syrupPayTokenBuilder.toJson(), SyrupPayToken.class);
        assertThat(t, is(notNullValue()));
        assertThat(t.getExp() - t.getIat(), is((long) (10 * 60)));
    }

    @Test
    public void _60___?()throws Exception
    {
        // Give
        syrupPayTokenBuilder.of("test");

        // When
        syrupPayTokenBuilder.expiredMinutes(60);

        // Then
        Token t = OBJECT_MAPPER.readValue(syrupPayTokenBuilder.toJson(), SyrupPayToken.class);
        assertThat(t, is(notNullValue()));
        assertThat(t.getExp() - t.getIat(), is((long) (60 * 60)));
    }

    @Test
    public void _0___?()throws Exception
    {
        // Give
        syrupPayTokenBuilder.of("test");

        // When
        syrupPayTokenBuilder.expiredMinutes(0);

        // Then
        Token t = OBJECT_MAPPER.readValue(syrupPayTokenBuilder.toJson(), SyrupPayToken.class);
        assertThat(t, is(notNullValue()));
        assertThat(t.getExp(), is(t.getIat()));
    }

    @Test
    public void _?_1____?()throws Exception
    {
        // Give
        syrupPayTokenBuilder.of("test");

        // When
        syrupPayTokenBuilder.expiredMinutes(-1);

        // Then
        Token t = OBJECT_MAPPER.readValue(syrupPayTokenBuilder.toJson(), SyrupPayToken.class);
        assertThat(t, is(notNullValue()));
        assertThat(t.isValidInTime(), is(false));
    }

    @Test
    public void ?_?_ __() throws Exception {
    // Give
    // @formatter:off
    syrupPayTokenBuilder.of("?")
            .login()
                .withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId("? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ")
            .and()
            .mapToSyrupPayUser()
                .withType(MapToSyrupPayUserConfigurer.MappingType.CI_MAPPED_KEY)
                .withValue("4987234")
                .withIdentityAuthenticationId("bddb74b0-981f-4070-8c02-0cdf324f46f6"); // Optional
    // @formatter:on
    // When
    String t = syrupPayTokenBuilder.generateTokenBy("??  ");
    System.out.println(t);
    // Then
    assertThat(t, is(notNullValue()));
    assertThat(t.length(), is(not(0)));
}

    @Test(expected = AlreadyBuiltException.class)
    public void ?_?_?_()throws Exception
    {
        // Give
        syrupPayTokenBuilder.of("?").generateTokenBy("??  ");

        // When
        syrupPayTokenBuilder.generateTokenBy("???  ");

        // Then
        // throw exception
    }

@Test
public void __?_?()throws Exception
    {
        // Give
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("??   ID")
                .withProductTitle("").withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(50000)
                .withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        String t = syrupPayTokenBuilder.generateTokenBy("??  ");

        // Then
        assertThat(t, is(notNullValue()));
        assertThat(t.length(), is(not(0)));
    }

@Test
public void ?_()throws Exception
    {
        // Given
        // @formatter:off
        String t = syrupPayTokenBuilder.of("?").login()
                .withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId(
                        "? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ").and()
                .generateTokenBy("??  ");
        // @formatter:on

        // When
        Token token = SyrupPayTokenBuilder.verify(t, "??  ");

        // Then
        assertThat(token, is(notNullValue()));
        assertThat(token.isValidInTime(), is(true));
        assertThat(token.getIss(), is("?"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void ?_?ID___?_?()throws Exception
    {
        // Given
        syrupPayTokenBuilder.of("?").login().withSsoCredential("SSO   ?  ");

        // When
        String token = syrupPayTokenBuilder.generateTokenBy("??  ");

        // Then
        // throw Exception
    }

    @Test(expected = IllegalArgumentException.class)
    public void ___?___?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("??   ID")
                //.withProductTitle("")
                .withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(50000)
                .withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        String t = syrupPayTokenBuilder.generateTokenBy("??  ");

        // Then
        // throw Exception
    }

    @Test(expected = IllegalArgumentException.class)
    public void _____?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("??   ID")
                .withProductTitle("").withLanguageForDisplay(PayConfigurer.Language.KO)
                //.withAmount(50000)
                .withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        String t = syrupPayTokenBuilder.generateTokenBy("??  ");

        // Then
        // throw Exception
    }

    @Test(expected = IllegalArgumentException.class)
    public void ___?___?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("??   ID")
                .withProductTitle("").withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(-1)
                .withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        String t = syrupPayTokenBuilder.generateTokenBy("??  ");

        // Then
        // throw Exception
    }

    @Test(expected = IllegalArgumentException.class)
    public void ___0___?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("??   ID")
                .withProductTitle("").withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(0)
                .withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        String t = syrupPayTokenBuilder.generateTokenBy("??  ");

        // Then
        // throw Exception
    }

    @Test
    public void ______?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("??   ID")
                .withProductTitle("").withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(500000)
                //.withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        Token token = SyrupPayTokenBuilder.verify(
                syrupPayTokenBuilder.generateTokenBy("??  "),
                "??  ");

        // Then
        assertThat(token.getTransactionInfo().getPaymentInfo().getCurrencyCode(), is("KRW"));
    }

    @Test
    public void _____?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("??   ID")
                .withProductTitle("")
                //.withLanguageForDisplay(PayConfigurer.Language.KO)
                .withAmount(5550).withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        Token token = SyrupPayTokenBuilder.verify(
                syrupPayTokenBuilder.generateTokenBy("??  "),
                "??  ");

        // Then
        assertThat(token.getTransactionInfo().getPaymentInfo().getLang(), is("KO"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void ______?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("??   ID")
                .withProductTitle("").withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(0)
                .withCurrency(PayConfigurer.Currency.KRW)
                //.withShippingAddress(new PayConfigurer.ShippingAddress("137-332", " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        String t = syrupPayTokenBuilder.generateTokenBy("??  ");

        // Then
        // throw Exception
    }

    @Test
    public void __?_ID_40?___?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("1234567890123456789012345678901234567890")
                .withProductTitle("").withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(50000)
                .withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        Token token = SyrupPayTokenBuilder.verify(
                syrupPayTokenBuilder.generateTokenBy("??  "),
                "??  ");

        // Then
        assertThat(token.getTransactionInfo().getMctTransAuthId().length(), is(40));
    }

    @Test(expected = IllegalArgumentException.class)
    public void __?_ID_41?___?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay()
                .withOrderIdOfMerchant("12345678901234567890123456789012345678901").withProductTitle("")
                .withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(50000)
                .withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        String t = syrupPayTokenBuilder.generateTokenBy("??  ");

        // Then
        // throw Exception
    }

    @Test
    public void ___?_URL__?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("1234567890123456789012345678901234567890")
                .withProductTitle("")
                .withProductUrls(
                        "http://www.11st.co.kr/product/SellerProductDetail.tmall?method=getSellerProductDetail&prdNo=1354119088&trTypeCd=22&trCtgrNo=895019")
                .withMerchantDefinedValue("{\n" + "\"id_1\": \"value\",\n" + "\"id_2\": 2\n" + "}")
                .withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(50000)
                .withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        Token token = SyrupPayTokenBuilder.verify(
                syrupPayTokenBuilder.generateTokenBy("??  "),
                "??  ");

        // Then
        assertThat(token.getTransactionInfo().getPaymentInfo().getProductUrls().size(), is(1));
    }

    @Test(expected = IllegalArgumentException.class)
    public void ___?_URL?_HTTP_____?_?()throws Exception
    {
        // @formatter:off
        syrupPayTokenBuilder.of("?").pay().withOrderIdOfMerchant("1234567890123456789012345678901234567890")
                .withProductTitle("")
                .withProductUrls(
                        "h://www.11st.co.kr/product/SellerProductDetail.tmall?method=getSellerProductDetail&prdNo=1354119088&trTypeCd=22&trCtgrNo=895019")
                .withLanguageForDisplay(PayConfigurer.Language.KO).withAmount(50000)
                .withCurrency(PayConfigurer.Currency.KRW)
                .withShippingAddress(new PayConfigurer.ShippingAddress("137-332",
                        " ?? ", "1? 1", "", "", "KR"))
                .withDeliveryPhoneNumber("01011112222").withDeliveryName(" ?")
                .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(
                        " ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6"))
                .withBeAbleToExchangeToCash(false)
                .withPayableRuleWithCard(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR);
        // @formatter:on
        // When
        Token token = SyrupPayTokenBuilder.verify(
                syrupPayTokenBuilder.generateTokenBy("??  "),
                "??  ");

        // Then
        // throw exception
    }

    @Test
    public void ?_???___()throws Exception
    {
        // Given
        // @formatter:off
        String t = syrupPayTokenBuilder.of("?").login()
                .withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId(
                        "? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ").and().mapToSyrupPayUser()
                .withType(MapToSyrupPayUserConfigurer.MappingType.CI_HASH).withValue("asdkfjhsakdfj").and()
                .generateTokenBy("??  ");
        // @formatter:on

        // When
        Token token = SyrupPayTokenBuilder.verify(t, "??  ");

        // Then
        assertThat(token, is(notNullValue()));
        assertThat(token.isValidInTime(), is(true));
        assertThat(token.getIss(), is("?"));
        assertThat(token.getUserInfoMapper(), is(notNullValue()));
        assertThat(token.getUserInfoMapper().getMappingValue(), is("asdkfjhsakdfj"));
    }

    @Test
    public void ??_?_??_?_?()throws Exception
    {
    // @formatter:off
    syrupPayTokenBuilder.of("?")
                        .checkout()
                            .withProductPrice(5000)
                            .withOffers(Mocks.offerList)
                            .withLoyalties(Mocks.loyalList)
                            .withProductDeliveryInfo(Mocks.productDeliveryInfoList.get(0))
                            .withShippingAddresses(Mocks.shippingAddressList)
                            .withSubmallName("11")
            ;
    // @formatter:on
    // When
    Token token = SyrupPayTokenBuilder.verify(syrupPayTokenBuilder.generateTokenBy("??  "), "??  ");

    // Then
    assertThat(token.getCheckoutInfo(), is(notNullValue()));
    assertThat(token.getCheckoutInfo().getProductPrice(), is(5000));
}

@Test
public void _1_2_30__()throws IOException,InvalidTokenException
    {
        SyrupPayTokenBuilder.uncheckHeaderOfToken();
        Token t = SyrupPayTokenBuilder.verify(TokenHistories.VERSION_1_2_30.token,
                TokenHistories.VERSION_1_2_30.key);
        System.out.println(new ObjectMapper().writeValueAsString(t));
    }

@Test
public void C__0_0_1__()throws IOException,InvalidTokenException
    {
        SyrupPayTokenBuilder.uncheckHeaderOfToken();
        Token t = SyrupPayTokenBuilder.verify(TokenHistories.C_SHARP_0_0_1.token, TokenHistories.C_SHARP_0_0_1.key);
        System.out.println(new ObjectMapper().writeValueAsString(t));
    }

@Test
public void _1_3_4__CJOSHOPPING_()throws Exception
    {
        SyrupPayTokenBuilder.uncheckHeaderOfToken();
        Token t = SyrupPayTokenBuilder.verify(TokenHistories.VERSION_1_3_4_BY_CJOSHOPPING.token,
                TokenHistories.VERSION_1_3_4_BY_CJOSHOPPING.key);
        assertThat(t.getTransactionInfo().getMctTransAuthId(), is(notNullValue()));
        assertThat(t.getTransactionInfo().getPaymentRestrictions().getCardIssuerRegion(), is(notNullValue()));
    }

@Test(expected = Exception.class)
public void ?_?__()throws IOException,InvalidTokenException
    {
        SyrupPayTokenBuilder.uncheckHeaderOfToken();
        Token t = SyrupPayTokenBuilder.verify(TokenHistories.VERSION_1_3_5_INVALID.token,
                TokenHistories.VERSION_1_3_5_INVALID.key);
        assertThat(t.getTransactionInfo().getMctTransAuthId(), is(notNullValue()));
        assertThat(t.getTransactionInfo().getPaymentRestrictions().getCardIssuerRegion(), is(notNullValue()));
    }

@Test
public void PHP__??_?__()throws IOException,InvalidTokenException
    {
        SyrupPayTokenBuilder.uncheckHeaderOfToken();
        Token t = SyrupPayTokenBuilder.verify(TokenHistories.PHP_TO_LOGIN_VERSION_1_0_0.token,
                TokenHistories.PHP_TO_LOGIN_VERSION_1_0_0.key);
        System.out.println(new ObjectMapper().writeValueAsString(t));
    }

@Test
public void PHP___?__()throws IOException,InvalidTokenException
    {
        SyrupPayTokenBuilder.uncheckHeaderOfToken();
        Token t = SyrupPayTokenBuilder.verify(TokenHistories.PHP_TO_PAY_VERSION_1_0_0.token,
                TokenHistories.PHP_TO_PAY_VERSION_1_0_0.key);
        System.out.println(new ObjectMapper().writeValueAsString(t));
    }

@Test
public void ??__??_?_?()throws Exception
    {
        // Given
        // @formatter:off
        String t = syrupPayTokenBuilder.of("?").login()
                .withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId(
                        "? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ").and().subscription()
                .withAutoPaymentId("? ? ?? ID") // Optional
                .withRestrictionOf(PayConfigurer.MatchedUser.CI_MATCHED_ONLY) // Optional
                .withMerchantSubscriptionRequestId("??  ? ID ?") // Optional
                .with(new SubscriptionConfigurer.Plan(SubscriptionConfigurer.Interval.WEEKLY, ""))
                .withPromotionCode("PROMOTION_CODE_001").and()
                .generateTokenBy("??  ");
        // @formatter:on
        System.out.printf(t);
        // When
        Token token = SyrupPayTokenBuilder.verify(t, "??  ");

        // Then
        assertThat(token, is(notNullValue()));
        assertThat(token.isValidInTime(), is(true));
        assertThat(token.getIss(), is("?"));
    }

@Test
public void OCB_()throws Exception
    {
        String t = "eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoic2t0bWFsbF9zMDAyIiwidmVyIjoiMS4zLjIifQ.RTsmoCwCgsBViSsQUzYy4iNM3MYVTmpbf9J5be_Kpf9pw5s8xrdGAQ.7wrdUYUgLnTXfK-B_Bjlhg.WiffmU_pgYtsPWi95sfRmGNyM8bIBWNN7YTUPW6LX14zWgOu8O43YIADhgZtG5b_65iBxq--vS1D_cKEPp523okH4cDLwaubsw8xkkh1ke_E9mxpXhEvjdPRyK4Kv7khYeBn3T515cby3fzHX5Ubv5qx3uJ_1u9udkCJ8LqdZEzyIfWeTIHQZTt2C3NAVWBK2s8dGSGsQLsRzKks-7BAMMVyS-IE_UYoQ4OQ5q41kyMIxqbstEiheYx8A-BU32KvBU_EqcS_zeRE-LgwgVIjh35KezLmdQQnD1Sp3aDMrV0.cYCigQ6r-1hv0oDtxqs0dA";

        String json = new Jose().configuration(JoseBuilders.compactDeserializationBuilder().serializedSource(t)
                .key("crTKa9RY5Re0J0UYSin9cFap6x5UDsib")).deserialization();
        System.out.printf(json);
    }

@Test
public void AES_MODE___ERROR() throws Exception {
    final String keyFactorySalt = "65594821073030071593";
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "SunJCE");
    SecretKeySpec secretKeySpec;
    try {
        KeySpec spec = new PBEKeySpec("7244798e1fab1a9175f752a8a7e12beafe2cd27b208f9f2f7ab43173358153fc5eae2499afa66f7386d74cb8cf4765133c513ae2e6acd521acde4f80d747".toCharArray(), keyFactorySalt.getBytes(), 1, 256);
        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
        SecretKey secretKey = secretKeyFactory.generateSecret(spec);
        secretKeySpec = new SecretKeySpec(secretKey.getEncoded(), "AES");
    } catch (Exception e) {
        throw e;
    }
    cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()]));
    System.out.println(new String(cipher.doFinal(Base64.decodeBase64("yMvtcFwlhwBg22GF-biF4A".getBytes())), "UTF-8"));
}

@Test
public void AES_MODE__()throws Exception
    {
        final String keyFactorySalt = "65594821073030071593";
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "SunJCE");
        SecretKeySpec secretKeySpec;
        try {
            KeySpec spec = new PBEKeySpec(
                    "56c32e32c94a9fbde34cbc25a3b232bf25e91ec3a8a67159cffef70b924a67dcca13fc364cdb10a7a265f5520469997709ce542e6644b861c585c7ccd2f3"
                            .toCharArray(),
                    keyFactorySalt.getBytes(), 1, 256);
            SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
            SecretKey secretKey = secretKeyFactory.generateSecret(spec);
            secretKeySpec = new SecretKeySpec(secretKey.getEncoded(), "AES");
        } catch (Exception e) {
            throw e;
        }
        cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()]));
        System.out.println(
                new String(cipher.doFinal(Base64.decodeBase64("yMvtcFwlhwBg22GF-biF4A".getBytes())), "UTF-8"));
    }

@Test
public void ??__??_?_?__?_?_()throws Exception
    {
    // Given
    // @formatter:off
    String t = syrupPayTokenBuilder.of("?")
            .login()
                .withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId("? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ")
            .and()
            .subscription()
                .withAutoPaymentId("? ? ?? ID") // Optional
                .withRestrictionOf(PayConfigurer.MatchedUser.CI_MATCHED_ONLY) // Optional
            .and()
            .generateTokenBy("??  ");
    // @formatter:on
    System.out.printf(t);
    // When
    Token token = SyrupPayTokenBuilder.verify(t, "??  ");

    // Then
    assertThat(token, is(notNullValue()));
    assertThat(token.getClaims(SyrupPayToken.Claim.TO_SUBSCRIPTION).size(), is(1));
    assertThat(token.getClaims(SyrupPayToken.Claim.TO_LOGIN).size(), is(1));
    assertThat(token.getClaims(SyrupPayToken.Claim.TO_PAY).size(), is(0));
}

@Test
public void ??__??_?_?___?_?_()throws Exception
    {
    // Given
    // @formatter:off
    String t = syrupPayTokenBuilder.of("?")
            .login()
                .withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId("? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ")
            .and()
            .subscription()
                .withAutoPaymentId("? ? ?? ID") // Optional
                .withRestrictionOf(PayConfigurer.MatchedUser.CI_MATCHED_ONLY) // Optional
            .and()
            .generateTokenBy("??  ");
    // @formatter:on
    System.out.printf(t);
    // When
    Token token = SyrupPayTokenBuilder.verify(t, "??  ");

    // Then
    assertThat(token, is(notNullValue()));
    assertThat(token.getClaim(SyrupPayToken.Claim.TO_SUBSCRIPTION), is(notNullValue()));
    assertThat(token.getClaim(SyrupPayToken.Claim.TO_LOGIN), is(notNullValue()));
    assertThat(token.getClaim(SyrupPayToken.Claim.TO_PAY), is(nullValue()));
}

@Test
public void ?_?_?_()throws Exception
    {
    // Given
    // @formatter:off
    String t = syrupPayTokenBuilder.of("?")
            .login()
                .withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId("? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ")
            .and()
            .mapToSyrupPayUser()
                .withType(MapToSyrupPayUserConfigurer.MappingType.ENCRYPTED_PERSONAL_INFO)
                .withValue(new MapToSyrupPayUserConfigurer.Personal("?", "1234567", "?"), "? ID", "??  ")
            .and()
            .generateTokenBy("??  ");
    // @formatter:on
    System.out.printf(t);
    // When
    Token token = SyrupPayTokenBuilder.verify(t, "??  ");

    // Then
    assertThat(token, is(notNullValue()));
    assertThat(token.getClaim(SyrupPayToken.Claim.TO_LOGIN), is(notNullValue()));
    assertThat(token.getClaim(SyrupPayToken.Claim.TO_MAP_USER), is(notNullValue()));
    assertThat(token.getUserInfoMapper().getPersonalIfNotExistThenNullWith("??  "), is(notNullValue()));
}

    @Test
    public void ?? _?_?_()throws Exception
    {
    // Given
    // @formatter:off
    String t = TokenHistories.VALIDATION_BACKWARD_OF_11ST.token;
    // @formatter:on

    SyrupPayTokenBuilder.uncheckHeaderOfToken();

    // When
    Token token = SyrupPayTokenBuilder.verify(t, TokenHistories.VALIDATION_BACKWARD_OF_11ST.key);

    // Then
    assertThat(token, is(notNullValue()));
    assertThat(token.getClaim(SyrupPayToken.Claim.TO_SUBSCRIPTION), is(nullValue()));
    assertThat(token.getClaim(SyrupPayToken.Claim.TO_LOGIN), is(notNullValue()));
    assertThat(token.getClaim(SyrupPayToken.Claim.TO_CHECKOUT), is(notNullValue()));
}

@Test
public void README__() throws Exception {
    // @formatter:off
    String token =
    new SyrupPayTokenBuilder().of("? ID")
        .login()
            .withMerchantUserId("?? ? ID ? ??")
            .withExtraMerchantUserId("? ? ?   ID    ") // Optional
            .withSsoCredential(" ? SSO")
        .and()
        .mapToSyrupPayUser() // Optional ? ? ? ? ? ??  ?  
            .withType(MapToSyrupPayUserConfigurer.MappingType.ENCRYPTED_PERSONAL_INFO)
            .withValue(new MapToSyrupPayUserConfigurer.Personal()
                    .setUsername("??")
                    .setSsnFirst7Digit("8011221")
                    .setLineNumber("01022223333")
                    .setOperatorCode(MapToSyrupPayUserConfigurer.OperatorCode.SKT)
                    .setCiHash("HHHHHHAAAAAAAAAAAASSSSSSSSSSSSSSHHHHHHHHHHH")
                    .setEmail("test@mail.com")
                    .setPayableCard(
                            new MapToSyrupPayUserConfigurer.PayableCard()
                                    .setCardNo("")
                                    .setExpireDate("202012")
                                    .setCardName("?")
                                    .setCardIssuerName("")
                                    .setCardIssuer("")
                                    .setCardAcquirer("")
                                    .setCardType(MapToSyrupPayUserConfigurer.CardType.CREDIT))
                    , "? ID", "??  ")
        .and()
        .pay()
            .withOrderIdOfMerchant("??   ID") // ? Transaction Id = mctTransAuthId
            .withProductTitle("")
            .withProductUrls(
                    "http://deal.11st.co.kr/product/SellerProductDetail.tmall?method=getSellerProductDetail&prdNo=1122841340",
                    "http://deal.11st.co.kr/product/SellerProductDetail.tmall?method=getSellerProductDetail&prdNo=1265508741"
            ) // Optional
            .withLanguageForDisplay(PayConfigurer.Language.KO)
            .withAmount(50000)
            .withCurrency(PayConfigurer.Currency.KRW)
            .withShippingAddress(new PayConfigurer.ShippingAddress("137-332", " ?? ", "1? 1", "", "", "kr")) // Optional
            .withDeliveryPhoneNumber("01011112222") // Optional
            .withDeliveryName(" ?") // Optional
            .withInstallmentPerCardInformation(new PayConfigurer.CardInstallmentInformation(" ", ". ex. NN1;NN2;YY3;YY4;YY5;NH6")) // Optional
            .withBeAbleToExchangeToCash(false) // Optional
            .withRestrictionOf(PayConfigurer.PayableLocaleRule.ONLY_ALLOWED_KOR) // Optional
            .withRestrictionPaymentTypeOf("CARD;MOBILE;BANK") // Optional
            .withMerchantDefinedValue("{" +
                    "\"id_1\": \"value\"," +
                    "\"id_2\": 2" +
                    "}") // Optional, JSON ? ?  Escape(\) ? ? , 1k 
            .withRestrictionOf(PayConfigurer.MatchedUser.CI_MATCHED_ONLY) // Optional. ? ? ? ??  ? ? 
        .and()
        .generateTokenBy("??  ");
    // @formatter:on
    System.out.printf(token);
    // When
    Token t = SyrupPayTokenBuilder.verify(token, "??  ");

    // Then
    assertThat(t, is(notNullValue()));
    assertThat(t.getClaim(SyrupPayToken.Claim.TO_LOGIN), is(notNullValue()));
    assertThat(t.getClaim(SyrupPayToken.Claim.TO_MAP_USER), is(notNullValue()));
    assertThat(t.getUserInfoMapper().getPersonalIfNotExistThenNullWith("??  "), is(notNullValue()));
}

@Test(expected = IllegalArgumentException.class)
public void ?_?_?__6?_()throws Exception
    {
        // Given
        // @formatter:off
        String t = syrupPayTokenBuilder.of("?").mapToSyrupPayUser()
                .withType(MapToSyrupPayUserConfigurer.MappingType.ENCRYPTED_PERSONAL_INFO)
                .withValue(new MapToSyrupPayUserConfigurer.Personal("?", "123456", "?"),
                        "? ID", "??  ")
                .and().generateTokenBy("??  ");
        // @formatter:on
        System.out.printf(t);
        // When
        Token token = SyrupPayTokenBuilder.verify(t, "??  ");

        // Then
        assertThat(token, is(notNullValue()));
        assertThat(token.getClaim(SyrupPayToken.Claim.TO_LOGIN), is(notNullValue()));
        assertThat(token.getClaim(SyrupPayToken.Claim.TO_MAP_USER), is(notNullValue()));
        assertThat(token.getUserInfoMapper().getPersonalIfNotExistThenNullWith("??  "),
                is(notNullValue()));
    }

@Test
public void ?_GETTER_()throws Exception
    {
        // Given
        // @formatter:off
        String t = syrupPayTokenBuilder.of("?").login()
                .withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId(
                        "? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ").and()
                .generateTokenBy("??  ");
        // @formatter:on
        System.out.printf(t);
        // When
        Token token = SyrupPayTokenBuilder.verify(t, "??  ");

        // Then
        assertThat(token, is(notNullValue()));
        assertThat(token.getClaim(SyrupPayToken.Claim.TO_LOGIN), is(notNullValue()));
        assertThat(token.getClaim(SyrupPayToken.Claim.TO_PAY), is(nullValue()));
    }

@Test
public void OCB_?_?_1_3_8__()throws IOException,InvalidTokenException
    {
        String t = TokenHistories.OCB_BACKWARE_VERSION_1_3_8.token;

        SyrupPayTokenBuilder.uncheckHeaderOfToken();

        // When
        Token token = SyrupPayTokenBuilder.verify(t, TokenHistories.OCB_BACKWARE_VERSION_1_3_8.key);

        // Then
        assertThat(token, is(notNullValue()));
        assertThat(token.getClaim(SyrupPayToken.Claim.TO_PAY), is(notNullValue()));
        assertThat(token.getClaim(SyrupPayToken.Claim.TO_LOGIN), is(notNullValue()));
    }

@Test(expected = AssertionError.class)
public void ?__Assert__SET_NULL_TO_?()
    {
        MapToSyrupPayUserConfigurer.Personal personal = new MapToSyrupPayUserConfigurer.Personal();
        personal.setUsername(null);
    }

@Test(expected = AssertionError.class)
public void ?__Assert__SET_BLANK_TO_?()
    {
        MapToSyrupPayUserConfigurer.Personal personal = new MapToSyrupPayUserConfigurer.Personal();
        personal.setUsername("");
    }

@Test
public void ?__Assert__SET_HASH_TO_?()
    {
        MapToSyrupPayUserConfigurer.Personal personal = new MapToSyrupPayUserConfigurer.Personal();
        personal.setUsername("??");
    }

    @Test
    public void ?_?_?_SSO__v1_3_11() throws Exception {
    // Give
    // @formatter:off
    syrupPayTokenBuilder.of("?")
            .login()
                .withMerchantUserId("?? ? ID ? ??")
                .withExtraMerchantUserId("? ? ?   ID    ")
                .withSsoCredential("SSO   ?  ")
                .isNotApplicableSso()
    ;

    // @formatter:on
    // When
    String t = syrupPayTokenBuilder.generateTokenBy("??  ");
    System.out.println(t);
    // Then
    assertThat(t, is(notNullValue()));
    assertThat(t.length(), is(not(0)));

    assertThat(SyrupPayTokenBuilder.verify(t, "??  ").getLoginInfo().getSsoPolicy(), is(notNullValue()));
}
}