Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo
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
Commits
9b05326f
Commit
9b05326f
authored
Apr 19, 2013
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Option 相关单元测试
parent
bf8cb4f8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
826 additions
and
525 deletions
+826
-525
core/src/main/java/org/b3log/solo/service/OptionMgmtService.java
...c/main/java/org/b3log/solo/service/OptionMgmtService.java
+28
-31
core/src/test/java/org/b3log/solo/AbstractTestCase.java
core/src/test/java/org/b3log/solo/AbstractTestCase.java
+569
-494
core/src/test/java/org/b3log/solo/repository/impl/OptionRepositoryImplTestCase.java
...og/solo/repository/impl/OptionRepositoryImplTestCase.java
+58
-0
core/src/test/java/org/b3log/solo/service/OptionMgmtServiceTestCase.java
...ava/org/b3log/solo/service/OptionMgmtServiceTestCase.java
+106
-0
core/src/test/java/org/b3log/solo/service/OptionQueryServiceTestCase.java
...va/org/b3log/solo/service/OptionQueryServiceTestCase.java
+65
-0
No files found.
core/src/main/java/org/b3log/solo/service/OptionMgmtService.java
View file @
9b05326f
...
...
@@ -47,24 +47,36 @@ public final class OptionMgmtService {
private
OptionRepository
optionRepository
=
OptionRepositoryImpl
.
getInstance
();
/**
*
Updates the specified option, if not found the old version of the specified option by id, creates it
.
*
Adds or updates the specified option
.
*
* @param option the specified option
* @throws ServiceException service exception
* @return option id
* @throws ServiceException
*/
public
void
updateOption
(
final
JSONObject
option
)
throws
ServiceException
{
final
String
id
=
option
.
optString
(
Keys
.
OBJECT_ID
);
public
String
addOrUpdateOption
(
final
JSONObject
option
)
throws
ServiceException
{
final
Transaction
transaction
=
optionRepository
.
beginTransaction
();
try
{
if
(
null
!=
optionRepository
.
get
(
id
))
{
optionRepository
.
update
(
id
,
option
);
String
id
=
option
.
optString
(
Keys
.
OBJECT_ID
);
if
(
Strings
.
isEmptyOrNull
(
id
))
{
id
=
optionRepository
.
add
(
option
);
}
else
{
optionRepository
.
add
(
option
);
final
JSONObject
old
=
optionRepository
.
get
(
id
);
if
(
null
==
old
)
{
// The id is specified by caller
id
=
optionRepository
.
add
(
option
);
}
else
{
old
.
put
(
Option
.
OPTION_CATEGORY
,
option
.
optString
(
Option
.
OPTION_CATEGORY
));
old
.
put
(
Option
.
OPTION_VALUE
,
option
.
optString
(
Option
.
OPTION_VALUE
));
optionRepository
.
update
(
id
,
old
);
}
}
transaction
.
commit
();
return
id
;
}
catch
(
final
Exception
e
)
{
if
(
transaction
.
isActive
())
{
transaction
.
rollback
();
...
...
@@ -73,34 +85,19 @@ public final class OptionMgmtService {
throw
new
ServiceException
(
e
);
}
}
/**
*
Adds or updates the specified option.
*
Removes the option specified by the given option id.
*
* @param option
the specified option
* @throws ServiceException
* @param option
Id the given option id
* @throws ServiceException
service exception
*/
public
void
addOrUpdateOption
(
final
JSONObject
option
)
throws
ServiceException
{
public
void
removeOption
(
final
String
optionId
)
throws
ServiceException
{
final
Transaction
transaction
=
optionRepository
.
beginTransaction
();
try
{
final
String
id
=
option
.
optString
(
Keys
.
OBJECT_ID
);
if
(
Strings
.
isEmptyOrNull
(
id
))
{
optionRepository
.
add
(
option
);
}
else
{
final
JSONObject
old
=
optionRepository
.
get
(
id
);
if
(
null
==
old
)
{
// The id is specified by caller
optionRepository
.
add
(
option
);
}
else
{
old
.
put
(
Option
.
OPTION_CATEGORY
,
option
.
optString
(
Option
.
OPTION_CATEGORY
));
old
.
put
(
Option
.
OPTION_VALUE
,
option
.
optString
(
Option
.
OPTION_VALUE
));
optionRepository
.
update
(
id
,
old
);
}
}
optionRepository
.
remove
(
optionId
);
transaction
.
commit
();
}
catch
(
final
Exception
e
)
{
if
(
transaction
.
isActive
())
{
...
...
core/src/test/java/org/b3log/solo/AbstractTestCase.java
View file @
9b05326f
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
b3log
.
solo
;
import
com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig
;
import
com.google.appengine.tools.development.testing.LocalServiceTestHelper
;
import
java.util.Locale
;
import
org.b3log.latke.Latkes
;
import
org.b3log.solo.repository.ArchiveDateArticleRepository
;
import
org.b3log.solo.repository.ArchiveDateRepository
;
import
org.b3log.solo.repository.ArticleRepository
;
import
org.b3log.solo.repository.CommentRepository
;
import
org.b3log.solo.repository.LinkRepository
;
import
org.b3log.solo.repository.PageRepository
;
import
org.b3log.solo.repository.PluginRepository
;
import
org.b3log.solo.repository.PreferenceRepository
;
import
org.b3log.solo.repository.StatisticRepository
;
import
org.b3log.solo.repository.TagArticleRepository
;
import
org.b3log.solo.repository.TagRepository
;
import
org.b3log.solo.repository.UserRepository
;
import
org.b3log.solo.repository.impl.ArchiveDateArticleRepositoryImpl
;
import
org.b3log.solo.repository.impl.ArchiveDateRepositoryImpl
;
import
org.b3log.solo.repository.impl.ArticleRepositoryImpl
;
import
org.b3log.solo.repository.impl.CommentRepositoryImpl
;
import
org.b3log.solo.repository.impl.LinkRepositoryImpl
;
import
org.b3log.solo.repository.impl.PageRepositoryImpl
;
import
org.b3log.solo.repository.impl.PluginRepositoryImpl
;
import
org.b3log.solo.repository.impl.PreferenceRepositoryImpl
;
import
org.b3log.solo.repository.impl.StatisticRepositoryImpl
;
import
org.b3log.solo.repository.impl.TagArticleRepositoryImpl
;
import
org.b3log.solo.repository.impl.TagRepositoryImpl
;
import
org.b3log.solo.repository.impl.UserRepositoryImpl
;
import
org.b3log.solo.service.*
;
import
org.testng.annotations.AfterClass
;
import
org.testng.annotations.BeforeClass
;
/**
* Abstract test case.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.5, Feb 8, 2013
* @see #beforeClass()
* @see #afterClass()
*/
public
abstract
class
AbstractTestCase
{
/**
* Local service test helper.
*/
private
final
LocalServiceTestHelper
localServiceTestHelper
=
new
LocalServiceTestHelper
(
new
LocalDatastoreServiceTestConfig
());
/**
* User repository.
*/
private
UserRepository
userRepository
;
/**
* Link repository.
*/
private
LinkRepository
linkRepository
;
/**
* Article repository.
*/
private
ArticleRepository
articleRepository
;
/**
* Tag repository.
*/
private
TagRepository
tagRepository
;
/**
* Tag-Article repository.
*/
private
TagArticleRepository
tagArticleRepository
;
/**
* Page repository.
*/
private
PageRepository
pageRepository
;
/**
* Comment repository.
*/
private
CommentRepository
commentRepository
;
/**
* Archive date repository.
*/
private
ArchiveDateRepository
archiveDateRepository
;
/**
* Archive date article repository.
*/
private
ArchiveDateArticleRepository
archiveDateArticleRepository
;
/**
* Plugin repository.
*/
private
PluginRepository
pluginRepository
;
/**
* Preference repository.
*/
private
PreferenceRepository
preferenceRepository
;
/**
* Statistic repository.
*/
private
StatisticRepository
statisticRepository
;
/**
* Initialization service.
*/
private
InitService
initService
;
/**
* User management service.
*/
private
UserMgmtService
userMgmtService
;
/**
* User query service.
*/
private
UserQueryService
userQueryService
;
/**
* Article management service.
*/
private
ArticleMgmtService
articleMgmtService
;
/**
* Article query service.
*/
private
ArticleQueryService
articleQueryService
;
/**
* Page management service.
*/
private
PageMgmtService
pageMgmtService
;
/**
* Page query service.
*/
private
PageQueryService
pageQueryService
;
/**
* Link management service.
*/
private
LinkMgmtService
linkMgmtService
;
/**
* Link query service.
*/
private
LinkQueryService
linkQueryService
;
/**
* Preference management service.
*/
private
PreferenceMgmtService
preferenceMgmtService
;
/**
* Preference query service.
*/
private
PreferenceQueryService
preferenceQueryService
;
/**
* Tag query service.
*/
private
TagQueryService
tagQueryService
;
/**
* Tag management service.
*/
private
TagMgmtService
tagMgmtService
;
/**
* Comment query service.
*/
private
CommentQueryService
commentQueryService
;
/**
* Comment management service.
*/
private
CommentMgmtService
commentMgmtService
;
/**
* Archive date query service.
*/
private
ArchiveDateQueryService
archiveDateQueryService
;
/**
* Before class.
*
* <ol>
* <li>Sets up GAE unit test runtime environment</li>
* <li>Initializes Latke runtime</li>
* <li>Instantiates repositories</li>
* </ol>
*/
@BeforeClass
public
void
beforeClass
()
{
localServiceTestHelper
.
setUp
();
Latkes
.
initRuntimeEnv
();
Latkes
.
setLocale
(
Locale
.
SIMPLIFIED_CHINESE
);
// Repositories
userRepository
=
UserRepositoryImpl
.
getInstance
();
linkRepository
=
LinkRepositoryImpl
.
getInstance
();
articleRepository
=
ArticleRepositoryImpl
.
getInstance
();
tagRepository
=
TagRepositoryImpl
.
getInstance
();
tagArticleRepository
=
TagArticleRepositoryImpl
.
getInstance
();
pageRepository
=
PageRepositoryImpl
.
getInstance
();
commentRepository
=
CommentRepositoryImpl
.
getInstance
();
archiveDateRepository
=
ArchiveDateRepositoryImpl
.
getInstance
();
archiveDateArticleRepository
=
ArchiveDateArticleRepositoryImpl
.
getInstance
();
pluginRepository
=
PluginRepositoryImpl
.
getInstance
();
preferenceRepository
=
PreferenceRepositoryImpl
.
getInstance
();
statisticRepository
=
StatisticRepositoryImpl
.
getInstance
();
// Services
initService
=
InitService
.
getInstance
();
userMgmtService
=
UserMgmtService
.
getInstance
();
userQueryService
=
UserQueryService
.
getInstance
();
articleMgmtService
=
ArticleMgmtService
.
getInstance
();
articleQueryService
=
ArticleQueryService
.
getInstance
();
pageMgmtService
=
PageMgmtService
.
getInstance
();
pageQueryService
=
PageQueryService
.
getInstance
();
linkMgmtService
=
LinkMgmtService
.
getInstance
();
linkQueryService
=
LinkQueryService
.
getInstance
();
preferenceMgmtService
=
PreferenceMgmtService
.
getInstance
();
preferenceQueryService
=
PreferenceQueryService
.
getInstance
();
tagQueryService
=
TagQueryService
.
getInstance
();
tagMgmtService
=
TagMgmtService
.
getInstance
();
commentQueryService
=
CommentQueryService
.
getInstance
();
commentMgmtService
=
CommentMgmtService
.
getInstance
();
archiveDateQueryService
=
ArchiveDateQueryService
.
getInstance
();
}
/**
* After class.
*
* <ol>
* <li>Tears down GAE unit test runtime environment</li>
* <li>Shutdowns Latke runtime</li>
* </ol>
*/
@AfterClass
public
void
afterClass
()
{
localServiceTestHelper
.
tearDown
();
Latkes
.
shutdown
();
}
/**
* Gets user repository.
*
* @return user repository
*/
public
UserRepository
getUserRepository
()
{
return
userRepository
;
}
/**
* Gets link repository.
*
* @return link repository
*/
public
LinkRepository
getLinkRepository
()
{
return
linkRepository
;
}
/**
* Gets article repository.
*
* @return article repository
*/
public
ArticleRepository
getArticleRepository
()
{
return
articleRepository
;
}
/**
* Gets tag repository.
*
* @return tag repository
*/
public
TagRepository
getTagRepository
()
{
return
tagRepository
;
}
/**
* Gets tag-article repository.
*
* @return tag-article repository
*/
public
TagArticleRepository
getTagArticleRepository
()
{
return
tagArticleRepository
;
}
/**
* Gets page repository.
*
* @return page repository
*/
public
PageRepository
getPageRepository
()
{
return
pageRepository
;
}
/**
* Gets comment repository.
*
* @return comment repository
*/
public
CommentRepository
getCommentRepository
()
{
return
commentRepository
;
}
/**
* Gets archive date repository.
*
* @return archive date repository
*/
public
ArchiveDateRepository
getArchiveDateRepository
()
{
return
archiveDateRepository
;
}
/**
* Archive date article repository.
*
* @return archive date article repository
*/
public
ArchiveDateArticleRepository
getArchiveDateArticleRepository
()
{
return
archiveDateArticleRepository
;
}
/**
* Gets plugin repository.
*
* @return plugin repository
*/
public
PluginRepository
getPluginRepository
()
{
return
pluginRepository
;
}
/**
* Gets preference repository.
*
* @return preference repository
*/
public
PreferenceRepository
getPreferenceRepository
()
{
return
preferenceRepository
;
}
/**
* Gets statistic repository.
*
* @return statistic repository
*/
public
StatisticRepository
getStatisticRepository
()
{
return
statisticRepository
;
}
/**
* Gets initialization service.
*
* @return initialization service
*/
public
InitService
getInitService
()
{
return
initService
;
}
/**
* Gets user management service.
*
* @return user management service
*/
public
UserMgmtService
getUserMgmtService
()
{
return
userMgmtService
;
}
/**
* Gets user query service.
*
* @return user query service
*/
public
UserQueryService
getUserQueryService
()
{
return
userQueryService
;
}
/**
* Gets article management service.
*
* @return article management service
*/
public
ArticleMgmtService
getArticleMgmtService
()
{
return
articleMgmtService
;
}
/**
* Gets article query service.
*
* @return article query service
*/
public
ArticleQueryService
getArticleQueryService
()
{
return
articleQueryService
;
}
/**
* Gets page management service.
*
* @return page management service
*/
public
PageMgmtService
getPageMgmtService
()
{
return
pageMgmtService
;
}
/**
* Gets page query service.
*
* @return page query service
*/
public
PageQueryService
getPageQueryService
()
{
return
pageQueryService
;
}
/**
* Gets link management service.
*
* @return link management service
*/
public
LinkMgmtService
getLinkMgmtService
()
{
return
linkMgmtService
;
}
/**
* Gets link query service.
*
* @return link query service
*/
public
LinkQueryService
getLinkQueryService
()
{
return
linkQueryService
;
}
/**
* Gets preference management service.
*
* @return preference management service
*/
public
PreferenceMgmtService
getPreferenceMgmtService
()
{
return
preferenceMgmtService
;
}
/**
* Gets preference query service.
*
* @return preference query service
*/
public
PreferenceQueryService
getPreferenceQueryService
()
{
return
preferenceQueryService
;
}
/**
* Gets tag query service.
*
* @return tag query service
*/
public
TagQueryService
getTagQueryService
()
{
return
tagQueryService
;
}
/**
* Gets tag management service.
*
* @return tag management service
*/
public
TagMgmtService
getTagMgmtService
()
{
return
tagMgmtService
;
}
/**
* Gets comment query service.
*
* @return comment query service
*/
public
CommentQueryService
getCommentQueryService
()
{
return
commentQueryService
;
}
/**
* Gets comment management service.
*
* @return comment management service
*/
public
CommentMgmtService
getCommentMgmtService
()
{
return
commentMgmtService
;
}
/**
* Gets archive date query service.
*
* @return archive date query service
*/
public
ArchiveDateQueryService
getArchiveDateQueryService
()
{
return
archiveDateQueryService
;
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
b3log
.
solo
;
import
com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig
;
import
com.google.appengine.tools.development.testing.LocalServiceTestHelper
;
import
java.util.Locale
;
import
org.b3log.latke.Latkes
;
import
org.b3log.solo.repository.ArchiveDateArticleRepository
;
import
org.b3log.solo.repository.ArchiveDateRepository
;
import
org.b3log.solo.repository.ArticleRepository
;
import
org.b3log.solo.repository.CommentRepository
;
import
org.b3log.solo.repository.LinkRepository
;
import
org.b3log.solo.repository.OptionRepository
;
import
org.b3log.solo.repository.PageRepository
;
import
org.b3log.solo.repository.PluginRepository
;
import
org.b3log.solo.repository.PreferenceRepository
;
import
org.b3log.solo.repository.StatisticRepository
;
import
org.b3log.solo.repository.TagArticleRepository
;
import
org.b3log.solo.repository.TagRepository
;
import
org.b3log.solo.repository.UserRepository
;
import
org.b3log.solo.repository.impl.ArchiveDateArticleRepositoryImpl
;
import
org.b3log.solo.repository.impl.ArchiveDateRepositoryImpl
;
import
org.b3log.solo.repository.impl.ArticleRepositoryImpl
;
import
org.b3log.solo.repository.impl.CommentRepositoryImpl
;
import
org.b3log.solo.repository.impl.LinkRepositoryImpl
;
import
org.b3log.solo.repository.impl.OptionRepositoryImpl
;
import
org.b3log.solo.repository.impl.PageRepositoryImpl
;
import
org.b3log.solo.repository.impl.PluginRepositoryImpl
;
import
org.b3log.solo.repository.impl.PreferenceRepositoryImpl
;
import
org.b3log.solo.repository.impl.StatisticRepositoryImpl
;
import
org.b3log.solo.repository.impl.TagArticleRepositoryImpl
;
import
org.b3log.solo.repository.impl.TagRepositoryImpl
;
import
org.b3log.solo.repository.impl.UserRepositoryImpl
;
import
org.b3log.solo.service.*
;
import
org.testng.annotations.AfterClass
;
import
org.testng.annotations.BeforeClass
;
/**
* Abstract test case.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.6, Apr 19, 2013
* @see #beforeClass()
* @see #afterClass()
*/
public
abstract
class
AbstractTestCase
{
/**
* Local service test helper.
*/
private
final
LocalServiceTestHelper
localServiceTestHelper
=
new
LocalServiceTestHelper
(
new
LocalDatastoreServiceTestConfig
());
/**
* User repository.
*/
private
UserRepository
userRepository
;
/**
* Link repository.
*/
private
LinkRepository
linkRepository
;
/**
* Article repository.
*/
private
ArticleRepository
articleRepository
;
/**
* Tag repository.
*/
private
TagRepository
tagRepository
;
/**
* Tag-Article repository.
*/
private
TagArticleRepository
tagArticleRepository
;
/**
* Page repository.
*/
private
PageRepository
pageRepository
;
/**
* Comment repository.
*/
private
CommentRepository
commentRepository
;
/**
* Archive date repository.
*/
private
ArchiveDateRepository
archiveDateRepository
;
/**
* Archive date article repository.
*/
private
ArchiveDateArticleRepository
archiveDateArticleRepository
;
/**
* Plugin repository.
*/
private
PluginRepository
pluginRepository
;
/**
* Preference repository.
*/
private
PreferenceRepository
preferenceRepository
;
/**
* Statistic repository.
*/
private
StatisticRepository
statisticRepository
;
/**
* Option repository.
*/
private
OptionRepository
optionRepository
;
/**
* Initialization service.
*/
private
InitService
initService
;
/**
* User management service.
*/
private
UserMgmtService
userMgmtService
;
/**
* User query service.
*/
private
UserQueryService
userQueryService
;
/**
* Article management service.
*/
private
ArticleMgmtService
articleMgmtService
;
/**
* Article query service.
*/
private
ArticleQueryService
articleQueryService
;
/**
* Page management service.
*/
private
PageMgmtService
pageMgmtService
;
/**
* Page query service.
*/
private
PageQueryService
pageQueryService
;
/**
* Link management service.
*/
private
LinkMgmtService
linkMgmtService
;
/**
* Link query service.
*/
private
LinkQueryService
linkQueryService
;
/**
* Preference management service.
*/
private
PreferenceMgmtService
preferenceMgmtService
;
/**
* Preference query service.
*/
private
PreferenceQueryService
preferenceQueryService
;
/**
* Tag query service.
*/
private
TagQueryService
tagQueryService
;
/**
* Tag management service.
*/
private
TagMgmtService
tagMgmtService
;
/**
* Comment query service.
*/
private
CommentQueryService
commentQueryService
;
/**
* Comment management service.
*/
private
CommentMgmtService
commentMgmtService
;
/**
* Archive date query service.
*/
private
ArchiveDateQueryService
archiveDateQueryService
;
/**
* Option management service.
*/
private
OptionMgmtService
optionMgmtService
;
/**
* Option query service.
*/
private
OptionQueryService
optionQueryService
;
/**
* Before class.
*
* <ol>
* <li>Sets up GAE unit test runtime environment</li>
* <li>Initializes Latke runtime</li>
* <li>Instantiates repositories</li>
* </ol>
*/
@BeforeClass
public
void
beforeClass
()
{
localServiceTestHelper
.
setUp
();
Latkes
.
initRuntimeEnv
();
Latkes
.
setLocale
(
Locale
.
SIMPLIFIED_CHINESE
);
// Repositories
userRepository
=
UserRepositoryImpl
.
getInstance
();
linkRepository
=
LinkRepositoryImpl
.
getInstance
();
articleRepository
=
ArticleRepositoryImpl
.
getInstance
();
tagRepository
=
TagRepositoryImpl
.
getInstance
();
tagArticleRepository
=
TagArticleRepositoryImpl
.
getInstance
();
pageRepository
=
PageRepositoryImpl
.
getInstance
();
commentRepository
=
CommentRepositoryImpl
.
getInstance
();
archiveDateRepository
=
ArchiveDateRepositoryImpl
.
getInstance
();
archiveDateArticleRepository
=
ArchiveDateArticleRepositoryImpl
.
getInstance
();
pluginRepository
=
PluginRepositoryImpl
.
getInstance
();
preferenceRepository
=
PreferenceRepositoryImpl
.
getInstance
();
statisticRepository
=
StatisticRepositoryImpl
.
getInstance
();
optionRepository
=
OptionRepositoryImpl
.
getInstance
();
// Services
initService
=
InitService
.
getInstance
();
userMgmtService
=
UserMgmtService
.
getInstance
();
userQueryService
=
UserQueryService
.
getInstance
();
articleMgmtService
=
ArticleMgmtService
.
getInstance
();
articleQueryService
=
ArticleQueryService
.
getInstance
();
pageMgmtService
=
PageMgmtService
.
getInstance
();
pageQueryService
=
PageQueryService
.
getInstance
();
linkMgmtService
=
LinkMgmtService
.
getInstance
();
linkQueryService
=
LinkQueryService
.
getInstance
();
preferenceMgmtService
=
PreferenceMgmtService
.
getInstance
();
preferenceQueryService
=
PreferenceQueryService
.
getInstance
();
tagQueryService
=
TagQueryService
.
getInstance
();
tagMgmtService
=
TagMgmtService
.
getInstance
();
commentQueryService
=
CommentQueryService
.
getInstance
();
commentMgmtService
=
CommentMgmtService
.
getInstance
();
archiveDateQueryService
=
ArchiveDateQueryService
.
getInstance
();
optionMgmtService
=
OptionMgmtService
.
getInstance
();
optionQueryService
=
OptionQueryService
.
getInstance
();
}
/**
* After class.
*
* <ol>
* <li>Tears down GAE unit test runtime environment</li>
* <li>Shutdowns Latke runtime</li>
* </ol>
*/
@AfterClass
public
void
afterClass
()
{
// XXX: NPE, localServiceTestHelper.tearDown();
Latkes
.
shutdown
();
}
/**
* Gets user repository.
*
* @return user repository
*/
public
UserRepository
getUserRepository
()
{
return
userRepository
;
}
/**
* Gets link repository.
*
* @return link repository
*/
public
LinkRepository
getLinkRepository
()
{
return
linkRepository
;
}
/**
* Gets article repository.
*
* @return article repository
*/
public
ArticleRepository
getArticleRepository
()
{
return
articleRepository
;
}
/**
* Gets tag repository.
*
* @return tag repository
*/
public
TagRepository
getTagRepository
()
{
return
tagRepository
;
}
/**
* Gets tag-article repository.
*
* @return tag-article repository
*/
public
TagArticleRepository
getTagArticleRepository
()
{
return
tagArticleRepository
;
}
/**
* Gets page repository.
*
* @return page repository
*/
public
PageRepository
getPageRepository
()
{
return
pageRepository
;
}
/**
* Gets comment repository.
*
* @return comment repository
*/
public
CommentRepository
getCommentRepository
()
{
return
commentRepository
;
}
/**
* Gets archive date repository.
*
* @return archive date repository
*/
public
ArchiveDateRepository
getArchiveDateRepository
()
{
return
archiveDateRepository
;
}
/**
* Archive date article repository.
*
* @return archive date article repository
*/
public
ArchiveDateArticleRepository
getArchiveDateArticleRepository
()
{
return
archiveDateArticleRepository
;
}
/**
* Gets plugin repository.
*
* @return plugin repository
*/
public
PluginRepository
getPluginRepository
()
{
return
pluginRepository
;
}
/**
* Gets preference repository.
*
* @return preference repository
*/
public
PreferenceRepository
getPreferenceRepository
()
{
return
preferenceRepository
;
}
/**
* Gets statistic repository.
*
* @return statistic repository
*/
public
StatisticRepository
getStatisticRepository
()
{
return
statisticRepository
;
}
/**
* Gets option repository.
*
* @return option repository
*/
public
OptionRepository
getOptionRepository
()
{
return
optionRepository
;
}
/**
* Gets initialization service.
*
* @return initialization service
*/
public
InitService
getInitService
()
{
return
initService
;
}
/**
* Gets user management service.
*
* @return user management service
*/
public
UserMgmtService
getUserMgmtService
()
{
return
userMgmtService
;
}
/**
* Gets user query service.
*
* @return user query service
*/
public
UserQueryService
getUserQueryService
()
{
return
userQueryService
;
}
/**
* Gets article management service.
*
* @return article management service
*/
public
ArticleMgmtService
getArticleMgmtService
()
{
return
articleMgmtService
;
}
/**
* Gets article query service.
*
* @return article query service
*/
public
ArticleQueryService
getArticleQueryService
()
{
return
articleQueryService
;
}
/**
* Gets page management service.
*
* @return page management service
*/
public
PageMgmtService
getPageMgmtService
()
{
return
pageMgmtService
;
}
/**
* Gets page query service.
*
* @return page query service
*/
public
PageQueryService
getPageQueryService
()
{
return
pageQueryService
;
}
/**
* Gets link management service.
*
* @return link management service
*/
public
LinkMgmtService
getLinkMgmtService
()
{
return
linkMgmtService
;
}
/**
* Gets link query service.
*
* @return link query service
*/
public
LinkQueryService
getLinkQueryService
()
{
return
linkQueryService
;
}
/**
* Gets preference management service.
*
* @return preference management service
*/
public
PreferenceMgmtService
getPreferenceMgmtService
()
{
return
preferenceMgmtService
;
}
/**
* Gets preference query service.
*
* @return preference query service
*/
public
PreferenceQueryService
getPreferenceQueryService
()
{
return
preferenceQueryService
;
}
/**
* Gets tag query service.
*
* @return tag query service
*/
public
TagQueryService
getTagQueryService
()
{
return
tagQueryService
;
}
/**
* Gets tag management service.
*
* @return tag management service
*/
public
TagMgmtService
getTagMgmtService
()
{
return
tagMgmtService
;
}
/**
* Gets comment query service.
*
* @return comment query service
*/
public
CommentQueryService
getCommentQueryService
()
{
return
commentQueryService
;
}
/**
* Gets comment management service.
*
* @return comment management service
*/
public
CommentMgmtService
getCommentMgmtService
()
{
return
commentMgmtService
;
}
/**
* Gets archive date query service.
*
* @return archive date query service
*/
public
ArchiveDateQueryService
getArchiveDateQueryService
()
{
return
archiveDateQueryService
;
}
/**
* Gets option management service.
*
* @return option management service
*/
public
OptionMgmtService
getOptionMgmtService
()
{
return
optionMgmtService
;
}
/**
* Gets option query service.
*
* @return option query service
*/
public
OptionQueryService
getOptionQueryService
()
{
return
optionQueryService
;
}
}
core/src/test/java/org/b3log/solo/repository/impl/OptionRepositoryImplTestCase.java
0 → 100644
View file @
9b05326f
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
b3log
.
solo
.
repository
.
impl
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.repository.Transaction
;
import
org.b3log.solo.AbstractTestCase
;
import
org.b3log.solo.model.Option
;
import
org.b3log.solo.repository.OptionRepository
;
import
org.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
/**
* {@link OptionRepositoryImpl} test case.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Apr 19, 2013
* @since 0.6.0
*/
@Test
(
suiteName
=
"repository"
)
public
final
class
OptionRepositoryImplTestCase
extends
AbstractTestCase
{
/**
* Tests.
*
* @throws Exception exception
*/
@Test
public
void
test
()
throws
Exception
{
final
OptionRepository
optionRepository
=
getOptionRepository
();
final
JSONObject
option
=
new
JSONObject
();
option
.
put
(
Keys
.
OBJECT_ID
,
Option
.
ID_C_BROADCAST_CHANCE_EXPIRATION_TIME
);
option
.
put
(
Option
.
OPTION_CATEGORY
,
Option
.
CATEGORY_C_BROADCAST
);
option
.
put
(
Option
.
OPTION_VALUE
,
0L
);
Transaction
transaction
=
optionRepository
.
beginTransaction
();
optionRepository
.
add
(
option
);
transaction
.
commit
();
Assert
.
assertEquals
(
optionRepository
.
count
(),
1
);
Assert
.
assertNotNull
(
optionRepository
.
get
(
Option
.
ID_C_BROADCAST_CHANCE_EXPIRATION_TIME
));
}
}
core/src/test/java/org/b3log/solo/service/OptionMgmtServiceTestCase.java
0 → 100644
View file @
9b05326f
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
b3log
.
solo
.
service
;
import
org.b3log.latke.Keys
;
import
org.b3log.solo.AbstractTestCase
;
import
org.b3log.solo.model.Option
;
import
org.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
/**
* {@link OptionMgmtService} test case.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Apr 19, 2013
* @since 0.6.0
*/
@Test
(
suiteName
=
"service"
)
public
class
OptionMgmtServiceTestCase
extends
AbstractTestCase
{
/**
* Add.
*
* @throws Exception exception
*/
@Test
public
void
add
()
throws
Exception
{
final
OptionMgmtService
optionMgmtService
=
getOptionMgmtService
();
final
JSONObject
option
=
new
JSONObject
();
option
.
put
(
Keys
.
OBJECT_ID
,
Option
.
ID_C_BROADCAST_CHANCE_EXPIRATION_TIME
);
option
.
put
(
Option
.
OPTION_CATEGORY
,
Option
.
CATEGORY_C_BROADCAST
);
option
.
put
(
Option
.
OPTION_VALUE
,
0L
);
final
String
id
=
optionMgmtService
.
addOrUpdateOption
(
option
);
System
.
out
.
println
(
id
);
Assert
.
assertNotNull
(
id
);
}
/**
* Update.
*
* @throws Exception exception
*/
@Test
public
void
update
()
throws
Exception
{
final
OptionMgmtService
optionMgmtService
=
getOptionMgmtService
();
JSONObject
option
=
new
JSONObject
();
option
.
put
(
Keys
.
OBJECT_ID
,
Option
.
ID_C_BROADCAST_CHANCE_EXPIRATION_TIME
);
option
.
put
(
Option
.
OPTION_CATEGORY
,
Option
.
CATEGORY_C_BROADCAST
);
option
.
put
(
Option
.
OPTION_VALUE
,
0L
);
final
String
id
=
optionMgmtService
.
addOrUpdateOption
(
option
);
// Add
System
.
out
.
println
(
id
);
Assert
.
assertNotNull
(
id
);
option
=
new
JSONObject
();
option
.
put
(
Keys
.
OBJECT_ID
,
Option
.
ID_C_BROADCAST_CHANCE_EXPIRATION_TIME
);
option
.
put
(
Option
.
OPTION_CATEGORY
,
Option
.
CATEGORY_C_BROADCAST
);
option
.
put
(
Option
.
OPTION_VALUE
,
1L
);
optionMgmtService
.
addOrUpdateOption
(
option
);
// Update
final
JSONObject
opt
=
getOptionQueryService
().
getOptionById
(
Option
.
ID_C_BROADCAST_CHANCE_EXPIRATION_TIME
);
Assert
.
assertEquals
(
opt
.
getInt
(
Option
.
OPTION_VALUE
),
1L
);
}
/**
* Remove.
*
* @throws Exception exception
*/
@Test
public
void
remove
()
throws
Exception
{
final
OptionMgmtService
optionMgmtService
=
getOptionMgmtService
();
final
JSONObject
option
=
new
JSONObject
();
option
.
put
(
Keys
.
OBJECT_ID
,
Option
.
ID_C_BROADCAST_CHANCE_EXPIRATION_TIME
);
option
.
put
(
Option
.
OPTION_CATEGORY
,
Option
.
CATEGORY_C_BROADCAST
);
option
.
put
(
Option
.
OPTION_VALUE
,
0L
);
final
String
id
=
optionMgmtService
.
addOrUpdateOption
(
option
);
Assert
.
assertNotNull
(
id
);
optionMgmtService
.
removeOption
(
id
);
final
JSONObject
opt
=
getOptionQueryService
().
getOptionById
(
id
);
Assert
.
assertNull
(
opt
);
}
}
core/src/test/java/org/b3log/solo/service/OptionQueryServiceTestCase.java
0 → 100644
View file @
9b05326f
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
b3log
.
solo
.
service
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.util.Requests
;
import
org.b3log.solo.AbstractTestCase
;
import
org.b3log.solo.model.Link
;
import
org.b3log.solo.model.Option
;
import
org.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
/**
* {@link OptionQueryService} test case.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Apr 19, 2013
* @since 0.6.0
*/
@Test
(
suiteName
=
"service"
)
public
class
OptionQueryServiceTestCase
extends
AbstractTestCase
{
/**
* Gets.
*
* @throws Exception exception
*/
@Test
public
void
get
()
throws
Exception
{
// Check
final
OptionQueryService
optionQueryService
=
getOptionQueryService
();
JSONObject
options
=
optionQueryService
.
getOptions
(
Option
.
CATEGORY_C_BROADCAST
);
Assert
.
assertNull
(
options
);
// Add one
final
OptionMgmtService
optionMgmtService
=
getOptionMgmtService
();
final
JSONObject
option
=
new
JSONObject
();
option
.
put
(
Keys
.
OBJECT_ID
,
Option
.
ID_C_BROADCAST_CHANCE_EXPIRATION_TIME
);
option
.
put
(
Option
.
OPTION_CATEGORY
,
Option
.
CATEGORY_C_BROADCAST
);
option
.
put
(
Option
.
OPTION_VALUE
,
0L
);
final
String
id
=
optionMgmtService
.
addOrUpdateOption
(
option
);
Assert
.
assertNotNull
(
id
);
// Check again
options
=
optionQueryService
.
getOptions
(
Option
.
CATEGORY_C_BROADCAST
);
Assert
.
assertNotNull
(
options
);
}
}
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