Introducing Spring Framework
Introducing Spring Framework Introducing Spring Framework
Chapter 5 ■ Working with Collections and Custom Types In mydocuments-util-context.xml (see Listing 5-7) you added the xmlns:util namespace that allows you to add the and tags that accepts the List and Map types, respectively. Also, the xmlns:util namespace has the , , and tags. They are easy to use, so go ahead and do some testing on your own with these collection tags. After all the modifications you did on the source code, you can run the unit test in the same way you have been running them, by using the gradle tool. If you are in the book’s source code base directory, it’s gradle :ch05:test Or in the project’s directory you can run gradle test You should expect the same result as the following output: com.apress.isf.spring.test.MyDocumentsTest > testAll STARTED com.apress.isf.spring.service.SearchEngineService@4068f746 Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,855 DEBUG [Test worker] Document DAO set: com.apress.isf.spring.data. DocumentRepository@4ad88414 Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] Start Params: Type Definition: Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: Name: WEB Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: Description: Web Link Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: Extension: .url 59
Chapter 5 ■ Working with Collections and Custom Types Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] Start Params: Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] Start Params: Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] End Result:[Lcom.apress.isf.java.model.Document;@8117683 Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] End Result: [com.apress.isf.java.model.Document@4fdbef0c, com.apress.isf.java.model.Document@20bde8a7, com.apress.isf.java.model.Document@13f53cbc, com.apress.isf.java.model.Document@496664e0] Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] End Result: [com.apress.isf.java.model.Document@496664e0] Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] Start Params: Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] Start Params: Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] End Result:[Lcom.apress.isf.java.model.Document;@5728210a Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22 21:47:27,857 DEBUG [Test worker] End Result: [com.apress.isf.java.model.Document@4fdbef0c, com.apress.isf.java.model.Document@20bde8a7, com.apress.isf.java.model.Document@13f53cbc, com.apress.isf.java.model.Document@496664e0] com.apress.isf.spring.test.MyDocumentsTest > testAll PASSED Summary You modified some of your source code, putting in some logs to identify what method you are using, what parameters you are sending, and the result. You also learned how to debug your code in case something happens. You introduced some collections to your code instead of handling each document one at a time. (Imagine if you have thousands of types in your documents. Impractical!!) In a real world scenario, the usage of collections is a nice feature from Spring. Certain values such as user roles or user permissions can be changed easily from an XML configuration file. You saw how in Spring you can use these collections in a declarative form, by using the list, map, set, and properties tags and the different ways to use collections, like the usage of XML namespaces. Which one should you use? Well, this will be your own preference. This is just a new syntax to accomplish the same, but in a more elegant way. 60
- Page 11 and 12: Chapter 1 ■ Your First Spring App
- Page 13 and 14: Chapter 1 ■ Your First Spring App
- Page 15 and 16: Chapter 1 ■ Your First Spring App
- Page 17 and 18: Chapter 1 ■ Your First Spring App
- Page 19 and 20: Chapter 2 ■ Working with Classes
- Page 21 and 22: Chapter 2 ■ Working with Classes
- Page 23 and 24: Chapter 2 ■ Working with Classes
- Page 25 and 26: Chapter 2 ■ Working with Classes
- Page 27 and 28: Chapter 2 ■ Working with Classes
- Page 29 and 30: Chapter 3 Applying Different Config
- Page 31 and 32: Chapter 3 ■ Applying Different Co
- Page 33 and 34: Chapter 3 ■ Applying Different Co
- Page 35 and 36: Chapter 3 ■ Applying Different Co
- Page 37 and 38: Chapter 3 ■ Applying Different Co
- Page 39 and 40: Chapter 3 ■ Applying Different Co
- Page 41 and 42: Spring Stereotypes Chapter 3 ■ Ap
- Page 43 and 44: Chapter 3 ■ Applying Different Co
- Page 45 and 46: Chapter 3 ■ Applying Different Co
- Page 47 and 48: Chapter 3 ■ Applying Different Co
- Page 49 and 50: Chapter 4 ■ Using Beans Scopes pu
- Page 51 and 52: Chapter 4 ■ Using Beans Scopes Th
- Page 53 and 54: Chapter 4 ■ Using Beans Scopes @A
- Page 55 and 56: Chapter 4 ■ Using Beans Scopes do
- Page 57 and 58: Chapter 5 ■ Working with Collecti
- Page 59 and 60: Chapter 5 ■ Working with Collecti
- Page 61: Chapter 5 ■ Working with Collecti
- Page 65 and 66: Chapter 6 ■ Using Resource Files
- Page 67 and 68: Chapter 6 ■ Using Resource Files
- Page 69 and 70: Chapter 6 ■ Using Resource Files
- Page 71 and 72: Chapter 6 ■ Using Resource Files
- Page 73 and 74: Chapter 6 ■ Using Resource Files
- Page 75 and 76: Chapter 6 ■ Using Resource Files
- Page 77 and 78: Chapter 7 Testing Your Spring Appli
- Page 79 and 80: Chapter 7 ■ Testing Your Spring A
- Page 81 and 82: Chapter 7 ■ Testing Your Spring A
- Page 83 and 84: Chapter 7 ■ Testing Your Spring A
- Page 85 and 86: Chapter 7 ■ Testing Your Spring A
- Page 87 and 88: Chapter 7 ■ Testing Your Spring A
- Page 89 and 90: Chapter 8 Give Advice to Your Sprin
- Page 91 and 92: Chapter 8 ■ Give Advice to Your S
- Page 93 and 94: Chapter 8 ■ Give Advice to Your S
- Page 95 and 96: Chapter 8 ■ Give Advice to Your S
- Page 97 and 98: Chapter 8 ■ Give Advice to Your S
- Page 99 and 100: Chapter 8 ■ Give Advice to Your S
- Page 101 and 102: Chapter 8 ■ Give Advice to Your S
- Page 103 and 104: Chapter 8 ■ Give Advice to Your S
- Page 105 and 106: Chapter 8 ■ Give Advice to Your S
- Page 107 and 108: Chapter 8 ■ Give Advice to Your S
- Page 109 and 110: Chapter 8 ■ Give Advice to Your S
- Page 111 and 112: Chapter 9 ■ Adding Persistence to
Chapter 5 ■ Working with Collections and Custom Types<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
In mydocuments-util-context.xml (see Listing 5-7) you added the xmlns:util namespace that allows you to<br />
add the and tags that accepts the List and Map types, respectively. Also, the xmlns:util<br />
namespace has the , , and tags. They are easy to use, so go<br />
ahead and do some testing on your own with these collection tags.<br />
After all the modifications you did on the source code, you can run the unit test in the same way you have been<br />
running them, by using the gradle tool. If you are in the book’s source code base directory, it’s<br />
gradle :ch05:test<br />
Or in the project’s directory you can run<br />
gradle test<br />
You should expect the same result as the following output:<br />
com.apress.isf.spring.test.MyDocumentsTest > testAll STARTED<br />
com.apress.isf.spring.service.SearchEngineService@4068f746<br />
Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err:<br />
2014-04-22 21:47:27,855 DEBUG [Test worker] Document DAO set: com.apress.isf.spring.data.<br />
DocumentRepository@4ad88414<br />
Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: 2014-04-22<br />
21:47:27,857 DEBUG [Test worker] Start Params: Type Definition:<br />
Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: Name: WEB<br />
Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err:<br />
Description: Web Link<br />
Test: test testAll(com.apress.isf.spring.test.MyDocumentsTest) produced standard out/err: Extension: .url<br />
59