Boilerplate unit testing with hsqldb for other devs ...

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@521303 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-03-22 15:11:37 +00:00
parent 2087d187e7
commit 3e1c7a3ad2
3 changed files with 42 additions and 21 deletions

View File

@ -25,6 +25,8 @@ import org.apache.maven.archiva.model.ArchivaRepositoryModel;
import java.util.List; import java.util.List;
import javax.jdo.JDOHelper;
/** /**
* JdoArchivaDAOTest * JdoArchivaDAOTest
* *
@ -35,33 +37,54 @@ public class JdoArchivaDAOTest extends AbstractArchivaDatabaseTestCase
{ {
public void testRepositoryCRUD() throws ArchivaDatabaseException public void testRepositoryCRUD() throws ArchivaDatabaseException
{ {
// Create it
ArchivaRepositoryModel repo = dao.createRepository( "testRepo", "http://localhost:8080/repository/foo" ); ArchivaRepositoryModel repo = dao.createRepository( "testRepo", "http://localhost:8080/repository/foo" );
assertNotNull( repo ); assertNotNull( repo );
repo.setName( "The Test Repostitory." ); // Set some mandatory values
repo.setName( "The Test Repository." );
repo.setCreationSource( "Test Case" );
repo.setLayoutName( "default" ); repo.setLayoutName( "default" );
// Save it.
ArchivaRepositoryModel repoSaved = dao.saveRepository( repo ); ArchivaRepositoryModel repoSaved = dao.saveRepository( repo );
assertNotNull( repoSaved ); assertNotNull( repoSaved );
assertEquals( "testRepo", JDOHelper.getObjectId( repoSaved ).toString() );
// Test that something has been saved.
List repos = dao.getRepositories(); List repos = dao.getRepositories();
assertNotNull( repos ); assertNotNull( repos );
assertEquals( 1, repos.size() ); assertEquals( 1, repos.size() );
// Test that retreived object is what we expect.
ArchivaRepositoryModel firstRepo = (ArchivaRepositoryModel) repos.get( 0 );
assertNotNull( firstRepo );
assertEquals( "testRepo", repo.getId() );
assertEquals( "The Test Repository.", repo.getName() );
assertEquals( "Test Case", repo.getCreationSource() );
assertEquals( "default", repo.getLayoutName() );
// Change value and save.
repoSaved.setName( "Saved Again" ); repoSaved.setName( "Saved Again" );
dao.saveRepository( repoSaved ); dao.saveRepository( repoSaved );
// Test that only 1 object is saved.
assertEquals( 1, dao.getRepositories().size() );
// Get the specific repo.
ArchivaRepositoryModel actualRepo = dao.getRepository( "testRepo" ); ArchivaRepositoryModel actualRepo = dao.getRepository( "testRepo" );
assertNotNull( actualRepo ); assertNotNull( actualRepo );
// Test expected values.
assertEquals( "testRepo", actualRepo.getId() ); assertEquals( "testRepo", actualRepo.getId() );
assertEquals( "http://localhost:8080/repository/foo", actualRepo.getUrl() ); assertEquals( "http://localhost:8080/repository/foo", actualRepo.getUrl() );
assertEquals( "Saved Again", actualRepo.getName() ); assertEquals( "Saved Again", actualRepo.getName() );
// Test that only 1 object is saved.
assertEquals( 1, dao.getRepositories().size() ); assertEquals( 1, dao.getRepositories().size() );
// Delete object.
dao.deleteRepository( actualRepo ); dao.deleteRepository( actualRepo );
assertEquals( 0, dao.getRepositories().size() ); assertEquals( 0, dao.getRepositories().size() );
} }
} }

View File

@ -76,20 +76,12 @@
<goals> <goals>
<goal>java</goal> <goal>java</goal>
<goal>xsd</goal> <goal>xsd</goal>
<goal>jpox-jdo-mapping</goal>
<goal>jpox-metadata-class</goal> <goal>jpox-metadata-class</goal>
<goal>xpp3-writer</goal> <goal>xpp3-writer</goal>
<goal>xpp3-reader</goal> <goal>xpp3-reader</goal>
</goals> </goals>
</execution> </execution>
<execution>
<id>jdo</id>
<goals>
<goal>jpox-jdo-mapping</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/org/apache/maven/archiva/model</outputDirectory>
</configuration>
</execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" ?> <?xml version="1.0" ?>
<model jpox.table-prefix="ARCHIVA_" <model jpox.mapping-in-package="true"
jpox.table-prefix="ARCHIVA_"
xsd.namespace="http://maven.apache.org/archiva/MODEL-1.0.0" xsd.namespace="http://maven.apache.org/archiva/MODEL-1.0.0"
xsd.target-namespace="http://maven.apache.org/archiva/MODEL-1.0.0"> xsd.target-namespace="http://maven.apache.org/archiva/MODEL-1.0.0">
<id>archiva-base-model</id> <id>archiva-base-model</id>
@ -93,11 +94,13 @@
--> -->
<class stash.storable="true" <class stash.storable="true"
jpox.table="REPOSITORIES"> jpox.table="REPOSITORIES"
jpox.not-persisted-fields="modelEncoding">
<name>ArchivaRepositoryModel</name> <name>ArchivaRepositoryModel</name>
<version>1.0.0+</version> <version>1.0.0+</version>
<fields> <fields>
<field> <field jpox.primary-key="true"
jpox.value-strategy="off">
<name>id</name> <name>id</name>
<identity>true</identity> <identity>true</identity>
<version>1.0.0+</version> <version>1.0.0+</version>
@ -148,26 +151,29 @@
The layout of the repository. The layout of the repository.
(Either 'default', or 'legacy') (Either 'default', or 'legacy')
</description> </description>
<defaultValue>default</defaultValue>
</field> </field>
<field> <field>
<name>releasePolicy</name> <name>releasePolicy</name>
<identity>false</identity> <identity>false</identity>
<version>1.0.0+</version> <version>1.0.0+</version>
<type>String</type> <type>boolean</type>
<required>true</required> <required>true</required>
<description> <description>
The releases policy of the repository. The releases policy of the repository.
</description> </description>
<defaultValue>true</defaultValue>
</field> </field>
<field> <field>
<name>snapshotPolicy</name> <name>snapshotPolicy</name>
<identity>false</identity> <identity>false</identity>
<version>1.0.0+</version> <version>1.0.0+</version>
<type>String</type> <type>boolean</type>
<required>true</required> <required>true</required>
<description> <description>
The snapshot policy of the repository. The snapshot policy of the repository.
</description> </description>
<defaultValue>false</defaultValue>
</field> </field>
</fields> </fields>
</class> </class>