1 package org.apache.archiva.metadata.repository;
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 junit.framework.TestCase;
23 import org.apache.archiva.metadata.model.ArtifactMetadata;
24 import org.apache.archiva.metadata.model.CiManagement;
25 import org.apache.archiva.metadata.model.Dependency;
26 import org.apache.archiva.metadata.model.IssueManagement;
27 import org.apache.archiva.metadata.model.License;
28 import org.apache.archiva.metadata.model.MailingList;
29 import org.apache.archiva.metadata.model.MetadataFacet;
30 import org.apache.archiva.metadata.model.MetadataFacetFactory;
31 import org.apache.archiva.metadata.model.Organization;
32 import org.apache.archiva.metadata.model.ProjectMetadata;
33 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
34 import org.apache.archiva.metadata.model.Scm;
35 import org.fest.assertions.Assertions;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.test.context.ContextConfiguration;
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.Collection;
45 import java.util.Collections;
46 import java.util.Comparator;
47 import java.util.Date;
48 import java.util.HashMap;
49 import java.util.List;
51 import org.apache.archiva.test.ArchivaSpringJUnit4ClassRunner;
53 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
54 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
55 public abstract class AbstractMetadataRepositoryTest
58 protected static final String OTHER_REPO_ID = "other-repo";
60 protected MetadataRepository repository;
62 protected static final String TEST_REPO_ID = "test";
64 private static final String TEST_PROJECT = "projectId";
66 private static final String TEST_NAMESPACE = "namespace";
68 private static final String TEST_PROJECT_VERSION = "1.0";
70 private static final String TEST_PROJECT_VERSION_2_0 = "2.0";
72 private static final String TEST_FACET_ID = "test-facet-id";
74 private static final String TEST_NAME = "test/name";
76 private static final String TEST_VALUE = "test-value";
78 private static final String UNKNOWN = "unknown";
80 private static final String TEST_MD5 = "bd4a9b642562547754086de2dab26b7d";
82 private static final String TEST_SHA1 = "2e5daf0201ddeb068a62d5e08da18657ab2c6be9";
84 private static final String TEST_METADATA_VALUE = "test-metadata";
86 protected Logger log = LoggerFactory.getLogger( getClass() );
88 protected static Map<String, MetadataFacetFactory> createTestMetadataFacetFactories()
90 Map<String, MetadataFacetFactory> factories = new HashMap<String, MetadataFacetFactory>();
91 factories.put( TEST_FACET_ID, new MetadataFacetFactory()
93 public MetadataFacet createMetadataFacet()
95 return new TestMetadataFacet( TEST_METADATA_VALUE );
98 public MetadataFacet createMetadataFacet( String repositoryId, String name )
100 return new TestMetadataFacet( TEST_METADATA_VALUE );
104 // add to ensure we don't accidentally create an empty facet ID.
105 factories.put( "", new MetadataFacetFactory()
107 public MetadataFacet createMetadataFacet()
109 return new TestMetadataFacet( "", TEST_VALUE );
112 public MetadataFacet createMetadataFacet( String repositoryId, String name )
114 return new TestMetadataFacet( "", TEST_VALUE );
121 public void testRootNamespaceWithNoMetadataRepository()
124 Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID );
125 assertEquals( Collections.<String>emptyList(), namespaces );
129 public void testGetNamespaceOnly()
132 assertEquals( Collections.emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) );
134 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
136 assertEquals( Collections.singletonList( TEST_NAMESPACE ), repository.getRootNamespaces( TEST_REPO_ID ) );
140 public void testGetProjectOnly()
143 assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
144 assertEquals( Collections.emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) );
146 ProjectMetadata project = new ProjectMetadata();
147 project.setId( TEST_PROJECT );
148 project.setNamespace( TEST_NAMESPACE );
150 repository.updateProject( TEST_REPO_ID, project );
152 project = repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
153 assertEquals( TEST_PROJECT, project.getId() );
154 assertEquals( TEST_NAMESPACE, project.getNamespace() );
156 // test that namespace is also constructed
157 assertEquals( Collections.singletonList( TEST_NAMESPACE ), repository.getRootNamespaces( TEST_REPO_ID ) );
161 public void testGetProjectVersionOnly()
164 assertNull( repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
165 assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
166 assertEquals( Collections.<String>emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) );
168 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
169 metadata.setId( TEST_PROJECT_VERSION );
171 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
173 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
174 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
176 // test that namespace and project is also constructed
177 assertEquals( Collections.singletonList( TEST_NAMESPACE ), repository.getRootNamespaces( TEST_REPO_ID ) );
178 ProjectMetadata projectMetadata = repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
179 assertEquals( TEST_PROJECT, projectMetadata.getId() );
180 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace() );
184 public void testGetArtifactOnly()
187 assertEquals( Collections.<ArtifactMetadata>emptyList(), new ArrayList<ArtifactMetadata>(
188 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
189 assertNull( repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
190 assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
191 assertEquals( Collections.<String>emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) );
193 ArtifactMetadata metadata = createArtifact();
195 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
197 Collection<ArtifactMetadata> artifacts =
198 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
199 assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
201 // test that namespace, project and project version is also constructed
202 assertEquals( Collections.singletonList( TEST_NAMESPACE ), repository.getRootNamespaces( TEST_REPO_ID ) );
204 ProjectMetadata projectMetadata = repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
205 assertEquals( TEST_PROJECT, projectMetadata.getId() );
206 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace() );
208 ProjectVersionMetadata projectVersionMetadata =
209 repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
210 assertEquals( TEST_PROJECT_VERSION, projectVersionMetadata.getId() );
214 public void testUpdateProjectVersionMetadataWithNoOtherArchives()
217 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
218 metadata.setId( TEST_PROJECT_VERSION );
219 MailingList mailingList = new MailingList();
220 mailingList.setName( "Foo List" );
221 mailingList.setOtherArchives( Collections.<String>emptyList() );
222 metadata.setMailingLists( Collections.singletonList( mailingList ) );
223 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
225 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
226 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
227 assertEquals( 1, metadata.getMailingLists().size() );
228 mailingList = metadata.getMailingLists().get( 0 );
229 assertEquals( "Foo List", mailingList.getName() );
230 assertEquals( Collections.<String>emptyList(), mailingList.getOtherArchives() );
234 public void testUpdateProjectVersionMetadataWithAllElements()
237 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
238 metadata.setId( TEST_PROJECT_VERSION );
240 metadata.setName( "project name" );
241 metadata.setDescription( "project description" );
243 MailingList mailingList = new MailingList();
244 mailingList.setName( "Foo List" );
245 mailingList.setOtherArchives( Collections.singletonList( "other archive" ) );
246 metadata.setMailingLists( Collections.singletonList( mailingList ) );
249 scm.setConnection( "connection" );
250 scm.setDeveloperConnection( "dev conn" );
252 metadata.setScm( scm );
254 CiManagement ci = new CiManagement();
255 ci.setSystem( "system" );
256 ci.setUrl( "ci url" );
257 metadata.setCiManagement( ci );
259 IssueManagement tracker = new IssueManagement();
260 tracker.setSystem( "system" );
261 tracker.setUrl( "issue tracker url" );
262 metadata.setIssueManagement( tracker );
264 Organization org = new Organization();
265 org.setName( "org name" );
267 metadata.setOrganization( org );
269 License l = new License();
270 l.setName( "license name" );
271 l.setUrl( "license url" );
272 metadata.addLicense( l );
274 Dependency d = new Dependency();
275 d.setArtifactId( "artifactId" );
276 d.setClassifier( "classifier" );
277 d.setGroupId( "groupId" );
278 d.setScope( "scope" );
279 d.setSystemPath( "system path" );
281 d.setVersion( "version" );
282 d.setOptional( true );
283 metadata.addDependency( d );
285 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
287 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
288 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
289 assertEquals( TEST_PROJECT_VERSION, metadata.getVersion() );
290 assertEquals( "project name", metadata.getName() );
291 assertEquals( "project description", metadata.getDescription() );
293 assertEquals( 1, metadata.getMailingLists().size() );
294 mailingList = metadata.getMailingLists().get( 0 );
295 assertEquals( "Foo List", mailingList.getName() );
296 assertEquals( Collections.singletonList( "other archive" ), mailingList.getOtherArchives() );
298 assertEquals( "connection", metadata.getScm().getConnection() );
299 assertEquals( "dev conn", metadata.getScm().getDeveloperConnection() );
300 assertEquals( "url", metadata.getScm().getUrl() );
302 assertEquals( "system", metadata.getCiManagement().getSystem() );
303 assertEquals( "ci url", metadata.getCiManagement().getUrl() );
305 assertEquals( "system", metadata.getIssueManagement().getSystem() );
306 assertEquals( "issue tracker url", metadata.getIssueManagement().getUrl() );
308 assertEquals( "org name", metadata.getOrganization().getName() );
309 assertEquals( "url", metadata.getOrganization().getUrl() );
311 assertEquals( 1, metadata.getLicenses().size() );
312 l = metadata.getLicenses().get( 0 );
313 assertEquals( "license name", l.getName() );
314 assertEquals( "license url", l.getUrl() );
316 assertEquals( 1, metadata.getDependencies().size() );
317 d = metadata.getDependencies().get( 0 );
318 assertEquals( "artifactId", d.getArtifactId() );
319 assertEquals( "classifier", d.getClassifier() );
320 assertEquals( "groupId", d.getGroupId() );
321 assertEquals( "scope", d.getScope() );
322 assertEquals( "system path", d.getSystemPath() );
323 assertEquals( "type", d.getType() );
324 assertEquals( "version", d.getVersion() );
325 assertTrue( d.isOptional() );
329 public void testGetRepositories()
332 // currently set up this way so the behaviour of both the test and the mock config return the same repository
333 // set as the File implementation just uses the config rather than the content
334 repository.updateNamespace( TEST_REPO_ID, "namespace" );
335 repository.updateNamespace( OTHER_REPO_ID, "namespace" );
337 assertEquals( "repository.getRepositories() -> " + repository.getRepositories(),
338 Arrays.asList( TEST_REPO_ID, OTHER_REPO_ID ),
339 new ArrayList<String>( repository.getRepositories() ) );
343 public void testUpdateProjectVersionMetadataIncomplete()
346 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
347 metadata.setId( TEST_PROJECT_VERSION );
348 metadata.setIncomplete( true );
349 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
351 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
352 assertEquals( true, metadata.isIncomplete() );
353 assertNull( metadata.getCiManagement() );
354 assertNull( metadata.getScm() );
355 assertNull( metadata.getIssueManagement() );
356 assertNull( metadata.getOrganization() );
357 assertNull( metadata.getDescription() );
358 assertNull( metadata.getName() );
359 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
360 assertEquals( TEST_PROJECT_VERSION, metadata.getVersion() );
361 assertTrue( metadata.getMailingLists().isEmpty() );
362 assertTrue( metadata.getLicenses().isEmpty() );
363 assertTrue( metadata.getDependencies().isEmpty() );
367 public void testUpdateProjectVersionMetadataWithExistingFacets()
370 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
371 metadata.setId( TEST_PROJECT_VERSION );
372 MetadataFacet facet = new TestMetadataFacet( "baz" );
373 metadata.addFacet( facet );
374 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
376 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
377 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
379 metadata = new ProjectVersionMetadata();
380 metadata.setId( TEST_PROJECT_VERSION );
381 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
383 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
384 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
385 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
386 assertEquals( "baz", testFacet.getValue() );
390 public void testUpdateProjectVersionMetadataWithNoExistingFacets()
393 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
394 metadata.setId( TEST_PROJECT_VERSION );
395 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
397 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
398 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
400 metadata = new ProjectVersionMetadata();
401 metadata.setId( TEST_PROJECT_VERSION );
402 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
404 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
405 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
409 public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved()
412 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
413 metadata.setId( TEST_PROJECT_VERSION );
415 Map<String, String> additionalProps = new HashMap<String, String>();
416 additionalProps.put( "deleteKey", "deleteValue" );
418 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
419 metadata.addFacet( facet );
420 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
422 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
423 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
425 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
426 Map<String, String> facetProperties = testFacet.toProperties();
428 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
430 facetProperties.remove( "deleteKey" );
432 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue(), facetProperties );
433 metadata.addFacet( newTestFacet );
435 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
437 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
438 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
439 testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
440 assertFalse( testFacet.toProperties().containsKey( "deleteKey" ) );
444 public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets()
447 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
448 versionMetadata.setId( TEST_PROJECT_VERSION );
450 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz" );
451 versionMetadata.addFacet( facet );
452 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata );
454 ArtifactMetadata artifactMetadata = createArtifact();
455 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata );
458 Collection<ArtifactMetadata> artifacts =
459 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
460 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
462 artifacts = repository.getArtifacts( TEST_REPO_ID );
463 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
465 artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 );
466 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
468 artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 );
469 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
471 artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, null, null );
472 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
476 public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved()
479 ArtifactMetadata metadata = createArtifact();
481 Map<String, String> additionalProps = new HashMap<String, String>();
482 additionalProps.put( "deleteKey", "deleteValue" );
484 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
485 metadata.addFacet( facet );
486 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
488 Collection<ArtifactMetadata> artifacts =
489 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
490 assertEquals( 1, artifacts.size() );
491 metadata = artifacts.iterator().next();
492 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
494 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
495 Map<String, String> facetProperties = testFacet.toProperties();
497 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
499 facetProperties.remove( "deleteKey" );
501 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue(), facetProperties );
502 metadata.addFacet( newTestFacet );
504 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
506 artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
507 assertEquals( 1, artifacts.size() );
508 metadata = artifacts.iterator().next();
509 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
510 testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
511 assertFalse( testFacet.toProperties().containsKey( "deleteKey" ) );
515 public void testUpdateArtifactMetadataWithExistingFacets()
518 ArtifactMetadata metadata = createArtifact();
519 MetadataFacet facet = new TestMetadataFacet( "baz" );
520 metadata.addFacet( facet );
521 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
523 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
524 TEST_PROJECT_VERSION ).iterator().next();
525 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
527 metadata = createArtifact();
528 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
530 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
531 TEST_PROJECT_VERSION ).iterator().next();
532 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
533 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
534 assertEquals( "baz", testFacet.getValue() );
538 public void testUpdateArtifactMetadataWithNoExistingFacets()
541 ArtifactMetadata metadata = createArtifact();
542 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
544 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
545 TEST_PROJECT_VERSION ).iterator().next();
546 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
548 metadata = createArtifact();
549 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
551 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
552 TEST_PROJECT_VERSION ).iterator().next();
553 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
557 public void testGetMetadataFacet()
560 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
562 assertEquals( new TestMetadataFacet( TEST_VALUE ),
563 repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
567 public void testGetMetadataFacetWhenEmpty()
570 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
574 public void testGetMetadataFacetWhenUnknownName()
577 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
579 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) );
583 public void testGetMetadataFacetWhenDefaultValue()
586 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) );
588 assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ),
589 repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
593 public void testGetMetadataFacetWhenUnknownFacetId()
596 assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
600 public void testGetMetadataFacets()
603 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
605 assertEquals( Collections.singletonList( TEST_NAME ),
606 repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ) );
610 public void testGetMetadataFacetsWhenEmpty()
614 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
615 assertTrue( facets.isEmpty() );
619 public void testRemoveFacets()
622 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
624 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
625 assertFalse( facets.isEmpty() );
627 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
629 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
630 assertTrue( facets.isEmpty() );
634 public void testRemoveFacetsWhenEmpty()
637 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
638 assertTrue( facets.isEmpty() );
640 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
642 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
643 assertTrue( facets.isEmpty() );
647 public void testRemoveFacetsWhenUnknown()
650 // testing no exception
651 repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN );
655 public void testRemoveFacetWhenUnknown()
658 // testing no exception
659 repository.removeMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME );
663 public void testRemoveFacet()
666 TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
667 repository.addMetadataFacet( TEST_REPO_ID, metadataFacet );
669 assertEquals( metadataFacet, repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
670 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
671 assertFalse( facets.isEmpty() );
673 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
675 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
676 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
677 assertTrue( facets.isEmpty() );
681 public void testRemoveFacetWhenEmpty()
684 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
685 assertTrue( facets.isEmpty() );
686 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
688 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
690 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
691 assertTrue( facets.isEmpty() );
692 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
696 public void testGetArtifacts()
699 ArtifactMetadata artifact1 = createArtifact();
700 ArtifactMetadata artifact2 = createArtifact( "pom" );
701 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
702 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
704 Collection<ArtifactMetadata> artifacts =
705 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
706 ArrayList<ArtifactMetadata> actual = new ArrayList<ArtifactMetadata>( artifacts );
707 Collections.sort( actual, new Comparator<ArtifactMetadata>()
709 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
711 return o1.getId().compareTo( o2.getId() );
714 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
718 public void testGetArtifactVersions()
721 ArtifactMetadata artifact1 = createArtifact();
722 String version1 = "1.0-20091212.012345-1";
723 artifact1.setId( artifact1.getProject() + "-" + version1 + ".jar" );
724 artifact1.setVersion( version1 );
725 ArtifactMetadata artifact2 = createArtifact();
726 String version2 = "1.0-20091212.123456-2";
727 artifact2.setId( artifact2.getProject() + "-" + version2 + ".jar" );
728 artifact2.setVersion( version2 );
729 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
730 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
732 List<String> versions = new ArrayList<String>(
733 repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
734 Collections.sort( versions );
735 assertEquals( Arrays.asList( version1, version2 ), versions );
739 public void testGetArtifactVersionsMultipleArtifactsSingleVersion()
742 ArtifactMetadata artifact1 = createArtifact();
743 artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
744 ArtifactMetadata artifact2 = createArtifact();
745 artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
746 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
747 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
749 assertEquals( Collections.singleton( TEST_PROJECT_VERSION ),
750 repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
751 TEST_PROJECT_VERSION ) );
755 public void testGetArtifactsByDateRangeOpen()
758 ArtifactMetadata artifact = createArtifact();
759 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
762 assertEquals( Collections.singletonList( artifact ),
763 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
767 public void testGetArtifactsByDateRangeSparseNamespace()
770 String namespace = "org.apache.archiva";
771 ArtifactMetadata artifact = createArtifact();
772 artifact.setNamespace( namespace );
773 repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
776 assertEquals( Collections.singletonList( artifact ),
777 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
781 public void testGetArtifactsByDateRangeLowerBound()
784 ArtifactMetadata artifact = createArtifact();
785 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
788 Date date = new Date( artifact.getWhenGathered().getTime() - 10000 );
789 assertEquals( Collections.singletonList( artifact ),
790 repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ) );
794 public void testGetArtifactsByDateRangeLowerBoundOutOfRange()
797 ArtifactMetadata artifact = createArtifact();
798 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
800 Date date = new Date( artifact.getWhenGathered().getTime() + 10000 );
801 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ).isEmpty() );
805 public void testGetArtifactsByDateRangeLowerAndUpperBound()
808 ArtifactMetadata artifact = createArtifact();
809 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
812 Date lower = new Date( artifact.getWhenGathered().getTime() - 10000 );
813 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
814 assertEquals( Collections.singletonList( artifact ),
815 repository.getArtifactsByDateRange( TEST_REPO_ID, lower, upper ) );
819 public void testGetArtifactsByDateRangeUpperBound()
822 ArtifactMetadata artifact = createArtifact();
823 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
826 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
827 assertEquals( Collections.singletonList( artifact ),
828 repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ) );
832 public void testGetArtifactsByDateRangeUpperBoundOutOfRange()
835 ArtifactMetadata artifact = createArtifact();
836 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
839 Date upper = new Date( artifact.getWhenGathered().getTime() - 10000 );
840 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ).isEmpty() );
844 public void testGetArtifactsByRepoId()
847 ArtifactMetadata artifact = createArtifact();
848 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
851 assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) );
855 public void testGetArtifactsByRepoIdMultipleCopies()
858 ArtifactMetadata artifact = createArtifact();
859 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
861 ArtifactMetadata secondArtifact = createArtifact();
862 secondArtifact.setRepositoryId( OTHER_REPO_ID );
863 repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
866 // test it restricts to the appropriate repository
867 assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) );
868 assertEquals( Collections.singletonList( secondArtifact ), repository.getArtifacts( OTHER_REPO_ID ) );
872 public void testGetArtifactsByDateRangeMultipleCopies()
875 ArtifactMetadata artifact = createArtifact();
876 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
878 ArtifactMetadata secondArtifact = createArtifact();
879 secondArtifact.setRepositoryId( OTHER_REPO_ID );
880 repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
883 // test it restricts to the appropriate repository
884 assertEquals( Collections.singletonList( artifact ),
885 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
886 assertEquals( Collections.singletonList( secondArtifact ),
887 repository.getArtifactsByDateRange( OTHER_REPO_ID, null, null ) );
891 public void testGetArtifactsByChecksumMultipleCopies()
894 ArtifactMetadata artifact = createArtifact();
895 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
897 ArtifactMetadata secondArtifact = createArtifact();
898 secondArtifact.setRepositoryId( OTHER_REPO_ID );
899 repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
902 // test it restricts to the appropriate repository
903 assertEquals( Collections.singletonList( artifact ),
904 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
905 assertEquals( Collections.singletonList( secondArtifact ),
906 repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_SHA1 ) );
907 assertEquals( Collections.singletonList( artifact ),
908 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
909 assertEquals( Collections.singletonList( secondArtifact ),
910 repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_MD5 ) );
914 public void testGetNamespacesWithSparseDepth()
917 repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
919 assertEquals( Arrays.asList( "org" ), repository.getRootNamespaces( TEST_REPO_ID ) );
920 assertEquals( Arrays.asList( "apache" ), repository.getNamespaces( TEST_REPO_ID, "org" ) );
921 assertEquals( Arrays.asList( "maven" ), repository.getNamespaces( TEST_REPO_ID, "org.apache" ) );
922 assertEquals( Arrays.asList( "shared" ), repository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) );
926 public void testGetNamespacesWithProjectsPresent()
929 String namespace = "org.apache.maven.shared";
930 repository.updateNamespace( TEST_REPO_ID, namespace );
932 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
933 metadata.setId( TEST_PROJECT_VERSION );
934 repository.updateProjectVersion( TEST_REPO_ID, namespace, TEST_PROJECT, metadata );
936 assertEquals( Collections.<String>emptyList(), repository.getNamespaces( TEST_REPO_ID, namespace ) );
940 public void testGetProjectsWithOtherNamespacesPresent()
943 ProjectMetadata projectMetadata = new ProjectMetadata();
944 projectMetadata.setId( TEST_PROJECT );
945 projectMetadata.setNamespace( "org.apache.maven" );
946 repository.updateProject( TEST_REPO_ID, projectMetadata );
948 repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
950 assertEquals( Collections.singletonList( TEST_PROJECT ),
951 repository.getProjects( TEST_REPO_ID, "org.apache.maven" ) );
955 public void testGetProjectVersionsWithOtherNamespacesPresent()
958 // an unusual case but technically possible where a project namespace matches another project's name
960 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
961 versionMetadata.setId( TEST_PROJECT_VERSION );
962 repository.updateProjectVersion( TEST_REPO_ID, "org.apache.maven", TEST_PROJECT, versionMetadata );
964 repository.updateProjectVersion( TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT, "other-project",
967 List<String> expectedVersions = Collections.singletonList( TEST_PROJECT_VERSION );
968 assertEquals( expectedVersions, repository.getProjectVersions( TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT,
970 assertEquals( expectedVersions,
971 repository.getProjectVersions( TEST_REPO_ID, "org.apache.maven", TEST_PROJECT ) );
975 public void testGetArtifactsByChecksumSingleResultMd5()
978 ArtifactMetadata artifact = createArtifact();
979 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
982 assertEquals( Collections.singletonList( artifact ),
983 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
987 public void testGetArtifactsByChecksumSingleResultSha1()
990 ArtifactMetadata artifact = createArtifact();
991 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
994 assertEquals( Collections.singletonList( artifact ),
995 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
999 public void testGetArtifactsByChecksumDeepNamespace()
1002 ArtifactMetadata artifact = createArtifact();
1003 String namespace = "multi.level.ns";
1004 artifact.setNamespace( namespace );
1005 repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1008 assertEquals( Collections.singletonList( artifact ),
1009 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
1010 assertEquals( Collections.singletonList( artifact ),
1011 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
1015 public void testGetArtifactsByChecksumMultipleResult()
1018 ArtifactMetadata artifact1 = createArtifact();
1019 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1021 String newProjectId = "another-project";
1022 ArtifactMetadata artifact2 = createArtifact();
1023 artifact2.setProject( newProjectId );
1024 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
1027 List<ArtifactMetadata> artifacts =
1028 new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
1029 Collections.sort( artifacts, new ArtifactMetadataComparator() );
1030 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1032 artifacts = new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
1033 Collections.sort( artifacts, new ArtifactMetadataComparator() );
1034 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1038 public void testGetArtifactsByChecksumNoResult()
1041 ArtifactMetadata artifact = createArtifact();
1042 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1044 List<ArtifactMetadata> artifactsByChecksum = repository.getArtifactsByChecksum( TEST_REPO_ID, "not checksum" );
1045 assertEquals( Collections.<ArtifactMetadata>emptyList(), artifactsByChecksum );
1050 public void testDeleteRepository()
1053 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
1055 ProjectMetadata project1 = new ProjectMetadata();
1056 project1.setNamespace( TEST_NAMESPACE );
1057 project1.setId( "project1" );
1058 repository.updateProject( TEST_REPO_ID, project1 );
1059 ProjectMetadata project2 = new ProjectMetadata();
1060 project2.setNamespace( TEST_NAMESPACE );
1061 project2.setId( "project2" );
1062 repository.updateProject( TEST_REPO_ID, project2 );
1064 ArtifactMetadata artifact1 = createArtifact();
1065 artifact1.setProject( "project1" );
1066 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
1067 ArtifactMetadata artifact2 = createArtifact();
1068 artifact2.setProject( "project2" );
1069 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
1072 List<ArtifactMetadata> expected = Arrays.asList( artifact1, artifact2 );
1073 Collections.sort( expected, new ArtifactMetadataComparator() );
1075 List<ArtifactMetadata> actual =
1076 new ArrayList<ArtifactMetadata>( repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
1077 Collections.sort( actual, new ArtifactMetadataComparator() );
1079 assertEquals( expected, actual );
1081 repository.removeRepository( TEST_REPO_ID );
1083 assertTrue( repository.getArtifacts( TEST_REPO_ID ).isEmpty() );
1084 assertTrue( repository.getRootNamespaces( TEST_REPO_ID ).isEmpty() );
1089 public void testDeleteArtifact()
1092 ArtifactMetadata artifact = createArtifact();
1093 artifact.addFacet( new TestMetadataFacet( "value" ) );
1095 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1097 assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>(
1098 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
1100 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact );
1102 Collection<String> versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1104 log.info( "versions {}", versions );
1106 Assertions.assertThat( versions ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "1.0", "2.0" );
1108 repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
1110 versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1112 log.info( "versions {}", versions );
1114 Assertions.assertThat( versions ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "2.0" );
1117 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() );
1119 Assertions.assertThat( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
1120 TEST_PROJECT_VERSION_2_0 ) ).isNotEmpty().hasSize( 1 );
1124 public void deleteVersion()
1127 ArtifactMetadata artifact = createArtifact();
1128 artifact.addFacet( new TestMetadataFacet( "value" ) );
1130 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1132 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1134 assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>(
1135 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
1137 repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
1140 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() );
1144 public void deleteSnapshotVersion()
1147 ArtifactMetadata artifactOne = createArtifact();
1148 artifactOne.setVersion( "2.0-20120618.214127-1" );
1149 artifactOne.setProjectVersion( "2.0-SNAPSHOT" );
1150 artifactOne.addFacet( new TestMetadataFacet( "value" ) );
1151 artifactOne.setId( TEST_PROJECT + "-" + "2.0-20120618.214127-1" + "." + "jar" );
1153 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactOne );
1155 ArtifactMetadata artifactTwo = createArtifact();
1156 artifactTwo.setVersion( "2.0-20120618.214135-2" );
1157 artifactTwo.setProjectVersion( "2.0-SNAPSHOT" );
1158 artifactTwo.addFacet( new TestMetadataFacet( "value" ) );
1159 artifactTwo.setId( TEST_PROJECT + "-" + "2.0-20120618.214135-2" + "." + "jar" );
1161 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactTwo );
1163 Collection<ArtifactMetadata> artifactMetadatas =
1164 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
1166 Assertions.assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 2 );
1168 log.info( "artifactMetadatas: {}", artifactMetadatas );
1170 //assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>(
1171 // repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" ) ) );
1173 repository.removeArtifact( artifactOne, "2.0-SNAPSHOT" );
1175 artifactMetadatas = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
1177 Assertions.assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 1 );
1179 repository.removeArtifact( artifactTwo, "2.0-SNAPSHOT" );
1181 artifactMetadatas = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
1183 Assertions.assertThat( artifactMetadatas ).isNotNull().isEmpty();
1186 private static ProjectMetadata createProject()
1188 return createProject( TEST_NAMESPACE );
1191 private static ProjectMetadata createProject( String ns )
1193 ProjectMetadata project = new ProjectMetadata();
1194 project.setId( TEST_PROJECT );
1195 project.setNamespace( ns );
1199 private static ArtifactMetadata createArtifact()
1201 return createArtifact( "jar" );
1204 private static ArtifactMetadata createArtifact( String type )
1206 ArtifactMetadata artifact = new ArtifactMetadata();
1207 artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
1208 artifact.setWhenGathered( new Date() );
1209 artifact.setNamespace( TEST_NAMESPACE );
1210 artifact.setProject( TEST_PROJECT );
1211 artifact.setRepositoryId( TEST_REPO_ID );
1212 artifact.setFileLastModified( System.currentTimeMillis() );
1213 artifact.setVersion( TEST_PROJECT_VERSION );
1214 artifact.setProjectVersion( TEST_PROJECT_VERSION );
1215 artifact.setMd5( TEST_MD5 );
1216 artifact.setSha1( TEST_SHA1 );
1220 private static class ArtifactMetadataComparator
1221 implements Comparator<ArtifactMetadata>
1223 public final int compare( ArtifactMetadata a, ArtifactMetadata b )
1225 return a.getProject().compareTo( b.getProject() );
1229 private static class TestMetadataFacet
1230 implements MetadataFacet
1232 private String testFacetId;
1234 private Map<String, String> additionalProps;
1236 private String value;
1238 private TestMetadataFacet( String value )
1241 testFacetId = TEST_FACET_ID;
1244 private TestMetadataFacet( String facetId, String value )
1247 testFacetId = facetId;
1250 private TestMetadataFacet( String facetId, String value, Map<String, String> additionalProps )
1252 this( facetId, value );
1253 this.additionalProps = additionalProps;
1256 public String getFacetId()
1261 public String getName()
1266 public Map<String, String> toProperties()
1268 if ( value != null )
1270 if ( additionalProps == null )
1272 return Collections.singletonMap( "foo", value );
1276 Map<String, String> props = new HashMap<String, String>();
1277 props.put( "foo", value );
1279 for ( String key : additionalProps.keySet() )
1281 props.put( key, additionalProps.get( key ) );
1288 return Collections.emptyMap();
1292 public void fromProperties( Map<String, String> properties )
1294 String value = properties.get( "foo" );
1295 if ( value != null )
1300 properties.remove( "foo" );
1302 if ( additionalProps == null )
1304 additionalProps = new HashMap<String, String>();
1307 for ( String key : properties.keySet() )
1309 additionalProps.put( key, properties.get( key ) );
1313 public String getValue()
1319 public String toString()
1321 return "TestMetadataFacet{" + "value='" + value + '\'' + '}';
1325 public boolean equals( Object o )
1331 if ( o == null || getClass() != o.getClass() )
1336 TestMetadataFacet that = (TestMetadataFacet) o;
1338 if ( value != null ? !value.equals( that.value ) : that.value != null )
1347 public int hashCode()
1349 return value != null ? value.hashCode() : 0;