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"));
}
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());
}
Aggregations