modules/core/domain/pom.xml | 6 modules/core/domain/src/test/java/org/rhq/core/domain/resource/ResourceTypeTest.java | 55 +++ modules/core/domain/src/test/resources/META-INF/test-persistence.xml | 144 ++++++++++ modules/core/domain/src/test/resources/org/rhq/core/domain/resource/ResourceTypeTest.xml | 20 + modules/test-utils/pom.xml | 51 +++ modules/test-utils/src/main/resources/unitils.properties | 27 + 6 files changed, 303 insertions(+)
New commits: commit ab9d3c77264a456c20d720d1dd6f6a45221ea715 Author: John Sanda jsanda@redhat.com Date: Wed Oct 20 20:57:39 2010 -0400
Initial commit for ResourceTypeTest.java
Adding support for testing with unitils. The tests going into ResourceTypeTest are right now specifically focused on testing the queries that have been modified as a result of adding the deleted flag to ResourceType.
diff --git a/modules/core/domain/pom.xml b/modules/core/domain/pom.xml index d59169b..e00488c 100644 --- a/modules/core/domain/pom.xml +++ b/modules/core/domain/pom.xml @@ -110,6 +110,12 @@ -->
<!--================ Test Deps ================--> + <dependency> + <groupId>${groupId}</groupId> + <artifactId>test-utils</artifactId> + <version>${version}</version> + <scope>test</scope> + </dependency>
<dependency> <groupId>javassist</groupId> diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/ResourceTypeTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/ResourceTypeTest.java new file mode 100644 index 0000000..bb20925 --- /dev/null +++ b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/ResourceTypeTest.java @@ -0,0 +1,55 @@ +package org.rhq.core.domain.resource; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.testng.annotations.Test; +import org.unitils.UnitilsTestNG; +import org.unitils.dbunit.annotation.DataSet; +import org.unitils.orm.jpa.annotation.JpaEntityManagerFactory; + +import static org.rhq.core.domain.resource.ResourceType.*; +import static org.testng.Assert.*; + +@JpaEntityManagerFactory(persistenceUnit = "rhq-test", configFile = "META-INF/test-persistence.xml") +@DataSet +public class ResourceTypeTest extends UnitilsTestNG { + + @PersistenceContext + EntityManager entityMgr; + + @Test + @SuppressWarnings("unchecked") + public void findByPlugin() { + List<ResourceType> results = entityMgr.createNamedQuery(QUERY_FIND_BY_PLUGIN) + .setParameter("plugin", "TestPlugin1") + .getResultList(); + + assertEquals(results.size(), 1, "Expected to get back 1 resource type"); + assertEquals(results.get(0).getId(), -1, "The wrong resource type was returned"); + } + + @Test + @SuppressWarnings("unchecked") + public void findByNameAndPlugin() { + ResourceType type = (ResourceType) entityMgr.createNamedQuery(QUERY_FIND_BY_NAME_AND_PLUGIN) + .setParameter("name", "TestServer1") + .setParameter("plugin", "TestPlugin1") + .getSingleResult(); + + assertEquals(type.getId(), -1, "Failed to find resource type by name and by plugin"); + } + + @Test + public void findByNameAndPluginShouldNotReturnDeletedType() { + List results = entityMgr.createNamedQuery(QUERY_FIND_BY_NAME_AND_PLUGIN) + .setParameter("name", "TestServer2") + .setParameter("plugin", "TestPlugin1") + .getResultList(); + + assertEquals(results.size(), 0, "Deleted type should be ignored"); + } + +} diff --git a/modules/core/domain/src/test/resources/META-INF/test-persistence.xml b/modules/core/domain/src/test/resources/META-INF/test-persistence.xml new file mode 100644 index 0000000..92dbe75 --- /dev/null +++ b/modules/core/domain/src/test/resources/META-INF/test-persistence.xml @@ -0,0 +1,144 @@ +<!-- + ~ RHQ Management Platform + ~ Copyright (C) 2005-2008 Red Hat, Inc. + ~ All rights reserved. + ~ + ~ This program is free software; you can redistribute it and/or modify + ~ it under the terms of the GNU General Public License as published by + ~ the Free Software Foundation version 2 of the License. + ~ + ~ This program is distributed in the hope that it will be useful, + ~ but WITHOUT ANY WARRANTY; without even the implied warranty of + ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ~ GNU General Public License for more details. + ~ + ~ You should have received a copy of the GNU General Public License + ~ along with this program; if not, write to the Free Software + ~ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + --> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="rhq-test" transaction-type="RESOURCE_LOCAL"> + <!--<jar-file>target/classes</jar-file>--> + <provider>org.hibernate.ejb.HibernatePersistence</provider> + <class>org.rhq.core.domain.resource.ResourceType</class> + <class>org.rhq.core.domain.resource.Resource</class> + <class>org.rhq.core.domain.configuration.definition.ConfigurationDefinition</class> + <class>org.rhq.core.domain.resource.ResourceSubCategory</class> + <class>org.rhq.core.domain.resource.ProcessScan</class> + <class>org.rhq.core.domain.measurement.MeasurementDefinition</class> + <class>org.rhq.core.domain.event.EventDefinition</class> + <class>org.rhq.core.domain.configuration.Configuration</class> + <class>org.rhq.core.domain.resource.ProductVersion</class> + <class>org.rhq.core.domain.resource.Agent</class> + <class>org.rhq.core.domain.cloud.AffinityGroup</class> + <class>org.rhq.core.domain.cloud.Server</class> + <class>org.rhq.core.domain.operation.OperationDefinition</class> + <class>org.rhq.core.domain.content.PackageType</class> + <class>org.rhq.core.domain.resource.group.ResourceGroup</class> + <class>org.rhq.core.domain.auth.Subject</class> + <class>org.rhq.core.domain.resource.group.GroupDefinition</class> + <class>org.rhq.core.domain.authz.Role</class> + <class>org.rhq.core.domain.bundle.BundleType</class> + <class>org.rhq.core.domain.alert.AlertDefinition</class> + <class>org.rhq.core.domain.configuration.ResourceConfigurationUpdate</class> + <class>org.rhq.core.domain.configuration.group.GroupResourceConfigurationUpdate</class> + <class>org.rhq.core.domain.configuration.PluginConfigurationUpdate</class> + <class>org.rhq.core.domain.configuration.group.GroupPluginConfigurationUpdate</class> + <class>org.rhq.core.domain.content.ContentServiceRequest</class> + <class>org.rhq.core.domain.resource.CreateResourceHistory</class> + <class>org.rhq.core.domain.resource.DeleteResourceHistory</class> + <class>org.rhq.core.domain.content.InstalledPackage</class> + <class>org.rhq.core.domain.content.PackageVersion</class> + <class>org.rhq.core.domain.content.PackageBits</class> + <class>org.rhq.core.domain.content.Architecture</class> + <class>org.rhq.core.domain.content.Package</class> + <class>org.rhq.core.domain.operation.ResourceOperationHistory</class> + <class>org.rhq.core.domain.operation.GroupOperationHistory</class> + <class>org.rhq.core.domain.content.InstalledPackageHistory</class> + <class>org.rhq.core.domain.content.ResourceRepo</class> + <class>org.rhq.core.domain.content.Repo</class> + <class>org.rhq.core.domain.measurement.MeasurementSchedule</class> + <class>org.rhq.core.domain.measurement.Availability</class> + <class>org.rhq.core.domain.measurement.ResourceAvailability</class> + <class>org.rhq.core.domain.resource.ResourceError</class> + <class>org.rhq.core.domain.event.EventSource</class> + <class>org.rhq.core.domain.tagging.Tag</class> + <class>org.rhq.core.domain.bundle.BundleDestination</class> + <class>org.rhq.core.domain.bundle.Bundle</class> + <class>org.rhq.core.domain.bundle.BundleDeployment</class> + <class>org.rhq.core.domain.bundle.BundleVersion</class> + <class>org.rhq.core.domain.configuration.definition.PropertyDefinition</class> + <class>org.rhq.core.domain.configuration.definition.PropertyDefinitionMap</class> + <class>org.rhq.core.domain.configuration.definition.PropertyDefinitionList</class> + <class>org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple</class> + <class>org.rhq.core.domain.configuration.Property</class> + <class>org.rhq.core.domain.configuration.PropertyMap</class> + <class>org.rhq.core.domain.configuration.PropertyList</class> + <class>org.rhq.core.domain.configuration.PropertySimple</class> + <class>org.rhq.core.domain.configuration.definition.PropertyGroupDefinition</class> + <class>org.rhq.core.domain.configuration.definition.ConfigurationTemplate</class> + <class>org.rhq.core.domain.alert.AlertCondition</class> + <class>org.rhq.core.domain.configuration.RawConfiguration</class> + <class>org.rhq.core.domain.content.ProductVersionPackageVersion</class> + <class>org.rhq.core.domain.resource.group.LdapGroup</class> + <class>org.rhq.core.domain.alert.AlertDampeningEvent</class> + <class>org.rhq.core.domain.alert.notification.AlertNotification</class> + <class>org.rhq.core.domain.alert.Alert</class> + <class>org.rhq.core.domain.content.RepoPackageVersion</class> + <class>org.rhq.core.domain.content.PackageInstallationStep</class> + <class>org.rhq.core.domain.content.RepoContentSource</class> + <class>org.rhq.core.domain.content.ContentSource</class> + <class>org.rhq.core.domain.content.ContentSourceType</class> + <class>org.rhq.core.domain.content.RepoRepoGroup</class> + <class>org.rhq.core.domain.content.RepoGroup</class> + <class>org.rhq.core.domain.content.RepoGroupType</class> + <class>org.rhq.core.domain.content.RepoRepoRelationship</class> + <class>org.rhq.core.domain.content.RepoRelationship</class> + <class>org.rhq.core.domain.content.RepoRelationshipType</class> + <class>org.rhq.core.domain.content.RepoSyncResults</class> + <class>org.rhq.core.domain.content.RepoDistribution</class> + <class>org.rhq.core.domain.content.Distribution</class> + <class>org.rhq.core.domain.content.DistributionType</class> + <class>org.rhq.core.domain.content.RepoAdvisory</class> + <class>org.rhq.core.domain.content.Advisory</class> + <class>org.rhq.core.domain.measurement.MeasurementBaseline</class> + <class>org.rhq.core.domain.event.Event</class> + <class>org.rhq.core.domain.bundle.BundleResourceDeployment</class> + <class>org.rhq.core.domain.bundle.BundleFile</class> + <class>org.rhq.core.domain.configuration.definition.constraint.Constraint</class> + <class>org.rhq.core.domain.configuration.definition.PropertyDefinitionEnumeration</class> + <class>org.rhq.core.domain.alert.AlertConditionLog</class> + <class>org.rhq.core.domain.alert.notification.AlertNotificationLog</class> + <class>org.rhq.core.domain.content.ContentSourceSyncResults</class> + <class>org.rhq.core.domain.content.DistributionFile</class> + <class>org.rhq.core.domain.content.AdvisoryPackage</class> + <class>org.rhq.core.domain.content.AdvisoryBuglist</class> + <class>org.rhq.core.domain.bundle.BundleResourceDeploymentHistory</class> + <class>org.rhq.core.domain.content.PackageBitsBlob</class> + <class>org.rhq.core.domain.content.PackageVersionContentSource</class> + <class>org.rhq.core.domain.measurement.MeasurementDataTrait</class> + <properties> + <property name="hibernate.connection.provider_class" value="org.hibernate.connection.DriverManagerConnectionProvider"/> + <!-- + Setting the autodetection property is supposed to cause hibernate to scan + for entity classes alleviating the need to list out all of the classes as + was done above. The autoscan however has not been working. + + jsanda 10/20/2010 + --> + <property name="hibernate.archive.autodetection" value="class"/> + <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> + <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/> + <property name="hibernate.connection.username" value="rhqadmin"/> + <property name="hibernate.connection.password" value="rhqadmin"/> + <property name="hibernate.connection.url" value="jdbc:postgresql://127.0.0.1:5432/rhq"/> + <property name="hibernate.jdbc.batch_size" value="30"/> + <property name="hibernate.cache.use_second_level_cache" value="false"/> + <property name="hibernate.show_sql" value="true" /> + <property name="hibernate.format_sql" value="true" /> + <property name="hibernate.use_sql_comments" value="true" /> + <property name="hibernate.connection.autocommit" value="false"/> + </properties> + </persistence-unit> +</persistence> diff --git a/modules/core/domain/src/test/resources/org/rhq/core/domain/resource/ResourceTypeTest.xml b/modules/core/domain/src/test/resources/org/rhq/core/domain/resource/ResourceTypeTest.xml new file mode 100644 index 0000000..15618c4 --- /dev/null +++ b/modules/core/domain/src/test/resources/org/rhq/core/domain/resource/ResourceTypeTest.xml @@ -0,0 +1,20 @@ +<dataset> + <rhq_resource_type id="-1" + name="TestServer1" + category="SERVER" + creation_data_type="CONFIGURATION" + create_delete_policy="BOTH" + supports_manual_add="true" + singleton="false" + plugin="TestPlugin1" + deleted="false"/> + <rhq_resource_type id="-2" + name="TestServer2" + category="SERVER" + creation_data_type="CONFIGURATION" + create_delete_policy="BOTH" + supports_manual_add="true" + singleton="false" + plugin="TestPlugin1" + deleted="true"/> +</dataset> \ No newline at end of file diff --git a/modules/test-utils/pom.xml b/modules/test-utils/pom.xml index d0b9c5c..258a5ae 100644 --- a/modules/test-utils/pom.xml +++ b/modules/test-utils/pom.xml @@ -32,5 +32,56 @@ <version>1.9.4.1</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.unitils</groupId> + <artifactId>unitils-dbunit</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>org.unitils</groupId> + <artifactId>unitils-orm</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>org.unitils</groupId> + <artifactId>unitils-dbmaintainer</artifactId> + <version>3.1</version> + <exclusions> + <!-- + Unitils depends on hibernate 3.2.5 and we are using a + an earlier 3.2 build. The 3.2.5 version causes some + dependencies clashes around asm which gets pulled + in by cobertura. We are excluding hibernate here to + avoid the dependency clash and to force unitils into + using the version that we use else where. + + jsanda 10/20/2010 + --> + <exclusion> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.unitils</groupId> + <artifactId>unitils-easymock</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>org.unitils</groupId> + <artifactId>unitils-testng</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>org.unitils</groupId> + <artifactId>unitils-inject</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>org.unitils</groupId> + <artifactId>unitils-mock</artifactId> + <version>3.1</version> + </dependency> </dependencies> </project> diff --git a/modules/test-utils/src/main/resources/unitils.properties b/modules/test-utils/src/main/resources/unitils.properties new file mode 100644 index 0000000..b73191e --- /dev/null +++ b/modules/test-utils/src/main/resources/unitils.properties @@ -0,0 +1,27 @@ +# Defaults and other keys with explanations can be found there: http://unitils.org/unitils-default.properties +unitils.module.database.enabled=true +unitils.module.dbunit.enabled=true +unitils.module.hibernate.enabled=false +unitils.module.mock.enabled=false +unitils.module.easymock.enabled=false +unitils.module.inject.enabled=true +unitils.module.spring.enabled=false +unitils.module.jpa.enabled=true + +database.driverClassName=org.postgresql.Driver +database.url=jdbc:postgresql://127.0.0.1:5432/rhq + +database.dialect=postgresql +database.userName=rhqadmin +database.password=rhqadmin +database.schemaNames=public + +org.unitils.core.dbsupport.DbSupport.implClassName.postgresql=org.unitils.core.dbsupport.PostgreSqlDbSupport +org.dbunit.dataset.datatype.IDataTypeFactory.implClassName.postgresql=org.dbunit.dataset.datatype.DefaultDataTypeFactory + +#DbUnitModule.DataSet.loadStrategy.default=org.unitils.dbunit.datasetloadstrategy.impl.RefreshLoadStrategy + + +updateDataBaseSchema.enabled=false + +jpa.persistenceProvider=hibernate
rhq-commits@lists.fedorahosted.org