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
ae37475b
Commit
ae37475b
authored
May 10, 2018
by
Greg Messner
Browse files
Updated with projects formatting style.
parent
8077face
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/models/Snippet.java
View file @
ae37475b
/*
* The MIT License (MIT)
*
* Copyright (c) 201
7
Greg Messner <greg@messners.com>
* Copyright (c) 201
8
Greg Messner <greg@messners.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
...
...
@@ -44,24 +44,23 @@ public class Snippet {
private
String
content
;
private
String
rawUrl
;
private
Visibility
visibility
;
private
String
description
;
private
String
description
;
public
Snippet
()
{
}
public
Snippet
(
String
title
,
String
fileName
,
String
content
,
Visibility
visibility
,
String
description
)
{
this
(
title
,
fileName
,
content
);
this
.
visibility
=
visibility
;
this
.
description
=
description
;
this
(
title
,
fileName
,
content
);
this
.
visibility
=
visibility
;
this
.
description
=
description
;
}
public
Snippet
(
String
title
,
String
fileName
,
String
content
)
{
this
.
title
=
title
;
this
.
fileName
=
fileName
;
this
.
content
=
content
;
this
.
title
=
title
;
this
.
fileName
=
fileName
;
this
.
content
=
content
;
}
public
Author
getAuthor
()
{
return
this
.
author
;
}
...
...
@@ -126,35 +125,35 @@ public class Snippet {
this
.
webUrl
=
webUrl
;
}
public
String
getContent
()
{
return
content
;
}
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
String
getRawUrl
()
{
return
rawUrl
;
}
public
String
getRawUrl
()
{
return
rawUrl
;
}
public
void
setRawUrl
(
String
rawUrl
)
{
this
.
rawUrl
=
rawUrl
;
}
public
void
setRawUrl
(
String
rawUrl
)
{
this
.
rawUrl
=
rawUrl
;
}
public
Visibility
getVisibility
()
{
return
visibility
;
}
public
Visibility
getVisibility
()
{
return
visibility
;
}
public
void
setVisibility
(
Visibility
visibility
)
{
this
.
visibility
=
visibility
;
}
public
void
setVisibility
(
Visibility
visibility
)
{
this
.
visibility
=
visibility
;
}
public
String
getDescription
()
{
return
description
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
}
src/test/java/org/gitlab4j/api/TestSnippetsApi.java
View file @
ae37475b
...
...
@@ -17,7 +17,7 @@ public class TestSnippetsApi {
private
static
final
String
TEST_HOST_URL
;
private
static
final
String
TEST_PRIVATE_TOKEN
;
static
{
TEST_HOST_URL
=
TestUtils
.
getProperty
(
"TEST_HOST_URL"
);
TEST_PRIVATE_TOKEN
=
TestUtils
.
getProperty
(
"TEST_PRIVATE_TOKEN"
);
...
...
@@ -29,8 +29,7 @@ public class TestSnippetsApi {
private
static
final
String
TEST_SNIPPET_CONTENT_1
=
"test-snippet-content-1"
;
private
static
final
String
TEST_SNIPPET_CONTENT_2
=
"test-snippet-content-2"
;
private
static
final
String
TEST_SNIPPET_DESCRIPTION_1
=
"test-snippet-description-1"
;
@BeforeClass
public
static
void
setup
()
{
...
...
@@ -50,95 +49,81 @@ public class TestSnippetsApi {
System
.
err
.
print
(
problems
);
}
}
@Test
public
void
testCreate
()
throws
GitLabApiException
{
Snippet
snippet
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
));
assertEquals
(
TEST_SNIPPET_TITLE_1
,
snippet
.
getTitle
());
assertEquals
(
TEST_SNIPPET_FILE_NAME_1
,
snippet
.
getFileName
());
assertNull
(
snippet
.
getContent
());
deleteSnippet
(
snippet
);
}
@Test
public
void
testDelete
()
throws
GitLabApiException
{
Snippet
snippet
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
));
deleteSnippet
(
snippet
);
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
List
<
Snippet
>
snippets
=
api
.
getSnippets
();
boolean
found
=
snippets
.
stream
().
anyMatch
(
s
->
s
.
getId
().
equals
(
snippet
.
getId
()));
assertFalse
(
found
);
}
@Test
public
void
testList
()
throws
GitLabApiException
{
Snippet
snippet1
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
));
Snippet
snippet2
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_2
));
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
List
<
Snippet
>
snippets
=
api
.
getSnippets
(
true
);
assertTrue
(
snippets
.
size
()
>=
2
);
assertTrue
(
snippets
.
stream
().
anyMatch
(
s
->
s
.
getContent
().
equals
(
TEST_SNIPPET_CONTENT_1
)));
assertTrue
(
snippets
.
stream
().
anyMatch
(
s
->
s
.
getContent
().
equals
(
TEST_SNIPPET_CONTENT_2
)));
deleteSnippet
(
snippet1
);
deleteSnippet
(
snippet2
);
}
@Test
public
void
testSnippetContent
()
throws
GitLabApiException
{
Snippet
snippet
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
));
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
String
snippetContent
=
api
.
getSnippetContent
(
snippet
.
getId
());
assertEquals
(
TEST_SNIPPET_CONTENT_1
,
snippetContent
);
deleteSnippet
(
snippet
);
}
@Test
public
void
testRetrieveSnippet
()
throws
GitLabApiException
{
Snippet
snippet
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
,
Visibility
.
INTERNAL
,
TEST_SNIPPET_DESCRIPTION_1
));
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
Snippet
savedSnippet
=
api
.
getSnippet
(
snippet
.
getId
(),
true
);
assertEquals
(
TEST_SNIPPET_TITLE_1
,
savedSnippet
.
getTitle
());
assertEquals
(
TEST_SNIPPET_FILE_NAME_1
,
savedSnippet
.
getFileName
());
assertEquals
(
TEST_SNIPPET_CONTENT_1
,
savedSnippet
.
getContent
());
assertEquals
(
TEST_SNIPPET_DESCRIPTION_1
,
savedSnippet
.
getDescription
());
deleteSnippet
(
savedSnippet
);
}
public
void
deleteSnippet
(
Snippet
snippet
)
throws
GitLabApiException
{
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
api
.
deleteSnippet
(
snippet
.
getId
());
}
public
Snippet
createSnippet
(
Snippet
snippet
)
throws
GitLabApiException
{
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
return
api
.
createSnippet
(
snippet
.
getTitle
(),
snippet
.
getFileName
(),
snippet
.
getContent
(),
snippet
.
getVisibility
(),
snippet
.
getDescription
());
}
@Test
public
void
testCreate
()
throws
GitLabApiException
{
Snippet
snippet
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
));
assertEquals
(
TEST_SNIPPET_TITLE_1
,
snippet
.
getTitle
());
assertEquals
(
TEST_SNIPPET_FILE_NAME_1
,
snippet
.
getFileName
());
assertNull
(
snippet
.
getContent
());
deleteSnippet
(
snippet
);
}
@Test
public
void
testDelete
()
throws
GitLabApiException
{
Snippet
snippet
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
));
deleteSnippet
(
snippet
);
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
List
<
Snippet
>
snippets
=
api
.
getSnippets
();
boolean
found
=
snippets
.
stream
().
anyMatch
(
s
->
s
.
getId
().
equals
(
snippet
.
getId
()));
assertFalse
(
found
);
}
@Test
public
void
testList
()
throws
GitLabApiException
{
Snippet
snippet1
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
));
Snippet
snippet2
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_2
));
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
List
<
Snippet
>
snippets
=
api
.
getSnippets
(
true
);
assertTrue
(
snippets
.
size
()
>=
2
);
assertTrue
(
snippets
.
stream
().
anyMatch
(
s
->
s
.
getContent
().
equals
(
TEST_SNIPPET_CONTENT_1
)));
assertTrue
(
snippets
.
stream
().
anyMatch
(
s
->
s
.
getContent
().
equals
(
TEST_SNIPPET_CONTENT_2
)));
deleteSnippet
(
snippet1
);
deleteSnippet
(
snippet2
);
}
@Test
public
void
testSnippetContent
()
throws
GitLabApiException
{
Snippet
snippet
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
));
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
String
snippetContent
=
api
.
getSnippetContent
(
snippet
.
getId
());
assertEquals
(
TEST_SNIPPET_CONTENT_1
,
snippetContent
);
deleteSnippet
(
snippet
);
}
@Test
public
void
testRetrieveSnippet
()
throws
GitLabApiException
{
Snippet
snippet
=
createSnippet
(
new
Snippet
(
TEST_SNIPPET_TITLE_1
,
TEST_SNIPPET_FILE_NAME_1
,
TEST_SNIPPET_CONTENT_1
,
Visibility
.
INTERNAL
,
TEST_SNIPPET_DESCRIPTION_1
));
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
Snippet
savedSnippet
=
api
.
getSnippet
(
snippet
.
getId
(),
true
);
assertEquals
(
TEST_SNIPPET_TITLE_1
,
savedSnippet
.
getTitle
());
assertEquals
(
TEST_SNIPPET_FILE_NAME_1
,
savedSnippet
.
getFileName
());
assertEquals
(
TEST_SNIPPET_CONTENT_1
,
savedSnippet
.
getContent
());
assertEquals
(
TEST_SNIPPET_DESCRIPTION_1
,
savedSnippet
.
getDescription
());
deleteSnippet
(
savedSnippet
);
}
public
void
deleteSnippet
(
Snippet
snippet
)
throws
GitLabApiException
{
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
api
.
deleteSnippet
(
snippet
.
getId
());
}
public
Snippet
createSnippet
(
Snippet
snippet
)
throws
GitLabApiException
{
SnippetsApi
api
=
gitLabApi
.
getSnippetApi
();
return
api
.
createSnippet
(
snippet
.
getTitle
(),
snippet
.
getFileName
(),
snippet
.
getContent
(),
snippet
.
getVisibility
(),
snippet
.
getDescription
());
}
}
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