25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

A Complete DocumentDAO Test<br />

Now you can complete the unit test with the rest of the DocumentDAO implementation. Remember that you have<br />

just migrated the existing data from JDBC to the MongoDB. So now it’s time to test the other methods from the<br />

DocumentDAO implementation—that is find, update, and remove from MongoDB. Listing 15-7 shows the completed<br />

unit test.<br />

Listing 15-7. MyDocumentsTest.java – Complete<br />

package com.apress.isf.spring.test;<br />

import static org.junit.Assert.assertEquals;<br />

import static org.junit.Assert.assertNotNull;<br />

import static org.junit.Assert.assertNull;<br />

import java.util.List;<br />

import org.junit.Ignore;<br />

import org.junit.Test;<br />

import org.junit.runner.RunWith;<br />

import org.slf4j.Logger;<br />

import org.slf4j.LoggerFactory;<br />

import org.springframework.beans.factory.annotation.Autowired;<br />

import org.springframework.test.context.ContextConfiguration;<br />

import org.springframework.test.context.junit4.<strong>Spring</strong>JUnit4ClassRunner;<br />

import com.apress.isf.java.model.Document;<br />

import com.apress.isf.java.model.Type;<br />

import com.apress.isf.java.service.DocumentService;<br />

import com.apress.isf.java.service.TypeService;<br />

import com.apress.isf.spring.data.DocumentDAO;<br />

import com.apress.isf.spring.data.TypeDAO;<br />

@RunWith(<strong>Spring</strong>JUnit4ClassRunner.class)<br />

@ContextConfiguration("classpath:META-INF/spring/mydocuments-context.xml")<br />

public class MyDocumentsTest {<br />

private static final Logger log = LoggerFactory.getLogger(MyDocumentsTest.class);<br />

private static final String ID = "1acbb68a-a859-49c9-ac88-d9e9322bac55";<br />

private static final String NAME = "Book Template";<br />

private static final String NAME_UPDATED = "My Book";<br />

@Autowired<br />

DocumentDAO mongoDocumentDAO;<br />

@Autowired<br />

TypeDAO mongoTypeDAO;<br />

@Autowired<br />

DocumentService documentFacade;<br />

@Autowired<br />

TypeService typeFacade;<br />

214

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

Saved successfully!

Ooh no, something went wrong!