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 />

<br />

<br />

<br />

<br />

<br />

Listing 15-5 shows the XML configuration file and the use of a new namespace. This tag tells the<br />

<strong>Spring</strong> Data module how to connect to the MongoDB server and what database to use, in this case mydocuments. Now<br />

you need to start testing your application.<br />

Testing MongoDB<br />

You are going to start testing the new DocumentDAO and TypeDAO implementations, so you need to have the<br />

MongoDB up and running. See the “Install Mongo DB” section in Appendix A. See Listing 15-6 for the unit test.<br />

Listing 15-6. MyDocumentsTest.java<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 />

210

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

Saved successfully!

Ooh no, something went wrong!