From: <id...@us...> - 2009-04-20 15:03:18
|
Revision: 126 http://cse-ip.svn.sourceforge.net/cse-ip/?rev=126&view=rev Author: idueppe Date: 2009-04-20 15:03:04 +0000 (Mon, 20 Apr 2009) Log Message: ----------- fixed tests Modified Paths: -------------- trunk/sandbox/cse-ip/framework/test-utilities/src/main/java/de/campussource/cse/common/test/AbstractPersistentUnitTest.java trunk/sandbox/cse-ip/pom.xml trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/Constants.java trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/DataModelManager.java trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/DataModelManagerBean.java trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Category.java trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Entity.java trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Role.java trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/CategoryDaoTest.java trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/CourseDaoTest.java trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/RoleDaoTest.java trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/TestXmlConversion.java trunk/sandbox/cse-ip/sc-cdmm/src/test/resources/META-INF/persistence.xml Added Paths: ----------- trunk/sandbox/cse-ip/build.xml Added: trunk/sandbox/cse-ip/build.xml =================================================================== --- trunk/sandbox/cse-ip/build.xml (rev 0) +++ trunk/sandbox/cse-ip/build.xml 2009-04-20 15:03:04 UTC (rev 126) @@ -0,0 +1,83 @@ +<project name="cse-ip" default="install" basedir="."> + + <condition property="maven.executable" value="mvn.bat" else="mvn"><os family="windows" /></condition> + <condition property="asadmin.executable" value="asadmin.bat" else="asadmin"><os family="windows"/></condition> + + <property environment="env"/> + + <property name="appname" value="solution.01.application"/> + <property name="asadmin" location="${env.GLASSFISH_HOME}/bin/${asadmin.executable}" /> + <property name="earfile" location="${basedir}/target/${appname}.ear"/> + + <property name="admin.host" value="localhost"/> + <property name="admin.port" value="4848" /> + <property name="admin.user" value="admin" /> + <property name="admin.pwfile" location="password.txt" /> + + <target name="init"> + </target> + + <target name="install" description="maven install"> + <exec executable="${maven.executable}"> + <arg line="install"/> + </exec> + </target> + + <target name="clean" description="maven clean"> + <exec executable="${maven.executable}"> + <arg line="clean"/> + </exec> + </target> + + <target name="eclipse" description="eclipse"> + <exec executable="${maven.executable}"> + <arg line="eclipse:clean eclipse:eclipse"/> + </exec> + </target> + + <target name="glassfish-start" description=""> + <exec executable="${asadmin}" failonerror="false"> + <arg line="start-domain domain1"/> + </exec> + </target> + + <target name="glassfish-stop" description=""> + <exec executable="${asadmin}" failonerror="false"> + <arg line="stop-domain domain1"/> + </exec> + </target> + + <target name="site" description="generate and deploy the project site"> + <exec executable="${maven.executable}"> + <arg line="install"/> + </exec> + </target> + + <!-- + + <target name="glassfish-deploy" depends="init, clean, install" description=""> + <exec executable="${asadmin}" failonerror="false"> + <arg line="deploy" /> + <arg line="--user ${admin.user}" /> + <arg line="--passwordfile ${admin.pwfile}" /> + <arg line="--host ${admin.host}" /> + <arg line="--port ${admin.port}" /> + <arg line="--upload=true" /> + <arg line="${earfile}" /> + </exec> + </target> + + <target name="glassfish-undeploy" depends="" description=""> + <exec executable="${asadmin}" failonerror="false"> + <arg line="undeploy" /> + <arg line="--user ${admin.user}" /> + <arg line="--passwordfile ${admin.pwfile}" /> + <arg line="--host ${admin.host}" /> + <arg line="--port ${admin.port}" /> + <arg line="${appname}" /> + </exec> + </target> + --> + + +</project> Property changes on: trunk/sandbox/cse-ip/build.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/sandbox/cse-ip/framework/test-utilities/src/main/java/de/campussource/cse/common/test/AbstractPersistentUnitTest.java =================================================================== --- trunk/sandbox/cse-ip/framework/test-utilities/src/main/java/de/campussource/cse/common/test/AbstractPersistentUnitTest.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/framework/test-utilities/src/main/java/de/campussource/cse/common/test/AbstractPersistentUnitTest.java 2009-04-20 15:03:04 UTC (rev 126) @@ -20,7 +20,8 @@ @BeforeClass public static void retrieveEntityManagerFactory() { - entityManagerFactory = Persistence.createEntityManagerFactory("cseip-test"); + if (entityManagerFactory == null) + entityManagerFactory = Persistence.createEntityManagerFactory("cseip-test"); } @Before Modified: trunk/sandbox/cse-ip/pom.xml =================================================================== --- trunk/sandbox/cse-ip/pom.xml 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/pom.xml 2009-04-20 15:03:04 UTC (rev 126) @@ -79,6 +79,11 @@ <url>http://www.gnu.org/copyleft/gpl.html</url> </license> </licenses> + + <issueManagement> + <url>https://apps.sourceforge.net/trac/cse-ip/</url> + <system>Trac</system> + </issueManagement> <scm> <connection>scm:svn:https://cse-ip.svn.sourceforge.net/svnroot/cse-ip/trunk</connection> Modified: trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/Constants.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/Constants.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/Constants.java 2009-04-20 15:03:04 UTC (rev 126) @@ -48,6 +48,7 @@ public static final String PROPERTY_NAME = "name"; public static final String PROPERTY_VALUE = "value"; public static final String PROPERTY_TRANSIENT = "transient"; + public static final String PROPERTY_STATE = "state"; //table names public static final String TABLENAME_ACCOUNT = "CDMM_ACCOUNT"; Modified: trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/DataModelManager.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/DataModelManager.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/DataModelManager.java 2009-04-20 15:03:04 UTC (rev 126) @@ -2,14 +2,11 @@ import java.util.List; -import javax.ejb.Remote; - /** * Service bean for CDMM package * @author Sebastian Roekens * */ -@Remote public interface DataModelManager { public List<EventMessage> createOrUpdateCourse(CourseMessage courseMessage); Modified: trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/DataModelManagerBean.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/DataModelManagerBean.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/DataModelManagerBean.java 2009-04-20 15:03:04 UTC (rev 126) @@ -5,6 +5,7 @@ import java.util.List; import javax.ejb.EJB; +import javax.ejb.Remote; import javax.ejb.Stateless; import de.campussource.cse.cdmm.dao.*; @@ -19,6 +20,7 @@ * */ @Stateless +@Remote(value=DataModelManager.class) public class DataModelManagerBean implements DataModelManager { @EJB Modified: trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Category.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Category.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Category.java 2009-04-20 15:03:04 UTC (rev 126) @@ -23,83 +23,91 @@ /** * Category entity object + * * @author Sebastian Roekens - * + * */ -@Entity(name=Constants.CATEGORY) -@Inheritance(strategy=InheritanceType.JOINED) +@Entity(name = Constants.CATEGORY) +@Inheritance(strategy = InheritanceType.JOINED) @Table(name = Constants.TABLENAME_CATEGORY) -@XmlRootElement(namespace=Constants.NAMESPACE_DATATYPES) -@XmlType(name=Constants.CATEGORY_TYPE, propOrder={Constants.PROPERTY_PARENT, Constants.PROPERTY_CHILDREN, Constants.PROPERTY_COURSES}, namespace=Constants.NAMESPACE_DATATYPES) +@XmlRootElement(namespace = Constants.NAMESPACE_DATATYPES) +@XmlType(name = Constants.CATEGORY_TYPE, propOrder = { Constants.PROPERTY_PARENT, Constants.PROPERTY_CHILDREN, + Constants.PROPERTY_COURSES }, namespace = Constants.NAMESPACE_DATATYPES) public class Category extends de.campussource.cse.cdmm.domain.Entity { - @ManyToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) + @ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }) @JoinTable(name = Constants.COLUMNNAME_CATEGORY2CATEGORY) private Category parent; - - @OneToMany(mappedBy=Constants.PARENT, cascade={CascadeType.REMOVE}) + + @OneToMany(mappedBy = Constants.PARENT, cascade = { CascadeType.REMOVE }) private List<Category> children; - - @ManyToMany(mappedBy=Constants.CATEGORIES) + + @ManyToMany(mappedBy = Constants.CATEGORIES) private List<Course> courses; - + public Category() { } - - public Category(Long id){ + + public Category(Long id) { setId(id); } - + /** * Convenience method for dependency check to prevent circular dependencies. * True if circular dependency would be created. * - * @param newChildCategory new child category to be added to this - * @return true, if newChildCategory is present in hierarchy above this, else false + * @param newChildCategory + * new child category to be added to this + * @return true, if newChildCategory is present in hierarchy above this, + * else false */ - private boolean checkForCircularDependencies(Category newChildCategory){ - if (this.equals(newChildCategory)){ + private boolean checkForCircularDependencies(Category newChildCategory) { + if (this.getId() != null && this.equals(newChildCategory)) { return true; } - if (this.isRoot()){ + if (this.getId() == null && this != newChildCategory) { return false; } + if (this.isRoot()) { + return false; + } return this.parent.checkForCircularDependencies(newChildCategory); } - + /** - * Private method for adding category to list of children. - * If list of children does not exist, it is created. + * Private method for adding category to list of children. If list of + * children does not exist, it is created. * - * @param category child category + * @param category + * child category * @return success of operation */ - private boolean addChild(Category category){ - if (this.children == null){ + private boolean addChild(Category category) { + if (this.children == null) { this.children = new ArrayList<Category>(); } - if (checkForCircularDependencies(category)){ + if (checkForCircularDependencies(category)) { return false; } return this.children.add(category); } - + /** * Convenience method for parent <-> children connection of categories. - * Parent of this is set to parent category and list of children of parent category - * is updated with this. - * - * @param parent parent category + * Parent of this is set to parent category and list of children of parent + * category is updated with this. + * + * @param parent + * parent category * @return Success of operation */ - public boolean addToParentCategory(Category parent){ + public boolean addToParentCategory(Category parent) { this.parent = parent; return parent.addChild(this); } - - - @XmlElementWrapper(name=Constants.CATEGORIES) - @XmlElement(name=Constants.CATEGORY) + + @XmlElementWrapper(name = Constants.CATEGORIES) + @XmlElement(name = Constants.CATEGORY) public List<Category> getChildren() { return children; } @@ -108,8 +116,8 @@ this.children = children; } - @XmlElementWrapper(name=Constants.COURSES) - @XmlElement(name=Constants.COURSE) + @XmlElementWrapper(name = Constants.COURSES) + @XmlElement(name = Constants.COURSE) @XmlIDREF public List<Course> getCourses() { return courses; @@ -119,7 +127,7 @@ this.courses = courses; } - @XmlElement(name=Constants.PARENT) + @XmlElement(name = Constants.PARENT) @XmlIDREF public Category getParent() { return parent; @@ -128,16 +136,15 @@ public void setParent(Category parent) { this.parent = parent; } - - + /** * Convenience method for checking if category is root category. * * @return true if category is root category, else returning false */ @XmlTransient - public boolean isRoot(){ - return (parent==null); + public boolean isRoot() { + return (parent == null); } } Modified: trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Entity.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Entity.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Entity.java 2009-04-20 15:03:04 UTC (rev 126) @@ -2,6 +2,7 @@ import java.util.ArrayList; +import java.util.Date; import java.util.List; import javax.persistence.Column; @@ -13,11 +14,15 @@ import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.persistence.Transient; +import javax.persistence.Version; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; @@ -36,7 +41,7 @@ @Table(name = Constants.TABLENAME_ENTITY) @Inheritance(strategy=InheritanceType.JOINED) @XmlRootElement(namespace=Constants.NAMESPACE_DATATYPES) -@XmlType(name=Constants.ENTITY_TYPE,propOrder={"id", Constants.PROPERTY_ATTRIBUTES}, namespace=Constants.NAMESPACE_DATATYPES) +@XmlType(name=Constants.ENTITY_TYPE,propOrder={"id", Constants.PROPERTY_STATE, Constants.PROPERTY_ATTRIBUTES}, namespace=Constants.NAMESPACE_DATATYPES) public class Entity{ @Id @@ -47,51 +52,38 @@ private List<Attribute> attributes; @Column(name=Constants.COLUMNNAME_STATE, nullable=false, insertable=true, updatable=true) - @Enumerated(EnumType.ORDINAL) - private State state; + @Enumerated(EnumType.STRING) + private State state = State.EXISTS; - public State getState() { - return state; - } - - public void setState(State state) { - this.state = state; - } - + @Version + private long version; + + @Column(name="LAST_UPDATE") + @Temporal(TemporalType.TIMESTAMP) + private Date date; + public Entity(){ } public Entity(Long id){ this.id = id; } + + private TransientAttribute attribute2TransientAttribute(Attribute attribute){ + return new TransientAttribute(attribute.getName(), attribute.getValue()); + } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof Entity)) { - return false; - } - if (this.id == null) { - return false; - } else { - return this.id.equals(((Entity) obj).id); - } + private PersistentAttribute attribute2PersistentAttribute(Attribute attribute){ + return new PersistentAttribute(attribute.getName(), attribute.getValue()); } - - @Override - public int hashCode() { - if (this.id == null) { - return super.hashCode(); - } else { - return this.id.hashCode(); - } + + public State getState() { + return state; } - @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(id).toString(); + @XmlElement(name=Constants.PROPERTY_STATE) + public void setState(State state) { + this.state = state; } public void setId(Long id) { @@ -111,14 +103,7 @@ return attributes; } - private TransientAttribute attribute2TransientAttribute(Attribute attribute){ - return new TransientAttribute(attribute.getName(), attribute.getValue()); - } - - private PersistentAttribute attribute2PersistentAttribute(Attribute attribute){ - return new PersistentAttribute(attribute.getName(), attribute.getValue()); - } - + // TODO Check if this is correct public void setAttributes(List<Attribute> attributes) { List<Attribute> newAttributeList = new ArrayList<Attribute>(); for (Attribute att : attributes){ @@ -130,4 +115,47 @@ } this.attributes = newAttributeList; } + + + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(id).toString(); + } + + public Date getDate() { + return date; + } + + @XmlTransient + public void setDate(Date date) { + this.date = date; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Entity other = (Entity) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + } \ No newline at end of file Modified: trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Role.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Role.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Role.java 2009-04-20 15:03:04 UTC (rev 126) @@ -24,55 +24,56 @@ /** * Role entity object + * * @author Sebastian Roekens - * + * */ -@Entity(name=Constants.ROLE) +@Entity(name = Constants.ROLE) @Table(name = Constants.TABLENAME_ROLE) -@Inheritance(strategy=InheritanceType.JOINED) -@NamedQueries(value = { - @NamedQuery( - name = "Role.findByAccountAndCourse", - query = "select r from role r where r.account.id=:accountId and r.course.id = :courseId")}) -@XmlRootElement(namespace=Constants.NAMESPACE_DATATYPES) -@XmlType(name=Constants.ROLE_TYPE, propOrder={Constants.TYPE, Constants.ACCOUNT, Constants.COURSE}, namespace=Constants.NAMESPACE_DATATYPES) -public class Role extends de.campussource.cse.cdmm.domain.Entity{ - - @Column(name=Constants.COLUMNNAME_ROLE_TYPE, nullable=false, insertable=true, updatable=true) +@Inheritance(strategy = InheritanceType.JOINED) +@NamedQueries(value = { @NamedQuery(name = "Role.findByAccountAndCourse", query = "select r from role r where r.account.id=:accountId and r.course.id = :courseId") }) +@XmlRootElement(namespace = Constants.NAMESPACE_DATATYPES) +@XmlType(name = Constants.ROLE_TYPE, propOrder = { Constants.TYPE, Constants.ACCOUNT, Constants.COURSE }, namespace = Constants.NAMESPACE_DATATYPES) +public class Role extends de.campussource.cse.cdmm.domain.Entity { + + @Column(name = Constants.COLUMNNAME_ROLE_TYPE, nullable = false, insertable = true, updatable = true) @Enumerated(EnumType.ORDINAL) private RoleType type; - - @ManyToOne(optional=false, cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) - @JoinColumn(name=Constants.COLUMNNAME_ACCOUNT_ID, nullable=false) + + @ManyToOne(optional = false, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }) + @JoinColumn(name = Constants.COLUMNNAME_ACCOUNT_ID, nullable = false) private Account account; - - @ManyToOne(optional=false, cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) - @JoinColumn(name=Constants.COLUMNNAME_COURSE_ID, nullable=false) + + @ManyToOne(optional = false, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }) + @JoinColumn(name = Constants.COLUMNNAME_COURSE_ID, nullable = false) private Course course; - + public static final String FIND_BY_ACCOUNT_AND_COURSE = "Role.findByAccountAndCourse"; - - public Role(){ + + public Role() { } - + /** - * Convenience method to add role to a course and an account. - * Role is added to roles list of course and account object, and - * course and account are added to role object - * @param course target course role is associated to - * @param account target account role is associated to + * Convenience method to add role to a course and an account. Role is added + * to roles list of course and account object, and course and account are + * added to role object + * + * @param course + * target course role is associated to + * @param account + * target account role is associated to * @return success of operation */ - public boolean addToCourseAndAccount(Course course, Account account){ - if ((course==null)||(account==null)){ + public boolean addToCourseAndAccount(Course course, Account account) { + if ((course == null) || (account == null)) { return false; } List<Role> courseRoles = course.getRoles(); - if (courseRoles==null){ + if (courseRoles == null) { courseRoles = new ArrayList<Role>(); } List<Role> accountRoles = account.getRoles(); - if (accountRoles==null){ + if (accountRoles == null) { accountRoles = new ArrayList<Role>(); } this.setAccount(account); @@ -83,17 +84,17 @@ course.setRoles(courseRoles); return true; } - - public Role(Long id, RoleType type){ + + public Role(Long id, RoleType type) { setId(id); this.type = type; } - + public Role(Long id) { setId(id); } - @XmlElement(name=Constants.TYPE) + @XmlElement(name = Constants.TYPE) public RoleType getType() { return type; } @@ -102,7 +103,7 @@ this.type = type; } - @XmlElement(name=Constants.ACCOUNT_ID, required=true) + @XmlElement(name = Constants.ACCOUNT_ID, required = true) @XmlIDREF public Account getAccount() { return account; @@ -112,7 +113,7 @@ this.account = account; } - @XmlElement(name=Constants.COURSE_ID, required=true) + @XmlElement(name = Constants.COURSE_ID, required = true) @XmlIDREF public Course getCourse() { return course; Modified: trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/CategoryDaoTest.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/CategoryDaoTest.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/CategoryDaoTest.java 2009-04-20 15:03:04 UTC (rev 126) @@ -15,15 +15,15 @@ import de.campussource.cse.cdmm.domain.Category; import de.campussource.cse.common.test.AbstractPersistentUnitTest; +public class CategoryDaoTest extends AbstractPersistentUnitTest { -public class CategoryDaoTest extends AbstractPersistentUnitTest{ - private CategoryDao dao; private Category category; private Category parentCategory; /** - * Creates a category object, a parent object for this category and the category dao. + * Creates a category object, a parent object for this category and the + * category dao. */ @Before public void setUp() { @@ -33,47 +33,46 @@ autowireByType(dao); txBegin(); } - + @After - public void tearDown(){ + public void tearDown() { txCommit(); } - -//FIXME fix broken tests -// /** -// * Checks if category can be persisted -// */ -// @Test -// public void testPersistCategory() { -// try { -// dao.persist(category); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException on creation of category"); -// } -// assertNotNull(category.getId()); -// } -// -// -// /** -// * Checks if category can be found by id -// */ -// @Test -// public void testFindCategory() { -// try { -// dao.persist(category); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException on creation of category"); -// } assertNotNull(category.getId()); -// Category coid = null; -// try { -// coid = dao.find(category.getId()); -// } catch (DataModelManagerException e) { -// fail("Created category could not be retrieved"); -// } -// assertEquals(category, coid); -// } - + /** + * Checks if category can be persisted + */ + @Test + public void testPersistCategory() { + try { + dao.persist(category); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException on creation of category"); + } + assertNotNull(category.getId()); + } + + /** + * Checks if category can be found by id + */ + @Test + public void testFindCategory() { + try { + dao.persist(category); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException on creation of category"); + } + assertNotNull(category.getId()); + Category coid = null; + try { + coid = dao.find(category.getId()); + } catch (DataModelManagerException e) { + fail("Created category could not be retrieved"); + } + assertEquals(category, coid); + } + + /** * Checks if category can be deleted */ @Test @@ -82,7 +81,8 @@ dao.persist(category); } catch (DataModelManagerException e) { fail("Unexpected DataModelManagerException on creation of category"); - } assertNotNull(category.getId()); + } + assertNotNull(category.getId()); try { dao.remove(category); } catch (DataModelManagerException e) { @@ -94,20 +94,21 @@ fail("Deleting of category failed"); } catch (DataModelManagerException e) { // Exception should occur - } + } } - + /** * Checks if cascading saving and cascading deleting work */ @Test - public void testCascading(){ + public void testCascading() { category.addToParentCategory(parentCategory); try { dao.persist(category); } catch (DataModelManagerException e) { fail("Unexpected DataModelManagerException on creation of category"); - } assertNotNull(category.getId()); + } + assertNotNull(category.getId()); assertNotNull(parentCategory.getId()); assertEquals(category.getParent(), parentCategory); assertEquals(parentCategory.getChildren().get(0), category); @@ -122,16 +123,16 @@ fail("Deleting of parent category failed"); } catch (DataModelManagerException e) { // Exception should occur - } + } try { @SuppressWarnings("unused") Category retrievedCategory = dao.find(category.getId()); fail("Cascaded deleting of child category failed"); } catch (DataModelManagerException e) { - // Exception should occur - } + // Exception should occur + } } - + /** * Checks if searching for not existing ids returns null */ @@ -146,24 +147,23 @@ } assertNull(foundCategory); } -//FIXME fix broken tests -// /** -// * Checks if circular category dependencies are prevented -// */ -// @Test -// public void testCircularDependencyCheck(){ -// assertTrue(category.addToParentCategory(parentCategory)); -// try { -// dao.persist(category); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException on creation of category"); -// } -// assertFalse(parentCategory.addToParentCategory(category)); -// } -// -// + + /** + * Checks if circular category dependencies are prevented + */ + @Test + public void testCircularDependencyCheck() { + assertTrue(category.addToParentCategory(parentCategory)); + try { + dao.persist(category); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException on creation of category"); + } + assertFalse(parentCategory.addToParentCategory(category)); + } + private Category newCategory() { - return new Category(); + return new Category(); } } Modified: trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/CourseDaoTest.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/CourseDaoTest.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/CourseDaoTest.java 2009-04-20 15:03:04 UTC (rev 126) @@ -17,7 +17,7 @@ import de.campussource.cse.common.test.AbstractPersistentUnitTest; public class CourseDaoTest extends AbstractPersistentUnitTest { - + private CourseDao dao; private Course course; @@ -31,47 +31,48 @@ autowireByType(dao); txBegin(); } - + @After - public void tearDown(){ + public void tearDown() { txCommit(); } -//FIXME fix broken tests -// /** -// * Tests creating of a course object -// */ -// @Test -// public void testPersistCourse() { -// try { -// dao.persist(course); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException!"); -// } -// assertNotNull(course.getId()); -// } -// -// -// /** -// * Tests searching for a course object by id -// */ -// @Test -// public void testFindCourse() { -// try { -// dao.persist(course); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException!"); -// } -// assertNotNull(course.getId()); -// commitAndBeginTx(); -// Course coid = null; -// try { -// coid = dao.find(course.getId()); -// } catch (DataModelManagerException e) { -// fail("Creating or retrieving of course failed!"); -// } -// assertEquals(course, coid); -// } + + /** + * Tests creating of a course object + */ + @Test + public void testPersistCourse() { + try { + dao.persist(course); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException!"); + } + assertNotNull(course.getId()); + } + + + /** + * Tests searching for a course object by id + */ + @Test + public void testFindCourse() { + try { + dao.persist(course); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException!"); + } + assertNotNull(course.getId()); + commitAndBeginTx(); + Course coid = null; + try { + coid = dao.find(course.getId()); + } catch (DataModelManagerException e) { + fail("Creating or retrieving of course failed!"); + } + assertEquals(course, coid); + } + /** * Tests deleting of course object */ @@ -94,9 +95,9 @@ fail("Deleting of course failed"); } catch (DataModelManagerException e) { // Exception should occur - } + } } - + /** * Tests if searching for not existing id returns null */ @@ -107,90 +108,89 @@ foundCourse = dao.find(0L); fail("Exception should occur"); } catch (DataModelManagerException e) { - //Exception should occur + // Exception should occur } assertNull(foundCourse); } - -//FIXME fix broken tests -// /** -// * Tests cascading to category objects. -// */ -// @Test -// public void testCascadingToCategory(){ -// Category category = new Category(); -// CategoryDao categoryDao = new CategoryDao(); -// autowireByType(categoryDao); -// try { -// categoryDao.persist(category); -// } catch (DataModelManagerException e1) { -// fail("Unexpected DataModelManagerException"); -// } -// assertNotNull(category.getId()); -// course.addToCategory(category); -// try { -// dao.persist(course); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException!"); -// } -// assertNotNull(course.getId()); -// assertNotNull(course.getCategories()); -// assertNotNull(category.getCourses()); -// assertEquals(course.getCategories().get(0), category); -// assertEquals(category.getCourses().get(0), course); -// } -// -// /** -// * Tests cascading in course hierarchy and correct course hierarchy -// */ -// @Test -// public void testWorkgroupCascading(){ -// //check correct cascading on creation of workgroup -// Course workgroup1 = new Course(); -// Course workgroup2 = new Course(); -// workgroup1.addAsWorkgroupTo(course); -// try { -// dao.persist(workgroup1); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException"); -// } -// assertNotNull(workgroup1.getId()); -// assertNotNull(course.getId()); -// assertNotNull(workgroup1.getParent()); -// assertEquals(workgroup1.getParent(), course); -// assertNotNull(course.getWorkgroups()); -// assertEquals(course.getWorkgroups().get(0), workgroup1); -// //check if circular dependency is prevented -// assertFalse(workgroup2.addAsWorkgroupTo(workgroup1)); -// //check correct deleting cascading -// try { -// dao.remove(course); -// } catch (DataModelManagerException e) { -// fail("Unexpected Exception on removing of course"); -// } -// try { -// @SuppressWarnings("unused") -// Course retrievedCourse = dao.find(course.getId()); -// fail("Deleting of course failed"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// try { -// @SuppressWarnings("unused") -// Course retrievedWorkgroup = dao.find(workgroup1.getId()); -// fail("Cascaded deleting of workgroup failed"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// } - - + + /** + * Tests cascading to category objects. + */ + @Test + public void testCascadingToCategory() { + Category category = new Category(); + CategoryDao categoryDao = new CategoryDao(); + autowireByType(categoryDao); + try { + categoryDao.persist(category); + } catch (DataModelManagerException e1) { + fail("Unexpected DataModelManagerException"); + } + assertNotNull(category.getId()); + course.addToCategory(category); + try { + dao.persist(course); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException!"); + } + assertNotNull(course.getId()); + assertNotNull(course.getCategories()); + assertNotNull(category.getCourses()); + assertEquals(course.getCategories().get(0), category); + assertEquals(category.getCourses().get(0), course); + } + /** + * Tests cascading in course hierarchy and correct course hierarchy + */ + @Test + public void testWorkgroupCascading() { + // check correct cascading on creation of workgroup + Course workgroup1 = new Course(); + Course workgroup2 = new Course(); + workgroup1.addAsWorkgroupTo(course); + try { + dao.persist(workgroup1); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException"); + } + assertNotNull(workgroup1.getId()); + assertNotNull(course.getId()); + assertNotNull(workgroup1.getParent()); + assertEquals(workgroup1.getParent(), course); + assertNotNull(course.getWorkgroups()); + assertEquals(course.getWorkgroups().get(0), workgroup1); + // check if circular dependency is prevented + assertFalse(workgroup2.addAsWorkgroupTo(workgroup1)); + // check correct deleting cascading + try { + dao.remove(course); + } catch (DataModelManagerException e) { + fail("Unexpected Exception on removing of course"); + } + try { + @SuppressWarnings("unused") + Course retrievedCourse = dao.find(course.getId()); + fail("Deleting of course failed"); + } catch (DataModelManagerException e) { + // Exception should occur + } + try { + @SuppressWarnings("unused") + Course retrievedWorkgroup = dao.find(workgroup1.getId()); + fail("Cascaded deleting of workgroup failed"); + } catch (DataModelManagerException e) { + // Exception should occur + } + } + + /** * Convenience method for creating a course object with a unique id + * * @return course object with unique id */ private Course newCourse() { - return new Course(); + return new Course(); } } Modified: trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/RoleDaoTest.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/RoleDaoTest.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/RoleDaoTest.java 2009-04-20 15:03:04 UTC (rev 126) @@ -15,6 +15,7 @@ import de.campussource.cse.cdmm.domain.Course; import de.campussource.cse.cdmm.domain.Role; import de.campussource.cse.cdmm.domain.RoleType; +import de.campussource.cse.cdmm.domain.State; import de.campussource.cse.common.test.AbstractPersistentUnitTest; public class RoleDaoTest extends AbstractPersistentUnitTest { @@ -25,292 +26,290 @@ private Account account; + @Before + public void setUp() { + //set up daos + dao = new RoleDao(); + autowireByType(dao); + //create role object with needed dependencies + course = new Course(); + account = new Account(); + role = newRole(); + txBegin(); + } + + @After + public void tearDown(){ + txCommit(); + } + + /** + * Tests if Role can be persisted + */ @Test - public void testNothing(){} + public void testPersistRole() { + try { + dao.persist(role); + } catch (MissingAttributeException e) { + e.printStackTrace(); + fail("Unexpected MissingAttributeException!"); + } + assertNotNull(role.getId()); + } + -// @Before -// public void setUp() { -// //set up daos -// dao = new RoleDao(); -// autowireByType(dao); -// //create role object with needed dependencies -// course = new Course(); -// account = new Account(); -// role = newRole(); -// txBegin(); -// } -// -// @After -// public void tearDown(){ -// txCommit(); -// } + /** + * Tests if role can be found by id + */ + @Test + public void testFindRole() { + try { + dao.persist(role); + } catch (MissingAttributeException e) { + fail("Unexpected MissingAttributeException!"); + } + assertNotNull(role.getId()); + Role roid = null; + try { + roid = dao.find(role.getId()); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException!"); + } + assertEquals(role, roid); + } -//FIXME fix broken tests -// /** -// * Tests if Role can be persisted -// */ -// @Test -// public void testPersistRole() { -// try { -// dao.persist(role); -// } catch (MissingAttributeException e) { -// fail("Unexpected MissingAttributeException!"); -// } -// assertNotNull(role.getId()); -// } -// -// -// /** -// * Tests if role can be found by id -// */ -// @Test -// public void testFindRole() { -// try { -// dao.persist(role); -// } catch (MissingAttributeException e) { -// fail("Unexpected MissingAttributeException!"); -// } -// assertNotNull(role.getId()); -// Role roid = null; -// try { -// roid = dao.find(role.getId()); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException!"); -// } -// assertEquals(role, roid); -// } -// -// /** -// * Tests if Role can be deleted -// */ -// @Test -// public void testRemoveRole() { -// try { -// dao.persist(role); -// } catch (MissingAttributeException e) { -// fail("Unexpected MissingAttributeException!"); -// } -// assertNotNull(role.getId()); -// try { -// dao.remove(role); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException!"); -// } -// try { -// @SuppressWarnings("unused") -// Role retrievedRole = dao.find(role.getId()); -// fail("Deleting failed"); -// } catch (DataModelManagerException e) { -// //Exception is correct -// } -// CourseDao courseDao = new CourseDao(); -// autowireByType(courseDao); -// try { -// Course retrievedCourse = courseDao.find(course.getId()); -// assertNotNull(retrievedCourse); -// } catch (DataModelManagerException e) { -// fail("Account should not be deleted!"); -// } -// } -// -// /** -// * Tests if search for not existing id returns null -// */ -// @Test -// public void testDoNotFindById() { -// @SuppressWarnings("unused") -// Role foundRole; -// try { -// foundRole = dao.find(0L); -// fail("DataModelManagerException should have been thrown, due to search for an not existing object!"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// } -// -// /** -// * Tests if create and update statements are correctly cascaded -// * to account and course entities -// */ -// @Test -// public void testCascadingOnCreate(){ -// try { -// dao.persist(role); -// } catch (MissingAttributeException e) { -// fail("Unexpected MissingAttributeException occured!"); -// } -// assertNotNull(role.getId()); -// assertNotNull(course.getId()); -// assertNotNull(account.getId()); -// assertNotNull(account.getRoles()); -// assertNotNull(course.getRoles()); -// assertEquals(course.getRoles().get(0), role); -// assertEquals(account.getRoles().get(0), role); -// assertEquals(role.getCourse(), course); -// assertEquals(role.getAccount(), account); -// } -// -// /** -// * Tests if role objects are deleted on deletion of parent course object -// */ -// @Test -// public void testCascadingOnDeleteCourse(){ -// try { -// dao.persist(role); -// } catch (MissingAttributeException e) { -// fail("Unexpected MissingAttributeException occured!"); -// } -// assertNotNull(role.getId()); -// assertNotNull(course.getId()); -// assertNotNull(account.getId()); -// assertNotNull(account.getRoles()); -// assertNotNull(course.getRoles()); -// assertEquals(course.getRoles().get(0), role); -// assertEquals(account.getRoles().get(0), role); -// assertEquals(role.getCourse(), course); -// assertEquals(role.getAccount(), account); -// -// commitAndBeginTx(); -// -// CourseDao courseDao = new CourseDao(); -// autowireByType(courseDao); -// try { -// courseDao.remove(course); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException occured!"); -// } -// try{ -// @SuppressWarnings("unused") -// Course retrievedCourse = courseDao.find(course.getId()); -// fail("Course deleting failed!"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// try { -// @SuppressWarnings("unused") -// Role retrievedRole = dao.find(role.getId()); -// fail("Cascaded Role deleting failed!"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// } -// -// @Test -// public void testCascadingOnDeleteAccount(){ -// try { -// dao.persist(role); -// } catch (MissingAttributeException e) { -// fail("Unexpected MissingAttributeException occured!"); -// } -// assertNotNull(role.getId()); -// assertNotNull(course.getId()); -// assertNotNull(account.getId()); -// assertNotNull(account.getRoles()); -// assertNotNull(course.getRoles()); -// assertEquals(course.getRoles().get(0), role); -// assertEquals(account.getRoles().get(0), role); -// assertEquals(role.getCourse(), course); -// assertEquals(role.getAccount(), account); -// -// commitAndBeginTx(); -// -// AccountDao accountDao = new AccountDao(); -// autowireByType(accountDao); -// try { -// accountDao.remove(account); -// } catch (DataModelManagerException e) { -// fail("Unexpected DataModelManagerException occured!"); -// } -// try { -// @SuppressWarnings("unused") -// Account retrievedAccount = accountDao.find(account.getId()); -// fail("Account deleting failed!"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// try { -// @SuppressWarnings("unused") -// Role retrievedRole = dao.find(role.getId()); -// fail("Cascaded role deleting failed"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// } -// -// @Test -// public void testRetrieveRole(){ -// Role role = new Role(); -// role.setType(RoleType.PARTICIPANT); -// Account account = new Account(); -// Course course = new Course(); -// -// try { -// dao.persist(role); -// fail("It should not be able to persist role without course and account reference"); -// } catch (MissingAttributeException e) { -// //Exception should occur; -// } -// role.setCourse(course); -// try { -// dao.persist(role); -// fail("It should not be able to persist role without course and account reference"); -// } catch (MissingAttributeException e) { -// //Exception should occur; -// } -// role.setCourse(null); -// role.setAccount(account); -// try { -// dao.persist(role); -// fail("It should not be able to persist role without course and account reference"); -// } catch (MissingAttributeException e) { -// //Exception should occur; -// } -// role.setCourse(course); -// try { -// dao.persist(role); -// } catch (MissingAttributeException e) { -// fail("Unexpected Missing Attribute Exception"); -// } -// Role retrievedRole = null; -// try { -// retrievedRole = dao.retrieveRole(0, course.getId()); -// fail("Retrieved object should not exist"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// try { -// retrievedRole = dao.retrieveRole(account.getId(),0); -// fail("Retrieved object should not exist"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// try { -// retrievedRole = dao.retrieveRole(1l, 1l); -// fail("Retrieved object should not exist"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// try { -// retrievedRole = dao.retrieveRole(account.getId(), course.getId()); -// } catch (DataModelManagerException e) { -// fail("Retrieved object should exist"); -// } -// assertNotNull(retrievedRole); -// assertEquals(role, retrievedRole); -// -// try { -// dao.remove(null); -// fail("null can't be removed"); -// } catch (DataModelManagerException e) { -// //Exception should occur -// } -// -// } + /** + * Tests if Role can be deleted + */ + @Test + public void testRemoveRole() { + try { + dao.persist(role); + } catch (MissingAttributeException e) { + fail("Unexpected MissingAttributeException!"); + } + assertNotNull(role.getId()); + try { + dao.remove(role); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException!"); + } + try { + @SuppressWarnings("unused") + Role retrievedRole = dao.find(role.getId()); + fail("Deleting failed"); + } catch (DataModelManagerException e) { + //Exception is correct + } + CourseDao courseDao = new CourseDao(); + autowireByType(courseDao); + try { + Course retrievedCourse = courseDao.find(course.getId()); + assertNotNull(retrievedCourse); + } catch (DataModelManagerException e) { + fail("Account should not be deleted!"); + } + } + /** + * Tests if search for not existing id returns null + */ + @Test + public void testDoNotFindById() { + @SuppressWarnings("unused") + Role foundRole; + try { + foundRole = dao.find(0L); + fail("DataModelManagerException should have been thrown, due to search for an not existing object!"); + } catch (DataModelManagerException e) { + //Exception should occur + } + } + + /** + * Tests if create and update statements are correctly cascaded + * to account and course entities + */ + @Test + public void testCascadingOnCreate(){ + try { + dao.persist(role); + } catch (MissingAttributeException e) { + fail("Unexpected MissingAttributeException occured!"); + } + assertNotNull(role.getId()); + assertNotNull(course.getId()); + assertNotNull(account.getId()); + assertNotNull(account.getRoles()); + assertNotNull(course.getRoles()); + assertEquals(course.getRoles().get(0), role); + assertEquals(account.getRoles().get(0), role); + assertEquals(role.getCourse(), course); + assertEquals(role.getAccount(), account); + } + + /** + * Tests if role objects are deleted on deletion of parent course object + */ + @Test + public void testCascadingOnDeleteCourse(){ + try { + dao.persist(role); + } catch (MissingAttributeException e) { + fail("Unexpected MissingAttributeException occured!"); + } + assertNotNull(role.getId()); + assertNotNull(course.getId()); + assertNotNull(account.getId()); + assertNotNull(account.getRoles()); + assertNotNull(course.getRoles()); + assertEquals(course.getRoles().get(0), role); + assertEquals(account.getRoles().get(0), role); + assertEquals(role.getCourse(), course); + assertEquals(role.getAccount(), account); + + commitAndBeginTx(); + + CourseDao courseDao = new CourseDao(); + autowireByType(courseDao); + try { + courseDao.remove(course); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException occured!"); + } + try{ + @SuppressWarnings("unused") + Course retrievedCourse = courseDao.find(course.getId()); + fail("Course deleting failed!"); + } catch (DataModelManagerException e) { + //Exception should occur + } + try { + @SuppressWarnings("unused") + Role retrievedRole = dao.find(role.getId()); + fail("Cascaded Role deleting failed!"); + } catch (DataModelManagerException e) { + //Exception should occur + } + } + + @Test + public void testCascadingOnDeleteAccount(){ + try { + dao.persist(role); + } catch (MissingAttributeException e) { + fail("Unexpected MissingAttributeException occured!"); + } + assertNotNull(role.getId()); + assertNotNull(course.getId()); + assertNotNull(account.getId()); + assertNotNull(account.getRoles()); + assertNotNull(course.getRoles()); + assertEquals(course.getRoles().get(0), role); + assertEquals(account.getRoles().get(0), role); + assertEquals(role.getCourse(), course); + assertEquals(role.getAccount(), account); + + commitAndBeginTx(); + + AccountDao accountDao = new AccountDao(); + autowireByType(accountDao); + try { + accountDao.remove(account); + } catch (DataModelManagerException e) { + fail("Unexpected DataModelManagerException occured!"); + } + try { + @SuppressWarnings("unused") + Account retrievedAccount = accountDao.find(account.getId()); + fail("Account deleting failed!"); + } catch (DataModelManagerException e) { + //Exception should occur + } + try { + @SuppressWarnings("unused") + Role retrievedRole = dao.find(role.getId()); + fail("Cascaded role deleting failed"); + } catch (DataModelManagerException e) { + //Exception should occur + } + } + + @Test + public void testRetrieveRole(){ + Role role = new Role(); + role.setType(RoleType.PARTICIPANT); + Account account = new Account(); + Course course = new Course(); + + try { + dao.persist(role); + fail("It should not be able to persist role without course and account reference"); + } catch (MissingAttributeException e) { + //Exception should occur; + } + role.setCourse(course); + try { + dao.persist(role); + fail("It should not be able to persist role without course and account reference"); + } catch (MissingAttributeException e) { + //Exception should occur; + } + role.setCourse(null); + role.setAccount(account); + try { + dao.persist(role); + fail("It should not be able to persist role without course and account reference"); + } catch (MissingAttributeException e) { + //Exception should occur; + } + role.setCourse(course); + try { + dao.persist(role); + } catch (MissingAttributeException e) { + fail("Unexpected Missing Attribute Exception"); + } + Role retrievedRole = null; + try { + retrievedRole = dao.retrieveRole(0, course.getId()); + fail("Retrieved object should not exist"); + } catch (DataModelManagerException e) { + //Exception should occur + } + try { + retrievedRole = dao.retrieveRole(account.getId(),0); + fail("Retrieved object should not exist"); + } catch (DataModelManagerException e) { + //Exception should occur + } + try { + retrievedRole = dao.retrieveRole(1l, 1l); + fail("Retrieved object should not exist"); + } catch (DataModelManagerException e) { + //Exception should occur + } + try { + retrievedRole = dao.retrieveRole(account.getId(), course.getId()); + } catch (DataModelManagerException e) { + fail("Retrieved object should exist"); + } + assertNotNull(retrievedRole); + assertEquals(role, retrievedRole); + + try { + dao.remove(null); + fail("null can't be removed"); + } catch (DataModelManagerException e) { + //Exception should occur + } + + } + private Role newRole() { Role role = new Role(); role.addToCourseAndAccount(course, account); role.setType(RoleType.ASSISTANT); + role.setState(State.EXISTS); return role; } } Modified: trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/TestXmlConversion.java =================================================================== --- trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/TestXmlConversion.java 2009-04-20 11:28:57 UTC (rev 125) +++ trunk/sandbox/cse-ip/sc-cdmm/src/test/java/de/campussource/cse/cdmm/TestXmlConversion.java 2009-04-20 15:03:04 UTC (rev 126) @@ -33,468 +33,458 @@ import de.campussource.cse.cdmm.domain.Role; import de.campussource.cse.cdmm.domain.RoleType; import de.campussource.cse.cdmm.domain.TransientAttribute; - + /** * @author Sebastian Roekens - * + * */ -public class TestXmlConversion extends TestCase{ +public class TestXmlConversion extends TestCase { + private static Long currentTimeMillis = System.currentTimeMillis(); - private Long createUniqueId(){ + private Long createUniqueId() { return currentTimeMillis++; } - + @Test - public void testNothing(){ + public void testAccountXml() { + System.out.println("----- entering Account XML Test -----"); + // create and fetch account object + EntityContainer container = generateTestStructure(); + Account account = null; + for (Account acc : container.getAccounts()) { + if (acc instanceof Account && !(acc instanceof Group)) { + account = acc; + } + } + if (account == null) { + fail("no account object created"); + } + + // create jaxb context and marshaller + Marshaller marshaller = null; + JAXBContext context = null; + try { + context = JAXBContext.newInstance(Account.class); + marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + // convert account object to xml + String outputXml = ""; + try { + Writer writer = new StringWriter(); + marshaller.marshal(account, writer); + outputXml = writer.toString(); + writer.close(); + } catch (JAXBException e) { + fail(e.getMessage()); + } catch (IOException e) { + fail(e.getMessage()); + } + assertTrue((outputXml != null) && (!outputXml.trim().isEmpty())); + System.out.println(outputXml); + + // convert xml back to an object and assert equality to source object + Account convertedAccount = null; + try { + Unmarshaller unmarshaller = context.createUnmarshaller(); + convertedAccount = (Account) unmarshaller.unmarshal(new StringReader(outputXml)); + System.out.println(convertedAccount.toString()); + } catch (JAXBException e) { + fail(e.getMessage()); + } + assertTrue(account.equals(convertedAccount)); + System.out.println("----- leaving Account XML Test -----"); } - -//FIXME fix broken tests -// @Test -// public void testAccountXml(){ -// System.out.println("----- entering Account XML Test -----"); -// //create and fetch account object -// EntityContainer container = generateTestStructure(); -// Account account = null; -// for (Account acc : container.getAccounts()){ -// if (acc instanceof Account && !(acc instanceof Group)){ -// account = acc; -// } -// } -// if (account == null){ -// fail("no account object created"); -// } -// -// //create jaxb context and marshaller -// Marshaller marshaller=null; -// JAXBContext context=null; -// try { -// context = JAXBContext.newInstance(Account.class); -// marshaller = context.createMarshaller(); -// marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); -// } catch (JAXBException e) { -// e.printStackTrace(); -// fail(e.getMessage()); -// } -// -// //convert account object to xml -// String outputXml = ""; -// try { -// Writer writer = new StringWriter(); -// marshaller.marshal(account, writer); -// outputXml = writer.toString(); -// writer.close(); -// } catch (JAXBException e) { -// fail(e.getMessage()); -// } catch (IOException e) { -// fail(e.getMessage()); -// } -// assertTrue((outputXml!=null)&&(outputXml!="")); -// System.out.println(outputXml); -// -// //convert xml back to an object and assert equality to source object -// Account convertedAccount=null; -// try { -// Unmarshaller unmarshaller = context.createUnmarshaller(); -// convertedAccount = (Account) unmarshaller.unmarshal(new StringReader(outputXml)); -// System.out.println(convertedAccount.toString()); -// } catch (JAXBException e) { -// fail(e.getMessage()); -// } -// assertTrue(account.equals(convertedAccount)); -// System.out.println("----- leaving Account XML Test -----"); -// } -// -// @Test -// public void testCategoryXml(){ -// System.out.println("----- entering Category XML Test -----"); -// //create and fetch category object -// EntityContainer container = generateTestStructure(); -// Category category = container.getRootCategory(); -// assertNotNull(category); -// -// //create jaxb context and marshaller -// Marshaller marshaller=null; -// JAXBContext context=null; -// try { -// context = JAXBContext.newInstance(Category.class); -// marshaller = context.createMarshaller(); -// marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); -// } catch (JAXBException e) { -// e.printStackTrace(); -// fail(e.getMessage()); -// } -// -// //convert category object to xml -// String outputXml = ""; -// try { -// Writer writer = new StringWriter(); -// marshaller.marshal(category, writer); -// outputXml = writer.toString(); -// writer.close(); -// } catch (JAXBException e) { -// fail(e.getMessage()); -// } catch (IOException e) { -// fail(e.getMessage()); -// } -// assertTrue((outputXml!=null)&&(outputXml!="")); -// System.out.println(outputXml); -// -// //convert xml back to an object and assert equality to source object -// Category convertedCategory=null; -// try { -// Unmarshaller unmarshaller = context.createUnmarshaller(); -// convertedCategory = (Category) unmarshaller.unmarshal(new StringReader(outputXml)); -// System.out.println(convertedCategory.toString()); -// } catch (JAXBException e) { -// fail(e.getMessage()); -// } -// assertTrue(category.equals(convertedCategory)); -// System.out.println("----- leaving Category XML Test -----"); -// } -// -// @Test -// public void testCourseXml(){ -// System.out.println("----- entering Course XML Test -----"); -// //create and fetch course object -// EntityContainer container = generateTestStructure(); -// Course course = container.getCourses().get(0); -// assertNotNull(course); -// -// //create jaxb context and marshaller -// Marshaller marshaller=null; -// JAXBContext context=null; -// try { -// context = JAXBContext.newInstance(Course.class); -// marshaller = context.createMarshaller(); -// marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); -// } catch (JAXBException e) { -// e.printStackTrace(); -// fail(e.getMessage()); -// } -// -// //convert course object to xml -// String outputXml = ""; -// try { -// Writer writer = new StringWriter(); -// marshaller.marshal(course, writer); -// outputXml = writer.toString(); -// writer.close(); -// } catch (JAXBException e) { -// fail(e.getMessage()); -// } catch (IOException e) { -// fail(e.getMessage()); -// } -// assertTrue((outputXml!=null)&&(outputXml!="")); -// System.out.println(outputXml); -// -// //convert xml back to an object and assert equality to source object -// Course convertedCourse=null; -// try { -// Unmarshaller unmarshaller = context.createUnmarshaller(); -// convertedCourse = (Course) unmarshaller.unmarsha... [truncated message content] |