Archive for the ‘Development’ Category
Group by SQL
Saturday, February 26th, 2011
For some reason I can never remember this simple piece of “group by SQL”. Some sort of mental block
SELECT foo, COUNT(foo) AS theCount FROM bar GROUP BY foo
Tags: sql
Posted in Development | No Comments »
DB2′s equivalent of Oracle’s “dual”
Wednesday, February 16th, 2011
This is really a quick example of DB2′s equivalent of Oracle’s “dual”
Get current date/time in DB2
select current date from sysibm.sysdummy1
Tags: DB2
Posted in Development, quick tips | No Comments »
How to stop XSLT from escaping XML in output
Tuesday, September 28th, 2010
I was asked by a colleague today how to prevent XSLT from escaping XML “special characters” in its output. i.e. < was being escaped to < ;.
I didn't know but somebody else did...
<xsl:value-of select=”somethingWhichContainsXml” /> should be <xsl:value-of select=”somethingWhichContainsXml” disable-output-escaping=”yes” />
Tags: xml, xslt
Posted in Development, How to's | No Comments »
Access a Spring Bean from within a Servlet
Tuesday, September 21st, 2010
ApplicationContext context =
WebApplicationContextUtils.getWebApplicationContext(getServletContext());
MyService service = (MyService) context.getBean("serviceBeanName");
Tags: java, spring
Posted in Development, quick tips | No Comments »
EasyMock Capture Example
Thursday, September 2nd, 2010
Background
EasyMock version 2.4 introduced some new functionality – the ability to capture the arguments passed to mock objects. As ever a few lines of code speaks volumes.
Capture Example
Test Class
package foo.bar;
import static org.junit.Assert.assertEquals;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.easymock.IMocksControl;
import org.junit.Before;
import org.junit.Test;
public class TestServiceImpl {
private Service service;
private Dao dao;
private IMocksControl controller;
private final String description = "description";
@Before
public void setUp() throws Exception {
controller = EasyMock.createStrictControl();
dao = controller.createMock(Dao.class);
service = new ServiceImpl();
service.setDao(dao);
}
@Test
public void testSave() {
Capture <DomainObject> capturedArgument = new Capture <DomainObject>();
dao.save(EasyMock.and(EasyMock.capture(capturedArgument), EasyMock.isA(DomainObject.class)));
controller.replay();
service.save(description);
controller.verify();
DomainObject record = capturedArgument.getValue();
assertEquals(description, record.getDescription());
assertEquals("getNextId", record.getId());
}
}
Source code for classes under test after the break…….
(more...)
Tags: easymock, java, testing
Posted in Development, Examples | No Comments »
