incubator-hise-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: r905993 - in /incubator/hise/trunk/hise-services/src/test/java/org/apache/hise: DaoTest.java TaskCreationHelper.java
Date Wed, 03 Feb 2010 11:05:46 GMT
Author: utr
Date: Wed Feb  3 11:05:43 2010
New Revision: 905993

URL: http://svn.apache.org/viewvc?rev=905993&view=rev
Log:
helper class for adding tasks in integration tests

Added:
    incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskCreationHelper.java
Modified:
    incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/DaoTest.java

Modified: incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/DaoTest.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/DaoTest.java?rev=905993&r1=905992&r2=905993&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/DaoTest.java (original)
+++ incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/DaoTest.java Wed Feb
 3 11:05:43 2010
@@ -1,22 +1,15 @@
 package org.apache.hise;
 
-import java.util.Collections;
 import java.util.Date;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
+import org.apache.hise.TaskCreationHelper.TaskType;
 import org.apache.hise.dao.GenericHumanRole;
 import org.apache.hise.dao.HISEDao;
 import org.apache.hise.dao.Job;
-import org.apache.hise.dao.Message;
 import org.apache.hise.dao.OrgEntity;
 import org.apache.hise.dao.Task;
-import org.apache.hise.dao.TaskOrgEntity;
 import org.apache.hise.dao.TaskQuery;
-import org.apache.hise.dao.Task.Status;
-import org.apache.hise.dao.TaskOrgEntity.OrgEntityType;
-import org.apache.hise.lang.xsd.htda.TStatus;
 import org.junit.Assert;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -24,124 +17,45 @@
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 import org.springframework.transaction.TransactionStatus;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.support.TransactionCallback;
 import org.springframework.transaction.support.TransactionTemplate;
 
 @ContextConfiguration(locations = "classpath:/dao.xml")
 public class DaoTest extends AbstractJUnit4SpringContextTests {
     
-    @Autowired
+	@Autowired
     private HISEDao hiseDao;
     
     @Autowired
     private JpaTransactionManager transactionManager;
     
+    private TaskCreationHelper taskHelper = new TaskCreationHelper();
+    
     private void cleanup() throws Exception {
         hiseDao.clearAllRecords(OrgEntity.class);
         hiseDao.clearAllRecords(Task.class);
         hiseDao.clearAllRecords(Job.class);
     }
     
-    private Long addTask() throws Exception {
-        Assert.assertTrue(hiseDao != null);
-        
-        OrgEntity o, o2;
-        
-        o2 = new OrgEntity();
-        o2.setName("group1");
-        o2.setType(OrgEntityType.GROUP);
-        hiseDao.persist(o2);
-
-        o = new OrgEntity();
-        o.setName("user1");
-        o.setType(OrgEntityType.USER);
-        o.setUserPassword("abc");
-        
-        o.addToGroup(o2);
-        hiseDao.persist(o);
-        
-        Task t = new Task();
-        t.setStatus(Status.CREATED);
-        t.setTaskDefinitionKey("asd");
-        t.setActualOwner("user1");
-        
-        t.getInput().put("abc", new Message("abc", "def"));
-        hiseDao.persist(t);
-        Long id = t.getId();
-        Assert.assertNotNull(id);
-        return id;
-    }
-
-    private void addTask2() throws Exception {
-        addTask();
-        Task t = new Task();
-        t.setStatus(Status.READY);
-        t.setTaskDefinitionKey("asd2");
-        Set<TaskOrgEntity> pa = new HashSet<TaskOrgEntity>();
-        TaskOrgEntity x = new TaskOrgEntity();
-        x.setName("user1");
-        x.setType(OrgEntityType.USER);
-        x.setGenericHumanRole(GenericHumanRole.POTENTIALOWNERS);
-        x.setTask(t);
-        pa.add(x);
-        t.setPeopleAssignments(pa);
-        hiseDao.persist(t);
-    }
-
-    private void addTask3() throws Exception {
-        addTask();
-        Task t = new Task();
-        t.setStatus(Status.READY);
-        t.setTaskDefinitionKey("asd3");
-        Set<TaskOrgEntity> pa = new HashSet<TaskOrgEntity>();
-        TaskOrgEntity x = new TaskOrgEntity();
-        x.setName("group1");
-        x.setType(OrgEntityType.GROUP);
-        x.setGenericHumanRole(GenericHumanRole.POTENTIALOWNERS);
-        x.setTask(t);
-        pa.add(x);
-        t.setPeopleAssignments(pa);
-        hiseDao.persist(t);
-    }
-
-    
     @Test
     public void testDao() throws Exception {
         TransactionTemplate tt = new TransactionTemplate(transactionManager);
-        final Long tid = (Long) tt.execute(new TransactionCallback() {
-            public Object doInTransaction(TransactionStatus arg0) {
-                try {
-                    return addTask();
-                } catch (Exception e) {
-                    throw new RuntimeException(e);
-                }
-            }
-        });
+        Long tid = taskHelper.addTaskInTransaction(TaskType.TASK1, tt, hiseDao);
+        Assert.assertNotNull(tid);
     }
     
-    
-    
     @Test 
     public void testUserTasks() throws Exception {
         TransactionTemplate tt = new TransactionTemplate(transactionManager);
-        final Long tid = (Long) tt.execute(new TransactionCallback() {
-            public Object doInTransaction(TransactionStatus arg0) {
-                try {
-                    cleanup();
-                    return addTask();
-                } catch (Exception e) {
-                    throw new RuntimeException(e);
-                }
-            }
-        });
+        taskHelper.addTaskInTransaction(TaskType.TASK1, tt, hiseDao);
+        
         tt.execute(new TransactionCallback() {
             public Object doInTransaction(TransactionStatus arg0) {
                 try {
                     TaskQuery query = new TaskQuery();
-                    query.setUser("user1");
+                    query.setUser(TaskCreationHelper.TASK1_OWNER);
                     List<Task> r = hiseDao.getUserTasks(query);
-                    Assert.assertEquals("asd", r.get(0).getTaskDefinitionKey());
+                    Assert.assertEquals(TaskCreationHelper.TASK1_DEFINITION_KEY, r.get(0).getTaskDefinitionKey());
                     return null;
                 } catch (Exception e) {
                     throw new RuntimeException(e);
@@ -153,19 +67,19 @@
     @Test 
     public void testUserTasks2() throws Exception {
         TransactionTemplate tt = new TransactionTemplate(transactionManager);
-        final Long tid = (Long) tt.execute(new TransactionCallback() {
+        tt.execute(new TransactionCallback() {
             public Object doInTransaction(TransactionStatus arg0) {
                 try{
                     cleanup();
-                    addTask2();
+                    taskHelper.addTask2(hiseDao);
                     TaskQuery query = new TaskQuery();
-                    query.setUser("user1");
+                    query.setUser(TaskCreationHelper.TASK2_ASSIGNED_USER);
                     query.setGenericHumanRole(GenericHumanRole.POTENTIALOWNERS);
                     List<Task> r = hiseDao.getUserTasks(query);
-                    query.getUserGroups().add("group1");
+                    query.getUserGroups().add(TaskCreationHelper.TASK2_ASSIGNED_USER_GROUP);
                     r = hiseDao.getUserTasks(query);
                     
-                    Assert.assertEquals("asd2", r.get(0).getTaskDefinitionKey());
+                    Assert.assertEquals(TaskCreationHelper.TASK2_DEFINITION_KEY, r.get(0).getTaskDefinitionKey());
                     return null;
                 } catch (Exception e) {
                     throw new RuntimeException(e);
@@ -177,20 +91,12 @@
     @Test
     public void testInputs() throws Exception {
         TransactionTemplate tt = new TransactionTemplate(transactionManager);
-        final Long tid = (Long) tt.execute(new TransactionCallback() {
-            public Object doInTransaction(TransactionStatus arg0) {
-                try {
-                    cleanup();
-                    return addTask();
-                } catch (Exception e) {
-                    throw new RuntimeException(e);
-                }
-            }
-        });
+        final Long tid = taskHelper.addTaskInTransaction(TaskType.TASK1, tt, hiseDao);
         tt.execute(new TransactionCallback() {
             public Object doInTransaction(TransactionStatus arg0) {
                 try {
-                    Assert.assertTrue(hiseDao.find(Task.class, tid).getInput().get("abc").getMessage().equals("def"));
+                	Task task = hiseDao.find(Task.class, tid);
+                	Assert.assertTrue(task.getInput().get(TaskCreationHelper.TASK1_INPUT_KEY).getMessage().equals(TaskCreationHelper.TASK1_INPUT_VALUE));
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
@@ -203,27 +109,17 @@
     @Test 
     public void testGroupQuery() throws Exception {
         TransactionTemplate tt = new TransactionTemplate(transactionManager);
-        tt.execute(new TransactionCallback() {
-            public Object doInTransaction(TransactionStatus arg0) {
-                try {
-                    cleanup();
-                    addTask3();
-                } catch (Exception e) {
-                    throw new RuntimeException(e);
-                }
-                return null;
-            }
-        });
+        taskHelper.addTaskInTransaction(TaskType.TASK3, tt, hiseDao);
                 
         tt.execute(new TransactionCallback() {
             public Object doInTransaction(TransactionStatus arg0) {
                 try {
                     TaskQuery query = new TaskQuery();
-                    query.setUser("user1");
-                    query.getUserGroups().add("group1");
+                    query.setUser(TaskCreationHelper.TASK3_ASSIGNED_USER);
+                    query.getUserGroups().add(TaskCreationHelper.TASK3_ASSIGNED_GROUP);
                     query.setGenericHumanRole(GenericHumanRole.POTENTIALOWNERS);
                     List<Task> r = hiseDao.getUserTasks(query);
-                    Assert.assertEquals("asd3", r.get(0).getTaskDefinitionKey());
+                    Assert.assertEquals(TaskCreationHelper.TASK3_DEFINITION_KEY, r.get(0).getTaskDefinitionKey());
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
@@ -261,7 +157,7 @@
             public Object doInTransaction(TransactionStatus arg0) {
                 try {
                     cleanup();
-                    Task t = hiseDao.find(Task.class, addTask());
+                    Task t = hiseDao.find(Task.class, taskHelper.addTask(hiseDao));
                     
                     {
                         Job j = new Job();

Added: incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskCreationHelper.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskCreationHelper.java?rev=905993&view=auto
==============================================================================
--- incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskCreationHelper.java
(added)
+++ incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskCreationHelper.java
Wed Feb  3 11:05:43 2010
@@ -0,0 +1,139 @@
+package org.apache.hise;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.hise.dao.GenericHumanRole;
+import org.apache.hise.dao.HISEDao;
+import org.apache.hise.dao.Job;
+import org.apache.hise.dao.Message;
+import org.apache.hise.dao.OrgEntity;
+import org.apache.hise.dao.Task;
+import org.apache.hise.dao.TaskOrgEntity;
+import org.apache.hise.dao.Task.Status;
+import org.apache.hise.dao.TaskOrgEntity.OrgEntityType;
+import org.junit.Assert;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+
+public class TaskCreationHelper {
+	
+	public enum TaskType {
+		TASK1, TASK2, TASK3
+	}
+	
+	public static String TASK1_GROUP = "group1";
+	public static String TASK1_OWNER = "user1";
+	public static String TASK1_OWNER_PASSWORD = "abc";
+	public static String TASK1_DEFINITION_KEY = "asd";
+	public static String TASK1_INPUT_KEY = "abc";
+	public static String TASK1_INPUT_VALUE = "def";
+	
+	public static String TASK2_ASSIGNED_USER = "user1";
+	public static String TASK2_ASSIGNED_USER_GROUP = "group1";
+	public static String TASK2_DEFINITION_KEY = "asd2";
+	
+	public static String TASK3_ASSIGNED_USER = "user1";
+	public static String TASK3_ASSIGNED_GROUP = "group1";
+	public static String TASK3_DEFINITION_KEY = "asd3";
+	
+	
+	private void cleanup(HISEDao hiseDao) throws Exception {
+        hiseDao.clearAllRecords(OrgEntity.class);
+        hiseDao.clearAllRecords(Task.class);
+        hiseDao.clearAllRecords(Job.class);
+    }
+    
+    
+    public Long addTask(HISEDao hiseDao) throws Exception {
+        Assert.assertTrue(hiseDao != null);
+        
+        OrgEntity o, o2;
+        
+        o2 = new OrgEntity();
+        o2.setName(TASK1_GROUP);
+        o2.setType(OrgEntityType.GROUP);
+        hiseDao.persist(o2);
+
+        o = new OrgEntity();
+        o.setName(TASK1_OWNER);
+        o.setType(OrgEntityType.USER);
+        o.setUserPassword(TASK1_OWNER_PASSWORD);
+        
+        o.addToGroup(o2);
+        hiseDao.persist(o);
+        
+        Task t = new Task();
+        t.setStatus(Status.CREATED);
+        t.setTaskDefinitionKey(TASK1_DEFINITION_KEY);
+        t.setActualOwner(TASK1_OWNER);
+        
+        t.getInput().put(TASK1_INPUT_KEY, new Message(TASK1_INPUT_KEY, TASK1_INPUT_VALUE));
+        hiseDao.persist(t);
+        Long id = t.getId();
+        Assert.assertNotNull(id);
+        return id;
+    }
+
+    public void addTask2(HISEDao hiseDao) throws Exception {
+        addTask(hiseDao);
+        Task t = new Task();
+        t.setStatus(Status.READY);
+        t.setTaskDefinitionKey(TASK2_DEFINITION_KEY);
+        Set<TaskOrgEntity> pa = new HashSet<TaskOrgEntity>();
+        TaskOrgEntity x = new TaskOrgEntity();
+        x.setName(TASK2_ASSIGNED_USER);
+        x.setType(OrgEntityType.USER);
+        x.setGenericHumanRole(GenericHumanRole.POTENTIALOWNERS);
+        x.setTask(t);
+        pa.add(x);
+        t.setPeopleAssignments(pa);
+        hiseDao.persist(t);
+    }
+
+    public void addTask3(HISEDao hiseDao) throws Exception {
+        addTask(hiseDao);
+        Task t = new Task();
+        t.setStatus(Status.READY);
+        t.setTaskDefinitionKey(TASK3_DEFINITION_KEY);
+        Set<TaskOrgEntity> pa = new HashSet<TaskOrgEntity>();
+        TaskOrgEntity x = new TaskOrgEntity();
+        x.setName(TASK3_ASSIGNED_GROUP);
+        x.setType(OrgEntityType.GROUP);
+        x.setGenericHumanRole(GenericHumanRole.POTENTIALOWNERS);
+        x.setTask(t);
+        pa.add(x);
+        t.setPeopleAssignments(pa);
+        hiseDao.persist(t);
+    }
+    
+    public Long addTaskInTransaction(final TaskType taskType, TransactionTemplate tt, final
HISEDao hiseDao) {
+    	Long tid = (Long) tt.execute(new TransactionCallback() {
+            public Object doInTransaction(TransactionStatus arg0) {
+                try {
+                	cleanup(hiseDao);
+                	Long tid = null;
+                    switch(taskType) {
+                    	case TASK1:
+                    		tid = addTask(hiseDao);
+                    		break;
+                    	case TASK2:
+                    		addTask2(hiseDao);
+                    		break;
+                    	case TASK3:
+                    		addTask3(hiseDao);
+                    		break;
+                    }
+                    return tid;
+                	
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        });
+    	return tid;
+    }
+
+    
+}
\ No newline at end of file



Mime
View raw message