Skip to content

Commit 1017fc2

Browse files
committed
tests prototypes in contexts
1 parent b7837c6 commit 1017fc2

23 files changed

+325
-47
lines changed

springboot-context-demo/README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## Spring Context test
22

3-
- <a href="lazy-bean">@Lazy</a>
4-
- <a href="ApplicationContext">ApplicationContext</a>
3+
- <a href="#lazy-bean">@Lazy</a>
4+
- <a href="#ApplicationContext">ApplicationContext</a>
5+
- <a href="#Prototype">Prototype</a>
56

67

78
---
@@ -26,3 +27,17 @@
2627

2728

2829
---
30+
31+
<div id="Prototype"></div>
32+
33+
## Tests prototype
34+
35+
- Profile : prototype
36+
- Test url :
37+
[GET] : http://localhost:8080/prototypes
38+
[GET] : http://localhost:8080/prototypes/ctx
39+
[GET] : http://localhost:8080/prototype/{id}
40+
[POST] : http://localhost:8080/prototype
41+
[DELETE] : http://localhost:8080/prototype/{id}
42+
43+
---

springboot-context-demo/lombok.config

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lombok.log.fieldname=logger
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_NAME="prototype.sh"
4+
URL="http://localhost:8080"
5+
COMMAND=
6+
ID=
7+
PORT=8080
8+
9+
function printHelp() {
10+
echo "Test for prototype."
11+
echo ""
12+
echo "commands :"
13+
echo " get getting bean all or one"
14+
echo " e.g : ${SCRIPT_NAME} get 1 or ${SCRIPT_NAME} get"
15+
echo " getctx getting bean all from context"
16+
echo " e.g : ${SCRIPT_NAME} getctx"
17+
echo " create create prototype bean"
18+
echo " e.g : ${SCRIPT_NAME} create "
19+
echo " delete destroy prototype bean"
20+
echo " e.g : ${SCRIPT_NAME} delete 1 "
21+
echo ""
22+
}
23+
24+
function get() {
25+
if [[ -z ${ID} ]]; then
26+
curl -X GET ${URL}/prototypes
27+
else
28+
curl -X GET ${URL}/prototype/${ID}
29+
fi
30+
echo ""
31+
}
32+
33+
function getctx() {
34+
curl -X GET -H "Content-Type: application/json; charset=utf-8" ${URL}/prototypes/ctx
35+
echo ""
36+
}
37+
38+
function create() {
39+
curl -X POST -H "Content-Type: application/json; charset=utf-8" ${URL}/prototype
40+
echo ""
41+
}
42+
43+
function delete() {
44+
curl -X DELETE ${URL}/prototype/${ID}
45+
echo ""
46+
}
47+
48+
# command
49+
case "${1}" in
50+
get | getctx | create | delete )
51+
COMMAND=${1}
52+
;;
53+
* )
54+
printHelp
55+
exit 1
56+
;;
57+
esac
58+
59+
case "${COMMAND}" in
60+
get )
61+
ID=${2}
62+
get
63+
;;
64+
getctx )
65+
getctx
66+
;;
67+
create )
68+
create
69+
;;
70+
delete )
71+
ID=${2}
72+
delete
73+
;;
74+
esac

springboot-context-demo/src/main/java/demo/DemoApplication.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public class DemoApplication {
1111
public static void main(String[] args) {
1212
ConfigurableApplicationContext ctx = SpringApplication.run(DemoApplication.class, args);
1313
System.out.println(">>>> Complete to load");
14+
1415
String displayBeanNames = ctx.getEnvironment().getProperty("display.beans.enabled", "false");
1516
if ("true".equalsIgnoreCase(displayBeanNames)) {
1617
displayBeanNames(ctx);
1718
}
18-
ctx.close();
1919
}
2020

2121
private static void displayBeanNames(ConfigurableApplicationContext ctx) {

springboot-context-demo/src/main/java/demo/appctx/AppCtxBean1.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
/**
99
* @author zacconding
10-
* @Date 2018-08-29
11-
* @GitHub : https://github.com/zacscoding
1210
*/
1311
@Slf4j
1412
@Component
@@ -17,11 +15,11 @@ public class AppCtxBean1 implements DaemonMaker {
1715

1816
@PostConstruct
1917
private void setUp() {
20-
log.info("AppCtxBean1 is called");
18+
logger.info("AppCtxBean1 is called");
2119
}
2220

2321
@Override
2422
public String getName() {
2523
return "AppCtxBean1";
2624
}
27-
}
25+
}

springboot-context-demo/src/main/java/demo/appctx/AppCtxBean2.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
/**
99
* @author zacconding
10-
* @Date 2018-08-29
11-
* @GitHub : https://github.com/zacscoding
1210
*/
1311
@Slf4j
1412
@Profile("appctx")
@@ -17,7 +15,7 @@ public class AppCtxBean2 implements DaemonMaker {
1715

1816
@PostConstruct
1917
private void setUp() {
20-
log.info("AppCtxBean2 is called");
18+
logger.info("AppCtxBean2 is called");
2119
}
2220

2321
@Override

springboot-context-demo/src/main/java/demo/appctx/GetBeansConfiguration.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
/**
1414
* @author zacconding
15-
* @Date 2018-08-29
16-
* @GitHub : https://github.com/zacscoding
1715
*/
1816
@Slf4j
1917
@ComponentScan(basePackages = "demo.appctx")
@@ -26,12 +24,12 @@ public class GetBeansConfiguration {
2624

2725
@PostConstruct
2826
private void setUp() {
29-
log.info("## GetBeansConfiguration() is called");
27+
logger.info("## GetBeansConfiguration() is called");
3028
Map<String, DaemonMaker> beans = ctx.getBeansOfType(DaemonMaker.class);
31-
log.info(">>>>>>>>>>>>>>>>>>>>> Check daemon... size : " + beans.size());
29+
logger.info(">>>>>>>>>>>>>>>>>>>>> Check daemon... size : " + beans.size());
3230

3331
for (Entry<String, DaemonMaker> entry : beans.entrySet()) {
34-
log.info("> Key : {} ==> Name : {}", entry.getKey(), entry.getValue().getName());
32+
logger.info("> Key : {} ==> Name : {}", entry.getKey(), entry.getValue().getName());
3533
}
3634
}
37-
}
35+
}

springboot-context-demo/src/main/java/demo/lazybean/LazyBeanConfiguration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public class LazyBeanConfiguration {
2222
@Bean
2323
@Lazy
2424
public LazyBeanService1 lazyBeanService1() {
25-
log.info("## lazyBeanService1() is called in LazyBeanConfiguration");
25+
logger.info("## lazyBeanService1() is called in LazyBeanConfiguration");
2626
return new LazyBeanService1();
2727
}
2828

2929
@Bean
3030
@Lazy
3131
public LazyBeanService2 lazyBeanService2() {
32-
log.info("## lazyBeanService2() is called in LazyBeanConfiguration");
32+
logger.info("## lazyBeanService2() is called in LazyBeanConfiguration");
3333
return new LazyBeanService2();
3434
}
35-
}
35+
}

springboot-context-demo/src/main/java/demo/lazybean/LazyBeanConfiguration2.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
public class LazyBeanConfiguration2 {
1818

1919
public LazyBeanConfiguration2() {
20-
log.info("## LazyBeanConfiguration2() is called");
20+
logger.info("## LazyBeanConfiguration2() is called");
2121
}
2222

2323
@Bean
2424
public LazyBeanService3 lazyBeanService3() {
25-
log.info("## lazyBeanService3() is called in LazyBeanConfiguration");
25+
logger.info("## lazyBeanService3() is called in LazyBeanConfiguration");
2626
return new LazyBeanService3();
2727
}
2828

2929
@Bean
3030
public LazyBeanService4 lazyBeanService4() {
31-
log.info("## lazyBeanService4() is called in LazyBeanConfiguration");
31+
logger.info("## lazyBeanService4() is called in LazyBeanConfiguration");
3232
return new LazyBeanService4();
3333
}
34-
}
34+
}

springboot-context-demo/src/main/java/demo/lazybean/LazyBeanController.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ public class LazyBeanController {
2727

2828
@GetMapping("/lazybean/bean1")
2929
public String call() {
30-
log.info("## /lazybean/test1 is called in LazyBeanController");
30+
logger.info("## /lazybean/test1 is called in LazyBeanController");
3131
return lazyBeanService1.getName();
3232
}
3333

3434
@GetMapping("/lazybean/bean2")
3535
public String call2() {
36-
log.info("## /lazybean/test2 is called in LazyBeanController");
36+
logger.info("## /lazybean/test2 is called in LazyBeanController");
3737
LazyBeanService2 bean = context.getBean(LazyBeanService2.class);
3838
return bean.getName();
3939
}
4040

4141
@GetMapping("/lazybean/bean3")
4242
public String call3() {
43-
log.info("## /lazybean/test3 is called in LazyBeanController");
43+
logger.info("## /lazybean/test3 is called in LazyBeanController");
4444
LazyBeanService3 bean = context.getBean(LazyBeanService3.class);
4545
return bean.getName();
4646
}
47-
}
47+
}

springboot-context-demo/src/main/java/demo/lazybean/LazyBeanController2.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class LazyBeanController2 {
1818

1919
@PostConstruct
2020
public void setUp() {
21-
log.info("## LazyBeanController2 is called in LazyBeanController2::setUp()");
21+
logger.info("## LazyBeanController2 is called in LazyBeanController2::setUp()");
2222
}
2323

2424
@GetMapping("/lazybean2")

springboot-context-demo/src/main/java/demo/lazybean/LazyBeanService1.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public class LazyBeanService1 {
1313

1414
@PostConstruct
1515
private void setUp() {
16-
log.info("## Create LazyBeanService1 in PostContruct");
16+
logger.info("## Create LazyBeanService1 in PostContruct");
1717
}
1818

1919
public String getName() {
2020
return "LazyBeanService1";
2121
}
22-
}
22+
}

springboot-context-demo/src/main/java/demo/lazybean/LazyBeanService2.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public class LazyBeanService2 {
1313

1414
@PostConstruct
1515
private void setUp() {
16-
log.info("## Create LazyBeanService2 in PostContruct");
16+
logger.info("## Create LazyBeanService2 in PostContruct");
1717
}
1818

1919
public String getName() {
2020
return "LazyBeanService2";
2121
}
22-
}
22+
}

springboot-context-demo/src/main/java/demo/lazybean/LazyBeanService3.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public class LazyBeanService3 {
1313

1414
@PostConstruct
1515
private void setUp() {
16-
log.info("## Create LazyBeanService3 in PostContruct");
16+
logger.info("## Create LazyBeanService3 in PostContruct");
1717
}
1818

1919
public String getName() {
2020
return "LazyBeanService3";
2121
}
22-
}
22+
}

springboot-context-demo/src/main/java/demo/lazybean/LazyBeanService4.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public class LazyBeanService4 {
1313

1414
@PostConstruct
1515
private void setUp() {
16-
log.info("## Create LazyBeanService4 in PostContruct");
16+
logger.info("## Create LazyBeanService4 in PostContruct");
1717
}
1818

1919
public String getName() {
2020
return "LazyBeanService4";
2121
}
22-
}
22+
}

springboot-context-demo/src/main/java/demo/multiplebean/LowerCaseMultipleBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public class LowerCaseMultipleBean implements IMultipleBean {
1616

1717
@Override
1818
public void onString(String message) {
19-
log.info("[LowerCaseListener] message : {}", message == null ? "NULL" : message.toLowerCase());
19+
logger.info("[LowerCaseListener] message : {}", message == null ? "NULL" : message.toLowerCase());
2020
}
2121
}

springboot-context-demo/src/main/java/demo/multiplebean/MultipleBeanMessageProducer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private void setUp() {
3939
Iterator<String> itr = beans.keySet().iterator();
4040
while (itr.hasNext()) {
4141
String beanName = itr.next();
42-
log.info("IMultipleBean : {}", beanName);
42+
logger.info("IMultipleBean : {}", beanName);
4343
listeners.add(beans.get(beanName));
4444
}
4545

springboot-context-demo/src/main/java/demo/multiplebean/UpperCaseMultipleBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public class UpperCaseMultipleBean implements IMultipleBean {
1818

1919
@Override
2020
public void onString(String message) {
21-
log.info("[UppercaseListener] message : {}", message == null ? "NULL" : message.toUpperCase());
21+
logger.info("[UppercaseListener] message : {}", message == null ? "NULL" : message.toUpperCase());
2222
}
2323
}

0 commit comments

Comments
 (0)