Search in sources :

Example 1 with HmacAuth

use of jp.ne.paypay.auth.HmacAuth in project paypayopa-sdk-java by paypay.

the class HmacAuthTest method hmacAuthTest.

@Test
public void hmacAuthTest() {
    HmacAuth hmacAuth = new HmacAuth();
    hmacAuth.setApiKey("API_KEY");
    hmacAuth.setApiSecretKey("SECRET_KEY");
    hmacAuth.setContentType("Application/Json");
    hmacAuth.setHttpMethod("POST");
    hmacAuth.setRequestUrl("/v2/api/test");
    QRCode qrCode = new QRCode();
    qrCode.setMerchantPaymentId(UUID.randomUUID().toString());
    hmacAuth.setRequestBody(qrCode.toString());
    Map<String, String> headerParams = new HashMap<>();
    List<Pair> queryParams = new ArrayList<>();
    hmacAuth.applyToParams(queryParams, headerParams);
    Assert.assertTrue(headerParams.get("Authorization").startsWith("hmac"));
    Assert.assertNotNull(hmacAuth.getApiKey());
    Assert.assertNotNull(hmacAuth.getApiSecretKey());
    Assert.assertNotNull(hmacAuth.getContentType());
    Assert.assertNotNull(hmacAuth.getHttpMethod());
    Assert.assertNotNull(hmacAuth.getRequestBody());
    Assert.assertNotNull(hmacAuth.getRequestUrl());
    hmacAuth.setRequestUrl("/v2/api/test?param=p1");
    hmacAuth.applyToParams(queryParams, headerParams);
    Assert.assertTrue(headerParams.get("Authorization").startsWith("hmac"));
    hmacAuth.setRequestUrl(null);
    hmacAuth.applyToParams(queryParams, headerParams);
    Assert.assertTrue(headerParams.get("Authorization").startsWith("hmac"));
    hmacAuth.setContentType(null);
    headerParams = new HashMap<>();
    hmacAuth.applyToParams(queryParams, headerParams);
    Assert.assertNull(headerParams.get("Authorization"));
}
Also used : QRCode(jp.ne.paypay.model.QRCode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HmacAuth(jp.ne.paypay.auth.HmacAuth) Pair(jp.ne.paypay.Pair) Test(org.junit.jupiter.api.Test)

Example 2 with HmacAuth

use of jp.ne.paypay.auth.HmacAuth in project paypayopa-sdk-java by paypay.

the class ApiClientTest method configTest.

@Test
public void configTest() throws ApiException {
    Configuration configuration = new Configuration();
    apiClient.setProductionMode(false);
    apiClient.setApiKey("api-key");
    apiClient.setApiSecretKey("api-secret-key");
    apiClient.setBasePath("basePath");
    configuration.setDefaultApiClient(apiClient);
    Assert.assertNotNull(configuration.getDefaultApiClient());
    Assert.assertNotNull(apiClient.getBasePath());
    Assert.assertFalse(apiClient.isProductionMode());
    Assert.assertEquals(apiClient.getBasePathProd(), "https://api.paypay.ne.jp");
    Assert.assertEquals(apiClient.getBasePathSandbox(), "https://stg-api.sandbox.paypay.ne.jp");
    apiClient.setProductionMode(true);
    Assert.assertEquals(apiClient.getBasePath(), "https://api.paypay.ne.jp");
    apiClient.setBasePathProd("prodUrl");
    Assert.assertEquals(apiClient.getBasePathProd(), "prodUrl");
    apiClient.setBasePathSandbox("sandboxUrl");
    Assert.assertEquals(apiClient.getBasePathSandbox(), "sandboxUrl");
    apiClient.setDefaultHeaderMap(new HashMap<>());
    Assert.assertNotNull(apiClient.getDefaultHeaderMap());
    Assert.assertEquals(apiClient.getAuthentications().size(), 1);
    Assert.assertNotNull(apiClient.getAuthentication("HmacAuth"));
    Map<String, Authentication> authentications = new HashMap<>();
    authentications.put("HmacAuth", new HmacAuth());
    authentications.put("BasicAuth", null);
    apiClient.setAuthentications(authentications);
    Assert.assertEquals(authentications.size(), 2);
    apiClient.setAssumeMerchant("merchantKey");
    Assert.assertEquals(apiClient.getDefaultHeaderMap().get("X-ASSUME-MERCHANT"), "merchantKey");
    Assert.assertEquals(apiClient.getAssumeMerchant(), "merchantKey");
    apiClient.setJson(new JSON());
    Assert.assertNotNull(apiClient.getJson());
}
Also used : Configuration(jp.ne.paypay.Configuration) HashMap(java.util.HashMap) Authentication(jp.ne.paypay.auth.Authentication) JSON(jp.ne.paypay.JSON) HmacAuth(jp.ne.paypay.auth.HmacAuth) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)2 HmacAuth (jp.ne.paypay.auth.HmacAuth)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 Configuration (jp.ne.paypay.Configuration)1 JSON (jp.ne.paypay.JSON)1 Pair (jp.ne.paypay.Pair)1 Authentication (jp.ne.paypay.auth.Authentication)1 QRCode (jp.ne.paypay.model.QRCode)1