Introducing Spring Framework

Introducing Spring Framework Introducing Spring Framework

25.02.2015 Views

Chapter 15 ■ Spring Data Within Your Spring Application Figure 15-2. MongoDB Shell Shows the Types Collections Figure 15-3. MongoDB Shell Shows the Docs Collections Figure 15-2 shows how you can execute the db.types.find() command in order to see the contents of the types collections. Figure 15-3 shows the contents of the docs collection. To see the docs collection data, execute the db.docs.find() command as shown in Figure 15-3. 213

Chapter 15 ■ Spring Data Within Your Spring Application A Complete DocumentDAO Test Now you can complete the unit test with the rest of the DocumentDAO implementation. Remember that you have just migrated the existing data from JDBC to the MongoDB. So now it’s time to test the other methods from the DocumentDAO implementation—that is find, update, and remove from MongoDB. Listing 15-7 shows the completed unit test. Listing 15-7. MyDocumentsTest.java – Complete package com.apress.isf.spring.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.util.List; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.apress.isf.java.model.Document; import com.apress.isf.java.model.Type; import com.apress.isf.java.service.DocumentService; import com.apress.isf.java.service.TypeService; import com.apress.isf.spring.data.DocumentDAO; import com.apress.isf.spring.data.TypeDAO; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:META-INF/spring/mydocuments-context.xml") public class MyDocumentsTest { private static final Logger log = LoggerFactory.getLogger(MyDocumentsTest.class); private static final String ID = "1acbb68a-a859-49c9-ac88-d9e9322bac55"; private static final String NAME = "Book Template"; private static final String NAME_UPDATED = "My Book"; @Autowired DocumentDAO mongoDocumentDAO; @Autowired TypeDAO mongoTypeDAO; @Autowired DocumentService documentFacade; @Autowired TypeService typeFacade; 214

Chapter 15 ■ <strong>Spring</strong> Data Within Your <strong>Spring</strong> Application<br />

Figure 15-2. MongoDB Shell Shows the Types Collections<br />

Figure 15-3. MongoDB Shell Shows the Docs Collections<br />

Figure 15-2 shows how you can execute the db.types.find() command in order to see the contents of the types<br />

collections. Figure 15-3 shows the contents of the docs collection.<br />

To see the docs collection data, execute the db.docs.find() command as shown in Figure 15-3.<br />

213

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

Saved successfully!

Ooh no, something went wrong!