From 7d8fb4e8d8aac4935c35ff3ac550c6fefdc93430 Mon Sep 17 00:00:00 2001 From: Dmitri Dolguikh Date: Thu, 31 Dec 2009 15:38:56 -0400 Subject: brought in changes from master --- proxy/buildfile | 22 ++- .../candlepin/guice/JPAInitializer.java | 32 ---- .../candlepin/guice/JerseyGuiceConfiguration.java | 49 ------ .../candlepin/model/AbstractHibernateCurator.java | 80 --------- .../fedoraproject/candlepin/model/Certificate.java | 112 ------------ .../candlepin/model/CertificateCurator.java | 26 --- .../candlepin/model/ConsumerCurator.java | 77 --------- .../candlepin/model/ConsumerInfoCurator.java | 14 -- .../candlepin/model/ConsumerTypeCurator.java | 30 ---- .../candlepin/model/EntitlementCurator.java | 27 --- .../candlepin/model/EntitlementPoolCurator.java | 89 ---------- .../candlepin/model/OwnerCurator.java | 45 ----- .../fedoraproject/candlepin/model/Persisted.java | 7 - .../candlepin/model/ProductCurator.java | 83 --------- .../fedoraproject/candlepin/model/UserCurator.java | 22 --- .../candlepin/model/test/CertificateTest.java | 82 --------- .../candlepin/model/test/EntitlementPoolTest.java | 57 ------- .../candlepin/model/test/UserTest.java | 45 ----- .../resource/test/CandlepinTestingModule.java | 17 -- .../resource/test/CertificateResourceTest.java | 117 ------------- .../candlepin/resource/test/spacewalk-public.cert | 23 --- .../candlepin/test/DatabaseTestFixture.java | 188 --------------------- .../org/fedoraproject/candlepin/test/TestUtil.java | 126 -------------- .../src/org/fedoraproject/candlepin/util/Util.java | 14 -- proxy/code/webapp/certs/certificates.readme | 22 --- proxy/code/webapp/certs/rest_api_test.jks | Bin 2001 -> 0 bytes proxy/code/webapp/certs/rest_client_test.p12 | Bin 1840 -> 0 bytes proxy/code/webapp/certs/server.xml | 147 ---------------- .../candlepin/guice/JPAInitializer.java | 32 ++++ .../candlepin/guice/JerseyGuiceConfiguration.java | 49 ++++++ .../candlepin/model/AbstractHibernateCurator.java | 80 +++++++++ .../fedoraproject/candlepin/model/Certificate.java | 112 ++++++++++++ .../candlepin/model/CertificateCurator.java | 26 +++ .../candlepin/model/ConsumerCurator.java | 77 +++++++++ .../candlepin/model/ConsumerInfoCurator.java | 14 ++ .../candlepin/model/ConsumerTypeCurator.java | 30 ++++ .../candlepin/model/EntitlementCurator.java | 27 +++ .../candlepin/model/EntitlementPoolCurator.java | 89 ++++++++++ .../candlepin/model/OwnerCurator.java | 45 +++++ .../fedoraproject/candlepin/model/Persisted.java | 7 + .../candlepin/model/ProductCurator.java | 83 +++++++++ .../fedoraproject/candlepin/model/UserCurator.java | 22 +++ .../org/fedoraproject/candlepin/util/Util.java | 14 ++ proxy/src/main/resources/META-INF/persistence.xml | 35 ---- proxy/src/main/resources/WEB-INF/web.xml | 53 ------ proxy/src/main/webapp/META-INF/persistence.xml | 35 ++++ proxy/src/main/webapp/WEB-INF/web.xml | 53 ++++++ .../candlepin/model/test/CertificateTest.java | 82 +++++++++ .../candlepin/model/test/EntitlementPoolTest.java | 57 +++++++ .../candlepin/model/test/UserTest.java | 45 +++++ .../resource/test/CandlepinTestingModule.java | 17 ++ .../resource/test/CertificateResourceTest.java | 117 +++++++++++++ .../candlepin/resource/test/spacewalk-public.cert | 23 +++ .../candlepin/test/DatabaseTestFixture.java | 188 +++++++++++++++++++++ .../org/fedoraproject/candlepin/test/TestUtil.java | 126 ++++++++++++++ proxy/src/test/resources/META-INF/persistence.xml | 20 --- proxy/src/test/resources/WEB-INF/web.xml | 45 ----- proxy/src/test/resources/certs/certificates.readme | 22 +++ proxy/src/test/resources/certs/rest_api_test.jks | Bin 0 -> 2001 bytes .../src/test/resources/certs/rest_client_test.p12 | Bin 0 -> 1840 bytes proxy/src/test/resources/certs/server.xml | 147 ++++++++++++++++ 61 files changed, 1629 insertions(+), 1696 deletions(-) delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/guice/JPAInitializer.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/guice/JerseyGuiceConfiguration.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/AbstractHibernateCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/Certificate.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/CertificateCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/ConsumerCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfoCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/ConsumerTypeCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/EntitlementCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPoolCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/OwnerCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/Persisted.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/ProductCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/UserCurator.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/test/CertificateTest.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/test/UserTest.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/resource/test/CandlepinTestingModule.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/util/Util.java delete mode 100644 proxy/code/webapp/certs/certificates.readme delete mode 100644 proxy/code/webapp/certs/rest_api_test.jks delete mode 100644 proxy/code/webapp/certs/rest_client_test.p12 delete mode 100644 proxy/code/webapp/certs/server.xml create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/guice/JPAInitializer.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/guice/JerseyGuiceConfiguration.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/AbstractHibernateCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/Certificate.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/CertificateCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerInfoCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerTypeCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/EntitlementCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/EntitlementPoolCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/OwnerCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/Persisted.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/ProductCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/model/UserCurator.java create mode 100644 proxy/src/main/java/org/fedoraproject/candlepin/util/Util.java delete mode 100644 proxy/src/main/resources/META-INF/persistence.xml delete mode 100644 proxy/src/main/resources/WEB-INF/web.xml create mode 100644 proxy/src/main/webapp/META-INF/persistence.xml create mode 100644 proxy/src/main/webapp/WEB-INF/web.xml create mode 100644 proxy/src/test/java/org/fedoraproject/candlepin/model/test/CertificateTest.java create mode 100644 proxy/src/test/java/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java create mode 100644 proxy/src/test/java/org/fedoraproject/candlepin/model/test/UserTest.java create mode 100644 proxy/src/test/java/org/fedoraproject/candlepin/resource/test/CandlepinTestingModule.java create mode 100644 proxy/src/test/java/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java create mode 100644 proxy/src/test/java/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert create mode 100644 proxy/src/test/java/org/fedoraproject/candlepin/test/DatabaseTestFixture.java create mode 100644 proxy/src/test/java/org/fedoraproject/candlepin/test/TestUtil.java delete mode 100644 proxy/src/test/resources/META-INF/persistence.xml delete mode 100644 proxy/src/test/resources/WEB-INF/web.xml create mode 100644 proxy/src/test/resources/certs/certificates.readme create mode 100644 proxy/src/test/resources/certs/rest_api_test.jks create mode 100644 proxy/src/test/resources/certs/rest_client_test.p12 create mode 100644 proxy/src/test/resources/certs/server.xml diff --git a/proxy/buildfile b/proxy/buildfile index c0bb3d8..e5a2e93 100644 --- a/proxy/buildfile +++ b/proxy/buildfile @@ -39,6 +39,7 @@ BOUNCYCASTLE = group('bcprov', 'bcpg', :under=>'org.bouncycastle', :version=>'1. GUICE = [group('guice', 'guice-assistedinject', 'guice-multibindings', 'guice-servlet', 'guice-throwingproviders', :under=>'com.google.guice', :version=>'2.0'), 'com.wideplay.warp:warp-persist:jar:2.0-20090214', 'com.sun.jersey:jersey-guice:jar:1.1.4.1', + 'aopalliance:aopalliance:jar:1.0', 'javax.servlet:servlet-api:jar:2.5'] @@ -62,18 +63,15 @@ define "candlepin" do project.group = GROUP manifest["Implementation-Vendor"] = COPYRIGHT compile.options.target = '1.5' - # Add classpath dependencies - # - compile.with COMMONS, DB, JERSEY, JUNIT, LOG4J, HIBERNATE, BOUNCYCASTLE, JDOM, GUICE - test.with COMMONS, DB, JERSEY, JUNIT, LOG4J, HIBERNATE, BOUNCYCASTLE, JDOM, DOM4J, HSQLDB, GUICE - - javadoc projects - package :war - #define "fbuild" do - #end - - #define "code" do - #end + compile.with COMMONS, DB, JERSEY, LOG4J, HIBERNATE, BOUNCYCASTLE, JDOM, GUICE + test.setup do |task| + filter('src/test/java').exclude('*.java').into('target/test/classes').run + filter('src/main/webapp/META-INF').into('target/classes/META-INF').run + end + test.teardown { rm_rf 'target/classes/META-INF' } + test.with COMMONS, DB, JERSEY, JUNIT, LOG4J, HIBERNATE, BOUNCYCASTLE, JDOM, DOM4J, HSQLDB, GUICE + #javadoc projects + package(:war) end diff --git a/proxy/code/src/org/fedoraproject/candlepin/guice/JPAInitializer.java b/proxy/code/src/org/fedoraproject/candlepin/guice/JPAInitializer.java deleted file mode 100644 index ab98d3b..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/guice/JPAInitializer.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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.guice; - -import com.google.inject.Inject; -import com.wideplay.warp.persist.PersistenceService; - -/** - * Initializes the JPA service - */ -public class JPAInitializer { - /** - * Initializes the JPA service. - * @param service to be initialized. - */ - @Inject - protected JPAInitializer(PersistenceService service) { - service.start(); - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/guice/JerseyGuiceConfiguration.java b/proxy/code/src/org/fedoraproject/candlepin/guice/JerseyGuiceConfiguration.java deleted file mode 100644 index 55b64f2..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/guice/JerseyGuiceConfiguration.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.guice; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.servlet.GuiceServletContextListener; -import com.google.inject.servlet.ServletModule; -import com.sun.jersey.guice.spi.container.servlet.GuiceContainer; -import com.wideplay.warp.persist.PersistenceService; -import com.wideplay.warp.persist.UnitOfWork; - -/** - * configure Guice with the resource classes. - */ -public class JerseyGuiceConfiguration extends GuiceServletContextListener { - - /** {@inheritDoc} */ - @Override - protected Injector getInjector() { - return Guice.createInjector( - PersistenceService.usingJpa() - .across(UnitOfWork.TRANSACTION) - .buildModule(), - - new CandlepinProductionConfiguration(), - - new ServletModule() { - /** {@inheritDoc} */ - @Override - protected void configureServlets() { - serve("/*").with(GuiceContainer.class); - } - }); - } - -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/AbstractHibernateCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/AbstractHibernateCurator.java deleted file mode 100644 index 38500c8..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/AbstractHibernateCurator.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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.model; - -import java.io.Serializable; -import java.util.List; - -import javax.persistence.EntityManager; - -import org.hibernate.Session; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.wideplay.warp.persist.Transactional; - -public abstract class AbstractHibernateCurator { - @Inject protected Provider entityManager; - private final Class entityType; - - protected AbstractHibernateCurator(Class entityType) { - //entityType = (Class) ((ParameterizedType) - //getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - this.entityType = entityType; - } - - public E find(Serializable id) { - return id == null ? null : get(entityType, id); - } - - @Transactional - public E create(E entity) { - save(entity); - flush(); - return entity; - } - - @SuppressWarnings("unchecked") - @Transactional() - public List findAll() { - return (List) currentSession().createCriteria(entityType).list(); - } - - @Transactional - public void delete(E entity) { - E toDelete = find(entity.getId()); - currentSession().delete(toDelete); - } - - protected final T get(Class clazz, Serializable id) { - return clazz.cast(currentSession().get(clazz, id)); - } - - protected final void save(Object anObject) { - getEntityManager().persist(anObject); - } - - protected final void flush() { - getEntityManager().flush(); - } - - protected Session currentSession() { - return (Session) entityManager.get().getDelegate(); - } - - protected EntityManager getEntityManager() { - return entityManager.get(); - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Certificate.java b/proxy/code/src/org/fedoraproject/candlepin/model/Certificate.java deleted file mode 100644 index 4938f87..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Certificate.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * 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.model; - - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; -import javax.persistence.Lob; -import javax.persistence.Id; -import javax.persistence.Column; - -import org.hibernate.annotations.ForeignKey; - - -@XmlRootElement -@XmlAccessorType(XmlAccessType.PROPERTY) -@Entity -@Table(name = "cp_certificate") -@SequenceGenerator(name="seq_certificate", sequenceName="seq_certificate", allocationSize=1) -public class Certificate implements Persisted { - - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_certificate") - private Long id; - - - @Lob - @Column(name = "certificate_blob") - private String certificate; - - - @ManyToOne - @ForeignKey(name = "fk_certificate_owner") - @JoinColumn(nullable = false) - private Owner owner; - - - public Certificate(String certificateIn, Owner ownerIn) { - certificate = certificateIn; - owner = ownerIn; - } - - public Certificate() { - } - - /** - * @return certficate blob - */ - public String getCertificate() { - return certificate; - } - - /** - * - * @param certificate the certificate's content. - */ - public void setCertificate(String certificate) { - this.certificate = certificate; - } - /** - * @return the id - */ - public Long getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(Long id) { - this.id = id; - } - - /** - * @return the owner - */ - @XmlTransient - public Owner getOwner() { - return owner; - } - - /** - * @param ownerIn the owner to set - */ - public void setOwner(Owner ownerIn) { - this.owner = ownerIn; - } - - -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/CertificateCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/CertificateCurator.java deleted file mode 100644 index 0d1e209..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/CertificateCurator.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * 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.model; - - -/** - * Handles the Certificate operations. - */ -public class CertificateCurator extends AbstractHibernateCurator { - - protected CertificateCurator() { - super(Certificate.class); - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerCurator.java deleted file mode 100644 index 8569a1b..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerCurator.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * 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.model; - -import java.util.HashSet; -import java.util.Set; - -import org.hibernate.criterion.Restrictions; - -import com.google.inject.Inject; -import com.wideplay.warp.persist.Transactional; - -public class ConsumerCurator extends AbstractHibernateCurator { - - @Inject private ConsumerInfoCurator consumerInfoCurator; - @Inject private ProductCurator productCurator; - @Inject private EntitlementCurator entitlementCurator; - - protected ConsumerCurator() { - super(Consumer.class); - } - - public Consumer lookupByName(String name) { - return (Consumer) currentSession().createCriteria(Consumer.class) - .add(Restrictions.like("name", name)) - .uniqueResult(); - } - - public Consumer lookupByUuid(String uuid) { - return (Consumer) currentSession().createCriteria(Consumer.class) - .add(Restrictions.like("uuid", uuid)) - .uniqueResult(); - } - - @Transactional - public Consumer update(Consumer updatedConsumer) { - Consumer existingConsumer = find(updatedConsumer.getId()); - if (existingConsumer == null) { - return create(updatedConsumer); - } - - // TODO: Are any of these read-only? - existingConsumer.setChildConsumers(bulkUpdate(updatedConsumer.getChildConsumers())); - existingConsumer.setConsumedProducts(productCurator.bulkUpdate(updatedConsumer.getConsumedProducts())); - existingConsumer.setEntitlements(entitlementCurator.bulkUpdate(updatedConsumer.getEntitlements())); - existingConsumer.setInfo(consumerInfoCurator.update(updatedConsumer.getInfo())); - existingConsumer.setName(updatedConsumer.getName()); - existingConsumer.setOwner(updatedConsumer.getOwner()); - existingConsumer.setParent(updatedConsumer.getParent()); - existingConsumer.setType(updatedConsumer.getType()); - existingConsumer.setUuid(updatedConsumer.getUuid()); - save(existingConsumer); - - return existingConsumer; - } - - @Transactional - public Set bulkUpdate(Set consumers) { - Set toReturn = new HashSet(); - for(Consumer toUpdate: consumers) { - toReturn.add(update(toUpdate)); - } - return toReturn; - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfoCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfoCurator.java deleted file mode 100644 index c861d23..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfoCurator.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.fedoraproject.candlepin.model; - -import com.wideplay.warp.persist.Transactional; - -public class ConsumerInfoCurator extends AbstractHibernateCurator { - public ConsumerInfoCurator() { - super(ConsumerInfo.class); - } - - @Transactional - public ConsumerInfo update(ConsumerInfo updated) { - return getEntityManager().merge(updated); - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerTypeCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerTypeCurator.java deleted file mode 100644 index 3c8f859..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerTypeCurator.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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.model; - -import org.hibernate.criterion.Restrictions; - -public class ConsumerTypeCurator extends AbstractHibernateCurator { - - protected ConsumerTypeCurator() { - super(ConsumerType.class); - } - - public ConsumerType lookupByLabel(String label) { - return (ConsumerType) currentSession().createCriteria(ConsumerType.class) - .add(Restrictions.eq("label", label)) - .uniqueResult(); - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementCurator.java deleted file mode 100644 index eeb987a..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementCurator.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.fedoraproject.candlepin.model; - -import java.util.HashSet; -import java.util.Set; - -import com.wideplay.warp.persist.Transactional; - -public class EntitlementCurator extends AbstractHibernateCurator { - public EntitlementCurator() { - super(Entitlement.class); - } - - // TODO: handles addition of new entitlements only atm! - @Transactional - public Set bulkUpdate(Set entitlements) { - Set toReturn = new HashSet(); - for(Entitlement toUpdate: entitlements) { - Entitlement found = find(toUpdate.getId()); - if(found != null) { - toReturn.add(found); - continue; - } - toReturn.add(create(toUpdate)); - } - return toReturn; - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPoolCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPoolCurator.java deleted file mode 100644 index 524f6ad..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPoolCurator.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * 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.model; - -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - -import org.hibernate.criterion.Restrictions; - -import com.wideplay.warp.persist.Transactional; - -public class EntitlementPoolCurator extends AbstractHibernateCurator { - - protected EntitlementPoolCurator() { - super(EntitlementPool.class); - } - - @SuppressWarnings("unchecked") - public List listByOwner(Owner o) { - List results = (List) currentSession() - .createCriteria(EntitlementPool.class) - .add(Restrictions.eq("owner", o)).list(); - if (results == null) { - return new LinkedList(); - } - else { - return results; - } - } - - public EntitlementPool lookupByOwnerAndProduct(Owner owner, Product product) { - return (EntitlementPool) currentSession().createCriteria(EntitlementPool.class) - .add(Restrictions.eq("owner", owner)) - .add(Restrictions.eq("product", product)) - .uniqueResult(); - } - - /** - * Create an entitlement. - * - * @param entPool - * @param consumer - * @return - */ - @Transactional - public Entitlement createEntitlement(EntitlementPool entPool, Consumer consumer) { - Entitlement e = new Entitlement(entPool, consumer.getOwner(), new Date()); - entPool.bumpCurrentMembers(); - consumer.addEntitlement(e); - consumer.addConsumedProduct(entPool.getProduct()); - e.setOwner(consumer.getOwner()); - - save(e); - flush(); - - return e; - } - - @Transactional - public EntitlementPool create(EntitlementPool entity) { - - // Make sure there isn't already a pool for this product. Ideally we'd catch - // this with a database constraint but I don't see how to do that just yet. - EntitlementPool existing = lookupByOwnerAndProduct(entity.getOwner(), - entity.getProduct()); - if (existing != null) { - throw new RuntimeException("Already an entitlement pool for owner " + - entity.getOwner().getName() + " and product " + - entity.getProduct().getLabel()); - } - - return super.create(entity); - } - - -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/OwnerCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/OwnerCurator.java deleted file mode 100644 index 422e2ad..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/OwnerCurator.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.model; - -import java.util.LinkedList; -import java.util.List; - -import org.hibernate.criterion.Restrictions; - -public class OwnerCurator extends AbstractHibernateCurator { - - protected OwnerCurator() { - super(Owner.class); - } - - public Owner lookupByName(String name) { - return (Owner) currentSession().createCriteria(Owner.class) - .add(Restrictions.like("name", name)) - .uniqueResult(); - } - - @SuppressWarnings("unchecked") - public List listAll() { - List results = (List) currentSession() - .createCriteria(Owner.class).list(); - if (results == null) { - return new LinkedList(); - } - else { - return results; - } - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Persisted.java b/proxy/code/src/org/fedoraproject/candlepin/model/Persisted.java deleted file mode 100644 index 8accf5a..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Persisted.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.fedoraproject.candlepin.model; - -import java.io.Serializable; - -public interface Persisted { - public Serializable getId(); -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ProductCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/ProductCurator.java deleted file mode 100644 index 9bd2144..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ProductCurator.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * 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.model; - -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import org.hibernate.criterion.Restrictions; - -import com.wideplay.warp.persist.Transactional; - -public class ProductCurator extends AbstractHibernateCurator { - - public ProductCurator() { - 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(); - } - - @SuppressWarnings("unchecked") - public List listAll() { - List results = (List) currentSession() - .createCriteria(Product.class).list(); - if (results == null) { - return new LinkedList(); - } - else { - return results; - } - } - - @Transactional - public Product update(Product updated) { - Product existingProduct = find(updated.getId()); - if (existingProduct == null) { - return create(updated); - } - - if (updated.getChildProducts() != null) { - existingProduct.setChildProducts(bulkUpdate(updated.getChildProducts())); - } - existingProduct.setLabel(updated.getLabel()); - existingProduct.setName(updated.getName()); - save(existingProduct); - flush(); - - return existingProduct; - } - - @Transactional - public Set bulkUpdate(Set products) { - Set toReturn = new HashSet(); - for(Product toUpdate: products) { - toReturn.add(update(toUpdate)); - } - return toReturn; - } - -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/UserCurator.java b/proxy/code/src/org/fedoraproject/candlepin/model/UserCurator.java deleted file mode 100644 index 07c8893..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/UserCurator.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * 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.model; - -public class UserCurator extends AbstractHibernateCurator { - - protected UserCurator() { - super(User.class); - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/CertificateTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/CertificateTest.java deleted file mode 100644 index fbcb191..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/CertificateTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * 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.model.test; - -import static org.junit.Assert.*; - -import java.util.List; - -import org.fedoraproject.candlepin.model.Certificate; -import org.fedoraproject.candlepin.model.Owner; -import org.fedoraproject.candlepin.test.DatabaseTestFixture; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - - -public class CertificateTest extends DatabaseTestFixture { - - @Before - public void setUpTestObjects() { - - String ownerName = "Example Corporation"; - Owner owner = new Owner(ownerName); - - ownerCurator.create(owner); - certificateCurator.create( - new Certificate("This is not actually a certificate. No entitlements for you!", owner)); - } - - - @Ignore - public void testGetCertificate() { - Certificate newCertificate = new Certificate(); - } - - @Test - public void testList() throws Exception { - List certificates = certificateCurator.findAll(); - int beforeCount = certificates.size(); - - for (int i = 0; i < 10; i++) { - Owner owner = new Owner("owner" + i); - ownerCurator.create(owner); - certificateCurator.create(new Certificate("this is a test", owner)); - } - - certificates = certificateCurator.findAll(); - int afterCount = certificates.size(); - assertEquals(10, afterCount - beforeCount); - } - - @Test - public void testLookup() throws Exception { - - Owner owner = new Owner("test company"); - Certificate certificate = new Certificate("not a cert", owner); - - ownerCurator.create(owner); - certificateCurator.create(certificate); - - Certificate lookedUp = certificateCurator.find(certificate.getId()); - - assertEquals(certificate.getId(), lookedUp.getId()); - assertEquals(certificate.getCertificate(), lookedUp.getCertificate()); - } -} - diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java deleted file mode 100644 index 3279216..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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.model.test; - -import static org.junit.Assert.*; - -import org.fedoraproject.candlepin.model.EntitlementPool; -import org.fedoraproject.candlepin.model.Owner; -import org.fedoraproject.candlepin.model.Product; -import org.fedoraproject.candlepin.test.DatabaseTestFixture; -import org.fedoraproject.candlepin.test.TestUtil; -import org.junit.Before; -import org.junit.Test; - - -public class EntitlementPoolTest extends DatabaseTestFixture { - - private EntitlementPool pool; - private Product prod; - private Owner owner; - - @Before - public void createObjects() { - beginTransaction(); - - pool = TestUtil.createEntitlementPool(); - owner = pool.getOwner(); - prod = pool.getProduct(); - entityManager().persist(owner); - entityManager().persist(prod); - entityManager().persist(pool); - - commitTransaction(); - } - - @Test - public void testCreate() { - EntitlementPool lookedUp = (EntitlementPool)entityManager().find(EntitlementPool.class, - pool.getId()); - assertNotNull(lookedUp); - assertEquals(owner.getId(), lookedUp.getOwner().getId()); - assertEquals(prod.getId(), lookedUp.getProduct().getId()); - } - -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/UserTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/UserTest.java deleted file mode 100644 index 4e8ea1d..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/UserTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.model.test; - -import static org.junit.Assert.*; - -import org.fedoraproject.candlepin.model.Owner; -import org.fedoraproject.candlepin.model.User; -import org.fedoraproject.candlepin.test.DatabaseTestFixture; -import org.junit.Test; - -public class UserTest extends DatabaseTestFixture { - - @Test - public void testCreate() throws Exception { - String ownerName = "Example Corporation"; - Owner o = new Owner(ownerName); - - String username = "TESTUSER"; - String password = "sekretpassword"; - User user = new User(o, username, password); - - beginTransaction(); - entityManager().persist(o); - entityManager().persist(user); - commitTransaction(); - - User lookedUp = (User)entityManager().find(User.class, user.getId()); - assertEquals(username, lookedUp.getLogin()); - assertEquals(password, lookedUp.getPassword()); - } - -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/test/CandlepinTestingModule.java b/proxy/code/src/org/fedoraproject/candlepin/resource/test/CandlepinTestingModule.java deleted file mode 100644 index 96e9f2f..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/resource/test/CandlepinTestingModule.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.fedoraproject.candlepin.resource.test; - -import org.fedoraproject.candlepin.guice.JPAInitializer; - -import com.google.inject.AbstractModule; -import com.wideplay.warp.persist.jpa.JpaUnit; - -public class CandlepinTestingModule extends AbstractModule { - - @Override - public void configure() { - - bind(JPAInitializer.class).asEagerSingleton(); - bindConstant().annotatedWith(JpaUnit.class).to("test"); - - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java b/proxy/code/src/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java deleted file mode 100644 index f835046..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * 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 static org.junit.Assert.*; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.List; - -import org.fedoraproject.candlepin.model.CertificateCurator; -import org.fedoraproject.candlepin.model.ConsumerCurator; -import org.fedoraproject.candlepin.model.EntitlementPool; -import org.fedoraproject.candlepin.model.EntitlementPoolCurator; -import org.fedoraproject.candlepin.model.Owner; -import org.fedoraproject.candlepin.model.OwnerCurator; -import org.fedoraproject.candlepin.model.Product; -import org.fedoraproject.candlepin.model.ProductCurator; -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 com.google.inject.Guice; -import com.google.inject.Injector; -import com.wideplay.warp.persist.PersistenceService; -import com.wideplay.warp.persist.UnitOfWork; - -public class CertificateResourceTest extends DatabaseTestFixture { - - private CertificateResource certResource; - private CertificateCurator certificateCurator; - private ConsumerCurator consumerRepository; - private EntitlementPoolCurator epCurator; - private ProductCurator productCurator; - private OwnerCurator ownerCurator; - private String sampleCertXml; - - @Before - public void createObjects() throws Exception { - - Injector injector = Guice.createInjector( - new CandlepinTestingModule(), - PersistenceService.usingJpa() - .across(UnitOfWork.TRANSACTION) - .buildModule() - ); - - consumerRepository = injector.getInstance(ConsumerCurator.class); - epCurator = injector.getInstance(EntitlementPoolCurator.class); - productCurator = injector.getInstance(ProductCurator.class); - ownerCurator = injector.getInstance(OwnerCurator.class); - certificateCurator = injector.getInstance(CertificateCurator.class); - - certResource = new CertificateResource(ownerCurator, productCurator, epCurator, certificateCurator); - - 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 ownerCreated() { - certResource.upload(TestUtil.xmlToBase64String(sampleCertXml)); - Owner owner = ownerCurator.lookupByName("Spacewalk Public Cert"); -// certResource.upload(TestUtil.xmlToBase64String(sampleCertXml)); - assertNotNull(owner); - } - - @Test - public void simpleUploadCertProductsCreated() { - certResource.upload(TestUtil.xmlToBase64String(sampleCertXml)); - List products = productCurator.listAll(); - assertEquals(5, products.size()); - } - - @Test - public void entitlementPoolCreation() { - String encoded = TestUtil.xmlToBase64String(sampleCertXml); - certResource.upload(encoded); - Owner owner = ownerCurator.lookupByName("Spacewalk Public Cert"); - List entPools = epCurator.listByOwner(owner); - assertEquals(5, entPools.size()); - } - - @Test - public void channelFamilyCreation() { - // TODO!!!!!! Current test cert has no channel families. - } - - @Test - public void uploadCertWithPreExistingProducts() { - // TODO - } - -} 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 deleted file mode 100644 index 4d63ab3..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert +++ /dev/null @@ -1,23 +0,0 @@ - - - SPACEWALK-001 - Spacewalk Public Cert - 2007-07-13 00:00:00 - 2010-07-13 00:00:00 - 20000 - 20000 - 20000 - 20000 - 20000 - spacewalk - 2 - ------BEGIN PGP SIGNATURE----- -Version: Crypt::OpenPGP 1.03 - -iQBGBAARAwAGBQJIUsb7AAoJEJ5yna8GlHkyi50Anjh4/GHHPoOUKO6LdDaE2ZcJ -X69tAJ41s97D66gXGvk244vkmSMajJT2hg== -=oOTl ------END PGP SIGNATURE----- - - diff --git a/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java b/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java deleted file mode 100644 index 289d9bb..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.fedoraproject.candlepin.test; - -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; - -import org.fedoraproject.candlepin.model.Certificate; -import org.fedoraproject.candlepin.model.CertificateCurator; -import org.fedoraproject.candlepin.model.Consumer; -import org.fedoraproject.candlepin.model.ConsumerCurator; -import org.fedoraproject.candlepin.model.ConsumerType; -import org.fedoraproject.candlepin.model.ConsumerTypeCurator; -import org.fedoraproject.candlepin.model.Entitlement; -import org.fedoraproject.candlepin.model.EntitlementPool; -import org.fedoraproject.candlepin.model.EntitlementPoolCurator; -import org.fedoraproject.candlepin.model.Owner; -import org.fedoraproject.candlepin.model.OwnerCurator; -import org.fedoraproject.candlepin.model.Product; -import org.fedoraproject.candlepin.model.ProductCurator; -import org.fedoraproject.candlepin.model.User; -import org.fedoraproject.candlepin.resource.test.CandlepinTestingModule; -import org.junit.After; -import org.junit.Before; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.wideplay.warp.persist.PersistenceService; -import com.wideplay.warp.persist.UnitOfWork; - -/** - * Test fixture for test classes requiring access to the database. - */ -public class DatabaseTestFixture { - - protected EntityManagerFactory emf; - protected Injector injector; - - protected OwnerCurator ownerCurator; - protected ProductCurator productCurator; - protected ConsumerCurator consumerCurator; - protected ConsumerTypeCurator consumerTypeCurator; - protected CertificateCurator certificateCurator; - protected EntitlementPoolCurator entitlementPoolCurator; - - - @Before - public void setUp() { - injector = Guice.createInjector( - new CandlepinTestingModule(), - PersistenceService.usingJpa() - .across(UnitOfWork.TRANSACTION) - .buildModule() - ); - - injector.getInstance(EntityManagerFactory.class); - emf = injector.getProvider(EntityManagerFactory.class).get(); - - ownerCurator = injector.getInstance(OwnerCurator.class); - productCurator = injector.getInstance(ProductCurator.class); - consumerCurator = injector.getInstance(ConsumerCurator.class); - consumerTypeCurator = injector.getInstance(ConsumerTypeCurator.class); - certificateCurator = injector.getInstance(CertificateCurator.class); - entitlementPoolCurator = injector.getInstance(EntitlementPoolCurator.class); - } - - /* - * As long as we are using in-memory db we don't need to clean it out; - * a new instance will be created for each test. cleanDb() is *not* being currently invoked. - * - * Cleans out everything in the database. Currently we test against an - * in-memory hsqldb, so this should be ok. - * - * WARNING: Don't flip the persistence unit to point to an actual live - * DB or you'll lose everything. - * - * WARNING: If you're creating objects in tables that have static - * pre-populated content, we may not want to wipe those tables here. - * This situation hasn't arisen yet. - */ - @SuppressWarnings("unchecked") - public void cleanDb() { - EntityManager em = entityManager(); - if (!em.getTransaction().isActive()) { - beginTransaction(); - } - - List users = em.createQuery("from User u").getResultList(); - for (User u : users) { - em.remove(u); - } - - List ents = em.createQuery("from Entitlement e"). - getResultList(); - for (Entitlement e : ents) { - em.remove(e); - } - - List pools = em.createQuery("from EntitlementPool p").getResultList(); - for (EntitlementPool p : pools) { - em.remove(p); - } - - // TODO: Would rather be doing this, but such a bulk delete does not seem to respect - // the cascade to child products and thus fails. - // em.createQuery("delete from Product").executeUpdate(); - List products = em.createQuery("from Product p").getResultList(); - for (Product p : products) { - em.remove(p); - } - - List consumers = em.createQuery("from Consumer c").getResultList(); - for (Consumer c : consumers) { - em.remove(c); - } - - List certificates = em.createQuery("from Certificate c").getResultList(); - for (Certificate c : certificates){ - em.remove(c); - } - - List owners = em.createQuery("from Owner o").getResultList(); - for (Owner o : owners) { - em.remove(o); - } - -// List consumerInfos = em.createQuery("from ConsumerInfo c").getResultList(); -// for (ConsumerInfo c : consumerInfos) { -// em.remove(c); -// } - - // TODO: Is this right? Or should we pre-populate default defined types, and always - // reference these in the tests instead of creating them everywhere? - List consumerTypes = em.createQuery("from ConsumerType c"). - getResultList(); - for (ConsumerType c : consumerTypes) { - em.remove(c); - } - - - - commitTransaction(); - em.close(); - } - - protected EntityManager entityManager() { - return injector.getProvider(EntityManager.class).get(); - } - - /** - * Begin a transaction, persist the given entity, and commit. - * - * @param storeMe Entity to persist. - */ - protected void persistAndCommit(Object storeMe) { - EntityTransaction tx = null; - - try { - tx = entityManager().getTransaction(); - tx.begin(); - entityManager().persist(storeMe); - tx.commit(); - } - catch (RuntimeException e) { - if (tx != null && tx.isActive()) { - tx.rollback(); - } - throw e; // or display error message - } - } - - /** - * Helper to open a new db transaction. Pretty simple for now, but may - * require additional logic and error handling down the road. - */ - protected void beginTransaction() { - entityManager().getTransaction().begin(); - } - - /** - * Helper to commit the current db transaction. Pretty simple for now, but may - * require additional logic and error handling down the road. - */ - protected void commitTransaction() { - entityManager().getTransaction().commit(); - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java b/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java deleted file mode 100644 index 21b005e..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * 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.test; - -import java.sql.Date; -import java.util.Calendar; -import java.util.Random; - -import org.apache.commons.codec.binary.Base64; -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; -import org.fedoraproject.candlepin.model.User; - -/** - * 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 " + randomInt()); -// o.setUuid(lookedUp); - ObjectFactory.get().store(o); - return o; - } - - public static Consumer createConsumer(ConsumerType type, Owner owner) { - Consumer c = new Consumer("Test Consumer " + randomInt(), owner, type); - ObjectFactory.get().store(c); - return c; - } - - /** - * Create a consumer with a new owner - * @return Consumer - */ - public static Consumer createConsumer() { - return createConsumer(createConsumerType(), createOwner()); - } - - public static ConsumerType createConsumerType() { - return new ConsumerType("test-consumer-type-" + randomInt()); - } - - public static int randomInt() { - return new Random().nextInt(10000); - } - - public static Product createProduct() { - 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 User createUser(Owner owner) { - User u = new User(owner, "testuser" + randomInt(), "sekret"); - return u; - } - - 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; - } - - public static String xmlToBase64String(String xml) { - -// byte[] bytes = Base64.encode(xml); - Base64 encoder = new Base64(); - byte [] bytes = encoder.encode(xml.getBytes()); - - StringBuffer buf = new StringBuffer(); - for (byte b : bytes) { - buf.append((char) Integer.parseInt(Integer.toHexString(b), 16)); - } - - return buf.toString(); - } - -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/util/Util.java b/proxy/code/src/org/fedoraproject/candlepin/util/Util.java deleted file mode 100644 index 3dd59f0..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/util/Util.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.fedoraproject.candlepin.util; - -import java.util.UUID; - -/** - * Genuinely random utilities. - */ -public class Util { - - public static String generateUUID() { - return UUID.randomUUID().toString(); - } - -} diff --git a/proxy/code/webapp/certs/certificates.readme b/proxy/code/webapp/certs/certificates.readme deleted file mode 100644 index 0039145..0000000 --- a/proxy/code/webapp/certs/certificates.readme +++ /dev/null @@ -1,22 +0,0 @@ -to generate certificates: - -keytool -genkeypair -alias servercert -keyalg RSA -dname "CN=Web Server,OU=Unit,O=Organization,L=City,S=State,C=US" -keypass password -keystore server.jks -storepass password -keytool -genkeypair -alias clientcert -keystore clientcert.p12 -storetype pkcs12 -keyalg RSA -dname "CN=Client,OU=Unit,O=Organization,L=City,S=State,C=US" -keypass password -storepass password -keytool -exportcert -alias %1 -file clientcert.cer -keystore clientcert.p12 -storetype pkcs12 -storepass password -keytool -importcert -keystore server.jks -alias clientcert -file clientcert.cer -v -trustcacerts -noprompt -storepass password - -tomcat connector configuration: - - - -install client certificate into your browser of choice, and you should be good to go! \ No newline at end of file diff --git a/proxy/code/webapp/certs/rest_api_test.jks b/proxy/code/webapp/certs/rest_api_test.jks deleted file mode 100644 index b055808..0000000 Binary files a/proxy/code/webapp/certs/rest_api_test.jks and /dev/null differ diff --git a/proxy/code/webapp/certs/rest_client_test.p12 b/proxy/code/webapp/certs/rest_client_test.p12 deleted file mode 100644 index f2d100e..0000000 Binary files a/proxy/code/webapp/certs/rest_client_test.p12 and /dev/null differ diff --git a/proxy/code/webapp/certs/server.xml b/proxy/code/webapp/certs/server.xml deleted file mode 100644 index 85ab0e1..0000000 --- a/proxy/code/webapp/certs/server.xml +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/guice/JPAInitializer.java b/proxy/src/main/java/org/fedoraproject/candlepin/guice/JPAInitializer.java new file mode 100644 index 0000000..ab98d3b --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/guice/JPAInitializer.java @@ -0,0 +1,32 @@ +/** + * 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.guice; + +import com.google.inject.Inject; +import com.wideplay.warp.persist.PersistenceService; + +/** + * Initializes the JPA service + */ +public class JPAInitializer { + /** + * Initializes the JPA service. + * @param service to be initialized. + */ + @Inject + protected JPAInitializer(PersistenceService service) { + service.start(); + } +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/guice/JerseyGuiceConfiguration.java b/proxy/src/main/java/org/fedoraproject/candlepin/guice/JerseyGuiceConfiguration.java new file mode 100644 index 0000000..55b64f2 --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/guice/JerseyGuiceConfiguration.java @@ -0,0 +1,49 @@ +/** + * 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.guice; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.servlet.GuiceServletContextListener; +import com.google.inject.servlet.ServletModule; +import com.sun.jersey.guice.spi.container.servlet.GuiceContainer; +import com.wideplay.warp.persist.PersistenceService; +import com.wideplay.warp.persist.UnitOfWork; + +/** + * configure Guice with the resource classes. + */ +public class JerseyGuiceConfiguration extends GuiceServletContextListener { + + /** {@inheritDoc} */ + @Override + protected Injector getInjector() { + return Guice.createInjector( + PersistenceService.usingJpa() + .across(UnitOfWork.TRANSACTION) + .buildModule(), + + new CandlepinProductionConfiguration(), + + new ServletModule() { + /** {@inheritDoc} */ + @Override + protected void configureServlets() { + serve("/*").with(GuiceContainer.class); + } + }); + } + +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/AbstractHibernateCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/AbstractHibernateCurator.java new file mode 100644 index 0000000..38500c8 --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/AbstractHibernateCurator.java @@ -0,0 +1,80 @@ +/** + * 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.model; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.EntityManager; + +import org.hibernate.Session; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.wideplay.warp.persist.Transactional; + +public abstract class AbstractHibernateCurator { + @Inject protected Provider entityManager; + private final Class entityType; + + protected AbstractHibernateCurator(Class entityType) { + //entityType = (Class) ((ParameterizedType) + //getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + this.entityType = entityType; + } + + public E find(Serializable id) { + return id == null ? null : get(entityType, id); + } + + @Transactional + public E create(E entity) { + save(entity); + flush(); + return entity; + } + + @SuppressWarnings("unchecked") + @Transactional() + public List findAll() { + return (List) currentSession().createCriteria(entityType).list(); + } + + @Transactional + public void delete(E entity) { + E toDelete = find(entity.getId()); + currentSession().delete(toDelete); + } + + protected final T get(Class clazz, Serializable id) { + return clazz.cast(currentSession().get(clazz, id)); + } + + protected final void save(Object anObject) { + getEntityManager().persist(anObject); + } + + protected final void flush() { + getEntityManager().flush(); + } + + protected Session currentSession() { + return (Session) entityManager.get().getDelegate(); + } + + protected EntityManager getEntityManager() { + return entityManager.get(); + } +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/Certificate.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/Certificate.java new file mode 100644 index 0000000..4938f87 --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/Certificate.java @@ -0,0 +1,112 @@ +/** + * 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.model; + + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Lob; +import javax.persistence.Id; +import javax.persistence.Column; + +import org.hibernate.annotations.ForeignKey; + + +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +@Entity +@Table(name = "cp_certificate") +@SequenceGenerator(name="seq_certificate", sequenceName="seq_certificate", allocationSize=1) +public class Certificate implements Persisted { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_certificate") + private Long id; + + + @Lob + @Column(name = "certificate_blob") + private String certificate; + + + @ManyToOne + @ForeignKey(name = "fk_certificate_owner") + @JoinColumn(nullable = false) + private Owner owner; + + + public Certificate(String certificateIn, Owner ownerIn) { + certificate = certificateIn; + owner = ownerIn; + } + + public Certificate() { + } + + /** + * @return certficate blob + */ + public String getCertificate() { + return certificate; + } + + /** + * + * @param certificate the certificate's content. + */ + public void setCertificate(String certificate) { + this.certificate = certificate; + } + /** + * @return the id + */ + public Long getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(Long id) { + this.id = id; + } + + /** + * @return the owner + */ + @XmlTransient + public Owner getOwner() { + return owner; + } + + /** + * @param ownerIn the owner to set + */ + public void setOwner(Owner ownerIn) { + this.owner = ownerIn; + } + + +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/CertificateCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/CertificateCurator.java new file mode 100644 index 0000000..0d1e209 --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/CertificateCurator.java @@ -0,0 +1,26 @@ +/** + * 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.model; + + +/** + * Handles the Certificate operations. + */ +public class CertificateCurator extends AbstractHibernateCurator { + + protected CertificateCurator() { + super(Certificate.class); + } +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerCurator.java new file mode 100644 index 0000000..8569a1b --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerCurator.java @@ -0,0 +1,77 @@ +/** + * 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.model; + +import java.util.HashSet; +import java.util.Set; + +import org.hibernate.criterion.Restrictions; + +import com.google.inject.Inject; +import com.wideplay.warp.persist.Transactional; + +public class ConsumerCurator extends AbstractHibernateCurator { + + @Inject private ConsumerInfoCurator consumerInfoCurator; + @Inject private ProductCurator productCurator; + @Inject private EntitlementCurator entitlementCurator; + + protected ConsumerCurator() { + super(Consumer.class); + } + + public Consumer lookupByName(String name) { + return (Consumer) currentSession().createCriteria(Consumer.class) + .add(Restrictions.like("name", name)) + .uniqueResult(); + } + + public Consumer lookupByUuid(String uuid) { + return (Consumer) currentSession().createCriteria(Consumer.class) + .add(Restrictions.like("uuid", uuid)) + .uniqueResult(); + } + + @Transactional + public Consumer update(Consumer updatedConsumer) { + Consumer existingConsumer = find(updatedConsumer.getId()); + if (existingConsumer == null) { + return create(updatedConsumer); + } + + // TODO: Are any of these read-only? + existingConsumer.setChildConsumers(bulkUpdate(updatedConsumer.getChildConsumers())); + existingConsumer.setConsumedProducts(productCurator.bulkUpdate(updatedConsumer.getConsumedProducts())); + existingConsumer.setEntitlements(entitlementCurator.bulkUpdate(updatedConsumer.getEntitlements())); + existingConsumer.setInfo(consumerInfoCurator.update(updatedConsumer.getInfo())); + existingConsumer.setName(updatedConsumer.getName()); + existingConsumer.setOwner(updatedConsumer.getOwner()); + existingConsumer.setParent(updatedConsumer.getParent()); + existingConsumer.setType(updatedConsumer.getType()); + existingConsumer.setUuid(updatedConsumer.getUuid()); + save(existingConsumer); + + return existingConsumer; + } + + @Transactional + public Set bulkUpdate(Set consumers) { + Set toReturn = new HashSet(); + for(Consumer toUpdate: consumers) { + toReturn.add(update(toUpdate)); + } + return toReturn; + } +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerInfoCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerInfoCurator.java new file mode 100644 index 0000000..c861d23 --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerInfoCurator.java @@ -0,0 +1,14 @@ +package org.fedoraproject.candlepin.model; + +import com.wideplay.warp.persist.Transactional; + +public class ConsumerInfoCurator extends AbstractHibernateCurator { + public ConsumerInfoCurator() { + super(ConsumerInfo.class); + } + + @Transactional + public ConsumerInfo update(ConsumerInfo updated) { + return getEntityManager().merge(updated); + } +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerTypeCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerTypeCurator.java new file mode 100644 index 0000000..3c8f859 --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerTypeCurator.java @@ -0,0 +1,30 @@ +/** + * 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.model; + +import org.hibernate.criterion.Restrictions; + +public class ConsumerTypeCurator extends AbstractHibernateCurator { + + protected ConsumerTypeCurator() { + super(ConsumerType.class); + } + + public ConsumerType lookupByLabel(String label) { + return (ConsumerType) currentSession().createCriteria(ConsumerType.class) + .add(Restrictions.eq("label", label)) + .uniqueResult(); + } +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/EntitlementCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/EntitlementCurator.java new file mode 100644 index 0000000..eeb987a --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/EntitlementCurator.java @@ -0,0 +1,27 @@ +package org.fedoraproject.candlepin.model; + +import java.util.HashSet; +import java.util.Set; + +import com.wideplay.warp.persist.Transactional; + +public class EntitlementCurator extends AbstractHibernateCurator { + public EntitlementCurator() { + super(Entitlement.class); + } + + // TODO: handles addition of new entitlements only atm! + @Transactional + public Set bulkUpdate(Set entitlements) { + Set toReturn = new HashSet(); + for(Entitlement toUpdate: entitlements) { + Entitlement found = find(toUpdate.getId()); + if(found != null) { + toReturn.add(found); + continue; + } + toReturn.add(create(toUpdate)); + } + return toReturn; + } +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/EntitlementPoolCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/EntitlementPoolCurator.java new file mode 100644 index 0000000..524f6ad --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/EntitlementPoolCurator.java @@ -0,0 +1,89 @@ +/** + * 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.model; + +import java.util.Date; +import java.util.LinkedList; +import java.util.List; + +import org.hibernate.criterion.Restrictions; + +import com.wideplay.warp.persist.Transactional; + +public class EntitlementPoolCurator extends AbstractHibernateCurator { + + protected EntitlementPoolCurator() { + super(EntitlementPool.class); + } + + @SuppressWarnings("unchecked") + public List listByOwner(Owner o) { + List results = (List) currentSession() + .createCriteria(EntitlementPool.class) + .add(Restrictions.eq("owner", o)).list(); + if (results == null) { + return new LinkedList(); + } + else { + return results; + } + } + + public EntitlementPool lookupByOwnerAndProduct(Owner owner, Product product) { + return (EntitlementPool) currentSession().createCriteria(EntitlementPool.class) + .add(Restrictions.eq("owner", owner)) + .add(Restrictions.eq("product", product)) + .uniqueResult(); + } + + /** + * Create an entitlement. + * + * @param entPool + * @param consumer + * @return + */ + @Transactional + public Entitlement createEntitlement(EntitlementPool entPool, Consumer consumer) { + Entitlement e = new Entitlement(entPool, consumer.getOwner(), new Date()); + entPool.bumpCurrentMembers(); + consumer.addEntitlement(e); + consumer.addConsumedProduct(entPool.getProduct()); + e.setOwner(consumer.getOwner()); + + save(e); + flush(); + + return e; + } + + @Transactional + public EntitlementPool create(EntitlementPool entity) { + + // Make sure there isn't already a pool for this product. Ideally we'd catch + // this with a database constraint but I don't see how to do that just yet. + EntitlementPool existing = lookupByOwnerAndProduct(entity.getOwner(), + entity.getProduct()); + if (existing != null) { + throw new RuntimeException("Already an entitlement pool for owner " + + entity.getOwner().getName() + " and product " + + entity.getProduct().getLabel()); + } + + return super.create(entity); + } + + +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/OwnerCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/OwnerCurator.java new file mode 100644 index 0000000..422e2ad --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/OwnerCurator.java @@ -0,0 +1,45 @@ +/** + * 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.model; + +import java.util.LinkedList; +import java.util.List; + +import org.hibernate.criterion.Restrictions; + +public class OwnerCurator extends AbstractHibernateCurator { + + protected OwnerCurator() { + super(Owner.class); + } + + public Owner lookupByName(String name) { + return (Owner) currentSession().createCriteria(Owner.class) + .add(Restrictions.like("name", name)) + .uniqueResult(); + } + + @SuppressWarnings("unchecked") + public List listAll() { + List results = (List) currentSession() + .createCriteria(Owner.class).list(); + if (results == null) { + return new LinkedList(); + } + else { + return results; + } + } +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/Persisted.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/Persisted.java new file mode 100644 index 0000000..8accf5a --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/Persisted.java @@ -0,0 +1,7 @@ +package org.fedoraproject.candlepin.model; + +import java.io.Serializable; + +public interface Persisted { + public Serializable getId(); +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/ProductCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/ProductCurator.java new file mode 100644 index 0000000..9bd2144 --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/ProductCurator.java @@ -0,0 +1,83 @@ +/** + * 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.model; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.hibernate.criterion.Restrictions; + +import com.wideplay.warp.persist.Transactional; + +public class ProductCurator extends AbstractHibernateCurator { + + public ProductCurator() { + 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(); + } + + @SuppressWarnings("unchecked") + public List listAll() { + List results = (List) currentSession() + .createCriteria(Product.class).list(); + if (results == null) { + return new LinkedList(); + } + else { + return results; + } + } + + @Transactional + public Product update(Product updated) { + Product existingProduct = find(updated.getId()); + if (existingProduct == null) { + return create(updated); + } + + if (updated.getChildProducts() != null) { + existingProduct.setChildProducts(bulkUpdate(updated.getChildProducts())); + } + existingProduct.setLabel(updated.getLabel()); + existingProduct.setName(updated.getName()); + save(existingProduct); + flush(); + + return existingProduct; + } + + @Transactional + public Set bulkUpdate(Set products) { + Set toReturn = new HashSet(); + for(Product toUpdate: products) { + toReturn.add(update(toUpdate)); + } + return toReturn; + } + +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/UserCurator.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/UserCurator.java new file mode 100644 index 0000000..07c8893 --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/UserCurator.java @@ -0,0 +1,22 @@ +/** + * 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.model; + +public class UserCurator extends AbstractHibernateCurator { + + protected UserCurator() { + super(User.class); + } +} diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/util/Util.java b/proxy/src/main/java/org/fedoraproject/candlepin/util/Util.java new file mode 100644 index 0000000..3dd59f0 --- /dev/null +++ b/proxy/src/main/java/org/fedoraproject/candlepin/util/Util.java @@ -0,0 +1,14 @@ +package org.fedoraproject.candlepin.util; + +import java.util.UUID; + +/** + * Genuinely random utilities. + */ +public class Util { + + public static String generateUUID() { + return UUID.randomUUID().toString(); + } + +} diff --git a/proxy/src/main/resources/META-INF/persistence.xml b/proxy/src/main/resources/META-INF/persistence.xml deleted file mode 100644 index 9c49dd9..0000000 --- a/proxy/src/main/resources/META-INF/persistence.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - org.hibernate.ejb.HibernatePersistence - - - - - - - - - - - - - - org.hibernate.ejb.HibernatePersistence - - - - - - - - - - - - - - diff --git a/proxy/src/main/resources/WEB-INF/web.xml b/proxy/src/main/resources/WEB-INF/web.xml deleted file mode 100644 index 1466d45..0000000 --- a/proxy/src/main/resources/WEB-INF/web.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - Jersey Web Application - com.sun.jersey.spi.container.servlet.ServletContainer - - - com.sun.jersey.config.property.packages - org.fedoraproject.candlepin.resource - - 1 - - - - - org.fedoraproject.candlepin.guice.JerseyGuiceConfiguration - - - Guice Filter - com.google.inject.servlet.GuiceFilter - - - Guice Filter - /* - - - diff --git a/proxy/src/main/webapp/META-INF/persistence.xml b/proxy/src/main/webapp/META-INF/persistence.xml new file mode 100644 index 0000000..9c49dd9 --- /dev/null +++ b/proxy/src/main/webapp/META-INF/persistence.xml @@ -0,0 +1,35 @@ + + + + org.hibernate.ejb.HibernatePersistence + + + + + + + + + + + + + + org.hibernate.ejb.HibernatePersistence + + + + + + + + + + + + + + diff --git a/proxy/src/main/webapp/WEB-INF/web.xml b/proxy/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..1466d45 --- /dev/null +++ b/proxy/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,53 @@ + + + + + + + Jersey Web Application + com.sun.jersey.spi.container.servlet.ServletContainer + + + com.sun.jersey.config.property.packages + org.fedoraproject.candlepin.resource + + 1 + + + + + org.fedoraproject.candlepin.guice.JerseyGuiceConfiguration + + + Guice Filter + com.google.inject.servlet.GuiceFilter + + + Guice Filter + /* + + + diff --git a/proxy/src/test/java/org/fedoraproject/candlepin/model/test/CertificateTest.java b/proxy/src/test/java/org/fedoraproject/candlepin/model/test/CertificateTest.java new file mode 100644 index 0000000..fbcb191 --- /dev/null +++ b/proxy/src/test/java/org/fedoraproject/candlepin/model/test/CertificateTest.java @@ -0,0 +1,82 @@ +/** + * 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.model.test; + +import static org.junit.Assert.*; + +import java.util.List; + +import org.fedoraproject.candlepin.model.Certificate; +import org.fedoraproject.candlepin.model.Owner; +import org.fedoraproject.candlepin.test.DatabaseTestFixture; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + + +public class CertificateTest extends DatabaseTestFixture { + + @Before + public void setUpTestObjects() { + + String ownerName = "Example Corporation"; + Owner owner = new Owner(ownerName); + + ownerCurator.create(owner); + certificateCurator.create( + new Certificate("This is not actually a certificate. No entitlements for you!", owner)); + } + + + @Ignore + public void testGetCertificate() { + Certificate newCertificate = new Certificate(); + } + + @Test + public void testList() throws Exception { + List certificates = certificateCurator.findAll(); + int beforeCount = certificates.size(); + + for (int i = 0; i < 10; i++) { + Owner owner = new Owner("owner" + i); + ownerCurator.create(owner); + certificateCurator.create(new Certificate("this is a test", owner)); + } + + certificates = certificateCurator.findAll(); + int afterCount = certificates.size(); + assertEquals(10, afterCount - beforeCount); + } + + @Test + public void testLookup() throws Exception { + + Owner owner = new Owner("test company"); + Certificate certificate = new Certificate("not a cert", owner); + + ownerCurator.create(owner); + certificateCurator.create(certificate); + + Certificate lookedUp = certificateCurator.find(certificate.getId()); + + assertEquals(certificate.getId(), lookedUp.getId()); + assertEquals(certificate.getCertificate(), lookedUp.getCertificate()); + } +} + diff --git a/proxy/src/test/java/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java b/proxy/src/test/java/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java new file mode 100644 index 0000000..3279216 --- /dev/null +++ b/proxy/src/test/java/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.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.model.test; + +import static org.junit.Assert.*; + +import org.fedoraproject.candlepin.model.EntitlementPool; +import org.fedoraproject.candlepin.model.Owner; +import org.fedoraproject.candlepin.model.Product; +import org.fedoraproject.candlepin.test.DatabaseTestFixture; +import org.fedoraproject.candlepin.test.TestUtil; +import org.junit.Before; +import org.junit.Test; + + +public class EntitlementPoolTest extends DatabaseTestFixture { + + private EntitlementPool pool; + private Product prod; + private Owner owner; + + @Before + public void createObjects() { + beginTransaction(); + + pool = TestUtil.createEntitlementPool(); + owner = pool.getOwner(); + prod = pool.getProduct(); + entityManager().persist(owner); + entityManager().persist(prod); + entityManager().persist(pool); + + commitTransaction(); + } + + @Test + public void testCreate() { + EntitlementPool lookedUp = (EntitlementPool)entityManager().find(EntitlementPool.class, + pool.getId()); + assertNotNull(lookedUp); + assertEquals(owner.getId(), lookedUp.getOwner().getId()); + assertEquals(prod.getId(), lookedUp.getProduct().getId()); + } + +} diff --git a/proxy/src/test/java/org/fedoraproject/candlepin/model/test/UserTest.java b/proxy/src/test/java/org/fedoraproject/candlepin/model/test/UserTest.java new file mode 100644 index 0000000..4e8ea1d --- /dev/null +++ b/proxy/src/test/java/org/fedoraproject/candlepin/model/test/UserTest.java @@ -0,0 +1,45 @@ +/** + * 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.model.test; + +import static org.junit.Assert.*; + +import org.fedoraproject.candlepin.model.Owner; +import org.fedoraproject.candlepin.model.User; +import org.fedoraproject.candlepin.test.DatabaseTestFixture; +import org.junit.Test; + +public class UserTest extends DatabaseTestFixture { + + @Test + public void testCreate() throws Exception { + String ownerName = "Example Corporation"; + Owner o = new Owner(ownerName); + + String username = "TESTUSER"; + String password = "sekretpassword"; + User user = new User(o, username, password); + + beginTransaction(); + entityManager().persist(o); + entityManager().persist(user); + commitTransaction(); + + User lookedUp = (User)entityManager().find(User.class, user.getId()); + assertEquals(username, lookedUp.getLogin()); + assertEquals(password, lookedUp.getPassword()); + } + +} diff --git a/proxy/src/test/java/org/fedoraproject/candlepin/resource/test/CandlepinTestingModule.java b/proxy/src/test/java/org/fedoraproject/candlepin/resource/test/CandlepinTestingModule.java new file mode 100644 index 0000000..96e9f2f --- /dev/null +++ b/proxy/src/test/java/org/fedoraproject/candlepin/resource/test/CandlepinTestingModule.java @@ -0,0 +1,17 @@ +package org.fedoraproject.candlepin.resource.test; + +import org.fedoraproject.candlepin.guice.JPAInitializer; + +import com.google.inject.AbstractModule; +import com.wideplay.warp.persist.jpa.JpaUnit; + +public class CandlepinTestingModule extends AbstractModule { + + @Override + public void configure() { + + bind(JPAInitializer.class).asEagerSingleton(); + bindConstant().annotatedWith(JpaUnit.class).to("test"); + + } +} diff --git a/proxy/src/test/java/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java b/proxy/src/test/java/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java new file mode 100644 index 0000000..f835046 --- /dev/null +++ b/proxy/src/test/java/org/fedoraproject/candlepin/resource/test/CertificateResourceTest.java @@ -0,0 +1,117 @@ +/** + * 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 static org.junit.Assert.*; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.List; + +import org.fedoraproject.candlepin.model.CertificateCurator; +import org.fedoraproject.candlepin.model.ConsumerCurator; +import org.fedoraproject.candlepin.model.EntitlementPool; +import org.fedoraproject.candlepin.model.EntitlementPoolCurator; +import org.fedoraproject.candlepin.model.Owner; +import org.fedoraproject.candlepin.model.OwnerCurator; +import org.fedoraproject.candlepin.model.Product; +import org.fedoraproject.candlepin.model.ProductCurator; +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 com.google.inject.Guice; +import com.google.inject.Injector; +import com.wideplay.warp.persist.PersistenceService; +import com.wideplay.warp.persist.UnitOfWork; + +public class CertificateResourceTest extends DatabaseTestFixture { + + private CertificateResource certResource; + private CertificateCurator certificateCurator; + private ConsumerCurator consumerRepository; + private EntitlementPoolCurator epCurator; + private ProductCurator productCurator; + private OwnerCurator ownerCurator; + private String sampleCertXml; + + @Before + public void createObjects() throws Exception { + + Injector injector = Guice.createInjector( + new CandlepinTestingModule(), + PersistenceService.usingJpa() + .across(UnitOfWork.TRANSACTION) + .buildModule() + ); + + consumerRepository = injector.getInstance(ConsumerCurator.class); + epCurator = injector.getInstance(EntitlementPoolCurator.class); + productCurator = injector.getInstance(ProductCurator.class); + ownerCurator = injector.getInstance(OwnerCurator.class); + certificateCurator = injector.getInstance(CertificateCurator.class); + + certResource = new CertificateResource(ownerCurator, productCurator, epCurator, certificateCurator); + + 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 ownerCreated() { + certResource.upload(TestUtil.xmlToBase64String(sampleCertXml)); + Owner owner = ownerCurator.lookupByName("Spacewalk Public Cert"); +// certResource.upload(TestUtil.xmlToBase64String(sampleCertXml)); + assertNotNull(owner); + } + + @Test + public void simpleUploadCertProductsCreated() { + certResource.upload(TestUtil.xmlToBase64String(sampleCertXml)); + List products = productCurator.listAll(); + assertEquals(5, products.size()); + } + + @Test + public void entitlementPoolCreation() { + String encoded = TestUtil.xmlToBase64String(sampleCertXml); + certResource.upload(encoded); + Owner owner = ownerCurator.lookupByName("Spacewalk Public Cert"); + List entPools = epCurator.listByOwner(owner); + assertEquals(5, entPools.size()); + } + + @Test + public void channelFamilyCreation() { + // TODO!!!!!! Current test cert has no channel families. + } + + @Test + public void uploadCertWithPreExistingProducts() { + // TODO + } + +} diff --git a/proxy/src/test/java/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert b/proxy/src/test/java/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert new file mode 100644 index 0000000..4d63ab3 --- /dev/null +++ b/proxy/src/test/java/org/fedoraproject/candlepin/resource/test/spacewalk-public.cert @@ -0,0 +1,23 @@ + + + SPACEWALK-001 + Spacewalk Public Cert + 2007-07-13 00:00:00 + 2010-07-13 00:00:00 + 20000 + 20000 + 20000 + 20000 + 20000 + spacewalk + 2 + +-----BEGIN PGP SIGNATURE----- +Version: Crypt::OpenPGP 1.03 + +iQBGBAARAwAGBQJIUsb7AAoJEJ5yna8GlHkyi50Anjh4/GHHPoOUKO6LdDaE2ZcJ +X69tAJ41s97D66gXGvk244vkmSMajJT2hg== +=oOTl +-----END PGP SIGNATURE----- + + diff --git a/proxy/src/test/java/org/fedoraproject/candlepin/test/DatabaseTestFixture.java b/proxy/src/test/java/org/fedoraproject/candlepin/test/DatabaseTestFixture.java new file mode 100644 index 0000000..289d9bb --- /dev/null +++ b/proxy/src/test/java/org/fedoraproject/candlepin/test/DatabaseTestFixture.java @@ -0,0 +1,188 @@ +package org.fedoraproject.candlepin.test; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; + +import org.fedoraproject.candlepin.model.Certificate; +import org.fedoraproject.candlepin.model.CertificateCurator; +import org.fedoraproject.candlepin.model.Consumer; +import org.fedoraproject.candlepin.model.ConsumerCurator; +import org.fedoraproject.candlepin.model.ConsumerType; +import org.fedoraproject.candlepin.model.ConsumerTypeCurator; +import org.fedoraproject.candlepin.model.Entitlement; +import org.fedoraproject.candlepin.model.EntitlementPool; +import org.fedoraproject.candlepin.model.EntitlementPoolCurator; +import org.fedoraproject.candlepin.model.Owner; +import org.fedoraproject.candlepin.model.OwnerCurator; +import org.fedoraproject.candlepin.model.Product; +import org.fedoraproject.candlepin.model.ProductCurator; +import org.fedoraproject.candlepin.model.User; +import org.fedoraproject.candlepin.resource.test.CandlepinTestingModule; +import org.junit.After; +import org.junit.Before; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.wideplay.warp.persist.PersistenceService; +import com.wideplay.warp.persist.UnitOfWork; + +/** + * Test fixture for test classes requiring access to the database. + */ +public class DatabaseTestFixture { + + protected EntityManagerFactory emf; + protected Injector injector; + + protected OwnerCurator ownerCurator; + protected ProductCurator productCurator; + protected ConsumerCurator consumerCurator; + protected ConsumerTypeCurator consumerTypeCurator; + protected CertificateCurator certificateCurator; + protected EntitlementPoolCurator entitlementPoolCurator; + + + @Before + public void setUp() { + injector = Guice.createInjector( + new CandlepinTestingModule(), + PersistenceService.usingJpa() + .across(UnitOfWork.TRANSACTION) + .buildModule() + ); + + injector.getInstance(EntityManagerFactory.class); + emf = injector.getProvider(EntityManagerFactory.class).get(); + + ownerCurator = injector.getInstance(OwnerCurator.class); + productCurator = injector.getInstance(ProductCurator.class); + consumerCurator = injector.getInstance(ConsumerCurator.class); + consumerTypeCurator = injector.getInstance(ConsumerTypeCurator.class); + certificateCurator = injector.getInstance(CertificateCurator.class); + entitlementPoolCurator = injector.getInstance(EntitlementPoolCurator.class); + } + + /* + * As long as we are using in-memory db we don't need to clean it out; + * a new instance will be created for each test. cleanDb() is *not* being currently invoked. + * + * Cleans out everything in the database. Currently we test against an + * in-memory hsqldb, so this should be ok. + * + * WARNING: Don't flip the persistence unit to point to an actual live + * DB or you'll lose everything. + * + * WARNING: If you're creating objects in tables that have static + * pre-populated content, we may not want to wipe those tables here. + * This situation hasn't arisen yet. + */ + @SuppressWarnings("unchecked") + public void cleanDb() { + EntityManager em = entityManager(); + if (!em.getTransaction().isActive()) { + beginTransaction(); + } + + List users = em.createQuery("from User u").getResultList(); + for (User u : users) { + em.remove(u); + } + + List ents = em.createQuery("from Entitlement e"). + getResultList(); + for (Entitlement e : ents) { + em.remove(e); + } + + List pools = em.createQuery("from EntitlementPool p").getResultList(); + for (EntitlementPool p : pools) { + em.remove(p); + } + + // TODO: Would rather be doing this, but such a bulk delete does not seem to respect + // the cascade to child products and thus fails. + // em.createQuery("delete from Product").executeUpdate(); + List products = em.createQuery("from Product p").getResultList(); + for (Product p : products) { + em.remove(p); + } + + List consumers = em.createQuery("from Consumer c").getResultList(); + for (Consumer c : consumers) { + em.remove(c); + } + + List certificates = em.createQuery("from Certificate c").getResultList(); + for (Certificate c : certificates){ + em.remove(c); + } + + List owners = em.createQuery("from Owner o").getResultList(); + for (Owner o : owners) { + em.remove(o); + } + +// List consumerInfos = em.createQuery("from ConsumerInfo c").getResultList(); +// for (ConsumerInfo c : consumerInfos) { +// em.remove(c); +// } + + // TODO: Is this right? Or should we pre-populate default defined types, and always + // reference these in the tests instead of creating them everywhere? + List consumerTypes = em.createQuery("from ConsumerType c"). + getResultList(); + for (ConsumerType c : consumerTypes) { + em.remove(c); + } + + + + commitTransaction(); + em.close(); + } + + protected EntityManager entityManager() { + return injector.getProvider(EntityManager.class).get(); + } + + /** + * Begin a transaction, persist the given entity, and commit. + * + * @param storeMe Entity to persist. + */ + protected void persistAndCommit(Object storeMe) { + EntityTransaction tx = null; + + try { + tx = entityManager().getTransaction(); + tx.begin(); + entityManager().persist(storeMe); + tx.commit(); + } + catch (RuntimeException e) { + if (tx != null && tx.isActive()) { + tx.rollback(); + } + throw e; // or display error message + } + } + + /** + * Helper to open a new db transaction. Pretty simple for now, but may + * require additional logic and error handling down the road. + */ + protected void beginTransaction() { + entityManager().getTransaction().begin(); + } + + /** + * Helper to commit the current db transaction. Pretty simple for now, but may + * require additional logic and error handling down the road. + */ + protected void commitTransaction() { + entityManager().getTransaction().commit(); + } +} diff --git a/proxy/src/test/java/org/fedoraproject/candlepin/test/TestUtil.java b/proxy/src/test/java/org/fedoraproject/candlepin/test/TestUtil.java new file mode 100644 index 0000000..21b005e --- /dev/null +++ b/proxy/src/test/java/org/fedoraproject/candlepin/test/TestUtil.java @@ -0,0 +1,126 @@ +/** + * 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.test; + +import java.sql.Date; +import java.util.Calendar; +import java.util.Random; + +import org.apache.commons.codec.binary.Base64; +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; +import org.fedoraproject.candlepin.model.User; + +/** + * 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 " + randomInt()); +// o.setUuid(lookedUp); + ObjectFactory.get().store(o); + return o; + } + + public static Consumer createConsumer(ConsumerType type, Owner owner) { + Consumer c = new Consumer("Test Consumer " + randomInt(), owner, type); + ObjectFactory.get().store(c); + return c; + } + + /** + * Create a consumer with a new owner + * @return Consumer + */ + public static Consumer createConsumer() { + return createConsumer(createConsumerType(), createOwner()); + } + + public static ConsumerType createConsumerType() { + return new ConsumerType("test-consumer-type-" + randomInt()); + } + + public static int randomInt() { + return new Random().nextInt(10000); + } + + public static Product createProduct() { + 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 User createUser(Owner owner) { + User u = new User(owner, "testuser" + randomInt(), "sekret"); + return u; + } + + 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; + } + + public static String xmlToBase64String(String xml) { + +// byte[] bytes = Base64.encode(xml); + Base64 encoder = new Base64(); + byte [] bytes = encoder.encode(xml.getBytes()); + + StringBuffer buf = new StringBuffer(); + for (byte b : bytes) { + buf.append((char) Integer.parseInt(Integer.toHexString(b), 16)); + } + + return buf.toString(); + } + +} diff --git a/proxy/src/test/resources/META-INF/persistence.xml b/proxy/src/test/resources/META-INF/persistence.xml deleted file mode 100644 index 2ecd9fd..0000000 --- a/proxy/src/test/resources/META-INF/persistence.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - org.hibernate.ejb.HibernatePersistence - - - - - - - - - - - - - diff --git a/proxy/src/test/resources/WEB-INF/web.xml b/proxy/src/test/resources/WEB-INF/web.xml deleted file mode 100644 index ca517c4..0000000 --- a/proxy/src/test/resources/WEB-INF/web.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - Jersey Web Application - com.sun.jersey.spi.container.servlet.ServletContainer - - - com.sun.jersey.config.property.packages - org.fedoraproject.candlepin.resource - - 1 - - - - - Jersey Web Application - /* - - diff --git a/proxy/src/test/resources/certs/certificates.readme b/proxy/src/test/resources/certs/certificates.readme new file mode 100644 index 0000000..0039145 --- /dev/null +++ b/proxy/src/test/resources/certs/certificates.readme @@ -0,0 +1,22 @@ +to generate certificates: + +keytool -genkeypair -alias servercert -keyalg RSA -dname "CN=Web Server,OU=Unit,O=Organization,L=City,S=State,C=US" -keypass password -keystore server.jks -storepass password +keytool -genkeypair -alias clientcert -keystore clientcert.p12 -storetype pkcs12 -keyalg RSA -dname "CN=Client,OU=Unit,O=Organization,L=City,S=State,C=US" -keypass password -storepass password +keytool -exportcert -alias %1 -file clientcert.cer -keystore clientcert.p12 -storetype pkcs12 -storepass password +keytool -importcert -keystore server.jks -alias clientcert -file clientcert.cer -v -trustcacerts -noprompt -storepass password + +tomcat connector configuration: + + + +install client certificate into your browser of choice, and you should be good to go! \ No newline at end of file diff --git a/proxy/src/test/resources/certs/rest_api_test.jks b/proxy/src/test/resources/certs/rest_api_test.jks new file mode 100644 index 0000000..b055808 Binary files /dev/null and b/proxy/src/test/resources/certs/rest_api_test.jks differ diff --git a/proxy/src/test/resources/certs/rest_client_test.p12 b/proxy/src/test/resources/certs/rest_client_test.p12 new file mode 100644 index 0000000..f2d100e Binary files /dev/null and b/proxy/src/test/resources/certs/rest_client_test.p12 differ diff --git a/proxy/src/test/resources/certs/server.xml b/proxy/src/test/resources/certs/server.xml new file mode 100644 index 0000000..85ab0e1 --- /dev/null +++ b/proxy/src/test/resources/certs/server.xml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit