/
HmacAuthTest.java
46 lines (42 loc) · 1.76 KB
/
HmacAuthTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package jp.ne.paypay.api;
import jp.ne.paypay.Pair;
import jp.ne.paypay.auth.HmacAuth;
import jp.ne.paypay.model.QRCode;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class 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.setContentType(null);
headerParams = new HashMap<>();
hmacAuth.applyToParams(queryParams, headerParams);
Assert.assertNull(headerParams.get("Authorization"));
}
}