-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetTranslationLoadTest.groovy
executable file
·76 lines (59 loc) · 2.67 KB
/
getTranslationLoadTest.groovy
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
69
70
71
72
73
74
75
76
#!/usr/bin/env groovy
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7')
import groovyx.net.http.RESTClient
def cli = new CliBuilder(usage:'get translation from zanata (sort of load testing)')
cli.h(longOpt: 'help', 'print help')
cli._(longOpt: 'url', args: 1, 'zanata url (default http://localhost:8080/zanata)')
cli.p(longOpt: 'project', args: 1, 'targeting project (default skynet-topics)')
cli.i(longOpt: 'project-version', args: 1, 'targeting project version (default 1)')
cli.u(longOpt: 'username', args: 1, 'username (default admin)')
cli.k(longOpt: 'apiKey', args: 1, 'API key (default b6d7044e9ee3b2447c28fb7c50d86d98)')
cli.v(longOpt: 'verbose', 'whether you want verbose logging')
def options = cli.parse(args)
if (options.help) {
cli.usage()
System.exit(1)
}
def verbose = options.v
def printIfVerbose = {
if (verbose) {
println it;
}
}
def zanataInstance = options.url ?: "http://localhost:8080/zanata"
def zanataRestUrl = "$zanataInstance/rest/"
def zanataRestClient = new RESTClient(zanataRestUrl, "application/xml")
zanataRestClient.handler.failure = {
it
}
def projectSlug = options.p ?: 'skynet-topics'
def versionSlug = options.i ?: '1'
def authHeaders = ['X-Auth-User': "admin", 'X-Auth-Token': "b6d7044e9ee3b2447c28fb7c50d86d98"]
// get all resource names
def resourcePath = "projects/p/$projectSlug/iterations/i/$versionSlug/r"
def response = zanataRestClient.get(headers: authHeaders, path : resourcePath)
assert response.status == 200 : "Error getting resource for $projectSlug/$versionSlug at $resourcePath"
def namespaces = ['http://zanata.org/namespace/api/': 'api']
def resources = response.data.declareNamespace(namespaces)
def names = resources.'resource-meta'.collect {
it.name
}
printIfVerbose "resource names: $names"
// get all available locales
def statsResponse = zanataRestClient.get(headers: authHeaders, path: "stats/proj/$projectSlug/iter/$versionSlug")
assert statsResponse.status == 200 : "Error getting statistics for $projectSlug/$versionSlug"
def locales = statsResponse.data.declareNamespace(namespaces).stats.stat.'@locale'.collect {
it
}
printIfVerbose "locales: $locales"
// get translations
printIfVerbose "getting translations for all these locales and resources"
locales.each { locale ->
names.each { resId ->
def msg = "getting translation for $resId for locale $locale"
def resp = zanataRestClient.get(headers: authHeaders, path: "$resourcePath/$resId/translations/$locale")
// we don't really care the response content
printIfVerbose "$msg -> $resp.status"
}
}
println "=== Get translation done (project: $projectSlug version: $versionSlug) ==="