jirarest2 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.txt +17 -0
- data/Manifest.txt +11 -9
- data/README.txt +1 -1
- data/Rakefile +1 -1
- data/bin/create_issue.rb +2 -2
- data/bin/jira_create_issue +397 -0
- data/bin/jira_create_issue.rb +3 -370
- data/lib/jirarest2.rb +8 -8
- data/lib/{connect.rb → jirarest2/connect.rb} +1 -1
- data/lib/{credentials.rb → jirarest2/credentials.rb} +0 -0
- data/lib/{exceptions.rb → jirarest2/exceptions.rb} +0 -0
- data/lib/{issue.rb → jirarest2/issue.rb} +15 -15
- data/lib/{madbitconfig.rb → jirarest2/madbitconfig.rb} +0 -0
- data/lib/{services.rb → jirarest2/services.rb} +0 -0
- data/lib/{services → jirarest2/services}/issuelink.rb +14 -8
- data/lib/jirarest2/services/issuelinktype.rb +108 -0
- data/lib/{services → jirarest2/services}/watcher.rb +2 -2
- data/test/data/issuespec.txt +14 -0
- data/test/test_connect.rb +28 -5
- data/test/test_issue.rb +7 -1
- data/test/test_issuelink.rb +36 -11
- data/test/test_issuelinktype.rb +30 -5
- data/test/test_madbitconfig.rb +9 -9
- data/test/test_result.rb +19 -5
- data/test/test_watcher.rb +21 -7
- metadata +30 -11
- metadata.gz.sig +0 -0
- data/lib/services/issuelinktype.rb +0 -91
File without changes
|
File without changes
|
@@ -15,11 +15,11 @@
|
|
15
15
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
16
|
#
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
require_relative "../connect"
|
19
|
+
require_relative "../services"
|
20
|
+
require_relative "../issue"
|
21
|
+
require_relative "issuelinktype"
|
22
|
+
require_relative "../exceptions"
|
23
23
|
|
24
24
|
# This class is responsible for the Linking of Issues
|
25
25
|
# No real getter as of yet (I just didn't need it)
|
@@ -28,6 +28,7 @@ class IssueLink < Services
|
|
28
28
|
def initialize(connection)
|
29
29
|
@uritail = "issueLink"
|
30
30
|
super(connection)
|
31
|
+
@linktype = IssueLinkType.new(@connection)
|
31
32
|
end
|
32
33
|
|
33
34
|
private
|
@@ -44,6 +45,12 @@ class IssueLink < Services
|
|
44
45
|
end
|
45
46
|
|
46
47
|
public
|
48
|
+
|
49
|
+
#Show the possible answers for the issuelinktypes
|
50
|
+
# @return String
|
51
|
+
def valid_issuelinktypes(delimiter = ", ")
|
52
|
+
return @linktype.valid_names(delimiter)
|
53
|
+
end
|
47
54
|
|
48
55
|
# Links two issues
|
49
56
|
# Right now the visibility feature for comments is not supported
|
@@ -57,9 +64,8 @@ class IssueLink < Services
|
|
57
64
|
outwardIssue = key(remoteIssue)
|
58
65
|
|
59
66
|
# lets see if we have the right name
|
60
|
-
|
61
|
-
|
62
|
-
realname = linktype.name(type)
|
67
|
+
if ! @linktype.internal_name?(type) then # time to find the correct name and see if we have to exchange tickets
|
68
|
+
realname = @linktype.name(type)
|
63
69
|
if realname.nil? then
|
64
70
|
raise Jirarest2::ValueNotAllowedException, type
|
65
71
|
else
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2012 Cyril Bitterich
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "jirarest2/services"
|
19
|
+
|
20
|
+
# Lets try it by making one class for each issue link type and glue them together in a list
|
21
|
+
class SingleIssueLinkType
|
22
|
+
# @return [String] Name of the Type
|
23
|
+
attr_reader :name
|
24
|
+
# @return [String] Name of the inward string
|
25
|
+
attr_reader :inward
|
26
|
+
# @return [String] Name of the outward string
|
27
|
+
attr_reader :outward
|
28
|
+
|
29
|
+
# @param [String] name The name of the IssueLinkType
|
30
|
+
# @param [String] inward The name used for inward links
|
31
|
+
# @param [String] outward The name used for outward links
|
32
|
+
def initialize(name,inward,outward)
|
33
|
+
@name = name
|
34
|
+
@inward = inward
|
35
|
+
@outward = outward
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# An IssueLinkType Object represents one or all IssueLinkTypes
|
40
|
+
class IssueLinkType < Services
|
41
|
+
|
42
|
+
|
43
|
+
# @param [Connection] connection
|
44
|
+
# @param [String] data issueLinkType ID
|
45
|
+
# @return [Jirarest2::Result]
|
46
|
+
def initialize(connection,data = "")
|
47
|
+
if data == "" then
|
48
|
+
@uritail = "issueLinkType"
|
49
|
+
else
|
50
|
+
@uritail = "issueLinkType/#{data}"
|
51
|
+
end
|
52
|
+
super(connection)
|
53
|
+
extract_fields(get) # Build the SingleIssueLinkType classes
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
# Extract the fieldtypes from the Hash we got from the server
|
58
|
+
# As the server does not always return the same structure for single and multi instances we have to do some alignment
|
59
|
+
# @param [Hash] jiraresponse Hash built from the JSON JIRA(tm) returned to us
|
60
|
+
def extract_fields(jiraresponse)
|
61
|
+
@types = Hash.new
|
62
|
+
if jiraresponse["issueLinkTypes"].instance_of?(Array) then
|
63
|
+
jiraresponse["issueLinkTypes"].each{ |hash|
|
64
|
+
@types[hash["name"]] = SingleIssueLinkType.new(hash["name"],hash["inward"],hash["outward"])
|
65
|
+
}
|
66
|
+
else
|
67
|
+
@types[jiraresponse["name"]] = SingleIssueLinkType.new(jiraresponse["name"],jiraresponse["inward"],jiraresponse["outward"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
public
|
72
|
+
|
73
|
+
#Get the internal name and direction instead of the one in the UI.
|
74
|
+
# @param [String] uiname the way the linktype is shown in the browser
|
75
|
+
# @return [Array, nil] Array with the name and the direction ("inward" or "outward") if successfull , nil if not
|
76
|
+
def name(uiname)
|
77
|
+
return uiname if @types.has_key?(uiname) # If the name is already correct just bounce it back
|
78
|
+
@types.each { |name,singletype|
|
79
|
+
if singletype.inward == uiname then
|
80
|
+
return singletype.name, "inward"
|
81
|
+
elsif singletype.outward == uiname then
|
82
|
+
return singletype.name, "outward"
|
83
|
+
end
|
84
|
+
}
|
85
|
+
return nil # Nothing found don't want to return @all
|
86
|
+
end # name
|
87
|
+
|
88
|
+
# Is the name realy the internal name we need to use?
|
89
|
+
# @param [String] test String to test agains the names of IssueLinkTypes
|
90
|
+
# @return [Boolean]
|
91
|
+
def internal_name?(test)
|
92
|
+
@types.has_key?(test)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Return all valid issuetypefield entries that we now of
|
96
|
+
# @param [String] delimiter Delimiter for the output (if you want ", " or "\n" or ...)
|
97
|
+
# @return [String] All the valid answers
|
98
|
+
def valid_names(delimiter = ", ")
|
99
|
+
answer = Array.new
|
100
|
+
@types.each { |name,singletype|
|
101
|
+
answer << singletype.name
|
102
|
+
answer << singletype.inward
|
103
|
+
answer << singletype.outward
|
104
|
+
}
|
105
|
+
return answer.join(delimiter)
|
106
|
+
end
|
107
|
+
|
108
|
+
end #class
|
@@ -15,8 +15,8 @@
|
|
15
15
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
16
|
#
|
17
17
|
|
18
|
-
require "connect"
|
19
|
-
require "services"
|
18
|
+
require "jirarest2/connect"
|
19
|
+
require "jirarest2/services"
|
20
20
|
|
21
21
|
# Watchers do have their own calling
|
22
22
|
class Watcher < Services
|
@@ -0,0 +1,14 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache-Coyote/1.1
|
3
|
+
X-AREQUESTID: 1205x110x1
|
4
|
+
Set-Cookie: JSESSIONID=3D7C4DCDAD212D6D5227E08E5059A347; Path=/
|
5
|
+
X-Seraph-LoginReason: OK
|
6
|
+
Set-Cookie: atlassian.xsrf.token=BP8Q-WXN6-SKX3-NB5M|09078c4ba23629ddc418efa11cc75a215f98ce1d|lin; Path=/jira
|
7
|
+
X-ASESSIONID: 1lodmqg
|
8
|
+
X-AUSERNAME: test
|
9
|
+
Cache-Control: no-cache, no-store, no-transform
|
10
|
+
Content-Type: application/json;charset=UTF-8
|
11
|
+
Transfer-Encoding: chunked
|
12
|
+
Date: Mon, 23 Jul 2012 18:05:26 GMT
|
13
|
+
|
14
|
+
{"expand":"projects","projects":[{"expand":"issuetypes","self":"http://localhost:2990/jira/rest/api/2/project/MFTP","id":"10000","key":"MFTP","name":"My first Test Project","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/projectavatar?size=small&pid=10000&avatarId=10011","48x48":"http://localhost:2990/jira/secure/projectavatar?pid=10000&avatarId=10011"},"issuetypes":[{"self":"http://localhost:2990/jira/rest/api/2/issuetype/6","id":"6","description":"An own issue type","iconUrl":"http://localhost:2990/jira/images/icons/ico_epic.png","name":"My issue type","subtask":false,"expand":"fields","fields":{"summary":{"required":true,"schema":{"type":"string","system":"summary"},"name":"Summary","operations":["set"]},"timetracking":{"required":false,"schema":{"type":"timetracking","system":"timetracking"},"name":"Time Tracking","operations":["set","edit"]},"customfield_10102":{"required":false,"schema":{"type":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:textfield","customId":10102},"name":"projects","operations":["set"]},"customfield_10101":{"required":false,"schema":{"type":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:textfield","customId":10101},"name":"Issue Type","operations":["set"]},"customfield_10100":{"required":false,"schema":{"type":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:textfield","customId":10100},"name":"issuetype","operations":["set"]},"issuetype":{"required":true,"schema":{"type":"issuetype","system":"issuetype"},"name":"Issue Type","operations":[],"allowedValues":[{"self":"http://localhost:2990/jira/rest/api/2/issuetype/6","id":"6","description":"An own issue type","iconUrl":"http://localhost:2990/jira/images/icons/ico_epic.png","name":"My issue type","subtask":false}]},"customfield_10006":{"required":false,"schema":{"type":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:select","customId":10006},"name":"List select","operations":["set"],"allowedValues":[{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10015","value":"Räuber","id":"10015"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10016","value":"Kabale und Liebe","id":"10016"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10017","value":"Faust","id":"10017"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10018","value":"Landleben","id":"10018"}]},"customfield_10005":{"required":false,"schema":{"type":"array","items":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:multiselect","customId":10005},"name":"Multi Select","operations":["add","set","remove"],"allowedValues":[{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10023","value":"Glocke","id":"10023"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10024","value":"Kabale und Liebe","id":"10024"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10025","value":"Schiller","id":"10025"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10026","value":"Göthe","id":"10026"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10027","value":"Faust","id":"10027"}]},"labels":{"required":false,"schema":{"type":"array","items":"string","system":"labels"},"name":"Labels","autoCompleteUrl":"http://localhost:2990/jira/rest/api/1.0/labels/suggest?query=","operations":["add","set","remove"]},"resolution":{"required":false,"schema":{"type":"resolution","system":"resolution"},"name":"Resolution","operations":["set"],"allowedValues":[{"self":"http://localhost:2990/jira/rest/api/2/resolution/1","name":"Fixed","id":"1"},{"self":"http://localhost:2990/jira/rest/api/2/resolution/2","name":"Won't Fix","id":"2"},{"self":"http://localhost:2990/jira/rest/api/2/resolution/3","name":"Duplicate","id":"3"},{"self":"http://localhost:2990/jira/rest/api/2/resolution/4","name":"Incomplete","id":"4"},{"self":"http://localhost:2990/jira/rest/api/2/resolution/5","name":"Cannot Reproduce","id":"5"}]},"attachment":{"required":false,"schema":{"type":"array","items":"attachment","system":"attachment"},"name":"Attachment","operations":[]},"project":{"required":true,"schema":{"type":"project","system":"project"},"autoCompleteUrl":"Project","operations":["set"],"allowedValues":[{"self":"http://localhost:2990/jira/rest/api/2/project/MFTP","id":"10000","key":"MFTP","name":"My first Test Project","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/projectavatar?size=small&pid=10000&avatarId=10011","48x48":"http://localhost:2990/jira/secure/projectavatar?pid=10000&avatarId=10011"}}]},"versions":{"required":false,"schema":{"type":"array","items":"version","system":"versions"},"name":"Affects Version/s","operations":["set","add","remove"],"allowedValues":[]},"environment":{"required":false,"schema":{"type":"string","system":"environment"},"name":"Environment","operations":["set"]},"priority":{"required":false,"schema":{"type":"priority","system":"priority"},"name":"Priority","operations":["set"],"allowedValues":[{"self":"http://localhost:2990/jira/rest/api/2/priority/1","iconUrl":"http://localhost:2990/jira/images/icons/priority_blocker.gif","name":"Blocker","id":"1"},{"self":"http://localhost:2990/jira/rest/api/2/priority/2","iconUrl":"http://localhost:2990/jira/images/icons/priority_critical.gif","name":"Critical","id":"2"},{"self":"http://localhost:2990/jira/rest/api/2/priority/3","iconUrl":"http://localhost:2990/jira/images/icons/priority_major.gif","name":"Major","id":"3"},{"self":"http://localhost:2990/jira/rest/api/2/priority/4","iconUrl":"http://localhost:2990/jira/images/icons/priority_minor.gif","name":"Minor","id":"4"},{"self":"http://localhost:2990/jira/rest/api/2/priority/5","iconUrl":"http://localhost:2990/jira/images/icons/priority_trivial.gif","name":"Trivial","id":"5"}]},"description":{"required":false,"schema":{"type":"string","system":"description"},"name":"Description","operations":["set"]},"customfield_10001":{"required":false,"schema":{"type":"datetime","custom":"com.atlassian.jira.plugin.system.customfieldtypes:datetime","customId":10001},"name":"Date Time Field","operations":["set"]},"customfield_10002":{"required":false,"schema":{"type":"date","custom":"com.atlassian.jira.plugin.system.customfieldtypes:datepicker","customId":10002},"name":"Date Picker","operations":["set"]},"customfield_10003":{"required":false,"schema":{"type":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:textarea","customId":10003},"name":"Großes Text","operations":["set"]},"customfield_10004":{"required":false,"schema":{"type":"array","items":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes","customId":10004},"name":"Multi Checkboxes","operations":["add","set","remove"],"allowedValues":[{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10019","value":"Göthe","id":"10019"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10020","value":"Schiller","id":"10020"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10021","value":"Heine","id":"10021"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10022","value":"Kafka","id":"10022"}]},"components":{"required":false,"schema":{"type":"array","items":"component","system":"components"},"name":"Component/s","operations":["add","set","remove"],"allowedValues":[]},"customfield_10000":{"required":false,"schema":{"type":"array","items":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:cascadingselect","customId":10000},"name":"Cascading Select Test","operations":["set"],"allowedValues":[{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10000","value":"English","id":"10000","children":[{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10003","value":"One","id":"10003"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10004","value":"Two","id":"10004"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10005","value":"Three","id":"10005"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10006","value":"Four","id":"10006"}]},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10001","value":"German","id":"10001","children":[{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10007","value":"Eins","id":"10007"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10008","value":"zwei","id":"10008"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10009","value":"drEi","id":"10009"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10010","value":"vier","id":"10010"}]},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10002","value":"ISO","id":"10002","children":[{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10011","value":"Unaone","id":"10011"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10012","value":"Bissotwo","id":"10012"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10013","value":"Terrathree","id":"10013"},{"self":"http://localhost:2990/jira/rest/api/2/customFieldOption/10014","value":"Kartefour","id":"10014"}]}]}}}]}]}
|
data/test/test_connect.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "minitest/autorun"
|
2
|
-
require "connect"
|
3
|
-
require "credentials"
|
2
|
+
require "jirarest2/connect"
|
3
|
+
require "jirarest2/credentials"
|
4
|
+
require "webmock/minitest"
|
4
5
|
|
5
6
|
class TestConnect < MiniTest::Unit::TestCase
|
6
7
|
def setup
|
@@ -8,24 +9,37 @@ class TestConnect < MiniTest::Unit::TestCase
|
|
8
9
|
@con = Connect.new(cred)
|
9
10
|
end
|
10
11
|
|
12
|
+
def test_access
|
13
|
+
stub_request(:any,"http://localhost:2990/jiar/rest/api/2/").with(:headers => {"Content-Type:" => "application/json;charset=UTF-8"})
|
14
|
+
end
|
11
15
|
|
12
|
-
def test_executeGET
|
16
|
+
def test_executeGET
|
17
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/createmeta/").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => "", :headers => {})
|
13
18
|
assert "projects", @con.execute("Get","issue/createmeta/","").result["expand"]
|
14
19
|
end
|
15
20
|
|
16
21
|
def test_executePOST
|
22
|
+
stub_request(:post, "http://test:1234@localhost:2990/jira/rest/api/2/search/").with(:body => "{\"jql\":\"project = MFTP\",\"startAt\":0,\"maxResults\":4}",:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => "", :headers => {})
|
23
|
+
|
17
24
|
query={"jql"=>"project = MFTP", "startAt"=>0, "maxResults"=>4 }
|
18
25
|
assert 4, @con.execute("Post","search/",query).result["maxResults"]
|
19
26
|
end
|
20
27
|
|
21
|
-
def
|
28
|
+
def test_check_uri_true
|
29
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/dashboard").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => "", :headers => {})
|
22
30
|
assert_equal true,@con.check_uri
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_check_uri_false
|
34
|
+
stub_request(:get, "http://test:1234@localhost:2990/rest/api/2/dashboard").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 400, :body => "", :headers => {})
|
23
35
|
cred = Credentials.new("http://localhost:2990/rest/api/2/","test","1234")
|
24
36
|
con1 = Connect.new(cred)
|
25
37
|
assert_equal false,con1.check_uri
|
26
38
|
end
|
27
39
|
|
28
40
|
def test_heal_uri
|
41
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/dashboard").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => "", :headers => {})
|
42
|
+
|
29
43
|
cred = Credentials.new("http://localhost:2990/jira//rest/api//2//","test","1234")
|
30
44
|
con = Connect.new(cred)
|
31
45
|
assert_equal "http://localhost:2990/jira/rest/api/2/",con.heal_uri
|
@@ -40,13 +54,22 @@ class TestConnect < MiniTest::Unit::TestCase
|
|
40
54
|
assert_equal "http://localhost:2990/secure/Dashboard.jspa",con.heal_uri("http://localhost:2990/secure/Dashboard.jspa") # If there is no Rest-Path at this point we have a problem
|
41
55
|
end
|
42
56
|
|
43
|
-
def
|
57
|
+
def test_working_heal_uri!
|
58
|
+
|
59
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira//rest/api//2//dashboard").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 404, :body => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><status><status-code>404</status-code><message>null for uri: http://localhost:2990/jira//rest/api//2//dashboard</message></status>', :headers => {"X-AUSERNAME" => "test" })
|
60
|
+
|
44
61
|
## First an URL we can fix
|
45
62
|
cred = Credentials.new("http://localhost:2990/jira//rest/api//2//","test","1234")
|
46
63
|
con = Connect.new(cred)
|
47
64
|
assert_equal false,con.check_uri
|
65
|
+
|
66
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/dashboard").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => "", :headers => {})
|
48
67
|
assert_equal "http://localhost:2990/jira/rest/api/2/", con.heal_uri!
|
49
68
|
assert_equal true,con.check_uri
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_notworking_heal_uri!
|
72
|
+
stub_request(:get, "http://test:1234@localhost:2990/secure/Dashboard.jspadashboard").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 400, :body => "", :headers => {})
|
50
73
|
## And now one we cant't fix
|
51
74
|
cred = Credentials.new("http://localhost:2990/secure/Dashboard.jspa","test","1234")
|
52
75
|
con = Connect.new(cred)
|
data/test/test_issue.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require "minitest/autorun"
|
3
3
|
require "jirarest2"
|
4
|
+
require "webmock/minitest"
|
4
5
|
|
5
6
|
class TestIssue < MiniTest::Unit::TestCase
|
6
7
|
def setup
|
7
8
|
@credentials = Credentials.new("http://localhost:2990/jira/rest/api/2/","test","1234")
|
8
9
|
@connect = Connect.new(@credentials)
|
10
|
+
raw_response_file = File.new(File.dirname(__FILE__)+"/data/issuespec.txt")
|
11
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/createmeta/?expand=projects.issuetypes.fields&issuetypeNames=My%20issue%20type&projectKeys=MFTP").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(raw_response_file)
|
9
12
|
@existentIssue = Issue.new("MFTP","My issue type",@connect)
|
10
13
|
end
|
11
14
|
|
12
15
|
def testNonExistentProject
|
16
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/createmeta/?expand=projects.issuetypes.fields&issuetypeNames=fasel&projectKeys=blubber").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"expand":"projects","projects":[]}', :headers => {})
|
13
17
|
assert_raises(Jirarest2::WrongProjectException) {
|
14
18
|
nonexistentProject = Issue.new("blubber","fasel",@connect)
|
15
19
|
}
|
16
20
|
end
|
17
|
-
|
21
|
+
|
18
22
|
def testNonExistentIssuetype
|
23
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/createmeta/?expand=projects.issuetypes.fields&issuetypeNames=fasel&projectKeys=MFTP").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"expand":"projects","projects":[{"expand":"issuetypes","self":"http://localhost:2990/jira/rest/api/2/project/MFTP","id":"10000","key":"MFTP","name":"My first Test Project","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/projectavatar?size=small&pid=10000&avatarId=10011","48x48":"http://localhost:2990/jira/secure/projectavatar?pid=10000&avatarId=10011"},"issuetypes":[]}]}', :headers => {})
|
19
24
|
assert_raises(Jirarest2::WrongIssuetypeException) {
|
20
25
|
nonexistentIssue = Issue.new("MFTP","fasel",@connect)
|
21
26
|
}
|
@@ -48,5 +53,6 @@ class TestIssue < MiniTest::Unit::TestCase
|
|
48
53
|
assert_equal "MFTP", blankissue["fields"]["project"]["key"]
|
49
54
|
assert_equal "Summary Text", issue.get_field("Summary")
|
50
55
|
end
|
56
|
+
|
51
57
|
|
52
58
|
end
|
data/test/test_issuelink.rb
CHANGED
@@ -1,31 +1,56 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require "minitest/autorun"
|
3
|
-
require "credentials"
|
4
|
-
require "connect"
|
5
|
-
require "services/issuelink"
|
3
|
+
require "jirarest2/credentials"
|
4
|
+
require "jirarest2/connect"
|
5
|
+
require "jirarest2/services/issuelink"
|
6
|
+
require "webmock/minitest"
|
7
|
+
|
6
8
|
|
7
9
|
class TestIssueLink < MiniTest::Unit::TestCase
|
8
10
|
def setup
|
9
11
|
cred = Credentials.new("http://localhost:2990/jira/rest/api/2/","test","1234")
|
10
12
|
@con = Connect.new(cred)
|
13
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issueLinkType").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"issueLinkTypes":[{"id":"10000","name":"Blocks","inward":"is blocked by","outward":"blocks","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10000"},{"id":"10001","name":"Cloners","inward":"is cloned by","outward":"clones","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10001"},{"id":"10002","name":"Duplicate","inward":"is duplicated by","outward":"duplicates","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10002"},{"id":"10003","name":"Relates","inward":"relates to","outward":"relates to","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10003"}]}', :headers => {})
|
14
|
+
@link = IssueLink.new(@con)
|
11
15
|
end
|
12
16
|
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
def test_link_issue_access
|
15
19
|
# check for right to link.
|
20
|
+
stub_request(:post, "http://test:1234@localhost:2990/jira/rest/api/2/issueLink").with(:body => "{\"type\":{\"name\":\"Blocks\"},\"inwardIssue\":{\"key\":\"MFTP-6\"},\"outwardIssue\":{\"key\":\"SP-2\"}}",:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 401, :body => '{"errorMessages":["No Link Issue Permission for issue \'MFTP-6\'"],"errors":{}}', :headers => {})
|
16
21
|
assert_raises(Jirarest2::AuthentificationError) {
|
17
|
-
link.link_issue("MFTP-6","SP-2","Blocks")
|
22
|
+
@link.link_issue("MFTP-6","SP-2","Blocks")
|
18
23
|
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_link_issue_badlinktype
|
19
27
|
# check for bullshio issuelinktype
|
20
28
|
assert_raises(Jirarest2::ValueNotAllowedException) {
|
21
|
-
|
29
|
+
@link.link_issue("SP-2","MFTP-6","Building")
|
22
30
|
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_link_issue_byname
|
23
34
|
# check for Basic link
|
24
|
-
|
35
|
+
stub_request(:post, "http://test:1234@localhost:2990/jira/rest/api/2/issueLink").with(:body => "{\"type\":{\"name\":\"Blocks\"},\"inwardIssue\":{\"key\":\"SP-2\"},\"outwardIssue\":{\"key\":\"MFTP-6\"}}",:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 201, :body => "", :headers => {})
|
36
|
+
assert_equal "201",@link.link_issue("SP-2","MFTP-6","Blocks").code
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_link_issue_byuiname
|
25
40
|
# Check for link type by name
|
26
|
-
|
41
|
+
stub_request(:post, "http://test:1234@localhost:2990/jira/rest/api/2/issueLink").with(:body => "{\"type\":{\"name\":\"Cloners\"},\"inwardIssue\":{\"key\":\"SP-2\"},\"outwardIssue\":{\"key\":\"MFTP-6\"}}",:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 201, :body => "", :headers => {})
|
42
|
+
assert_equal "201",@link.link_issue("SP-2","MFTP-6","clones").code
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_link_issue_changearound
|
27
46
|
# Check for twisted "only onw way for links policy with jira", MFTP-6 to SP-3 would result in AuthError
|
28
|
-
|
47
|
+
stub_request(:post, "http://test:1234@localhost:2990/jira/rest/api/2/issueLink").with(:body => "{\"type\":{\"name\":\"Cloners\"},\"inwardIssue\":{\"key\":\"SP-3\"},\"outwardIssue\":{\"key\":\"MFTP-6\"}}", :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 201, :body => "", :headers => {})
|
48
|
+
assert_equal "201",@link.link_issue("MFTP-6","SP-3","is cloned by").code
|
29
49
|
end
|
30
|
-
|
50
|
+
|
51
|
+
def test_valid_issuelinktype
|
52
|
+
block = Regexp.new("blocks, Cloners, is cloned by,")
|
53
|
+
assert_match block, @link.valid_issuelinktypes
|
54
|
+
end
|
55
|
+
|
31
56
|
end
|
data/test/test_issuelinktype.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require "minitest/autorun"
|
3
|
-
require "credentials"
|
4
|
-
require "connect"
|
5
|
-
require "services/issuelinktype"
|
3
|
+
require "jirarest2/credentials"
|
4
|
+
require "jirarest2/connect"
|
5
|
+
require "jirarest2/services/issuelinktype"
|
6
|
+
require "webmock/minitest"
|
6
7
|
|
7
8
|
|
8
9
|
class TestIssueLinkType < MiniTest::Unit::TestCase
|
@@ -11,25 +12,49 @@ class TestIssueLinkType < MiniTest::Unit::TestCase
|
|
11
12
|
@con = Connect.new(cred)
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
+
def test_single_name
|
16
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issueLinkType/10000").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"id":"10000","name":"Blocks","inward":"is blocked by","outward":"blocks","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10000"}', :headers => {})
|
15
17
|
singlelinktype = IssueLinkType.new(@con,"10000")
|
16
|
-
linktype = IssueLinkType.new(@con)
|
17
18
|
assert_equal "10000", singlelinktype.get["id"]
|
18
19
|
assert_equal ["Blocks", "outward"], singlelinktype.name("blocks")
|
19
20
|
assert_equal ["Blocks", "inward"], singlelinktype.name("is blocked by")
|
21
|
+
end
|
22
|
+
def test_multiple_name
|
23
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issueLinkType").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"issueLinkTypes":[{"id":"10000","name":"Blocks","inward":"is blocked by","outward":"blocks","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10000"},{"id":"10001","name":"Cloners","inward":"is cloned by","outward":"clones","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10001"},{"id":"10002","name":"Duplicate","inward":"is duplicated by","outward":"duplicates","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10002"},{"id":"10003","name":"Relates","inward":"relates to","outward":"relates to","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10003"}]}', :headers => {})
|
24
|
+
linktype = IssueLinkType.new(@con)
|
20
25
|
assert_equal ["Cloners", "outward"], linktype.name("clones")
|
21
26
|
assert_equal ["Cloners", "inward"], linktype.name("is cloned by")
|
22
27
|
assert_equal nil, linktype.name("unknown")
|
23
28
|
end
|
24
29
|
|
25
30
|
def test_internal_name?
|
31
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issueLinkType/10000").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"id":"10000","name":"Blocks","inward":"is blocked by","outward":"blocks","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10000"}', :headers => {})
|
26
32
|
singlelinktype = IssueLinkType.new(@con,"10000")
|
27
33
|
assert_equal false,singlelinktype.internal_name?("blocks")
|
28
34
|
assert_equal true, singlelinktype.internal_name?("Blocks")
|
35
|
+
end
|
36
|
+
def test_multiple_internal_name
|
37
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issueLinkType").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"issueLinkTypes":[{"id":"10000","name":"Blocks","inward":"is blocked by","outward":"blocks","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10000"},{"id":"10001","name":"Cloners","inward":"is cloned by","outward":"clones","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10001"},{"id":"10002","name":"Duplicate","inward":"is duplicated by","outward":"duplicates","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10002"},{"id":"10003","name":"Relates","inward":"relates to","outward":"relates to","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10003"}]}', :headers => {})
|
29
38
|
linktype = IssueLinkType.new(@con)
|
30
39
|
assert_equal false,linktype.internal_name?("blocks")
|
31
40
|
assert_equal true, linktype.internal_name?("Cloners")
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_single_valid_names
|
44
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issueLinkType/10000").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"id":"10000","name":"Blocks","inward":"is blocked by","outward":"blocks","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10000"}', :headers => {})
|
45
|
+
singlelinktype = IssueLinkType.new(@con,"10000")
|
46
|
+
assert_equal "Blocks, is blocked by, blocks",singlelinktype.valid_names
|
47
|
+
end
|
48
|
+
def test_multiple_valid_names
|
49
|
+
stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issueLinkType").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"issueLinkTypes":[{"id":"10000","name":"Blocks","inward":"is blocked by","outward":"blocks","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10000"},{"id":"10001","name":"Cloners","inward":"is cloned by","outward":"clones","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10001"},{"id":"10002","name":"Duplicate","inward":"is duplicated by","outward":"duplicates","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10002"},{"id":"10003","name":"Relates","inward":"relates to","outward":"relates to","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10003"}]}', :headers => {})
|
50
|
+
|
51
|
+
linktype = IssueLinkType.new(@con)
|
52
|
+
block = Regexp.new("blocks, Cloners, is cloned by,")
|
53
|
+
assert_match block, linktype.valid_names
|
54
|
+
block = Regexp.new("blocks\nCloners\nis cloned by\n")
|
55
|
+
assert_match block, linktype.valid_names("\n")
|
32
56
|
|
33
57
|
end
|
58
|
+
|
34
59
|
|
35
60
|
end
|
data/test/test_madbitconfig.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require "minitest/autorun"
|
2
|
-
require "madbitconfig"
|
2
|
+
require "jirarest2/madbitconfig"
|
3
3
|
require "pp"
|
4
4
|
|
5
5
|
class TestConfig < MiniTest::Unit::TestCase
|
6
6
|
|
7
7
|
def test_read_configfile
|
8
|
-
testdir = File.dirname(
|
9
|
-
testfile = testdir + "/
|
8
|
+
testdir = File.dirname(__FILE__)
|
9
|
+
testfile = testdir + "/data/test.config.data"
|
10
10
|
# Should work
|
11
11
|
testdata = {"username"=>"UsErNaMe", "password"=>"pAsSw0rD;", "URL"=>"https://jira.localhost:2990/jira"}
|
12
12
|
assert_equal testdata,MadbitConfig::read_configfile(testfile)
|
@@ -15,8 +15,8 @@ class TestConfig < MiniTest::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_write_configfile
|
18
|
-
testdir = File.dirname(
|
19
|
-
testfile = testdir + "/
|
18
|
+
testdir = File.dirname(__FILE__)
|
19
|
+
testfile = testdir + "/data/test.config.tmp"
|
20
20
|
#make sure
|
21
21
|
File.delete(testfile) if File.exists?(testfile)
|
22
22
|
#test
|
@@ -30,12 +30,12 @@ class TestConfig < MiniTest::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_readjfile
|
33
|
-
testdir = File.dirname(
|
34
|
-
testfile = testdir + "/
|
33
|
+
testdir = File.dirname(__FILE__)
|
34
|
+
testfile = testdir + "/data/test.json"
|
35
35
|
assert_equal ["One", "Two", "Three", "Four"],MadbitConfig::read_configfile(testfile)["Many Values"]
|
36
|
-
testfile = testdir + "/
|
36
|
+
testfile = testdir + "/data/test.nojson"
|
37
37
|
assert_equal " \\This is a summary. We prefer to use it, as is\\", MadbitConfig::read_configfile(testfile, true)["\\Summary\\ "] # Not really what we want but didn't know how to fix now
|
38
|
-
testfile = testdir + "/
|
38
|
+
testfile = testdir + "/data/test.nojson1"
|
39
39
|
assert_equal " One, Two, Three, Four",MadbitConfig::read_configfile(testfile, true)["Many Values "]
|
40
40
|
|
41
41
|
# I dont' know how to run this test in a automated setup. How do we feed one of the files above to STDIN so the testscript gets the data?
|