Small Batches
Great article on small batches and continuous integration.
http://startuplessonslearned.blogspot.com/2009/02/work-in-small-batches.html
FERC – Electric Power Markets Overview
http://www.ferc.gov/market-oversight/mkt-electric/overview.asp
Good sight for overall statistics and information on each of the power markets in the US.
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);
}
}
First Post from my IPhone
I just downloaded the wordpress app from iTunes so I am taking it for a spin.
Seems to write pretty well and adding photos is fairly simple.
Good for quick posts or something to do while waiting.
