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

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

// The Previous test goes here<br />

@Test<br />

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

log.debug("Testing Caching Module...");<br />

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

assertNotNull(documents);<br />

int count = documents.size();<br />

log.debug("It should be now cached!");<br />

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

assertNotNull(documents);<br />

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

}<br />

}<br />

log.debug("It should be now cached!");<br />

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

assertNotNull(documents);<br />

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

If you run Listing 8-16 with the new method for testing the cache with<br />

gradle :ch08:test<br />

you should have the following output:<br />

2014-02-23 21:07:04,630 DEBUG [main] Testing Caching Module...<br />

2014-02-23 21:07:04,639 DEBUG [main] @@@(Caching) review if this call is cachable...<br />

2014-02-23 21:07:04,639 DEBUG [main] @@@(Caching) Is cachable!!<br />

2014-02-23 21:07:04,640 DEBUG [main] @@@(Caching) Not Found! but is cachable!<br />

2014-02-23 21:07:04,680 DEBUG [main] It should be now cached!<br />

2014-02-23 21:07:04,680 DEBUG [main] @@@(Caching) review if this call is cachable...<br />

106

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

Saved successfully!

Ooh no, something went wrong!