7
7
import java .util .Arrays ;
8
8
9
9
import org .gitlab4j .api .utils .AccessTokenUtils ;
10
+ import org .junit .AfterClass ;
10
11
import org .junit .BeforeClass ;
11
12
import org .junit .experimental .categories .Categories .IncludeCategory ;
12
13
import org .junit .runner .RunWith ;
@@ -26,8 +27,12 @@ public class IntegrationTestSuite implements PropertyConstants {
26
27
protected static final String TEST_PROJECT_NAME = HelperUtils .getProperty (PROJECT_NAME_KEY );
27
28
protected static final String TEST_NAMESPACE = HelperUtils .getProperty (NAMESPACE_KEY );
28
29
30
+ protected static final String TEST_PRIVATE_TOKEN_NAME = "GitLab4J Test Private Token - " + HelperUtils .getRandomInt (1000 );
29
31
protected static String TEST_PRIVATE_TOKEN ;
32
+
33
+ protected static final String TEST_ACCESS_TOKEN_NAME = "GitLab4J Test Access Token - " + HelperUtils .getRandomInt (1000 );
30
34
protected static String TEST_ACCESS_TOKEN ;
35
+
31
36
private static String problems = "" ;
32
37
33
38
@ BeforeClass
@@ -55,19 +60,45 @@ public static void suiteSetup() throws GitLabApiException {
55
60
56
61
// Create a new personal access token for both the private and access tokens
57
62
TEST_PRIVATE_TOKEN = AccessTokenUtils .createPersonalAccessToken (
58
- TEST_HOST_URL , TEST_LOGIN_USERNAME , TEST_LOGIN_PASSWORD ,
59
- "GitLab4J Test Private Token" , Arrays .asList ("api" , "sudo" ));
63
+ TEST_HOST_URL , TEST_LOGIN_USERNAME , TEST_LOGIN_PASSWORD ,
64
+ TEST_PRIVATE_TOKEN_NAME , Arrays .asList ("api" , "sudo" ));
60
65
System .out .println ("Created private token: " + TEST_PRIVATE_TOKEN );
61
66
assertNotNull (TEST_PRIVATE_TOKEN );
62
67
assertFalse (TEST_PRIVATE_TOKEN .trim ().isEmpty ());
63
68
HelperUtils .setProperty (PRIVATE_TOKEN_KEY , TEST_PRIVATE_TOKEN );
64
69
65
70
TEST_ACCESS_TOKEN = AccessTokenUtils .createPersonalAccessToken (
66
- TEST_HOST_URL , TEST_LOGIN_USERNAME , TEST_LOGIN_PASSWORD ,
67
- "GitLab4J Test Access Token" , Arrays .asList ("api" , "sudo" ));
68
- System .out .println ("Created private token: " + TEST_ACCESS_TOKEN );
71
+ TEST_HOST_URL , TEST_LOGIN_USERNAME , TEST_LOGIN_PASSWORD ,
72
+ TEST_ACCESS_TOKEN_NAME , Arrays .asList ("api" , "sudo" ));
73
+ System .out .println ("Created access token: " + TEST_ACCESS_TOKEN );
69
74
assertNotNull (TEST_ACCESS_TOKEN );
70
75
assertFalse (TEST_ACCESS_TOKEN .trim ().isEmpty ());
71
76
HelperUtils .setProperty (ACCESS_TOKEN_KEY , TEST_ACCESS_TOKEN );
72
77
}
78
+
79
+ @ AfterClass
80
+ public static void suiteTeardown () throws GitLabApiException {
81
+
82
+ System .out .println ("********************************************************" );
83
+ System .out .println ("* Test Suite Teardown *" );
84
+ System .out .println ("********************************************************" );
85
+
86
+ if (TEST_PRIVATE_TOKEN != null ) {
87
+ try {
88
+ AccessTokenUtils .revokePersonalAccessToken (
89
+ TEST_HOST_URL , TEST_LOGIN_USERNAME , TEST_LOGIN_PASSWORD ,
90
+ TEST_PRIVATE_TOKEN_NAME , Arrays .asList ("api" , "sudo" ));
91
+ System .out .format ("Revoved '%s'%n" , TEST_PRIVATE_TOKEN_NAME );
92
+ } catch (Exception ignore ) {}
93
+ }
94
+
95
+ if (TEST_ACCESS_TOKEN != null ) {
96
+ try {
97
+ AccessTokenUtils .revokePersonalAccessToken (
98
+ TEST_HOST_URL , TEST_LOGIN_USERNAME , TEST_LOGIN_PASSWORD ,
99
+ TEST_ACCESS_TOKEN_NAME , Arrays .asList ("api" , "sudo" ));
100
+ System .out .format ("Revoved '%s'%n" , TEST_ACCESS_TOKEN_NAME );
101
+ } catch (Exception ignore ) {}
102
+ }
103
+ }
73
104
}
0 commit comments