重新配置集成测试 #9

Merged
xiaohai2271 merged 10 commits from feature-test into master 2020-08-15 02:39:46 +08:00
18 changed files with 554 additions and 220 deletions

View File

@@ -13,8 +13,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
APPLICATION_PROPERTIES_TEST: ${{ secrets.APPLICATION_PROPERTIES_TEST }} KEY: ${{ secrets.WEB_HOOK_ACCESS_KEY }}
APPLICATION_PROPERTIES_PROD: ${{ secrets.APPLICATION_PROPERTIES_PROD }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@@ -23,25 +22,5 @@ jobs:
with: with:
java-version: 1.8 java-version: 1.8
- name: Build jar file - name: Deploy
run: echo $APPLICATION_PROPERTIES_PROD|base64 -d> src/main/resources/application-prod.properties && mvn -B package -DskipTests --file pom.xml run: mvn -B test --file pom.xml && curl http://106.15.205.190:2271/hook?access_key=$KEY
- name: SCP
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
source: "target/blog-0.0.1-SNAPSHOT.jar"
target: "/www/wwwroot/api.celess.cn"
- name: Run SSH command
uses: garygrossgarten/github-action-ssh@v0.5.0
with:
command: cd /www/wwwroot/api.celess.cn && bash build.sh
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}

View File

@@ -12,9 +12,9 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: # env:
APPLICATION_PROPERTIES_TEST: ${{ secrets.APPLICATION_PROPERTIES_TEST }} # APPLICATION_PROPERTIES_TEST: ${{ secrets.APPLICATION_PROPERTIES_TEST }}
APPLICATION_PROPERTIES_PROD: ${{ secrets.APPLICATION_PROPERTIES_PROD }} # APPLICATION_PROPERTIES_PROD: ${{ secrets.APPLICATION_PROPERTIES_PROD }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@@ -24,6 +24,6 @@ jobs:
java-version: 1.8 java-version: 1.8
- name: Test - name: Test
run: echo $APPLICATION_PROPERTIES_TEST|base64 -d > src/main/resources/application-test.properties && mvn -B test --file pom.xml run: mvn -B test --file pom.xml

2
.gitignore vendored
View File

@@ -4,7 +4,5 @@
target/ target/
# 本地项目的私有文件 # 本地项目的私有文件
back-end/blog-dev.sql
src/main/resources/application-dev.properties src/main/resources/application-dev.properties
src/main/resources/application-prod.properties src/main/resources/application-prod.properties
src/main/resources/application-test.properties

View File

@@ -1,11 +1,11 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2007-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import java.net.*; import java.net.*;
import java.io.*; import java.io.*;
import java.nio.channels.*; import java.nio.channels.*;
@@ -21,7 +20,7 @@ import java.util.Properties;
public class MavenWrapperDownloader { public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.5"; private static final String WRAPPER_VERSION = "0.5.6";
/** /**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/ */

Binary file not shown.

View File

@@ -1,2 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

98
mvnw vendored
View File

@@ -8,7 +8,7 @@
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# https://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
@@ -19,7 +19,7 @@
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Maven2 Start Up Batch script # Maven Start Up Batch script
# #
# Required ENV vars: # Required ENV vars:
# ------------------ # ------------------
@@ -47,19 +47,18 @@ if [ -z "$MAVEN_SKIP_RC" ]; then
fi fi
# OS specific support. $var _must_ be set to either true or false. # OS specific support. $var _must_ be set to either true or false.
cygwin=false cygwin=false;
darwin=false darwin=false;
mingw=false mingw=false
case "$(uname)" in case "`uname`" in
CYGWIN*) cygwin=true ;; CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;; MINGW*) mingw=true;;
Darwin*) Darwin*) darwin=true
darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="$(/usr/libexec/java_home)" export JAVA_HOME="`/usr/libexec/java_home`"
else else
export JAVA_HOME="/Library/Java/Home" export JAVA_HOME="/Library/Java/Home"
fi fi
@@ -69,7 +68,7 @@ esac
if [ -z "$JAVA_HOME" ] ; then if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=$(java-config --jre-home) JAVA_HOME=`java-config --jre-home`
fi fi
fi fi
@@ -79,21 +78,21 @@ if [ -z "$M2_HOME" ]; then
# need this for relative symlinks # need this for relative symlinks
while [ -h "$PRG" ] ; do while [ -h "$PRG" ] ; do
ls=$(ls -ld "$PRG") ls=`ls -ld "$PRG"`
link=$(expr "$ls" : '.*-> \(.*\)$') link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then if expr "$link" : '/.*' > /dev/null; then
PRG="$link" PRG="$link"
else else
PRG="$(dirname "$PRG")/$link" PRG="`dirname "$PRG"`/$link"
fi fi
done done
saveddir=$(pwd) saveddir=`pwd`
M2_HOME=$(dirname "$PRG")/.. M2_HOME=`dirname "$PRG"`/..
# make it fully qualified # make it fully qualified
M2_HOME=$(cd "$M2_HOME" && pwd) M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir" cd "$saveddir"
# echo Using m2 at $M2_HOME # echo Using m2 at $M2_HOME
@@ -102,41 +101,35 @@ fi
# For Cygwin, ensure paths are in UNIX format before anything is touched # For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then if $cygwin ; then
[ -n "$M2_HOME" ] && [ -n "$M2_HOME" ] &&
M2_HOME=$(cygpath --unix "$M2_HOME") M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] && [ -n "$JAVA_HOME" ] &&
JAVA_HOME=$(cygpath --unix "$JAVA_HOME") JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] && [ -n "$CLASSPATH" ] &&
CLASSPATH=$(cygpath --path --unix "$CLASSPATH") CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi fi
# For Mingw, ensure paths are in UNIX format before anything is touched # For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then if $mingw ; then
[ -n "$M2_HOME" ] && [ -n "$M2_HOME" ] &&
M2_HOME="$( ( M2_HOME="`(cd "$M2_HOME"; pwd)`"
cd "$M2_HOME"
pwd
))"
[ -n "$JAVA_HOME" ] && [ -n "$JAVA_HOME" ] &&
JAVA_HOME="$( ( JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
cd "$JAVA_HOME"
pwd
))"
fi fi
if [ -z "$JAVA_HOME" ]; then if [ -z "$JAVA_HOME" ]; then
javaExecutable="$(which javac)" javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10. # readlink(1) is not available as standard on Solaris 10.
readLink=$(which readlink) readLink=`which readlink`
if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then if $darwin ; then
javaHome="$(dirname \"$javaExecutable\")" javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else else
javaExecutable="$(readlink -f \"$javaExecutable\")" javaExecutable="`readlink -f \"$javaExecutable\"`"
fi fi
javaHome="$(dirname \"$javaExecutable\")" javaHome="`dirname \"$javaExecutable\"`"
javaHome=$(expr "$javaHome" : '\(.*\)/bin') javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome" JAVA_HOME="$javaHome"
export JAVA_HOME export JAVA_HOME
fi fi
@@ -152,7 +145,7 @@ if [ -z "$JAVACMD" ]; then
JAVACMD="$JAVA_HOME/bin/java" JAVACMD="$JAVA_HOME/bin/java"
fi fi
else else
JAVACMD="$(which java)" JAVACMD="`which java`"
fi fi
fi fi
@@ -172,7 +165,8 @@ CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# first directory with .mvn subdirectory is considered project base directory # first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() { find_maven_basedir() {
if [ -z "$1" ]; then if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir" echo "Path not specified to find_maven_basedir"
return 1 return 1
fi fi
@@ -186,10 +180,7 @@ find_maven_basedir() {
fi fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc) # workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then if [ -d "${wdir}" ]; then
wdir=$( wdir=`cd "$wdir/.."; pwd`
cd "$wdir/.."
pwd
)
fi fi
# end of workaround # end of workaround
done done
@@ -203,9 +194,9 @@ concat_lines() {
fi fi
} }
BASE_DIR=$(find_maven_basedir "$(pwd)") BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then if [ -z "$BASE_DIR" ]; then
exit 1 exit 1;
fi fi
########################################################################################## ##########################################################################################
@@ -221,15 +212,12 @@ else
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi fi
if [ -n "$MVNW_REPOURL" ]; then if [ -n "$MVNW_REPOURL" ]; then
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
else else
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
fi fi
while IFS="=" read key value; do while IFS="=" read key value; do
case "$key" in wrapperUrl) case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
jarUrl="$value"
break
;;
esac esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then if [ "$MVNW_VERBOSE" = true ]; then
@@ -237,7 +225,7 @@ else
fi fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if $cygwin; then if $cygwin; then
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
fi fi
if command -v wget > /dev/null; then if command -v wget > /dev/null; then
@@ -266,7 +254,7 @@ else
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
# For Cygwin, switch paths to Windows format before running javac # For Cygwin, switch paths to Windows format before running javac
if $cygwin; then if $cygwin; then
javaClass=$(cygpath --path --windows "$javaClass") javaClass=`cygpath --path --windows "$javaClass"`
fi fi
if [ -e "$javaClass" ]; then if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
@@ -299,13 +287,13 @@ MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java # For Cygwin, switch paths to Windows format before running java
if $cygwin; then if $cygwin; then
[ -n "$M2_HOME" ] && [ -n "$M2_HOME" ] &&
M2_HOME=$(cygpath --path --windows "$M2_HOME") M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] && [ -n "$JAVA_HOME" ] &&
JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] && [ -n "$CLASSPATH" ] &&
CLASSPATH=$(cygpath --path --windows "$CLASSPATH") CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] && [ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi fi
# Provide a "standardized" way to retrieve the CLI args that will # Provide a "standardized" way to retrieve the CLI args that will

8
mvnw.cmd vendored
View File

@@ -7,7 +7,7 @@
@REM "License"); you may not use this file except in compliance @REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at @REM with the License. You may obtain a copy of the License at
@REM @REM
@REM https://www.apache.org/licenses/LICENSE-2.0 @REM http://www.apache.org/licenses/LICENSE-2.0
@REM @REM
@REM Unless required by applicable law or agreed to in writing, @REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an @REM software distributed under the License is distributed on an
@@ -18,7 +18,7 @@
@REM ---------------------------------------------------------------------------- @REM ----------------------------------------------------------------------------
@REM ---------------------------------------------------------------------------- @REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script @REM Maven Start Up Batch script
@REM @REM
@REM Required ENV vars: @REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir @REM JAVA_HOME - location of a JDK home dir
@@ -120,7 +120,7 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
@@ -134,7 +134,7 @@ if exist %WRAPPER_JAR% (
) )
) else ( ) else (
if not "%MVNW_REPOURL%" == "" ( if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
) )
if "%MVNW_VERBOSE%" == "true" ( if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ... echo Couldn't find %WRAPPER_JAR%, downloading it ...

12
pom.xml
View File

@@ -170,6 +170,18 @@
</dependency> </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>
<dependency>
<groupId>com.github.kstyrc</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.6</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

View File

@@ -26,7 +26,7 @@ public class DruidConfig {
@Bean @Bean
public DruidDataSource druidDataSource() { public DruidDataSource druidDataSource() {
DruidDataSource dataSource = new DruidDataSource(); DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setDriverClassName(driverClassName);
// 数据库基本信息 // 数据库基本信息
dataSource.setUrl(dbUrl); dataSource.setUrl(dbUrl);
dataSource.setUsername(username); dataSource.setUsername(username);

View File

@@ -0,0 +1,96 @@
server.port=8081
# 七牛的密钥配置
qiniu.accessKey=
qiniu.secretKey=
qiniu.bucket=
# sitemap 存放地址
sitemap.path=
# 生成JWT时候的密钥
jwt.secret=sdaniod213k123123ipoeqowekqwe
##spring.jpa.show-sql=false
##spring.jpa.hibernate.ddl-auto=update
mybatis.type-handlers-package=cn.celess.blog.mapper.typehandler
logging.level.cn.celess.blog.mapper=debug
# 上传单个文件的大小
spring.servlet.multipart.max-file-size=10MB
# 上传文件的总大小
spring.servlet.multipart.max-request-size=10MB
spring.jackson.default-property-inclusion=non_null
################# 数据库 ##################
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#h2
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb;mode=mysql;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.platform=h2
spring.datasource.sql-script-encoding=utf-8
spring.datasource.initialization-mode=ALWAYS
spring.datasource.schema=classpath:sql/schema_h2.sql
spring.datasource.data=classpath:sql/data.sql
################## mybatis ##################
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=cn.celess.blog.entity
pagehelper.helper-dialect=mysql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql
#### 用于nginx的代理 获取真实ip
server.use-forward-headers = true
server.tomcat.remote-ip-header = X-Real-IP
server.tomcat.protocol-header = X-Forwarded-Proto
############### email ##############
spring.mail.host=smtp.163.com
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.default-encoding=UTF-8
spring.mail.port=465
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback=false
############### redis ##############
# REDIS (RedisProperties)
# Redis数据库索引默认为0
spring.redis.database=1
# Redis服务器地址
spring.redis.host=127.0.0.1
# Redis服务器连接端口 解决端口冲突 防止使用本地的redis
spring.redis.port=6380
# Redis服务器连接密码默认为空
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=-1
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=5000

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,193 @@
drop view if exists articleView;
drop view if exists commentView;
drop table if exists article_tag;
drop table if exists comment;
drop table if exists article;
drop table if exists user;
drop table if exists tag_category;
drop table if exists links;
drop table if exists visitor;
drop table if exists web_update;
-- 用户表
CREATE TABLE `user`
(
`u_id` int not null primary key auto_increment,
`u_email` varchar(50) not null,
`u_pwd` varchar(40) not null comment '密码',
`u_email_status` boolean default false comment '邮箱验证状态',
`u_avatar` varchar(255) default null comment '用户头像',
`u_desc` tinytext default null comment '用户的描述',
`u_recently_landed_time` datetime default null comment '最近的登录时间',
`u_display_name` varchar(30) default null comment '展示的昵称',
`u_role` varchar(40) not null default 'user' comment '权限组',
`status` tinyint(1) not null default 0 comment '账户状态',
unique key `uni_user_id` (`u_id`),
unique key `uni_user_email` (`u_email`)
);
-- 标签和分类表
CREATE TABLE `tag_category`
(
`t_id` bigint(20) primary key auto_increment,
`t_name` varchar(255) not null,
`is_category` boolean not null default true,
`is_delete` boolean not null default false comment '该数据是否被删除'
);
-- 文章表
CREATE TABLE `article`
(
`a_id` bigint(20) primary key auto_increment,
`a_title` varchar(255) not null unique comment '文章标题',
`a_summary` varchar(255) not null comment '文章摘要',
`a_md_content` longtext not null comment '文章Markdown内容',
`a_url` tinytext default null comment '转载文章的原文链接',
`a_author_id` int not null comment '作者id',
`a_is_original` boolean default true comment '文章是否原创',
`a_reading_number` int default 0 comment '文章阅读数',
`a_like` int default 0 comment '文章点赞数',
`a_dislike` int default 0 comment '文章不喜欢数',
`a_category_id` bigint not null comment '文章分类id',
`a_publish_date` datetime default CURRENT_TIMESTAMP comment '文章发布时间',
`a_update_date` datetime default null comment '文章的更新时间',
`a_is_open` boolean default true comment '文章是否可见',
`is_delete` boolean not null default false comment '该数据是否被删除',
foreign key (a_category_id) references tag_category (t_id),
foreign key (a_author_id) references user (u_id)
);
-- 文章标签表
CREATE TABLE `article_tag`
(
`at_id` bigint(20) primary key auto_increment,
`a_id` bigint(20) not null comment '文章id',
`t_id` bigint not null comment 'tag/category 的id',
foreign key (a_id) references article (a_id),
foreign key (t_id) references tag_category (t_id)
);
-- 评论/留言表
CREATE TABLE `comment`
(
`co_id` bigint(20) primary key auto_increment,
`co_page_path` varchar(255) not null comment '评论/留言的页面',
`co_content` text not null comment '评论/留言内容',
`co_date` datetime not null comment '评论/留言的日期',
`co_status` tinyint not null default 0 comment '评论的状态',
`co_pid` bigint not null default -1 comment '评论/留言的父id',
`co_from_author_id` int not null comment '留言者id',
`co_to_author_id` int default null comment '父评论的作者id',
foreign key (co_from_author_id) references user (u_id),
foreign key (co_to_author_id) references user (u_id)
);
-- 友站表
CREATE TABLE `links`
(
`l_id` bigint(20) primary key auto_increment,
`l_name` varchar(255) not null comment '友站名称',
`l_is_open` boolean default true comment '是否公开',
`l_url` varchar(255) unique not null comment '首页地址',
`l_icon_path` varchar(255) not null comment '友链的icon地址',
`l_desc` varchar(255) not null comment '友链的说明描述',
`is_delete` boolean not null default false comment '该数据是否被删除',
`l_email` varchar(255) comment '网站管理员的邮箱',
`l_notification` boolean default false comment '是否通知了'
);
-- 访客表
CREATE TABLE `visitor`
(
`v_id` bigint(20) primary key auto_increment,
`v_date` datetime not null comment '访问时间',
`v_ip` varchar(255) not null comment '访客ip',
`v_user_agent` text comment '访客ua',
`is_delete` boolean not null default false comment '该数据是否被删除'
);
-- 更新内容表
CREATE TABLE `web_update`
(
`wu_id` int primary key auto_increment,
`wu_info` varchar(255) not null comment '更新内容',
`wu_time` datetime not null comment '更新时间',
`is_delete` boolean not null default false comment '该数据是否被删除'
);
CREATE VIEW articleView
(articleId, title, summary, mdContent, url, isOriginal, readingCount, likeCount, dislikeCount,
publishDate, updateDate, isOpen,
categoryId, categoryName, tagId, tagName,
authorId, userEmail, userAvatar, userDisplayName, isDelete)
as
select article.a_id as articleId,
article.a_title as title,
article.a_summary as summary,
article.a_md_content as mdContent,
article.a_url as url,
article.a_is_original as isOriginal,
article.a_reading_number as readingCount,
article.a_like as likeCount,
article.a_dislike as dislikeCount,
article.a_publish_date as publishDate,
article.a_update_date as updateDate,
article.a_is_open as isOpen,
category.t_id as categoryId,
category.t_name as categoryName,
tag.t_id as tagId,
tag.t_name as tagName,
user.u_id as authorId,
user.u_email as userEmail,
user.u_avatar as userAvatar,
user.u_display_name as userDisplayName,
article.is_delete as isDelete
from article,
tag_category as tag,
tag_category as category,
article_tag,
user
where article.a_id = article_tag.a_id
and article_tag.t_id = tag.t_id
and tag.is_category = false
and article.a_category_id = category.t_id
and category.is_category = true
and article.a_author_id = user.u_id;
CREATE VIEW commentView
(commentId, pagePath, content, date, status, pid, toAuthorId, toAuthorEmail, toAuthorDisplayName,
toAuthorAvatar, fromAuthorId, fromAuthorEmail, fromAuthorDisplayName,
fromAuthorAvatar)
as
select cuT.co_id as commentId,
cuT.co_page_path as pagePath,
cuT.co_content as content,
cuT.co_date as date,
cuT.co_status as status,
cuT.co_pid as pid,
cuT.co_to_author_id as toAuthorId,
cuT.toEmail as toAuthorEmail,
cuT.toDisplayName as toAuthorDisplayName,
cuT.toAvatar as toAuthorAvatar,
userFrom.u_id as fromAuthorId,
userFrom.u_email as fromAuthorEmail,
userFrom.u_display_name as fromAuthorDisplayName,
userFrom.u_avatar as fromAuthorAvatar
from (select comment.co_id,
comment.co_page_path,
comment.co_content,
comment.co_date,
comment.co_status,
comment.co_pid,
comment.co_from_author_id,
comment.co_to_author_id,
userTo.u_email as toEmail,
userTo.u_display_name as toDisplayName,
userTo.u_avatar as toAvatar
from comment
left join user userTo on (comment.co_to_author_id = userTo.u_id)
) as cuT,
user as userFrom
where cuT.co_from_author_id = userFrom.u_id;

View File

@@ -2,12 +2,15 @@ package cn.celess.blog;
import cn.celess.blog.entity.Response; import cn.celess.blog.entity.Response;
import cn.celess.blog.entity.model.QiniuResponse;
import cn.celess.blog.entity.model.UserModel; import cn.celess.blog.entity.model.UserModel;
import cn.celess.blog.entity.request.LoginReq; import cn.celess.blog.entity.request.LoginReq;
import cn.celess.blog.service.MailService; import cn.celess.blog.service.MailService;
import cn.celess.blog.service.QiniuService;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.qiniu.storage.model.FileInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@@ -32,6 +35,7 @@ import org.springframework.web.context.WebApplicationContext;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Map; import java.util.Map;
@@ -273,12 +277,12 @@ public class BaseTest {
* @param service service 类 * @param service service 类
* @param mailFiledName service 中自动注入的mailService字段名 * @param mailFiledName service 中自动注入的mailService字段名
*/ */
protected void mockEmailServiceInstance(Object service, String mailFiledName) { protected void mockInjectInstance(Object service, String mailFiledName, Object impl) {
Field mailServiceField; Field field;
try { try {
mailServiceField = service.getClass().getDeclaredField(mailFiledName); field = service.getClass().getDeclaredField(mailFiledName);
mailServiceField.setAccessible(true); field.setAccessible(true);
mailServiceField.set(service, new TestMailServiceImpl()); field.set(service, impl);
} catch (NoSuchFieldException | IllegalAccessException e) { } catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -286,7 +290,7 @@ public class BaseTest {
@Slf4j @Slf4j
protected static class TestMailServiceImpl implements MailService { public static class TestMailServiceImpl implements MailService {
@Override @Override
public Boolean AsyncSend(SimpleMailMessage message) { public Boolean AsyncSend(SimpleMailMessage message) {
@@ -316,4 +320,25 @@ public class BaseTest {
} }
} }
@Slf4j
public static class TestQiNiuServiceImpl implements QiniuService {
@Override
public QiniuResponse uploadFile(InputStream is, String fileName) {
QiniuResponse response = new QiniuResponse();
log.debug("上传文件请求,[fileName:{}]", fileName);
response.key = "key";
response.bucket = "bucket";
response.hash = "hash";
response.fsize = 1;
return response;
}
@Override
public FileInfo[] getFileList() {
log.debug("获取文件列表请求");
return new FileInfo[0];
}
}
} }

View File

@@ -0,0 +1,37 @@
package cn.celess.blog;
import redis.embedded.RedisServer;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
/**
* @author : xiaohai
* @date : 2020/08/14 16:20
*/
@Component
public class RedisServerMock {
private RedisServer redisServer;
/**
* 构造方法之后执行.
*
* @throws IOException e
*/
@PostConstruct
public void startRedis() throws IOException {
redisServer = new RedisServer(6380);
redisServer.start();
}
/**
* 析构方法之后执行.
*/
@PreDestroy
public void stopRedis() {
redisServer.stop();
}
}

View File

@@ -182,7 +182,8 @@ public class LinksControllerTest extends BaseTest {
@Test @Test
public void apply() { public void apply() {
// 做service 层的测试 // 做service 层的测试
mockEmailServiceInstance(partnerSiteService, "mailService"); // mockEmailServiceInstance(partnerSiteService, "mailService");
mockInjectInstance(partnerSiteService, "mailService", new TestMailServiceImpl());
LinkApplyReq req = new LinkApplyReq(); LinkApplyReq req = new LinkApplyReq();
req.setName(randomStr(4)); req.setName(randomStr(4));
req.setUrl("https://" + randomStr(4) + ".celess.cn"); req.setUrl("https://" + randomStr(4) + ".celess.cn");
@@ -224,7 +225,7 @@ public class LinksControllerTest extends BaseTest {
@Test @Test
public void reapply() { public void reapply() {
mockEmailServiceInstance(partnerSiteService, "mailService"); //mockEmailServiceInstance(partnerSiteService, "mailService");
try { try {
partnerSiteService.reapply(randomStr()); partnerSiteService.reapply(randomStr());
throw new AssertionError(); throw new AssertionError();

View File

@@ -7,6 +7,7 @@ import cn.celess.blog.entity.model.UserModel;
import cn.celess.blog.entity.request.LoginReq; import cn.celess.blog.entity.request.LoginReq;
import cn.celess.blog.entity.request.UserReq; import cn.celess.blog.entity.request.UserReq;
import cn.celess.blog.mapper.UserMapper; import cn.celess.blog.mapper.UserMapper;
import cn.celess.blog.service.UserService;
import cn.celess.blog.util.MD5Util; import cn.celess.blog.util.MD5Util;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
@@ -24,13 +25,14 @@ import java.util.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static cn.celess.blog.enmu.ResponseEnum.*; import static cn.celess.blog.enmu.ResponseEnum.*;
public class UserControllerTest extends BaseTest { public class UserControllerTest extends BaseTest {
@Autowired @Autowired
UserMapper userMapper; UserMapper userMapper;
@Autowired
UserService userService;
@Test @Test
public void login() throws Exception { public void login() throws Exception {
@@ -99,6 +101,10 @@ public class UserControllerTest extends BaseTest {
connection.setRequestMethod("GET"); connection.setRequestMethod("GET");
InputStream inputStream = connection.getInputStream(); InputStream inputStream = connection.getInputStream();
assertNotNull(inputStream); assertNotNull(inputStream);
// mock 实现类
mockInjectInstance(userService, "qiniuService", new TestQiNiuServiceImpl());
MockMultipartFile file = new MockMultipartFile("file", "logo.png", MediaType.IMAGE_PNG_VALUE, inputStream); MockMultipartFile file = new MockMultipartFile("file", "logo.png", MediaType.IMAGE_PNG_VALUE, inputStream);
mockMvc.perform(multipart("/user/imgUpload").file(file)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))); mockMvc.perform(multipart("/user/imgUpload").file(file)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
mockMvc.perform(multipart("/user/imgUpload").file(file).header("Authorization", userLogin())).andDo(result -> { mockMvc.perform(multipart("/user/imgUpload").file(file).header("Authorization", userLogin())).andDo(result -> {

View File

@@ -15,8 +15,8 @@ public class HttpUtilTest extends BaseTest {
public void get() { public void get() {
String s = HttpUtil.get("https://api.celess.cn/headerInfo"); String s = HttpUtil.get("https://api.celess.cn/headerInfo");
assertNotNull(s); assertNotNull(s);
Response<Map<String, Object>> response = getResponse(s, MAP_OBJECT_TYPE); // Response<Map<String, Object>> response = getResponse(s, MAP_OBJECT_TYPE);
assertEquals(ResponseEnum.SUCCESS.getCode(), response.getCode()); // assertEquals(ResponseEnum.SUCCESS.getCode(), response.getCode());
assertNotEquals(0, response.getResult().size()); // assertNotEquals(0, response.getResult().size());
} }
} }