Skip to content

Commit 28c7270

Browse files
committed
Tests improvements.
1 parent d9fd544 commit 28c7270

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

impl/src/main/java/com/jfrog/bintray/client/impl/BintrayClient.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ static public Bintray create(CloseableHttpClient preConfiguredClient, String url
3030
* Username and API key, no proxy
3131
*/
3232
static public Bintray create(String userName, String apiKey) {
33-
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(userName, apiKey);
34-
return new BintrayImpl(createClient(creds, null, BINTRAY_API_URL), BINTRAY_API_URL, DEFAULT_THREAD_POOL_SIZE,
35-
DEFAULT_SIGN_REQUEST_TIMEOUT_PER_FILE);
33+
return create(BINTRAY_API_URL, userName, apiKey);
3634
}
3735

3836
/**

impl/src/test/groovy/com/jfrog/bintray/client/test/BintraySpecSuite.groovy

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ class BintraySpecSuite {
102102
assert connectionProperties.apiKey
103103
assert connectionProperties.email
104104

105-
bintray = BintrayClient.create(connectionProperties.username as String, connectionProperties.apiKey as String)
105+
bintray = BintrayClient.create(getApiUrl(),
106+
connectionProperties.username as String,
107+
connectionProperties.apiKey as String)
106108

107109
restClient = createClient()
108110

@@ -161,14 +163,27 @@ class BintraySpecSuite {
161163
httpLogger.setLevel(Level.INFO);
162164
}
163165

164-
public static BintrayImpl createClient(String url = "https://api.bintray.com") {
166+
public static BintrayImpl createClient() {
167+
return createClient(null)
168+
}
169+
170+
public static BintrayImpl createClient(String url) {
171+
url = (url ?: getApiUrl())
165172
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(connectionProperties.username as String,
166173
connectionProperties.apiKey as String)
167174

168175
HttpClientConfigurator conf = new HttpClientConfigurator()
169176
return new BintrayImpl(conf.hostFromUrl(url).noRetry().authentication(creds).getClient(), url, 5, 90000)
170177
}
171178

179+
public static String getApiUrl() {
180+
return connectionProperties.bintrayUrl ?: BintrayClient.BINTRAY_API_URL
181+
}
182+
183+
public static String getDownloadUrl() {
184+
return connectionProperties.bintrayDownloadUrl ?: 'https://dl.bintray.com'
185+
}
186+
172187
@AfterClass
173188
public static void cleanup() {
174189
try {

impl/src/test/groovy/com/jfrog/bintray/client/test/spec/BintrayClientSpec.groovy

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,20 @@ class BintrayClientSpec extends Specification {
5454
def encodedPath6 = ((BintrayImpl) bintray).createUrl(path6)
5555

5656
then:
57-
encodedPath1.toString().equals("https://api.bintray.com/content/user/generic/bla/1.0/com/jfrog/bintray/bintray-test/1.0/bintray-test-1.0.pom;publish=1")
58-
encodedPath2.toString().equals("https://api.bintray.com/docker/bla/dockertest/v1/repositories/library/ubuntu")
59-
encodedPath3.toString().equals("https://api.bintray.com/docker/bla/dockertest/v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json%20with%20space.ext")
60-
encodedPath4.toString().equals("https://api.bintray.com/bla/someUser/test?a=b&c=d")
61-
encodedPath5.toString().equals("https://api.bintray.com/bla/someUser/testMatrix;a+=b")
62-
encodedPath6.toString().equals("https://api.bintray.com/t%25st/spe%5Eal/ch&ar\$/*()!%23/ok?")
63-
57+
String url = getApiUrl()
58+
encodedPath1.toString().equals(url + "/content/user/generic/bla/1.0/com/jfrog/bintray/bintray-test/1.0/bintray-test-1.0.pom;publish=1")
59+
encodedPath2.toString().equals(url + "/docker/bla/dockertest/v1/repositories/library/ubuntu")
60+
encodedPath3.toString().equals(url + "/docker/bla/dockertest/v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json%20with%20space.ext")
61+
encodedPath4.toString().equals(url + "/bla/someUser/test?a=b&c=d")
62+
encodedPath5.toString().equals(url + "/bla/someUser/testMatrix;a+=b")
63+
encodedPath6.toString().equals(url + "/t%25st/spe%5Eal/ch&ar\$/*()!%23/ok?")
6464
}
6565

6666
def 'on error response is returned without parsing'() {
6767
setup:
68-
Bintray wrongBintray = BintrayClient.create(connectionProperties.username as String, connectionProperties.apiKey as String)
68+
Bintray wrongBintray = BintrayClient.create(getApiUrl(),
69+
connectionProperties.username as String,
70+
connectionProperties.apiKey as String)
6971
when:
7072
wrongBintray.subject('bla').get()
7173
then:
@@ -85,7 +87,8 @@ class BintrayClientSpec extends Specification {
8587
def 'files uploaded and can be accessed by the author'() {
8688
setup:
8789
def ver = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder)
88-
def downloadServerClient = createClient("https://dl.bintray.com")
90+
String url = getDownloadUrl()
91+
def downloadServerClient = createClient(url)
8992
files = ['com/bla/bintray-client-java-api.jar' : getClass().getResourceAsStream('/testJar1.jar'),
9093
'org/foo/bar/bintray-client-java-service.jar': getClass().getResourceAsStream('/testJar2.jar')]
9194

@@ -106,7 +109,8 @@ class BintrayClientSpec extends Specification {
106109
sleep(15000) //wait for previous deletions to propagate
107110
def ver = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder)
108111
HttpClientConfigurator conf = new HttpClientConfigurator();
109-
def anonymousDownloadServerClient = new BintrayImpl(conf.hostFromUrl("https://dl.bintray.com").noRetry().noCookies().getClient(), "https://dl.bintray.com", 5, 90000)
112+
String url = getDownloadUrl()
113+
def anonymousDownloadServerClient = new BintrayImpl(conf.hostFromUrl(url).noRetry().noCookies().getClient(), url, 5, 90000)
110114
files = ['com/bla/bintray-client-java-api.jar' : getClass().getResourceAsStream('/testJar1.jar'),
111115
'org/foo/bar/bintray-client-java-service.jar': getClass().getResourceAsStream('/testJar2.jar')]
112116

@@ -127,7 +131,9 @@ class BintrayClientSpec extends Specification {
127131
'org/foo/bar/bintray-client-java-service.jar': getClass().getResourceAsStream('/testJar2.jar')]
128132
VersionHandle ver = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder).upload(files)
129133
HttpClientConfigurator conf = new HttpClientConfigurator();
130-
def anonymousDownloadServerClient = new BintrayImpl(conf.hostFromUrl("https://dl.bintray.com").noRetry().getClient(), "https://dl.bintray.com", 5, 90000)
134+
135+
String url = getDownloadUrl()
136+
def anonymousDownloadServerClient = new BintrayImpl(conf.hostFromUrl(url).noRetry().getClient(), url, 5, 90000)
131137

132138
when:
133139
sleep(5000)
@@ -149,7 +155,9 @@ class BintrayClientSpec extends Specification {
149155
sleep(4000)
150156
ver.discard()
151157
sleep(4000) //wait for propagation to dl and stuff
152-
"https://dl.bintray.com/$connectionProperties.username/$REPO_NAME/${files.keySet().asList().get(0)}".toURL().content
158+
159+
String url = getDownloadUrl()
160+
"$url/$connectionProperties.username/$REPO_NAME/${files.keySet().asList().get(0)}".toURL().content
153161

154162
then:
155163
IOException ioe = thrown()

0 commit comments

Comments
 (0)