25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

@Autowired<br />

DocumentDAO mongoDocumentDAO;<br />

@Autowired<br />

TypeDAO mongoTypeDAO;<br />

@Autowired<br />

DocumentService documentFacade;<br />

@Autowired<br />

TypeService typeFacade;<br />

@Test<br />

public void testMongoDBMigration(){<br />

log.debug("Testing <strong>Spring</strong> Data MongoDB - Migration (Run only once)...");<br />

assertNotNull(mongoDocumentDAO);<br />

assertNotNull(documentFacade);<br />

assertNotNull(typeFacade);<br />

assertNotNull(mongoTypeDAO);<br />

List types = typeFacade.getAllDefinedTypes();<br />

assertNotNull(types);<br />

assertEquals(4, types.size());<br />

for(Type type: types){<br />

mongoTypeDAO.save(type);<br />

}<br />

List documents = documentFacade.getAllDocuments();<br />

assertNotNull(documents);<br />

assertEquals(6, documents.size());<br />

}<br />

}<br />

for(Document document : documents){<br />

mongoDocumentDAO.save(document.getDocumentId(), document);<br />

}<br />

Reviewing the logic in your unit test (see Listing 15-6), you are going to start by migrating the JDBC into the<br />

MongoDB server; here you are using the two implementations of the DocumentDAO interface. And you are going to<br />

begin by adding the types that should be in the types collection, and then the documents that should be in the docs<br />

collection. After running the unit test you can open a new terminal (DOS or Unix) and connect to the MongoDB server<br />

to see if the data is there.<br />

Figure 15-1 shows the databases and the collections created.<br />

211

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

Saved successfully!

Ooh no, something went wrong!