summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevan Goodwin <dgoodwin@redhat.com>2009-12-05 13:36:00 -0400
committerDevan Goodwin <dgoodwin@redhat.com>2009-12-05 13:36:00 -0400
commit1bee200575dda5cf1b41bf879f79471e47311740 (patch)
treef09a2c6debbe8293286ca317b7bb70eda67a054f
parent0a1e68069524f42adc7539f8c94d5fbc7423c00a (diff)
downloadcandlepin-1bee200575dda5cf1b41bf879f79471e47311740.tar.gz
candlepin-1bee200575dda5cf1b41bf879f79471e47311740.tar.xz
candlepin-1bee200575dda5cf1b41bf879f79471e47311740.zip
Start testing the CertificateResource.
-rw-r--r--proxy/build.xml4
-rw-r--r--proxy/code/src/META-INF/persistence.xml4
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/Pinsetter.java1
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/ProductRepository.java24
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java10
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java57
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert23
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java14
8 files changed, 122 insertions, 15 deletions
diff --git a/proxy/build.xml b/proxy/build.xml
index f1593cc..dc3c6ea 100644
--- a/proxy/build.xml
+++ b/proxy/build.xml
@@ -569,10 +569,6 @@ Running @{banner} ...
<mkdir dir="${dir.genhbm}" />
<hibernatetool destdir="${dir.genhbm}">
-<!--
- <property key="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
- <property key="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
--->
<classpath>
<path location="build/classes"/>
diff --git a/proxy/code/src/META-INF/persistence.xml b/proxy/code/src/META-INF/persistence.xml
index ee53eba..b41164a 100644
--- a/proxy/code/src/META-INF/persistence.xml
+++ b/proxy/code/src/META-INF/persistence.xml
@@ -12,7 +12,7 @@
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
- <property name="hibernate.show_sql" value="true" />
+ <property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
@@ -28,7 +28,7 @@
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
- <property name="hibernate.show_sql" value="true" />
+ <property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Pinsetter.java b/proxy/code/src/org/fedoraproject/candlepin/model/Pinsetter.java
index ac3ae8f..9c65b9e 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/Pinsetter.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/Pinsetter.java
@@ -45,6 +45,7 @@ public class Pinsetter {
*/
public void addProduct(Owner owner, String pname, long maxmem,
Date start, Date end) {
+ System.out.println("Adding product " + pname);
Product p = new Product(pname, pname);
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ProductRepository.java b/proxy/code/src/org/fedoraproject/candlepin/model/ProductRepository.java
new file mode 100644
index 0000000..0beaab0
--- /dev/null
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/ProductRepository.java
@@ -0,0 +1,24 @@
+package org.fedoraproject.candlepin.model;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.criterion.Restrictions;
+
+public class ProductRepository extends AbstractHibernateRepository<Product> {
+
+ public ProductRepository(EntityManager em) {
+ super(Product.class);
+ }
+
+ public Product lookupByName(String name) {
+ return (Product) currentSession().createCriteria(Product.class)
+ .add(Restrictions.like("name", name))
+ .uniqueResult();
+ }
+
+ public Product lookupByLabel(String label) {
+ return (Product) currentSession().createCriteria(Product.class)
+ .add(Restrictions.like("label", label))
+ .uniqueResult();
+ }
+}
diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java b/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java
index e4e5138..fdfcc45 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java
@@ -91,15 +91,7 @@ public class CertificateResource extends BaseResource {
return "uuid";
}
- private String createString(byte[] bytes) {
- StringBuffer buf = new StringBuffer();
- for (byte b : bytes) {
- buf.append((char) Integer.parseInt(Integer.toHexString(b), 16));
- }
-
- return buf.toString();
- }
-
+
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public String get() {
diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java b/proxy/code/src/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java
new file mode 100644
index 0000000..99751eb
--- /dev/null
+++ b/proxy/code/src/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2009 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+
+package org.fedoraproject.candlepin.resource.test;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.fedoraproject.candlepin.model.Product;
+import org.fedoraproject.candlepin.resource.CertificateResource;
+import org.fedoraproject.candlepin.test.DatabaseTestFixture;
+import org.fedoraproject.candlepin.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class CertificateResourceTest extends DatabaseTestFixture {
+
+ private CertificateResource certResource;
+ private String sampleCertXml;
+
+ @Before
+ public void createObjects() throws Exception {
+ certResource = new CertificateResource();
+
+ InputStream is = this.getClass().getResourceAsStream(
+ "/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert");
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ StringBuilder builder = new StringBuilder();
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ builder.append(line + "\n");
+ }
+ sampleCertXml = builder.toString();
+ }
+
+ @Test
+ public void simpleUploadCertProductsCreated() {
+ certResource.upload(TestUtil.xmlToBase64String(sampleCertXml));
+ // TODO: check that products got created!
+ }
+
+
+}
diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert b/proxy/code/src/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert
new file mode 100644
index 0000000..4d63ab3
--- /dev/null
+++ b/proxy/code/src/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rhn-cert version="0.1">
+ <rhn-cert-field name="product">SPACEWALK-001</rhn-cert-field>
+ <rhn-cert-field name="owner">Spacewalk Public Cert</rhn-cert-field>
+ <rhn-cert-field name="issued">2007-07-13 00:00:00</rhn-cert-field>
+ <rhn-cert-field name="expires">2010-07-13 00:00:00</rhn-cert-field>
+ <rhn-cert-field name="slots">20000</rhn-cert-field>
+ <rhn-cert-field name="monitoring-slots">20000</rhn-cert-field>
+ <rhn-cert-field name="provisioning-slots">20000</rhn-cert-field>
+ <rhn-cert-field name="virtualization_host">20000</rhn-cert-field>
+ <rhn-cert-field name="virtualization_host_platform">20000</rhn-cert-field>
+ <rhn-cert-field name="satellite-version">spacewalk</rhn-cert-field>
+ <rhn-cert-field name="generation">2</rhn-cert-field>
+ <rhn-cert-signature>
+-----BEGIN PGP SIGNATURE-----
+Version: Crypt::OpenPGP 1.03
+
+iQBGBAARAwAGBQJIUsb7AAoJEJ5yna8GlHkyi50Anjh4/GHHPoOUKO6LdDaE2ZcJ
+X69tAJ41s97D66gXGvk244vkmSMajJT2hg==
+=oOTl
+-----END PGP SIGNATURE-----
+</rhn-cert-signature>
+</rhn-cert>
diff --git a/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java b/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java
index 4c5aba1..8c8ee90 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java
@@ -27,6 +27,8 @@ import org.fedoraproject.candlepin.model.Owner;
import org.fedoraproject.candlepin.model.Product;
import org.fedoraproject.candlepin.model.User;
+import com.sun.jersey.core.util.Base64;
+
/**
* TestUtil for creating various testing objects.
*
@@ -107,5 +109,17 @@ public class TestUtil {
Date jsqlD = new Date(cal.getTime().getTime());
return jsqlD;
}
+
+ public static String xmlToBase64String(String xml) {
+
+ byte[] bytes = Base64.encode(xml);
+
+ StringBuffer buf = new StringBuffer();
+ for (byte b : bytes) {
+ buf.append((char) Integer.parseInt(Integer.toHexString(b), 16));
+ }
+
+ return buf.toString();
+ }
}