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
Expand all
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 {
...
@@ -47,24 +47,36 @@ public final class OptionMgmtService {
private
OptionRepository
optionRepository
=
OptionRepositoryImpl
.
getInstance
();
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
* @param option the specified option
* @throws ServiceException service exception
* @return option id
* @throws ServiceException
*/
*/
public
void
updateOption
(
final
JSONObject
option
)
throws
ServiceException
{
public
String
addOrUpdateOption
(
final
JSONObject
option
)
throws
ServiceException
{
final
String
id
=
option
.
optString
(
Keys
.
OBJECT_ID
);
final
Transaction
transaction
=
optionRepository
.
beginTransaction
();
final
Transaction
transaction
=
optionRepository
.
beginTransaction
();
try
{
try
{
if
(
null
!=
optionRepository
.
get
(
id
))
{
String
id
=
option
.
optString
(
Keys
.
OBJECT_ID
);
optionRepository
.
update
(
id
,
option
);
if
(
Strings
.
isEmptyOrNull
(
id
))
{
id
=
optionRepository
.
add
(
option
);
}
else
{
}
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
();
transaction
.
commit
();
return
id
;
}
catch
(
final
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
if
(
transaction
.
isActive
())
{
if
(
transaction
.
isActive
())
{
transaction
.
rollback
();
transaction
.
rollback
();
...
@@ -73,34 +85,19 @@ public final class OptionMgmtService {
...
@@ -73,34 +85,19 @@ public final class OptionMgmtService {
throw
new
ServiceException
(
e
);
throw
new
ServiceException
(
e
);
}
}
}
}
/**
/**
*
Adds or updates the specified option.
*
Removes the option specified by the given option id.
*
*
* @param option
the specified option
* @param option
Id the given option id
* @throws ServiceException
* @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
();
final
Transaction
transaction
=
optionRepository
.
beginTransaction
();
try
{
try
{
final
String
id
=
option
.
optString
(
Keys
.
OBJECT_ID
);
optionRepository
.
remove
(
optionId
);
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
);
}
}
transaction
.
commit
();
transaction
.
commit
();
}
catch
(
final
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
if
(
transaction
.
isActive
())
{
if
(
transaction
.
isActive
())
{
...
...
core/src/test/java/org/b3log/solo/AbstractTestCase.java
View file @
9b05326f
This diff is collapsed.
Click to expand it.
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