Skip to content

Commit a16d953

Browse files
author
danf
committed
Split and refactor tests
1 parent d13a451 commit a16d953

File tree

7 files changed

+834
-704
lines changed

7 files changed

+834
-704
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ subprojects() {
8585
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
8686
minGranularity 0
8787
}
88+
//Have the BintraySpecSuite run all tests
89+
exclude 'com/jfrog/bintray/client/test/spec'
8890

8991
finalizedBy(testResultsZip)
9092
}

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

Lines changed: 0 additions & 704 deletions
This file was deleted.
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
package com.jfrog.bintray.client.test
2+
3+
import ch.qos.logback.classic.Level
4+
import ch.qos.logback.classic.Logger
5+
import ch.qos.logback.classic.LoggerContext
6+
import com.jfrog.bintray.client.api.BintrayCallException
7+
import com.jfrog.bintray.client.api.details.Attribute
8+
import com.jfrog.bintray.client.api.details.PackageDetails
9+
import com.jfrog.bintray.client.api.details.VersionDetails
10+
import com.jfrog.bintray.client.api.handle.Bintray
11+
import com.jfrog.bintray.client.impl.BintrayClient
12+
import com.jfrog.bintray.client.impl.HttpClientConfigurator
13+
import com.jfrog.bintray.client.impl.handle.BintrayImpl
14+
import com.jfrog.bintray.client.test.spec.BintrayClientSpec
15+
import com.jfrog.bintray.client.test.spec.PackageSpec
16+
import com.jfrog.bintray.client.test.spec.RepoSpec
17+
import com.jfrog.bintray.client.test.spec.VersionSpec
18+
import org.apache.http.auth.UsernamePasswordCredentials
19+
import org.junit.AfterClass
20+
import org.junit.BeforeClass
21+
import org.junit.runner.RunWith
22+
import org.junit.runners.Suite
23+
import org.slf4j.LoggerFactory
24+
import spock.lang.Shared
25+
26+
import static org.apache.http.HttpStatus.SC_NOT_FOUND
27+
28+
/**
29+
* @author Dan Feldman
30+
*/
31+
@RunWith(Suite)
32+
@Suite.SuiteClasses([RepoSpec.class, PackageSpec.class, VersionSpec.class, BintrayClientSpec.class])
33+
class BintraySpecSuite {
34+
35+
public static final String REPO_NAME = 'generic'
36+
public static final String PKG_NAME = 'bla'
37+
public static final String VERSION = '1.0'
38+
public static final String ATTRIBUTE_NAME = 'att1'
39+
public static final String ATTRIBUTE_VALUE = 'bla'
40+
@Shared
41+
public static Properties connectionProperties
42+
@Shared
43+
public static Bintray bintray
44+
@Shared
45+
public static BintrayImpl restClient
46+
@Shared
47+
public static PackageDetails pkgBuilder
48+
@Shared
49+
public static VersionDetails versionBuilder
50+
@Shared
51+
public static String tempPkgName = "PkgTest"
52+
@Shared
53+
public static String pkgJson;
54+
@Shared
55+
public static String tempVerName = "3.0"
56+
@Shared
57+
public static String verJson;
58+
59+
public static ArrayList<Attribute<String>> attributes = [
60+
new Attribute<String>('a', Attribute.Type.string, "ay1", "ay2"),
61+
new Attribute<String>('b', 'b', 'e'),
62+
new Attribute<String>('c', 'cee')]
63+
64+
public static String expectedAttributes = '[[values:[ay1, ay2], name:a, type:string], ' +
65+
'[values:[cee], name:c, type:string], [values:[e, b], name:b, type:string]]'
66+
67+
public
68+
static String assortedAttributes = "[{\"name\":\"verAttr2\",\"values\":[\"val1\",\"val2\"],\"type\":\"string\"}," +
69+
"{\"name\":\"verAttr3\",\"values\":[1,2.2,4],\"type\":\"number\"},{\"name\":\"verAttr2\"," +
70+
"\"values\":[\"2011-07-14T19:43:37+0100\"],\"type\":\"date\"}]"
71+
72+
@BeforeClass
73+
def static void setup() {
74+
connectionProperties = new Properties()
75+
def streamFromProperties = this.class.getResourceAsStream('/bintray-client.properties')
76+
if (streamFromProperties) {
77+
streamFromProperties.withStream {
78+
connectionProperties.load(it)
79+
}
80+
}
81+
def usernameFromEnv = System.getenv('BINTRAY_USERNAME')
82+
if (usernameFromEnv) {
83+
connectionProperties.username = usernameFromEnv
84+
}
85+
def apiKeyFromEnv = System.getenv('BINTRAY_API_KEY')
86+
if (apiKeyFromEnv) {
87+
connectionProperties.apiKey = apiKeyFromEnv
88+
}
89+
def emailFromEnv = System.getenv('BINTRAY_EMAIL')
90+
if (emailFromEnv) {
91+
connectionProperties.email = emailFromEnv
92+
}
93+
assert connectionProperties
94+
assert connectionProperties.username
95+
assert connectionProperties.apiKey
96+
assert connectionProperties.email
97+
98+
bintray = BintrayClient.create(connectionProperties.username as String, connectionProperties.apiKey as String)
99+
100+
restClient = createClient()
101+
102+
pkgBuilder = new PackageDetails(PKG_NAME).description('bla-bla').labels(['l1', 'l2'])
103+
.licenses(['Apache-2.0']).vcsUrl("https://github.com/bintray/bintray-client-java.git")
104+
105+
versionBuilder = new VersionDetails(VERSION).description('versionDesc')
106+
107+
pkgJson = "{\n" +
108+
"\t\t\"name\": \"" + tempPkgName + "\",\n" +
109+
"\t\t\"repo\": \"generic\",\n" +
110+
"\t\t\"owner\": \"" + connectionProperties.username + "\",\n" +
111+
"\t\t\"desc\": \"Bintray Client Java\",\n" +
112+
"\t\t\"website_url\": \"http://www.jfrog.com\",\n" +
113+
"\t\t\"issue_tracker_url\": \"https://github.com/bintray/bintray-client-java/issues\",\n" +
114+
"\t\t\"vcs_url\": \"https://github.com/bintray/bintray-client-java.git\",\n" +
115+
"\t\t\"licenses\": [\"MIT\"],\n" +
116+
"\t\t\"labels\": [\"cool\", \"awesome\", \"gorilla\"],\n" +
117+
"\t\t\"public_download_numbers\": false,\n" +
118+
"\t\t\"attributes\": [{\"name\": \"att1\", \"values\" : [\"val1\"], \"type\": \"string\"},\n" +
119+
"\t\t\t\t\t {\"name\": \"att3\", \"values\" : [1, 3.3, 5], \"type\": \"number\"},\n" +
120+
"\t\t\t\t\t {\"name\": \"att5\", \"values\" : [\"2011-07-14T19:43:37+0100\"], \"type\": \"date\"}]\n" +
121+
"}"
122+
123+
verJson = "{\n" +
124+
" \"name\": \"" + tempVerName + "\",\n" +
125+
" \"desc\": \"Version Test\",\n" +
126+
" \"package\": \"" + tempPkgName + "\",\n" +
127+
" \"repo\": \"generic\",\n" +
128+
" \"owner\": \"" + connectionProperties.username + "\",\n" +
129+
" \"labels\": [\"cool\",\"awesome\",\"gorilla\"],\n" +
130+
" \"attribute_names\": [\"verAtt1\",\"verAtt2\",\"verAtt3\"],\n" +
131+
" \"released\": \" 2015-01-07T18:00:00.000-06:00\",\n" +
132+
" \"github_use_tag_release_notes\": false,\n" +
133+
" \"vcs_tag\": \"3.8\",\n" +
134+
" \"ordinal\": 0,\n" +
135+
" \"attributes\": [{\"name\": \"VerAtt1\",\"values\": [\"VerVal1\"],\"type\": \"string\"},\n" +
136+
" {\"name\": \"VerAtt2\",\"values\": [1,3.3,5],\"type\": \"number\"},\n" +
137+
" {\"name\": \"VerAtt3\",\"values\": [\"2015-01-01T19:43:37+0100\"],\"type\": \"date\"}]\n" +
138+
"}"
139+
140+
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
141+
//Set level for root logger
142+
loggerContext.getLogger("ROOT").setLevel(Level.INFO)
143+
//Disable debug for org.apache.http - you can tweak the level here
144+
Logger httpLogger = loggerContext.getLogger("org.apache.http");
145+
httpLogger.setLevel(Level.INFO);
146+
}
147+
148+
public static BintrayImpl createClient(String url = "https://api.bintray.com") {
149+
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(connectionProperties.username as String,
150+
connectionProperties.apiKey as String)
151+
152+
HttpClientConfigurator conf = new HttpClientConfigurator()
153+
return new BintrayImpl(conf.hostFromUrl(url).noRetry().authentication(creds).getClient(), url, 5, 90000)
154+
}
155+
156+
@AfterClass
157+
public static void cleanup() {
158+
try {
159+
String pkg = "/packages/" + connectionProperties.username + "/" + REPO_NAME + "/" + PKG_NAME
160+
restClient.delete(pkg, null)
161+
} catch (BintrayCallException e) {
162+
if (e.getStatusCode() != SC_NOT_FOUND) { //don't care
163+
throw e
164+
}
165+
}
166+
}
167+
}

0 commit comments

Comments
 (0)