extends AbstractArchivaDatabaseTestCase
{
public void testProjectModelCRUD()
throws Exception
{
ProjectModelDAO projectDao = dao.getProjectModelDAO();
// Create it
ArchivaProjectModel model = projectDao.createProjectModel( "org.apache.maven.archiva", "archiva-test-module",
"1.0" );
assertNotNull( model );
// Set some mandatory values
model.setPackaging( "pom" );
model.setWhenIndexed( new Date() );
model.setOrigin( "test" );
// Save it.
ArchivaProjectModel savedModel = projectDao.saveProjectModel( model );
assertNotNull( savedModel );
String savedKeyId = JDOHelper.getObjectId( savedModel ).toString();
assertEquals( "org.apache.maven.archiva:archiva-test-module:1.0", savedKeyId );
// Test that something has been saved.
List<ArchivaProjectModel> projects = projectDao.queryProjectModels( null );
assertNotNull( projects );
assertEquals( 1, projects.size() );
// Test that retrieved object is what we expect.
ArchivaProjectModel firstModel = (ArchivaProjectModel) projects.get( 0 );
assertNotNull( firstModel );
assertEquals( "org.apache.maven.archiva", firstModel.getGroupId() );
assertEquals( "archiva-test-module", firstModel.getArtifactId() );
assertEquals( "1.0", firstModel.getVersion() );
// Change value and save.
savedModel.setOrigin( "changed" );
projectDao.saveProjectModel( savedModel );
// Test that only 1 object is saved.
assertEquals( 1, projectDao.queryProjectModels( null ).size() );
// Get the specific artifact.
ArchivaProjectModel actualModel = projectDao.getProjectModel( "org.apache.maven.archiva",
"archiva-test-module", "1.0" );
assertNotNull( actualModel );
// Test expected values.
assertEquals( "archiva-test-module", actualModel.getArtifactId() );
assertEquals( "changed", actualModel.getOrigin() );
// Test that only 1 object is saved.
assertEquals( 1, projectDao.queryProjectModels( null ).size() );
// Delete object.
projectDao.deleteProjectModel( actualModel );
assertEquals( 0, projectDao.queryProjectModels( null ).size() );
}