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 8 ■ Give Advice to Your <strong>Spring</strong> Application<br />

As you can see in Listing 8-4, the file is nothing out of the ordinary; in fact, it’s the same file as in previous<br />

chapters. The file contains your SearchEngineService and your DocumentRepository classes defined with a list of<br />

references of documents. But you will be modifying the file in the following sections. First, let’s review your unit test<br />

(see Listing 8-5).<br />

Listing 8-5. MyDocumentsAOPTest.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.assertTrue;<br />

import java.util.List;<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.SearchEngine;<br />

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

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

public class MyDocumentsAOPTest {<br />

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

@Autowired<br />

private SearchEngine engineProxy;<br />

@Autowired<br />

private Type webType;<br />

@Test<br />

public void testUsing<strong>Spring</strong>AOP() {<br />

log.debug("Using <strong>Spring</strong> AOP:");<br />

List documents = engineProxy.findByType(webType);<br />

assertNotNull(documents);<br />

assertTrue(documents.size() == 1);<br />

assertEquals(webType.getName(),documents.get(0).getType().getName());<br />

assertEquals(webType.getDesc(),documents.get(0).getType().getDesc());<br />

assertEquals(webType.getExtension(),documents.get(0).getType().getExtension());<br />

documents = engineProxy.listAll();<br />

assertNotNull(documents);<br />

assertTrue(documents.size() == 4);<br />

95

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

Saved successfully!

Ooh no, something went wrong!