Commit a27b80d8 authored by Liang Ding's avatar Liang Ding

去除单元测试对 GAE 的依赖

parent 04bb7815
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Description: Solo POM. Description: Solo POM.
Version: 2.9.1.16, Jan 7, 2016 Version: 3.9.1.16, Jan 8, 2016
Author: Liang Ding Author: Liang Ding
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
...@@ -105,7 +105,7 @@ ...@@ -105,7 +105,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.b3log.latke.version>1.4.9</org.b3log.latke.version> <org.b3log.latke.version>1.4.10-SNAPSHOT</org.b3log.latke.version>
<servlet.version>3.1.0</servlet.version> <servlet.version>3.1.0</servlet.version>
<slf4j.version>1.7.5</slf4j.version> <slf4j.version>1.7.5</slf4j.version>
...@@ -125,7 +125,6 @@ ...@@ -125,7 +125,6 @@
<maven-min-plugin.version>1.0.0</maven-min-plugin.version> <maven-min-plugin.version>1.0.0</maven-min-plugin.version>
<!-- Unit Test --> <!-- Unit Test -->
<testng.version>6.1.1</testng.version> <testng.version>6.1.1</testng.version>
<gae.version>1.8.1.1</gae.version>
<!-- JDBC Drivers --> <!-- JDBC Drivers -->
<mysql-connector-java.version>5.1.18</mysql-connector-java.version> <mysql-connector-java.version>5.1.18</mysql-connector-java.version>
</properties> </properties>
...@@ -203,29 +202,6 @@ ...@@ -203,29 +202,6 @@
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version> <version>${commons-cli.version}</version>
</dependency> </dependency>
<!-- BEGIN: GAE related dependencies just for testing -->
<dependency>
<groupId>org.b3log</groupId>
<artifactId>latke-gae</artifactId>
<version>${org.b3log.latke.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
<!-- END: GAE related dependencies just for testing -->
</dependencies> </dependencies>
<build> <build>
......
...@@ -15,10 +15,8 @@ ...@@ -15,10 +15,8 @@
# #
# #
# Description: Solo local environment configurations. Configures this file # Description: Solo local environment configurations.
# if Solo runs on a standard Servlet container or Baidu App Engine, # Version: 1.1.2.8, Jan 8, 2016
# it is unnecessary to care this file if Solo runs on Google App Engine.
# Version: 1.1.2.7, Jan 7, 2016
# Author: Liang Ding # Author: Liang Ding
# #
......
...@@ -15,14 +15,15 @@ ...@@ -15,14 +15,15 @@
*/ */
package org.b3log.solo; package org.b3log.solo;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; import java.sql.Connection;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import java.util.Collection; import java.util.Collection;
import java.util.Locale; import java.util.Locale;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.LatkeBeanManager; import org.b3log.latke.ioc.LatkeBeanManager;
import org.b3log.latke.ioc.Lifecycle; import org.b3log.latke.ioc.Lifecycle;
import org.b3log.latke.ioc.config.Discoverer; import org.b3log.latke.ioc.config.Discoverer;
import org.b3log.latke.repository.jdbc.util.Connections;
import org.b3log.latke.repository.jdbc.util.JdbcRepositories;
import org.b3log.solo.repository.ArchiveDateArticleRepository; import org.b3log.solo.repository.ArchiveDateArticleRepository;
import org.b3log.solo.repository.ArchiveDateRepository; import org.b3log.solo.repository.ArchiveDateRepository;
import org.b3log.solo.repository.ArticleRepository; import org.b3log.solo.repository.ArticleRepository;
...@@ -48,25 +49,18 @@ import org.b3log.solo.repository.impl.TagArticleRepositoryImpl; ...@@ -48,25 +49,18 @@ import org.b3log.solo.repository.impl.TagArticleRepositoryImpl;
import org.b3log.solo.repository.impl.TagRepositoryImpl; import org.b3log.solo.repository.impl.TagRepositoryImpl;
import org.b3log.solo.repository.impl.UserRepositoryImpl; import org.b3log.solo.repository.impl.UserRepositoryImpl;
import org.b3log.solo.service.*; import org.b3log.solo.service.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
/** /**
* Abstract test case. * Abstract test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.9, Dec 13, 2015 * @version 2.0.0.9, Jan 8, 2016
* @see #beforeClass() * @see #beforeClass()
* @see #afterClass() * @see #afterClass()
*/ */
public abstract class AbstractTestCase { public abstract class AbstractTestCase {
/**
* Local service test helper.
*/
private final LocalServiceTestHelper localServiceTestHelper
= new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
/** /**
* Bean manager. * Bean manager.
*/ */
...@@ -76,7 +70,6 @@ public abstract class AbstractTestCase { ...@@ -76,7 +70,6 @@ public abstract class AbstractTestCase {
* Before class. * Before class.
* *
* <ol> * <ol>
* <li>Sets up GAE unit test runtime environment</li>
* <li>Initializes Latke runtime</li> * <li>Initializes Latke runtime</li>
* <li>Instantiates repositories</li> * <li>Instantiates repositories</li>
* </ol> * </ol>
...@@ -85,30 +78,18 @@ public abstract class AbstractTestCase { ...@@ -85,30 +78,18 @@ public abstract class AbstractTestCase {
*/ */
@BeforeClass @BeforeClass
public void beforeClass() throws Exception { public void beforeClass() throws Exception {
localServiceTestHelper.setUp();
Latkes.initRuntimeEnv(); Latkes.initRuntimeEnv();
Latkes.setLocale(Locale.SIMPLIFIED_CHINESE); Latkes.setLocale(Locale.SIMPLIFIED_CHINESE);
final Collection<Class<?>> classes = Discoverer.discover("org.b3log.solo"); final Collection<Class<?>> classes = Discoverer.discover("org.b3log.solo");
Lifecycle.startApplication(classes); Lifecycle.startApplication(classes);
beanManager = Lifecycle.getBeanManager(); beanManager = Lifecycle.getBeanManager();
}
/** final Connection connection = Connections.getConnection();
* After class. connection.createStatement().execute("DROP ALL OBJECTS");
* connection.close();
* <ol> JdbcRepositories.initAllTables();
* <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();
} }
/** /**
......
...@@ -46,7 +46,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase { ...@@ -46,7 +46,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase {
final JSONObject archiveDate = new JSONObject(); final JSONObject archiveDate = new JSONObject();
archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate("2011/12", new String[] {"yyyy/MM"}).getTime()); archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate("2011/12", new String[]{"yyyy/MM"}).getTime());
archiveDate.put(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT, 1); archiveDate.put(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT, 1);
archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 1); archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 1);
...@@ -56,7 +56,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase { ...@@ -56,7 +56,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase {
final List<JSONObject> archiveDates = archiveDateRepository.getArchiveDates(); final List<JSONObject> archiveDates = archiveDateRepository.getArchiveDates();
Assert.assertNotNull(archiveDates); Assert.assertNotNull(archiveDates);
Assert.assertEquals(archiveDates.size(), 1); Assert.assertEquals(1, archiveDates.size());
} }
/** /**
......
...@@ -43,8 +43,7 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase { ...@@ -43,8 +43,7 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
*/ */
@Test @Test
public void add() throws Exception { public void add() throws Exception {
final TagArticleRepository tagArticleRepository = final TagArticleRepository tagArticleRepository = getTagArticleRepository();
getTagArticleRepository();
final JSONObject tagArticle = new JSONObject(); final JSONObject tagArticle = new JSONObject();
...@@ -63,14 +62,14 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase { ...@@ -63,14 +62,14 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
*/ */
@Test(dependsOnMethods = "add") @Test(dependsOnMethods = "add")
public void getByArticleId() throws Exception { public void getByArticleId() throws Exception {
final TagArticleRepository tagArticleRepository = final TagArticleRepository tagArticleRepository
getTagArticleRepository(); = getTagArticleRepository();
final List<JSONObject> tagArticle = final List<JSONObject> tagArticle
tagArticleRepository.getByArticleId("article1 id"); = tagArticleRepository.getByArticleId("article1 id");
Assert.assertNotNull(tagArticle); Assert.assertNotNull(tagArticle);
Assert.assertEquals(tagArticleRepository.getByArticleId("").size(), 0); Assert.assertEquals(0, tagArticleRepository.getByArticleId("").size());
} }
/** /**
...@@ -80,12 +79,12 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase { ...@@ -80,12 +79,12 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
*/ */
@Test(dependsOnMethods = "add") @Test(dependsOnMethods = "add")
public void getByTagId() throws Exception { public void getByTagId() throws Exception {
final TagArticleRepository tagArticleRepository = final TagArticleRepository tagArticleRepository
getTagArticleRepository(); = getTagArticleRepository();
final JSONArray results = final JSONArray results
tagArticleRepository.getByTagId("tag1 id", 1, Integer.MAX_VALUE). = tagArticleRepository.getByTagId("tag1 id", 1, Integer.MAX_VALUE).
getJSONArray(Keys.RESULTS); getJSONArray(Keys.RESULTS);
Assert.assertEquals(results.length(), 1); Assert.assertEquals(1, results.length());
} }
} }
...@@ -69,9 +69,8 @@ public class TagRepositoryImplTestCase extends AbstractTestCase { ...@@ -69,9 +69,8 @@ public class TagRepositoryImplTestCase extends AbstractTestCase {
Assert.assertNotNull(found); Assert.assertNotNull(found);
Assert.assertEquals(found.getString(Tag.TAG_TITLE), "tag title1"); Assert.assertEquals(found.getString(Tag.TAG_TITLE), "tag title1");
Assert.assertEquals(found.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT), Assert.assertEquals(0, found.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT));
0); Assert.assertEquals(1, found.getInt(Tag.TAG_REFERENCE_COUNT));
Assert.assertEquals(found.getInt(Tag.TAG_REFERENCE_COUNT), 1);
final JSONObject notFound = tagRepository.getByTitle(""); final JSONObject notFound = tagRepository.getByTitle("");
Assert.assertNull(notFound); Assert.assertNull(notFound);
...@@ -98,13 +97,12 @@ public class TagRepositoryImplTestCase extends AbstractTestCase { ...@@ -98,13 +97,12 @@ public class TagRepositoryImplTestCase extends AbstractTestCase {
List<JSONObject> mostUsedTags = tagRepository.getMostUsedTags(3); List<JSONObject> mostUsedTags = tagRepository.getMostUsedTags(3);
Assert.assertNotNull(mostUsedTags); Assert.assertNotNull(mostUsedTags);
Assert.assertEquals(mostUsedTags.size(), 2); Assert.assertEquals(2, mostUsedTags.size());
mostUsedTags = tagRepository.getMostUsedTags(1); mostUsedTags = tagRepository.getMostUsedTags(1);
Assert.assertNotNull(mostUsedTags); Assert.assertNotNull(mostUsedTags);
Assert.assertEquals(mostUsedTags.size(), 1); Assert.assertEquals(1, mostUsedTags.size());
Assert.assertEquals(mostUsedTags.get(0).getInt( Assert.assertEquals(3, mostUsedTags.get(0).getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT));
Tag.TAG_PUBLISHED_REFERENCE_COUNT), 3);
} }
/** /**
...@@ -120,16 +118,16 @@ public class TagRepositoryImplTestCase extends AbstractTestCase { ...@@ -120,16 +118,16 @@ public class TagRepositoryImplTestCase extends AbstractTestCase {
List<JSONObject> tags = tagRepository.getByArticleId("article1 id"); List<JSONObject> tags = tagRepository.getByArticleId("article1 id");
Assert.assertNotNull(tags); Assert.assertNotNull(tags);
Assert.assertEquals(tags.size(), 1); Assert.assertEquals(1, tags.size());
tags = tagRepository.getByArticleId("not found"); tags = tagRepository.getByArticleId("not found");
Assert.assertNotNull(tags); Assert.assertNotNull(tags);
Assert.assertEquals(tags.size(), 0); Assert.assertEquals(0, tags.size());
} }
private void addTagArticle() throws Exception { private void addTagArticle() throws Exception {
final TagArticleRepository tagArticleRepository = final TagArticleRepository tagArticleRepository
getTagArticleRepository(); = getTagArticleRepository();
final JSONObject tagArticle = new JSONObject(); final JSONObject tagArticle = new JSONObject();
......
...@@ -90,7 +90,7 @@ public class UserQueryServiceTestCase extends AbstractTestCase { ...@@ -90,7 +90,7 @@ public class UserQueryServiceTestCase extends AbstractTestCase {
final JSONObject paginationRequest = Requests.buildPaginationRequest("1/20/10"); final JSONObject paginationRequest = Requests.buildPaginationRequest("1/20/10");
final JSONObject result = userQueryService.getUsers(paginationRequest); final JSONObject result = userQueryService.getUsers(paginationRequest);
final JSONArray users = result.getJSONArray(User.USERS); final JSONArray users = result.getJSONArray(User.USERS);
Assert.assertEquals(users.length(), 1); Assert.assertEquals(1, users.length());
} }
/** /**
......
...@@ -65,13 +65,13 @@ public final class MarkdownsTestCase { ...@@ -65,13 +65,13 @@ public final class MarkdownsTestCase {
} }
markdownText = markdownTextBuilder.toString(); markdownText = markdownTextBuilder.toString();
System.out.println(markdownText); //System.out.println(markdownText);
Stopwatchs.start("Markdowning"); Stopwatchs.start("Markdowning");
html = Markdowns.toHTML(markdownText); html = Markdowns.toHTML(markdownText);
Stopwatchs.end(); Stopwatchs.end();
System.out.println(html); //System.out.println(html);
System.out.println("Stopwatch: "); System.out.println("Stopwatch: ");
System.out.println(Stopwatchs.getTimingStat()); System.out.println(Stopwatchs.getTimingStat());
......
...@@ -15,41 +15,11 @@ ...@@ -15,41 +15,11 @@
# #
# #
# Description: B3log Latke configurations for test (GAE runtime). # Description: Latke configurations for test.
# Version: 1.0.0.2, Apr 1, 2013 # Version: 2.0.0.2, Jan 8, 2016
# Author: Liang Ding # Author: Liang Ding
# #
#### Server ####
# Configures the followings before deploy
serverScheme=http serverScheme=http
serverHost=localhost serverHost=localhost
serverPort=8080 serverPort=8080
staticServerScheme=http
staticServerHost=localhost
staticServerPort=8080
# Note: The context path and static path should be "" if deploy app on ROOT. For other cases, starts with '/'
# and not ends with '/', for example, /blog
contextPath=
staticPath=
#### Runtime Environment ####
#runtimeEnv=LOCAL
runtimeEnv=GAE
#### Runtime Mode ####
runtimeMode=DEVELOPMENT
#runtimeMode=PRODUCTION
#### Cache Implementation ####
# Note: If the runtime environment is LOCAL, the cache will be LOCAL always
#cache=LOCAL
cache=GAE
#### User Service Implementation ####
# userService=GAE
userService=LOCAL
#### Static resource version ####
staticResourceVersion=201206280945
...@@ -14,4 +14,28 @@ ...@@ -14,4 +14,28 @@
# limitations under the License. # limitations under the License.
# #
DO NOT REMOVE THIS FILE! #### H2 runtime ####
\ No newline at end of file runtimeDatabase=H2
jdbc.username=root
jdbc.password=
jdbc.driver=org.h2.Driver
jdbc.URL=jdbc:h2:./target/solo_h2_test/db
jdbc.pool=h2
#### MySQL runtime ####
#runtimeDatabase=MYSQL
#jdbc.username=root
#jdbc.password=
#jdbc.driver=com.mysql.jdbc.Driver
#jdbc.URL=jdbc:mysql://localhost:3306/b3log?useUnicode=yes&characterEncoding=utf8
#jdbc.pool=druid
# The minConnCnt MUST larger or equal to 3
jdbc.minConnCnt=5
jdbc.maxConnCnt=10
# Be care to change the transaction isolation
jdbc.transactionIsolation=REPEATABLE_READ
# The specific table name prefix
jdbc.tablePrefix=b3_solo
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment