My test fails on the "testModifyModules". Is there something that I am doing wrong?
Following is my Stateless Bean: /* | * Created on May 23, 2006 | * | * This distribution may include materials developed by third parties. | * | * Copyright (c) 2004 Vivek Srivastav. All rights reserved. | * U.S. - Commercial software. Use is subject to license terms. | */ | package org.test.ejb3.sb; | | import java.util.Collection; | | import javax.ejb.Remote; | import javax.ejb.Stateless; | import javax.persistence.EntityManager; | import javax.persistence.PersistenceContext; | | import org.test.ejb3.eb.Module; | | @Stateless | @Remote(ModuleManager.class) | public class ModuleManagerBean implements ModuleManager { | @PersistenceContext(unitName = "test") | protected EntityManager em; | | @SuppressWarnings("unchecked") | public Collection<Module> getModules() { | return em.createQuery("from Module m").getResultList(); | } | | public Module addModule(Module m) { | em.persist(m); | return m; | } | | public Module updateModule(Module m) { | em.merge(m); | return m; | } | | public void removeModule(Module m) { | em.remove(m); | } | | public Module getModule(int moduleID) { | return em.find(Module.class,moduleID); | } | | } | and the junit test case: | /* | * Created on May 23, 2006 | * | * This distribution may include materials developed by third parties. | * | * Copyright (c) 2004 Vivek Srivastav. All rights reserved. | * U.S. - Commercial software. Use is subject to license terms. | */ | package org.test.ejb3.sb; | | import java.util.Collection; | import java.util.HashSet; | import java.util.Properties; | import java.util.logging.Logger; | | import javax.naming.Context; | import javax.naming.InitialContext; | | import org.test.ejb3.eb.Module; | import org.test.ejb3.eb.ModuleProperty; | import org.test.ejb3.eb.ModulePropertyPK; | | import junit.framework.Assert; | import junit.framework.TestCase; | | public class ModuleManagerTest extends TestCase { | | InitialContext context; | | /* | * Test method for 'org.test.ejb3.sb.ModuleManagerBean.getModules()' | */ | public void testGetModules() { | try { | ModuleManager manager = (ModuleManager) context | .lookup("cortest/ModuleManagerBean/remote"); | Collection<Module> modules = manager.getModules(); | int size = modules.size(); | Assert.assertTrue("The modules count is not 10",size==modules.size()); | } catch (Exception ex) { | ex.printStackTrace(); | Assert.fail("Test Failed: " + ex.getClass().getSimpleName()+":"+ex.getMessage()); | } | } | | public void testAddRemoveModules() { | try { | ModuleManager manager = (ModuleManager) context | .lookup("cortest/ModuleManagerBean/remote"); | Module m = manager.addModule(new Module()); | Assert.assertTrue("Failed to add module, returned null",m!=null); | Assert.assertTrue("Module ID is not set",m.getModuleID()!=0); | manager.removeModule(m); | m = manager.getModule(m.getModuleID()); | Assert.assertTrue("Module not deleted.",m==null); | } catch (Exception ex) { | ex.printStackTrace(); | Assert.fail("Test Failed: " + ex.getClass().getSimpleName()+":"+ex.getMessage()); | } | } | | public void testModifyModules(){ | try { | ModuleManager manager = (ModuleManager) context | .lookup("cortest/ModuleManagerBean/remote"); | Collection<Module> modules = manager.getModules(); | for(Module module: modules){ | addProperties(module); | module = manager.updateModule(module); | updateProperties(module); | module = manager.updateModule(module); | removeProperties(module); | module = manager.updateModule(module); | } | } catch (Exception ex) { | ex.printStackTrace(); | Assert.fail("Test Failed: " + ex.getClass().getSimpleName()+":"+ex.getMessage()); | } | } | | private void updateProperties(Module module) { | // TODO Auto-generated method stub | Collection<ModuleProperty>properties = module.getProperties(); | int count = (int)Math.random()*properties.size(); | Logger.global.info("Updating "+count+" properties out off tatal:"+ properties.size()+" for module: "+module.getModuleID()); | for(ModuleProperty p: properties){ | p.setValue("UPDATED VAL: "+count--); | if(count==0) | break; | } | } | | private void removeProperties(Module module) { | Collection<ModuleProperty>properties = module.getProperties(); | Collection<ModuleProperty>new_props = new HashSet<ModuleProperty>(); | for(ModuleProperty p : properties){ | if(p.getValue().startsWith("UPDATED")) | new_props.add(p); | } | module.setProperties(new_props); | } | | private void addProperties(Module module) { | // TODO Auto-generated method stub | Collection<ModuleProperty>properties = module.getProperties(); | if(properties == null){ | properties = new HashSet<ModuleProperty>(); | } | int count = (int)(Math.random()*100); | Logger.global.info("Adding "+count+" properties to module: "+module.getModuleID()); | for(int i=0;i<count;i++){ | ModuleProperty p = new ModuleProperty(); | p.setId(new ModulePropertyPK()); | p.getId().setName("PROP"+i); | p.setValue("VAL"+i); | properties.add(p); | } | module.setProperties(properties); | } | | @Override | protected void setUp() throws Exception { | // TODO Auto-generated method stub | super.setUp(); | Properties jndiProperties = new Properties(); | jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, | "org.jnp.interfaces.NamingContextFactory"); | jndiProperties.put(Context.URL_PKG_PREFIXES, | "org.jboss.naming:org.jnp.interfaces"); | jndiProperties.put(Context.PROVIDER_URL, "localhost:1099"); | context = new InitialContext(jndiProperties); | ModuleManager manager = (ModuleManager) context | .lookup("cortest/ModuleManagerBean/remote"); | for(int i=0;i<10;i++) | manager.addModule(new Module()); | } | | @Override | protected void tearDown() throws Exception { | // TODO Auto-generated method stub | super.tearDown(); | } | | } | View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3946125#3946125 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3946125 ------------------------------------------------------- All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in the hosting industry. Fanatical Support. Click to learn more http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user