Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » Java » General » Downloads
 
Add your own
alternative version

Modular J2EE, Using Spring DM, Zk and EclipseLink

, 21 Apr 2011 CPOL
This article describes how to create a basic modular Java Enterprise Application, by using these Open Source frameworks
modular-j2ee.zip
jln-core
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
META-INF
MANIFEST.MF
config
jdbc.properties
spring
build.properties
jln-entities
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
META-INF
MANIFEST.MF
bin
com
cp
adrabi
jln
model
Todo.class
build.properties
src
com
cp
adrabi
jln
model
jln-log-config
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
META-INF
MANIFEST.MF
build.properties
log4j.properties
jln-persistence-1.0.0
.project
.settings
org.eclipse.pde.core.prefs
META-INF
MANIFEST.MF
persistence
1.0.0
build.properties
jln-todo-component
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
META-INF
MANIFEST.MF
spring
bin
com
cp
adrabi
jln
todo
services
TodoService.class
impl
TodoServiceImpl.class
build.properties
src
com
cp
adrabi
jln
todo
services
impl
jln-todo-component-test
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
resources
log4j.properties
src
com
cp
adrabi
jln
todo
tests
integration
utils
jln-validation-config
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
META-INF
MANIFEST.MF
services
javax.validation.spi.ValidationProvider
spring
bin
javax
validation
ValidatorFactoryProxy.class
build.properties
src
javax
validation
jln-web-core
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
META-INF
MANIFEST.MF
WEB-INF
components
gentlepage.zul
spring
bin
com
cp
adrabi
web
controllers
BasicComposer.class
build.properties
jln
404.jsp
index.zul
login.zul
src
com
cp
adrabi
web
controllers
jln-web-todo
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
META-INF
MANIFEST.MF
WEB-INF
spring
bin
com
cp
adrabi
jln
web
todo
components
TodoRowModel$1.class
TodoRowModel$2.class
TodoRowModel.class
controllers
ControllerBaseTodo.class
ControllerListTodo.class
ControllerNewTodo.class
ControllerRemoveTodo.class
ControllerUpdateTodo.class
build.properties
jln
admin
todo
list.zul
new.zul
remove.zul
update.zul
src
com
cp
adrabi
jln
web
todo
components
controllers
package com.cp.adrabi.jln.todo.tests.integration;

import java.util.ArrayList;
import java.util.List;

import net.sf.ehcache.CacheManager;

import org.osgi.framework.ServiceReference;
import org.springframework.core.io.Resource;
import org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests;

import com.cp.adrabi.jln.model.Todo;
import com.cp.adrabi.jln.todo.services.TodoService;
import com.cp.adrabi.jln.todo.tests.utils.TestUtil;

/**
 * Integration test for Todo service
 * 
 * @author ADRABI Abderrahim (z3vil)
 *
 */
public class TodoServiceIntegrationTest extends AbstractConfigurableBundleCreatorTests
{
	private static final String TODO_CACHE = "todoCache";
	
	/**
	 * Set up bundles/fragments needed by Todo service
	 */
	@Override
	protected Resource[] getTestFrameworkBundles()
	{
		// *** change path ***
		List<Resource> resources = new ArrayList<Resource>();
		for(Resource r : TestUtil.makeResources("/base-test.txt", "/mnt/dev/java/platform/"))
		{
			resources.add(r);
		}
		for(Resource r : TestUtil.makeResources("/todo-test.txt", "/mnt/dev/java/jeenightmare/plugins/"))
		{
			resources.add(r);
		}
		
		return resources.toArray(new Resource[]{});
	}
	
	/**
	 * Override root path for classes
	 */
	@Override
	public String getRootPath() 
	{
		   return"file:./bin";
	}
	
	/**
	 * test bundle context, work only on JUnit 3
	 */
	public void testBundleContext()
	{
		assertNotNull( this.bundleContext );
	}
	
	/**
	 * Test todo service
	 */
	public void testTodoService()
	{
		assertNotNull( makeService() );
	}
	
	/**
	 * Test cache service
	 */
	public void testCacheService()
	{
		assertNotNull(makeCache());
	}
	
	/**
	 * Test list of Todo objects
	 */
	public void testListTodo()
	{
		final int cache_size = 1;
		
		cacheEmpty();
		
		List<Todo> list = makeService().getListTodo();
		
		assertNotNull(list);
		
		cacheNonEmpty();
		
		cacheSize( cache_size );
		
		list = makeService().getListTodo();
		
		cacheNonEmpty();
		
		cacheSize( cache_size );
		
	}
	
	/**
	 * Test save new Todo object
	 */
	public void testSaveTodo()
	{
		cacheNonEmpty();
		
		Todo todo = new Todo();
		todo.setSummary("#Homework n1");
		todo.setSummary("Create a test integration for service Todo");
		
		makeService().saveTodo(todo);
		
		// after any persist operation need cache be empty
		cacheEmpty();
	}
	
	/**
	 * Test get user by ID
	 */
	public void testGetTodoById()
	{
		final int cache_size = 1;
		
		final Long id = 1l;
		
		cacheEmpty();
		
		Todo todo = makeService().getTodoById(id);
		
		assertNotNull(todo);
		
		cacheNonEmpty();
		cacheSize(cache_size);
	}
	
	/**
	 * Test list todo after insert
	 */
	public void testListTodoAfterInsert()
	{
		final int cache_size = 2;
		
		cacheNonEmpty();
		
		List<Todo> list = makeService().getListTodo();
		
		assertEquals(1, list.size());
		
		cacheNonEmpty();
		cacheSize(cache_size);
	}
	
	/**
	 * Test update todo
	 */
	public void testUpdateTodo()
	{
		final int cache_size = 1;
		
		final Long id = 1l;
		
		cacheNonEmpty();
		
		Todo todo = makeService().getTodoById(id);
		String old_val = todo.getSummary();
		
		assertSame(old_val, todo.getSummary());
		
		todo.setSummary("#Update");
		
		assertNotSame(old_val, todo.getSummary());
		
		makeService().updateTodo(todo);
		
		cacheEmpty();
		
		todo = makeService().getTodoById(id);
		
		assertNotSame(old_val, todo.getSummary());
		
		cacheNonEmpty();
		
		cacheSize(cache_size);
	}
	
	/**
	 * Test remove todo
	 */
	public void testRemoveTodoById()
	{
		cacheNonEmpty();
		
		final Long id = 1l;
		
		makeService().removeTodoById(id);
		
		cacheEmpty();
	}
	
	/**
	 * Test list todo list after delete
	 */
	public void testListTodoAfterDelete()
	{
		cacheEmpty();
		
		List<Todo> list = makeService().getListTodo();
		
		assertEquals(0, list.size());
		
		cacheNonEmpty();
	}
	
	/*
	 *
	 * Private stuff
	 * 
	 */
	
	private TodoService makeService()
	{
		ServiceReference ref = this.bundleContext.getServiceReference("com.cp.adrabi.jln.todo.services.TodoService");
		return (TodoService) this.bundleContext.getService(ref);
	}
	
	private CacheManager makeCache()
	{
		ServiceReference ref = this.bundleContext.getServiceReference("net.sf.ehcache.CacheManager");
		return (CacheManager) this.bundleContext.getService(ref);
	}
	
	private void cacheEmpty()
	{
		CacheManager cache = makeCache();
		assertTrue( cache.getCache(TODO_CACHE).getSize() == 0 );
	}
	
	private void cacheNonEmpty()
	{
		CacheManager cache = makeCache();
		assertTrue( cache.getCache(TODO_CACHE).getSize() > 0 );
	}
	
	private void cacheSize(int size)
	{
		CacheManager cache = makeCache();
		assertTrue( cache.getCache(TODO_CACHE).getSize() == size );
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Adrabi Abderrahim
Technical Lead
Morocco Morocco
Adrabi!, Just another Ghost in the Shell =)

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150331.1 | Last Updated 21 Apr 2011
Article Copyright 2011 by Adrabi Abderrahim
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid