Introducing Spring Framework

Introducing Spring Framework Introducing Spring Framework

25.02.2015 Views

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

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

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!