1 package org.apache.maven.archiva.database.jdo;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
23 import org.apache.maven.archiva.database.ArchivaDatabaseException;
24 import org.apache.maven.archiva.database.RepositoryDAO;
25 import org.apache.maven.archiva.model.ArchivaRepositoryModel;
27 import java.util.List;
29 import javax.jdo.JDOHelper;
32 * JdoRepositoryDAOTest
34 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
37 public class JdoRepositoryDAOTest
38 extends AbstractArchivaDatabaseTestCase
40 public void testRepositoryCRUD()
41 throws ArchivaDatabaseException
43 RepositoryDAO repoDao = dao.getRepositoryDAO();
46 ArchivaRepositoryModel repo = repoDao.createRepository( "testRepo", "http://localhost:8080/repository/foo" );
47 assertNotNull( repo );
49 // Set some mandatory values
50 repo.setName( "The Test Repository." );
51 repo.setCreationSource( "Test Case" );
52 repo.setLayoutName( "default" );
55 ArchivaRepositoryModel repoSaved = repoDao.saveRepository( repo );
56 assertNotNull( repoSaved );
57 assertEquals( "testRepo", JDOHelper.getObjectId( repoSaved ).toString() );
59 // Test that something has been saved.
60 List repos = repoDao.getRepositories();
61 assertNotNull( repos );
62 assertEquals( 1, repos.size() );
64 // Test that retreived object is what we expect.
65 ArchivaRepositoryModel firstRepo = (ArchivaRepositoryModel) repos.get( 0 );
66 assertNotNull( firstRepo );
67 assertEquals( "testRepo", repo.getId() );
68 assertEquals( "The Test Repository.", repo.getName() );
69 assertEquals( "Test Case", repo.getCreationSource() );
70 assertEquals( "default", repo.getLayoutName() );
72 // Change value and save.
73 repoSaved.setName( "Saved Again" );
74 repoDao.saveRepository( repoSaved );
76 // Test that only 1 object is saved.
77 assertEquals( 1, repoDao.getRepositories().size() );
79 // Get the specific repo.
80 ArchivaRepositoryModel actualRepo = repoDao.getRepository( "testRepo" );
81 assertNotNull( actualRepo );
83 // Test expected values.
84 assertEquals( "testRepo", actualRepo.getId() );
85 assertEquals( "http://localhost:8080/repository/foo", actualRepo.getUrl() );
86 assertEquals( "Saved Again", actualRepo.getName() );
88 // Test that only 1 object is saved.
89 assertEquals( 1, repoDao.getRepositories().size() );
92 repoDao.deleteRepository( actualRepo );
93 assertEquals( 0, repoDao.getRepositories().size() );