Skip to content

Commit 17845e6

Browse files
committed
test case
1 parent e354b34 commit 17845e6

File tree

11 files changed

+165
-5
lines changed

11 files changed

+165
-5
lines changed

spring-boot-data-aggregate-autoconfigure/src/main/java/org/feego/spring/annotation/DataBeanConsumer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import java.lang.annotation.*;
44

55
/**
6+
* 数据依赖项
7+
*
68
79
* @since 2019/6/1 0:05
810
*/
9-
@Target({ElementType.METHOD})
11+
@Target({ElementType.PARAMETER})
1012
@Retention(RetentionPolicy.RUNTIME)
1113
@Documented
1214
public @interface DataBeanConsumer {
13-
15+
String id();
16+
String namespace();
1417
}

spring-boot-data-aggregate-autoconfigure/src/main/java/org/feego/spring/annotation/DataBeanProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
import java.lang.annotation.*;
44

55
/**
6+
* 数据提供者
7+
*
68
79
* @since 2019/6/1 0:05
810
*/
911
@Target({ElementType.METHOD})
1012
@Retention(RetentionPolicy.RUNTIME)
1113
@Documented
1214
public @interface DataBeanProvider {
13-
15+
String id();
16+
String namespace();
17+
long timeout() default 1000;
1418
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.feego.spring.annotation;
2+
3+
/**
4+
* 数据聚合时需要的输入参数
5+
*
6+
7+
* @since 2019/6/2 16:32
8+
*/
9+
public @interface InvokeParameter {
10+
String value();
11+
}

spring-boot-data-aggregate-example/src/main/java/org/feego/spring/example/ExampleApplication.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.feego.spring.example;
22

33
import org.feego.spring.aggregate.facade.DataBeanAggregateQueryFacade;
4+
import org.feego.spring.example.model.User;
45
import org.springframework.boot.SpringApplication;
56
import org.springframework.boot.autoconfigure.SpringBootApplication;
67
import org.springframework.context.ConfigurableApplicationContext;
8+
import org.springframework.util.Assert;
79

810
/**
911
@@ -15,7 +17,8 @@ public class ExampleApplication {
1517
public static void main(String[] args) {
1618
ConfigurableApplicationContext context = SpringApplication.run(ExampleApplication.class);
1719
DataBeanAggregateQueryFacade queryFacade = context.getBean(DataBeanAggregateQueryFacade.class);
18-
String loginUserName = queryFacade.get("login.user", String.class);
19-
System.out.println(loginUserName);
20+
User user = queryFacade.get("login.user", User.class);
21+
Assert.notNull(user,"user not null");
22+
Assert.notNull(user.getPosts(),"user posts not null");
2023
}
2124
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.feego.spring.example.aggregate;
2+
3+
import org.feego.spring.annotation.DataBeanConsumer;
4+
import org.feego.spring.annotation.DataBeanProvider;
5+
import org.feego.spring.example.model.Post;
6+
import org.feego.spring.example.model.User;
7+
import org.feego.spring.example.service.UserService;
8+
import org.springframework.stereotype.Component;
9+
10+
import java.util.List;
11+
12+
/**
13+
14+
* @since 2019/6/2 16:42
15+
*/
16+
@Component
17+
public class UserAggregate {
18+
private UserService userService;
19+
20+
@DataBeanProvider(id="userWithPosts",namespace = "feego.example")
21+
public User userWithPosts(
22+
@DataBeanConsumer(id = "user",namespace = "feego.example") User user,
23+
@DataBeanConsumer(id = "posts",namespace = "feego.example") List<Post> posts) {
24+
user.setPosts(posts);
25+
return user;
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.feego.spring.example.model;
2+
3+
import lombok.Data;
4+
5+
/**
6+
7+
* @since 2019/6/2 16:44
8+
*/
9+
@Data
10+
public class Post {
11+
private String title;
12+
private String content;
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.feego.spring.example.model;
2+
3+
import lombok.Data;
4+
5+
import java.util.List;
6+
7+
/**
8+
9+
* @since 2019/6/2 16:38
10+
*/
11+
@Data
12+
public class User {
13+
private Long id;
14+
private String username;
15+
private String email;
16+
List<Post> posts ;
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.feego.spring.example.service;
2+
3+
import org.feego.spring.example.model.Post;
4+
5+
import java.util.List;
6+
7+
/**
8+
9+
* @since 2019/6/2 16:53
10+
*/
11+
public interface PostService {
12+
List<Post> getPosts(Long userId);
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.feego.spring.example.service;
2+
3+
import org.feego.spring.example.model.User;
4+
5+
/**
6+
7+
* @since 2019/6/2 16:36
8+
*/
9+
public interface UserService {
10+
User get(Long id);
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.feego.spring.example.service.impl;
2+
3+
import org.feego.spring.annotation.DataBeanProvider;
4+
import org.feego.spring.annotation.InvokeParameter;
5+
import org.feego.spring.example.model.Post;
6+
import org.feego.spring.example.service.PostService;
7+
import org.springframework.stereotype.Service;
8+
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
/**
13+
14+
* @since 2019/6/2 16:54
15+
*/
16+
@Service
17+
public class PostServiceImpl implements PostService {
18+
@DataBeanProvider(id = "posts",namespace = "feego.example")
19+
@Override
20+
public List<Post> getPosts(@InvokeParameter("userId") Long userId) {
21+
Post post = new Post();
22+
post.setTitle("spring data aggregate example");
23+
post.setContent("No active profile set, falling back to default profiles");
24+
return Collections.singletonList(post);
25+
}
26+
}

0 commit comments

Comments
 (0)