Skip to content

Commit b8389fe

Browse files
committed
更新SpringBoot1.5.3 并修改测试用例
1 parent cf3d8bf commit b8389fe

16 files changed

Lines changed: 214 additions & 132 deletions

File tree

baas.iml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="Spring" name="Spring">
5+
<configuration />
6+
</facet>
7+
</component>
8+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
9+
<output url="file://$MODULE_DIR$/target/classes" />
10+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
11+
<content url="file://$MODULE_DIR$">
12+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
13+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
14+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
15+
<excludeFolder url="file://$MODULE_DIR$/target" />
16+
</content>
17+
<orderEntry type="inheritedJdk" />
18+
<orderEntry type="sourceFolder" forTests="false" />
19+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-mongodb:1.5.3.RELEASE" level="project" />
20+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:1.5.3.RELEASE" level="project" />
21+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:1.5.3.RELEASE" level="project" />
22+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:1.5.3.RELEASE" level="project" />
23+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:1.5.3.RELEASE" level="project" />
24+
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.11" level="project" />
25+
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.11" level="project" />
26+
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
27+
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.25" level="project" />
28+
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
29+
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver:3.4.2" level="project" />
30+
<orderEntry type="library" name="Maven: org.mongodb:bson:3.4.2" level="project" />
31+
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:3.4.2" level="project" />
32+
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-mongodb:1.10.3.RELEASE" level="project" />
33+
<orderEntry type="library" name="Maven: org.springframework:spring-tx:4.3.8.RELEASE" level="project" />
34+
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.8.RELEASE" level="project" />
35+
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.3.8.RELEASE" level="project" />
36+
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.8.RELEASE" level="project" />
37+
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:1.13.3.RELEASE" level="project" />
38+
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" />
39+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:1.5.3.RELEASE" level="project" />
40+
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:1.8.3.RELEASE" level="project" />
41+
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:1.2.3.RELEASE" level="project" />
42+
<orderEntry type="library" name="Maven: org.springframework:spring-oxm:4.3.8.RELEASE" level="project" />
43+
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.3.8.RELEASE" level="project" />
44+
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:4.3.8.RELEASE" level="project" />
45+
<orderEntry type="library" name="Maven: redis.clients:jedis:2.9.0" level="project" />
46+
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.4.2" level="project" />
47+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE" level="project" />
48+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:1.5.3.RELEASE" level="project" />
49+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.5.14" level="project" />
50+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:8.5.14" level="project" />
51+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.5.14" level="project" />
52+
<orderEntry type="library" name="Maven: org.hibernate:hibernate-validator:5.3.5.Final" level="project" />
53+
<orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" />
54+
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.1.Final" level="project" />
55+
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.3" level="project" />
56+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.8" level="project" />
57+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
58+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.8" level="project" />
59+
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.3.8.RELEASE" level="project" />
60+
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.8.RELEASE" level="project" />
61+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-configuration-processor:1.5.3.RELEASE" level="project" />
62+
<orderEntry type="library" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
63+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:1.5.3.RELEASE" level="project" />
64+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:1.5.3.RELEASE" level="project" />
65+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:1.5.3.RELEASE" level="project" />
66+
<orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.2.0" level="project" />
67+
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.2.1" level="project" />
68+
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:1.1" level="project" />
69+
<orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:5.0.3" level="project" />
70+
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
71+
<orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:2.6.0" level="project" />
72+
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:1.10.19" level="project" />
73+
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.1" level="project" />
74+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
75+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
76+
<orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.4.0" level="project" />
77+
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.8.RELEASE" level="project" />
78+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:4.3.8.RELEASE" level="project" />
79+
<orderEntry type="library" name="Maven: com.qiniu:qiniu-java-sdk:7.0.4.2" level="project" />
80+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
81+
<orderEntry type="library" name="Maven: com.squareup.okhttp:okhttp:2.3.0" level="project" />
82+
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.3.0" level="project" />
83+
<orderEntry type="library" name="Maven: cn.jpush.api:jpush-client:3.1.3" level="project" />
84+
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
85+
<orderEntry type="library" name="Maven: com.google.guava:guava:17.0" level="project" />
86+
</component>
87+
</module>

pom.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>1.4.0.RELEASE</version>
17+
<version>1.5.3.RELEASE</version>
1818
</parent>
1919

2020
<properties>
@@ -25,17 +25,13 @@
2525
</properties>
2626

2727
<dependencies>
28-
<dependency>
29-
<groupId>org.springframework.boot</groupId>
30-
<artifactId>spring-boot-starter-actuator</artifactId>
31-
</dependency>
3228
<dependency>
3329
<groupId>org.springframework.boot</groupId>
3430
<artifactId>spring-boot-starter-data-mongodb</artifactId>
3531
</dependency>
3632
<dependency>
3733
<groupId>org.springframework.boot</groupId>
38-
<artifactId>spring-boot-starter-redis</artifactId>
34+
<artifactId>spring-boot-starter-data-redis</artifactId>
3935
</dependency>
4036
<dependency>
4137
<groupId>org.springframework.boot</groupId>

src/main/java/com/javabaas/server/object/service/ObjectService.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package com.javabaas.server.object.service;
22

33
import com.javabaas.server.admin.entity.*;
4-
import com.javabaas.server.common.entity.SimpleError;
5-
import com.javabaas.server.object.dao.impl.mongo.MongoDao;
6-
import com.javabaas.server.object.entity.*;
7-
import com.javabaas.server.object.entity.error.FieldRequiredError;
8-
import com.javabaas.server.object.entity.error.FieldTypeError;
9-
import com.javabaas.server.user.entity.BaasUser;
104
import com.javabaas.server.admin.service.ClazzService;
115
import com.javabaas.server.admin.service.FieldService;
126
import com.javabaas.server.admin.service.StatService;
137
import com.javabaas.server.common.entity.SimpleCode;
8+
import com.javabaas.server.common.entity.SimpleError;
149
import com.javabaas.server.common.util.JSONUtil;
1510
import com.javabaas.server.file.entity.BaasFile;
1611
import com.javabaas.server.file.service.FileService;
1712
import com.javabaas.server.hook.service.HookService;
1813
import com.javabaas.server.object.dao.IDao;
14+
import com.javabaas.server.object.dao.impl.mongo.MongoDao;
15+
import com.javabaas.server.object.entity.*;
16+
import com.javabaas.server.object.entity.error.FieldRequiredError;
17+
import com.javabaas.server.object.entity.error.FieldTypeError;
18+
import com.javabaas.server.user.entity.BaasUser;
1919
import org.springframework.beans.factory.annotation.Autowired;
2020
import org.springframework.stereotype.Service;
2121
import org.springframework.util.StringUtils;
@@ -158,7 +158,8 @@ public void update(String appId, String plat, String className, String id, BaasO
158158
hookService.afterUpdate(appId, className, object, currentUser);
159159
}
160160

161-
public void increment(String appId, String plat, String className, String id, BaasObject object, BaasUser currentUser, boolean isMaster) {
161+
public void increment(String appId, String plat, String className, String id, BaasObject object, BaasUser currentUser, boolean
162+
isMaster) {
162163
//查询已经存在的对象
163164
BaasObject exist = getObject(appId, className, id, isMaster);
164165
if (exist == null) {
@@ -205,7 +206,8 @@ public BaasObject get(String appId, String plat, String className, String id) {
205206
return get(appId, plat, className, id, null, null, true);
206207
}
207208

208-
public BaasObject get(String appId, String plat, String className, String id, BaasInclude include, BaasUser currentUser, boolean isMaster) {
209+
public BaasObject get(String appId, String plat, String className, String id, BaasInclude include, BaasUser currentUser, boolean
210+
isMaster) {
209211
//判断id是否合法
210212
if (!isValidId(id)) {
211213
throw new SimpleError(SimpleCode.OBJECT_ID_ERROR);
@@ -225,6 +227,8 @@ public List<BaasObject> list(String appId, String plat, String className, BaasQu
225227
int limit, int skip, BaasUser currentUser, boolean isMaster) {
226228
//上限不得超过1000
227229
limit = limit > 1000 ? 1000 : limit;
230+
//limit必须为正数
231+
if (limit <= 0) limit = 100;
228232
//验证表级ACL
229233
verifyClazzAccess(appId, ClazzAclMethod.FIND, className, currentUser, isMaster);
230234
//查询条件
@@ -239,7 +243,7 @@ public List<BaasObject> list(String appId, String plat, String className, BaasQu
239243
if (resultMap == null) {
240244
return result;
241245
}
242-
resultMap.values().forEach(result::add);
246+
result.addAll(resultMap.values());
243247
//处理包含数据
244248
if (result.size() > 0 && include != null && include.getSubs().size() > 0) {
245249
//获取包含数据
@@ -256,7 +260,8 @@ private void handleSubQuery(String appId, BaasUser user, boolean isMaster, BaasQ
256260
}
257261
}
258262

259-
private boolean handleSub(String appId, BaasUser user, boolean isMaster, String field, Map<String, Object> parent, Map<String, Object> query) {
263+
private boolean handleSub(String appId, BaasUser user, boolean isMaster, String field, Map<String, Object> parent, Map<String,
264+
Object> query) {
260265
boolean flag = false;
261266
boolean sub = false;
262267
Set<Map.Entry<String, Object>> entries = query.entrySet();
@@ -293,7 +298,8 @@ private void replaceSub(String appId, BaasUser user, boolean isMaster, Map paren
293298
if (StringUtils.isEmpty(searchClass) || !(searchClass instanceof String)) {
294299
throw new SimpleError(SimpleCode.OBJECT_SUB_QUERY_EMPTY_SEARCH_CLASS);
295300
}
296-
Map<String, BaasObject> subs = getObjects(appId, (String) searchClass, new BaasQuery((Map) where), null, 1000, null, user, isMaster);
301+
Map<String, BaasObject> subs = getObjects(appId, (String) searchClass, new BaasQuery((Map) where), null, 1000, null, user,
302+
isMaster);
297303
if (subs != null) {
298304
//用查询结果$in替换$sub
299305
BaasList list = new BaasList();
@@ -358,7 +364,8 @@ private void handleInclude(String appId, List<BaasObject> objects, BaasInclude i
358364
//查询对应的对象列表
359365
List<String> objectIds = ids.getIds(className);
360366
//被关联的对象
361-
Map<String, BaasObject> subObjects = getObjects(appId, className, new BaasQuery("_id", new BaasObject("$in", objectIds)), user, isMaster);
367+
Map<String, BaasObject> subObjects = getObjects(appId, className, new BaasQuery("_id", new BaasObject("$in", objectIds)),
368+
user, isMaster);
362369
if (subObjects != null && subObjects.size() > 0) {
363370
//添加到对应对象
364371
for (BaasObject o : objects) {
@@ -401,7 +408,8 @@ private Map<String, BaasObject> getObjects(String appId, String className, BaasQ
401408
return getObjects(appId, className, query, null, null, null, user, isMaster);
402409
}
403410

404-
private Map<String, BaasObject> getObjects(String appId, String className, BaasQuery query, BaasSort sort, Integer limit, Integer skip, BaasUser user, boolean isMaster) {
411+
private Map<String, BaasObject> getObjects(String appId, String className, BaasQuery query, BaasSort sort, Integer limit, Integer
412+
skip, BaasUser user, boolean isMaster) {
405413
//排序条件
406414
if (sort == null) {
407415
//默认排序为更新时间倒序

src/test/java/com/javabaas/server/AclTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
import com.javabaas.server.admin.entity.*;
44
import com.javabaas.server.admin.service.AppService;
5-
import com.javabaas.server.common.entity.SimpleError;
6-
import com.javabaas.server.object.entity.BaasAcl;
7-
import com.javabaas.server.user.entity.BaasUser;
8-
import com.javabaas.server.user.service.UserService;
95
import com.javabaas.server.admin.service.ClazzService;
106
import com.javabaas.server.admin.service.FieldService;
117
import com.javabaas.server.common.entity.SimpleCode;
8+
import com.javabaas.server.common.entity.SimpleError;
9+
import com.javabaas.server.object.entity.BaasAcl;
1210
import com.javabaas.server.object.entity.BaasObject;
1311
import com.javabaas.server.object.service.ObjectService;
12+
import com.javabaas.server.user.entity.BaasUser;
13+
import com.javabaas.server.user.service.UserService;
1414
import org.junit.After;
1515
import org.junit.Assert;
1616
import org.junit.Before;
1717
import org.junit.Test;
1818
import org.junit.runner.RunWith;
1919
import org.springframework.beans.factory.annotation.Autowired;
20-
import org.springframework.boot.test.SpringApplicationConfiguration;
21-
import org.springframework.boot.test.WebIntegrationTest;
20+
import org.springframework.boot.test.context.SpringBootTest;
2221
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
22+
import org.springframework.test.context.junit4.SpringRunner;
2323

2424
import java.util.List;
2525

@@ -29,8 +29,7 @@
2929
* Created by Staryet on 15/8/11.
3030
*/
3131
@RunWith(SpringJUnit4ClassRunner.class)
32-
@SpringApplicationConfiguration(classes = Main.class)
33-
@WebIntegrationTest("server.port:9000")
32+
@SpringBootTest(classes = Main.class,webEnvironment = SpringBootTest.WebEnvironment.MOCK)
3433
public class AclTests {
3534

3635
@Autowired

src/test/java/com/javabaas/server/AppTests.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
package com.javabaas.server;
22

3-
import com.javabaas.server.admin.entity.dto.FieldExport;
4-
import com.javabaas.server.common.entity.SimpleError;
5-
import com.javabaas.server.user.service.UserService;
63
import com.javabaas.server.admin.entity.App;
74
import com.javabaas.server.admin.entity.Clazz;
85
import com.javabaas.server.admin.entity.Field;
96
import com.javabaas.server.admin.entity.FieldType;
107
import com.javabaas.server.admin.entity.dto.AppExport;
118
import com.javabaas.server.admin.entity.dto.ClazzExport;
9+
import com.javabaas.server.admin.entity.dto.FieldExport;
1210
import com.javabaas.server.admin.repository.ClazzRepository;
1311
import com.javabaas.server.admin.service.AppService;
1412
import com.javabaas.server.admin.service.ClazzService;
1513
import com.javabaas.server.admin.service.FieldService;
1614
import com.javabaas.server.common.entity.SimpleCode;
15+
import com.javabaas.server.common.entity.SimpleError;
1716
import com.javabaas.server.object.service.ObjectService;
17+
import com.javabaas.server.user.service.UserService;
1818
import org.junit.After;
1919
import org.junit.Assert;
2020
import org.junit.Before;
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
2323
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.boot.test.SpringApplicationConfiguration;
25-
import org.springframework.boot.test.WebIntegrationTest;
26-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
24+
import org.springframework.boot.test.context.SpringBootTest;
25+
import org.springframework.test.context.junit4.SpringRunner;
2726

2827
import java.util.List;
2928

@@ -33,9 +32,8 @@
3332
/**
3433
* Created by Staryet on 15/8/11.
3534
*/
36-
@RunWith(SpringJUnit4ClassRunner.class)
37-
@SpringApplicationConfiguration(classes = Main.class)
38-
@WebIntegrationTest("server.port:9000")
35+
@RunWith(SpringRunner.class)
36+
@SpringBootTest(classes = Main.class,webEnvironment = SpringBootTest.WebEnvironment.MOCK)
3937
public class AppTests {
4038

4139
@Autowired

0 commit comments

Comments
 (0)