Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
6bb771ca
Unverified
Commit
6bb771ca
authored
Dec 07, 2018
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
增加后台单元测试
parent
782b97e6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
148 additions
and
0 deletions
+148
-0
src/test/java/org/b3log/solo/processor/console/ArticleConsoleTestCase.java
.../b3log/solo/processor/console/ArticleConsoleTestCase.java
+148
-0
No files found.
src/test/java/org/b3log/solo/processor/console/ArticleConsoleTestCase.java
0 → 100644
View file @
6bb771ca
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package
org
.
b3log
.
solo
.
processor
.
console
;
import
org.apache.commons.lang.StringUtils
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.repository.Query
;
import
org.b3log.solo.AbstractTestCase
;
import
org.b3log.solo.MockHttpServletRequest
;
import
org.b3log.solo.MockHttpServletResponse
;
import
org.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
/**
* {@link ArticleConsole} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Dec 7, 2018
* @since 2.9.7
*/
@Test
(
suiteName
=
"processor"
)
public
class
ArticleConsoleTestCase
extends
AbstractTestCase
{
/**
* Init.
*
* @throws Exception exception
*/
@Test
public
void
init
()
throws
Exception
{
super
.
init
();
}
/**
* getArticleThumbs.
*
* @throws Exception exception
*/
@Test
(
dependsOnMethods
=
"init"
)
public
void
getArticleThumbs
()
throws
Exception
{
final
MockHttpServletRequest
request
=
mockRequest
();
request
.
setRequestURI
(
"/console/thumbs"
);
mockAdminLogin
(
request
);
final
MockHttpServletResponse
response
=
mockResponse
();
mockDispatcherServletService
(
request
,
response
);
final
String
content
=
response
.
body
();
Assert
.
assertTrue
(
StringUtils
.
contains
(
content
,
"{\"sc\":true,"
));
}
/**
* markdown2HTML.
*
* @throws Exception exception
*/
@Test
(
dependsOnMethods
=
"init"
)
public
void
markdown2HTML
()
throws
Exception
{
final
MockHttpServletRequest
request
=
mockRequest
();
request
.
setRequestURI
(
"/console/markdown/2html"
);
request
.
putParameter
(
"markdownText"
,
"**Solo**"
);
request
.
setMethod
(
"POST"
);
mockAdminLogin
(
request
);
final
MockHttpServletResponse
response
=
mockResponse
();
mockDispatcherServletService
(
request
,
response
);
final
String
content
=
response
.
body
();
Assert
.
assertTrue
(
StringUtils
.
contains
(
content
,
"<p><strong>Solo<\\/strong><\\/p>"
));
}
/**
* getArticle.
*
* @throws Exception exception
*/
@Test
(
dependsOnMethods
=
"init"
)
public
void
getArticle
()
throws
Exception
{
final
JSONObject
article
=
getArticleRepository
().
get
(
new
Query
()).
optJSONArray
(
Keys
.
RESULTS
).
optJSONObject
(
0
);
final
String
articleId
=
article
.
optString
(
Keys
.
OBJECT_ID
);
final
MockHttpServletRequest
request
=
mockRequest
();
request
.
setRequestURI
(
"/console/article/"
+
articleId
);
mockAdminLogin
(
request
);
final
MockHttpServletResponse
response
=
mockResponse
();
mockDispatcherServletService
(
request
,
response
);
final
String
content
=
response
.
body
();
Assert
.
assertTrue
(
StringUtils
.
contains
(
content
,
"{\"sc\":true,"
));
}
/**
* getArticles.
*
* @throws Exception exception
*/
@Test
(
dependsOnMethods
=
"init"
)
public
void
getArticles
()
throws
Exception
{
final
MockHttpServletRequest
request
=
mockRequest
();
request
.
setRequestURI
(
"/console/articles/status/published/1/10/20"
);
mockAdminLogin
(
request
);
final
MockHttpServletResponse
response
=
mockResponse
();
mockDispatcherServletService
(
request
,
response
);
final
String
content
=
response
.
body
();
Assert
.
assertTrue
(
StringUtils
.
contains
(
content
,
"{\"sc\":true,"
));
}
/**
* removeArticle.
*
* @throws Exception exception
*/
@Test
(
dependsOnMethods
=
"init"
)
public
void
removeArticle
()
throws
Exception
{
final
JSONObject
article
=
getArticleRepository
().
get
(
new
Query
()).
optJSONArray
(
Keys
.
RESULTS
).
optJSONObject
(
0
);
final
String
articleId
=
article
.
optString
(
Keys
.
OBJECT_ID
);
final
MockHttpServletRequest
request
=
mockRequest
();
request
.
setRequestURI
(
"/console/article/"
+
articleId
);
request
.
setMethod
(
"DELETE"
);
mockAdminLogin
(
request
);
final
MockHttpServletResponse
response
=
mockResponse
();
mockDispatcherServletService
(
request
,
response
);
final
String
content
=
response
.
body
();
Assert
.
assertTrue
(
StringUtils
.
contains
(
content
,
"{\"sc\":true,"
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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