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
2b84f8f1
Commit
2b84f8f1
authored
Apr 12, 2017
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
#12256 持久层单元测试
parent
6e34cc5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
1 deletion
+119
-1
src/test/java/org/b3log/solo/AbstractTestCase.java
src/test/java/org/b3log/solo/AbstractTestCase.java
+20
-1
src/test/java/org/b3log/solo/repository/impl/CategoryRepositoryImplTestCase.java
.../solo/repository/impl/CategoryRepositoryImplTestCase.java
+99
-0
No files found.
src/test/java/org/b3log/solo/AbstractTestCase.java
View file @
2b84f8f1
...
...
@@ -35,7 +35,7 @@ import java.util.Locale;
* Abstract test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.
1.0.9, Mar 28
, 2017
* @version 2.
2.0.9, Apr 12
, 2017
* @see #beforeClass()
*/
public
abstract
class
AbstractTestCase
{
...
...
@@ -52,6 +52,7 @@ public abstract class AbstractTestCase {
* <li>Initializes Latke runtime</li>
* <li>Instantiates repositories</li>
* </ol>
* </p>
*
* @throws Exception exception
*/
...
...
@@ -197,6 +198,24 @@ public abstract class AbstractTestCase {
return
beanManager
.
getReference
(
OptionRepositoryImpl
.
class
);
}
/**
* Gets category query service.
*
* @return category query service
*/
public
CategoryQueryService
getCategoryQueryService
()
{
return
beanManager
.
getReference
(
CategoryQueryService
.
class
);
}
/**
* Gets category management service.
*
* @return category management service
*/
public
CategoryMgmtService
getCategoryMgmtService
()
{
return
beanManager
.
getReference
(
CategoryMgmtService
.
class
);
}
/**
* Gets initialization service.
*
...
...
src/test/java/org/b3log/solo/repository/impl/CategoryRepositoryImplTestCase.java
0 → 100644
View file @
2b84f8f1
/*
* Copyright (c) 2010-2017, b3log.org & hacpai.com
*
* 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.repository.Transaction
;
import
org.b3log.solo.AbstractTestCase
;
import
org.b3log.solo.model.Category
;
import
org.b3log.solo.repository.CategoryRepository
;
import
org.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
/**
* {@link CategoryRepositoryImpl} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Apr 12, 2017
* @since 2.0.0
*/
@Test
(
suiteName
=
"repository"
)
public
final
class
CategoryRepositoryImplTestCase
extends
AbstractTestCase
{
/**
* Tests.
*
* @throws Exception exception
*/
@Test
public
void
test
()
throws
Exception
{
final
CategoryRepository
categoryRepository
=
getCategoryRepository
();
final
int
category1Order
=
1
,
category2Order
=
2
,
category3Order
=
3
;
JSONObject
category1
=
new
JSONObject
();
category1
.
put
(
Category
.
CATEGORY_TITLE
,
"category title"
);
category1
.
put
(
Category
.
CATEGORY_DESCRIPTION
,
"cateogry description"
);
category1
.
put
(
Category
.
CATEGORY_URI
,
"category uri"
);
category1
.
put
(
Category
.
CATEGORY_ORDER
,
category1Order
);
category1
.
put
(
Category
.
CATEGORY_TAG_CNT
,
0
);
Transaction
transaction
=
categoryRepository
.
beginTransaction
();
categoryRepository
.
add
(
category1
);
transaction
.
commit
();
Assert
.
assertNull
(
categoryRepository
.
getByTitle
(
"title"
));
Assert
.
assertNotNull
(
categoryRepository
.
getByTitle
(
"category title"
));
Assert
.
assertNull
(
categoryRepository
.
getByOrder
(
0
));
Assert
.
assertNotNull
(
categoryRepository
.
getByOrder
(
category1Order
));
final
JSONObject
category2
=
new
JSONObject
();
category2
.
put
(
Category
.
CATEGORY_TITLE
,
"category title"
);
category2
.
put
(
Category
.
CATEGORY_DESCRIPTION
,
"cateogry description"
);
category2
.
put
(
Category
.
CATEGORY_URI
,
"category uri"
);
category2
.
put
(
Category
.
CATEGORY_ORDER
,
category2Order
);
category2
.
put
(
Category
.
CATEGORY_TAG_CNT
,
0
);
transaction
=
categoryRepository
.
beginTransaction
();
final
String
category2Id
=
categoryRepository
.
add
(
category2
);
transaction
.
commit
();
Assert
.
assertEquals
(
categoryRepository
.
getMaxOrder
(),
category2Order
);
JSONObject
category3
=
new
JSONObject
();
category3
.
put
(
Category
.
CATEGORY_TITLE
,
"category title"
);
category3
.
put
(
Category
.
CATEGORY_DESCRIPTION
,
"cateogry description"
);
category3
.
put
(
Category
.
CATEGORY_URI
,
"category uri"
);
category3
.
put
(
Category
.
CATEGORY_ORDER
,
category3Order
);
category3
.
put
(
Category
.
CATEGORY_TAG_CNT
,
0
);
transaction
=
categoryRepository
.
beginTransaction
();
categoryRepository
.
add
(
category3
);
transaction
.
commit
();
final
int
total
=
3
;
Assert
.
assertEquals
(
categoryRepository
.
count
(),
total
);
category1
=
categoryRepository
.
getUpper
(
category2Id
);
Assert
.
assertNotNull
(
category1
);
Assert
.
assertEquals
(
category1
.
getInt
(
Category
.
CATEGORY_ORDER
),
category1Order
);
category3
=
categoryRepository
.
getUnder
(
category2Id
);
Assert
.
assertNotNull
(
category3
);
Assert
.
assertEquals
(
category3
.
getInt
(
Category
.
CATEGORY_ORDER
),
category3Order
);
}
}
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