From 6693502d647cf707a15aedd444cb01f0026df863 Mon Sep 17 00:00:00 2001 From: Peter Hormanns 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 +- .../de/hsadmin/remote/PacMigrationTest.java | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) 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 @@ public class Pac extends AbstractEntity implements Serializable { @ManyToOne(fetch = EAGER) private INetAddress oldINetAddr; - @OneToMany(fetch = EAGER, cascade = ALL, mappedBy="pac", orphanRemoval=true) + @OneToMany(fetch = EAGER, cascade = ALL, mappedBy="pac") private Set 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.assertNotNull; 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.Before; 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 @@ public class PacMigrationTest { } } + @Test + public void testDeleteSW() { + String user = "ad"; + try { + int count = getPacsCount(); + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map setParams = new HashMap(); + setParams.put("created", TextUtil.format(daysBack(10))); + Map whereParams = new HashMap(); + 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(); + setParams.put("cancelled", TextUtil.format(daysBack(1))); + whereParams = new HashMap(); + 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";