25
25
26
26
import com .projectkaiser .scm .vcs .api .IVCS ;
27
27
import com .projectkaiser .scm .vcs .api .VCSWorkspace ;
28
+ import com .projectkaiser .scm .vcs .api .exceptions .EVCSBranchExists ;
28
29
29
30
public class GitVCSTest {
30
31
31
32
private static final String FILE1_ADDED_COMMIT_MESSAGE = "file1 added" ;
32
33
private static final String FILE2_ADDED_COMMIT_MESSAGE = "file2 added" ;
33
34
private static final String WORKSPACE_DIR = System .getProperty ("java.io.tmpdir" ) + "pk-vcs-workspaces" ;
34
35
private static final String REPO_NAME = "pk-vcs-git-testrepo" ;
35
- private static final String GITHUB_USER = System .getenv ("PK_VCS_TEST_GITHUB_USER" );
36
- private static final String GITHUB_PASS = System .getenv ("PK_VCS_TEST_GITHUB_PASS" );
36
+ private static final String GITHUB_USER = System .getProperty ("PK_VCS_TEST_GITHUB_USER" ) == null ?
37
+ System .getenv ("PK_VCS_TEST_GITHUB_USER" ) : System .getProperty ("PK_VCS_TEST_GITHUB_USER" );
38
+ private static final String GITHUB_PASS = System .getProperty ("PK_VCS_TEST_GITHUB_PASS" ) == null ?
39
+ System .getenv ("PK_VCS_TEST_GITHUB_PASS" ) : System .getProperty ("PK_VCS_TEST_GITHUB_PASS" );
37
40
private static final String NEW_BRANCH = "new-branch" ;
38
41
private static final String SRC_BRANCH = "master" ;
39
42
private static final String INITIAL_COMMIT_MESSAGE = "Initial commit" ;
40
43
private static final String CREATED_DST_BRANCH_COMMIT_MESSAGE = "created dst branch" ;
41
44
private static final String CONTENT_CHANGED_COMMIT_MESSAGE = "changed file content" ;
42
45
private static final String MERGE_COMMIT_MESSAGE = "merged." ;
43
46
private static final String DELETE_BRANCH_COMMIT_MESSAGE = "deleted" ;
44
- private static final String PROXY_HOST = "localhost" ;
45
- private static final Integer PROXY_PORT = 3128 ;
47
+ private static final String PROXY_HOST = getJvmProperty ("https.proxyHost" );
48
+ private static final Integer PROXY_PORT = getJvmProperty ("https.proxyPort" ) == null ? null :
49
+ Integer .parseInt (getJvmProperty ("https.proxyPort" ));
50
+ private static final String PROXY_USER = getJvmProperty ("https.proxyUser" );
51
+ private static final String PROXY_PASS = getJvmProperty ("https.proxyPassword" );
46
52
private static final String LINE_1 = "line 1" ;
47
53
private static final String LINE_2 = "line 2" ;
48
54
@@ -64,12 +70,37 @@ public static void setUpClass() {
64
70
GITHUB_PASS != null );
65
71
}
66
72
73
+ private static String getJvmProperty (String name ) {
74
+ if (name == null ) {
75
+ return null ;
76
+ }
77
+
78
+ String res = System .getProperty (name );
79
+ if (res != null ) {
80
+ return res ;
81
+ }
82
+
83
+ res = System .getenv ("JAVA_OPTS" );
84
+ if (res == null ) {
85
+ return null ;
86
+ }
87
+
88
+ Integer st = res .indexOf (name );
89
+ if (st < 0 ) {
90
+ return null ;
91
+ }
92
+
93
+ res = res .substring (st + name .length () + 1 , res .indexOf (" -D" , st + name .length () + 1 ) < 0 ? name .length () :
94
+ res .indexOf (" -D" , st + name .length ())).trim ();
95
+ return res ;
96
+ }
97
+
67
98
@ Before
68
99
public void setUp () throws IOException {
69
100
github = GitHub .connectUsingPassword (GITHUB_USER , GITHUB_PASS );
70
101
String uuid = UUID .randomUUID ().toString ();
71
102
repoName = (REPO_NAME + "_" + uuid );
72
-
103
+
73
104
repo = github .createRepository (repoName )
74
105
.issues (false )
75
106
.wiki (false )
@@ -79,7 +110,9 @@ public void setUp() throws IOException {
79
110
gitVCS = new GitVCS (null , WORKSPACE_DIR , gitUrl + repoName + ".git" );
80
111
vcs = gitVCS ;
81
112
vcs .setCredentials (GITHUB_USER , GITHUB_PASS );
82
- vcs .setProxy (PROXY_HOST , PROXY_PORT , "" , "" );
113
+ if (PROXY_HOST != null ) {
114
+ vcs .setProxy (PROXY_HOST , PROXY_PORT , PROXY_USER , PROXY_PASS );
115
+ }
83
116
}
84
117
85
118
@ After
@@ -98,6 +131,12 @@ public void testGitCreateAndDeleteBranch() throws InterruptedException, IOExcept
98
131
assertTrue (repo .getBranches ().containsKey (NEW_BRANCH ));
99
132
assertTrue (repo .getBranches ().size () == 2 ); // master & NEW_BRANCH
100
133
134
+ try {
135
+ vcs .createBranch (SRC_BRANCH , NEW_BRANCH , CREATED_DST_BRANCH_COMMIT_MESSAGE );
136
+ fail ("\" Branch exists\" situation not detected" );
137
+ } catch (EVCSBranchExists e ) {
138
+ }
139
+
101
140
vcs .deleteBranch (NEW_BRANCH , DELETE_BRANCH_COMMIT_MESSAGE );
102
141
Thread .sleep (2000 ); // next operation fails from time to time. Looks like github has some latency on branch operations
103
142
assertTrue (repo .getBranches ().size () == 1 );
0 commit comments