Big Ball of Mud
My personal favorite is "Keep It Working".
Must read for people who "prototype".
Small Batches
Great article on small batches and continuous integration.
http://startuplessonslearned.blogspot.com/2009/02/work-in-small-batches.html
TestNG, Spring, Maven – Quick and Easy
First, you need the dependencies. TestNG requires you to have a classifier for the jdk.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stephennimmo</groupId>
<artifactId>demo</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>domain</name>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.8</version>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>2.5.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
Now the testng.xml that is located in your test resources dir.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="domain" verbose="5"> <test name="DomainObjectFactoryTests"> <packages> <package name="com.stephennimmo.domain.test" /> </packages> </test> </suite>
Here's the test class. Pay attention that it extends the AbstractTestNGSpringContextTests. If you want transactions involved, extend AbstractTransactionalTestNGSpringContextTests and set it up in the @BeforeClass.
@ContextConfiguration(locations={"classpath:ServiceFactoryContext.xml"})
public class TestPersonService extends AbstractTestNGSpringContextTests {
@Autowired
private PersonService personService;
@Test(groups = { "service" })
public void testPersonService(){
long id = 1000;
Person p = personService.find(id);
assertNotNull(p);
assertEquals(p.getId(), id);
}
}
Thanks to Josh Long.
http://www.joshlong.com/jl/entry/testng_spring_testcontext_and_maven
Using Factories as Entry Points for APIs
How do we get started? What do we do first? Do we instantiate an object? Do we get our trusty Spring context started with a good old new ClassPathXmlApplicationContext? How can we have a centralized and easy to use entry point regardless of the environment or container?
The factory pattern is a great opportunity to allow the developer to manage access to objects and handle some of the service-type concerns such as dependency injection and context building.
public abstract class AbstractFactory implements ApplicationContextAware {
private ApplicationContext applicationContext;
public ApplicationContext getApplicationContext() {
return applicationContext;
}
public void setApplicationContext(String contextFile) {
if (contextFile.indexOf("classpath") > 0){
this.applicationContext = new ClassPathXmlApplicationContext(contextFile);
} else {
this.applicationContext = new FileSystemXmlApplicationContext(contextFile);
}
}
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
}
By simply extending this AbstractFactory, your context will always be managed, regardless of whether you are running in a TestNG environment or in a web container with the ContextLoaderListener.
public class DomainObjectFactoryImpl extends AbstractFactory implements DomainObjectFactory {
public Person createPerson(){
return (Person) getApplicationContext().getBean("person");
}
}
Run it in your test...
@ContextConfiguration(locations={&amp;quot;classpath:DomainObjectContext.xml&amp;quot;})
public class TestDomainObjectFactory extends AbstractTestNGSpringContextTests {
private DomainObjectFactory domainObjectFactory;
@Test(groups = { "domain" })
public void testPerson(){
Person p = domainObjectFactory.createPerson();
assertNotNull(p);
}
public void setDomainObjectFactory(DomainObjectFactory domainObjectFactory) {
this.domainObjectFactory = domainObjectFactory;
}
}
If you create your modules to be packaged as supporting jars, such as when you use maven, you are able to include context files on the classpath using the classpath* searching features. To use this particular class, simply add the jar dependency to your maven pom and add in the import into your existing spring context.
At that point, the end user needs to know one thing. The name of the factory interface. If you name the context file as InterfaceContext.xml and the bean name is the same as the interface, no more searching for entry points. And if you get REALLY fancy the object type (or pattern) can even help you more.
Where do I find that one service? Service...ServiceFactory...ServiceFactoryContext.xml
What is the correct implementation for the Trade interface? What is a trade? It's a domain object. DomainObject. DomainObjectFactory. DomainObjectFactoryContext.xml
It can be this easy.
Great WordPress Themes
I got me a new theme today and I love it.
Here's the site where I found it.
It has tons of free, clean and easy to manage WP themes.
Generic Coherence Filter
public abstract class AbstractFilter<KEY extends Serializable, OBJECT>
implements Filter, Serializable {
public abstract boolean evaluate(KEY key, OBJECT object);
@SuppressWarnings("unchecked";)
public boolean evaluate(Object o) {
MapEvent event = (MapEvent)o;
KEY key = (KEY)event.getKey();
OBJECT object = (OBJECT) event.getNewValue();
return evaluate(key, object);
}
}
Agile Project Managers
Quote from a response on LinkedIn.
"If you are a PM or IT manager, you should sit with your developers often at random. They should be pairing, talking to each other, writing failing tests before writing code, checking in several times a day, should have a green CI build before the end of the day, etc. etc. Yes, of course no team does these things ALL the time. But real Agile teams do them almost all the time, and have frequent discussions at Retrospectives about when it is appropriate NOT to do them.
If your developers are not doing these things, but still say they are "Agile", here's a secret - they ain't. They are paying lip service, and are at a great risk of failing - and besmirching the good name of Agile."
Written by Chad Wooley
If you are a project manager - regardless or whether you are actively using scrum - read this every day with your morning coffee.
Google GWT Maven Archetype and GWT Debugging
mvn archetype:create -DarchetypeGroupId=com.totsp.gwt -DarchetypeArtifactId=maven-googlewebtoolkit2-archetype -DarchetypeVersion=1.0.3 -DartifactId=foobar -DgroupId=foo.bar -DremoteRepositories=http://gwt-maven.googlecode.com/svn/trunk/mavenrepo mvn eclipse:eclipse mvn clean mvn com.totsp.gwt:maven-googlewebtoolkit2-plugin:gwt mvn com.totsp.gwt:maven-googlewebtoolkit2-plugin:debug
To set up debugging, see
http://www.screaming-penguin.com/node/7353
Goodbye Dojo. Hello GWT.
Difference #2 – Windows vs. Ubuntu
Table names through MySQL are case sensitive.
'select * from sch.TABLE' is not the same as 'select * from sch.table'
So if you start getting "Table 'xxxx' doesn't exist" you'll know why.
Check your hibernate mapping and table names. Hibernate does not check the database structure on startup, only the mappings.