Commit a27b80d8 authored by Liang Ding's avatar Liang Ding

去除单元测试对 GAE 的依赖

parent 04bb7815
<?xml version="1.0" encoding="UTF-8"?>
<!--
Description: Solo POM.
Version: 2.9.1.16, Jan 7, 2016
Version: 3.9.1.16, Jan 8, 2016
Author: Liang Ding
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
......@@ -105,7 +105,7 @@
<properties>
<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>
<slf4j.version>1.7.5</slf4j.version>
......@@ -125,7 +125,6 @@
<maven-min-plugin.version>1.0.0</maven-min-plugin.version>
<!-- Unit Test -->
<testng.version>6.1.1</testng.version>
<gae.version>1.8.1.1</gae.version>
<!-- JDBC Drivers -->
<mysql-connector-java.version>5.1.18</mysql-connector-java.version>
</properties>
......@@ -203,29 +202,6 @@
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</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>
<build>
......
......@@ -15,10 +15,8 @@
#
#
# Description: Solo local environment configurations. Configures this file
# if Solo runs on a standard Servlet container or Baidu App Engine,
# it is unnecessary to care this file if Solo runs on Google App Engine.
# Version: 1.1.2.7, Jan 7, 2016
# Description: Solo local environment configurations.
# Version: 1.1.2.8, Jan 8, 2016
# Author: Liang Ding
#
......
......@@ -15,14 +15,15 @@
*/
package org.b3log.solo;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import java.sql.Connection;
import java.util.Collection;
import java.util.Locale;
import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.LatkeBeanManager;
import org.b3log.latke.ioc.Lifecycle;
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.ArchiveDateRepository;
import org.b3log.solo.repository.ArticleRepository;
......@@ -48,25 +49,18 @@ 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="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 #afterClass()
*/
public abstract class AbstractTestCase {
/**
* Local service test helper.
*/
private final LocalServiceTestHelper localServiceTestHelper
= new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
/**
* Bean manager.
*/
......@@ -76,7 +70,6 @@ public abstract class AbstractTestCase {
* Before class.
*
* <ol>
* <li>Sets up GAE unit test runtime environment</li>
* <li>Initializes Latke runtime</li>
* <li>Instantiates repositories</li>
* </ol>
......@@ -85,30 +78,18 @@ public abstract class AbstractTestCase {
*/
@BeforeClass
public void beforeClass() throws Exception {
localServiceTestHelper.setUp();
Latkes.initRuntimeEnv();
Latkes.setLocale(Locale.SIMPLIFIED_CHINESE);
final Collection<Class<?>> classes = Discoverer.discover("org.b3log.solo");
Lifecycle.startApplication(classes);
beanManager = Lifecycle.getBeanManager();
}
/**
* 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();
final Connection connection = Connections.getConnection();
connection.createStatement().execute("DROP ALL OBJECTS");
connection.close();
JdbcRepositories.initAllTables();
Latkes.shutdown();
}
/**
......
......@@ -46,7 +46,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase {
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_PUBLISHED_ARTICLE_COUNT, 1);
......@@ -56,7 +56,7 @@ public class ArchiveDateRepositoryImplTestCase extends AbstractTestCase {
final List<JSONObject> archiveDates = archiveDateRepository.getArchiveDates();
Assert.assertNotNull(archiveDates);
Assert.assertEquals(archiveDates.size(), 1);
Assert.assertEquals(1, archiveDates.size());
}
/**
......
......@@ -43,8 +43,7 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
*/
@Test
public void add() throws Exception {
final TagArticleRepository tagArticleRepository =
getTagArticleRepository();
final TagArticleRepository tagArticleRepository = getTagArticleRepository();
final JSONObject tagArticle = new JSONObject();
......@@ -63,14 +62,14 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
*/
@Test(dependsOnMethods = "add")
public void getByArticleId() throws Exception {
final TagArticleRepository tagArticleRepository =
getTagArticleRepository();
final TagArticleRepository tagArticleRepository
= getTagArticleRepository();
final List<JSONObject> tagArticle =
tagArticleRepository.getByArticleId("article1 id");
final List<JSONObject> tagArticle
= tagArticleRepository.getByArticleId("article1 id");
Assert.assertNotNull(tagArticle);
Assert.assertEquals(tagArticleRepository.getByArticleId("").size(), 0);
Assert.assertEquals(0, tagArticleRepository.getByArticleId("").size());
}
/**
......@@ -80,12 +79,12 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
*/
@Test(dependsOnMethods = "add")
public void getByTagId() throws Exception {
final TagArticleRepository tagArticleRepository =
getTagArticleRepository();
final TagArticleRepository tagArticleRepository
= getTagArticleRepository();
final JSONArray results =
tagArticleRepository.getByTagId("tag1 id", 1, Integer.MAX_VALUE).
final JSONArray results
= tagArticleRepository.getByTagId("tag1 id", 1, Integer.MAX_VALUE).
getJSONArray(Keys.RESULTS);
Assert.assertEquals(results.length(), 1);
Assert.assertEquals(1, results.length());
}
}
......@@ -69,9 +69,8 @@ public class TagRepositoryImplTestCase extends AbstractTestCase {
Assert.assertNotNull(found);
Assert.assertEquals(found.getString(Tag.TAG_TITLE), "tag title1");
Assert.assertEquals(found.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT),
0);
Assert.assertEquals(found.getInt(Tag.TAG_REFERENCE_COUNT), 1);
Assert.assertEquals(0, found.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT));
Assert.assertEquals(1, found.getInt(Tag.TAG_REFERENCE_COUNT));
final JSONObject notFound = tagRepository.getByTitle("");
Assert.assertNull(notFound);
......@@ -98,13 +97,12 @@ public class TagRepositoryImplTestCase extends AbstractTestCase {
List<JSONObject> mostUsedTags = tagRepository.getMostUsedTags(3);
Assert.assertNotNull(mostUsedTags);
Assert.assertEquals(mostUsedTags.size(), 2);
Assert.assertEquals(2, mostUsedTags.size());
mostUsedTags = tagRepository.getMostUsedTags(1);
Assert.assertNotNull(mostUsedTags);
Assert.assertEquals(mostUsedTags.size(), 1);
Assert.assertEquals(mostUsedTags.get(0).getInt(
Tag.TAG_PUBLISHED_REFERENCE_COUNT), 3);
Assert.assertEquals(1, mostUsedTags.size());
Assert.assertEquals(3, mostUsedTags.get(0).getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT));
}
/**
......@@ -120,16 +118,16 @@ public class TagRepositoryImplTestCase extends AbstractTestCase {
List<JSONObject> tags = tagRepository.getByArticleId("article1 id");
Assert.assertNotNull(tags);
Assert.assertEquals(tags.size(), 1);
Assert.assertEquals(1, tags.size());
tags = tagRepository.getByArticleId("not found");
Assert.assertNotNull(tags);
Assert.assertEquals(tags.size(), 0);
Assert.assertEquals(0, tags.size());
}
private void addTagArticle() throws Exception {
final TagArticleRepository tagArticleRepository =
getTagArticleRepository();
final TagArticleRepository tagArticleRepository
= getTagArticleRepository();
final JSONObject tagArticle = new JSONObject();
......
......@@ -90,7 +90,7 @@ public class UserQueryServiceTestCase extends AbstractTestCase {
final JSONObject paginationRequest = Requests.buildPaginationRequest("1/20/10");
final JSONObject result = userQueryService.getUsers(paginationRequest);
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 {
}
markdownText = markdownTextBuilder.toString();
System.out.println(markdownText);
//System.out.println(markdownText);
Stopwatchs.start("Markdowning");
html = Markdowns.toHTML(markdownText);
Stopwatchs.end();
System.out.println(html);
//System.out.println(html);
System.out.println("Stopwatch: ");
System.out.println(Stopwatchs.getTimingStat());
......
......@@ -15,41 +15,11 @@
#
#
# Description: B3log Latke configurations for test (GAE runtime).
# Version: 1.0.0.2, Apr 1, 2013
# Description: Latke configurations for test.
# Version: 2.0.0.2, Jan 8, 2016
# Author: Liang Ding
#
#### Server ####
# Configures the followings before deploy
serverScheme=http
serverHost=localhost
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 @@
# limitations under the License.
#
DO NOT REMOVE THIS FILE!
\ No newline at end of file
#### H2 runtime ####
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