}
public void testArtifactCRUD()
throws Exception
{
ArtifactDAO artiDao = dao.getArtifactDAO();
// Create it
ArchivaArtifact artifact = artiDao.createArtifact( "org.apache.maven.archiva", "archiva-test-module", "1.0",
"", "jar", "testrepo" );
assertNotNull( artifact );
// Set some mandatory values
artifact.getModel().setLastModified( new Date() );
artifact.getModel().setOrigin( "test" );
// Save it.
ArchivaArtifact savedArtifact = artiDao.saveArtifact( artifact );
assertNotNull( savedArtifact );
String savedKeyId = JDOHelper.getObjectId( savedArtifact.getModel() ).toString();
assertEquals( "org.apache.maven.archiva:archiva-test-module:1.0::jar:testrepo", savedKeyId );
// Test that something has been saved.
List<ArchivaArtifact> artifacts = artiDao.queryArtifacts( null );
assertNotNull( artifacts );
assertEquals( 1, artifacts.size() );
// Test that retrieved object is what we expect.
ArchivaArtifact firstArtifact = (ArchivaArtifact) artifacts.get( 0 );
assertNotNull( firstArtifact );
assertEquals( "org.apache.maven.archiva", firstArtifact.getGroupId() );
assertEquals( "archiva-test-module", firstArtifact.getArtifactId() );
assertEquals( "1.0", firstArtifact.getVersion() );
assertEquals( "", firstArtifact.getClassifier() );
assertEquals( "jar", firstArtifact.getType() );
// Change value and save.
savedArtifact.getModel().setOrigin( "changed" );
artiDao.saveArtifact( savedArtifact );
// Test that only 1 object is saved.
assertEquals( 1, artiDao.queryArtifacts( null ).size() );
// Get the specific artifact.
ArchivaArtifact actualArtifact = artiDao.getArtifact( "org.apache.maven.archiva", "archiva-test-module", "1.0",
null, "jar", "testrepo" );
assertNotNull( actualArtifact );
// Test expected values.
assertEquals( "archiva-test-module", actualArtifact.getArtifactId() );
assertEquals( "changed", actualArtifact.getModel().getOrigin() );
// Test that only 1 object is saved.
assertEquals( 1, artiDao.queryArtifacts( null ).size() );
// Delete object.
artiDao.deleteArtifact( actualArtifact );
assertEquals( 0, artiDao.queryArtifacts( null ).size() );
}