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.Ignore;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.test.context.ContextConfiguration;
42 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
44 import java.util.ArrayList;
45 import java.util.Arrays;
46 import java.util.Collection;
47 import java.util.Collections;
48 import java.util.Comparator;
49 import java.util.Date;
50 import java.util.HashMap;
51 import java.util.List;
54 @RunWith( SpringJUnit4ClassRunner.class )
55 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
56 public abstract class AbstractMetadataRepositoryTest
59 protected static final String OTHER_REPO_ID = "other-repo";
61 protected MetadataRepository repository;
63 protected static final String TEST_REPO_ID = "test";
65 private static final String TEST_PROJECT = "projectId";
67 private static final String TEST_NAMESPACE = "namespace";
69 private static final String TEST_PROJECT_VERSION = "1.0";
71 private static final String TEST_PROJECT_VERSION_2_0 = "2.0";
73 private static final String TEST_FACET_ID = "test-facet-id";
75 private static final String TEST_NAME = "test/name";
77 private static final String TEST_VALUE = "test-value";
79 private static final String UNKNOWN = "unknown";
81 private static final String TEST_MD5 = "bd4a9b642562547754086de2dab26b7d";
83 private static final String TEST_SHA1 = "2e5daf0201ddeb068a62d5e08da18657ab2c6be9";
85 private static final String TEST_METADATA_VALUE = "test-metadata";
87 protected Logger log = LoggerFactory.getLogger( getClass() );
89 protected static Map<String, MetadataFacetFactory> createTestMetadataFacetFactories()
91 Map<String, MetadataFacetFactory> factories = new HashMap<String, MetadataFacetFactory>();
92 factories.put( TEST_FACET_ID, new MetadataFacetFactory()
94 public MetadataFacet createMetadataFacet()
96 return new TestMetadataFacet( TEST_METADATA_VALUE );
99 public MetadataFacet createMetadataFacet( String repositoryId, String name )
101 return new TestMetadataFacet( TEST_METADATA_VALUE );
105 // add to ensure we don't accidentally create an empty facet ID.
106 factories.put( "", new MetadataFacetFactory()
108 public MetadataFacet createMetadataFacet()
110 return new TestMetadataFacet( "", TEST_VALUE );
113 public MetadataFacet createMetadataFacet( String repositoryId, String name )
115 return new TestMetadataFacet( "", TEST_VALUE );
122 public void testRootNamespaceWithNoMetadataRepository()
125 Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID );
126 assertEquals( Collections.<String>emptyList(), namespaces );
130 public void testGetNamespaceOnly()
133 assertEquals( Collections.emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) );
135 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
137 assertEquals( Collections.singletonList( TEST_NAMESPACE ), repository.getRootNamespaces( TEST_REPO_ID ) );
141 public void testGetProjectOnly()
144 assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
145 assertEquals( Collections.emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) );
147 ProjectMetadata project = new ProjectMetadata();
148 project.setId( TEST_PROJECT );
149 project.setNamespace( TEST_NAMESPACE );
151 repository.updateProject( TEST_REPO_ID, project );
153 project = repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
154 assertEquals( TEST_PROJECT, project.getId() );
155 assertEquals( TEST_NAMESPACE, project.getNamespace() );
157 // test that namespace is also constructed
158 assertEquals( Collections.singletonList( TEST_NAMESPACE ), repository.getRootNamespaces( TEST_REPO_ID ) );
162 public void testGetProjectVersionOnly()
165 assertNull( repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
166 assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
167 assertEquals( Collections.<String>emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) );
169 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
170 metadata.setId( TEST_PROJECT_VERSION );
172 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
174 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
175 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
177 // test that namespace and project is also constructed
178 assertEquals( Collections.singletonList( TEST_NAMESPACE ), repository.getRootNamespaces( TEST_REPO_ID ) );
179 ProjectMetadata projectMetadata = repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
180 assertEquals( TEST_PROJECT, projectMetadata.getId() );
181 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace() );
185 public void testGetArtifactOnly()
188 assertEquals( Collections.<ArtifactMetadata>emptyList(), new ArrayList<ArtifactMetadata>(
189 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
190 assertNull( repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
191 assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
192 assertEquals( Collections.<String>emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) );
194 ArtifactMetadata metadata = createArtifact();
196 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
198 Collection<ArtifactMetadata> artifacts =
199 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
200 assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
202 // test that namespace, project and project version is also constructed
203 assertEquals( Collections.singletonList( TEST_NAMESPACE ), repository.getRootNamespaces( TEST_REPO_ID ) );
205 ProjectMetadata projectMetadata = repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
206 assertEquals( TEST_PROJECT, projectMetadata.getId() );
207 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace() );
209 ProjectVersionMetadata projectVersionMetadata =
210 repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
211 assertEquals( TEST_PROJECT_VERSION, projectVersionMetadata.getId() );
215 public void testUpdateProjectVersionMetadataWithNoOtherArchives()
218 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
219 metadata.setId( TEST_PROJECT_VERSION );
220 MailingList mailingList = new MailingList();
221 mailingList.setName( "Foo List" );
222 mailingList.setOtherArchives( Collections.<String>emptyList() );
223 metadata.setMailingLists( Collections.singletonList( mailingList ) );
224 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
226 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
227 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
228 assertEquals( 1, metadata.getMailingLists().size() );
229 mailingList = metadata.getMailingLists().get( 0 );
230 assertEquals( "Foo List", mailingList.getName() );
231 assertEquals( Collections.<String>emptyList(), mailingList.getOtherArchives() );
235 public void testUpdateProjectVersionMetadataWithAllElements()
238 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
239 metadata.setId( TEST_PROJECT_VERSION );
241 metadata.setName( "project name" );
242 metadata.setDescription( "project description" );
244 MailingList mailingList = new MailingList();
245 mailingList.setName( "Foo List" );
246 mailingList.setOtherArchives( Collections.singletonList( "other archive" ) );
247 metadata.setMailingLists( Collections.singletonList( mailingList ) );
250 scm.setConnection( "connection" );
251 scm.setDeveloperConnection( "dev conn" );
253 metadata.setScm( scm );
255 CiManagement ci = new CiManagement();
256 ci.setSystem( "system" );
257 ci.setUrl( "ci url" );
258 metadata.setCiManagement( ci );
260 IssueManagement tracker = new IssueManagement();
261 tracker.setSystem( "system" );
262 tracker.setUrl( "issue tracker url" );
263 metadata.setIssueManagement( tracker );
265 Organization org = new Organization();
266 org.setName( "org name" );
268 metadata.setOrganization( org );
270 License l = new License();
271 l.setName( "license name" );
272 l.setUrl( "license url" );
273 metadata.addLicense( l );
275 Dependency d = new Dependency();
276 d.setArtifactId( "artifactId" );
277 d.setClassifier( "classifier" );
278 d.setGroupId( "groupId" );
279 d.setScope( "scope" );
280 d.setSystemPath( "system path" );
282 d.setVersion( "version" );
283 d.setOptional( true );
284 metadata.addDependency( d );
286 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
288 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
289 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
290 assertEquals( TEST_PROJECT_VERSION, metadata.getVersion() );
291 assertEquals( "project name", metadata.getName() );
292 assertEquals( "project description", metadata.getDescription() );
294 assertEquals( 1, metadata.getMailingLists().size() );
295 mailingList = metadata.getMailingLists().get( 0 );
296 assertEquals( "Foo List", mailingList.getName() );
297 assertEquals( Collections.singletonList( "other archive" ), mailingList.getOtherArchives() );
299 assertEquals( "connection", metadata.getScm().getConnection() );
300 assertEquals( "dev conn", metadata.getScm().getDeveloperConnection() );
301 assertEquals( "url", metadata.getScm().getUrl() );
303 assertEquals( "system", metadata.getCiManagement().getSystem() );
304 assertEquals( "ci url", metadata.getCiManagement().getUrl() );
306 assertEquals( "system", metadata.getIssueManagement().getSystem() );
307 assertEquals( "issue tracker url", metadata.getIssueManagement().getUrl() );
309 assertEquals( "org name", metadata.getOrganization().getName() );
310 assertEquals( "url", metadata.getOrganization().getUrl() );
312 assertEquals( 1, metadata.getLicenses().size() );
313 l = metadata.getLicenses().get( 0 );
314 assertEquals( "license name", l.getName() );
315 assertEquals( "license url", l.getUrl() );
317 assertEquals( 1, metadata.getDependencies().size() );
318 d = metadata.getDependencies().get( 0 );
319 assertEquals( "artifactId", d.getArtifactId() );
320 assertEquals( "classifier", d.getClassifier() );
321 assertEquals( "groupId", d.getGroupId() );
322 assertEquals( "scope", d.getScope() );
323 assertEquals( "system path", d.getSystemPath() );
324 assertEquals( "type", d.getType() );
325 assertEquals( "version", d.getVersion() );
326 assertTrue( d.isOptional() );
330 public void testGetRepositories()
333 // currently set up this way so the behaviour of both the test and the mock config return the same repository
334 // set as the File implementation just uses the config rather than the content
335 repository.updateNamespace( TEST_REPO_ID, "namespace" );
336 repository.updateNamespace( OTHER_REPO_ID, "namespace" );
338 assertEquals( "repository.getRepositories() -> " + repository.getRepositories(),
339 Arrays.asList( TEST_REPO_ID, OTHER_REPO_ID ),
340 new ArrayList<String>( repository.getRepositories() ) );
344 public void testUpdateProjectVersionMetadataIncomplete()
347 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
348 metadata.setId( TEST_PROJECT_VERSION );
349 metadata.setIncomplete( true );
350 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
352 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
353 assertEquals( true, metadata.isIncomplete() );
354 assertNull( metadata.getCiManagement() );
355 assertNull( metadata.getScm() );
356 assertNull( metadata.getIssueManagement() );
357 assertNull( metadata.getOrganization() );
358 assertNull( metadata.getDescription() );
359 assertNull( metadata.getName() );
360 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
361 assertEquals( TEST_PROJECT_VERSION, metadata.getVersion() );
362 assertTrue( metadata.getMailingLists().isEmpty() );
363 assertTrue( metadata.getLicenses().isEmpty() );
364 assertTrue( metadata.getDependencies().isEmpty() );
368 public void testUpdateProjectVersionMetadataWithExistingFacets()
371 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
372 metadata.setId( TEST_PROJECT_VERSION );
373 MetadataFacet facet = new TestMetadataFacet( "baz" );
374 metadata.addFacet( facet );
375 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
377 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
378 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
380 metadata = new ProjectVersionMetadata();
381 metadata.setId( TEST_PROJECT_VERSION );
382 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
384 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
385 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
386 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
387 assertEquals( "baz", testFacet.getValue() );
391 public void testUpdateProjectVersionMetadataWithNoExistingFacets()
394 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
395 metadata.setId( TEST_PROJECT_VERSION );
396 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
398 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
399 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
401 metadata = new ProjectVersionMetadata();
402 metadata.setId( TEST_PROJECT_VERSION );
403 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
405 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
406 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
410 public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved()
413 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
414 metadata.setId( TEST_PROJECT_VERSION );
416 Map<String, String> additionalProps = new HashMap<String, String>();
417 additionalProps.put( "deleteKey", "deleteValue" );
419 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
420 metadata.addFacet( facet );
421 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
423 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
424 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
426 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
427 Map<String, String> facetProperties = testFacet.toProperties();
429 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
431 facetProperties.remove( "deleteKey" );
433 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue(), facetProperties );
434 metadata.addFacet( newTestFacet );
436 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
438 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
439 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
440 testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
441 assertFalse( testFacet.toProperties().containsKey( "deleteKey" ) );
445 public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets()
448 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
449 versionMetadata.setId( TEST_PROJECT_VERSION );
451 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz" );
452 versionMetadata.addFacet( facet );
453 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata );
455 ArtifactMetadata artifactMetadata = createArtifact();
456 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata );
459 Collection<ArtifactMetadata> artifacts =
460 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
461 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
463 artifacts = repository.getArtifacts( TEST_REPO_ID );
464 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
466 artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 );
467 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
469 artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 );
470 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
472 artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, null, null );
473 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
477 public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved()
480 ArtifactMetadata metadata = createArtifact();
482 Map<String, String> additionalProps = new HashMap<String, String>();
483 additionalProps.put( "deleteKey", "deleteValue" );
485 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
486 metadata.addFacet( facet );
487 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
489 Collection<ArtifactMetadata> artifacts =
490 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
491 assertEquals( 1, artifacts.size() );
492 metadata = artifacts.iterator().next();
493 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
495 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
496 Map<String, String> facetProperties = testFacet.toProperties();
498 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
500 facetProperties.remove( "deleteKey" );
502 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue(), facetProperties );
503 metadata.addFacet( newTestFacet );
505 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
507 artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
508 assertEquals( 1, artifacts.size() );
509 metadata = artifacts.iterator().next();
510 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
511 testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
512 assertFalse( testFacet.toProperties().containsKey( "deleteKey" ) );
516 public void testUpdateArtifactMetadataWithExistingFacets()
519 ArtifactMetadata metadata = createArtifact();
520 MetadataFacet facet = new TestMetadataFacet( "baz" );
521 metadata.addFacet( facet );
522 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
524 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
525 TEST_PROJECT_VERSION ).iterator().next();
526 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
528 metadata = createArtifact();
529 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
531 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
532 TEST_PROJECT_VERSION ).iterator().next();
533 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
534 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
535 assertEquals( "baz", testFacet.getValue() );
539 public void testUpdateArtifactMetadataWithNoExistingFacets()
542 ArtifactMetadata metadata = createArtifact();
543 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
545 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
546 TEST_PROJECT_VERSION ).iterator().next();
547 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
549 metadata = createArtifact();
550 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
552 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
553 TEST_PROJECT_VERSION ).iterator().next();
554 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
558 public void testGetMetadataFacet()
561 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
563 assertEquals( new TestMetadataFacet( TEST_VALUE ),
564 repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
568 public void testGetMetadataFacetWhenEmpty()
571 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
575 public void testGetMetadataFacetWhenUnknownName()
578 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
580 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) );
584 public void testGetMetadataFacetWhenDefaultValue()
587 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) );
589 assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ),
590 repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
594 public void testGetMetadataFacetWhenUnknownFacetId()
597 assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
601 public void testGetMetadataFacets()
604 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
606 assertEquals( Collections.singletonList( TEST_NAME ),
607 repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ) );
611 public void testGetMetadataFacetsWhenEmpty()
615 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
616 assertTrue( facets.isEmpty() );
620 public void testRemoveFacets()
623 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
625 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
626 assertFalse( facets.isEmpty() );
628 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
630 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
631 assertTrue( facets.isEmpty() );
635 public void testRemoveFacetsWhenEmpty()
638 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
639 assertTrue( facets.isEmpty() );
641 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
643 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
644 assertTrue( facets.isEmpty() );
648 public void testRemoveFacetsWhenUnknown()
651 // testing no exception
652 repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN );
656 public void testRemoveFacetWhenUnknown()
659 // testing no exception
660 repository.removeMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME );
664 public void testRemoveFacet()
667 TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
668 repository.addMetadataFacet( TEST_REPO_ID, metadataFacet );
670 assertEquals( metadataFacet, repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
671 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
672 assertFalse( facets.isEmpty() );
674 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
676 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
677 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
678 assertTrue( facets.isEmpty() );
682 public void testRemoveFacetWhenEmpty()
685 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
686 assertTrue( facets.isEmpty() );
687 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
689 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
691 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
692 assertTrue( facets.isEmpty() );
693 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
697 public void testGetArtifacts()
700 ArtifactMetadata artifact1 = createArtifact();
701 ArtifactMetadata artifact2 = createArtifact( "pom" );
702 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
703 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
705 Collection<ArtifactMetadata> artifacts =
706 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
707 ArrayList<ArtifactMetadata> actual = new ArrayList<ArtifactMetadata>( artifacts );
708 Collections.sort( actual, new Comparator<ArtifactMetadata>()
710 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
712 return o1.getId().compareTo( o2.getId() );
715 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
719 public void testGetArtifactVersions()
722 ArtifactMetadata artifact1 = createArtifact();
723 String version1 = "1.0-20091212.012345-1";
724 artifact1.setId( artifact1.getProject() + "-" + version1 + ".jar" );
725 artifact1.setVersion( version1 );
726 ArtifactMetadata artifact2 = createArtifact();
727 String version2 = "1.0-20091212.123456-2";
728 artifact2.setId( artifact2.getProject() + "-" + version2 + ".jar" );
729 artifact2.setVersion( version2 );
730 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
731 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
733 List<String> versions = new ArrayList<String>(
734 repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
735 Collections.sort( versions );
736 assertEquals( Arrays.asList( version1, version2 ), versions );
740 public void testGetArtifactVersionsMultipleArtifactsSingleVersion()
743 ArtifactMetadata artifact1 = createArtifact();
744 artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
745 ArtifactMetadata artifact2 = createArtifact();
746 artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
747 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
748 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
750 assertEquals( Collections.singleton( TEST_PROJECT_VERSION ),
751 repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
752 TEST_PROJECT_VERSION ) );
756 public void testGetArtifactsByDateRangeOpen()
759 ArtifactMetadata artifact = createArtifact();
760 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
763 assertEquals( Collections.singletonList( artifact ),
764 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
768 public void testGetArtifactsByDateRangeSparseNamespace()
771 String namespace = "org.apache.archiva";
772 ArtifactMetadata artifact = createArtifact();
773 artifact.setNamespace( namespace );
774 repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
777 assertEquals( Collections.singletonList( artifact ),
778 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
782 public void testGetArtifactsByDateRangeLowerBound()
785 ArtifactMetadata artifact = createArtifact();
786 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
789 Date date = new Date( artifact.getWhenGathered().getTime() - 10000 );
790 assertEquals( Collections.singletonList( artifact ),
791 repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ) );
795 public void testGetArtifactsByDateRangeLowerBoundOutOfRange()
798 ArtifactMetadata artifact = createArtifact();
799 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
801 Date date = new Date( artifact.getWhenGathered().getTime() + 10000 );
802 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ).isEmpty() );
806 public void testGetArtifactsByDateRangeLowerAndUpperBound()
809 ArtifactMetadata artifact = createArtifact();
810 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
813 Date lower = new Date( artifact.getWhenGathered().getTime() - 10000 );
814 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
815 assertEquals( Collections.singletonList( artifact ),
816 repository.getArtifactsByDateRange( TEST_REPO_ID, lower, upper ) );
820 public void testGetArtifactsByDateRangeUpperBound()
823 ArtifactMetadata artifact = createArtifact();
824 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
827 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
828 assertEquals( Collections.singletonList( artifact ),
829 repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ) );
833 public void testGetArtifactsByDateRangeUpperBoundOutOfRange()
836 ArtifactMetadata artifact = createArtifact();
837 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
840 Date upper = new Date( artifact.getWhenGathered().getTime() - 10000 );
841 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ).isEmpty() );
845 public void testGetArtifactsByRepoId()
848 ArtifactMetadata artifact = createArtifact();
849 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
852 assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) );
856 public void testGetArtifactsByRepoIdMultipleCopies()
859 ArtifactMetadata artifact = createArtifact();
860 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
862 ArtifactMetadata secondArtifact = createArtifact();
863 secondArtifact.setRepositoryId( OTHER_REPO_ID );
864 repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
867 // test it restricts to the appropriate repository
868 assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) );
869 assertEquals( Collections.singletonList( secondArtifact ), repository.getArtifacts( OTHER_REPO_ID ) );
873 public void testGetArtifactsByDateRangeMultipleCopies()
876 ArtifactMetadata artifact = createArtifact();
877 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
879 ArtifactMetadata secondArtifact = createArtifact();
880 secondArtifact.setRepositoryId( OTHER_REPO_ID );
881 repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
884 // test it restricts to the appropriate repository
885 assertEquals( Collections.singletonList( artifact ),
886 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
887 assertEquals( Collections.singletonList( secondArtifact ),
888 repository.getArtifactsByDateRange( OTHER_REPO_ID, null, null ) );
892 public void testGetArtifactsByChecksumMultipleCopies()
895 ArtifactMetadata artifact = createArtifact();
896 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
898 ArtifactMetadata secondArtifact = createArtifact();
899 secondArtifact.setRepositoryId( OTHER_REPO_ID );
900 repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
903 // test it restricts to the appropriate repository
904 assertEquals( Collections.singletonList( artifact ),
905 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
906 assertEquals( Collections.singletonList( secondArtifact ),
907 repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_SHA1 ) );
908 assertEquals( Collections.singletonList( artifact ),
909 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
910 assertEquals( Collections.singletonList( secondArtifact ),
911 repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_MD5 ) );
915 public void testGetNamespacesWithSparseDepth()
918 repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
920 assertEquals( Arrays.asList( "org" ), repository.getRootNamespaces( TEST_REPO_ID ) );
921 assertEquals( Arrays.asList( "apache" ), repository.getNamespaces( TEST_REPO_ID, "org" ) );
922 assertEquals( Arrays.asList( "maven" ), repository.getNamespaces( TEST_REPO_ID, "org.apache" ) );
923 assertEquals( Arrays.asList( "shared" ), repository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) );
927 public void testGetNamespacesWithProjectsPresent()
930 String namespace = "org.apache.maven.shared";
931 repository.updateNamespace( TEST_REPO_ID, namespace );
933 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
934 metadata.setId( TEST_PROJECT_VERSION );
935 repository.updateProjectVersion( TEST_REPO_ID, namespace, TEST_PROJECT, metadata );
937 assertEquals( Collections.<String>emptyList(), repository.getNamespaces( TEST_REPO_ID, namespace ) );
941 public void testGetProjectsWithOtherNamespacesPresent()
944 ProjectMetadata projectMetadata = new ProjectMetadata();
945 projectMetadata.setId( TEST_PROJECT );
946 projectMetadata.setNamespace( "org.apache.maven" );
947 repository.updateProject( TEST_REPO_ID, projectMetadata );
949 repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
951 assertEquals( Collections.singletonList( TEST_PROJECT ),
952 repository.getProjects( TEST_REPO_ID, "org.apache.maven" ) );
956 public void testGetProjectVersionsWithOtherNamespacesPresent()
959 // an unusual case but technically possible where a project namespace matches another project's name
961 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
962 versionMetadata.setId( TEST_PROJECT_VERSION );
963 repository.updateProjectVersion( TEST_REPO_ID, "org.apache.maven", TEST_PROJECT, versionMetadata );
965 repository.updateProjectVersion( TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT, "other-project",
968 List<String> expectedVersions = Collections.singletonList( TEST_PROJECT_VERSION );
969 assertEquals( expectedVersions, repository.getProjectVersions( TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT,
971 assertEquals( expectedVersions,
972 repository.getProjectVersions( TEST_REPO_ID, "org.apache.maven", TEST_PROJECT ) );
976 public void testGetArtifactsByChecksumSingleResultMd5()
979 ArtifactMetadata artifact = createArtifact();
980 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
983 assertEquals( Collections.singletonList( artifact ),
984 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
988 public void testGetArtifactsByChecksumSingleResultSha1()
991 ArtifactMetadata artifact = createArtifact();
992 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
995 assertEquals( Collections.singletonList( artifact ),
996 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
1000 public void testGetArtifactsByChecksumDeepNamespace()
1003 ArtifactMetadata artifact = createArtifact();
1004 String namespace = "multi.level.ns";
1005 artifact.setNamespace( namespace );
1006 repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1009 assertEquals( Collections.singletonList( artifact ),
1010 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
1011 assertEquals( Collections.singletonList( artifact ),
1012 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
1016 public void testGetArtifactsByChecksumMultipleResult()
1019 ArtifactMetadata artifact1 = createArtifact();
1020 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1022 String newProjectId = "another-project";
1023 ArtifactMetadata artifact2 = createArtifact();
1024 artifact2.setProject( newProjectId );
1025 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
1028 List<ArtifactMetadata> artifacts =
1029 new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
1030 Collections.sort( artifacts, new ArtifactMetadataComparator() );
1031 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1033 artifacts = new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
1034 Collections.sort( artifacts, new ArtifactMetadataComparator() );
1035 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1039 public void testGetArtifactsByChecksumNoResult()
1042 ArtifactMetadata artifact = createArtifact();
1043 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1045 List<ArtifactMetadata> artifactsByChecksum = repository.getArtifactsByChecksum( TEST_REPO_ID, "not checksum" );
1046 assertEquals( Collections.<ArtifactMetadata>emptyList(), artifactsByChecksum );
1051 public void testDeleteRepository()
1054 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
1056 ProjectMetadata project1 = new ProjectMetadata();
1057 project1.setNamespace( TEST_NAMESPACE );
1058 project1.setId( "project1" );
1059 repository.updateProject( TEST_REPO_ID, project1 );
1060 ProjectMetadata project2 = new ProjectMetadata();
1061 project2.setNamespace( TEST_NAMESPACE );
1062 project2.setId( "project2" );
1063 repository.updateProject( TEST_REPO_ID, project2 );
1065 ArtifactMetadata artifact1 = createArtifact();
1066 artifact1.setProject( "project1" );
1067 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
1068 ArtifactMetadata artifact2 = createArtifact();
1069 artifact2.setProject( "project2" );
1070 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
1073 List<ArtifactMetadata> expected = Arrays.asList( artifact1, artifact2 );
1074 Collections.sort( expected, new ArtifactMetadataComparator() );
1076 List<ArtifactMetadata> actual =
1077 new ArrayList<ArtifactMetadata>( repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
1078 Collections.sort( actual, new ArtifactMetadataComparator() );
1080 assertEquals( expected, actual );
1082 repository.removeRepository( TEST_REPO_ID );
1084 assertTrue( repository.getArtifacts( TEST_REPO_ID ).isEmpty() );
1085 assertTrue( repository.getRootNamespaces( TEST_REPO_ID ).isEmpty() );
1090 public void testDeleteArtifact()
1093 ArtifactMetadata artifact = createArtifact();
1094 artifact.addFacet( new TestMetadataFacet( "value" ) );
1096 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1098 assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>(
1099 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
1101 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact );
1103 Collection<String> versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1105 log.info( "versions {}", versions );
1107 Assertions.assertThat( versions ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "1.0", "2.0" );
1109 repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
1111 versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1113 log.info( "versions {}", versions );
1115 Assertions.assertThat( versions ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "2.0" );
1118 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() );
1120 Assertions.assertThat( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
1121 TEST_PROJECT_VERSION_2_0 ) ).isNotEmpty().hasSize( 1 );
1125 public void deleteVersion()
1128 ArtifactMetadata artifact = createArtifact();
1129 artifact.addFacet( new TestMetadataFacet( "value" ) );
1131 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1133 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1135 assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>(
1136 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
1138 repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
1141 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() );
1144 private static ProjectMetadata createProject()
1146 return createProject( TEST_NAMESPACE );
1149 private static ProjectMetadata createProject( String ns )
1151 ProjectMetadata project = new ProjectMetadata();
1152 project.setId( TEST_PROJECT );
1153 project.setNamespace( ns );
1157 private static ArtifactMetadata createArtifact()
1159 return createArtifact( "jar" );
1162 private static ArtifactMetadata createArtifact( String type )
1164 ArtifactMetadata artifact = new ArtifactMetadata();
1165 artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
1166 artifact.setWhenGathered( new Date() );
1167 artifact.setNamespace( TEST_NAMESPACE );
1168 artifact.setProject( TEST_PROJECT );
1169 artifact.setRepositoryId( TEST_REPO_ID );
1170 artifact.setFileLastModified( System.currentTimeMillis() );
1171 artifact.setVersion( TEST_PROJECT_VERSION );
1172 artifact.setProjectVersion( TEST_PROJECT_VERSION );
1173 artifact.setMd5( TEST_MD5 );
1174 artifact.setSha1( TEST_SHA1 );
1178 private static class ArtifactMetadataComparator
1179 implements Comparator<ArtifactMetadata>
1181 public final int compare( ArtifactMetadata a, ArtifactMetadata b )
1183 return a.getProject().compareTo( b.getProject() );
1187 private static class TestMetadataFacet
1188 implements MetadataFacet
1190 private String testFacetId;
1192 private Map<String, String> additionalProps;
1194 private String value;
1196 private TestMetadataFacet( String value )
1199 testFacetId = TEST_FACET_ID;
1202 private TestMetadataFacet( String facetId, String value )
1205 testFacetId = facetId;
1208 private TestMetadataFacet( String facetId, String value, Map<String, String> additionalProps )
1210 this( facetId, value );
1211 this.additionalProps = additionalProps;
1214 public String getFacetId()
1219 public String getName()
1224 public Map<String, String> toProperties()
1226 if ( value != null )
1228 if ( additionalProps == null )
1230 return Collections.singletonMap( "foo", value );
1234 Map<String, String> props = new HashMap<String, String>();
1235 props.put( "foo", value );
1237 for ( String key : additionalProps.keySet() )
1239 props.put( key, additionalProps.get( key ) );
1246 return Collections.emptyMap();
1250 public void fromProperties( Map<String, String> properties )
1252 String value = properties.get( "foo" );
1253 if ( value != null )
1258 properties.remove( "foo" );
1260 if ( additionalProps == null )
1262 additionalProps = new HashMap<String, String>();
1265 for ( String key : properties.keySet() )
1267 additionalProps.put( key, properties.get( key ) );
1271 public String getValue()
1277 public String toString()
1279 return "TestMetadataFacet{" + "value='" + value + '\'' + '}';
1283 public boolean equals( Object o )
1289 if ( o == null || getClass() != o.getClass() )
1294 TestMetadataFacet that = (TestMetadataFacet) o;
1296 if ( value != null ? !value.equals( that.value ) : that.value != null )
1305 public int hashCode()
1307 return value != null ? value.hashCode() : 0;