summaryrefslogtreecommitdiffstats
path: root/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java
diff options
context:
space:
mode:
authorAdrian Likins <adrian@alikins.usersys.redhat.com>2009-12-03 10:24:45 -0500
committerAdrian Likins <adrian@alikins.usersys.redhat.com>2009-12-03 10:24:45 -0500
commit744109c91948fc68bf3a63f52b88801e9d2bc438 (patch)
treec11d096c09cdd9373ae85e47f3833374e28e4e95 /proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java
parentc26e628a4fd5d8796c777b0f7daa0f43110f96e9 (diff)
parentb4c989272f444850e8f819b2b7a77a21cc9afad7 (diff)
downloadcandlepin-744109c91948fc68bf3a63f52b88801e9d2bc438.tar.gz
candlepin-744109c91948fc68bf3a63f52b88801e9d2bc438.tar.xz
candlepin-744109c91948fc68bf3a63f52b88801e9d2bc438.zip
Merge branch 'master' of ssh://alikins@git.fedorahosted.org/git/candlepin
Conflicts: proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java
Diffstat (limited to 'proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java')
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java58
1 files changed, 53 insertions, 5 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java b/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java
index f71d36a..30f8e85 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java
@@ -14,27 +14,39 @@
*/
package org.fedoraproject.candlepin.test;
+import java.sql.Date;
+
+import java.util.Calendar;
+import java.util.Random;
+
import org.fedoraproject.candlepin.model.Consumer;
import org.fedoraproject.candlepin.model.ConsumerType;
+import org.fedoraproject.candlepin.model.Entitlement;
+import org.fedoraproject.candlepin.model.EntitlementPool;
import org.fedoraproject.candlepin.model.ObjectFactory;
import org.fedoraproject.candlepin.model.Owner;
import org.fedoraproject.candlepin.model.Product;
-// TODO: Do we want to keep this style of creating objects for testing?
+/**
+ * TestUtil for creating various testing objects.
+ *
+ * Objects backed by the database are not persisted, the caller is expected to persist
+ * the entities returned and any dependent objects.
+ */
public class TestUtil {
private TestUtil() {
}
public static Owner createOwner() {
- Owner o = new Owner("Test Owner");
+ Owner o = new Owner("Test Owner " + randomInt());
// o.setUuid(lookedUp);
ObjectFactory.get().store(o);
return o;
}
public static Consumer createConsumer(ConsumerType type, Owner owner) {
- Consumer c = new Consumer("Consumer Name", owner, type);
+ Consumer c = new Consumer("Test Consumer " + randomInt(), owner, type);
ObjectFactory.get().store(c);
return c;
}
@@ -44,12 +56,48 @@ public class TestUtil {
* @return Consumer
*/
public static Consumer createConsumer() {
- return createConsumer(new ConsumerType("some-consumer-type"), createOwner());
+ return createConsumer(new ConsumerType("test-consumer-type-" + randomInt()),
+ createOwner());
+ }
+
+ public static int randomInt() {
+ return new Random().nextInt(10000);
}
public static Product createProduct() {
- Product rhel = new Product("rhel-label", "Red Hat Enterprise Linux");
+ int random = randomInt();
+ Product rhel = new Product("test-product-" + random,
+ "Test Product " + random);
ObjectFactory.get().store(rhel);
return rhel;
}
+
+ public static EntitlementPool createEntitlementPool() {
+ EntitlementPool pool = new EntitlementPool(createOwner(), createProduct(),
+ new Long(1000),
+ TestUtil.createDate(2009, 11, 30), TestUtil.createDate(2015, 11, 30));
+ return pool;
+ }
+
+ public static Entitlement createEntitlement(EntitlementPool pool) {
+ Entitlement e = new Entitlement(pool, pool.getOwner(), pool.getStartDate());
+ return e;
+ }
+
+ public static Date createDate(int year, int month, int day) {
+ Calendar cal = Calendar.getInstance();
+
+ cal.set(Calendar.YEAR, year);
+ cal.set(Calendar.MONTH, month);
+ cal.set(Calendar.DATE, day);
+
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+
+ Date jsqlD = new Date(cal.getTime().getTime());
+ return jsqlD;
+ }
+
}