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 14 ■ Using Dynamic Languages<br />

@Test<br />

public void testSecurity(){<br />

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

assertNotNull(security);<br />

}<br />

assertTrue(security.areCredentialsValid(EMAIL,PASSWORD));<br />

}<br />

Listing 14-6 shows you that the only assertion here will be just to verify that the credentials are valid by calling the<br />

areCredentialsValid method. So, after you run the test (Listing 14-6) with<br />

gradle :ch14:test<br />

you should see the following output:<br />

2014-03-20 00:11:59,835 DEBUG [Test worker] Testing Security...<br />

2014-03-20 00:11:59,854 DEBUG [Test worker] Validating Credentials > email:john@email.com, pass:doe<br />

com.apress.isf.spring.test.MyDocumentsTest > testBeanShell PASSED<br />

It worked! Now you know how to use Groovy if you want to implement or add some dynamic business logic to<br />

your <strong>Spring</strong> application. But wait, there’s more! The <strong>Spring</strong> <strong>Framework</strong> also allows you to add inline scripting in the<br />

XML configuration. Listing 14-7 shows that.<br />

Listing 14-7. mydocuments-context.xml<br />

<br />

<br />

<br />

<br />

<br />

import com.apress.isf.java.service.Login<br />

class GroovyLoginService implements Login {<br />

String username<br />

String password<br />

199

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

Saved successfully!

Ooh no, something went wrong!