From 6693502d647cf707a15aedd444cb01f0026df863 Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@jalin.de>
Date: Mon, 27 May 2013 19:54:29 +0200
Subject: [PATCH] fix new error on pac.delete

---
 hsarback/src/de/hsadmin/mods/pac/Pac.java             |    2 +-
 hsarback/test/de/hsadmin/remote/PacMigrationTest.java |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/hsarback/src/de/hsadmin/mods/pac/Pac.java b/hsarback/src/de/hsadmin/mods/pac/Pac.java
index 0c2750b..4fa5ef0 100644
--- a/hsarback/src/de/hsadmin/mods/pac/Pac.java
+++ b/hsarback/src/de/hsadmin/mods/pac/Pac.java
@@ -79,7 +79,7 @@
 	@ManyToOne(fetch = EAGER)
 	private INetAddress oldINetAddr;
 
-	@OneToMany(fetch = EAGER, cascade = ALL, mappedBy="pac", orphanRemoval=true)
+	@OneToMany(fetch = EAGER, cascade = ALL, mappedBy="pac")
 	private Set<PacComponent> pacComponents;
 
 	@OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac")
diff --git a/hsarback/test/de/hsadmin/remote/PacMigrationTest.java b/hsarback/test/de/hsadmin/remote/PacMigrationTest.java
index 42e2c81..a0119ae 100644
--- a/hsarback/test/de/hsadmin/remote/PacMigrationTest.java
+++ b/hsarback/test/de/hsadmin/remote/PacMigrationTest.java
@@ -5,6 +5,8 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.Calendar;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -15,6 +17,7 @@
 import org.junit.Test;
 
 import de.hsadmin.core.util.Config;
+import de.hsadmin.core.util.TextUtil;
 import de.hsadmin.hostsharing.BasePacType;
 
 public class PacMigrationTest {
@@ -154,6 +157,47 @@
 		}
 	}
 
+	@Test
+	public void testDeleteSW() {
+		String user = "ad";
+		try {
+			int count = getPacsCount();
+			String grantingTicketURL = cas.getGrantingTicketURL(user);
+			Map<String, Object> setParams = new HashMap<String, Object>();
+			setParams.put("created", TextUtil.format(daysBack(10)));
+			Map<String, String> whereParams = new HashMap<String, String>();
+			whereParams.put("name", "aaa05");
+			Object[] params = new Object[] { user, 
+					cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), 
+					setParams, whereParams };
+			Object execute = client.execute(MODULE + ".update", params);
+			assertNotNull(execute);
+			setParams = new HashMap<String, Object>();
+			setParams.put("cancelled", TextUtil.format(daysBack(1)));
+			whereParams = new HashMap<String, String>();
+			whereParams.put("name", "aaa05");
+			params = new Object[] { user, 
+					cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), 
+					setParams, whereParams };
+			execute = client.execute(MODULE + ".update", params);
+			assertNotNull(execute);
+			whereParams.put("name", "aaa05");
+			params = new Object[] { user, 
+					cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), 
+					whereParams };
+			execute = client.execute(MODULE + ".delete", params);
+			assertEquals(count - 1, getPacsCount());
+		} catch (XmlRpcException e) {
+			fail(e.getMessage());
+		}
+	}
+
+	private Date daysBack(int days) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.add(Calendar.DAY_OF_YEAR, -days);
+		return calendar.getTime();
+	}
+
 	private int getPacsCount() {
 		int count = 0;
 		String user = "hsh00-aaa";

--
Gitblit v1.9.0-SNAPSHOT