FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
amadeus-java/src/test/java/com/amadeus/AccessTokenTest.java at master · alnacle/amadeus-java · GitHub
alnacle
/
amadeus-java
Public
forked from
amadeus4dev/amadeus-java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
amadeus-java
/
src
/
test
/
java
/
com
/
amadeus
/
AccessTokenTest.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
68 lines (56 loc) · 2.28 KB
Breadcrumbs
amadeus-java
/
src
/
test
/
java
/
com
/
amadeus
/
AccessTokenTest.java
Copy path
File metadata and controls
68 lines (56 loc) · 2.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package
com
.
amadeus
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
isNull
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
com
.
amadeus
.
client
.
AccessToken
;
import
com
.
amadeus
.
exceptions
.
ResponseException
;
import
com
.
google
.
gson
.
JsonObject
;
import
org
.
junit
.
Before
;
import
org
.
junit
.
Test
;
public
class
AccessTokenTest
{
Amadeus
client
;
Configuration
configuration
;
Response
response
;
JsonObject
json
;
@
Before
public
void
setupClientAndResponses
()
throws
ResponseException
{
client
=
mock
(
Amadeus
.
class
);
configuration
=
new
Configuration
(
"client_id"
,
"client_secret"
);
when
(
client
.
getConfiguration
()).
thenReturn
(
configuration
);
response
=
mock
(
Response
.
class
);
json
=
new
JsonObject
();
json
.
addProperty
(
"access_token"
,
"my_token"
);
json
.
addProperty
(
"expires_in"
,
600
);
when
(
response
.
getResult
()).
thenReturn
(
json
);
when
(
client
.
unauthenticatedRequest
(
"POST"
,
"/v1/security/oauth2/token"
,
Params
.
with
(
"grant_type"
,
"client_credentials"
)
.
and
(
"client_id"
,
"client_id"
)
.
and
(
"client_secret"
,
"client_secret"
),
null
,
null
)).
thenReturn
(
response
);
}
@
Test
public
void
testNewToken
()
throws
ResponseException
{
assertEquals
(
new
AccessToken
(
client
).
getBearerToken
(),
"Bearer my_token"
);
}
@
Test
public
void
testCachedToken
()
throws
ResponseException
{
AccessToken
accessToken
=
new
AccessToken
(
client
);
accessToken
.
getBearerToken
();
accessToken
.
getBearerToken
();
verify
(
client
,
times
(
1
))
.
unauthenticatedRequest
(
anyString
(),
anyString
(),
any
(
Params
.
class
), (
String
)
isNull
(), (
String
)
isNull
());
}
@
Test
public
void
testExpiredToken
()
throws
ResponseException
{
AccessToken
accessToken
=
new
AccessToken
(
client
);
json
.
addProperty
(
"expires_in"
,
0
);
accessToken
.
getBearerToken
();
accessToken
.
getBearerToken
();
verify
(
client
,
times
(
2
))
.
unauthenticatedRequest
(
anyString
(),
anyString
(),
any
(
Params
.
class
), (
String
)
isNull
(), (
String
)
isNull
());
}
}
Back
|
FazBrowse Home
|
New Git URL