|
From: <pka...@us...> - 2009-07-24 11:53:55
|
Revision: 364
http://cse-ip.svn.sourceforge.net/cse-ip/?rev=364&view=rev
Author: pkasprzak
Date: 2009-07-24 11:53:48 +0000 (Fri, 24 Jul 2009)
Log Message:
-----------
* Added EntityManager.updateAttributes() for attribute checks on entities (+ some tests)
* Fixed Attribute -> Entity cascades
Modified Paths:
--------------
trunk/sandbox/lsf-adapter-demo/CSECore-test/src/java/de/campussource/cse/core/test/Main.java
Modified: trunk/sandbox/lsf-adapter-demo/CSECore-test/src/java/de/campussource/cse/core/test/Main.java
===================================================================
--- trunk/sandbox/lsf-adapter-demo/CSECore-test/src/java/de/campussource/cse/core/test/Main.java 2009-07-24 11:53:42 UTC (rev 363)
+++ trunk/sandbox/lsf-adapter-demo/CSECore-test/src/java/de/campussource/cse/core/test/Main.java 2009-07-24 11:53:48 UTC (rev 364)
@@ -12,6 +12,8 @@
import de.campussource.cse.core.cdm.AttributeType;
import de.campussource.cse.core.cdm.CourseType;
import de.campussource.cse.core.cdm.EntityType;
+import de.campussource.cse.core.pdm.Attribute;
+import de.campussource.cse.core.pdm.Entity;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -57,6 +59,16 @@
print(buffer.toString());
}
+ private static void dumpEntity(Entity entity) {
+ print("--------------------------------------");
+ print("Entity-type: " + entity.getType());
+ print("Attributes:");
+ for (Attribute attribute : entity.getAttributes()) {
+ print("name: " + attribute.getName() + "; value: " + attribute.getValue());
+ }
+ print("--------------------------------------");
+ }
+
private static void addAttribute(String attributeName, String attributeValue, EntityType entity) {
AttributeType attribute = new AttributeType();
attribute.setName(attributeName);
@@ -64,15 +76,71 @@
entity.getAttribute().add(attribute);
}
- public static void test_entityManager() {
+ public static void test_entityManager_createCourse() {
CourseType course = new CourseType();
- addAttribute("clientId", "5", course);
- addAttribute("attribute1", "value1", course);
- addAttribute("attribute2", "value2", course);
+ addAttribute("clientId", "1", course);
+ addAttribute("attribute1", "value1", course);
+ addAttribute("attribute2", "value2", course);
int courseId = entityManager.createCourse(course);
- print("*** Generated course with id = " + courseId);
+ print("Created course with id = " + courseId);
}
+ public static void test_entityManager_updateAttributes() {
+
+ /* First create course with some attributes */
+ print("\nTest: persisting course");
+ CourseType course = new CourseType();
+ addAttribute("clientId", "1", course);
+ addAttribute("attribute1", "value1", course);
+ addAttribute("attribute2", "value2", course);
+ addAttribute("attribute3", "value3", course);
+ int courseId = entityManager.createCourse(course);
+ print("Created course with id = " + courseId);
+ print("Course as persisted:");
+ dumpEntity(entityManager.getEntity(courseId));
+
+ /* Test attribute change */
+ print("\nTest: changing attribute value");
+ course = new CourseType();
+ addAttribute("clientId", "1", course);
+ addAttribute("attribute1", "changedvalue1", course);
+ addAttribute("attribute2", "value2", course);
+ addAttribute("attribute3", "value3", course);
+ course.setBusId(courseId);
+ boolean attributesChanged = entityManager.updateAttributes(course);
+ print("Attributes changed (as reported) [YES]: " + (attributesChanged ? "YES" : "NO"));
+ print("Course as persisted:");
+ dumpEntity(entityManager.getEntity(courseId));
+
+ /* Test addition of an attribute */
+ print("\nTest: adding attribute");
+ addAttribute("attribute4", "value4", course);
+ attributesChanged = entityManager.updateAttributes(course);
+ print("Attributes changed (as reported) [YES]: " + (attributesChanged ? "YES" : "NO"));
+ print("Course as persisted:");
+ dumpEntity(entityManager.getEntity(courseId));
+
+ /* Test no changes */
+ print("\nTest: no changes");
+ attributesChanged = entityManager.updateAttributes(course);
+ print("Attributes changed (as reported) [NO]: " + (attributesChanged ? "YES" : "NO"));
+ print("Course as persisted:");
+ dumpEntity(entityManager.getEntity(courseId));
+
+ /* Test removal of an attribute */
+ print("\nTest: removing attribute");
+ course = new CourseType();
+ addAttribute("clientId", "1", course);
+ addAttribute("attribute1", "changedvalue1", course);
+ addAttribute("attribute2", "value2", course);
+ addAttribute("attribute3", "value3", course);
+ course.setBusId(courseId);
+ attributesChanged = entityManager.updateAttributes(course);
+ print("Attributes changed (as reported) [YES]: " + (attributesChanged ? "YES" : "NO"));
+ print("Course as persisted:");
+ dumpEntity(entityManager.getEntity(courseId));
+ }
+
/**
* @param args the command line arguments
*/
@@ -85,7 +153,9 @@
identityManager = (IdentityManager) ctx.lookup("cse/IdentityManager");
dependencyManager = (DependencyManager) ctx.lookup("cse/DependencyManager");
- test_entityManager();
+// test_entityManager_createCourse();
+
+ test_entityManager_updateAttributes();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|