Compare commits
202 Commits
v2.1.0
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49a1a53ecb | ||
| 2a3ae4a376 | |||
| 92e818e370 | |||
|
|
c8e93c45c7 | ||
|
|
32de31a21e | ||
|
|
cc20df91e6 | ||
|
|
71d79ed008 | ||
|
|
f7ff494ea4 | ||
|
|
971f48c5f9 | ||
|
|
e1522a8cc1 | ||
|
|
3cc4989960 | ||
|
|
8c751e6e76 | ||
|
|
af47631126 | ||
|
|
2107a1c100 | ||
|
|
2eac16dbe4 | ||
|
|
d248e15cea | ||
|
|
91a818d293 | ||
|
|
65c31e96b4 | ||
|
|
81b4851e42 | ||
|
|
9c580cf6d9 | ||
|
|
9eea5b3db9 | ||
|
|
eacb2e29f3 | ||
|
|
fafee4f918 | ||
|
|
30a4c11366 | ||
|
|
5632d47674 | ||
|
|
15b5d89554 | ||
|
|
79426dbe24 | ||
|
|
b3b19dbc45 | ||
|
|
87ec6d24ca | ||
|
|
0148c5e3f5 | ||
|
|
7cff3b9c08 | ||
|
|
a354f48edf | ||
|
|
2cd2dc93d7 | ||
|
|
d5fbc0fbf1 | ||
|
|
b29362eb8c | ||
|
|
d7c6cca683 | ||
|
|
8020eaeff3 | ||
|
|
aedcaf207b | ||
|
|
af9bf9ef46 | ||
|
|
b38ce4c8ce | ||
|
|
3d3548b984 | ||
|
|
4be9eda566 | ||
|
|
e5711746fb | ||
|
|
cc9cf8b1e8 | ||
|
|
ff076f8366 | ||
|
|
dd9ae0b3f9 | ||
|
|
0e7d5f2d23 | ||
|
|
1de1af2a54 | ||
|
|
857a3d9473 | ||
|
|
78efa62476 | ||
|
|
674812c5c6 | ||
|
|
14ce46c312 | ||
|
|
5f5fbadfd8 | ||
|
|
c153d9a0e3 | ||
|
|
18d35809f5 | ||
|
|
75e2424f75 | ||
|
|
b6c4251198 | ||
|
|
fc1bfa0e4f | ||
|
|
e37de0e177 | ||
|
|
082662af66 | ||
|
|
0c0e2404d0 | ||
|
|
71f82bfe32 | ||
|
|
61ce2fddad | ||
|
|
a245f259f7 | ||
|
|
aa22369b13 | ||
|
|
8c3866afe6 | ||
|
|
2c85c3eaac | ||
|
|
2559937e02 | ||
|
|
8de4be602e | ||
|
|
1f88995884 | ||
|
|
c879fbff5f | ||
|
|
f6020bf8d0 | ||
|
|
418b1d78e5 | ||
|
|
98ed489bb1 | ||
|
|
cfdd818829 | ||
|
|
3afbef009f | ||
|
|
8f4d1cd6c8 | ||
|
|
0ba7e06695 | ||
|
|
512d04f3e9 | ||
|
|
ada8f67171 | ||
|
|
6e12331e61 | ||
|
|
81ee71adf1 | ||
|
|
7e7332694e | ||
|
|
8db690a55f | ||
|
|
0b40522e93 | ||
|
|
9026ba0732 | ||
|
|
f5f2437fa4 | ||
|
|
0bcca091e1 | ||
|
|
3c69baa4ad | ||
|
|
baf5b1bbb7 | ||
|
|
38621bcfa4 | ||
|
|
cf435a588f | ||
|
|
feab26f4f7 | ||
|
|
578dbe6cc5 | ||
|
|
f3b03f4853 | ||
|
|
ee85b1f175 | ||
|
|
925e816f7a | ||
|
|
a59bb7f231 | ||
|
|
7f17c20e01 | ||
|
|
6eabb3ab22 | ||
|
|
72674f4612 | ||
|
|
9b460ff33c | ||
|
|
a26946a583 | ||
|
|
01407aba7e | ||
|
|
a54e04abf3 | ||
|
|
450b4a40bd | ||
|
|
9f883d12df | ||
|
|
c17b56b436 | ||
|
|
b55a50d548 | ||
|
|
4c9b193857 | ||
|
|
18a8c916c3 | ||
|
|
99f2907621 | ||
|
|
939b06d0a9 | ||
|
|
a7f947a017 | ||
|
|
40e1f4d6ab | ||
|
|
6b77655c16 | ||
|
|
7ff44fd73e | ||
|
|
c9f91bf2c1 | ||
|
|
03fcddb971 | ||
|
|
dc851e84a4 | ||
|
|
b34acee733 | ||
|
|
d46dada23a | ||
|
|
47e5030f52 | ||
|
|
94c9fc1c46 | ||
|
|
bdcfaef5f8 | ||
|
|
3b6439c5cf | ||
|
|
938a051487 | ||
|
|
a04b51a82e | ||
|
|
ee4c4bd87e | ||
|
|
e70ad72523 | ||
|
|
c466ddddea | ||
|
|
7257f23ef6 | ||
|
|
7c96151830 | ||
|
|
5a47803611 | ||
|
|
af9f243a83 | ||
|
|
3c8abc895a | ||
|
|
9ffa293d24 | ||
|
|
d13ab4e522 | ||
|
|
2fce2d8a1c | ||
|
|
6eb7d01875 | ||
|
|
aa751dbba1 | ||
|
|
14ff60ecfc | ||
|
|
5dae647885 | ||
|
|
bf2abd6072 | ||
|
|
a62b395a8a | ||
|
|
5059859ae4 | ||
|
|
ecdbf8e21c | ||
|
|
c69eee7027 | ||
|
|
8e8a7c809d | ||
|
|
c6a97e4c5b | ||
|
|
d50cd93e55 | ||
|
|
e32600d892 | ||
|
|
d473b5931b | ||
|
|
ab6f9d894d | ||
|
|
49ee7c73e2 | ||
|
|
4a65df2a7d | ||
|
|
b6c6cda4ae | ||
|
|
a9efb1c04d | ||
|
|
4ac430445d | ||
|
|
7ac3d69da4 | ||
|
|
657a200d81 | ||
|
|
85c3541445 | ||
|
|
c6877c2b4a | ||
|
|
9e98134003 | ||
|
|
7a81d8e4ce | ||
|
|
1b52e27b72 | ||
|
|
cd9d9ff0e6 | ||
|
|
dcf44cefb6 | ||
|
|
d83e4de9a3 | ||
|
|
9c949576aa | ||
|
|
85b24891be | ||
|
|
da95470993 | ||
|
|
3b368c92cb | ||
|
|
ad5271f740 | ||
|
|
d2cf640133 | ||
|
|
4a2abc47cc | ||
|
|
6b29cd39d4 | ||
|
|
69da168fc1 | ||
|
|
d6cede718b | ||
|
|
7922ea558f | ||
|
|
f65c96fa2d | ||
|
|
1bfd2d713e | ||
|
|
ffed0d5cd0 | ||
|
|
b9094c1345 | ||
|
|
e9209d1852 | ||
|
|
9900605e1a | ||
|
|
883a78e872 | ||
|
|
c7016dcf5f | ||
|
|
66b2b26b15 | ||
|
|
f1d3a79919 | ||
|
|
003f74f5f1 | ||
|
|
2f6253c175 | ||
|
|
aa3ee5db72 | ||
|
|
d340ba8218 | ||
|
|
7be1c9dfb0 | ||
|
|
b7f26cbfdb | ||
|
|
de5e40e6b8 | ||
|
|
d1f08b58c0 | ||
|
|
8b255372dd | ||
|
|
f88bf105a9 | ||
|
|
0e26eab2e6 | ||
|
|
778c2dba58 |
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. iOS]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Smartphone (please complete the following information):**
|
||||||
|
- Device: [e.g. iPhone6]
|
||||||
|
- OS: [e.g. iOS8.1]
|
||||||
|
- Browser [e.g. stock browser, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
12
.github/dependabot.yml
vendored
Normal file
12
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# To get started with Dependabot version updates, you'll need to specify which
|
||||||
|
# package ecosystems to update and where the package manifests are located.
|
||||||
|
# Please see the documentation for all configuration options:
|
||||||
|
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "maven" # See documentation for possible values
|
||||||
|
directory: "/" # Location of package manifests
|
||||||
|
schedule:
|
||||||
|
interval: "monthly"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
37
.github/workflows/build.yml
vendored
Normal file
37
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
||||||
|
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
|
||||||
|
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '.md')" # 如果 commit 信息包含以下关键字则跳过该任务
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
KEY: ${{ secrets.WEB_HOOK_ACCESS_KEY }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up JDK 1.8
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 1.8
|
||||||
|
|
||||||
|
- name: Sync repository
|
||||||
|
uses: x-dr/sync-repo-to-gitee@v1.0
|
||||||
|
env:
|
||||||
|
# 在 Settings->Secrets 配置 GITEE_KEY
|
||||||
|
SSH_KEY: ${{ secrets.GITEE_KEY }}
|
||||||
|
with:
|
||||||
|
# GitHub存储库的SSH URL.
|
||||||
|
github-repo: git@github.com:xiaohai2271/blog-backEnd.git
|
||||||
|
# Gitee存储库的SSH URL.
|
||||||
|
gitee-repo: git@gitee.com:xiaohai2271/blog-backEnd.git
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
run: mvn -B test --file pom.xml && curl http://bt.celess.cn:2271/hook?access_key=$KEY
|
||||||
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [master]
|
||||||
|
schedule:
|
||||||
|
- cron: '0 14 * * 2'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
# Override automatic language detection by changing the below list
|
||||||
|
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
|
||||||
|
language: ['java']
|
||||||
|
# Learn more...
|
||||||
|
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
# We must fetch at least the immediate parents so that if this is
|
||||||
|
# a pull request then we can checkout the head.
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
# If this run was triggered by a pull request event, then checkout
|
||||||
|
# the head of the pull request instead of the merge commit.
|
||||||
|
- run: git checkout HEAD^2
|
||||||
|
if: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v1
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v1
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v1
|
||||||
47
.github/workflows/deplay.yml
vendored
47
.github/workflows/deplay.yml
vendored
@@ -1,47 +0,0 @@
|
|||||||
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
|
||||||
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
|
|
||||||
|
|
||||||
name: Deplay
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
APPLICATION_PROPERTIES_TEST: ${{ secrets.APPLICATION_PROPERTIES_TEST }}
|
|
||||||
APPLICATION_PROPERTIES_PROD: ${{ secrets.APPLICATION_PROPERTIES_PROD }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Set up JDK 1.8
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: 1.8
|
|
||||||
|
|
||||||
- name: Build jar file
|
|
||||||
run: echo $APPLICATION_PROPERTIES_PROD|base64 -d> src/main/resources/application-prod.properties && mvn -B package --file pom.xml
|
|
||||||
|
|
||||||
- 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 }}
|
|
||||||
|
|
||||||
24
.github/workflows/test.yml
vendored
24
.github/workflows/test.yml
vendored
@@ -1,7 +1,7 @@
|
|||||||
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
||||||
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
|
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
|
||||||
|
|
||||||
name: pr Test
|
name: Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -10,20 +10,20 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '.md')" # 如果 commit 信息包含以下关键字则跳过该任务
|
||||||
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
|
||||||
- name: Set up JDK 1.8
|
- name: Set up JDK 1.8
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
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
2
.gitignore
vendored
@@ -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
|
|
||||||
|
|||||||
17
.mvn/wrapper/MavenWrapperDownloader.java
vendored
17
.mvn/wrapper/MavenWrapperDownloader.java
vendored
@@ -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,12 +20,12 @@ 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.
|
||||||
*/
|
*/
|
||||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||||
@@ -55,7 +54,7 @@ public class MavenWrapperDownloader {
|
|||||||
// wrapperUrl parameter.
|
// wrapperUrl parameter.
|
||||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||||
String url = DEFAULT_DOWNLOAD_URL;
|
String url = DEFAULT_DOWNLOAD_URL;
|
||||||
if (mavenWrapperPropertyFile.exists()) {
|
if(mavenWrapperPropertyFile.exists()) {
|
||||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||||
try {
|
try {
|
||||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||||
@@ -66,7 +65,7 @@ public class MavenWrapperDownloader {
|
|||||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (mavenWrapperPropertyFileInputStream != null) {
|
if(mavenWrapperPropertyFileInputStream != null) {
|
||||||
mavenWrapperPropertyFileInputStream.close();
|
mavenWrapperPropertyFileInputStream.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -77,8 +76,8 @@ public class MavenWrapperDownloader {
|
|||||||
System.out.println("- Downloading from: " + url);
|
System.out.println("- Downloading from: " + url);
|
||||||
|
|
||||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||||
if (!outputFile.getParentFile().exists()) {
|
if(!outputFile.getParentFile().exists()) {
|
||||||
if (!outputFile.getParentFile().mkdirs()) {
|
if(!outputFile.getParentFile().mkdirs()) {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Binary file not shown.
4
.mvn/wrapper/maven-wrapper.properties
vendored
4
.mvn/wrapper/maven-wrapper.properties
vendored
@@ -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
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2019 小海
|
Copyright (c) 2020 禾几海
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
38
README.md
38
README.md
@@ -1,11 +1,23 @@
|
|||||||
# 小海博客后端管理系统
|
<h1 align="center">
|
||||||
   [](https://www.celess.cn)
|
小海博客后端管理系统
|
||||||
## 基于Springboot的后端博客管理系统
|
</h1>
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
|
基于Springboot的后端博客管理系统
|
||||||
|
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://www.celess.cn)
|
||||||
|
</div>
|
||||||
|
|
||||||
### 主要使用的技术
|
> 请配合前端项目一起食用 [https://github.com/xiaohai2271/blog-frontEnd](https://github.com/xiaohai2271/blog-frontEnd)
|
||||||
|
## 🎈主要使用的技术
|
||||||
|
|
||||||
| 使用的技术 | 名称 | 版本 |
|
| 使用的技术 | 名称 | 版本 |
|
||||||
| :--------------: | :--------: | :-----------: |
|
| :--------------: | :--------: | :-----------: |
|
||||||
@@ -18,18 +30,16 @@
|
|||||||
| 接口文档 | Swagger | 2.6.1 |
|
| 接口文档 | Swagger | 2.6.1 |
|
||||||
| 数据库连接池 | druid | 1.1.14 |
|
| 数据库连接池 | druid | 1.1.14 |
|
||||||
| 缓存(线上环境) | redis | 3.0.6 |
|
| 缓存(线上环境) | redis | 3.0.6 |
|
||||||
|数据库|mysql|5.7|
|
| 数据库 |mysql |5.7 |
|
||||||
|
|
||||||
### 接口文档
|
## 🔨如何构建
|
||||||
|
详情参照[Build](./doc/Build.md)文档
|
||||||
|
|
||||||
项目采用swagger2,接口文档自动生成,具体为 http://ip:端口/swagger-ui.html
|
|
||||||
|
|
||||||
### 📝TODO
|
## 📒接口文档
|
||||||
|
项目采用swagger2,接口文档自动生成,具体为 http://ip:port/doc.html
|
||||||
|
|
||||||
- [x] 密码重置
|
或者参照[离线API文档](./doc/API.md)
|
||||||
- [x] 信息修改
|
|
||||||
- [ ] 接入qq登录
|
|
||||||
|
|
||||||
### 📌FIXME
|
## ☀授权协议
|
||||||
|
[MIT](./LICENSE)
|
||||||
- [ ] `/write` 图片上传的跨域问题
|
|
||||||
|
|||||||
8
build.sh
8
build.sh
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
echo "查询已存在进程"
|
|
||||||
pgrep -af blog-0.0.1-SNAPSHOT.jar
|
|
||||||
echo "结束已存在进程"
|
|
||||||
pkill -f blog-0.0.1-SNAPSHOT.jar
|
|
||||||
echo "开始运行小海博客"
|
|
||||||
nohup java -jar -Dfile.encoding=UTF-8 blog-0.0.1-SNAPSHOT.jar >blog.log &
|
|
||||||
echo "更新结束"
|
|
||||||
4079
doc/API.md
Normal file
4079
doc/API.md
Normal file
File diff suppressed because it is too large
Load Diff
33
doc/Build.md
Normal file
33
doc/Build.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# 如何构建
|
||||||
|
### 1. 构建前准备
|
||||||
|
- 安装jdk
|
||||||
|
- 安装maven(也可使使用项目中的maven wrapper)
|
||||||
|
- 安装mysql
|
||||||
|
- 安装redis
|
||||||
|
- 获取七牛云的AccessKey/SecretKey (个人中心-密钥管理) [七牛云官网](https://www.qiniu.com/)
|
||||||
|
|
||||||
|
### 2. 拉取项目到本地
|
||||||
|
``` shell script
|
||||||
|
git clone https://github.com/xiaohai2271/blog-backEnd.git
|
||||||
|
# 或
|
||||||
|
git clone git@github.com:xiaohai2271/blog-backEnd.git
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. maven构建
|
||||||
|
```shell script
|
||||||
|
mvn package
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 运行
|
||||||
|
```shell script
|
||||||
|
java -jar target/blog-0.0.1-SNAPSHOT.jar
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. 其他命令
|
||||||
|
```shell script
|
||||||
|
mvn clean # 清理项目资源
|
||||||
|
mvn clean package # 清理项目资源并重新打包
|
||||||
|
mvn clean package -DskipTests # 清理项目资源,重新打包并跳过测试
|
||||||
|
mvn test # 运行测试
|
||||||
|
..... #待添加
|
||||||
|
```
|
||||||
256
mvnw
vendored
256
mvnw
vendored
@@ -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:
|
||||||
# ------------------
|
# ------------------
|
||||||
@@ -34,135 +34,128 @@
|
|||||||
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
if [ -z "$MAVEN_SKIP_RC" ]; then
|
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||||
|
|
||||||
if [ -f /etc/mavenrc ]; then
|
if [ -f /etc/mavenrc ] ; then
|
||||||
. /etc/mavenrc
|
. /etc/mavenrc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$HOME/.mavenrc" ]; then
|
if [ -f "$HOME/.mavenrc" ] ; then
|
||||||
. "$HOME/.mavenrc"
|
. "$HOME/.mavenrc"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
fi
|
||||||
fi
|
;;
|
||||||
;;
|
|
||||||
esac
|
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
|
||||||
|
|
||||||
if [ -z "$M2_HOME" ]; then
|
if [ -z "$M2_HOME" ] ; then
|
||||||
## resolve links - $0 may be a link to maven's home
|
## resolve links - $0 may be a link to maven's home
|
||||||
PRG="$0"
|
PRG="$0"
|
||||||
|
|
||||||
# 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
|
||||||
fi
|
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
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$JAVACMD" ]; then
|
if [ -z "$JAVACMD" ] ; then
|
||||||
if [ -n "$JAVA_HOME" ]; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="$(which java)"
|
JAVACMD="`which java`"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -x "$JAVACMD" ]; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
echo "Error: JAVA_HOME is not defined correctly." >&2
|
echo "Error: JAVA_HOME is not defined correctly." >&2
|
||||||
echo " We cannot execute $JAVACMD" >&2
|
echo " We cannot execute $JAVACMD" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$JAVA_HOME" ]; then
|
if [ -z "$JAVA_HOME" ] ; then
|
||||||
echo "Warning: JAVA_HOME environment variable is not set."
|
echo "Warning: JAVA_HOME environment variable is not set."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -172,24 +165,22 @@ 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
|
||||||
|
|
||||||
basedir="$1"
|
basedir="$1"
|
||||||
wdir="$1"
|
wdir="$1"
|
||||||
while [ "$wdir" != '/' ]; do
|
while [ "$wdir" != '/' ] ; do
|
||||||
if [ -d "$wdir"/.mvn ]; then
|
if [ -d "$wdir"/.mvn ] ; then
|
||||||
basedir=$wdir
|
basedir=$wdir
|
||||||
break
|
break
|
||||||
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
|
||||||
@@ -199,13 +190,13 @@ find_maven_basedir() {
|
|||||||
# concatenates all lines of a file
|
# concatenates all lines of a file
|
||||||
concat_lines() {
|
concat_lines() {
|
||||||
if [ -f "$1" ]; then
|
if [ -f "$1" ]; then
|
||||||
echo "$(tr -s '\n' ' ' <"$1")"
|
echo "$(tr -s '\n' ' ' < "$1")"
|
||||||
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
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
@@ -213,78 +204,75 @@ fi
|
|||||||
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
|
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
echo "Found .mvn/wrapper/maven-wrapper.jar"
|
echo "Found .mvn/wrapper/maven-wrapper.jar"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
|
||||||
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
|
||||||
fi
|
|
||||||
if [ -n "$MVNW_REPOURL" ]; then
|
|
||||||
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
|
|
||||||
else
|
|
||||||
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
|
|
||||||
fi
|
|
||||||
while IFS="=" read key value; do
|
|
||||||
case "$key" in wrapperUrl)
|
|
||||||
jarUrl="$value"
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
|
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
|
||||||
echo "Downloading from: $jarUrl"
|
|
||||||
fi
|
|
||||||
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
|
|
||||||
if $cygwin; then
|
|
||||||
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
|
|
||||||
fi
|
|
||||||
|
|
||||||
if command -v wget >/dev/null; then
|
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
echo "Found wget ... using wget"
|
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
||||||
fi
|
fi
|
||||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
if [ -n "$MVNW_REPOURL" ]; then
|
||||||
wget "$jarUrl" -O "$wrapperJarPath"
|
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||||
else
|
else
|
||||||
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
|
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||||
fi
|
fi
|
||||||
elif command -v curl >/dev/null; then
|
while IFS="=" read key value; do
|
||||||
|
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
|
||||||
|
esac
|
||||||
|
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
echo "Found curl ... using curl"
|
echo "Downloading from: $jarUrl"
|
||||||
fi
|
fi
|
||||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
|
||||||
curl -o "$wrapperJarPath" "$jarUrl" -f
|
|
||||||
else
|
|
||||||
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
|
||||||
echo "Falling back to using Java to download"
|
|
||||||
fi
|
|
||||||
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
|
||||||
# For Cygwin, switch paths to Windows format before running javac
|
|
||||||
if $cygwin; then
|
if $cygwin; then
|
||||||
javaClass=$(cygpath --path --windows "$javaClass")
|
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
|
||||||
fi
|
fi
|
||||||
if [ -e "$javaClass" ]; then
|
|
||||||
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
if command -v wget > /dev/null; then
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
echo " - Compiling MavenWrapperDownloader.java ..."
|
echo "Found wget ... using wget"
|
||||||
fi
|
fi
|
||||||
# Compiling the Java class
|
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||||
("$JAVA_HOME/bin/javac" "$javaClass")
|
wget "$jarUrl" -O "$wrapperJarPath"
|
||||||
fi
|
else
|
||||||
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
|
||||||
# Running the downloader
|
fi
|
||||||
|
elif command -v curl > /dev/null; then
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
echo " - Running MavenWrapperDownloader.java ..."
|
echo "Found curl ... using curl"
|
||||||
|
fi
|
||||||
|
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||||
|
curl -o "$wrapperJarPath" "$jarUrl" -f
|
||||||
|
else
|
||||||
|
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo "Falling back to using Java to download"
|
||||||
|
fi
|
||||||
|
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
||||||
|
# For Cygwin, switch paths to Windows format before running javac
|
||||||
|
if $cygwin; then
|
||||||
|
javaClass=`cygpath --path --windows "$javaClass"`
|
||||||
|
fi
|
||||||
|
if [ -e "$javaClass" ]; then
|
||||||
|
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo " - Compiling MavenWrapperDownloader.java ..."
|
||||||
|
fi
|
||||||
|
# Compiling the Java class
|
||||||
|
("$JAVA_HOME/bin/javac" "$javaClass")
|
||||||
|
fi
|
||||||
|
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||||
|
# Running the downloader
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo " - Running MavenWrapperDownloader.java ..."
|
||||||
|
fi
|
||||||
|
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
# End of extension
|
# End of extension
|
||||||
@@ -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
|
||||||
|
|||||||
10
mvnw.cmd
vendored
10
mvnw.cmd
vendored
@@ -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
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
@REM Optional ENV vars
|
@REM Optional ENV vars
|
||||||
@REM M2_HOME - location of maven2's installed home dir
|
@REM M2_HOME - location of maven2's installed home dir
|
||||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
|
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
|
||||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||||
@REM e.g. to debug Maven itself, use
|
@REM e.g. to debug Maven itself, use
|
||||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||||
@@ -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 ...
|
||||||
|
|||||||
113
pom.xml
113
pom.xml
@@ -5,8 +5,8 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.1.3.RELEASE</version>
|
<version>3.0.3</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>cn.celess</groupId>
|
<groupId>cn.celess</groupId>
|
||||||
<artifactId>blog</artifactId>
|
<artifactId>blog</artifactId>
|
||||||
@@ -40,14 +40,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>druid</artifactId>
|
<artifactId>druid</artifactId>
|
||||||
<version>1.1.14</version>
|
<version>1.2.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- lombok -->
|
<!-- lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.6</version>
|
<version>1.18.20</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
@@ -67,23 +67,15 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youbenzi</groupId>
|
<groupId>com.youbenzi</groupId>
|
||||||
<artifactId>MDTool</artifactId>
|
<artifactId>MDTool</artifactId>
|
||||||
<version>1.2.3</version>
|
<version>1.2.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.minidev</groupId>
|
<groupId>net.minidev</groupId>
|
||||||
<artifactId>json-smart</artifactId>
|
<artifactId>json-smart</artifactId>
|
||||||
<version>2.3</version>
|
<version>2.4.7</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--Json-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.sf.json-lib</groupId>
|
|
||||||
<artifactId>json-lib</artifactId>
|
|
||||||
<version>2.4</version>
|
|
||||||
<classifier>jdk15</classifier>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 七牛云SDK -->
|
<!-- 七牛云SDK -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.qiniu</groupId>
|
<groupId>com.qiniu</groupId>
|
||||||
@@ -107,39 +99,39 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
<version>2.0.1</version>
|
<version>2.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- pageHelper -->
|
<!-- pageHelper -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.pagehelper</groupId>
|
<groupId>com.github.pagehelper</groupId>
|
||||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
<version>1.2.12</version>
|
<version>1.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- protostuff序列化依赖 -->
|
<!-- protostuff序列化依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.dyuproject.protostuff</groupId>
|
<groupId>com.dyuproject.protostuff</groupId>
|
||||||
<artifactId>protostuff-core</artifactId>
|
<artifactId>protostuff-core</artifactId>
|
||||||
<version>1.0.8</version>
|
<version>1.1.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.dyuproject.protostuff</groupId>
|
<groupId>com.dyuproject.protostuff</groupId>
|
||||||
<artifactId>protostuff-runtime</artifactId>
|
<artifactId>protostuff-runtime</artifactId>
|
||||||
<version>1.0.8</version>
|
<version>1.1.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Ua解析-->
|
<!-- Ua解析-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>eu.bitwalker</groupId>
|
<groupId>eu.bitwalker</groupId>
|
||||||
<artifactId>UserAgentUtils</artifactId>
|
<artifactId>UserAgentUtils</artifactId>
|
||||||
<version>1.20</version>
|
<version>1.21</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>4.13.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JJwt -->
|
<!-- JJwt -->
|
||||||
@@ -148,6 +140,69 @@
|
|||||||
<artifactId>jjwt</artifactId>
|
<artifactId>jjwt</artifactId>
|
||||||
<version>0.9.1</version>
|
<version>0.9.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- OkHttp -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
<artifactId>okhttp</artifactId>
|
||||||
|
<version>4.9.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib</artifactId>
|
||||||
|
<version>1.4.20</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sourceforge.htmlunit</groupId>
|
||||||
|
<artifactId>htmlunit</artifactId>
|
||||||
|
<version>2.45.0</version>
|
||||||
|
</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>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-impl</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-core</artifactId>
|
||||||
|
<version>2.3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.activation</groupId>
|
||||||
|
<artifactId>activation</artifactId>
|
||||||
|
<version>1.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lionsoul</groupId>
|
||||||
|
<artifactId>ip2region</artifactId>
|
||||||
|
<version>1.7.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -157,21 +212,15 @@
|
|||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
<version>0.7.9</version>
|
<version>1.5.10</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>pre-unit-test</id>
|
<id>compile</id>
|
||||||
|
<phase>process-sources</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>prepare-agent</goal>
|
<goal>compile</goal>
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>post-unit-test</id>
|
|
||||||
<phase>test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>report</goal>
|
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package cn.celess.blog.configuration;
|
||||||
|
|
||||||
|
import cn.celess.blog.util.EnvironmentUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||||
|
import org.springframework.boot.logging.DeferredLog;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.PropertiesPropertySource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>date: 2022/12/02</P>
|
||||||
|
* <p>desc: </p>
|
||||||
|
* <p>mail: a@celess.cn</p>
|
||||||
|
*
|
||||||
|
* @author 禾几海
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CommonEnvPostProcessor implements EnvironmentPostProcessor, ApplicationListener<ApplicationEvent>, Ordered {
|
||||||
|
public static final DeferredLog log = new DeferredLog();
|
||||||
|
|
||||||
|
private static final String CONFIG_PATH = "/HBlog/config/blog.properties";
|
||||||
|
private static final String SOURCE_NAME = "localize";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postProcessEnvironment(ConfigurableEnvironment configurableEnvironment, SpringApplication springApplication) {
|
||||||
|
|
||||||
|
EnvironmentUtil.setEnvironment(configurableEnvironment);
|
||||||
|
|
||||||
|
log.info("加载本地配置文件--");
|
||||||
|
//获取环境变量
|
||||||
|
String homeEnv = EnvironmentUtil.getEnv("BLOG_HOME", EnvironmentUtil.getEnv("USERPROFILE"));
|
||||||
|
String configPath = (homeEnv + CONFIG_PATH).replaceAll("[\\|/]+", Matcher.quoteReplacement(File.separator));
|
||||||
|
try (InputStream input = Files.newInputStream(Paths.get(configPath))) {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.load(input);
|
||||||
|
PropertiesPropertySource propertySource = new PropertiesPropertySource(SOURCE_NAME, properties);
|
||||||
|
configurableEnvironment.getPropertySources().addLast(propertySource);
|
||||||
|
log.info("成功加载本地配置文件:)");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("加载本地[" + configPath + "]的配置文件失败:(");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(@NotNull ApplicationEvent event) {
|
||||||
|
log.replayTo(CommonEnvPostProcessor.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -31,19 +31,16 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
@Override
|
@Override
|
||||||
@Bean
|
@Bean
|
||||||
public KeyGenerator keyGenerator() {
|
public KeyGenerator keyGenerator() {
|
||||||
return new KeyGenerator() {
|
return (target, method, params) -> {
|
||||||
@Override
|
StringBuilder sb = new StringBuilder();
|
||||||
public Object generate(Object target, Method method, Object... params) {
|
String name = target.getClass().getName();
|
||||||
StringBuilder sb = new StringBuilder();
|
sb.append(name.substring(name.lastIndexOf(".") + 1));
|
||||||
String name = target.getClass().getName();
|
sb.append(":");
|
||||||
sb.append(name.substring(name.lastIndexOf(".") + 1));
|
sb.append(method.getName());
|
||||||
sb.append(":");
|
for (Object obj : params) {
|
||||||
sb.append(method.getName());
|
sb.append("-").append(obj.toString());
|
||||||
for (Object obj : params) {
|
|
||||||
sb.append("-").append(obj.toString());
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
return sb.toString();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import cn.celess.blog.entity.Response;
|
|||||||
import cn.celess.blog.service.UserService;
|
import cn.celess.blog.service.UserService;
|
||||||
import cn.celess.blog.util.JwtUtil;
|
import cn.celess.blog.util.JwtUtil;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -84,7 +84,7 @@ public class AuthenticationFilter implements HandlerInterceptor {
|
|||||||
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
try {
|
try {
|
||||||
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
|
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
|
||||||
response.getWriter().println(JSONObject.fromObject(Response.response(e, null)));
|
response.getWriter().println(new ObjectMapper().writeValueAsString(Response.response(e, null)));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public class SessionListener implements HttpSessionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sessionCreated(HttpSessionEvent se) {
|
public void sessionCreated(HttpSessionEvent se) {
|
||||||
// TODO : can move 'visit' api to here
|
|
||||||
se.getSession().setAttribute("visitDetail", new HashMap<String, Integer>());
|
se.getSession().setAttribute("visitDetail", new HashMap<String, Integer>());
|
||||||
// 10s for debug
|
// 10s for debug
|
||||||
// se.getSession().setMaxInactiveInterval(10);
|
// se.getSession().setMaxInactiveInterval(10);
|
||||||
@@ -44,9 +43,7 @@ public class SessionListener implements HttpSessionListener {
|
|||||||
sb.append("\t登录情况 => ");
|
sb.append("\t登录情况 => ");
|
||||||
String email = (String) se.getSession().getAttribute("email");
|
String email = (String) se.getSession().getAttribute("email");
|
||||||
sb.append(email == null ? "游客访问" : email);
|
sb.append(email == null ? "游客访问" : email);
|
||||||
visitDetail.forEach((s, integer) -> {
|
visitDetail.forEach((s, integer) -> sb.append("\n").append("Method:[").append(s.split(":")[1]).append("]\tTimes:[").append(integer).append("]\tPath:[").append(s.split(":")[0]).append("]"));
|
||||||
sb.append("\n").append("Method:[").append(s.split(":")[1]).append("]\tTimes:[").append(integer).append("]\tPath:[").append(s.split(":")[0]).append("]");
|
|
||||||
});
|
|
||||||
log.info(sb.toString());
|
log.info(sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,15 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.ArticleModel;
|
import cn.celess.blog.entity.model.ArticleModel;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
|
||||||
import cn.celess.blog.entity.request.ArticleReq;
|
import cn.celess.blog.entity.request.ArticleReq;
|
||||||
import cn.celess.blog.service.ArticleService;
|
import cn.celess.blog.service.ArticleService;
|
||||||
import cn.celess.blog.util.RedisUserUtil;
|
import cn.celess.blog.util.RedisUserUtil;
|
||||||
import cn.celess.blog.util.SitemapGenerateUtil;
|
import cn.celess.blog.util.SitemapGenerateUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -27,6 +25,8 @@ public class ArticleController {
|
|||||||
SitemapGenerateUtil sitemapGenerateUtil;
|
SitemapGenerateUtil sitemapGenerateUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
RedisUserUtil redisUserUtil;
|
RedisUserUtil redisUserUtil;
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String activeModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建一篇文章
|
* 新建一篇文章
|
||||||
@@ -37,7 +37,9 @@ public class ArticleController {
|
|||||||
@PostMapping("/admin/article/create")
|
@PostMapping("/admin/article/create")
|
||||||
public Response create(@RequestBody ArticleReq body) {
|
public Response create(@RequestBody ArticleReq body) {
|
||||||
ArticleModel articleModel = articleService.create(body);
|
ArticleModel articleModel = articleService.create(body);
|
||||||
sitemapGenerateUtil.createSitemap();
|
if ("prod".equals(activeModel)) {
|
||||||
|
sitemapGenerateUtil.createSitemap();
|
||||||
|
}
|
||||||
return Response.success(articleModel);
|
return Response.success(articleModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +52,9 @@ public class ArticleController {
|
|||||||
@DeleteMapping("/admin/article/del")
|
@DeleteMapping("/admin/article/del")
|
||||||
public Response delete(@RequestParam("articleID") long articleId) {
|
public Response delete(@RequestParam("articleID") long articleId) {
|
||||||
boolean delete = articleService.delete(articleId);
|
boolean delete = articleService.delete(articleId);
|
||||||
sitemapGenerateUtil.createSitemap();
|
if ("prod".equals(activeModel)) {
|
||||||
|
sitemapGenerateUtil.createSitemap();
|
||||||
|
}
|
||||||
return Response.success(delete);
|
return Response.success(delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +67,9 @@ public class ArticleController {
|
|||||||
@PutMapping("/admin/article/update")
|
@PutMapping("/admin/article/update")
|
||||||
public Response update(@RequestBody ArticleReq body) {
|
public Response update(@RequestBody ArticleReq body) {
|
||||||
ArticleModel update = articleService.update(body);
|
ArticleModel update = articleService.update(body);
|
||||||
sitemapGenerateUtil.createSitemap();
|
if ("prod".equals(activeModel)) {
|
||||||
|
sitemapGenerateUtil.createSitemap();
|
||||||
|
}
|
||||||
return Response.success(update);
|
return Response.success(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +120,7 @@ public class ArticleController {
|
|||||||
@GetMapping("/admin/articles")
|
@GetMapping("/admin/articles")
|
||||||
public Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
|
public Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||||
@RequestParam(name = "count", defaultValue = "10") int count,
|
@RequestParam(name = "count", defaultValue = "10") int count,
|
||||||
@RequestParam(name = "deleted", defaultValue = "false") boolean deleted) {
|
@RequestParam(name = "deleted", required = false) Boolean deleted) {
|
||||||
return Response.success(articleService.adminArticles(count, page, deleted));
|
return Response.success(articleService.adminArticles(count, page, deleted));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import cn.celess.blog.exception.MyException;
|
|||||||
import cn.celess.blog.service.CountService;
|
import cn.celess.blog.service.CountService;
|
||||||
import cn.celess.blog.service.QiniuService;
|
import cn.celess.blog.service.QiniuService;
|
||||||
import cn.celess.blog.util.HttpUtil;
|
import cn.celess.blog.util.HttpUtil;
|
||||||
|
import cn.celess.blog.util.RedisUserUtil;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.VeriCodeUtil;
|
import cn.celess.blog.util.VeriCodeUtil;
|
||||||
import net.sf.json.JSONArray;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -27,9 +28,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Enumeration;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,7 +46,7 @@ public class CommonController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
RedisUtil redisUtil;
|
RedisUtil redisUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
HttpServletRequest request;
|
RedisUserUtil redisUserUtil;
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/counts")
|
@GetMapping("/counts")
|
||||||
@@ -89,7 +88,7 @@ public class CommonController {
|
|||||||
* @throws IOException IOException
|
* @throws IOException IOException
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/imgCode", produces = MediaType.IMAGE_PNG_VALUE)
|
@GetMapping(value = "/imgCode", produces = MediaType.IMAGE_PNG_VALUE)
|
||||||
public void getImg(HttpServletResponse response) throws IOException {
|
public void getImg(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
Object[] obj = VeriCodeUtil.createImage();
|
Object[] obj = VeriCodeUtil.createImage();
|
||||||
request.getSession().setAttribute("code", obj[0]);
|
request.getSession().setAttribute("code", obj[0]);
|
||||||
//将图片输出给浏览器
|
//将图片输出给浏览器
|
||||||
@@ -133,14 +132,14 @@ public class CommonController {
|
|||||||
* FIXME :: 单张图片多次上传的问题
|
* FIXME :: 单张图片多次上传的问题
|
||||||
* editor.md图片上传的接口
|
* editor.md图片上传的接口
|
||||||
* FUCK !!!
|
* FUCK !!!
|
||||||
*
|
* !! 推荐使用 fileUpload(/fileUpload) 接口
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
* @return
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@PostMapping("/imgUpload")
|
@PostMapping("/imgUpload")
|
||||||
public void upload(HttpServletRequest request, HttpServletResponse response, @RequestParam("editormd-image-file") MultipartFile file) throws IOException {
|
public void upload(HttpServletRequest request, HttpServletResponse response, @RequestParam("editormd-image-file") MultipartFile file) throws IOException {
|
||||||
JSONObject jsonObject = new JSONObject();
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String uploadTimesStr = redisUtil.get(request.getRemoteAddr() + "-ImgUploadTimes");
|
String uploadTimesStr = redisUtil.get(request.getRemoteAddr() + "-ImgUploadTimes");
|
||||||
int uploadTimes = 0;
|
int uploadTimes = 0;
|
||||||
if (uploadTimesStr != null) {
|
if (uploadTimesStr != null) {
|
||||||
@@ -150,41 +149,74 @@ public class CommonController {
|
|||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||||
}
|
}
|
||||||
request.setCharacterEncoding("utf-8");
|
request.setCharacterEncoding("utf-8");
|
||||||
response.setContentType("text/html");
|
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
jsonObject.put("success", 0);
|
map.put("success", 0);
|
||||||
jsonObject.put("message", "上传失败,请选择文件");
|
map.put("message", "上传失败,请选择文件");
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(mapper.writeValueAsString(map));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
|
assert fileName != null;
|
||||||
String mime = fileName.substring(fileName.lastIndexOf("."));
|
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||||
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
||||||
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
||||||
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
||||||
jsonObject.put("success", 1);
|
map.put("success", 1);
|
||||||
jsonObject.put("message", "上传成功");
|
map.put("message", "上传成功");
|
||||||
jsonObject.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
map.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(mapper.writeValueAsString(map));
|
||||||
redisUtil.setEx(request.getRemoteAddr() + "-ImgUploadTimes", uploadTimes + 1 + "", 2, TimeUnit.HOURS);
|
redisUtil.setEx(request.getRemoteAddr() + "-ImgUploadTimes", uploadTimes + 1 + "", 2, TimeUnit.HOURS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
jsonObject.put("success", 0);
|
map.put("success", 0);
|
||||||
jsonObject.put("message", "上传失败,请上传图片文件");
|
map.put("message", "上传失败,请上传图片文件");
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(mapper.writeValueAsString(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/bingPic")
|
@GetMapping("/bingPic")
|
||||||
public Response bingPic() {
|
public Response bingPic() {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JSONObject imageObj;
|
JsonNode root;
|
||||||
try {
|
try {
|
||||||
imageObj = JSONObject.fromObject(HttpUtil.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"));
|
root = mapper.readTree(HttpUtil.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return Response.failure(null);
|
return Response.failure(null);
|
||||||
}
|
}
|
||||||
JSONArray jsonArray = imageObj.getJSONArray("images");
|
JsonNode images = root.get("images").elements().next();
|
||||||
String imageName = jsonArray.getJSONObject(0).getString("url");
|
return Response.success("https://cn.bing.com" + images.get("url").asText());
|
||||||
return Response.success("https://cn.bing.com" + imageName);
|
}
|
||||||
|
|
||||||
|
@PostMapping("/fileUpload")
|
||||||
|
public Response<List<Map<String, Object>>> fileUpload(@RequestParam("file[]") MultipartFile[] files) throws IOException {
|
||||||
|
List<Map<String, Object>> result = new ArrayList<>();
|
||||||
|
String uploadTimesStr = redisUtil.get(redisUserUtil.get().getEmail() + "-fileUploadTimes");
|
||||||
|
int uploadTimes = 0;
|
||||||
|
if (uploadTimesStr != null) {
|
||||||
|
uploadTimes = Integer.parseInt(uploadTimesStr);
|
||||||
|
}
|
||||||
|
if (uploadTimes == 10) {
|
||||||
|
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||||
|
}
|
||||||
|
if (files.length == 0) {
|
||||||
|
throw new MyException(ResponseEnum.NO_FILE);
|
||||||
|
}
|
||||||
|
for (MultipartFile file : files) {
|
||||||
|
Map<String, Object> resp = new HashMap<>(4);
|
||||||
|
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
assert fileName != null;
|
||||||
|
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||||
|
String name = fileName.replace(mime, "").replaceAll(" ", "");
|
||||||
|
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "file_" + name + '_' + System.currentTimeMillis() + mime);
|
||||||
|
resp.put("originalFilename", fileName);
|
||||||
|
resp.put("success", qiniuResponse != null);
|
||||||
|
if (qiniuResponse != null) {
|
||||||
|
resp.put("host", "http://cdn.celess.cn/");
|
||||||
|
resp.put("path", qiniuResponse.key);
|
||||||
|
}
|
||||||
|
result.add(resp);
|
||||||
|
}
|
||||||
|
return Response.success(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,18 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
|
||||||
import cn.celess.blog.service.MailService;
|
import cn.celess.blog.service.MailService;
|
||||||
import cn.celess.blog.service.PartnerSiteService;
|
import cn.celess.blog.service.PartnerSiteService;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.RegexUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -51,47 +46,24 @@ public class LinksController {
|
|||||||
|
|
||||||
@GetMapping("/links")
|
@GetMapping("/links")
|
||||||
public Response allForOpen() {
|
public Response allForOpen() {
|
||||||
List<PartnerSite> sites = new ArrayList<>();
|
List<PartnerSite> sites = partnerSiteService.findAll().stream().peek(partnerSite -> partnerSite.setOpen(null)).collect(Collectors.toList());
|
||||||
for (PartnerSite p : partnerSiteService.findAll()) {
|
|
||||||
if (p.getOpen()) {
|
|
||||||
//隐藏open字段
|
|
||||||
p.setOpen(null);
|
|
||||||
sites.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Response.success(sites);
|
return Response.success(sites);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/admin/links")
|
@GetMapping("/admin/links")
|
||||||
public Response all(@RequestParam("page") int page,
|
public Response all(@RequestParam("page") int page,
|
||||||
@RequestParam("count") int count) {
|
@RequestParam("count") int count,
|
||||||
return Response.success(partnerSiteService.partnerSitePages(page, count));
|
@RequestParam(value = "deleted", required = false) Boolean deleted) {
|
||||||
|
return Response.success(partnerSiteService.partnerSitePages(page, count, deleted));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/apply")
|
@PostMapping("/apply")
|
||||||
public Response apply(@RequestParam("name") String name,
|
public Response apply(@RequestBody() LinkApplyReq linkApplyReq) {
|
||||||
@RequestParam("url") String url) {
|
return Response.success(partnerSiteService.apply(linkApplyReq));
|
||||||
// TODO :: 弃用发送邮件的方式。
|
}
|
||||||
if (name == null || name.replaceAll(" ", "").isEmpty()) {
|
|
||||||
return Response.response(ResponseEnum.PARAMETERS_ERROR, null);
|
@PostMapping("/reapply")
|
||||||
}
|
public Response reapply(@RequestParam("key") String key) {
|
||||||
if (!RegexUtil.urlMatch(url)) {
|
return Response.success(partnerSiteService.reapply(key));
|
||||||
return Response.response(ResponseEnum.PARAMETERS_URL_ERROR, null);
|
|
||||||
}
|
|
||||||
String applyTimeStr = redisUtil.get(request.getRemoteAddr() + "-Apply");
|
|
||||||
int applyTime = 0;
|
|
||||||
if (applyTimeStr != null) {
|
|
||||||
applyTime = Integer.parseInt(applyTimeStr);
|
|
||||||
}
|
|
||||||
if (applyTime == 10) {
|
|
||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "申请次数已达10次,请2小时后重试");
|
|
||||||
}
|
|
||||||
SimpleMailMessage message = new SimpleMailMessage();
|
|
||||||
message.setSubject("友链申请:" + name);
|
|
||||||
message.setTo("a@celess.cn");
|
|
||||||
message.setText("name:" + name + "\nurl:" + url + "\n" + DateFormatUtil.getNow());
|
|
||||||
Boolean send = mailService.send(message);
|
|
||||||
redisUtil.setEx(request.getRemoteAddr() + "-Apply", applyTime + 1 + "", 2, TimeUnit.HOURS);
|
|
||||||
return send ? Response.success("") : Response.failure("");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.TagModel;
|
import cn.celess.blog.entity.model.TagModel;
|
||||||
import cn.celess.blog.service.TagService;
|
import cn.celess.blog.service.TagService;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -44,13 +45,13 @@ public class TagController {
|
|||||||
|
|
||||||
@GetMapping("/tags/nac")
|
@GetMapping("/tags/nac")
|
||||||
public Response getTagNameAndCount() {
|
public Response getTagNameAndCount() {
|
||||||
List<JSONObject> nameAndCount = new ArrayList<>();
|
List<Map<String, Object>> nameAndCount = new ArrayList<>();
|
||||||
List<TagModel> all = tagService.findAll();
|
List<TagModel> all = tagService.findAll();
|
||||||
for (TagModel t : all) {
|
for (TagModel t : all) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
Map<String, Object> map = new HashMap<>(2);
|
||||||
jsonObject.put("name", t.getName());
|
map.put("name", t.getName());
|
||||||
jsonObject.put("size", t.getArticles().size());
|
map.put("size", t.getArticles().size());
|
||||||
nameAndCount.add(jsonObject);
|
nameAndCount.add(map);
|
||||||
}
|
}
|
||||||
return Response.success(nameAndCount);
|
return Response.success(nameAndCount);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/admin/users")
|
@GetMapping("/admin/users")
|
||||||
public Response getAllUser(@RequestParam("page") int pageNum, @RequestParam("count") int count) {
|
public Response getAllUser(@RequestParam("page") int pageNum, @RequestParam("count") int count, @RequestParam(name = "status", required = false) Integer status) {
|
||||||
return Response.success(userService.getUserList(pageNum, count));
|
return Response.success(userService.getUserList(pageNum, count, status));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/emailStatus/{email}")
|
@GetMapping("/emailStatus/{email}")
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class VisitorController {
|
|||||||
@GetMapping("/admin/visitor/page")
|
@GetMapping("/admin/visitor/page")
|
||||||
public Response page(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
public Response page(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
|
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
|
||||||
@RequestParam(value = "showLocation", required = false, defaultValue = "false") boolean showLocation) {
|
@RequestParam(value = "showLocation", required = false, defaultValue = "true") boolean showLocation) {
|
||||||
return Response.success(visitorService.visitorPage(page, count, showLocation));
|
return Response.success(visitorService.visitorPage(page, count, showLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public enum ResponseEnum {
|
|||||||
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
||||||
LOGIN_EXPIRED(3700, "登陆过期"),
|
LOGIN_EXPIRED(3700, "登陆过期"),
|
||||||
LOGOUT(3710, "账户已注销"),
|
LOGOUT(3710, "账户已注销"),
|
||||||
|
CAN_NOT_USE(3711, "账户不可用"),
|
||||||
PWD_WRONG(3800, "密码不正确"),
|
PWD_WRONG(3800, "密码不正确"),
|
||||||
|
|
||||||
JWT_EXPIRED(3810, "Token过期"),
|
JWT_EXPIRED(3810, "Token过期"),
|
||||||
@@ -58,6 +59,11 @@ public enum ResponseEnum {
|
|||||||
DATA_HAS_EXIST(7020, "数据已存在"),
|
DATA_HAS_EXIST(7020, "数据已存在"),
|
||||||
|
|
||||||
//其他
|
//其他
|
||||||
|
APPLY_LINK_NO_ADD_THIS_SITE(7200, "暂未在您的网站中抓取到本站链接"),
|
||||||
|
DATA_EXPIRED(7300, "数据过期"),
|
||||||
|
CANNOT_GET_DATA(7400, "暂无法获取到数据"),
|
||||||
|
NO_FILE(7500, "未选择文件,请重新选择"),
|
||||||
|
|
||||||
|
|
||||||
//提交更新之前,没有获取数据/,
|
//提交更新之前,没有获取数据/,
|
||||||
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package cn.celess.blog.enmu;
|
package cn.celess.blog.enmu;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 小海
|
* @Author: 小海
|
||||||
* @Date: 2020-05-22 21:32
|
* @Date: 2020-05-22 21:32
|
||||||
@@ -36,4 +42,31 @@ public enum UserAccountStatusEnum {
|
|||||||
public String getDesc() {
|
public String getDesc() {
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UserAccountStatusEnum get(int code) {
|
||||||
|
for (UserAccountStatusEnum value : UserAccountStatusEnum.values()) {
|
||||||
|
if (value.code == code) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public static UserAccountStatusEnum get(Map<String, Object> map) {
|
||||||
|
for (UserAccountStatusEnum value : UserAccountStatusEnum.values()) {
|
||||||
|
if (value.code == (int) map.get("code") && value.desc.equals(map.get("desc"))) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public Map<String, Object> toJson() {
|
||||||
|
Map<String, Object> map = new HashMap<>(2);
|
||||||
|
map.put("code", code);
|
||||||
|
map.put("desc", desc);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ public class PartnerSite {
|
|||||||
|
|
||||||
private Boolean delete = false;
|
private Boolean delete = false;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private Boolean notification = true;
|
||||||
|
|
||||||
public PartnerSite() {
|
public PartnerSite() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.blog.entity;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.sf.json.JSONObject;
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@@ -31,8 +32,8 @@ public class Response<T> implements Serializable {
|
|||||||
* @param result 结果
|
* @param result 结果
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public static Response success(Object result) {
|
public static <T> Response<T> success(T result) {
|
||||||
return new Response(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), result);
|
return new Response<T>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,8 +42,8 @@ public class Response<T> implements Serializable {
|
|||||||
* @param result 结果
|
* @param result 结果
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public static Response failure(String result) {
|
public static Response<String> failure(String result) {
|
||||||
return new Response(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMsg(), result);
|
return new Response<String>(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMsg(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,13 +53,13 @@ public class Response<T> implements Serializable {
|
|||||||
* @param result 结果
|
* @param result 结果
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public static Response response(ResponseEnum r, String result) {
|
public static <T> Response<T> response(ResponseEnum r, T result) {
|
||||||
return new Response(r.getCode(), r.getMsg(), result);
|
return new Response<T>(r.getCode(), r.getMsg(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(this);
|
return new ObjectMapper().writeValueAsString(this);
|
||||||
return jsonObject.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.blog.entity.model;
|
||||||
|
|
||||||
|
import cn.celess.blog.enmu.UserAccountStatusEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -38,5 +39,5 @@ public class UserModel {
|
|||||||
|
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
private int status;
|
private UserAccountStatusEnum status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package cn.celess.blog.entity.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2020/07/31 20:50
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LinkApplyReq {
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private String url;
|
||||||
|
private String linkUrl;
|
||||||
|
private String desc;
|
||||||
|
private String iconPath;
|
||||||
|
}
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
package cn.celess.blog.entity.request;
|
package cn.celess.blog.entity.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/06/01 22:47
|
* @date : 2019/06/01 22:47
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class LoginReq {
|
public class LoginReq {
|
||||||
private String email;
|
private String email;
|
||||||
private String password;
|
private String password;
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ public class ExceptionHandle {
|
|||||||
public Response handle(Exception e) {
|
public Response handle(Exception e) {
|
||||||
//自定义错误
|
//自定义错误
|
||||||
if (e instanceof MyException) {
|
if (e instanceof MyException) {
|
||||||
logger.debug("返回了自定义的exception,[code={},msg={}]", ((MyException) e).getCode(), e.getMessage());
|
MyException exception = (MyException) e;
|
||||||
return new Response(((MyException) e).getCode(), e.getMessage(), null);
|
logger.debug("返回了自定义的exception,[code={},msg={},result={}]", exception.getCode(), e.getMessage(), exception.getResult());
|
||||||
|
return new Response(exception.getCode(), e.getMessage(), exception.getResult());
|
||||||
}
|
}
|
||||||
//请求路径不支持该方法
|
//请求路径不支持该方法
|
||||||
if (e instanceof HttpRequestMethodNotSupportedException) {
|
if (e instanceof HttpRequestMethodNotSupportedException) {
|
||||||
@@ -82,7 +83,12 @@ public class ExceptionHandle {
|
|||||||
simpleMailMessage.setTo("a@celess.cn");
|
simpleMailMessage.setTo("a@celess.cn");
|
||||||
simpleMailMessage.setSubject("服务器出现了错误");
|
simpleMailMessage.setSubject("服务器出现了错误");
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append("requirePath:\n").append(request.getRequestURL().toString()).append("?").append(request.getQueryString()).append("\n\n\n");
|
String queryString = request.getQueryString();
|
||||||
|
msg.append("requirePath:\n").append(request.getRequestURL().toString());
|
||||||
|
if (queryString != null) {
|
||||||
|
msg.append("?").append(queryString);
|
||||||
|
}
|
||||||
|
msg.append("\n\n\n");
|
||||||
msg.append("msg:\n").append(e.getMessage()).append("\n\n\n");
|
msg.append("msg:\n").append(e.getMessage()).append("\n\n\n");
|
||||||
msg.append("date:\n").append(DateFormatUtil.getNow()).append("\n\n\n");
|
msg.append("date:\n").append(DateFormatUtil.getNow()).append("\n\n\n");
|
||||||
msg.append("from:\n").append(request.getHeader("User-Agent")).append("\n\n\n");
|
msg.append("from:\n").append(request.getHeader("User-Agent")).append("\n\n\n");
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
package cn.celess.blog.exception;
|
package cn.celess.blog.exception;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/03/28 16:56
|
* @date : 2019/03/28 16:56
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class MyException extends RuntimeException {
|
public class MyException extends RuntimeException {
|
||||||
private int code;
|
private int code;
|
||||||
|
private Object result;
|
||||||
|
|
||||||
public MyException(int code, String msg) {
|
public MyException(int code, String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@@ -19,16 +22,20 @@ public class MyException extends RuntimeException {
|
|||||||
this.code = e.getCode();
|
this.code = e.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MyException(ResponseEnum e, Object result) {
|
||||||
|
super(e.getMsg());
|
||||||
|
this.code = e.getCode();
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
public MyException(ResponseEnum e, String msg) {
|
public MyException(ResponseEnum e, String msg) {
|
||||||
super(msg + e.getMsg());
|
super(msg + e.getMsg());
|
||||||
this.code = e.getCode();
|
this.code = e.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCode() {
|
public MyException(ResponseEnum e, String msg, Object result) {
|
||||||
return code;
|
super(e.getMsg());
|
||||||
}
|
this.code = e.getCode();
|
||||||
|
this.result = result;
|
||||||
public void setCode(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cn.celess.blog.mapper;
|
package cn.celess.blog.mapper;
|
||||||
|
|
||||||
import cn.celess.blog.entity.ArticleTag;
|
import cn.celess.blog.entity.ArticleTag;
|
||||||
|
import cn.celess.blog.entity.Tag;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@@ -27,6 +28,8 @@ public interface ArticleTagMapper {
|
|||||||
|
|
||||||
List<ArticleTag> findAllByArticleId(Long articleId);
|
List<ArticleTag> findAllByArticleId(Long articleId);
|
||||||
|
|
||||||
|
List<Tag> findTagByArticleId(Long articleId);
|
||||||
|
|
||||||
int deleteMultiById(List<ArticleTag> articleTags);
|
int deleteMultiById(List<ArticleTag> articleTags);
|
||||||
|
|
||||||
List<ArticleTag> findArticleByTag(Long tagId);
|
List<ArticleTag> findArticleByTag(Long tagId);
|
||||||
|
|||||||
@@ -36,5 +36,6 @@ public interface PartnerMapper {
|
|||||||
|
|
||||||
List<PartnerSite> findAll();
|
List<PartnerSite> findAll();
|
||||||
|
|
||||||
|
List<PartnerSite> findAll(Boolean deleted);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ public interface UserMapper {
|
|||||||
|
|
||||||
int setUserRole(Long id, String role);
|
int setUserRole(Long id, String role);
|
||||||
|
|
||||||
|
List<User> findAll(Integer status);
|
||||||
|
|
||||||
List<User> findAll();
|
List<User> findAll();
|
||||||
|
|
||||||
int update(User user);
|
int update(User user);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public interface ArticleService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageData<ArticleModel> adminArticles(int count, int page, boolean deleted);
|
PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文章状态为开放的文章
|
* 获取文章状态为开放的文章
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.celess.blog.service;
|
|||||||
|
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ public interface PartnerSiteService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageData<PartnerSite> partnerSitePages(int page, int count);
|
PageData<PartnerSite> partnerSitePages(int page, int count, Boolean deleted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部数据
|
* 获取全部数据
|
||||||
@@ -53,4 +54,19 @@ public interface PartnerSiteService {
|
|||||||
*/
|
*/
|
||||||
List<PartnerSite> findAll();
|
List<PartnerSite> findAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请友链
|
||||||
|
*
|
||||||
|
* @param linkApplyReq linkApplyReq
|
||||||
|
* @return linkApplyReq
|
||||||
|
*/
|
||||||
|
PartnerSite apply(LinkApplyReq linkApplyReq);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写申请友链
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @return msg
|
||||||
|
*/
|
||||||
|
String reapply(String key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public interface UserService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageData<UserModel> getUserList(Integer page, Integer count);
|
PageData<UserModel> getUserList(Integer page, Integer count, Integer status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更改用户信息
|
* 更改用户信息
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package cn.celess.blog.service;
|
|||||||
|
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -59,5 +59,5 @@ public interface WebUpdateInfoService {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JSONObject getLastestUpdateTime();
|
Map<String, Object> getLastestUpdateTime();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.springframework.beans.BeanUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import sun.security.krb5.internal.PAData;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -279,17 +278,21 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
* @return PageInfo
|
* @return PageInfo
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageData<ArticleModel> adminArticles(int count, int page, boolean deleted) {
|
public PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted) {
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
List<Article> articleList = articleMapper.findAll();
|
List<Article> articleList = articleMapper.findAll();
|
||||||
|
|
||||||
PageData<ArticleModel> pageData = new PageData<>(null, 0, count, page);
|
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<>(articleList));
|
||||||
List<Article> collect = articleList.stream().filter(article -> article.isDeleted() == deleted).collect(Collectors.toList());
|
|
||||||
pageData.setTotal(collect.size());
|
List<Article> collect;
|
||||||
|
if (deleted != null) {
|
||||||
|
collect = articleList.stream().filter(article -> article.isDeleted() == deleted).collect(Collectors.toList());
|
||||||
|
} else {
|
||||||
|
collect = articleList;
|
||||||
|
}
|
||||||
List<ArticleModel> articleModels = collect.stream()
|
List<ArticleModel> articleModels = collect.stream()
|
||||||
.peek(article -> article.setMdContent(null))
|
.peek(article -> article.setMdContent(null))
|
||||||
.map(ModalTrans::article)
|
.map(ModalTrans::article)
|
||||||
.skip((page - 1) * count)
|
|
||||||
.limit(count)
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
pageData.setList(articleModels);
|
pageData.setList(articleModels);
|
||||||
|
|
||||||
@@ -300,16 +303,12 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
public PageData<ArticleModel> retrievePageForOpen(int count, int page) {
|
public PageData<ArticleModel> retrievePageForOpen(int count, int page) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Article> articleList = articleMapper.findAllByOpen(true);
|
List<Article> articleList = articleMapper.findAllByOpen(true);
|
||||||
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<Article>(articleList));
|
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<>(articleList));
|
||||||
|
|
||||||
List<ArticleModel> articleModelList = new ArrayList<>();
|
|
||||||
|
|
||||||
articleList.forEach(article -> {
|
|
||||||
ArticleModel model = ModalTrans.article(article, true);
|
|
||||||
setPreAndNextArticle(model);
|
|
||||||
articleModelList.add(model);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
List<ArticleModel> articleModelList = articleList
|
||||||
|
.stream()
|
||||||
|
.map(article -> setPreAndNextArticle(ModalTrans.article(article, true)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
pageData.setList(articleModelList);
|
pageData.setList(articleModelList);
|
||||||
return pageData;
|
return pageData;
|
||||||
}
|
}
|
||||||
@@ -323,17 +322,14 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Article> open = articleMapper.findAllByCategoryIdAndOpen(category.getId());
|
List<Article> open = articleMapper.findAllByCategoryIdAndOpen(category.getId());
|
||||||
|
|
||||||
List<ArticleModel> modelList = new ArrayList<>();
|
List<ArticleModel> modelList = open.stream()
|
||||||
|
.map(article -> ModalTrans.article(article, true))
|
||||||
open.forEach(article -> {
|
.peek(articleModel -> {
|
||||||
ArticleModel model = ModalTrans.article(article, true);
|
articleModel.setNextArticle(null);
|
||||||
model.setTags(null);
|
articleModel.setPreArticle(null);
|
||||||
// setPreAndNextArticle(model);
|
})
|
||||||
model.setNextArticle(null);
|
.collect(Collectors.toList());
|
||||||
model.setPreArticle(null);
|
return new PageData<>(new PageInfo<>(open), modelList);
|
||||||
modelList.add(model);
|
|
||||||
});
|
|
||||||
return new PageData<ArticleModel>(new PageInfo<Article>(open), modelList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -344,21 +340,22 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
}
|
}
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTagAndOpen(tag.getId());
|
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTagAndOpen(tag.getId());
|
||||||
List<ArticleModel> modelList = new ArrayList<>();
|
List<ArticleModel> modelList = articleByTag
|
||||||
articleByTag.forEach(articleTag -> {
|
.stream()
|
||||||
ArticleModel model = ModalTrans.article(articleTag.getArticle(), true);
|
.map(articleTag -> ModalTrans.article(articleTag.getArticle(), true))
|
||||||
model.setNextArticle(null);
|
.peek(articleModel -> {
|
||||||
model.setPreArticle(null);
|
articleModel.setNextArticle(null);
|
||||||
modelList.add(model);
|
articleModel.setPreArticle(null);
|
||||||
});
|
}).collect(Collectors.toList());
|
||||||
return new PageData<ArticleModel>(new PageInfo<ArticleTag>(articleByTag), modelList);
|
return new PageData<>(new PageInfo<>(articleByTag), modelList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPreAndNextArticle(ArticleModel articleModel) {
|
private ArticleModel setPreAndNextArticle(ArticleModel articleModel) {
|
||||||
if (articleModel == null) {
|
if (articleModel == null) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(articleModel.getId()), true));
|
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(articleModel.getId()), true));
|
||||||
articleModel.setNextArticle(ModalTrans.article(articleMapper.getNextArticle(articleModel.getId()), true));
|
articleModel.setNextArticle(ModalTrans.article(articleMapper.getNextArticle(articleModel.getId()), true));
|
||||||
|
return articleModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -68,22 +68,25 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
public PageData<CategoryModel> retrievePage(int page, int count) {
|
public PageData<CategoryModel> retrievePage(int page, int count) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Category> all = categoryMapper.findAll();
|
List<Category> all = categoryMapper.findAll();
|
||||||
List<CategoryModel> modelList = new ArrayList<>();
|
// 遍历没一个category
|
||||||
all.forEach(e -> {
|
List<CategoryModel> modelList = all
|
||||||
CategoryModel model = ModalTrans.category(e);
|
.stream()
|
||||||
List<Article> allByCategoryId = articleMapper.findAllByCategoryId(e.getId());
|
.map(ModalTrans::category)
|
||||||
List<ArticleModel> articleModelList = new ArrayList<>();
|
.peek(categoryModel -> {
|
||||||
allByCategoryId.forEach(article -> {
|
// 根据category去查article,并赋值给categoryModel
|
||||||
ArticleModel articleModel = ModalTrans.article(article, true);
|
List<Article> allByCategoryId = articleMapper.findAllByCategoryId(categoryModel.getId());
|
||||||
articleModel.setPreArticle(null);
|
List<ArticleModel> articleModelList = allByCategoryId
|
||||||
articleModel.setNextArticle(null);
|
.stream()
|
||||||
articleModel.setTags(null);
|
.map(article -> ModalTrans.article(article, true))
|
||||||
articleModelList.add(articleModel);
|
.peek(articleModel -> {
|
||||||
});
|
// 去除不必要的字段
|
||||||
model.setArticles(articleModelList);
|
articleModel.setPreArticle(null);
|
||||||
modelList.add(model);
|
articleModel.setNextArticle(null);
|
||||||
});
|
articleModel.setTags(null);
|
||||||
|
})
|
||||||
return new PageData<CategoryModel>(new PageInfo<Category>(all), modelList);
|
.collect(Collectors.toList());
|
||||||
|
categoryModel.setArticles(articleModelList);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return new PageData<>(new PageInfo<>(all), modelList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -59,7 +60,7 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
Comment comment = new Comment();
|
Comment comment = new Comment();
|
||||||
comment.setFromUser(user);
|
comment.setFromUser(user);
|
||||||
User userTo = new User();
|
User userTo = new User();
|
||||||
userTo.setId(-1L);
|
userTo.setId(null);
|
||||||
if (reqBody.getToUserId() != -1) {
|
if (reqBody.getToUserId() != -1) {
|
||||||
userTo = userMapper.findById(reqBody.getToUserId());
|
userTo = userMapper.findById(reqBody.getToUserId());
|
||||||
comment.setToUser(userTo);
|
comment.setToUser(userTo);
|
||||||
@@ -107,14 +108,11 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
@Override
|
@Override
|
||||||
public List<CommentModel> retrievePageByPid(long pid) {
|
public List<CommentModel> retrievePageByPid(long pid) {
|
||||||
List<Comment> allByPagePath = commentMapper.findAllByPid(pid);
|
List<Comment> allByPagePath = commentMapper.findAllByPid(pid);
|
||||||
List<CommentModel> commentModels = new ArrayList<>();
|
return allByPagePath
|
||||||
allByPagePath.forEach(comment -> {
|
.stream()
|
||||||
if (comment.getStatus() != CommentStatusEnum.DELETED.getCode()) {
|
.filter(comment -> comment.getStatus() != CommentStatusEnum.DELETED.getCode())
|
||||||
commentModels.add(ModalTrans.comment(comment));
|
.map(ModalTrans::comment)
|
||||||
}
|
.collect(Collectors.toList());
|
||||||
});
|
|
||||||
|
|
||||||
return commentModels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -145,14 +143,11 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
|
|
||||||
private PageData<CommentModel> pageTrans(List<Comment> commentList, boolean noResponseList) {
|
private PageData<CommentModel> pageTrans(List<Comment> commentList, boolean noResponseList) {
|
||||||
PageInfo<Comment> p = PageInfo.of(commentList);
|
PageInfo<Comment> p = PageInfo.of(commentList);
|
||||||
List<CommentModel> modelList = new ArrayList<>();
|
List<CommentModel> modelList = commentList
|
||||||
commentList.forEach(l -> {
|
.stream()
|
||||||
CommentModel model = ModalTrans.comment(l);
|
.map(ModalTrans::comment)
|
||||||
if (!noResponseList) {
|
.peek(commentModel -> commentModel.setRespComment(this.retrievePageByPid(commentModel.getId())))
|
||||||
model.setRespComment(this.retrievePageByPid(model.getId()));
|
.collect(Collectors.toList());
|
||||||
}
|
return new PageData<>(p, modelList);
|
||||||
modelList.add(model);
|
|
||||||
});
|
|
||||||
return new PageData<CommentModel>(p, modelList);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,29 @@ package cn.celess.blog.service.serviceimpl;
|
|||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.PartnerMapper;
|
import cn.celess.blog.mapper.PartnerMapper;
|
||||||
|
import cn.celess.blog.service.MailService;
|
||||||
import cn.celess.blog.service.PartnerSiteService;
|
import cn.celess.blog.service.PartnerSiteService;
|
||||||
|
import cn.celess.blog.util.HttpUtil;
|
||||||
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.RegexUtil;
|
import cn.celess.blog.util.RegexUtil;
|
||||||
|
import com.alibaba.druid.util.StringUtils;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -24,6 +35,13 @@ import java.util.List;
|
|||||||
public class PartnerSiteServiceImpl implements PartnerSiteService {
|
public class PartnerSiteServiceImpl implements PartnerSiteService {
|
||||||
@Autowired
|
@Autowired
|
||||||
PartnerMapper partnerMapper;
|
PartnerMapper partnerMapper;
|
||||||
|
@Autowired
|
||||||
|
MailService mailService;
|
||||||
|
@Autowired
|
||||||
|
RedisUtil redisUtil;
|
||||||
|
private static final String SITE_NAME = "小海博客";
|
||||||
|
private static final String SITE_URL = "celess.cn";
|
||||||
|
private static final String SITE_EMAIL = "a@celess.cn";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PartnerSite create(LinkReq reqBody) {
|
public PartnerSite create(LinkReq reqBody) {
|
||||||
@@ -86,17 +104,28 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
if (!reqBody.getUrl().contains("http://") && !reqBody.getUrl().contains("https://")) {
|
if (!reqBody.getUrl().contains("http://") && !reqBody.getUrl().contains("https://")) {
|
||||||
reqBody.setUrl("http://" + reqBody.getUrl());
|
reqBody.setUrl("http://" + reqBody.getUrl());
|
||||||
}
|
}
|
||||||
|
if (reqBody.isOpen() != partnerSite.getOpen() && !partnerSite.getNotification() && !StringUtils.isEmpty(partnerSite.getEmail())) {
|
||||||
|
SimpleMailMessage smm = new SimpleMailMessage();
|
||||||
|
smm.setTo(partnerSite.getEmail());
|
||||||
|
smm.setText("您的友链申请,已通过");
|
||||||
|
smm.setSubject("友链申请通过");
|
||||||
|
smm.setSentDate(new Date());
|
||||||
|
mailService.send(smm);
|
||||||
|
partnerSite.setNotification(true);
|
||||||
|
}
|
||||||
|
BeanUtils.copyProperties(reqBody, partnerSite);
|
||||||
|
partnerMapper.update(partnerSite);
|
||||||
partnerSite.setName(reqBody.getName());
|
partnerSite.setName(reqBody.getName());
|
||||||
partnerSite.setUrl(reqBody.getUrl());
|
partnerSite.setUrl(reqBody.getUrl());
|
||||||
partnerSite.setOpen(reqBody.isOpen());
|
partnerSite.setOpen(reqBody.isOpen());
|
||||||
partnerMapper.update(partnerSite);
|
|
||||||
return partnerSite;
|
return partnerSite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageData<PartnerSite> partnerSitePages(int page, int count) {
|
public PageData<PartnerSite> partnerSitePages(int page, int count, Boolean deleted) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<PartnerSite> sitePage = partnerMapper.findAll();
|
List<PartnerSite> sitePage = partnerMapper.findAll(deleted);
|
||||||
PageInfo<PartnerSite> pageInfo = new PageInfo<PartnerSite>(sitePage);
|
PageInfo<PartnerSite> pageInfo = new PageInfo<PartnerSite>(sitePage);
|
||||||
return new PageData<>(pageInfo, sitePage);
|
return new PageData<>(pageInfo, sitePage);
|
||||||
}
|
}
|
||||||
@@ -108,5 +137,92 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public PartnerSite apply(LinkApplyReq linkApplyReq) {
|
||||||
|
// 空值字段
|
||||||
|
if (StringUtils.isEmpty(linkApplyReq.getName())
|
||||||
|
|| StringUtils.isEmpty(linkApplyReq.getUrl())
|
||||||
|
|| StringUtils.isEmpty(linkApplyReq.getEmail())
|
||||||
|
|| StringUtils.isEmpty(linkApplyReq.getLinkUrl())) {
|
||||||
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
// 链接不合法
|
||||||
|
if (!RegexUtil.emailMatch(linkApplyReq.getEmail())) {
|
||||||
|
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||||
|
}
|
||||||
|
if (!RegexUtil.urlMatch(linkApplyReq.getLinkUrl()) || !RegexUtil.urlMatch(linkApplyReq.getUrl())) {
|
||||||
|
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
|
}
|
||||||
|
if (!StringUtils.isEmpty(linkApplyReq.getIconPath()) && !RegexUtil.urlMatch(linkApplyReq.getIconPath())) {
|
||||||
|
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
|
}
|
||||||
|
// 非强制字段 设置空
|
||||||
|
if (StringUtils.isEmpty(linkApplyReq.getIconPath())) {
|
||||||
|
linkApplyReq.setIconPath("");
|
||||||
|
}
|
||||||
|
// 抓取页面
|
||||||
|
String resp = HttpUtil.getAfterRendering(linkApplyReq.getLinkUrl());
|
||||||
|
if (resp == null) {
|
||||||
|
throw new MyException(ResponseEnum.CANNOT_GET_DATA);
|
||||||
|
}
|
||||||
|
PartnerSite ps = new PartnerSite();
|
||||||
|
if (resp.contains(SITE_URL)) {
|
||||||
|
//包含站点
|
||||||
|
BeanUtils.copyProperties(linkApplyReq, ps);
|
||||||
|
ps.setNotification(false);
|
||||||
|
ps.setOpen(false);
|
||||||
|
boolean exists = partnerMapper.existsByUrl(linkApplyReq.getUrl());
|
||||||
|
if (!exists) {
|
||||||
|
partnerMapper.insert(ps);
|
||||||
|
} else {
|
||||||
|
ps.setId(partnerMapper.findByUrl(linkApplyReq.getUrl()).getId());
|
||||||
|
}
|
||||||
|
SimpleMailMessage smm = new SimpleMailMessage();
|
||||||
|
smm.setSubject("友链申请");
|
||||||
|
smm.setText("有一条友链申请" + (exists ? ",已存在的友链链接" : "") + ",[\n" + linkApplyReq.toString() + "\n]");
|
||||||
|
smm.setTo(SITE_EMAIL);
|
||||||
|
smm.setSentDate(new Date());
|
||||||
|
mailService.send(smm);
|
||||||
|
} else {
|
||||||
|
// 不包含站点
|
||||||
|
String uuid;
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
if (redisUtil.hasKey(linkApplyReq.getUrl())) {
|
||||||
|
uuid = redisUtil.get(linkApplyReq.getUrl());
|
||||||
|
if (!redisUtil.hasKey(uuid)) {
|
||||||
|
redisUtil.setEx(uuid, mapper.writeValueAsString(linkApplyReq), 10, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
|
redisUtil.setEx(uuid, mapper.writeValueAsString(linkApplyReq), 10, TimeUnit.MINUTES);
|
||||||
|
redisUtil.setEx(linkApplyReq.getUrl(), uuid, 10, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
throw new MyException(ResponseEnum.APPLY_LINK_NO_ADD_THIS_SITE, null, uuid);
|
||||||
|
}
|
||||||
|
return ps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public String reapply(String key) {
|
||||||
|
if (!redisUtil.hasKey(key)) {
|
||||||
|
throw new MyException(ResponseEnum.DATA_EXPIRED);
|
||||||
|
}
|
||||||
|
String s = redisUtil.get(key);
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
LinkApplyReq linkApplyReq = mapper.readValue(s, LinkApplyReq.class);
|
||||||
|
if (linkApplyReq == null) {
|
||||||
|
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
|
}
|
||||||
|
SimpleMailMessage smm = new SimpleMailMessage();
|
||||||
|
smm.setSubject("友链申请");
|
||||||
|
smm.setText("有一条未抓取到信息的友链申请,[\n" + linkApplyReq.toString() + "\n]");
|
||||||
|
smm.setTo(SITE_EMAIL);
|
||||||
|
smm.setSentDate(new Date());
|
||||||
|
mailService.send(smm);
|
||||||
|
redisUtil.delete(key);
|
||||||
|
redisUtil.delete(linkApplyReq.getUrl());
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -81,20 +82,22 @@ public class TagServiceImpl implements TagService {
|
|||||||
List<Tag> tagList = tagMapper.findAll();
|
List<Tag> tagList = tagMapper.findAll();
|
||||||
List<TagModel> modelList = new ArrayList<>();
|
List<TagModel> modelList = new ArrayList<>();
|
||||||
tagList.forEach(tag -> modelList.add(ModalTrans.tag(tag)));
|
tagList.forEach(tag -> modelList.add(ModalTrans.tag(tag)));
|
||||||
return new PageData<TagModel>(new PageInfo<Tag>(tagList), modelList);
|
return new PageData<>(new PageInfo<>(tagList), modelList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TagModel> findAll() {
|
public List<TagModel> findAll() {
|
||||||
List<TagModel> list = new ArrayList<>();
|
return tagMapper.findAll().stream()
|
||||||
tagMapper.findAll().forEach(e -> {
|
.map(ModalTrans::tag)
|
||||||
TagModel model = ModalTrans.tag(e);
|
.peek(tagModel -> {
|
||||||
List<ArticleTag> articleByTagAndOpen = articleTagMapper.findArticleByTagAndOpen(e.getId());
|
List<ArticleTag> articleByTagAndOpen = articleTagMapper.findArticleByTagAndOpen(tagModel.getId());
|
||||||
List<ArticleModel> articleModelList = new ArrayList<>();
|
tagModel.setArticles(
|
||||||
articleByTagAndOpen.forEach(articleTag -> articleModelList.add(ModalTrans.article(articleTag.getArticle(), true)));
|
articleByTagAndOpen
|
||||||
model.setArticles(articleModelList);
|
.stream()
|
||||||
list.add(model);
|
.map(articleTag -> ModalTrans.article(articleTag.getArticle(), true))
|
||||||
});
|
.collect(Collectors.toList())
|
||||||
return list;
|
);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.celess.blog.service.serviceimpl;
|
|||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.enmu.RoleEnum;
|
import cn.celess.blog.enmu.RoleEnum;
|
||||||
|
import cn.celess.blog.enmu.UserAccountStatusEnum;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.User;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
@@ -17,8 +18,6 @@ import cn.celess.blog.service.UserService;
|
|||||||
import cn.celess.blog.util.*;
|
import cn.celess.blog.util.*;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import net.sf.json.JSONArray;
|
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -28,10 +27,9 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.beans.Transient;
|
import java.beans.Transient;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -102,6 +100,16 @@ public class UserServiceImpl implements UserService {
|
|||||||
if (!RegexUtil.pwdMatch(loginReq.getPassword())) {
|
if (!RegexUtil.pwdMatch(loginReq.getPassword())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User user = userMapper.findByEmail(loginReq.getEmail());
|
||||||
|
if (user == null) {
|
||||||
|
// 用户不存在
|
||||||
|
throw new MyException(ResponseEnum.USER_NOT_EXIST);
|
||||||
|
}
|
||||||
|
if (user.getStatus() != UserAccountStatusEnum.NORMAL.getCode()) {
|
||||||
|
throw new MyException(ResponseEnum.CAN_NOT_USE, UserAccountStatusEnum.get(user.getStatus()));
|
||||||
|
}
|
||||||
|
|
||||||
//获取redis缓存中登录失败次数
|
//获取redis缓存中登录失败次数
|
||||||
String s = redisUtil.get(loginReq.getEmail() + "-passwordWrongTime");
|
String s = redisUtil.get(loginReq.getEmail() + "-passwordWrongTime");
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
@@ -109,14 +117,9 @@ public class UserServiceImpl implements UserService {
|
|||||||
throw new MyException(ResponseEnum.LOGIN_LATER, loginReq.getEmail());
|
throw new MyException(ResponseEnum.LOGIN_LATER, loginReq.getEmail());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
User user = null;
|
|
||||||
user = userMapper.findByEmail(loginReq.getEmail());
|
String token;
|
||||||
String token = null;
|
|
||||||
// 密码比对
|
// 密码比对
|
||||||
if (user == null) {
|
|
||||||
// 用户不存在
|
|
||||||
throw new MyException(ResponseEnum.USER_NOT_EXIST);
|
|
||||||
}
|
|
||||||
if (user.getPwd().equals(MD5Util.getMD5(loginReq.getPassword()))) {
|
if (user.getPwd().equals(MD5Util.getMD5(loginReq.getPassword()))) {
|
||||||
logger.info("====> {} 进行权限认证 状态:登录成功 <====", loginReq.getEmail());
|
logger.info("====> {} 进行权限认证 状态:登录成功 <====", loginReq.getEmail());
|
||||||
userMapper.updateLoginTime(loginReq.getEmail());
|
userMapper.updateLoginTime(loginReq.getEmail());
|
||||||
@@ -312,14 +315,14 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object deleteUser(Integer[] id) {
|
public Object deleteUser(Integer[] id) {
|
||||||
JSONArray status = new JSONArray();
|
List<Map<String, Object>> status = new ArrayList<>();
|
||||||
if (id == null || id.length == 0) {
|
if (id == null || id.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Integer integer : id) {
|
for (Integer integer : id) {
|
||||||
String role = userMapper.getRoleById(integer);
|
String role = userMapper.getRoleById(integer);
|
||||||
int deleteResult = 0;
|
int deleteResult = 0;
|
||||||
JSONObject deleteStatus = new JSONObject();
|
Map<String, Object> deleteStatus = new HashMap<>(3);
|
||||||
deleteStatus.put("id", integer);
|
deleteStatus.put("id", integer);
|
||||||
// 管理员账户不可删
|
// 管理员账户不可删
|
||||||
if ("admin".equals(role)) {
|
if ("admin".equals(role)) {
|
||||||
@@ -342,12 +345,11 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageData<UserModel> getUserList(Integer page, Integer count) {
|
public PageData<UserModel> getUserList(Integer page, Integer count, Integer status) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<User> all = userMapper.findAll();
|
List<User> all = userMapper.findAll(status);
|
||||||
List<UserModel> modelList = new ArrayList<>();
|
List<UserModel> modelList = all.stream().map(ModalTrans::userFullInfo).collect(Collectors.toList());
|
||||||
all.forEach(user -> modelList.add(ModalTrans.userFullInfo(user)));
|
return new PageData<>(PageInfo.of(all), modelList);
|
||||||
return new PageData<UserModel>(PageInfo.of(all), modelList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import cn.celess.blog.entity.model.VisitorModel;
|
|||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.VisitorMapper;
|
import cn.celess.blog.mapper.VisitorMapper;
|
||||||
import cn.celess.blog.service.VisitorService;
|
import cn.celess.blog.service.VisitorService;
|
||||||
|
import cn.celess.blog.util.AddressUtil;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
import cn.celess.blog.util.DateFormatUtil;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
@@ -15,7 +16,6 @@ import eu.bitwalker.useragentutils.Browser;
|
|||||||
import eu.bitwalker.useragentutils.OperatingSystem;
|
import eu.bitwalker.useragentutils.OperatingSystem;
|
||||||
import eu.bitwalker.useragentutils.UserAgent;
|
import eu.bitwalker.useragentutils.UserAgent;
|
||||||
import eu.bitwalker.useragentutils.Version;
|
import eu.bitwalker.useragentutils.Version;
|
||||||
import org.apache.commons.lang.time.DateUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.json.JsonParserFactory;
|
import org.springframework.boot.json.JsonParserFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -26,6 +26,8 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -49,7 +51,7 @@ public class VisitorServiceImpl implements VisitorService {
|
|||||||
public PageData<VisitorModel> visitorPage(int page, int count, boolean showLocation) {
|
public PageData<VisitorModel> visitorPage(int page, int count, boolean showLocation) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Visitor> visitorList = visitorMapper.findAll();
|
List<Visitor> visitorList = visitorMapper.findAll();
|
||||||
return new PageData<VisitorModel>(new PageInfo<Visitor>(visitorList), list2List(visitorList, showLocation));
|
return new PageData<>(new PageInfo<>(visitorList), list2List(visitorList, showLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,8 +69,9 @@ public class VisitorServiceImpl implements VisitorService {
|
|||||||
visitor.setUa(request.getHeader("User-Agent"));
|
visitor.setUa(request.getHeader("User-Agent"));
|
||||||
//记录当日的访问
|
//记录当日的访问
|
||||||
String dayVisitCount = redisUtil.get("dayVisitCount");
|
String dayVisitCount = redisUtil.get("dayVisitCount");
|
||||||
long secondsLeftToday = 86400 - DateUtils.getFragmentInSeconds(Calendar.getInstance(), Calendar.DATE);
|
|
||||||
Date date = new Date(Calendar.YEAR);
|
LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||||
|
long secondsLeftToday = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight);
|
||||||
if (dayVisitCount == null) {
|
if (dayVisitCount == null) {
|
||||||
redisUtil.setEx("dayVisitCount", "1", secondsLeftToday, TimeUnit.SECONDS);
|
redisUtil.setEx("dayVisitCount", "1", secondsLeftToday, TimeUnit.SECONDS);
|
||||||
} else {
|
} else {
|
||||||
@@ -149,60 +152,7 @@ public class VisitorServiceImpl implements VisitorService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String getLocation(String ip) {
|
private String getLocation(String ip) {
|
||||||
StringBuilder result = new StringBuilder();
|
return AddressUtil.getCityInfo(ip);
|
||||||
URL url;
|
|
||||||
HttpURLConnection conn = null;
|
|
||||||
InputStream inputStream = null;
|
|
||||||
InputStreamReader inputStreamReader = null;
|
|
||||||
BufferedReader bufferedReader = null;
|
|
||||||
try {
|
|
||||||
url = new URL("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip);
|
|
||||||
conn = (HttpURLConnection) url.openConnection();
|
|
||||||
conn.setConnectTimeout(3000);
|
|
||||||
conn.setDoInput(true);
|
|
||||||
conn.setRequestMethod("GET");
|
|
||||||
inputStream = conn.getInputStream();
|
|
||||||
inputStreamReader = new InputStreamReader(inputStream);
|
|
||||||
bufferedReader = new BufferedReader(inputStreamReader);
|
|
||||||
String tmp;
|
|
||||||
while ((tmp = bufferedReader.readLine()) != null) {
|
|
||||||
result.append(tmp);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ignore
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (conn != null) {
|
|
||||||
conn.disconnect();
|
|
||||||
}
|
|
||||||
if (inputStream != null) {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
if (inputStreamReader != null) {
|
|
||||||
inputStreamReader.close();
|
|
||||||
}
|
|
||||||
if (bufferedReader != null) {
|
|
||||||
bufferedReader.close();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
if ("".equals(result.toString())) {
|
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
|
||||||
}
|
|
||||||
Map<String, Object> stringObjectMap = JsonParserFactory.getJsonParser().parseMap(result.toString());
|
|
||||||
if ((Integer) stringObjectMap.get("code") == 0) {
|
|
||||||
LinkedHashMap data = (LinkedHashMap) stringObjectMap.get("data");
|
|
||||||
sb.append(data.get("country"))
|
|
||||||
.append("-")
|
|
||||||
.append(data.get("region"))
|
|
||||||
.append("-")
|
|
||||||
.append(data.get("city"));
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,112 +1,114 @@
|
|||||||
package cn.celess.blog.service.serviceimpl;
|
package cn.celess.blog.service.serviceimpl;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.WebUpdate;
|
import cn.celess.blog.entity.WebUpdate;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
||||||
import cn.celess.blog.service.WebUpdateInfoService;
|
import cn.celess.blog.service.WebUpdateInfoService;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
import cn.celess.blog.util.DateFormatUtil;
|
||||||
import cn.celess.blog.util.HttpUtil;
|
import cn.celess.blog.util.HttpUtil;
|
||||||
import cn.celess.blog.util.ModalTrans;
|
import cn.celess.blog.util.ModalTrans;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.alibaba.druid.util.StringUtils;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import net.sf.json.JSONArray;
|
import com.github.pagehelper.PageHelper;
|
||||||
import net.sf.json.JSONObject;
|
import com.github.pagehelper.PageInfo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
import java.util.stream.Collectors;
|
||||||
import java.util.List;
|
|
||||||
|
/**
|
||||||
/**
|
* @author : xiaohai
|
||||||
* @author : xiaohai
|
* @date : 2019/05/12 11:43
|
||||||
* @date : 2019/05/12 11:43
|
*/
|
||||||
*/
|
@Service
|
||||||
@Service
|
@Slf4j
|
||||||
@Slf4j
|
public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
||||||
public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
@Autowired
|
||||||
@Autowired
|
WebUpdateInfoMapper webUpdateInfoMapper;
|
||||||
WebUpdateInfoMapper webUpdateInfoMapper;
|
|
||||||
|
|
||||||
|
@Override
|
||||||
@Override
|
public WebUpdateModel create(String info) {
|
||||||
public WebUpdateModel create(String info) {
|
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
||||||
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
}
|
||||||
}
|
WebUpdate webUpdate = new WebUpdate(info);
|
||||||
WebUpdate webUpdate = new WebUpdate(info);
|
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
||||||
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
throw new MyException(ResponseEnum.FAILURE);
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
}
|
||||||
}
|
return ModalTrans.webUpdate(webUpdateInfoMapper.findById(webUpdate.getId()));
|
||||||
return ModalTrans.webUpdate(webUpdateInfoMapper.findById(webUpdate.getId()));
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public Boolean del(long id) {
|
||||||
public Boolean del(long id) {
|
if (!webUpdateInfoMapper.existsById(id)) {
|
||||||
if (!webUpdateInfoMapper.existsById(id)) {
|
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
}
|
||||||
}
|
return webUpdateInfoMapper.delete(id) == 1;
|
||||||
return webUpdateInfoMapper.delete(id) == 1;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public WebUpdateModel update(long id, String info) {
|
||||||
public WebUpdateModel update(long id, String info) {
|
WebUpdate webUpdate = webUpdateInfoMapper.findById(id);
|
||||||
WebUpdate webUpdate = webUpdateInfoMapper.findById(id);
|
if (webUpdate == null) {
|
||||||
if (webUpdate == null) {
|
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
}
|
||||||
}
|
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
||||||
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
}
|
||||||
}
|
webUpdate.setUpdateInfo(info);
|
||||||
webUpdate.setUpdateInfo(info);
|
webUpdateInfoMapper.update(id, info);
|
||||||
webUpdateInfoMapper.update(id, info);
|
return ModalTrans.webUpdate(webUpdate);
|
||||||
return ModalTrans.webUpdate(webUpdate);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public PageData<WebUpdateModel> pages(int count, int page) {
|
||||||
public PageData<WebUpdateModel> pages(int count, int page) {
|
PageHelper.startPage(page, count);
|
||||||
PageHelper.startPage(page, count);
|
List<WebUpdate> updateList = webUpdateInfoMapper.findAll();
|
||||||
List<WebUpdate> updateList = webUpdateInfoMapper.findAll();
|
return new PageData<>(new PageInfo<>(updateList), list2List(updateList));
|
||||||
return new PageData<WebUpdateModel>(new PageInfo<WebUpdate>(updateList), list2List(updateList));
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public List<WebUpdateModel> findAll() {
|
||||||
public List<WebUpdateModel> findAll() {
|
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
||||||
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
return list2List(all);
|
||||||
return list2List(all);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
|
||||||
public JSONObject getLastestUpdateTime() {
|
public Map<String, Object> getLastestUpdateTime() {
|
||||||
JSONObject jsonObject = new JSONObject();
|
Map<String, Object> map = new HashMap<>();
|
||||||
jsonObject.put("lastUpdateTime", DateFormatUtil.get(webUpdateInfoMapper.getLastestOne().getUpdateTime()));
|
map.put("lastUpdateTime", DateFormatUtil.get(webUpdateInfoMapper.getLastestOne().getUpdateTime()));
|
||||||
jsonObject.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo());
|
map.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo());
|
||||||
try {
|
try {
|
||||||
JSONArray array = JSONArray.fromObject(HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1"));
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JSONObject object = array.getJSONObject(0);
|
String respStr = HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1");
|
||||||
JSONObject commit = object.getJSONObject("commit");
|
if (!StringUtils.isEmpty(respStr)) {
|
||||||
jsonObject.put("lastCommit", commit.getString("message"));
|
JsonNode root = mapper.readTree(respStr);
|
||||||
jsonObject.put("committerAuthor", commit.getJSONObject("committer").getString("name"));
|
Iterator<JsonNode> elements = root.elements();
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat();
|
JsonNode next = elements.next();
|
||||||
Instant parse = Instant.parse(commit.getJSONObject("committer").getString("date"));
|
JsonNode commit = next.get("commit");
|
||||||
jsonObject.put("committerDate", DateFormatUtil.get(Date.from(parse)));
|
map.put("lastCommit", commit.get("message"));
|
||||||
jsonObject.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + object.getString("sha"));
|
map.put("committerAuthor", commit.get("committer").get("name"));
|
||||||
} catch (IOException e) {
|
Instant parse = Instant.parse(commit.get("committer").get("date").asText());
|
||||||
log.info("网络请求失败{}", e.getMessage());
|
map.put("committerDate", DateFormatUtil.get(Date.from(parse)));
|
||||||
}
|
map.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + next.get("sha").asText());
|
||||||
return jsonObject;
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
|
log.info("网络请求失败{}", e.getMessage());
|
||||||
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
}
|
||||||
List<WebUpdateModel> webUpdateModels = new ArrayList<>();
|
return map;
|
||||||
webUpdates.forEach(update -> webUpdateModels.add(ModalTrans.webUpdate(update)));
|
}
|
||||||
return webUpdateModels;
|
|
||||||
}
|
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
||||||
}
|
return webUpdates.stream().map(ModalTrans::webUpdate).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
71
src/main/java/cn/celess/blog/util/AddressUtil.java
Normal file
71
src/main/java/cn/celess/blog/util/AddressUtil.java
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.lionsoul.ip2region.DataBlock;
|
||||||
|
import org.lionsoul.ip2region.DbConfig;
|
||||||
|
import org.lionsoul.ip2region.DbSearcher;
|
||||||
|
import org.lionsoul.ip2region.Util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2020/09/04 9:36
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class AddressUtil {
|
||||||
|
|
||||||
|
public static String getCityInfo(String ip) {
|
||||||
|
File file;
|
||||||
|
try {
|
||||||
|
//db
|
||||||
|
String dbPath = AddressUtil.class.getResource("/ip2region/ip2region.db").getPath();
|
||||||
|
file = new File(dbPath);
|
||||||
|
if (!file.exists()) {
|
||||||
|
String tmpDir = System.getProperties().getProperty("java.io.tmpdir");
|
||||||
|
dbPath = tmpDir + "ip.db";
|
||||||
|
file = new File(dbPath);
|
||||||
|
FileUtils.copyInputStreamToFile(Objects.requireNonNull(AddressUtil.class.getClassLoader().getResourceAsStream("classpath:ip2region/ip2region.db")), file);
|
||||||
|
}
|
||||||
|
//查询算法
|
||||||
|
//B-tree
|
||||||
|
int algorithm = DbSearcher.BTREE_ALGORITHM;
|
||||||
|
try {
|
||||||
|
DbConfig config = new DbConfig();
|
||||||
|
DbSearcher searcher = new DbSearcher(config, dbPath);
|
||||||
|
Method method = null;
|
||||||
|
switch (algorithm) {
|
||||||
|
case DbSearcher.BTREE_ALGORITHM:
|
||||||
|
method = searcher.getClass().getMethod("btreeSearch", String.class);
|
||||||
|
break;
|
||||||
|
case DbSearcher.BINARY_ALGORITHM:
|
||||||
|
method = searcher.getClass().getMethod("binarySearch", String.class);
|
||||||
|
break;
|
||||||
|
case DbSearcher.MEMORY_ALGORITYM:
|
||||||
|
method = searcher.getClass().getMethod("memorySearch", String.class);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataBlock dataBlock;
|
||||||
|
if (!Util.isIpAddress(ip)) {
|
||||||
|
System.out.println("Error: Invalid ip address");
|
||||||
|
}
|
||||||
|
|
||||||
|
dataBlock = (DataBlock) method.invoke(searcher, ip);
|
||||||
|
|
||||||
|
return dataBlock.getRegion();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
51
src/main/java/cn/celess/blog/util/EnvironmentUtil.java
Normal file
51
src/main/java/cn/celess/blog/util/EnvironmentUtil.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>date: 2022/12/02</P>
|
||||||
|
* <p>desc: </p>
|
||||||
|
* <p>mail: a@celess.cn</p>
|
||||||
|
*
|
||||||
|
* @author 禾几海
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class EnvironmentUtil {
|
||||||
|
|
||||||
|
private static Environment environment;
|
||||||
|
|
||||||
|
public static String getEnv(String name) {
|
||||||
|
String value = System.getenv(name);
|
||||||
|
if (StringUtils.isBlank(value)) {
|
||||||
|
log.error("没有找到环境变量:" + name);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getEnv(String name, String defaultValue) {
|
||||||
|
String env = getEnv(name);
|
||||||
|
if (env == null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getProperties(String key) {
|
||||||
|
String value = environment.getProperty(key);
|
||||||
|
if (StringUtils.isBlank(value)) {
|
||||||
|
log.error("没有找到配置项: {}", key);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getProperties(String key, String defaultValue) {
|
||||||
|
return environment.getProperty(key, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setEnvironment(Environment environment) {
|
||||||
|
EnvironmentUtil.environment = environment;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
package cn.celess.blog.util;
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||||
|
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.util.Objects;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 小海
|
* @Author: 小海
|
||||||
@@ -14,38 +17,34 @@ import java.nio.charset.StandardCharsets;
|
|||||||
* @Desc:
|
* @Desc:
|
||||||
*/
|
*/
|
||||||
public class HttpUtil {
|
public class HttpUtil {
|
||||||
|
private static final OkHttpClient CLIENT = new OkHttpClient();
|
||||||
|
|
||||||
public static String get(String urlStr) throws IOException {
|
public static String get(String urlStr) {
|
||||||
|
Request request = new Request.Builder()
|
||||||
StringBuffer sb = new StringBuffer();
|
.url(urlStr)
|
||||||
|
.get()
|
||||||
HttpURLConnection urlConnection = null;
|
.build();
|
||||||
try {
|
try (Response response = CLIENT.newCall(request).execute()) {
|
||||||
URL url = new URL(urlStr);
|
return Objects.requireNonNull(response.body()).string();
|
||||||
|
} catch (IOException e) {
|
||||||
//打开http
|
return null;
|
||||||
urlConnection = (HttpURLConnection) url.openConnection();
|
}
|
||||||
urlConnection.setDoInput(true);
|
}
|
||||||
urlConnection.setRequestMethod("GET");
|
|
||||||
urlConnection.connect();
|
|
||||||
|
public static String getAfterRendering(String url) {
|
||||||
try (
|
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
|
||||||
InputStream inputStream = urlConnection.getInputStream();
|
webClient.getOptions().setCssEnabled(false);
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
webClient.getOptions().setJavaScriptEnabled(true);
|
||||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)
|
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
|
||||||
) {
|
webClient.getOptions().setThrowExceptionOnScriptError(false);
|
||||||
//将bufferReader的值给放到buffer里
|
webClient.getOptions().setDownloadImages(false);
|
||||||
String str = null;
|
webClient.getOptions().setActiveXNative(false);
|
||||||
while ((str = bufferedReader.readLine()) != null) {
|
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
|
||||||
sb.append(str);
|
final HtmlPage page = webClient.getPage(url);
|
||||||
}
|
return page.asXml();
|
||||||
}
|
} catch (IOException e) {
|
||||||
} finally {
|
return null;
|
||||||
//断开连接
|
|
||||||
if (urlConnection != null) {
|
|
||||||
urlConnection.disconnect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ public class JwtUtil {
|
|||||||
*/
|
*/
|
||||||
public static final long EXPIRATION_SHORT_TIME = 7200000;
|
public static final long EXPIRATION_SHORT_TIME = 7200000;
|
||||||
private static final String CLAIM_KEY_USERNAME = "sub";
|
private static final String CLAIM_KEY_USERNAME = "sub";
|
||||||
|
private static final String BEARER_PREFIX_UPPER = "Bearer";
|
||||||
|
private static final String BEARER_PREFIX_LOWER = "bearer";
|
||||||
/**
|
/**
|
||||||
* JWT 秘钥需自行设置不可泄露
|
* JWT 秘钥需自行设置不可泄露
|
||||||
*/
|
*/
|
||||||
@@ -48,7 +50,7 @@ public class JwtUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String updateTokenDate(String token) {
|
public String updateTokenDate(String token) {
|
||||||
Claims claims = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody();
|
Claims claims = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(getJwtString(token)).getBody();
|
||||||
return Jwts.builder()
|
return Jwts.builder()
|
||||||
.setClaims(claims)
|
.setClaims(claims)
|
||||||
.setExpiration(new Date(claims.getExpiration().getTime() + EXPIRATION_SHORT_TIME))
|
.setExpiration(new Date(claims.getExpiration().getTime() + EXPIRATION_SHORT_TIME))
|
||||||
@@ -60,7 +62,7 @@ public class JwtUtil {
|
|||||||
* 获取token是否过期
|
* 获取token是否过期
|
||||||
*/
|
*/
|
||||||
public Boolean isTokenExpired(String token) {
|
public Boolean isTokenExpired(String token) {
|
||||||
Date expiration = getExpirationDateFromToken(token);
|
Date expiration = getExpirationDateFromToken(getJwtString(token));
|
||||||
return expiration == null || expiration.before(new Date());
|
return expiration == null || expiration.before(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +70,7 @@ public class JwtUtil {
|
|||||||
* 根据token获取username
|
* 根据token获取username
|
||||||
*/
|
*/
|
||||||
public String getUsernameFromToken(String token) {
|
public String getUsernameFromToken(String token) {
|
||||||
Claims claims = getClaimsFromToken(token);
|
Claims claims = getClaimsFromToken(getJwtString(token));
|
||||||
return claims == null ? null : claims.getSubject();
|
return claims == null ? null : claims.getSubject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +78,7 @@ public class JwtUtil {
|
|||||||
* 获取token的过期时间
|
* 获取token的过期时间
|
||||||
*/
|
*/
|
||||||
public Date getExpirationDateFromToken(String token) {
|
public Date getExpirationDateFromToken(String token) {
|
||||||
Claims claims = getClaimsFromToken(token);
|
Claims claims = getClaimsFromToken(getJwtString(token));
|
||||||
return claims == null ? null : claims.getExpiration();
|
return claims == null ? null : claims.getExpiration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +90,7 @@ public class JwtUtil {
|
|||||||
try {
|
try {
|
||||||
claims = Jwts.parser()
|
claims = Jwts.parser()
|
||||||
.setSigningKey(SECRET)
|
.setSigningKey(SECRET)
|
||||||
.parseClaimsJws(token)
|
.parseClaimsJws(getJwtString(token))
|
||||||
.getBody();
|
.getBody();
|
||||||
} catch (ExpiredJwtException e) {
|
} catch (ExpiredJwtException e) {
|
||||||
log.info("JWT令牌过期");
|
log.info("JWT令牌过期");
|
||||||
@@ -107,4 +109,9 @@ public class JwtUtil {
|
|||||||
return claims;
|
return claims;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getJwtString(String token) {
|
||||||
|
if (token == null) return token;
|
||||||
|
return token.replaceFirst(BEARER_PREFIX_UPPER, "").replace(BEARER_PREFIX_LOWER, "");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.celess.blog.util;
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
|
import cn.celess.blog.enmu.UserAccountStatusEnum;
|
||||||
import cn.celess.blog.entity.*;
|
import cn.celess.blog.entity.*;
|
||||||
import cn.celess.blog.entity.model.*;
|
import cn.celess.blog.entity.model.*;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
@@ -46,6 +47,7 @@ public class ModalTrans {
|
|||||||
}
|
}
|
||||||
UserModel userModel = new UserModel();
|
UserModel userModel = new UserModel();
|
||||||
BeanUtils.copyProperties(user, userModel);
|
BeanUtils.copyProperties(user, userModel);
|
||||||
|
userModel.setStatus(UserAccountStatusEnum.get(user.getStatus()));
|
||||||
userModel.setAvatarImgUrl(user.getAvatarImgUrl() == null || user.getAvatarImgUrl().length() == 0 ?
|
userModel.setAvatarImgUrl(user.getAvatarImgUrl() == null || user.getAvatarImgUrl().length() == 0 ?
|
||||||
null :
|
null :
|
||||||
"http://cdn.celess.cn/" + user.getAvatarImgUrl());
|
"http://cdn.celess.cn/" + user.getAvatarImgUrl());
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package cn.celess.blog.util;
|
|||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.User;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -31,24 +32,27 @@ public class RedisUserUtil {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public User getWithOutExc() {
|
public User getWithOutExc() {
|
||||||
String token = request.getHeader("Authorization");
|
String token = request.getHeader("Authorization");
|
||||||
if (token == null || token.isEmpty()) {
|
if (token == null || token.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String email = jwtUtil.getUsernameFromToken(token);
|
String email = jwtUtil.getUsernameFromToken(token);
|
||||||
return (User) JSONObject.toBean(JSONObject.fromObject(redisUtil.get(email + "-login")), User.class);
|
return new ObjectMapper().readValue(redisUtil.get(email + "-login"), User.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public User set(User user) {
|
public User set(User user) {
|
||||||
Long expire = redisUtil.getExpire(user.getEmail() + "-login");
|
Long expire = redisUtil.getExpire(user.getEmail() + "-login");
|
||||||
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
redisUtil.setEx(user.getEmail() + "-login", new ObjectMapper().writeValueAsString(user),
|
||||||
expire > 0 ? expire : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
expire > 0 ? expire : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public User set(User user, boolean isRemember) {
|
public User set(User user, boolean isRemember) {
|
||||||
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
redisUtil.setEx(user.getEmail() + "-login", new ObjectMapper().writeValueAsString(user),
|
||||||
isRemember ? JwtUtil.EXPIRATION_LONG_TIME : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
isRemember ? JwtUtil.EXPIRATION_LONG_TIME : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
||||||
request.getSession().setAttribute("email", user.getEmail());
|
request.getSession().setAttribute("email", user.getEmail());
|
||||||
return user;
|
return user;
|
||||||
|
|||||||
2
src/main/resources/META-INF/spring.factories
Normal file
2
src/main/resources/META-INF/spring.factories
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
org.springframework.boot.env.EnvironmentPostProcessor=cn.celess.blog.configuration.CommonEnvPostProcessor
|
||||||
|
org.springframework.context.ApplicationListener=cn.celess.blog.configuration.CommonEnvPostProcessor
|
||||||
@@ -1,31 +1,37 @@
|
|||||||
server.port=8081
|
server.port=8081
|
||||||
|
|
||||||
# 七牛的密钥配置
|
# ???????
|
||||||
qiniu.accessKey=
|
qiniu.accessKey=
|
||||||
qiniu.secretKey=
|
qiniu.secretKey=
|
||||||
qiniu.bucket=
|
qiniu.bucket=
|
||||||
# sitemap 存放地址
|
# sitemap ????
|
||||||
sitemap.path=
|
sitemap.path=
|
||||||
# 生成JWT时候的密钥
|
# ??JWT?????
|
||||||
jwt.secret=
|
jwt.secret=
|
||||||
|
|
||||||
spring.jpa.show-sql=false
|
spring.jpa.show-sql=false
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
# 上传单个文件的大小
|
# ?????????
|
||||||
spring.servlet.multipart.max-file-size=10MB
|
spring.servlet.multipart.max-file-size=10MB
|
||||||
# 上传文件的总大小
|
# ????????
|
||||||
spring.servlet.multipart.max-request-size=10MB
|
spring.servlet.multipart.max-request-size=10MB
|
||||||
##null字段不显示
|
##null?????
|
||||||
spring.jackson.default-property-inclusion=non_null
|
spring.jackson.default-property-inclusion=non_null
|
||||||
|
|
||||||
|
|
||||||
################# 数据库 ##################
|
################# ??? ##################
|
||||||
#请先填写下面的配置
|
#?????????
|
||||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
||||||
spring.datasource.url=
|
spring.datasource.url=
|
||||||
spring.datasource.username=
|
spring.datasource.username=
|
||||||
spring.datasource.password=
|
spring.datasource.password=
|
||||||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||||
|
spring.datasource.platform=mysql
|
||||||
|
# never / always / embedded
|
||||||
|
spring.datasource.initialization-mode=never
|
||||||
|
spring.datasource.sql-script-encoding=utf-8
|
||||||
|
spring.datasource.schema=classpath:sql/schema.sql
|
||||||
|
spring.datasource.data=classpath:sql/data.sql
|
||||||
|
|
||||||
|
|
||||||
################## mybatis ##################
|
################## mybatis ##################
|
||||||
@@ -42,7 +48,7 @@ pagehelper.params=count=countSql
|
|||||||
|
|
||||||
|
|
||||||
################ email ##############
|
################ email ##############
|
||||||
#请先填写下面的配置,不然可能运行不起来
|
#???????????????????
|
||||||
spring.mail.host=
|
spring.mail.host=
|
||||||
spring.mail.username=
|
spring.mail.username=
|
||||||
spring.mail.password=
|
spring.mail.password=
|
||||||
@@ -56,7 +62,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact
|
|||||||
spring.mail.properties.mail.smtp.socketFactory.fallback=false
|
spring.mail.properties.mail.smtp.socketFactory.fallback=false
|
||||||
|
|
||||||
|
|
||||||
#### 用于nginx的代理 获取真实ip
|
#### ??nginx??? ????ip
|
||||||
server.use-forward-headers = true
|
server.use-forward-headers = true
|
||||||
server.tomcat.remote-ip-header = X-Real-IP
|
server.tomcat.remote-ip-header = X-Real-IP
|
||||||
server.tomcat.protocol-header = X-Forwarded-Proto
|
server.tomcat.protocol-header = X-Forwarded-Proto
|
||||||
@@ -64,21 +70,21 @@ server.tomcat.protocol-header = X-Forwarded-Proto
|
|||||||
|
|
||||||
############### redis ##############
|
############### redis ##############
|
||||||
# REDIS (RedisProperties)
|
# REDIS (RedisProperties)
|
||||||
# Redis数据库索引(默认为0)
|
# Redis?????????0?
|
||||||
spring.redis.database=0
|
spring.redis.database=0
|
||||||
# Redis服务器地址
|
# Redis?????
|
||||||
spring.redis.host=
|
spring.redis.host=
|
||||||
# Redis服务器连接端口
|
# Redis???????
|
||||||
spring.redis.port=6379
|
spring.redis.port=6379
|
||||||
# Redis服务器连接密码(默认为空)
|
# Redis?????????????
|
||||||
spring.redis.password=
|
spring.redis.password=
|
||||||
# 连接池最大连接数(使用负值表示没有限制)
|
# ????????????????????
|
||||||
spring.redis.jedis.pool.max-active=-1
|
spring.redis.jedis.pool.max-active=-1
|
||||||
# 连接池最大阻塞等待时间(使用负值表示没有限制)
|
# ???????????????????????
|
||||||
spring.redis.jedis.pool.max-wait=-1
|
spring.redis.jedis.pool.max-wait=-1
|
||||||
# 连接池中的最大空闲连接
|
# ???????????
|
||||||
spring.redis.jedis.pool.max-idle=8
|
spring.redis.jedis.pool.max-idle=8
|
||||||
# 连接池中的最小空闲连接
|
# ???????????
|
||||||
spring.redis.jedis.pool.min-idle=0
|
spring.redis.jedis.pool.min-idle=0
|
||||||
# 连接超时时间(毫秒)
|
# ??????????
|
||||||
spring.redis.timeout=5000
|
spring.redis.timeout=5000
|
||||||
95
src/main/resources/application-test.properties
Normal file
95
src/main/resources/application-test.properties
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
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
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
spring.profiles.active=prod
|
spring.profiles.active=dev
|
||||||
####七牛的配置
|
#### ?????
|
||||||
####cn.celess.blog.service.serviceimpl.QiniuServiceImpl
|
####cn.celess.blog.service.serviceimpl.QiniuServiceImpl
|
||||||
logging.level.cn.celess.blog=debug
|
logging.level.cn.celess.blog=debug
|
||||||
logging.level.cn.celess.blog.mapper=info
|
logging.level.cn.celess.blog.mapper=info
|
||||||
|
|
||||||
## 修改openSource 添加-test 文件用于测试 -prod文件用于线上发布
|
## ??openSource ??-test ?????? -prod????????
|
||||||
BIN
src/main/resources/ip2region/ip2region.db
Normal file
BIN
src/main/resources/ip2region/ip2region.db
Normal file
Binary file not shown.
@@ -64,6 +64,14 @@
|
|||||||
and article_tag.t_id = tag_category.t_id
|
and article_tag.t_id = tag_category.t_id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="findTagByArticleId" resultMap="cn.celess.blog.mapper.TagMapper.tagResultMap">
|
||||||
|
select tag_category.*
|
||||||
|
from article_tag,
|
||||||
|
tag_category
|
||||||
|
where a_id = #{articleId}
|
||||||
|
and article_tag.t_id = tag_category.t_id
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="findOneById" resultMap="articleTagResultMap">
|
<select id="findOneById" resultMap="articleTagResultMap">
|
||||||
select *
|
select *
|
||||||
from article_tag,
|
from article_tag,
|
||||||
@@ -98,4 +106,4 @@
|
|||||||
and article_tag.a_id = article.a_id
|
and article_tag.a_id = article.a_id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -9,20 +9,26 @@
|
|||||||
<result column="l_icon_path" property="iconPath"/>
|
<result column="l_icon_path" property="iconPath"/>
|
||||||
<result column="l_desc" property="desc"/>
|
<result column="l_desc" property="desc"/>
|
||||||
<result column="is_delete" property="delete"/>
|
<result column="is_delete" property="delete"/>
|
||||||
|
<result column="l_email" property="email"/>
|
||||||
|
<result column="l_notification" property="notification"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insert" parameterType="cn.celess.blog.entity.PartnerSite" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insert" parameterType="cn.celess.blog.entity.PartnerSite" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into links (l_name, l_is_open, l_url, l_icon_path, l_desc, is_delete)
|
insert into links (l_name, l_is_open, l_url, l_icon_path, l_desc, l_email, l_notification, is_delete)
|
||||||
values (#{name}, #{open}, #{url}, #{iconPath}, #{desc}, false)
|
values (#{name}, #{open}, #{url}, #{iconPath}, #{desc}, #{email}, #{notification}, false)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="update" parameterType="cn.celess.blog.entity.PartnerSite">
|
<update id="update" parameterType="cn.celess.blog.entity.PartnerSite">
|
||||||
update links set
|
update links
|
||||||
<if test="open!=null">l_is_open=#{open},</if>
|
<trim prefix="set" suffixOverrides=",">
|
||||||
<if test="iconPath!=null">l_icon_path=#{iconPath},</if>
|
<if test="open!=null">l_is_open=#{open},</if>
|
||||||
<if test="desc!=null">l_desc=#{desc},</if>
|
<if test="iconPath!=null">l_icon_path=#{iconPath},</if>
|
||||||
<if test="url!=null">l_url=#{url},</if>
|
<if test="desc!=null">l_desc=#{desc},</if>
|
||||||
<if test="name!=null">l_name=#{name}</if>
|
<if test="url!=null">l_url=#{url},</if>
|
||||||
|
<if test="name!=null">l_name=#{name},</if>
|
||||||
|
<if test="notification!=null">l_notification=#{notification},</if>
|
||||||
|
<if test="email!=null">l_email=#{email}</if>
|
||||||
|
</trim>
|
||||||
where l_id=#{id}
|
where l_id=#{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
@@ -72,6 +78,9 @@
|
|||||||
<select id="findAll" resultMap="partnerSiteResultMap">
|
<select id="findAll" resultMap="partnerSiteResultMap">
|
||||||
select *
|
select *
|
||||||
from links
|
from links
|
||||||
|
<if test="_parameter != null">
|
||||||
|
where is_delete=#{deleted}
|
||||||
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -130,5 +130,8 @@
|
|||||||
<select id="findAll" resultMap="userResultMap">
|
<select id="findAll" resultMap="userResultMap">
|
||||||
select *
|
select *
|
||||||
from user
|
from user
|
||||||
|
<if test="_parameter != null">
|
||||||
|
where status=#{status}
|
||||||
|
</if>
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -1,185 +1,242 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="cn.celess.blog.mapper.ArticleMapper">
|
<mapper namespace="cn.celess.blog.mapper.ArticleMapper">
|
||||||
<resultMap id="articleResultMap" type="cn.celess.blog.entity.Article">
|
<resultMap id="articleResultMap" type="cn.celess.blog.entity.Article">
|
||||||
<id column="a_id" property="id"/>
|
<id column="a_id" property="id"/>
|
||||||
<result column="a_title" property="title"/>
|
<result column="a_title" property="title"/>
|
||||||
<result column="a_summary" property="summary"/>
|
<result column="a_summary" property="summary"/>
|
||||||
<result column="a_md_content" property="mdContent"/>
|
<result column="a_md_content" property="mdContent"/>
|
||||||
<result column="a_url" property="url"/>
|
<result column="a_url" property="url"/>
|
||||||
<result column="a_author_id" property="user.id"/>
|
<result column="a_author_id" property="user.id"/>
|
||||||
<result column="a_is_open" property="open"/>
|
<result column="a_is_open" property="open"/>
|
||||||
<result column="a_is_original" property="type"/>
|
<result column="a_is_original" property="type"/>
|
||||||
<!-- <result column="next_a_id" property="nextArticleId"/>-->
|
<!-- <result column="next_a_id" property="nextArticleId"/>-->
|
||||||
<!-- <result column="pre_a_id" property="preArticleId"/>-->
|
<!-- <result column="pre_a_id" property="preArticleId"/>-->
|
||||||
<result column="a_reading_number" property="readingNumber"/>
|
<result column="a_reading_number" property="readingNumber"/>
|
||||||
<result column="a_publish_date" property="publishDate"/>
|
<result column="a_publish_date" property="publishDate"/>
|
||||||
<result column="a_update_date" property="updateDate"/>
|
<result column="a_update_date" property="updateDate"/>
|
||||||
<result column="is_delete" property="deleted"/>
|
<result column="is_delete" property="deleted"/>
|
||||||
<association property="category" column="a_category_id" javaType="cn.celess.blog.entity.TagCategory"
|
<association property="category" column="a_category_id" javaType="cn.celess.blog.entity.TagCategory"
|
||||||
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||||
</association>
|
</association>
|
||||||
<collection property="tags" ofType="cn.celess.blog.entity.TagCategory"
|
<collection property="tags" ofType="cn.celess.blog.entity.Tag"
|
||||||
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
select="cn.celess.blog.mapper.ArticleTagMapper.findTagByArticleId" column="a_id">
|
||||||
</collection>
|
<id column="tagId" property="id"/>
|
||||||
</resultMap>
|
<result column="tagName" property="name"/>
|
||||||
|
</collection>
|
||||||
|
</resultMap>
|
||||||
<resultMap id="articleViewResultMap" type="cn.celess.blog.entity.Article">
|
|
||||||
<id column="articleId" property="id"/>
|
|
||||||
<result column="title" property="title"/>
|
<resultMap id="articleViewResultMap" type="cn.celess.blog.entity.Article">
|
||||||
<result column="summary" property="summary"/>
|
<id column="articleId" property="id"/>
|
||||||
<result column="mdContent" property="mdContent"/>
|
<result column="title" property="title"/>
|
||||||
<result column="url" property="url"/>
|
<result column="summary" property="summary"/>
|
||||||
<result column="isOpen" property="open"/>
|
<result column="mdContent" property="mdContent"/>
|
||||||
<result column="isOriginal" property="type"/>
|
<result column="url" property="url"/>
|
||||||
<result column="likeCount" property="likeCount"/>
|
<result column="isOpen" property="open"/>
|
||||||
<result column="dislikeCount" property="dislikeCount"/>
|
<result column="isOriginal" property="type"/>
|
||||||
<result column="readingCount" property="readingNumber"/>
|
<result column="likeCount" property="likeCount"/>
|
||||||
<result column="publishDate" property="publishDate"/>
|
<result column="dislikeCount" property="dislikeCount"/>
|
||||||
<result column="updateDate" property="updateDate"/>
|
<result column="readingCount" property="readingNumber"/>
|
||||||
<result column="isDelete" property="deleted"/>
|
<result column="publishDate" property="publishDate"/>
|
||||||
<association property="category" column="categoryId" javaType="cn.celess.blog.entity.Category">
|
<result column="updateDate" property="updateDate"/>
|
||||||
<id column="categoryId" property="id"/>
|
<result column="isDelete" property="deleted"/>
|
||||||
<result column="categoryName" property="name"/>
|
<association property="category" column="categoryId" javaType="cn.celess.blog.entity.Category">
|
||||||
</association>
|
<id column="categoryId" property="id"/>
|
||||||
<association property="user" column="authorId" javaType="cn.celess.blog.entity.User">
|
<result column="categoryName" property="name"/>
|
||||||
<id column="authorId" property="id"/>
|
</association>
|
||||||
<result column="userEmail" property="email"/>
|
<association property="user" column="authorId" javaType="cn.celess.blog.entity.User">
|
||||||
<result column="userAvatar" property="avatarImgUrl"/>
|
<id column="authorId" property="id"/>
|
||||||
<result column="userDisplayName" property="displayName"/>
|
<result column="userEmail" property="email"/>
|
||||||
</association>
|
<result column="userAvatar" property="avatarImgUrl"/>
|
||||||
<collection property="tags" ofType="cn.celess.blog.entity.Tag">
|
<result column="userDisplayName" property="displayName"/>
|
||||||
<id column="tagId" property="id"/>
|
</association>
|
||||||
<result column="tagName" property="name"/>
|
<collection property="tags" ofType="cn.celess.blog.entity.Tag"
|
||||||
</collection>
|
select="cn.celess.blog.mapper.ArticleTagMapper.findTagByArticleId" column="{articleId=articleId}">
|
||||||
|
<id column="tagId" property="id"/>
|
||||||
</resultMap>
|
<result column="tagName" property="name"/>
|
||||||
|
</collection>
|
||||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.celess.blog.entity.Article">
|
|
||||||
insert into article (a_author_id, a_category_id, a_md_content, a_is_original,
|
</resultMap>
|
||||||
a_summary, a_title, a_url)
|
|
||||||
values (#{user.id}, #{category.id}, #{mdContent}, #{type}, #{summary}, #{title}, #{url})
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.celess.blog.entity.Article">
|
||||||
</insert>
|
insert into article (a_author_id, a_category_id, a_md_content, a_is_original,
|
||||||
<update id="delete">
|
a_summary, a_title, a_url)
|
||||||
update article
|
values (#{user.id}, #{category.id}, #{mdContent}, #{type}, #{summary}, #{title}, #{url})
|
||||||
set is_delete = true
|
</insert>
|
||||||
where a_id = #{id}
|
<update id="delete">
|
||||||
</update>
|
update article
|
||||||
|
set is_delete = true
|
||||||
<update id="update">
|
where a_id = #{id}
|
||||||
update article
|
</update>
|
||||||
set a_update_date=now(),
|
|
||||||
<if test="title!=null">a_title=#{title},</if>
|
<update id="update">
|
||||||
<if test="mdContent!=null">a_md_content=#{mdContent},</if>
|
update article
|
||||||
<if test="summary!=null">a_summary=#{summary},</if>
|
set a_update_date=now(),
|
||||||
<if test="type!=null">a_is_original=#{type},</if>
|
<if test="title!=null">a_title=#{title},</if>
|
||||||
<if test="url!=null">a_url=#{url},</if>
|
<if test="mdContent!=null">a_md_content=#{mdContent},</if>
|
||||||
<if test="category!=null">a_category_id=#{category.id},</if>
|
<if test="summary!=null">a_summary=#{summary},</if>
|
||||||
<if test="open!=null">a_is_open=#{open}</if>
|
<if test="type!=null">a_is_original=#{type},</if>
|
||||||
where a_id = #{id}
|
<if test="url!=null">a_url=#{url},</if>
|
||||||
</update>
|
<if test="category!=null">a_category_id=#{category.id},</if>
|
||||||
|
<if test="open!=null">a_is_open=#{open}</if>
|
||||||
<update id="updateReadingNumber">
|
where a_id = #{id}
|
||||||
update article
|
</update>
|
||||||
set a_reading_number=a_reading_number + 1
|
|
||||||
where a_id = #{id}
|
<update id="updateReadingNumber">
|
||||||
</update>
|
update article
|
||||||
|
set a_reading_number=a_reading_number + 1
|
||||||
<select id="getLastestArticle" resultMap="articleViewResultMap" resultType="cn.celess.blog.entity.Article">
|
where a_id = #{id}
|
||||||
select *
|
</update>
|
||||||
from articleView
|
|
||||||
order by articleId desc
|
<select id="getLastestArticle" resultMap="articleViewResultMap" resultType="cn.celess.blog.entity.Article">
|
||||||
limit 1
|
select *
|
||||||
</select>
|
from articleView
|
||||||
|
order by articleId desc
|
||||||
|
limit 1
|
||||||
<select id="findArticleById" resultMap="articleViewResultMap">
|
</select>
|
||||||
select *
|
|
||||||
from articleView
|
|
||||||
where articleId = #{id}
|
<select id="findArticleById" resultMap="articleViewResultMap">
|
||||||
</select>
|
select *
|
||||||
|
from articleView
|
||||||
<select id="existsByTitle" resultType="boolean">
|
where articleId = #{id}
|
||||||
SELECT EXISTS(SELECT * FROM article WHERE a_title = #{title})
|
</select>
|
||||||
</select>
|
|
||||||
|
<select id="existsByTitle" resultType="boolean">
|
||||||
<select id="isDeletedById" resultType="boolean">
|
SELECT EXISTS(SELECT * FROM article WHERE a_title = #{title})
|
||||||
select is_delete
|
</select>
|
||||||
from article
|
|
||||||
WHERE a_id = #{id}
|
<select id="isDeletedById" resultType="boolean">
|
||||||
</select>
|
select is_delete
|
||||||
|
from article
|
||||||
<select id="findAllByAuthorId" resultMap="articleViewResultMap">
|
WHERE a_id = #{id}
|
||||||
select *
|
</select>
|
||||||
from articleView
|
|
||||||
where authorId = #{authorId}
|
<select id="findAllByAuthorId" resultMap="articleViewResultMap">
|
||||||
and isDelete = false
|
select *
|
||||||
order by articleId desc
|
from articleView
|
||||||
</select>
|
where authorId = #{authorId}
|
||||||
|
and isDelete = false
|
||||||
<select id="findAllByOpen" resultMap="articleViewResultMap">
|
order by articleId desc
|
||||||
select *
|
</select>
|
||||||
from articleView
|
|
||||||
where isOpen = #{isOpen}
|
<select id="findAllByOpen" resultMap="articleViewResultMap">
|
||||||
and isDelete = false
|
select article.a_id as articleId,
|
||||||
order by articleId desc
|
article.a_title as title,
|
||||||
</select>
|
article.a_summary as summary,
|
||||||
|
article.a_md_content as mdContent,
|
||||||
|
article.a_url as url,
|
||||||
<select id="getTitleById" resultType="string">
|
article.a_is_original as isOriginal,
|
||||||
SELECT title
|
article.a_reading_number as readingCount,
|
||||||
from articleView
|
article.a_like as likeCount,
|
||||||
where articleId = #{id}
|
article.a_dislike as dislikeCount,
|
||||||
</select>
|
article.a_publish_date as publishDate,
|
||||||
|
article.a_update_date as updateDate,
|
||||||
<select id="findAllByCategoryId" resultMap="articleViewResultMap">
|
article.a_is_open as isOpen,
|
||||||
select *
|
category.t_id as categoryId,
|
||||||
from articleView
|
category.t_name as categoryName,
|
||||||
where categoryId = #{id}
|
user.u_id as authorId,
|
||||||
and isDelete = false
|
user.u_email as userEmail,
|
||||||
order by articleId desc
|
user.u_avatar as userAvatar,
|
||||||
</select>
|
user.u_display_name as userDisplayName,
|
||||||
|
article.is_delete as isDelete
|
||||||
<select id="findAllByCategoryIdAndOpen" resultMap="articleViewResultMap">
|
from article,
|
||||||
select *
|
tag_category as category,
|
||||||
from articleView
|
article_tag,
|
||||||
where categoryId = #{id}
|
user
|
||||||
and isDelete = false
|
where article.a_is_open = #{isOpen}
|
||||||
and isOpen = true
|
and article.is_delete = false
|
||||||
order by articleId desc
|
and article.a_id = article_tag.a_id
|
||||||
</select>
|
and article.a_category_id = category.t_id
|
||||||
|
and category.is_category = true
|
||||||
|
and article.a_author_id = user.u_id
|
||||||
<select id="findAll" resultMap="articleViewResultMap">
|
group by article.a_id
|
||||||
select *
|
order by article.a_id desc
|
||||||
from articleView
|
</select>
|
||||||
order by articleId desc
|
|
||||||
</select>
|
|
||||||
|
<select id="getTitleById" resultType="string">
|
||||||
|
SELECT title
|
||||||
<select id="count" resultType="long">
|
from articleView
|
||||||
select count(*)
|
where articleId = #{id}
|
||||||
from article
|
</select>
|
||||||
where is_delete = false;
|
|
||||||
</select>
|
<select id="findAllByCategoryId" resultMap="articleViewResultMap">
|
||||||
|
select *
|
||||||
<select id="getPreArticle" resultMap="articleViewResultMap">
|
from articleView
|
||||||
select *
|
where categoryId = #{id}
|
||||||
from articleView
|
and isDelete = false
|
||||||
where articleId = (select max(articleId)
|
order by articleId desc
|
||||||
from articleView
|
</select>
|
||||||
where articleId < #{id}
|
|
||||||
)
|
<select id="findAllByCategoryIdAndOpen" resultMap="articleViewResultMap">
|
||||||
</select>
|
select *
|
||||||
<select id="getNextArticle" resultMap="articleViewResultMap">
|
from articleView
|
||||||
select *
|
where categoryId = #{id}
|
||||||
from articleView
|
and isDelete = false
|
||||||
where articleId = (select min(articleId)
|
and isOpen = true
|
||||||
from articleView
|
order by articleId desc
|
||||||
where articleId > #{id}
|
</select>
|
||||||
)
|
|
||||||
</select>
|
|
||||||
|
<select id="findAll" resultMap="articleViewResultMap">
|
||||||
|
select article.a_id as articleId,
|
||||||
</mapper>
|
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,
|
||||||
|
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 category,
|
||||||
|
article_tag,
|
||||||
|
user
|
||||||
|
where article.a_id = article_tag.a_id
|
||||||
|
and article.a_category_id = category.t_id
|
||||||
|
and category.is_category = true
|
||||||
|
and article.a_author_id = user.u_id
|
||||||
|
group by article.a_id
|
||||||
|
order by article.a_id desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="count" resultType="long">
|
||||||
|
select count(*)
|
||||||
|
from article
|
||||||
|
where is_delete = false;
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getPreArticle" resultMap="articleViewResultMap">
|
||||||
|
select *
|
||||||
|
from articleView
|
||||||
|
where articleId = (select max(articleId)
|
||||||
|
from articleView
|
||||||
|
where isOpen = true
|
||||||
|
and articleId < #{id}
|
||||||
|
)
|
||||||
|
</select>
|
||||||
|
<select id="getNextArticle" resultMap="articleViewResultMap">
|
||||||
|
select *
|
||||||
|
from articleView
|
||||||
|
where articleId = (select min(articleId)
|
||||||
|
from articleView
|
||||||
|
where isOpen = true
|
||||||
|
and articleId > #{id}
|
||||||
|
)
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,14 @@
|
|||||||
CREATE DATABASE if not exists `blog`;
|
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;
|
||||||
|
|
||||||
USE blog;
|
|
||||||
|
|
||||||
CREATE TABLE `user`
|
CREATE TABLE `user`
|
||||||
(
|
(
|
||||||
@@ -66,19 +74,23 @@ CREATE TABLE `comment`
|
|||||||
`co_status` tinyint not null default 0 comment '评论的状态',
|
`co_status` tinyint not null default 0 comment '评论的状态',
|
||||||
`co_pid` bigint not null default -1 comment '评论/留言的父id',
|
`co_pid` bigint not null default -1 comment '评论/留言的父id',
|
||||||
`co_from_author_id` int not null comment '留言者id',
|
`co_from_author_id` int not null comment '留言者id',
|
||||||
`co_to_author_id` int default 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)
|
||||||
) DEFAULT CHARSET = utf8mb4
|
) DEFAULT CHARSET = utf8mb4
|
||||||
COLLATE utf8mb4_general_ci,comment '评论/留言表';
|
COLLATE utf8mb4_general_ci,comment '评论/留言表';
|
||||||
|
|
||||||
CREATE TABLE `links`
|
CREATE TABLE `links`
|
||||||
(
|
(
|
||||||
`l_id` bigint(20) primary key auto_increment,
|
`l_id` bigint(20) primary key auto_increment,
|
||||||
`l_name` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友站名称',
|
`l_name` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友站名称',
|
||||||
`l_is_open` boolean default true comment '是否公开',
|
`l_is_open` boolean default true comment '是否公开',
|
||||||
`l_url` varchar(255) not null comment '首页地址',
|
`l_url` varchar(255) unique not null comment '首页地址',
|
||||||
`l_icon_path` varchar(255) not null comment '友链的icon地址',
|
`l_icon_path` varchar(255) not null comment '友链的icon地址',
|
||||||
`l_desc` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友链的说明描述',
|
`l_desc` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友链的说明描述',
|
||||||
`is_delete` boolean not null default false comment '该数据是否被删除'
|
`is_delete` boolean not null default false comment '该数据是否被删除',
|
||||||
|
`l_email` varchar(255) comment '网站管理员的邮箱',
|
||||||
|
`l_notification` boolean default false comment '是否通知了'
|
||||||
) comment '友站表';
|
) comment '友站表';
|
||||||
|
|
||||||
CREATE TABLE `visitor`
|
CREATE TABLE `visitor`
|
||||||
193
src/main/resources/sql/schema_h2.sql
Normal file
193
src/main/resources/sql/schema_h2.sql
Normal 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;
|
||||||
|
|
||||||
@@ -1,194 +1,347 @@
|
|||||||
package cn.celess.blog;
|
package cn.celess.blog;
|
||||||
|
|
||||||
|
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.UserModel;
|
import cn.celess.blog.entity.model.QiniuResponse;
|
||||||
import cn.celess.blog.entity.request.LoginReq;
|
import cn.celess.blog.entity.model.UserModel;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import cn.celess.blog.entity.request.LoginReq;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import cn.celess.blog.service.MailService;
|
||||||
import org.junit.After;
|
import cn.celess.blog.service.QiniuService;
|
||||||
import org.junit.Before;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import org.junit.runner.RunWith;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import com.qiniu.storage.model.FileInfo;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.MediaType;
|
import org.junit.After;
|
||||||
import org.springframework.mock.web.MockHttpSession;
|
import org.junit.Before;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.junit.Test;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
import org.slf4j.Logger;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.test.web.servlet.ResultActions;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import java.util.UUID;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
import static org.junit.Assert.*;
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
/**
|
import java.io.IOException;
|
||||||
* @Author: 小海
|
import java.io.InputStream;
|
||||||
* @Date: 2019/08/22 12:46
|
import java.io.UnsupportedEncodingException;
|
||||||
* @Description: 测试基类
|
import java.lang.reflect.Field;
|
||||||
*/
|
import java.util.Map;
|
||||||
@SpringBootTest
|
import java.util.UUID;
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@WebAppConfiguration
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
@ActiveProfiles("test")
|
import static org.junit.Assert.*;
|
||||||
public class BaseTest {
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
protected MockMvc mockMvc;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
protected final static String Code = "code";
|
|
||||||
protected final static String Result = "result";
|
/**
|
||||||
private static String userToken = null;
|
* @Author: 小海
|
||||||
private static String adminToken = null;
|
* @Date: 2019/08/22 12:46
|
||||||
/**
|
* @Description: 测试基类
|
||||||
* jackson 序列化/反序列化Json
|
*/
|
||||||
*/
|
@SpringBootTest
|
||||||
protected final ObjectMapper mapper = new ObjectMapper();
|
@RunWith(SpringRunner.class)
|
||||||
|
@WebAppConfiguration
|
||||||
@Autowired
|
@ActiveProfiles("test")
|
||||||
private WebApplicationContext wac;
|
public class BaseTest {
|
||||||
protected MockHttpSession session;
|
|
||||||
|
|
||||||
@Before
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
public void before() {
|
|
||||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
protected MockMvc mockMvc;
|
||||||
session = new MockHttpSession();
|
protected final static String Code = "code";
|
||||||
System.out.println("==========> 开始测试 <=========");
|
protected final static String Result = "result";
|
||||||
}
|
protected final static String USERE_MAIL = "zh56462271@qq.com";
|
||||||
|
protected final static String ADMIN_EMAIL = "a@celess.cn";
|
||||||
@After
|
|
||||||
public void after() {
|
/**
|
||||||
System.out.println("==========> 测试结束 <=========");
|
* jackson 序列化/反序列化Json
|
||||||
}
|
*/
|
||||||
|
protected final ObjectMapper mapper = new ObjectMapper();
|
||||||
/**
|
protected static final TypeReference<?> BOOLEAN_TYPE = new TypeReference<Response<Boolean>>() {
|
||||||
* admin 权限用户登录
|
};
|
||||||
*
|
protected static final TypeReference<?> STRING_TYPE = new TypeReference<Response<String>>() {
|
||||||
* @return token
|
};
|
||||||
*/
|
protected static final TypeReference<?> OBJECT_TYPE = new TypeReference<Response<Object>>() {
|
||||||
protected String adminLogin() {
|
};
|
||||||
if (adminToken != null) return adminToken;
|
protected static final TypeReference<?> MAP_OBJECT_TYPE = new TypeReference<Response<Map<String, Object>>>() {
|
||||||
LoginReq req = new LoginReq();
|
};
|
||||||
req.setEmail("a@celess.cn");
|
|
||||||
req.setPassword("123456789");
|
@Autowired
|
||||||
req.setIsRememberMe(false);
|
private WebApplicationContext wac;
|
||||||
adminToken = login(req);
|
protected MockHttpSession session;
|
||||||
assertNotNull(adminToken);
|
|
||||||
return adminToken;
|
@Before
|
||||||
}
|
public void before() {
|
||||||
|
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
||||||
/**
|
session = new MockHttpSession();
|
||||||
* user 权限用户登录
|
System.out.println("==========> 开始测试 <=========");
|
||||||
*
|
}
|
||||||
* @return token
|
|
||||||
*/
|
@After
|
||||||
protected String userLogin() {
|
public void after() {
|
||||||
if (userToken != null) return userToken;
|
System.out.println("==========> 测试结束 <=========");
|
||||||
LoginReq req = new LoginReq();
|
}
|
||||||
req.setEmail("zh56462271@qq.com");
|
|
||||||
req.setPassword("123456789");
|
/**
|
||||||
req.setIsRememberMe(false);
|
* admin 权限用户登录
|
||||||
userToken = login(req);
|
*
|
||||||
assertNotNull(userToken);
|
* @return token
|
||||||
return userToken;
|
*/
|
||||||
}
|
protected String adminLogin() {
|
||||||
|
LoginReq req = new LoginReq();
|
||||||
/**
|
req.setEmail(ADMIN_EMAIL);
|
||||||
* 登录逻辑
|
req.setPassword("123456789");
|
||||||
*
|
req.setIsRememberMe(true);
|
||||||
* @param req 用户信息
|
String token = login(req);
|
||||||
* @return token | null
|
assertNotNull(token);
|
||||||
*/
|
return token;
|
||||||
private String login(LoginReq req) {
|
}
|
||||||
String str = null;
|
|
||||||
try {
|
/**
|
||||||
str = getMockData(post("/login"), null, req)
|
* user 权限用户登录
|
||||||
.andReturn().getResponse().getContentAsString();
|
*
|
||||||
Response<UserModel> response = mapper.readValue(str, new TypeReference<Response<UserModel>>() {
|
* @return token
|
||||||
});
|
*/
|
||||||
assertEquals(SUCCESS.getCode(), response.getCode());
|
protected String userLogin() {
|
||||||
String token = response.getResult().getToken();
|
LoginReq req = new LoginReq();
|
||||||
assertNotNull(token);
|
req.setEmail(USERE_MAIL);
|
||||||
return token;
|
req.setPassword("123456789");
|
||||||
} catch (Exception e) {
|
req.setIsRememberMe(true);
|
||||||
e.printStackTrace();
|
String token = login(req);
|
||||||
}
|
assertNotNull(token);
|
||||||
return null;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/**
|
||||||
public void test() {
|
* 登录逻辑
|
||||||
// 测试登录
|
*
|
||||||
assertNotNull(userLogin());
|
* @param req 用户信息
|
||||||
assertNotNull(adminLogin());
|
* @return token | null
|
||||||
try {
|
*/
|
||||||
// 测试getMockData方法
|
protected String login(LoginReq req) {
|
||||||
assertNotNull(getMockData(get("/headerInfo")));
|
String str = null;
|
||||||
} catch (Exception e) {
|
try {
|
||||||
e.printStackTrace();
|
str = getMockData(post("/login"), null, req)
|
||||||
}
|
.andReturn().getResponse().getContentAsString();
|
||||||
}
|
Response<UserModel> response = mapper.readValue(str, new TypeReference<Response<UserModel>>() {
|
||||||
|
});
|
||||||
/**
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
* 产生指定长度的随机字符
|
String token = response.getResult().getToken();
|
||||||
*
|
assertNotNull(token);
|
||||||
* @param len
|
return token;
|
||||||
* @return
|
} catch (Exception e) {
|
||||||
*/
|
logger.error("测试登录错误");
|
||||||
protected String randomStr(int len) {
|
e.printStackTrace();
|
||||||
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, len);
|
}
|
||||||
}
|
assertNotNull(str);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 抽离的mock请求方法
|
@Test
|
||||||
*
|
public void test() {
|
||||||
* @param builder MockHttpServletRequestBuilder :get(...) post(...) ....
|
// 测试登录
|
||||||
* @return 返回 ResultActions
|
assertNotNull(userLogin());
|
||||||
* @throws Exception exc
|
assertNotNull(adminLogin());
|
||||||
*/
|
assertNotEquals(userLogin(), adminLogin());
|
||||||
protected ResultActions getMockData(MockHttpServletRequestBuilder builder) throws Exception {
|
try {
|
||||||
return getMockData(builder, null, null);
|
// 测试getMockData方法
|
||||||
}
|
assertNotNull(getMockData(get("/headerInfo")));
|
||||||
|
getMockData((get("/headerInfo"))).andDo(result -> assertNotNull(getResponse(result, OBJECT_TYPE)));
|
||||||
/**
|
} catch (Exception e) {
|
||||||
* 抽离的mock请求方法 重载
|
e.printStackTrace();
|
||||||
*
|
}
|
||||||
* @param builder ..
|
}
|
||||||
* @param token 用户登录的token
|
|
||||||
* @return ..
|
/**
|
||||||
* @throws Exception ..
|
* 产生指定长度的随机字符
|
||||||
*/
|
*
|
||||||
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token) throws Exception {
|
* @param len len
|
||||||
return getMockData(builder, token, null);
|
* @return str
|
||||||
}
|
*/
|
||||||
|
protected String randomStr(int len) {
|
||||||
/**
|
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, len);
|
||||||
* 抽离的mock请求方法 重载
|
}
|
||||||
*
|
|
||||||
* @param builder ..
|
/**
|
||||||
* @param token ..
|
* 产生指定长度的随机字符
|
||||||
* @param content http中发送的APPLICATION_JSON的json数据
|
*
|
||||||
* @return ..
|
* @return str
|
||||||
* @throws Exception ..
|
*/
|
||||||
*/
|
protected String randomStr() {
|
||||||
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token, Object content) throws Exception {
|
return UUID.randomUUID().toString();
|
||||||
// MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get(url);
|
}
|
||||||
if (token != null) {
|
|
||||||
builder.header("Authorization", token);
|
/**
|
||||||
}
|
* 抽离的mock请求方法
|
||||||
if (content != null) {
|
*
|
||||||
builder.content(mapper.writeValueAsString(content)).contentType(MediaType.APPLICATION_JSON);
|
* @param builder MockHttpServletRequestBuilder :get(...) post(...) ....
|
||||||
}
|
* @return 返回 ResultActions
|
||||||
return mockMvc.perform(builder).andExpect(status().isOk());
|
* @throws Exception exc
|
||||||
}
|
*/
|
||||||
}
|
protected ResultActions getMockData(MockHttpServletRequestBuilder builder) throws Exception {
|
||||||
|
return getMockData(builder, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抽离的mock请求方法 重载
|
||||||
|
*
|
||||||
|
* @param builder ..
|
||||||
|
* @param token 用户登录的token
|
||||||
|
* @return ..
|
||||||
|
* @throws Exception ..
|
||||||
|
*/
|
||||||
|
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token) throws Exception {
|
||||||
|
return getMockData(builder, token, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抽离的mock请求方法 重载
|
||||||
|
*
|
||||||
|
* @param builder ..
|
||||||
|
* @param token ..
|
||||||
|
* @param content http中发送的APPLICATION_JSON的json数据
|
||||||
|
* @return ..
|
||||||
|
* @throws Exception ..
|
||||||
|
*/
|
||||||
|
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token, Object content) throws Exception {
|
||||||
|
// MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get(url);
|
||||||
|
if (token != null) {
|
||||||
|
builder.header("Authorization", "Bearer "+token);
|
||||||
|
}
|
||||||
|
if (content != null) {
|
||||||
|
builder.content(mapper.writeValueAsString(content)).contentType(MediaType.APPLICATION_JSON);
|
||||||
|
logger.debug("param::json->{}", mapper.writeValueAsString(content));
|
||||||
|
}
|
||||||
|
return mockMvc.perform(builder).andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected <T> Response<T> getResponse(String json) {
|
||||||
|
return getResponse(json, OBJECT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T> Response<T> getResponse(MvcResult result) {
|
||||||
|
return getResponse(result, OBJECT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据json 信息反序列化成Response对象
|
||||||
|
*
|
||||||
|
* @param json json
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @return Response对象
|
||||||
|
*/
|
||||||
|
protected <T> Response<T> getResponse(String json, TypeReference<?> responseType) {
|
||||||
|
Response<T> response = null;
|
||||||
|
try {
|
||||||
|
response = mapper.readValue(json, responseType);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("解析json Response对象错误,json:[{}]", json);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
assertNotNull(response);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据json 信息反序列化成Response对象
|
||||||
|
*
|
||||||
|
* @param result MvcResult
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @return Response对象
|
||||||
|
*/
|
||||||
|
protected <T> Response<T> getResponse(MvcResult result, TypeReference<?> responseType) {
|
||||||
|
try {
|
||||||
|
return getResponse(result.getResponse().getContentAsString(), responseType);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
logger.error("解析json Response对象错误,result:[{}]", result);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改 mailService 的实现类
|
||||||
|
*
|
||||||
|
* @param service service 类
|
||||||
|
* @param mailFiledName service 中自动注入的mailService字段名
|
||||||
|
*/
|
||||||
|
protected void mockInjectInstance(Object service, String mailFiledName, Object impl) {
|
||||||
|
Field field;
|
||||||
|
try {
|
||||||
|
assertNotNull(service);
|
||||||
|
field = service.getClass().getDeclaredField(mailFiledName);
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(service, impl);
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public static class TestMailServiceImpl implements MailService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean AsyncSend(SimpleMailMessage message) {
|
||||||
|
log.debug("异步邮件请求,SimpleMailMessage:[{}]", getJson(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean send(SimpleMailMessage message) {
|
||||||
|
log.debug("邮件请求,SimpleMailMessage:[{}]", getJson(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转json
|
||||||
|
*
|
||||||
|
* @param o
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getJson(Object o) {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
try {
|
||||||
|
return mapper.writeValueAsString(o);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
37
src/test/java/cn/celess/blog/RedisServerMock.java
Normal file
37
src/test/java/cn/celess/blog/RedisServerMock.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package cn.celess.blog;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import redis.embedded.RedisServer;
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,29 +9,30 @@ import cn.celess.blog.entity.model.PageData;
|
|||||||
import cn.celess.blog.entity.request.ArticleReq;
|
import cn.celess.blog.entity.request.ArticleReq;
|
||||||
import cn.celess.blog.mapper.ArticleMapper;
|
import cn.celess.blog.mapper.ArticleMapper;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import java.util.*;
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
|
|
||||||
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.*;
|
|
||||||
|
|
||||||
public class ArticleControllerTest extends BaseTest {
|
public class ArticleControllerTest extends BaseTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
ArticleMapper articleMapper;
|
ArticleMapper articleMapper;
|
||||||
|
private static final TypeReference<?> ARTICLE_MODEL_TYPE = new TypeReference<Response<ArticleModel>>() {
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> ARTICLE_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<ArticleModel>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create() {
|
public void create() {
|
||||||
ArticleReq articleReq = new ArticleReq();
|
ArticleReq articleReq = new ArticleReq();
|
||||||
// 应该正常通过
|
// 应该正常通过
|
||||||
articleReq.setTitle("test-" + UUID.randomUUID().toString());
|
articleReq.setTitle("test-" + randomStr());
|
||||||
articleReq.setMdContent("# test title");
|
articleReq.setMdContent("# test title");
|
||||||
articleReq.setCategory("随笔");
|
articleReq.setCategory("随笔");
|
||||||
String[] tagList = {"tag", "category"};
|
String[] tagList = {"tag", "category"};
|
||||||
@@ -39,58 +40,29 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
articleReq.setOpen(true);
|
articleReq.setOpen(true);
|
||||||
articleReq.setType(true);
|
articleReq.setType(true);
|
||||||
articleReq.setUrl("http://xxxx.com");
|
articleReq.setUrl("http://xxxx.com");
|
||||||
JSONObject jsonObject = JSONObject.fromObject(articleReq);
|
MockHttpServletRequestBuilder post = post("/admin/article/create");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 未登录
|
getMockData(post, adminLogin(), articleReq).andDo(result -> {
|
||||||
mockMvc.perform(post("/admin/article/create")
|
Response<ArticleModel> response = getResponse(result, ARTICLE_MODEL_TYPE);
|
||||||
.content(jsonObject.toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.contentType("application/json"))
|
assertNotNull(response.getResult());
|
||||||
.andExpect(status().isOk())
|
ArticleModel articleModel = response.getResult();
|
||||||
.andDo(result -> {
|
assertNotNull(articleModel.getId());
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(),
|
assertNotNull(articleModel.getTitle());
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)
|
assertNotNull(articleModel.getSummary());
|
||||||
);
|
assertNotNull(articleModel.getOriginal());
|
||||||
});
|
assertNotNull(articleModel.getTags());
|
||||||
// User权限
|
assertNotNull(articleModel.getCategory());
|
||||||
String token = userLogin();
|
assertNotNull(articleModel.getPublishDateFormat());
|
||||||
mockMvc.perform(post("/admin/article/create")
|
assertNotNull(articleModel.getMdContent());
|
||||||
.content(jsonObject.toString())
|
assertNotNull(articleModel.getPreArticle());
|
||||||
.contentType("application/json")
|
assertNull(articleModel.getNextArticle());
|
||||||
.header("Authorization", token))
|
assertNotNull(articleModel.getOpen());
|
||||||
.andExpect(status().isOk())
|
assertNotNull(articleModel.getReadingNumber());
|
||||||
.andDo(result -> {
|
assertNotNull(articleModel.getAuthor());
|
||||||
assertEquals(PERMISSION_ERROR.getCode(),
|
assertNotNull(articleModel.getUrl());
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)
|
});
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Admin权限
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(post("/admin/article/create")
|
|
||||||
.content(jsonObject.toString())
|
|
||||||
.contentType("application/json")
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
ArticleModel articleModel = (ArticleModel) JSONObject.toBean(object.getJSONObject(Result), ArticleModel.class);
|
|
||||||
assertNotNull(articleModel.getId());
|
|
||||||
assertNotNull(articleModel.getTitle());
|
|
||||||
assertNotNull(articleModel.getSummary());
|
|
||||||
assertNotNull(articleModel.getOriginal());
|
|
||||||
assertNotNull(articleModel.getTags());
|
|
||||||
assertNotNull(articleModel.getCategory());
|
|
||||||
assertNotNull(articleModel.getPublishDateFormat());
|
|
||||||
assertNotNull(articleModel.getMdContent());
|
|
||||||
assertNotNull(articleModel.getPreArticle());
|
|
||||||
assertNull(articleModel.getNextArticle());
|
|
||||||
assertNotNull(articleModel.getOpen());
|
|
||||||
assertNotNull(articleModel.getReadingNumber());
|
|
||||||
assertNotNull(articleModel.getAuthor());
|
|
||||||
assertNotNull(articleModel.getUrl());
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -98,33 +70,22 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void delete() {
|
public void delete() {
|
||||||
Article article = articleMapper.getLastestArticle();
|
Article article;
|
||||||
|
do {
|
||||||
|
article = articleMapper.getLastestArticle();
|
||||||
|
create();
|
||||||
|
} while (article.isDeleted());
|
||||||
|
assertFalse(article.isDeleted());
|
||||||
|
MockHttpServletRequestBuilder delete = MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId());
|
||||||
try {
|
try {
|
||||||
// 未登录删除文章
|
Article finalArticle = article;
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
getMockData(delete, adminLogin()).andDo(result -> {
|
||||||
).andDo(result -> {
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(),
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)
|
// 断言删除成功
|
||||||
);
|
assertTrue(response.getResult());
|
||||||
|
assertTrue(articleMapper.isDeletedById(finalArticle.getId()));
|
||||||
});
|
});
|
||||||
// user 权限删除文章
|
|
||||||
String token = userLogin();
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(),
|
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
|
||||||
);
|
|
||||||
// admin 权限删除文章
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
// 断言删除成功
|
|
||||||
assertTrue(object.getBoolean(Result));
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -146,27 +107,21 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
articleReq.setTags(tagList);
|
articleReq.setTags(tagList);
|
||||||
articleReq.setTitle("test-" + article.getTitle());
|
articleReq.setTitle("test-" + article.getTitle());
|
||||||
try {
|
try {
|
||||||
// Admin 权限
|
getMockData(put("/admin/article/update"), adminLogin(), articleReq).andDo(result -> {
|
||||||
mockMvc.perform(put("/admin/article/update")
|
Response<ArticleModel> response = getResponse(result, ARTICLE_MODEL_TYPE);
|
||||||
.content(JSONObject.fromObject(articleReq).toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.contentType("application/json")
|
ArticleModel a = response.getResult();
|
||||||
.header("Authorization", adminLogin()))
|
assertEquals(articleReq.getCategory(), a.getCategory());
|
||||||
.andExpect(status().isOk())
|
assertEquals(articleReq.getUrl(), a.getUrl());
|
||||||
.andDo(result -> {
|
assertEquals(articleReq.getMdContent(), a.getMdContent());
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(articleReq.getTitle(), a.getTitle());
|
||||||
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
assertEquals(articleReq.getType(), a.getOriginal());
|
||||||
ArticleModel a = (ArticleModel) JSONObject.toBean(jsonObject.getJSONObject(Result), ArticleModel.class);
|
// Tag
|
||||||
assertEquals(articleReq.getCategory(), a.getCategory());
|
List<Tag> asList = a.getTags();
|
||||||
assertEquals(articleReq.getUrl(), a.getUrl());
|
assertEquals(3, asList.size());
|
||||||
assertEquals(articleReq.getMdContent(), a.getMdContent());
|
assertEquals(articleReq.getOpen(), a.getOpen());
|
||||||
assertEquals(articleReq.getTitle(), a.getTitle());
|
assertEquals(articleReq.getId(), a.getId());
|
||||||
assertEquals(articleReq.getType(), a.getOriginal());
|
});
|
||||||
// Tag
|
|
||||||
List<Tag> asList = a.getTags();
|
|
||||||
assertEquals(3, asList.size());
|
|
||||||
assertEquals(articleReq.getOpen(), a.getOpen());
|
|
||||||
assertEquals(articleReq.getId(), a.getId());
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -176,43 +131,35 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
public void retrieveOneById() {
|
public void retrieveOneById() {
|
||||||
try {
|
try {
|
||||||
long articleID = 3;
|
long articleID = 3;
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/article/articleID/" + articleID))
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/" + articleID));
|
||||||
.andExpect(status().is(200));
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=true"));
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=true"))
|
|
||||||
.andExpect(status().is(200));
|
|
||||||
|
|
||||||
// 文章不存在
|
// 文章不存在
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/article/articleID/-1"))
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/-1"))
|
||||||
.andExpect(status().is(200))
|
.andDo(result -> assertEquals(ARTICLE_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(ARTICLE_NOT_EXIST.getCode(), jsonObject.getInt(Code));
|
|
||||||
});
|
|
||||||
|
|
||||||
// 正常情况
|
// 正常情况
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=false"))
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=false")).andDo(result -> {
|
||||||
.andExpect(status().is(200))
|
Response<ArticleModel> response = getResponse(result, ARTICLE_MODEL_TYPE);
|
||||||
.andDo(result -> {
|
// 断言获取数据成功
|
||||||
JSONObject articleJson = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
// 断言获取数据成功
|
assertNotNull(response.getResult());
|
||||||
assertEquals(SUCCESS.getCode(), articleJson.getInt(Code));
|
|
||||||
assertNotNull(articleJson.getJSONObject(Result));
|
|
||||||
|
|
||||||
ArticleModel a = (ArticleModel) JSONObject.toBean(articleJson.getJSONObject(Result), ArticleModel.class);
|
ArticleModel a = response.getResult();
|
||||||
assertNotNull(a.getTitle());
|
assertNotNull(a.getTitle());
|
||||||
assertNotNull(a.getId());
|
assertNotNull(a.getId());
|
||||||
assertNotNull(a.getSummary());
|
assertNotNull(a.getSummary());
|
||||||
assertNotNull(a.getMdContent());
|
assertNotNull(a.getMdContent());
|
||||||
assertNotNull(a.getUrl());
|
assertNotNull(a.getUrl());
|
||||||
assertNotNull(a.getUpdateDateFormat());
|
assertNotNull(a.getUpdateDateFormat());
|
||||||
assertTrue(a.getPreArticle() != null || a.getNextArticle() != null);
|
assertTrue(a.getPreArticle() != null || a.getNextArticle() != null);
|
||||||
assertNotNull(a.getReadingNumber());
|
assertNotNull(a.getReadingNumber());
|
||||||
assertNotNull(a.getOriginal());
|
assertNotNull(a.getOriginal());
|
||||||
assertNotNull(a.getPublishDateFormat());
|
assertNotNull(a.getPublishDateFormat());
|
||||||
assertNotNull(a.getCategory());
|
assertNotNull(a.getCategory());
|
||||||
assertNotNull(a.getTags());
|
assertNotNull(a.getTags());
|
||||||
assertNotNull(a.getAuthor());
|
assertNotNull(a.getAuthor());
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -222,39 +169,32 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
public void articles() {
|
public void articles() {
|
||||||
try {
|
try {
|
||||||
// 测试不带参数访问
|
// 测试不带参数访问
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles"))
|
getMockData(MockMvcRequestBuilders.get("/articles"));
|
||||||
.andExpect(status().is(200));
|
getMockData(MockMvcRequestBuilders.get("/articles?page=1&count=5")).andDo(result -> {
|
||||||
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles?page=1&count=5"))
|
// 断言获取数据成功
|
||||||
.andExpect(status().is(200))
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.andDo(result -> {
|
// 结果集非空
|
||||||
JSONObject articlesJSON = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertNotNull(response.getResult());
|
||||||
Response response = (Response) JSONObject.toBean(articlesJSON, Response.class);
|
// 判断pageInfo是否包装完全
|
||||||
// 断言获取数据成功
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
assertEquals(SUCCESS.getCode(), response.getCode());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
// 结果集非空
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotNull(response.getResult());
|
assertEquals(5, pageData.getPageSize());
|
||||||
// 判断pageInfo是否包装完全
|
// 内容完整
|
||||||
JSONObject resultJson = JSONObject.fromObject(response.getResult());
|
for (ArticleModel a : pageData.getList()) {
|
||||||
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(resultJson, PageData.class);
|
assertNotNull(a.getTitle());
|
||||||
assertNotEquals(0, pageData.getTotal());
|
assertNotNull(a.getId());
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertNotNull(a.getSummary());
|
||||||
assertEquals(5, pageData.getPageSize());
|
assertNotNull(a.getOriginal());
|
||||||
// 内容完整
|
assertNotNull(a.getPublishDateFormat());
|
||||||
for (Object arc : pageData.getList()) {
|
assertNotNull(a.getCategory());
|
||||||
ArticleModel a = (ArticleModel) JSONObject.toBean(JSONObject.fromObject(arc), ArticleModel.class);
|
assertNotNull(a.getTags());
|
||||||
assertNotNull(a.getTitle());
|
assertNotNull(a.getAuthor());
|
||||||
assertNotNull(a.getId());
|
assertNull(a.getOpen());
|
||||||
assertNotNull(a.getSummary());
|
assertNull(a.getMdContent());
|
||||||
assertNotNull(a.getOriginal());
|
}
|
||||||
assertNotNull(a.getPublishDateFormat());
|
});
|
||||||
assertNotNull(a.getCategory());
|
|
||||||
assertNotNull(a.getTags());
|
|
||||||
assertNotNull(a.getAuthor());
|
|
||||||
assertNull(a.getOpen());
|
|
||||||
assertNull(a.getMdContent());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -264,19 +204,18 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
public void adminArticles() {
|
public void adminArticles() {
|
||||||
try {
|
try {
|
||||||
getMockData(get("/admin/articles?page=1&count=10")).andExpect(result ->
|
getMockData(get("/admin/articles?page=1&count=10")).andExpect(result ->
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), mapper.readValue(result.getResponse().getContentAsString(), Response.class).getCode())
|
assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result, STRING_TYPE).getCode())
|
||||||
);
|
);
|
||||||
|
|
||||||
// User权限登陆
|
// User权限登陆
|
||||||
getMockData(get("/admin/articles?page=1&count=10"), userLogin()).andDo(result ->
|
getMockData(get("/admin/articles?page=1&count=10"), userLogin()).andDo(result ->
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), mapper.readValue(result.getResponse().getContentAsString(), Response.class).getCode())
|
assertEquals(PERMISSION_ERROR.getCode(), getResponse(result, STRING_TYPE).getCode())
|
||||||
);
|
);
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
// admin权限登陆
|
// admin权限登陆
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
getMockData(get("/admin/articles?page=1&count=10&deleted=" + (i == 1)), adminLogin()).andDo(result -> {
|
getMockData(get("/admin/articles?page=1&count=10&deleted=" + (i == 1)), adminLogin()).andDo(result -> {
|
||||||
Response<PageData<ArticleModel>> response = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference<Response<PageData<ArticleModel>>>() {
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
});
|
|
||||||
assertEquals(SUCCESS.getCode(), response.getCode());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(response.getResult());
|
assertNotNull(response.getResult());
|
||||||
// 判断pageInfo是否包装完全
|
// 判断pageInfo是否包装完全
|
||||||
@@ -309,27 +248,22 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
try {
|
try {
|
||||||
// 分类不存在
|
// 分类不存在
|
||||||
String categoryName = "NoSuchCategory";
|
String categoryName = "NoSuchCategory";
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
getMockData(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
||||||
.andExpect(status().is(200))
|
.andDo(result -> assertEquals(CATEGORY_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(CATEGORY_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// 正常查询
|
// 正常查询
|
||||||
categoryName = "linux";
|
categoryName = "linux";
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
getMockData(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
||||||
.andExpect(status().is(200))
|
|
||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(jsonObject.getJSONObject(Result), PageData.class);
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
assertNotEquals(0, pageData.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertEquals(10, pageData.getPageSize());
|
assertEquals(10, pageData.getPageSize());
|
||||||
for (Object arc : pageData.getList()) {
|
for (ArticleModel arc : pageData.getList()) {
|
||||||
JSONObject jsonObject1 = JSONObject.fromObject(arc);
|
assertNotEquals(0, arc.getId().longValue());
|
||||||
assertNotEquals(0, jsonObject1.getInt("id"));
|
assertNotNull(arc.getTitle());
|
||||||
assertNotNull(jsonObject1.getString("title"));
|
assertNotNull(arc.getSummary());
|
||||||
assertNotNull(jsonObject1.getString("summary"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -342,28 +276,23 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
try {
|
try {
|
||||||
// 分类不存在
|
// 分类不存在
|
||||||
String tagName = "NoSuchTag";
|
String tagName = "NoSuchTag";
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
getMockData(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
||||||
.andExpect(status().is(200))
|
.andDo(result -> assertEquals(TAG_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(TAG_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// 正常查询
|
// 正常查询
|
||||||
tagName = "linux";
|
tagName = "linux";
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
getMockData(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
||||||
.andExpect(status().is(200))
|
|
||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(jsonObject.getJSONObject(Result), PageData.class);
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
assertNotEquals(0, pageData.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertEquals(10, pageData.getPageSize());
|
assertEquals(10, pageData.getPageSize());
|
||||||
|
|
||||||
for (Object arc : pageData.getList()) {
|
for (ArticleModel arc : pageData.getList()) {
|
||||||
JSONObject jsonObject1 = JSONObject.fromObject(arc);
|
assertNotEquals(0, arc.getId().longValue());
|
||||||
assertNotEquals(0, jsonObject1.getInt("id"));
|
assertNotNull(arc.getTitle());
|
||||||
assertNotNull(jsonObject1.getString("title"));
|
assertNotNull(arc.getSummary());
|
||||||
assertNotNull(jsonObject1.getString("summary"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -2,132 +2,77 @@ package cn.celess.blog.controller;
|
|||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.Category;
|
import cn.celess.blog.entity.Category;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.CategoryModel;
|
import cn.celess.blog.entity.model.CategoryModel;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.mapper.CategoryMapper;
|
import cn.celess.blog.mapper.CategoryMapper;
|
||||||
import net.sf.json.JSONArray;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.UUID;
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
|
|
||||||
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.*;
|
|
||||||
|
|
||||||
public class CategoryControllerTest extends BaseTest {
|
public class CategoryControllerTest extends BaseTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CategoryMapper categoryMapper;
|
CategoryMapper categoryMapper;
|
||||||
|
private static final TypeReference<?> CATEGORY_MODEL_TYPE = new TypeReference<Response<CategoryModel>>() {
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> CATEGORY_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<CategoryModel>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOne() throws Exception {
|
public void addOne() throws Exception {
|
||||||
String categoryName = randomStr(4);
|
String categoryName = randomStr(4);
|
||||||
System.out.println("categoryName: ==> " + categoryName);
|
getMockData(post("/admin/category/create?name=" + categoryName), adminLogin()).andDo(result -> {
|
||||||
// 未登录
|
Response<CategoryModel> response = getResponse(result, CATEGORY_MODEL_TYPE);
|
||||||
mockMvc.perform(post("/admin/category/create?name=" + categoryName)).andExpect(status().isOk())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.andDo(result -> {
|
CategoryModel category = response.getResult();
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
assertEquals(categoryName, category.getName());
|
||||||
});
|
assertNotNull(category.getId());
|
||||||
// User权限
|
assertNull(category.getArticles());
|
||||||
String token = userLogin();
|
});
|
||||||
mockMvc.perform(post("/admin/category/create?name=" + categoryName)
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// Admin权限
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(post("/admin/category/create?name=" + categoryName)
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CategoryModel category = (CategoryModel) JSONObject.toBean(object.getJSONObject(Result), CategoryModel.class);
|
|
||||||
assertEquals(categoryName, category.getName());
|
|
||||||
assertNotNull(category.getId());
|
|
||||||
assertNotEquals(0, category.getArticles());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteOne() throws Exception {
|
public void deleteOne() throws Exception {
|
||||||
Category category = categoryMapper.getLastestCategory();
|
Category category = categoryMapper.getLastestCategory();
|
||||||
// 未登录
|
getMockData(delete("/admin/category/del?id=" + category.getId()), adminLogin()).andDo(result -> {
|
||||||
mockMvc.perform(delete("/admin/category/del?id=" + category.getId())).andExpect(status().isOk())
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
.andDo(result -> {
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
assertTrue(response.getResult());
|
||||||
});
|
});
|
||||||
// User权限
|
|
||||||
String token = userLogin();
|
|
||||||
mockMvc.perform(delete("/admin/category/del?id=" + category.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// Admin权限
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(delete("/admin/category/del?id=" + category.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
assertTrue(object.getBoolean(Result));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateOne() throws Exception {
|
public void updateOne() throws Exception {
|
||||||
Category category = categoryMapper.getLastestCategory();
|
Category category = categoryMapper.getLastestCategory();
|
||||||
String name = randomStr(4);
|
String name = randomStr(4);
|
||||||
// 未登录
|
getMockData(put("/admin/category/update?id=" + category.getId() + "&name=" + name), adminLogin()).andDo(result -> {
|
||||||
mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name)).andExpect(status().isOk())
|
// Response<CategoryModel> response = mapper.readValue(result.getResponse().getContentAsString(), new ResponseType<Response<CategoryModel>>());
|
||||||
.andDo(result -> {
|
Response<CategoryModel> response = getResponse(result, CATEGORY_MODEL_TYPE);
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
});
|
CategoryModel c = response.getResult();
|
||||||
// User权限
|
assertEquals(name, c.getName());
|
||||||
String token = userLogin();
|
assertNull(c.getArticles());
|
||||||
mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name)
|
assertNotNull(c.getId());
|
||||||
.header("Authorization", token))
|
});
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// Admin权限
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name)
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CategoryModel c = (CategoryModel) JSONObject.toBean(object.getJSONObject(Result), CategoryModel.class);
|
|
||||||
assertEquals(name, c.getName());
|
|
||||||
assertNotEquals(0, c.getArticles());
|
|
||||||
assertNotNull(c.getId());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPage() throws Exception {
|
public void getPage() throws Exception {
|
||||||
mockMvc.perform(get("/categories")).andExpect(status().isOk())
|
getMockData(get("/categories")).andDo(result -> {
|
||||||
.andDo(result -> {
|
Response<PageData<CategoryModel>> response = getResponse(result, CATEGORY_MODEL_PAGE_TYPE);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertNotNull(response.getResult());
|
||||||
JSONArray jsonArray = object.getJSONObject(Result).getJSONArray("list");
|
response.getResult().getList().forEach(c -> {
|
||||||
assertNotNull(jsonArray);
|
assertNotNull(c.getName());
|
||||||
jsonArray.forEach(o -> {
|
assertNotNull(c.getId());
|
||||||
CategoryModel c = (CategoryModel) JSONObject.toBean(JSONObject.fromObject(o), CategoryModel.class);
|
assertNotNull(c.getArticles());
|
||||||
assertNotNull(c.getName());
|
});
|
||||||
assertNotNull(c.getId());
|
});
|
||||||
assertNotEquals(0, c.getArticles());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,21 +3,22 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.Article;
|
import cn.celess.blog.entity.Article;
|
||||||
import cn.celess.blog.entity.Comment;
|
import cn.celess.blog.entity.Comment;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.User;
|
||||||
import cn.celess.blog.entity.model.CommentModel;
|
import cn.celess.blog.entity.model.CommentModel;
|
||||||
import cn.celess.blog.entity.request.CommentReq;
|
import cn.celess.blog.entity.request.CommentReq;
|
||||||
import cn.celess.blog.mapper.ArticleMapper;
|
import cn.celess.blog.mapper.ArticleMapper;
|
||||||
import cn.celess.blog.mapper.CommentMapper;
|
import cn.celess.blog.mapper.CommentMapper;
|
||||||
import cn.celess.blog.mapper.UserMapper;
|
import cn.celess.blog.mapper.UserMapper;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.DATA_IS_DELETED;
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
public class CommentControllerTest extends BaseTest {
|
public class CommentControllerTest extends BaseTest {
|
||||||
@@ -27,46 +28,40 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
UserMapper userMapper;
|
UserMapper userMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
CommentMapper commentMapper;
|
CommentMapper commentMapper;
|
||||||
|
private static final TypeReference<?> COMMENT_MODEL_TYPE = new TypeReference<Response<CommentModel>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOne() throws Exception {
|
public void addOne() throws Exception {
|
||||||
Article article = articleMapper.getLastestArticle();
|
Article article = articleMapper.getLastestArticle();
|
||||||
CommentReq commentReq = new CommentReq();
|
CommentReq commentReq = new CommentReq();
|
||||||
commentReq.setPagePath("/article/" + article.getId());
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(randomStr());
|
||||||
commentReq.setPid(-1L);
|
List<User> all = userMapper.findAll();
|
||||||
commentReq.setToUserId(-1L);
|
commentReq.setPid(1L);
|
||||||
String token = userLogin();
|
commentReq.setToUserId(2l);
|
||||||
mockMvc.perform(post("/user/comment/create")
|
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.header("Authorization", token)
|
CommentModel model = response.getResult();
|
||||||
).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
||||||
assertEquals(-1, model.getPid().longValue());
|
assertEquals(1, model.getPid().longValue());
|
||||||
assertEquals(commentReq.getContent(), model.getContent());
|
assertEquals(commentReq.getContent(), model.getContent());
|
||||||
assertNotNull(model.getDate());
|
assertNotNull(model.getDate());
|
||||||
assertNotNull(model.getFromUser());
|
assertNotNull(model.getFromUser());
|
||||||
assertNull(model.getToUser());
|
assertNotNull(model.getToUser());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
commentReq.setPagePath("/article/" + article.getId());
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(randomStr());
|
||||||
commentReq.setPid(-1L);
|
commentReq.setPid(-1L);
|
||||||
commentReq.setToUserId(2);
|
commentReq.setToUserId(2);
|
||||||
mockMvc.perform(post("/user/comment/create")
|
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.header("Authorization", token)
|
CommentModel model = response.getResult();
|
||||||
).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
|
||||||
// 响应数据的完整性
|
// 响应数据的完整性
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
||||||
@@ -79,20 +74,16 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 测试二级回复
|
// 测试二级回复
|
||||||
Comment lastestComment = commentMapper.getLastestComment();
|
Comment latestComment = commentMapper.getLastestComment();
|
||||||
commentReq.setPagePath("/article/" + article.getId());
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(randomStr());
|
||||||
commentReq.setPid(lastestComment.getId());
|
commentReq.setPid(latestComment.getId());
|
||||||
mockMvc.perform(post("/user/comment/create")
|
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.header("Authorization", token)
|
CommentModel model = response.getResult();
|
||||||
).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
|
||||||
// 重新获取父评论信息
|
// 重新获取父评论信息
|
||||||
Comment pCommon = commentMapper.findCommentById(lastestComment.getId());
|
Comment pCommon = commentMapper.findCommentById(latestComment.getId());
|
||||||
assertEquals(pCommon.getId(), model.getPid());
|
assertEquals(pCommon.getId(), model.getPid());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -116,16 +107,13 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
// 接口测试
|
// 接口测试
|
||||||
long id = comment.getId();
|
long id = comment.getId();
|
||||||
assertNotEquals(0, id);
|
assertNotEquals(0, id);
|
||||||
String token = userLogin();
|
getMockData(delete("/user/comment/del?id=" + id), userLogin()).andDo(result -> {
|
||||||
mockMvc.perform(delete("/user/comment/del?id=" + id).header("Authorization", token)).andDo(result -> {
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertTrue(response.getResult());
|
||||||
assertTrue(object.getBoolean(Result));
|
|
||||||
});
|
|
||||||
mockMvc.perform(delete("/user/comment/del?id=" + id).header("Authorization", token)).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(DATA_IS_DELETED.getCode(), object.getInt(Code));
|
|
||||||
});
|
});
|
||||||
|
getMockData(delete("/user/comment/del?id=" + id), userLogin())
|
||||||
|
.andDo(result -> assertEquals(DATA_IS_DELETED.getCode(), getResponse(result, COMMENT_MODEL_TYPE).getCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -133,16 +121,12 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
Comment comment = commentMapper.getLastestComment();
|
Comment comment = commentMapper.getLastestComment();
|
||||||
CommentReq commentReq = new CommentReq();
|
CommentReq commentReq = new CommentReq();
|
||||||
commentReq.setId(comment.getId());
|
commentReq.setId(comment.getId());
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(randomStr());
|
||||||
// 不合法数据 setResponseId
|
// 不合法数据 setResponseId
|
||||||
mockMvc.perform(put("/user/comment/update")
|
getMockData(put("/user/comment/update"), userLogin(), commentReq).andDo(result -> {
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.header("Authorization", userLogin())
|
CommentModel c = response.getResult();
|
||||||
).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CommentModel c = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
|
||||||
assertEquals(commentReq.getContent(), c.getContent());
|
assertEquals(commentReq.getContent(), c.getContent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,183 +1,238 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.mapper.PartnerMapper;
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import com.github.pagehelper.PageInfo;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import net.sf.json.JSONObject;
|
import cn.celess.blog.exception.MyException;
|
||||||
import org.junit.Test;
|
import cn.celess.blog.mapper.PartnerMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import cn.celess.blog.service.PartnerSiteService;
|
||||||
import org.springframework.http.MediaType;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import java.util.UUID;
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
|
||||||
import static org.junit.Assert.*;
|
import java.util.List;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
public class LinksControllerTest extends BaseTest {
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
@Autowired
|
|
||||||
PartnerMapper mapper;
|
@Slf4j
|
||||||
|
public class LinksControllerTest extends BaseTest {
|
||||||
@Test
|
|
||||||
public void create() throws Exception {
|
@Autowired
|
||||||
LinkReq linkReq = new LinkReq();
|
PartnerMapper mapper;
|
||||||
linkReq.setName(UUID.randomUUID().toString().substring(0, 4));
|
private static final TypeReference<?> LINK_MODEL_TYPE = new TypeReference<Response<PartnerSite>>() {
|
||||||
linkReq.setOpen(false);
|
};
|
||||||
linkReq.setUrl("https://example.com");
|
private static final TypeReference<?> LINK_MODEL_LIST_TYPE = new TypeReference<Response<List<PartnerSite>>>() {
|
||||||
String token = adminLogin();
|
};
|
||||||
mockMvc.perform(
|
private static final TypeReference<?> LINK_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<PartnerSite>>>() {
|
||||||
post("/admin/links/create")
|
};
|
||||||
.content(JSONObject.fromObject(linkReq).toString())
|
@Autowired
|
||||||
.header("Authorization", token)
|
PartnerSiteService partnerSiteService;
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
@Test
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
public void create() throws Exception {
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(object.getJSONObject(Result), PartnerSite.class);
|
LinkReq linkReq = new LinkReq();
|
||||||
assertNotNull(site.getId());
|
linkReq.setName(randomStr(4));
|
||||||
assertEquals(linkReq.getName(), site.getName());
|
linkReq.setOpen(false);
|
||||||
assertEquals(linkReq.getUrl(), site.getUrl());
|
linkReq.setUrl("https://" + randomStr(4) + "example.com");
|
||||||
assertEquals(linkReq.isOpen(), site.getOpen());
|
getMockData(post("/admin/links/create"), adminLogin(), linkReq).andDo(result -> {
|
||||||
});
|
Response<PartnerSite> response = getResponse(result, LINK_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
// https/http
|
PartnerSite site = response.getResult();
|
||||||
linkReq.setName(UUID.randomUUID().toString().substring(0, 4));
|
assertNotNull(site.getId());
|
||||||
linkReq.setOpen(false);
|
assertEquals(linkReq.getName(), site.getName());
|
||||||
linkReq.setUrl("example.com");
|
assertEquals(linkReq.getUrl(), site.getUrl());
|
||||||
mockMvc.perform(
|
assertEquals(linkReq.isOpen(), site.getOpen());
|
||||||
post("/admin/links/create")
|
});
|
||||||
.content(JSONObject.fromObject(linkReq).toString())
|
|
||||||
.header("Authorization", token)
|
// https/http
|
||||||
.contentType("application/json")
|
linkReq.setName(randomStr(4));
|
||||||
).andDo(result -> {
|
linkReq.setOpen(false);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
linkReq.setUrl(randomStr(4) + ".example.com");
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
getMockData(post("/admin/links/create"), adminLogin(), linkReq).andDo(result -> {
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(object.getJSONObject(Result), PartnerSite.class);
|
Response<PartnerSite> response = getResponse(result, LINK_MODEL_TYPE);
|
||||||
assertEquals("http://example.com", site.getUrl());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
});
|
PartnerSite site = response.getResult();
|
||||||
|
assertEquals("http://" + linkReq.getUrl(), site.getUrl());
|
||||||
// 测试已存在的数据
|
});
|
||||||
mockMvc.perform(
|
|
||||||
post("/admin/links/create")
|
// 测试已存在的数据
|
||||||
.content(JSONObject.fromObject(linkReq).toString())
|
getMockData(post("/admin/links/create"), adminLogin(), linkReq).andDo(result ->
|
||||||
.header("Authorization", token)
|
assertEquals(DATA_HAS_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode())
|
||||||
.contentType("application/json")
|
);
|
||||||
).andDo(result -> assertEquals(DATA_HAS_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
public void del() throws Exception {
|
||||||
public void del() throws Exception {
|
PartnerSite partnerSite = new PartnerSite();
|
||||||
PartnerSite partnerSite = new PartnerSite();
|
partnerSite.setName(randomStr(4));
|
||||||
partnerSite.setName(UUID.randomUUID().toString().substring(0, 4));
|
partnerSite.setOpen(true);
|
||||||
partnerSite.setOpen(true);
|
partnerSite.setDesc("");
|
||||||
partnerSite.setDesc("");
|
partnerSite.setIconPath("");
|
||||||
partnerSite.setIconPath("");
|
partnerSite.setUrl("https://" + randomStr(4) + ".celess.cn");
|
||||||
partnerSite.setUrl("https://www.celess.cn");
|
mapper.insert(partnerSite);
|
||||||
mapper.insert(partnerSite);
|
PartnerSite latest = mapper.getLastest();
|
||||||
PartnerSite lastest = mapper.getLastest();
|
assertNotNull(latest.getId());
|
||||||
assertNotNull(lastest.getId());
|
getMockData(delete("/admin/links/del/" + latest.getId()), adminLogin()).andDo(result -> {
|
||||||
String token = adminLogin();
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
mockMvc.perform(delete("/admin/links/del/" + lastest.getId()).header("Authorization", token)).andDo(result -> {
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertTrue(response.getResult());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
});
|
||||||
assertTrue(object.getBoolean(Result));
|
long id = latest.getId();
|
||||||
});
|
do {
|
||||||
long id = lastest.getId();
|
id += 1;
|
||||||
do {
|
} while (mapper.existsById(id));
|
||||||
id += 1;
|
System.out.println("删除ID=" + id + "的数据");
|
||||||
} while (mapper.existsById(id));
|
getMockData(delete("/admin/links/del/" + id), adminLogin()).andDo(result ->
|
||||||
System.out.println("删除ID=" + id + "的数据");
|
assertEquals(DATA_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode())
|
||||||
mockMvc.perform(delete("/admin/links/del/" + id).header("Authorization", token)).andDo(result ->
|
);
|
||||||
assertEquals(DATA_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
}
|
||||||
);
|
|
||||||
}
|
@Test
|
||||||
|
public void update() throws Exception {
|
||||||
@Test
|
// 增数据
|
||||||
public void update() throws Exception {
|
PartnerSite partnerSite = new PartnerSite();
|
||||||
// 增数据
|
partnerSite.setName(randomStr(4));
|
||||||
PartnerSite partnerSite = new PartnerSite();
|
partnerSite.setOpen(true);
|
||||||
partnerSite.setName(UUID.randomUUID().toString().substring(0, 4));
|
partnerSite.setDesc("");
|
||||||
partnerSite.setOpen(true);
|
partnerSite.setIconPath("");
|
||||||
partnerSite.setDesc("");
|
partnerSite.setDelete(false);
|
||||||
partnerSite.setIconPath("");
|
partnerSite.setUrl("https://" + randomStr(5) + ".celess.cn");
|
||||||
partnerSite.setDelete(false);
|
mapper.insert(partnerSite);
|
||||||
partnerSite.setUrl("https://www.celess.cn");
|
// 查数据
|
||||||
mapper.insert(partnerSite);
|
PartnerSite latest = mapper.getLastest();
|
||||||
// 查数据
|
assertNotNull(latest.getId());
|
||||||
PartnerSite lastest = mapper.getLastest();
|
// 构建请求
|
||||||
assertNotNull(lastest.getId());
|
LinkReq linkReq = new LinkReq();
|
||||||
String token = adminLogin();
|
linkReq.setUrl(latest.getUrl());
|
||||||
// 构建请求
|
linkReq.setOpen(!latest.getOpen());
|
||||||
LinkReq linkReq = new LinkReq();
|
linkReq.setName(randomStr(4));
|
||||||
linkReq.setUrl(lastest.getUrl());
|
linkReq.setId(latest.getId());
|
||||||
linkReq.setOpen(!lastest.getOpen());
|
|
||||||
linkReq.setName(UUID.randomUUID().toString().substring(0, 4));
|
getMockData(put("/admin/links/update"), adminLogin(), linkReq).andDo(result -> {
|
||||||
linkReq.setId(lastest.getId());
|
Response<PartnerSite> response = getResponse(result, LINK_MODEL_TYPE);
|
||||||
mockMvc.perform(
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
put("/admin/links/update")
|
PartnerSite site = response.getResult();
|
||||||
.content(JSONObject.fromObject(linkReq).toString())
|
assertNotNull(site.getId());
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
assertEquals(linkReq.getId(), site.getId().longValue());
|
||||||
.header("Authorization", token)
|
assertEquals(linkReq.getUrl(), site.getUrl());
|
||||||
).andDo(result -> {
|
assertEquals(linkReq.getName(), site.getName());
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(linkReq.isOpen(), site.getOpen());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
});
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(object.getJSONObject(Result), PartnerSite.class);
|
}
|
||||||
assertNotNull(site.getId());
|
|
||||||
assertEquals(linkReq.getId(), site.getId().longValue());
|
@Test
|
||||||
assertEquals(linkReq.getUrl(), site.getUrl());
|
public void allForOpen() throws Exception {
|
||||||
assertEquals(linkReq.getName(), site.getName());
|
getMockData(get("/links")).andDo(result -> {
|
||||||
assertEquals(linkReq.isOpen(), site.getOpen());
|
Response<List<PartnerSite>> response = getResponse(result, LINK_MODEL_LIST_TYPE);
|
||||||
});
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
}
|
response.getResult().forEach(site -> {
|
||||||
|
assertNotNull(site.getUrl());
|
||||||
@Test
|
assertNull(site.getOpen());
|
||||||
public void allForOpen() throws Exception {
|
assertNotNull(site.getName());
|
||||||
mockMvc.perform(get("/links")).andDo(result -> {
|
});
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
});
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
}
|
||||||
object.getJSONArray(Result).forEach(o -> {
|
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(JSONObject.fromObject(o), PartnerSite.class);
|
@Test
|
||||||
assertNotNull(site.getUrl());
|
public void all() throws Exception {
|
||||||
assertNull(site.getOpen());
|
getMockData(get("/admin/links?page=1&count=10"), adminLogin()).andDo(result -> {
|
||||||
assertNotNull(site.getName());
|
Response<PageData<PartnerSite>> response = getResponse(result, LINK_MODEL_PAGE_TYPE);
|
||||||
});
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
});
|
PageData<PartnerSite> pageData = response.getResult();
|
||||||
}
|
assertEquals(1, pageData.getPageNum());
|
||||||
|
assertEquals(10, pageData.getPageSize());
|
||||||
@Test
|
for (PartnerSite site : pageData.getList()) {
|
||||||
public void all() throws Exception {
|
assertNotNull(site.getUrl());
|
||||||
mockMvc.perform(get("/admin/links?page=1&count=10").header("Authorization", adminLogin())).andDo(result -> {
|
assertNotNull(site.getName());
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertNotNull(site.getOpen());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
}
|
||||||
PageData<PartnerSite> pageData = (PageData<PartnerSite>) JSONObject.toBean(object.getJSONObject(Result), PageData.class);
|
});
|
||||||
assertEquals(1, pageData.getPageNum());
|
}
|
||||||
assertEquals(10, pageData.getPageSize());
|
|
||||||
for (Object o : pageData.getList()) {
|
@Test
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(JSONObject.fromObject(o), PartnerSite.class);
|
public void apply() {
|
||||||
assertNotNull(site.getUrl());
|
// 做service 层的测试
|
||||||
assertNotNull(site.getName());
|
// mockEmailServiceInstance(partnerSiteService, "mailService");
|
||||||
assertNotNull(site.getOpen());
|
mockInjectInstance(partnerSiteService, "mailService", new TestMailServiceImpl());
|
||||||
}
|
LinkApplyReq req = new LinkApplyReq();
|
||||||
});
|
req.setName(randomStr(4));
|
||||||
}
|
req.setUrl("https://" + randomStr(4) + ".celess.cn");
|
||||||
|
req.setIconPath("https://www.celess.cn/example.png");
|
||||||
// 手动测试
|
req.setDesc("desc :" + randomStr());
|
||||||
// @Test
|
req.setEmail(randomStr(4) + "@celess.cn");
|
||||||
public void apply() throws Exception {
|
req.setLinkUrl(req.getUrl() + "/links");
|
||||||
long l = System.currentTimeMillis();
|
try {
|
||||||
String url = "https://www.example.com";
|
// 抓取不到数据的链接
|
||||||
mockMvc.perform(post("/apply?name=小海博客Api测试,请忽略&url=" + url)).andDo(result -> {
|
partnerSiteService.apply(req);
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
} catch (MyException e) {
|
||||||
});
|
log.debug("测试抓取不到数据");
|
||||||
System.out.println("耗时:" + (System.currentTimeMillis() - l) / 1000 + "s");
|
assertEquals(CANNOT_GET_DATA.getCode(), e.getCode());
|
||||||
url = "xxxxxxxxxm";
|
}
|
||||||
mockMvc.perform(post("/apply?name=小海博客Api测试,请忽略&url=" + url)).andDo(result -> {
|
|
||||||
assertEquals(PARAMETERS_URL_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
req.setLinkUrl("https://bing.com");
|
||||||
});
|
req.setUrl(req.getLinkUrl());
|
||||||
|
try {
|
||||||
}
|
partnerSiteService.apply(req);
|
||||||
|
} catch (MyException e) {
|
||||||
|
log.debug("测试未添加本站链接的友链申请");
|
||||||
|
assertEquals(APPLY_LINK_NO_ADD_THIS_SITE.getCode(), e.getCode());
|
||||||
|
assertNotNull(e.getResult());
|
||||||
|
try {
|
||||||
|
// 测试uuid一致性
|
||||||
|
log.debug("测试uuid一致性");
|
||||||
|
partnerSiteService.apply(req);
|
||||||
|
} catch (MyException e2) {
|
||||||
|
assertEquals(e.getResult(), e2.getResult());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.debug("测试正常申请");
|
||||||
|
req.setLinkUrl("https://www.celess.cn");
|
||||||
|
req.setUrl(req.getLinkUrl());
|
||||||
|
PartnerSite apply = partnerSiteService.apply(req);
|
||||||
|
assertNotNull(apply);
|
||||||
|
assertNotNull(apply.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void reapply() {
|
||||||
|
//mockEmailServiceInstance(partnerSiteService, "mailService");
|
||||||
|
try {
|
||||||
|
partnerSiteService.reapply(randomStr());
|
||||||
|
throw new AssertionError();
|
||||||
|
} catch (MyException e) {
|
||||||
|
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkApplyReq req = new LinkApplyReq();
|
||||||
|
req.setName(randomStr(4));
|
||||||
|
req.setIconPath("https://www.celess.cn/example.png");
|
||||||
|
req.setDesc("desc :" + randomStr());
|
||||||
|
req.setEmail(randomStr(4) + "@celess.cn");
|
||||||
|
req.setLinkUrl("https://bing.com");
|
||||||
|
req.setUrl(req.getLinkUrl());
|
||||||
|
String uuid;
|
||||||
|
try {
|
||||||
|
partnerSiteService.apply(req);
|
||||||
|
// err here
|
||||||
|
throw new AssertionError();
|
||||||
|
} catch (MyException e) {
|
||||||
|
uuid = (String) e.getResult();
|
||||||
|
String reapply = partnerSiteService.reapply(uuid);
|
||||||
|
assertEquals(reapply, "success");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
partnerSiteService.reapply(uuid);
|
||||||
|
throw new AssertionError();
|
||||||
|
} catch (MyException e) {
|
||||||
|
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,42 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.Tag;
|
import cn.celess.blog.entity.Tag;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.TagModel;
|
import cn.celess.blog.entity.model.TagModel;
|
||||||
import cn.celess.blog.mapper.TagMapper;
|
import cn.celess.blog.mapper.TagMapper;
|
||||||
import net.sf.json.JSONArray;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
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.*;
|
|
||||||
|
|
||||||
public class TagControllerTest extends BaseTest {
|
public class TagControllerTest extends BaseTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
TagMapper tagMapper;
|
TagMapper tagMapper;
|
||||||
|
private static final TypeReference<?> TAG_MODEL_TYPE = new TypeReference<Response<TagModel>>() {
|
||||||
|
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> TAG_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<TagModel>>>() {
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> TAG_NAC_LIST_TYPE = new TypeReference<Response<List<Map<String, Object>>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOne() throws Exception {
|
public void addOne() throws Exception {
|
||||||
String name = randomStr(4);
|
String name = randomStr(4);
|
||||||
mockMvc.perform(post("/admin/tag/create?name=" + name)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
getMockData(post("/admin/tag/create?name=" + name)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
mockMvc.perform(post("/admin/tag/create?name=" + name).header("authorization", userLogin())).andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
getMockData(post("/admin/tag/create?name=" + name), userLogin()).andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
mockMvc.perform(post("/admin/tag/create?name=" + name).header("authorization", adminLogin())).andDo(result -> {
|
getMockData(post("/admin/tag/create?name=" + name), adminLogin()).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<TagModel> response = getResponse(result, TAG_MODEL_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONObject resJson = object.getJSONObject(Result);
|
TagModel tag = response.getResult();
|
||||||
TagModel tag = (TagModel) JSONObject.toBean(resJson, TagModel.class);
|
|
||||||
assertNotNull(tag.getId());
|
assertNotNull(tag.getId());
|
||||||
assertEquals(name, tag.getName());
|
assertEquals(name, tag.getName());
|
||||||
});
|
});
|
||||||
@@ -42,16 +48,14 @@ public class TagControllerTest extends BaseTest {
|
|||||||
public void delOne() throws Exception {
|
public void delOne() throws Exception {
|
||||||
Tag lastestTag = tagMapper.getLastestTag();
|
Tag lastestTag = tagMapper.getLastestTag();
|
||||||
assertNotNull(lastestTag.getId());
|
assertNotNull(lastestTag.getId());
|
||||||
String token = adminLogin();
|
getMockData(delete("/admin/tag/del?id=" + lastestTag.getId()), adminLogin()).andDo(result -> {
|
||||||
mockMvc.perform(delete("/admin/tag/del?id=" + lastestTag.getId()).header("Authorization", token)).andDo(result -> {
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertTrue(response.getResult());
|
||||||
assertTrue(object.getBoolean(Result));
|
|
||||||
});
|
});
|
||||||
long id = lastestTag.getId() * 2;
|
long id = lastestTag.getId() * 2;
|
||||||
mockMvc.perform(delete("/admin/tag/del?id=" + id).header("Authorization", token)).andDo(result ->
|
getMockData(delete("/admin/tag/del?id=" + id), adminLogin())
|
||||||
assertEquals(TAG_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
.andDo(result -> assertEquals(TAG_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,12 +63,12 @@ public class TagControllerTest extends BaseTest {
|
|||||||
public void updateOne() throws Exception {
|
public void updateOne() throws Exception {
|
||||||
Tag tag = tagMapper.getLastestTag();
|
Tag tag = tagMapper.getLastestTag();
|
||||||
assertNotNull(tag.getId());
|
assertNotNull(tag.getId());
|
||||||
String name = UUID.randomUUID().toString().substring(0, 4);
|
String name = randomStr(4);
|
||||||
mockMvc.perform(put("/admin/tag/update?id=" + tag.getId() + "&name=" + name).header("Authorization", adminLogin())).andDo(result -> {
|
getMockData(put("/admin/tag/update?id=" + tag.getId() + "&name=" + name), adminLogin()).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<TagModel> response = getResponse(result, TAG_MODEL_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(object.getJSONObject(Result));
|
assertNotNull(response.getResult());
|
||||||
TagModel t = (TagModel) JSONObject.toBean(object.getJSONObject(Result), TagModel.class);
|
TagModel t = response.getResult();
|
||||||
assertEquals(name, t.getName());
|
assertEquals(name, t.getName());
|
||||||
assertEquals(tag.getId(), t.getId());
|
assertEquals(tag.getId(), t.getId());
|
||||||
});
|
});
|
||||||
@@ -73,40 +77,33 @@ public class TagControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPage() throws Exception {
|
public void getPage() throws Exception {
|
||||||
mockMvc.perform(get("/tags?page=1&count=5"))
|
getMockData(get("/tags?page=1&count=5")).andDo(result -> {
|
||||||
.andExpect(status().is(200))
|
Response<PageData<TagModel>> response = getResponse(result, TAG_MODEL_PAGE_TYPE);
|
||||||
.andDo(result -> {
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONObject articlesJSON = JSONObject.fromObject(result.getResponse().getContentAsString());
|
// 结果集非空
|
||||||
// 断言获取数据成功
|
assertNotNull(response.getResult());
|
||||||
assertEquals(SUCCESS.getCode(), articlesJSON.getInt(Code));
|
// 判断pageInfo是否包装完全
|
||||||
// 结果集非空
|
PageData<TagModel> pageData = response.getResult();
|
||||||
assertNotNull(articlesJSON.getJSONObject(Result));
|
assertNotEquals(0, pageData.getTotal());
|
||||||
// 判断pageInfo是否包装完全
|
assertEquals(1, pageData.getPageNum());
|
||||||
JSONObject resultJson = JSONObject.fromObject(articlesJSON.getJSONObject(Result));
|
assertEquals(5, pageData.getPageSize());
|
||||||
PageData<TagModel> pageData = (PageData<TagModel>) JSONObject.toBean(resultJson, PageData.class);
|
// 内容完整
|
||||||
assertNotEquals(0, pageData.getTotal());
|
for (TagModel t : pageData.getList()) {
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertNotNull(t.getId());
|
||||||
assertEquals(5, pageData.getPageSize());
|
assertNotNull(t.getName());
|
||||||
// 内容完整
|
}
|
||||||
for (Object tag : pageData.getList()) {
|
});
|
||||||
TagModel t = (TagModel) JSONObject.toBean(JSONObject.fromObject(tag), TagModel.class);
|
|
||||||
assertNotNull(t.getId());
|
|
||||||
assertNotNull(t.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTagNameAndCount() throws Exception {
|
public void getTagNameAndCount() throws Exception {
|
||||||
mockMvc.perform(get("/tags/nac")).andDo(result -> {
|
getMockData(get("/tags/nac")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<List<Map<String, Object>>> response = getResponse(result, TAG_NAC_LIST_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONArray jsonArray = object.getJSONArray(Result);
|
assertNotNull(response.getResult());
|
||||||
assertNotNull(jsonArray);
|
response.getResult().forEach(o -> {
|
||||||
jsonArray.forEach(o -> {
|
assertNotNull(o.get("name"));
|
||||||
JSONObject json = JSONObject.fromObject(o);
|
assertNotNull(o.get("size"));
|
||||||
assertTrue(json.containsKey("size"));
|
|
||||||
assertTrue(json.containsKey("name"));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,276 +1,277 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.User;
|
||||||
import cn.celess.blog.entity.model.UserModel;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.request.LoginReq;
|
import cn.celess.blog.entity.model.UserModel;
|
||||||
import cn.celess.blog.entity.request.UserReq;
|
import cn.celess.blog.entity.request.LoginReq;
|
||||||
import cn.celess.blog.mapper.UserMapper;
|
import cn.celess.blog.entity.request.UserReq;
|
||||||
import cn.celess.blog.util.MD5Util;
|
import cn.celess.blog.mapper.UserMapper;
|
||||||
import net.sf.json.JSONArray;
|
import cn.celess.blog.service.UserService;
|
||||||
import net.sf.json.JSONObject;
|
import cn.celess.blog.util.MD5Util;
|
||||||
import org.junit.Test;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import org.springframework.http.MediaType;
|
import org.junit.Test;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
import java.io.InputStream;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import java.net.HttpURLConnection;
|
import org.springframework.util.MultiValueMap;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.*;
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import static org.junit.Assert.*;
|
import java.net.URL;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import java.util.ArrayList;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import java.util.List;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
public class UserControllerTest extends BaseTest {
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
@Autowired
|
|
||||||
UserMapper userMapper;
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
@Test
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
public void login() throws Exception {
|
|
||||||
assertNotNull(userLogin());
|
|
||||||
assertNotNull(adminLogin());
|
public class UserControllerTest extends BaseTest {
|
||||||
// 用户不存在
|
|
||||||
LoginReq req = new LoginReq();
|
@Autowired
|
||||||
req.setEmail("zh@celess.cn");
|
UserMapper userMapper;
|
||||||
req.setPassword("123456789");
|
@Autowired
|
||||||
req.setIsRememberMe(false);
|
|
||||||
JSONObject loginReq = JSONObject.fromObject(req);
|
RedisUtil redisUtil;
|
||||||
mockMvc.perform(post("/login").content(loginReq.toString()).contentType("application/json"))
|
private static final TypeReference<?> USER_MODEL_TYPE = new TypeReference<Response<UserModel>>() {
|
||||||
.andDo(result ->
|
};
|
||||||
assertEquals(USER_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
private static final TypeReference<?> USER_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<UserModel>>>() {
|
||||||
);
|
};
|
||||||
}
|
private static final TypeReference<?> USER_MODEL_LIST_TYPE = new TypeReference<Response<List<Map<String, Object>>>>() {
|
||||||
|
};
|
||||||
@Test
|
@Autowired
|
||||||
public void registration() {
|
UserService userService;
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
public void login() throws Exception {
|
||||||
public void logout() throws Exception {
|
assertNotNull(userLogin());
|
||||||
mockMvc.perform(get("/logout")).andDo(result -> assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
assertNotNull(adminLogin());
|
||||||
mockMvc.perform(get("/logout").header("Authorization", userLogin())).andDo(result -> assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
// 用户不存在
|
||||||
}
|
LoginReq req = new LoginReq();
|
||||||
|
req.setEmail("zh@celess.cn");
|
||||||
@Test
|
req.setPassword("123456789");
|
||||||
public void updateInfo() throws Exception {
|
req.setIsRememberMe(false);
|
||||||
String desc = UUID.randomUUID().toString().substring(0, 4);
|
getMockData(post("/login"), null, req).andDo(result -> assertEquals(USER_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
String disPlayName = UUID.randomUUID().toString().substring(0, 4);
|
}
|
||||||
mockMvc.perform(put("/user/userInfo/update?desc=" + desc + "&displayName=" + disPlayName).header("Authorization", userLogin()))
|
|
||||||
.andDo(result -> {
|
@Test
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
public void registration() {
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
// ignore
|
||||||
UserModel u = (UserModel) JSONObject.toBean(object.getJSONObject(Result), UserModel.class);
|
}
|
||||||
assertEquals(desc, u.getDesc());
|
|
||||||
assertEquals(disPlayName, u.getDisplayName());
|
@Test
|
||||||
assertNotNull(u.getId());
|
public void logout() throws Exception {
|
||||||
});
|
getMockData(get("/logout")).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
}
|
getMockData(get("/logout"), adminLogin()).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void getUserInfo() throws Exception {
|
@Test
|
||||||
mockMvc.perform(get("/user/userInfo").header("Authorization", userLogin()))
|
public void updateInfo() throws Exception {
|
||||||
.andDo(result -> {
|
String desc = randomStr(4);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
String disPlayName = randomStr(4);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
getMockData(put("/user/userInfo/update?desc=" + desc + "&displayName=" + disPlayName), userLogin()).andDo(result -> {
|
||||||
UserModel u = (UserModel) JSONObject.toBean(object.getJSONObject(Result), UserModel.class);
|
Response<UserModel> response = getResponse(result, USER_MODEL_TYPE);
|
||||||
assertNotNull(u.getId());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(u.getEmail());
|
UserModel u = response.getResult();
|
||||||
assertNotNull(u.getDisplayName());
|
assertEquals(desc, u.getDesc());
|
||||||
assertNotNull(u.getEmailStatus());
|
assertEquals(disPlayName, u.getDisplayName());
|
||||||
assertNotNull(u.getAvatarImgUrl());
|
assertNotNull(u.getId());
|
||||||
assertNotNull(u.getDesc());
|
});
|
||||||
assertNotNull(u.getRecentlyLandedDate());
|
}
|
||||||
assertNotNull(u.getRole());
|
|
||||||
});
|
@Test
|
||||||
}
|
public void getUserInfo() throws Exception {
|
||||||
|
getMockData(get("/user/userInfo"), adminLogin()).andDo(result -> {
|
||||||
@Test
|
Response<UserModel> response = getResponse(result, USER_MODEL_TYPE);
|
||||||
public void upload() throws Exception {
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
URL url = new URL("https://56462271.oss-cn-beijing.aliyuncs.com/web/logo.png");
|
UserModel u = response.getResult();
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
assertNotNull(u.getId());
|
||||||
connection.setRequestMethod("GET");
|
assertNotNull(u.getEmail());
|
||||||
InputStream inputStream = connection.getInputStream();
|
assertNotNull(u.getDisplayName());
|
||||||
assertNotNull(inputStream);
|
assertNotNull(u.getEmailStatus());
|
||||||
MockMultipartFile file = new MockMultipartFile("file", "logo.png", MediaType.IMAGE_PNG_VALUE, inputStream);
|
assertNotNull(u.getAvatarImgUrl());
|
||||||
mockMvc.perform(multipart("/user/imgUpload").file(file)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
assertNotNull(u.getDesc());
|
||||||
mockMvc.perform(multipart("/user/imgUpload").file(file).header("Authorization", userLogin())).andDo(result -> {
|
assertNotNull(u.getRecentlyLandedDate());
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertNotNull(u.getRole());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
});
|
||||||
assertNotNull(object.getString(Result));
|
}
|
||||||
});
|
|
||||||
}
|
@Test
|
||||||
|
public void upload() throws Exception {
|
||||||
@Test
|
URL url = new URL("https://56462271.oss-cn-beijing.aliyuncs.com/web/logo.png");
|
||||||
public void sendResetPwdEmail() {
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
// ignore
|
connection.setRequestMethod("GET");
|
||||||
}
|
InputStream inputStream = connection.getInputStream();
|
||||||
|
assertNotNull(inputStream);
|
||||||
@Test
|
|
||||||
public void sendVerifyEmail() {
|
// mock 实现类
|
||||||
// ignore
|
mockInjectInstance(userService, "qiniuService", new TestQiNiuServiceImpl());
|
||||||
}
|
|
||||||
|
MockMultipartFile file = new MockMultipartFile("file", "logo.png", MediaType.IMAGE_PNG_VALUE, inputStream);
|
||||||
@Test
|
getMockData(multipart("/user/imgUpload").file(file), userLogin()).andDo(result -> {
|
||||||
public void emailVerify() {
|
Response<Object> response = getResponse(result, OBJECT_TYPE);
|
||||||
// ignore
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
}
|
assertNotNull(response.getResult());
|
||||||
|
});
|
||||||
@Test
|
}
|
||||||
public void resetPwd() {
|
|
||||||
// ignore
|
@Test
|
||||||
}
|
public void sendResetPwdEmail() {
|
||||||
|
// ignore
|
||||||
@Test
|
}
|
||||||
public void multipleDelete() throws Exception {
|
|
||||||
List<User> userList = new ArrayList<>();
|
@Test
|
||||||
for (int i = 0; i < 10; i++) {
|
public void sendVerifyEmail() {
|
||||||
String s = UUID.randomUUID().toString();
|
// ignore
|
||||||
String email = s.substring(s.length() - 4) + "@celess.cn";
|
}
|
||||||
String pwd = MD5Util.getMD5("123456789");
|
|
||||||
User user = new User(email, pwd);
|
@Test
|
||||||
int i1 = userMapper.addUser(user);
|
public void emailVerify() throws Exception {
|
||||||
if (i1 == 0) {
|
String email = randomStr(4) + "@celess.cn";
|
||||||
continue;
|
String pwd = MD5Util.getMD5("123456789");
|
||||||
}
|
userMapper.addUser(new User(email, pwd));
|
||||||
userList.add(userMapper.findByEmail(email));
|
String verifyId = randomStr();
|
||||||
if (i == 9) {
|
LoginReq req = new LoginReq(email, "123456789", true);
|
||||||
//设置一个管理员
|
redisUtil.setEx(email + "-verify", verifyId, 2, TimeUnit.DAYS);
|
||||||
userMapper.setUserRole(userMapper.findByEmail(email).getId(), "admin");
|
getMockData(post("/emailVerify").param("verifyId", verifyId).param("email", email), login(req)).andDo(result ->
|
||||||
}
|
assertEquals(SUCCESS.getCode(), getResponse(result, OBJECT_TYPE).getCode())
|
||||||
}
|
);
|
||||||
List<Long> idList = new ArrayList<>();
|
}
|
||||||
userList.forEach(user -> idList.add(user.getId()));
|
|
||||||
System.out.println("id :: == > " + idList.toString());
|
@Test
|
||||||
mockMvc.perform(delete("/admin/user/delete").content(idList.toString()).contentType("application/json"))
|
public void resetPwd() throws Exception {
|
||||||
.andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
String email = randomStr(4) + "@celess.cn";
|
||||||
mockMvc.perform(delete("/admin/user/delete").content(idList.toString()).contentType("application/json").header("Authorization", userLogin()))
|
String pwd = MD5Util.getMD5("1234567890");
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
userMapper.addUser(new User(email, pwd));
|
||||||
mockMvc.perform(delete("/admin/user/delete").content(idList.toString()).contentType("application/json").header("Authorization", adminLogin()))
|
LoginReq req = new LoginReq(email, "1234567890", true);
|
||||||
.andDo(result -> {
|
String verifyId = randomStr();
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
// 设置验证id
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
redisUtil.setEx(email + "-resetPwd", verifyId, 2, TimeUnit.DAYS);
|
||||||
JSONArray jsonArray = object.getJSONArray(Result);
|
MockHttpServletRequestBuilder resetPwd = post("/resetPwd").param("verifyId", verifyId).param("email", email).param("pwd", "123456789");
|
||||||
jsonArray.forEach(o -> {
|
// 未验证
|
||||||
JSONObject json = JSONObject.fromObject(o);
|
getMockData(resetPwd, login(req)).andDo(result -> assertEquals(USEREMAIL_NOT_VERIFY.getCode(), getResponse(result, OBJECT_TYPE).getCode()));
|
||||||
// 判断响应数据中是否包含输入的id
|
// 设置未验证
|
||||||
assertTrue(idList.contains((long) json.getInt("id")));
|
userMapper.updateEmailStatus(email, true);
|
||||||
// 判断处理状态
|
// 正常
|
||||||
boolean status = json.getBoolean("status");
|
getMockData(resetPwd, login(req)).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result, OBJECT_TYPE).getCode()));
|
||||||
if (json.containsKey("msg"))
|
}
|
||||||
assertFalse(status);
|
|
||||||
else
|
@Test
|
||||||
assertTrue(status);
|
public void multipleDelete() throws Exception {
|
||||||
});
|
List<User> userList = new ArrayList<>();
|
||||||
});
|
for (int i = 0; i < 10; i++) {
|
||||||
|
String s = randomStr();
|
||||||
}
|
String email = s.substring(s.length() - 4) + "@celess.cn";
|
||||||
|
String pwd = MD5Util.getMD5("123456789");
|
||||||
@Test
|
User user = new User(email, pwd);
|
||||||
public void updateInfoByAdmin() throws Exception {
|
int i1 = userMapper.addUser(user);
|
||||||
UserReq userReq = new UserReq();
|
if (i1 == 0) {
|
||||||
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
continue;
|
||||||
User user = new User(email, MD5Util.getMD5("123456789"));
|
}
|
||||||
userMapper.addUser(user);
|
userList.add(userMapper.findByEmail(email));
|
||||||
User userByDb = userMapper.findByEmail(email);
|
if (i == 9) {
|
||||||
userReq.setId(userByDb.getId());
|
//设置一个管理员
|
||||||
userReq.setPwd(UUID.randomUUID().toString().replaceAll("-", "").substring(0, 10));
|
userMapper.setUserRole(userMapper.findByEmail(email).getId(), "admin");
|
||||||
userReq.setDesc(UUID.randomUUID().toString());
|
}
|
||||||
userReq.setEmailStatus(new Random().nextBoolean());
|
}
|
||||||
userReq.setRole("admin");
|
List<Integer> idList = userList.stream().map(user -> user.getId().intValue()).collect(Collectors.toList());
|
||||||
userReq.setDisplayName(UUID.randomUUID().toString().substring(0, 4));
|
getMockData(delete("/admin/user/delete"), adminLogin(), idList).andDo(result -> {
|
||||||
userReq.setEmail(UUID.randomUUID().toString().substring(0, 5) + "@celess.cn");
|
Response<List<Map<String, Object>>> response = getResponse(result, USER_MODEL_LIST_TYPE);
|
||||||
mockMvc.perform(put("/admin/user").contentType("application/json").content(JSONObject.fromObject(userReq).toString()))
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
response.getResult().forEach(o -> {
|
||||||
mockMvc.perform(put("/admin/user").contentType("application/json").header("Authorization", userLogin()).content(JSONObject.fromObject(userReq).toString()))
|
// 判断响应数据中是否包含输入的id
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
assertTrue(idList.contains((int) o.get("id")));
|
||||||
mockMvc.perform(put("/admin/user").contentType("application/json").header("Authorization", adminLogin()).content(JSONObject.fromObject(userReq).toString()))
|
// 判断处理状态
|
||||||
.andDo(result -> {
|
boolean status = (boolean) o.get("status");
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
if (o.containsKey("msg"))
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertFalse(status);
|
||||||
UserModel userModel = (UserModel) JSONObject.toBean(object.getJSONObject(Result), UserModel.class);
|
else
|
||||||
assertEquals(userReq.getId(), userModel.getId());
|
assertTrue(status);
|
||||||
assertEquals(userReq.getRole(), userModel.getRole());
|
});
|
||||||
assertEquals(userReq.getEmail(), userModel.getEmail());
|
});
|
||||||
assertEquals(userReq.getDesc(), userModel.getDesc());
|
|
||||||
assertEquals(userReq.getDisplayName(), userModel.getDisplayName());
|
}
|
||||||
});
|
|
||||||
}
|
@Test
|
||||||
|
public void updateInfoByAdmin() throws Exception {
|
||||||
@Test
|
UserReq userReq = new UserReq();
|
||||||
public void getAllUser() throws Exception {
|
String email = randomStr(4) + "@celess.cn";
|
||||||
mockMvc.perform(get("/admin/users?page=1&count=10"))
|
User user = new User(email, MD5Util.getMD5("123456789"));
|
||||||
.andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
userMapper.addUser(user);
|
||||||
mockMvc.perform(get("/admin/users?page=1&count=10").header("authorization", userLogin()))
|
User userByDb = userMapper.findByEmail(email);
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
userReq.setId(userByDb.getId());
|
||||||
mockMvc.perform(get("/admin/users?page=1&count=10").header("Authorization", adminLogin()))
|
userReq.setPwd(randomStr().substring(0, 10));
|
||||||
.andDo(result -> {
|
userReq.setDesc(randomStr());
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
userReq.setEmailStatus(new Random().nextBoolean());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
userReq.setRole("admin");
|
||||||
// 结果集非空
|
userReq.setDisplayName(randomStr(4));
|
||||||
assertNotNull(object.getJSONObject(Result));
|
userReq.setEmail(randomStr(5) + "@celess.cn");
|
||||||
// 判断pageInfo是否包装完全
|
getMockData(put("/admin/user"), adminLogin(), userReq).andDo(result -> {
|
||||||
JSONObject resultJson = JSONObject.fromObject(object.getJSONObject(Result));
|
Response<UserModel> response = getResponse(result, USER_MODEL_TYPE);
|
||||||
PageData<UserModel> pageData = (PageData<UserModel>) JSONObject.toBean(resultJson, PageData.class);
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotEquals(0, pageData.getTotal());
|
UserModel userModel = response.getResult();
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertEquals(userReq.getId(), userModel.getId());
|
||||||
assertEquals(10, pageData.getPageSize());
|
assertEquals(userReq.getRole(), userModel.getRole());
|
||||||
// 内容完整
|
assertEquals(userReq.getEmail(), userModel.getEmail());
|
||||||
for (Object user : pageData.getList()) {
|
assertEquals(userReq.getDesc(), userModel.getDesc());
|
||||||
UserModel u = (UserModel) JSONObject.toBean(JSONObject.fromObject(user), UserModel.class);
|
assertEquals(userReq.getDisplayName(), userModel.getDisplayName());
|
||||||
assertNotNull(u.getId());
|
});
|
||||||
assertNotNull(u.getEmail());
|
}
|
||||||
assertNotNull(u.getRole());
|
|
||||||
assertNotNull(u.getEmailStatus());
|
@Test
|
||||||
assertNotNull(u.getDisplayName());
|
public void getAllUser() throws Exception {
|
||||||
}
|
getMockData(get("/admin/users?page=1&count=10"), adminLogin()).andDo(result -> {
|
||||||
});
|
Response<PageData<UserModel>> response = getResponse(result, USER_MODEL_PAGE_TYPE);
|
||||||
}
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
// 结果集非空
|
||||||
@Test
|
assertNotNull(response.getResult());
|
||||||
public void getEmailStatus() throws Exception {
|
// 判断pageInfo是否包装完全
|
||||||
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
PageData<UserModel> pageData = response.getResult();
|
||||||
mockMvc.perform(get("/emailStatus/" + email)).andDo(result -> {
|
assertNotEquals(0, pageData.getTotal());
|
||||||
String content = result.getResponse().getContentAsString();
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(content).getInt(Code));
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertFalse(JSONObject.fromObject(content).getBoolean(Result));
|
// 内容完整
|
||||||
});
|
for (UserModel u : pageData.getList()) {
|
||||||
email = "a@celess.cn";
|
assertNotNull(u.getId());
|
||||||
mockMvc.perform(get("/emailStatus/" + email)).andDo(result -> {
|
assertNotNull(u.getEmail());
|
||||||
String content = result.getResponse().getContentAsString();
|
assertNotNull(u.getRole());
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(content).getInt(Code));
|
assertNotNull(u.getEmailStatus());
|
||||||
assertTrue(JSONObject.fromObject(content).getBoolean(Result));
|
assertNotNull(u.getDisplayName());
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void setPwd() throws Exception {
|
@Test
|
||||||
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
public void getEmailStatus() throws Exception {
|
||||||
assertEquals(1, userMapper.addUser(new User(email, MD5Util.getMD5("1234567890"))));
|
String email = randomStr(4) + "@celess.cn";
|
||||||
LoginReq req = new LoginReq();
|
getMockData(get("/emailStatus/" + email)).andDo(result -> assertFalse((Boolean) getResponse(result, BOOLEAN_TYPE).getResult()));
|
||||||
req.setEmail(email);
|
getMockData(get("/emailStatus/" + ADMIN_EMAIL)).andDo(result -> assertTrue((Boolean) getResponse(result, BOOLEAN_TYPE).getResult()));
|
||||||
req.setPassword("1234567890");
|
}
|
||||||
req.setIsRememberMe(false);
|
|
||||||
JSONObject loginReq = JSONObject.fromObject(req);
|
@Test
|
||||||
String contentAsString = mockMvc.perform(post("/login").content(loginReq.toString()).contentType("application/json")).andReturn().getResponse().getContentAsString();
|
public void setPwd() throws Exception {
|
||||||
assertNotNull(contentAsString);
|
String email = randomStr(4) + "@celess.cn";
|
||||||
String token = JSONObject.fromObject(contentAsString).getJSONObject(Result).getString("token");
|
assertEquals(1, userMapper.addUser(new User(email, MD5Util.getMD5("1234567890"))));
|
||||||
assertNotNull(token);
|
LoginReq req = new LoginReq(email, "1234567890", false);
|
||||||
MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
|
String token = login(req);
|
||||||
param.add("pwd", "1234567890");
|
assertNotNull(token);
|
||||||
param.add("newPwd", "aaabbbccc");
|
MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
|
||||||
param.add("confirmPwd", "aaabbbccc");
|
param.add("pwd", "1234567890");
|
||||||
mockMvc.perform(post("/user/setPwd").header("Authorization", token).params(param)).andDo(result -> {
|
param.add("newPwd", "aaabbbccc");
|
||||||
String content = result.getResponse().getContentAsString();
|
param.add("confirmPwd", "aaabbbccc");
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(content).getInt(Code));
|
getMockData(post("/user/setPwd").params(param), token).andDo(result -> {
|
||||||
assertEquals(MD5Util.getMD5("aaabbbccc"), userMapper.getPwd(email));
|
assertEquals(SUCCESS.getCode(), getResponse(result).getCode());
|
||||||
});
|
assertEquals(MD5Util.getMD5("aaabbbccc"), userMapper.getPwd(email));
|
||||||
}
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,29 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.VisitorModel;
|
import cn.celess.blog.entity.model.VisitorModel;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
|
||||||
|
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
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.get;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
|
||||||
public class VisitorControllerTest extends BaseTest {
|
public class VisitorControllerTest extends BaseTest {
|
||||||
|
private final TypeReference<?> VISITOR_PAGE_TYPE = new TypeReference<Response<PageData<VisitorModel>>>() {
|
||||||
|
};
|
||||||
|
private final TypeReference<?> VISITOR_TYPE = new TypeReference<Response<VisitorModel>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getVisitorCount() throws Exception {
|
public void getVisitorCount() throws Exception {
|
||||||
mockMvc.perform(get("/visitor/count")).andDo(result -> {
|
getMockData(get("/visitor/count")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<Object> response = getResponse(result);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertTrue(object.containsKey(Result));
|
assertNotNull(response.getResult());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,29 +31,28 @@ public class VisitorControllerTest extends BaseTest {
|
|||||||
public void page() throws Exception {
|
public void page() throws Exception {
|
||||||
int count = 10;
|
int count = 10;
|
||||||
int page = 1;
|
int page = 1;
|
||||||
mockMvc.perform(get("/admin/visitor/page?count=" + count + "&page=" + page).header("Authorization", adminLogin()))
|
// 默认显示location
|
||||||
.andDo(result -> {
|
getMockData(get("/admin/visitor/page?count=" + count + "&page=" + page), adminLogin()).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<PageData<VisitorModel>> response = getResponse(result, VISITOR_PAGE_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONObject resultJson = JSONObject.fromObject(object.getJSONObject(Result));
|
PageData<VisitorModel> pageData = response.getResult();
|
||||||
PageData<VisitorModel> pageData = (PageData<VisitorModel>) JSONObject.toBean(resultJson, PageData.class);
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertNotEquals(0, pageData.getTotal());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(10, pageData.getPageSize());
|
for (VisitorModel v : pageData.getList()) {
|
||||||
for (Object ver : pageData.getList()) {
|
assertNotEquals(0, v.getId());
|
||||||
VisitorModel v = (VisitorModel) JSONObject.toBean(JSONObject.fromObject(ver), VisitorModel.class);
|
assertNotNull(v.getDate());
|
||||||
assertNotEquals(0, v.getId());
|
assertNotNull(v.getLocation());
|
||||||
assertNotNull(v.getDate());
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void add() throws Exception {
|
public void add() throws Exception {
|
||||||
mockMvc.perform(post("/visit")).andDo(MockMvcResultHandlers.print()).andDo(result -> {
|
getMockData(post("/visit")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<VisitorModel> response = getResponse(result, VISITOR_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
VisitorModel visitorModel = (VisitorModel) JSONObject.toBean(object.getJSONObject(Result), VisitorModel.class);
|
VisitorModel visitorModel = response.getResult();
|
||||||
assertNotEquals(0, visitorModel.getId());
|
assertNotEquals(0, visitorModel.getId());
|
||||||
assertNotNull(visitorModel.getIp());
|
assertNotNull(visitorModel.getIp());
|
||||||
});
|
});
|
||||||
@@ -57,26 +60,26 @@ public class VisitorControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dayVisitCount() throws Exception {
|
public void dayVisitCount() throws Exception {
|
||||||
mockMvc.perform(get("/dayVisitCount")).andDo(MockMvcResultHandlers.print()).andDo(result ->
|
getMockData(get("/dayVisitCount")).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手动测试
|
// 手动测试
|
||||||
// @Test
|
// @Test
|
||||||
public void ipLocation() throws Exception {
|
public void ipLocation() throws Exception {
|
||||||
String ip = "127.0.0.1";
|
String ip = "127.0.0.1";
|
||||||
mockMvc.perform(get("/ip/" + ip)).andDo(MockMvcResultHandlers.print()).andDo(result -> {
|
getMockData(get("/ip/" + ip)).andDo(result -> {
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
Response<Object> response = getResponse(result);
|
||||||
assertTrue(JSONObject.fromObject(result.getResponse().getContentAsString()).containsKey(Result));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getIp() throws Exception {
|
public void getIp() throws Exception {
|
||||||
mockMvc.perform(get("/ip")).andDo(MockMvcResultHandlers.print()).andDo(result -> {
|
getMockData(get("/ip")).andDo(result -> {
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
Response<String> response = getResponse(result, STRING_TYPE);
|
||||||
assertEquals("127.0.0.1", JSONObject.fromObject(result.getResponse().getContentAsString()).getString(Result));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertEquals("127.0.0.1", response.getResult());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,35 +1,46 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.WebUpdate;
|
import cn.celess.blog.entity.WebUpdate;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
||||||
import net.sf.json.JSONArray;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import net.sf.json.JSONObject;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
import static cn.celess.blog.enmu.ResponseEnum.DATA_NOT_EXIST;
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
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.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class WebUpdateInfoControllerTest extends BaseTest {
|
public class WebUpdateInfoControllerTest extends BaseTest {
|
||||||
|
|
||||||
|
private final TypeReference<?> MODAL_TYPE = new TypeReference<Response<WebUpdateModel>>() {
|
||||||
|
};
|
||||||
|
private final TypeReference<?> MODAL_LIST_TYPE = new TypeReference<Response<List<WebUpdateModel>>>() {
|
||||||
|
};
|
||||||
|
private final TypeReference<?> MODAL_PAGE_TYPE = new TypeReference<Response<PageData<WebUpdateModel>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
WebUpdateInfoMapper mapper;
|
WebUpdateInfoMapper mapper;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create() throws Exception {
|
public void create() throws Exception {
|
||||||
String info = UUID.randomUUID().toString();
|
String info = randomStr();
|
||||||
mockMvc.perform(post("/admin/webUpdate/create?info=" + info).header("Authorization", adminLogin())).andDo(result -> {
|
getMockData(post("/admin/webUpdate/create?info=" + info), adminLogin()).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<WebUpdateModel> response = getResponse(result, MODAL_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertTrue(object.containsKey(Result));
|
assertNotNull(response.getResult());
|
||||||
WebUpdateModel webUpdateModel = (WebUpdateModel) JSONObject.toBean(object.getJSONObject(Result), WebUpdateModel.class);
|
WebUpdateModel webUpdateModel = response.getResult();
|
||||||
assertEquals(info, webUpdateModel.getInfo());
|
assertEquals(info, webUpdateModel.getInfo());
|
||||||
assertNotNull(webUpdateModel.getTime());
|
assertNotNull(webUpdateModel.getTime());
|
||||||
assertNotEquals(0, webUpdateModel.getId());
|
assertNotEquals(0, webUpdateModel.getId());
|
||||||
@@ -40,7 +51,7 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
public void del() throws Exception {
|
public void del() throws Exception {
|
||||||
// 新增数据
|
// 新增数据
|
||||||
WebUpdate webUpdate = new WebUpdate();
|
WebUpdate webUpdate = new WebUpdate();
|
||||||
webUpdate.setUpdateInfo(UUID.randomUUID().toString());
|
webUpdate.setUpdateInfo(randomStr());
|
||||||
webUpdate.setUpdateTime(new Date());
|
webUpdate.setUpdateTime(new Date());
|
||||||
mapper.insert(webUpdate);
|
mapper.insert(webUpdate);
|
||||||
// 接口测试
|
// 接口测试
|
||||||
@@ -49,32 +60,31 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
assertNotEquals(0, update.getId());
|
assertNotEquals(0, update.getId());
|
||||||
|
|
||||||
long id = update.getId();
|
long id = update.getId();
|
||||||
mockMvc.perform(delete("/admin/webUpdate/del/" + id).header("Authorization", adminLogin())).andDo(result -> {
|
getMockData(delete("/admin/webUpdate/del/" + id), adminLogin()).andDo(result -> {
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
Response<Object> response = getResponse(result);
|
||||||
assertTrue(JSONObject.fromObject(result.getResponse().getContentAsString()).getBoolean(Result));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
});
|
});
|
||||||
do {
|
do {
|
||||||
id += 2;
|
id += 2;
|
||||||
} while (mapper.existsById(id));
|
} while (mapper.existsById(id));
|
||||||
System.out.println("准备删除ID=" + id + "的不存在记录");
|
log.debug("准备删除ID={}的不存在记录", id);
|
||||||
mockMvc.perform(delete("/admin/webUpdate/del/" + id).header("Authorization", adminLogin())).andDo(result ->
|
getMockData(delete("/admin/webUpdate/del/" + id), adminLogin()).andDo(result -> assertEquals(DATA_NOT_EXIST.getCode(), getResponse(result).getCode()));
|
||||||
assertEquals(DATA_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void update() throws Exception {
|
public void update() throws Exception {
|
||||||
// 新增数据
|
// 新增数据
|
||||||
WebUpdate webUpdate = new WebUpdate();
|
WebUpdate webUpdate = new WebUpdate();
|
||||||
webUpdate.setUpdateInfo(UUID.randomUUID().toString());
|
webUpdate.setUpdateInfo(randomStr());
|
||||||
webUpdate.setUpdateTime(new Date());
|
webUpdate.setUpdateTime(new Date());
|
||||||
mapper.insert(webUpdate);
|
mapper.insert(webUpdate);
|
||||||
List<WebUpdate> all = mapper.findAll();
|
List<WebUpdate> all = mapper.findAll();
|
||||||
WebUpdate update = all.get(all.size() - 1);
|
WebUpdate update = all.get(all.size() - 1);
|
||||||
assertNotEquals(0, update.getId());
|
assertNotEquals(0, update.getId());
|
||||||
assertNotNull(update.getUpdateInfo());
|
assertNotNull(update.getUpdateInfo());
|
||||||
String info = UUID.randomUUID().toString();
|
String info = randomStr();
|
||||||
mockMvc.perform(put("/admin/webUpdate/update?id=" + update.getId() + "&info=" + info).header("Authorization", adminLogin())).andDo(result -> {
|
getMockData(put("/admin/webUpdate/update?id=" + update.getId() + "&info=" + info), adminLogin()).andDo(result -> {
|
||||||
List<WebUpdate> list = mapper.findAll();
|
List<WebUpdate> list = mapper.findAll();
|
||||||
WebUpdate up = list.get(list.size() - 1);
|
WebUpdate up = list.get(list.size() - 1);
|
||||||
assertEquals(update.getId(), up.getId());
|
assertEquals(update.getId(), up.getId());
|
||||||
@@ -85,12 +95,12 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findAll() throws Exception {
|
public void findAll() throws Exception {
|
||||||
mockMvc.perform(get("/webUpdate")).andDo(result -> {
|
getMockData(get("/webUpdate")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<List<WebUpdateModel>> response = getResponse(result, MODAL_LIST_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONArray jsonArray = object.getJSONArray(Result);
|
assertNotNull(response.getResult());
|
||||||
jsonArray.forEach(o -> {
|
assertNotEquals(0, response.getResult());
|
||||||
WebUpdateModel webUpdate = (WebUpdateModel) JSONObject.toBean(JSONObject.fromObject(o), WebUpdateModel.class);
|
response.getResult().forEach(webUpdate -> {
|
||||||
assertNotEquals(0, webUpdate.getId());
|
assertNotEquals(0, webUpdate.getId());
|
||||||
assertNotNull(webUpdate.getTime());
|
assertNotNull(webUpdate.getTime());
|
||||||
assertNotNull(webUpdate.getInfo());
|
assertNotNull(webUpdate.getInfo());
|
||||||
@@ -100,15 +110,14 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void page() throws Exception {
|
public void page() throws Exception {
|
||||||
mockMvc.perform(get("/webUpdate/pages?page=1&count=10")).andDo(result -> {
|
getMockData(get("/webUpdate/pages?page=1&count=10")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<PageData<WebUpdateModel>> response = getResponse(result, MODAL_PAGE_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(object.getJSONObject(Result));
|
assertNotNull(response.getResult());
|
||||||
PageData<WebUpdateModel> pageData = (PageData<WebUpdateModel>) JSONObject.toBean(object.getJSONObject(Result), PageData.class);
|
PageData<WebUpdateModel> pageData = response.getResult();
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertEquals(10, pageData.getPageSize());
|
assertEquals(10, pageData.getPageSize());
|
||||||
for (Object o : pageData.getList()) {
|
for (WebUpdateModel model : pageData.getList()) {
|
||||||
WebUpdateModel model = (WebUpdateModel) JSONObject.toBean(JSONObject.fromObject(o), WebUpdateModel.class);
|
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertNotNull(model.getTime());
|
assertNotNull(model.getTime());
|
||||||
assertNotNull(model.getInfo());
|
assertNotNull(model.getInfo());
|
||||||
@@ -118,7 +127,6 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lastestUpdateTime() throws Exception {
|
public void lastestUpdateTime() throws Exception {
|
||||||
mockMvc.perform(get("/lastestUpdate")).andDo(result ->
|
getMockData(get("/lastestUpdate")).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package cn.celess.blog.enmu;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class UserAccountStatusEnumTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void get() {
|
||||||
|
assertEquals(UserAccountStatusEnum.NORMAL, UserAccountStatusEnum.get(0));
|
||||||
|
assertEquals(UserAccountStatusEnum.LOCKED, UserAccountStatusEnum.get(1));
|
||||||
|
assertEquals(UserAccountStatusEnum.DELETED, UserAccountStatusEnum.get(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toJson() throws JsonProcessingException {
|
||||||
|
// 序列化
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
assertEquals("{\"code\":0,\"desc\":\"正常\"}", objectMapper.writeValueAsString(UserAccountStatusEnum.NORMAL));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGet() throws IOException {
|
||||||
|
// 反序列化
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
UserAccountStatusEnum userAccountStatusEnum = mapper.readValue(mapper.writeValueAsString(UserAccountStatusEnum.NORMAL), UserAccountStatusEnum.class);
|
||||||
|
assertEquals(UserAccountStatusEnum.NORMAL.getCode(), userAccountStatusEnum.getCode());
|
||||||
|
assertEquals(UserAccountStatusEnum.NORMAL.getDesc(), userAccountStatusEnum.getDesc());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package cn.celess.blog.filter;
|
package cn.celess.blog.filter;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import net.sf.json.JSONObject;
|
import cn.celess.blog.entity.Response;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 小海
|
* @Author: 小海
|
||||||
@@ -17,60 +17,37 @@ public class AuthorizationFilter extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void UserAccess() throws Exception {
|
public void UserAccess() throws Exception {
|
||||||
String token = "";
|
|
||||||
// 未登录
|
// 未登录
|
||||||
mockMvc.perform(get("/user/userInfo").header("Authorization", token)).andDo(result -> {
|
getMockData(get("/user/userInfo")).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result).getCode()));
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
// user权限登录
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
getMockData(get("/user/userInfo"), userLogin()).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
});
|
|
||||||
token = userLogin();
|
|
||||||
mockMvc.perform(get("/user/userInfo").header("Authorization", token)).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void AdminAccess() throws Exception {
|
public void AdminAccess() throws Exception {
|
||||||
String token = "";
|
|
||||||
// 未登录
|
// 未登录
|
||||||
mockMvc.perform(get("/admin/articles?page=1&count=1").header("Authorization", token)).andDo(result -> {
|
getMockData(get("/admin/articles?page=1&count=1")).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result).getCode()));
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
// user权限
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
getMockData(get("/admin/articles?page=1&count=1"), userLogin()).andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), getResponse(result).getCode()));
|
||||||
});
|
// admin 权限
|
||||||
token = userLogin();
|
getMockData(get("/admin/articles?page=1&count=1"), adminLogin()).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
mockMvc.perform(get("/admin/articles?page=1&count=1").header("Authorization", token)).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(get("/admin/articles?page=1&count=1").header("Authorization", token)).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void VisitorAccess() throws Exception {
|
public void VisitorAccess() throws Exception {
|
||||||
mockMvc.perform(get("/user/userInfo")).andDo(result -> {
|
getMockData(get("/user/userInfo")).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result).getCode()));
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
getMockData(get("/admin/articles?page=1&count=1")).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result).getCode()));
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
mockMvc.perform(get("/admin/articles?page=1&count=1")).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void authorizationTest() throws Exception {
|
public void authorizationTest() throws Exception {
|
||||||
// 测试response中有无Authorization字段
|
// 测试response中有无Authorization字段
|
||||||
String s = userLogin();
|
String token = userLogin();
|
||||||
mockMvc.perform(get("/user/userInfo").header("Authorization", s)).andDo(result -> {
|
getMockData(get("/user/userInfo"), token).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<Object> response = getResponse(result);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(result.getResponse().getHeader("Authorization"));
|
assertNotNull(result.getResponse().getHeader("Authorization"));
|
||||||
assertNotEquals(s, result.getResponse().getHeader("Authorization"));
|
assertNotEquals(token, result.getResponse().getHeader("Authorization"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,11 @@ package cn.celess.blog.filter;
|
|||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import net.sf.json.JSONObject;
|
import cn.celess.blog.entity.Response;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
|
||||||
import org.springframework.mock.web.MockHttpSession;
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
|
||||||
|
|
||||||
import javax.servlet.http.Cookie;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 小海
|
* @Author: 小海
|
||||||
@@ -31,11 +26,11 @@ public class MultipleSubmitFilter extends BaseTest {
|
|||||||
|
|
||||||
|
|
||||||
private void sendRequest(ResponseEnum expectResponse, String... msg) throws Exception {
|
private void sendRequest(ResponseEnum expectResponse, String... msg) throws Exception {
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/counts").session(session)).andDo(result -> {
|
getMockData(MockMvcRequestBuilders.get("/counts").session(session)).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<Object> response = getResponse(result);
|
||||||
Assert.assertEquals(expectResponse.getCode(), object.getInt(Code));
|
Assert.assertEquals(expectResponse.getCode(), response.getCode());
|
||||||
if (msg.length != 0) {
|
if (msg.length != 0) {
|
||||||
Assert.assertEquals(msg[0], object.getString("msg"));
|
Assert.assertEquals(msg[0], response.getMsg());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.junit.Test;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@@ -37,7 +36,7 @@ public class ArticleMapperTest extends BaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void update() {
|
public void update() {
|
||||||
Article article = generateArticle().getArticle();
|
Article article = generateArticle().getArticle();
|
||||||
String randomText = UUID.randomUUID().toString();
|
String randomText = randomStr();
|
||||||
|
|
||||||
// 此字段不会通过insert被写入数据库而是使用插入数据的默认值 数据库中该字段默认为true
|
// 此字段不会通过insert被写入数据库而是使用插入数据的默认值 数据库中该字段默认为true
|
||||||
article.setOpen(true);
|
article.setOpen(true);
|
||||||
@@ -117,7 +116,7 @@ public class ArticleMapperTest extends BaseTest {
|
|||||||
public void existsByTitle() {
|
public void existsByTitle() {
|
||||||
Article article = generateArticle().getArticle();
|
Article article = generateArticle().getArticle();
|
||||||
assertTrue(articleMapper.existsByTitle(article.getTitle()));
|
assertTrue(articleMapper.existsByTitle(article.getTitle()));
|
||||||
assertFalse(articleMapper.existsByTitle(UUID.randomUUID().toString()));
|
assertFalse(articleMapper.existsByTitle(randomStr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -196,7 +195,7 @@ public class ArticleMapperTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ArticleTag generateArticle() {
|
private ArticleTag generateArticle() {
|
||||||
String randomText = UUID.randomUUID().toString();
|
String randomText = randomStr();
|
||||||
|
|
||||||
Article article = new Article();
|
Article article = new Article();
|
||||||
Category category = new Category();
|
Category category = new Category();
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import cn.celess.blog.entity.*;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@@ -111,7 +109,7 @@ public class ArticleTagMapperTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ArticleTag generateArticle() {
|
private ArticleTag generateArticle() {
|
||||||
String randomText = UUID.randomUUID().toString();
|
String randomText = randomStr();
|
||||||
|
|
||||||
Article article = new Article();
|
Article article = new Article();
|
||||||
Category category = new Category();
|
Category category = new Category();
|
||||||
@@ -136,4 +134,13 @@ public class ArticleTagMapperTest extends BaseTest {
|
|||||||
|
|
||||||
return articleTag;
|
return articleTag;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
public void findTagByArticleId() {
|
||||||
|
Article article = articleMapper.findAll().get(0);
|
||||||
|
assertNotNull(article);
|
||||||
|
|
||||||
|
List<Tag> tagByArticleId = articleTagMapper.findTagByArticleId(article.getId());
|
||||||
|
assertNotEquals(0, tagByArticleId.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import cn.celess.blog.entity.Category;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class PartnerMapperTest extends BaseTest {
|
|||||||
partnerSite.setIconPath(randomStr(5));
|
partnerSite.setIconPath(randomStr(5));
|
||||||
partnerSite.setDesc(randomStr(5));
|
partnerSite.setDesc(randomStr(5));
|
||||||
partnerSite.setOpen(false);
|
partnerSite.setOpen(false);
|
||||||
partnerSite.setUrl("www.celess.cn?random=" + randomStr(4));
|
partnerSite.setUrl("www.celess.cn/?random=" + randomStr(4));
|
||||||
assertEquals(1, partnerMapper.update(partnerSite));
|
assertEquals(1, partnerMapper.update(partnerSite));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
public class VisitorMapperTest extends BaseTest {
|
public class VisitorMapperTest extends BaseTest {
|
||||||
|
|
||||||
|
|||||||
52
src/test/java/cn/celess/blog/service/ArticleServiceTest.java
Normal file
52
src/test/java/cn/celess/blog/service/ArticleServiceTest.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.model.ArticleModel;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import cn.celess.blog.mapper.ArticleMapper;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class ArticleServiceTest extends BaseTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ArticleService articleService;
|
||||||
|
@Autowired
|
||||||
|
ArticleMapper articleMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void adminArticles() {
|
||||||
|
// 测deleted参数传值
|
||||||
|
PageData<ArticleModel> pageData = articleService.adminArticles(10, 1, true);
|
||||||
|
assertTrue(pageData.getList().stream().allMatch(ArticleModel::isDeleted));
|
||||||
|
pageData = articleService.adminArticles(10, 1, false);
|
||||||
|
assertFalse(pageData.getList().stream().allMatch(ArticleModel::isDeleted));
|
||||||
|
pageData = articleService.adminArticles(10, 1, null);
|
||||||
|
assertTrue(pageData.getList().stream().anyMatch(ArticleModel::isDeleted));
|
||||||
|
assertTrue(pageData.getList().stream().anyMatch(articleModel -> !articleModel.isDeleted()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void retrievePageForOpen() {
|
||||||
|
PageData<ArticleModel> articleModelPageData = articleService.retrievePageForOpen(10, 1);
|
||||||
|
assertEquals(10, articleModelPageData.getPageSize());
|
||||||
|
assertEquals(1, articleModelPageData.getPageNum());
|
||||||
|
assertEquals(10, articleModelPageData.getList().size());
|
||||||
|
articleModelPageData.getList().forEach(Assert::assertNotNull);
|
||||||
|
|
||||||
|
// 测试open字段
|
||||||
|
articleModelPageData.getList().forEach(articleModel -> {
|
||||||
|
// 当前文章
|
||||||
|
assertTrue(articleMapper.findArticleById(articleModel.getId()).getOpen());
|
||||||
|
if (articleModel.getPreArticle() != null) {
|
||||||
|
assertTrue(articleMapper.findArticleById(articleModel.getPreArticle().getId()).getOpen());
|
||||||
|
}
|
||||||
|
if (articleModel.getNextArticle() != null) {
|
||||||
|
assertTrue(articleMapper.findArticleById(articleModel.getNextArticle().getId()).getOpen());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class PartnerSiteServiceTest extends BaseTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
PartnerSiteService partnerSiteService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void partnerSitePages() {
|
||||||
|
// 测试deleted 参数
|
||||||
|
PageData<PartnerSite> pageData = partnerSiteService.partnerSitePages(1, 10, true);
|
||||||
|
assertTrue(pageData.getList().stream().allMatch(PartnerSite::getDelete));
|
||||||
|
pageData = partnerSiteService.partnerSitePages(1, 10, false);
|
||||||
|
assertTrue(pageData.getList().stream().noneMatch(PartnerSite::getDelete));
|
||||||
|
pageData = partnerSiteService.partnerSitePages(1, 10, null);
|
||||||
|
|
||||||
|
List<PartnerSite> list = pageData.getList();
|
||||||
|
assertNotEquals(0, list.stream().filter(PartnerSite::getDelete).count());
|
||||||
|
assertNotEquals(0, list.stream().filter(partnerSite -> !partnerSite.getDelete()).count());
|
||||||
|
}
|
||||||
|
}
|
||||||
73
src/test/java/cn/celess/blog/service/UserServiceTest.java
Normal file
73
src/test/java/cn/celess/blog/service/UserServiceTest.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
|
import cn.celess.blog.enmu.UserAccountStatusEnum;
|
||||||
|
import cn.celess.blog.entity.User;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import cn.celess.blog.entity.model.UserModel;
|
||||||
|
import cn.celess.blog.entity.request.LoginReq;
|
||||||
|
import cn.celess.blog.exception.MyException;
|
||||||
|
import cn.celess.blog.mapper.UserMapper;
|
||||||
|
import cn.celess.blog.util.MD5Util;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class UserServiceTest extends BaseTest {
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
@Autowired
|
||||||
|
UserMapper userMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getUserList() {
|
||||||
|
// 测试status 参数
|
||||||
|
PageData<UserModel> userList = userService.getUserList(1, 10, UserAccountStatusEnum.NORMAL.getCode());
|
||||||
|
assertTrue(userList.getList().stream().allMatch(userModel -> userModel.getStatus().getCode() == UserAccountStatusEnum.NORMAL.getCode()));
|
||||||
|
userList = userService.getUserList(1, 10, UserAccountStatusEnum.LOCKED.getCode());
|
||||||
|
assertTrue(userList.getList().stream().allMatch(userModel -> userModel.getStatus().getCode() == UserAccountStatusEnum.LOCKED.getCode()));
|
||||||
|
userList = userService.getUserList(1, 10, UserAccountStatusEnum.DELETED.getCode());
|
||||||
|
assertTrue(userList.getList().stream().allMatch(userModel -> userModel.getStatus().getCode() == UserAccountStatusEnum.DELETED.getCode()));
|
||||||
|
userList = userService.getUserList(1, 10, null);
|
||||||
|
assertTrue(userList.getList().stream().anyMatch(userModel -> userModel.getStatus().getCode() == UserAccountStatusEnum.NORMAL.getCode()));
|
||||||
|
assertTrue(userList.getList().stream().anyMatch(userModel -> userModel.getStatus().getCode() == UserAccountStatusEnum.LOCKED.getCode()));
|
||||||
|
assertTrue(userList.getList().stream().anyMatch(userModel -> userModel.getStatus().getCode() == UserAccountStatusEnum.DELETED.getCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLogin() {
|
||||||
|
// 测试账户 被锁 被删除 登录
|
||||||
|
String email = randomStr(5) + "@celess.cn";
|
||||||
|
String pwd = MD5Util.getMD5("123456789");
|
||||||
|
User user = new User(email, pwd);
|
||||||
|
userMapper.addUser(user);
|
||||||
|
assertNotNull(user.getId());
|
||||||
|
|
||||||
|
user = userMapper.findByEmail(email);
|
||||||
|
LoginReq loginReq = new LoginReq(email, "123456789", false);
|
||||||
|
UserModel login = userService.login(loginReq);
|
||||||
|
assertEquals(UserAccountStatusEnum.NORMAL, login.getStatus());
|
||||||
|
|
||||||
|
userMapper.lock(user.getId());
|
||||||
|
try {
|
||||||
|
userService.login(loginReq);
|
||||||
|
fail("测试登录被锁账户 失败!");
|
||||||
|
} catch (MyException e) {
|
||||||
|
assertEquals(ResponseEnum.CAN_NOT_USE.getCode(), e.getCode());
|
||||||
|
assertEquals(UserAccountStatusEnum.LOCKED, e.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
userMapper.delete(user.getId());
|
||||||
|
try {
|
||||||
|
userService.login(loginReq);
|
||||||
|
fail("测试登录被删除账户 失败!");
|
||||||
|
} catch (MyException e) {
|
||||||
|
assertEquals(ResponseEnum.CAN_NOT_USE.getCode(), e.getCode());
|
||||||
|
assertEquals(UserAccountStatusEnum.DELETED, e.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/test/java/cn/celess/blog/service/VisitorServiceTest.java
Normal file
29
src/test/java/cn/celess/blog/service/VisitorServiceTest.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import cn.celess.blog.entity.model.VisitorModel;
|
||||||
|
import com.alibaba.druid.util.StringUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class VisitorServiceTest extends BaseTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
VisitorService visitorService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void location() {
|
||||||
|
assertEquals("0|0|0|内网IP|内网IP", visitorService.location("127.0.0.1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void visitorPage() {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
PageData<VisitorModel> visitorModelPageData = visitorService.visitorPage(1, 10, true);
|
||||||
|
assertTrue(System.currentTimeMillis() - start <= 1500);
|
||||||
|
assertTrue(visitorModelPageData.getList().stream().noneMatch(visitor -> StringUtils.isEmpty(visitor.getLocation())));
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/test/java/cn/celess/blog/util/AddressUtilTest.java
Normal file
15
src/test/java/cn/celess/blog/util/AddressUtilTest.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class AddressUtilTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getCityInfo() {
|
||||||
|
assertEquals("0|0|0|内网IP|内网IP", AddressUtil.getCityInfo("127.0.0.1"));
|
||||||
|
assertEquals("中国|0|上海|上海市|阿里云", AddressUtil.getCityInfo("106.15.205.190"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
public class DateFormatUtilTest extends BaseTest {
|
public class DateFormatUtilTest extends BaseTest {
|
||||||
|
|
||||||
|
|||||||
18
src/test/java/cn/celess/blog/util/HttpUtilTest.java
Normal file
18
src/test/java/cn/celess/blog/util/HttpUtilTest.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
public class HttpUtilTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void get() {
|
||||||
|
String s = HttpUtil.get("https://api.celess.cn/headerInfo");
|
||||||
|
assertNotNull(s);
|
||||||
|
// Response<Map<String, Object>> response = getResponse(s, MAP_OBJECT_TYPE);
|
||||||
|
// assertEquals(ResponseEnum.SUCCESS.getCode(), response.getCode());
|
||||||
|
// assertNotEquals(0, response.getResult().size());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package cn.celess.blog.util;
|
|||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class MD5UtilTest extends BaseTest {
|
public class MD5UtilTest extends BaseTest {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user