import java.util.List;
+import javax.jdo.JDOHelper;
+
/**
* JdoArchivaDAOTest
*
{
public void testRepositoryCRUD() throws ArchivaDatabaseException
{
+ // Create it
ArchivaRepositoryModel repo = dao.createRepository( "testRepo", "http://localhost:8080/repository/foo" );
-
assertNotNull( repo );
- repo.setName( "The Test Repostitory." );
+ // Set some mandatory values
+ repo.setName( "The Test Repository." );
+ repo.setCreationSource( "Test Case" );
repo.setLayoutName( "default" );
+ // Save it.
ArchivaRepositoryModel repoSaved = dao.saveRepository( repo );
assertNotNull( repoSaved );
+ assertEquals( "testRepo", JDOHelper.getObjectId( repoSaved ).toString() );
+ // Test that something has been saved.
List repos = dao.getRepositories();
assertNotNull( repos );
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" );
dao.saveRepository( repoSaved );
-
+
+ // Test that only 1 object is saved.
+ assertEquals( 1, dao.getRepositories().size() );
+
+ // Get the specific repo.
ArchivaRepositoryModel actualRepo = dao.getRepository( "testRepo" );
assertNotNull( actualRepo );
+
+ // Test expected values.
assertEquals( "testRepo", actualRepo.getId() );
assertEquals( "http://localhost:8080/repository/foo", actualRepo.getUrl() );
assertEquals( "Saved Again", actualRepo.getName() );
-
+
+ // Test that only 1 object is saved.
assertEquals( 1, dao.getRepositories().size() );
-
+
+ // Delete object.
dao.deleteRepository( actualRepo );
assertEquals( 0, dao.getRepositories().size() );
}
}
-
<?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.target-namespace="http://maven.apache.org/archiva/MODEL-1.0.0">
<id>archiva-base-model</id>
-->
<class stash.storable="true"
- jpox.table="REPOSITORIES">
+ jpox.table="REPOSITORIES"
+ jpox.not-persisted-fields="modelEncoding">
<name>ArchivaRepositoryModel</name>
<version>1.0.0+</version>
<fields>
- <field>
+ <field jpox.primary-key="true"
+ jpox.value-strategy="off">
<name>id</name>
<identity>true</identity>
<version>1.0.0+</version>
The layout of the repository.
(Either 'default', or 'legacy')
</description>
+ <defaultValue>default</defaultValue>
</field>
<field>
<name>releasePolicy</name>
<identity>false</identity>
<version>1.0.0+</version>
- <type>String</type>
+ <type>boolean</type>
<required>true</required>
<description>
The releases policy of the repository.
</description>
+ <defaultValue>true</defaultValue>
</field>
<field>
<name>snapshotPolicy</name>
<identity>false</identity>
<version>1.0.0+</version>
- <type>String</type>
+ <type>boolean</type>
<required>true</required>
<description>
The snapshot policy of the repository.
</description>
+ <defaultValue>false</defaultValue>
</field>
</fields>
</class>