Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
5ffec843
Commit
5ffec843
authored
Mar 02, 2014
by
Greg Messner
Browse files
Fixed issues exposed by unit tests.
parent
3489473f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/test/java/com/messners/gitlab/api/TestGitLabApiEvents.java
View file @
5ffec843
...
@@ -5,9 +5,11 @@ import static org.junit.Assert.assertTrue;
...
@@ -5,9 +5,11 @@ import static org.junit.Assert.assertTrue;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
org.codehaus.jackson.JsonNode
;
import
org.codehaus.jackson.JsonParseException
;
import
org.codehaus.jackson.JsonParseException
;
import
org.codehaus.jackson.map.JsonMappingException
;
import
org.codehaus.jackson.map.JsonMappingException
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.json.JSONException
;
import
org.junit.BeforeClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -16,7 +18,7 @@ import com.messners.gitlab.api.webhook.PushEvent;
...
@@ -16,7 +18,7 @@ import com.messners.gitlab.api.webhook.PushEvent;
public
class
TestGitLabApiEvents
{
public
class
TestGitLabApiEvents
{
private
static
JacksonJson
jacksonJson
Config
;
private
static
JacksonJson
jacksonJson
;
public
TestGitLabApiEvents
()
{
public
TestGitLabApiEvents
()
{
super
();
super
();
...
@@ -24,7 +26,7 @@ public class TestGitLabApiEvents {
...
@@ -24,7 +26,7 @@ public class TestGitLabApiEvents {
@BeforeClass
@BeforeClass
public
static
void
setup
()
{
public
static
void
setup
()
{
jacksonJson
Config
=
new
JacksonJson
();
jacksonJson
=
new
JacksonJson
();
}
}
@Test
@Test
...
@@ -32,7 +34,7 @@ public class TestGitLabApiEvents {
...
@@ -32,7 +34,7 @@ public class TestGitLabApiEvents {
try
{
try
{
EventObject
issueEvent
=
makeFakeApiCall
(
EventObject
.
class
,
"issue-event"
);
EventObject
issueEvent
=
makeFakeApiCall
(
EventObject
.
class
,
"issue-event"
);
assertTrue
(
issueEvent
!=
null
);
assertTrue
(
compareJson
(
issueEvent
,
"issue-event"
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -43,7 +45,7 @@ public class TestGitLabApiEvents {
...
@@ -43,7 +45,7 @@ public class TestGitLabApiEvents {
try
{
try
{
EventObject
mergeRequestEvent
=
makeFakeApiCall
(
EventObject
.
class
,
"merge-request-event"
);
EventObject
mergeRequestEvent
=
makeFakeApiCall
(
EventObject
.
class
,
"merge-request-event"
);
assertTrue
(
mergeRequestEvent
!=
null
);
assertTrue
(
compareJson
(
mergeRequestEvent
,
"merge-request-event"
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -54,7 +56,7 @@ public class TestGitLabApiEvents {
...
@@ -54,7 +56,7 @@ public class TestGitLabApiEvents {
try
{
try
{
PushEvent
pushEvent
=
makeFakeApiCall
(
PushEvent
.
class
,
"push-event"
);
PushEvent
pushEvent
=
makeFakeApiCall
(
PushEvent
.
class
,
"push-event"
);
assertTrue
(
pushEvent
!=
null
);
assertTrue
(
compareJson
(
pushEvent
,
"push-event"
)
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -63,7 +65,17 @@ public class TestGitLabApiEvents {
...
@@ -63,7 +65,17 @@ public class TestGitLabApiEvents {
private
<
T
>
T
makeFakeApiCall
(
Class
<
T
>
returnType
,
String
file
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
private
<
T
>
T
makeFakeApiCall
(
Class
<
T
>
returnType
,
String
file
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
InputStreamReader
reader
=
new
InputStreamReader
(
GitLabApi
.
class
.
getResourceAsStream
(
file
+
".json"
));
InputStreamReader
reader
=
new
InputStreamReader
(
GitLabApi
.
class
.
getResourceAsStream
(
file
+
".json"
));
ObjectMapper
objectMapper
=
jacksonJson
Config
.
getContext
(
returnType
);
ObjectMapper
objectMapper
=
jacksonJson
.
getContext
(
returnType
);
return
(
objectMapper
.
readValue
(
reader
,
returnType
));
return
(
objectMapper
.
readValue
(
reader
,
returnType
));
}
}
private
<
T
>
boolean
compareJson
(
T
apiObject
,
String
file
)
throws
IOException
,
JSONException
{
InputStreamReader
reader
=
new
InputStreamReader
(
GitLabApi
.
class
.
getResourceAsStream
(
file
+
".json"
));
String
objectJson
=
jacksonJson
.
marshal
(
apiObject
);
JsonNode
tree1
=
jacksonJson
.
getObjectMapper
().
readTree
(
objectJson
.
getBytes
());
JsonNode
tree2
=
jacksonJson
.
getObjectMapper
().
readTree
(
reader
);
boolean
sameJson
=
tree1
.
equals
(
tree2
);
return
(
sameJson
);
}
}
}
src/test/resources/com/messners/gitlab/api/issue-event.json
View file @
5ffec843
...
@@ -9,9 +9,7 @@
...
@@ -9,9 +9,7 @@
"created_at"
:
"2013-12-03T17:15:43Z"
,
"created_at"
:
"2013-12-03T17:15:43Z"
,
"updated_at"
:
"2013-12-03T17:15:43Z"
,
"updated_at"
:
"2013-12-03T17:15:43Z"
,
"position"
:
0
,
"position"
:
0
,
"branch_name"
:
null
,
"description"
:
"Create new API for manipulations with repository"
,
"description"
:
"Create new API for manipulations with repository"
,
"milestone_id"
:
null
,
"state"
:
"opened"
,
"state"
:
"opened"
,
"iid"
:
23
"iid"
:
23
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment