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 org.apache.archiva.metadata.model.ArtifactMetadata;
23 import org.apache.archiva.metadata.model.MailingList;
24 import org.apache.archiva.metadata.model.MetadataFacet;
25 import org.apache.archiva.metadata.model.MetadataFacetFactory;
26 import org.apache.archiva.metadata.model.ProjectMetadata;
27 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
28 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collection;
33 import java.util.Collections;
34 import java.util.Comparator;
35 import java.util.Date;
36 import java.util.HashMap;
37 import java.util.HashSet;
38 import java.util.List;
41 public abstract class AbstractMetadataRepositoryTest
42 extends PlexusInSpringTestCase
44 protected MetadataRepository repository;
46 protected static final String TEST_REPO_ID = "test";
48 private static final String TEST_PROJECT = "projectId";
50 private static final String TEST_NAMESPACE = "namespace";
52 private static final String TEST_PROJECT_VERSION = "1.0";
54 private static final String TEST_FACET_ID = "test-facet-id";
56 private static final String TEST_NAME = "test/name";
58 private static final String TEST_VALUE = "test-value";
60 private static final String UNKNOWN = "unknown";
62 private static final String TEST_MD5 = "bd4a9b642562547754086de2dab26b7d";
64 private static final String TEST_SHA1 = "2e5daf0201ddeb068a62d5e08da18657ab2c6be9";
66 private static final String TEST_METADATA_VALUE = "test-metadata";
68 protected static Map<String, MetadataFacetFactory> createTestMetadataFacetFactories()
70 Map<String, MetadataFacetFactory> factories = new HashMap<String, MetadataFacetFactory>();
71 factories.put( TEST_FACET_ID, new MetadataFacetFactory()
73 public MetadataFacet createMetadataFacet()
75 return new TestMetadataFacet( TEST_METADATA_VALUE );
78 public MetadataFacet createMetadataFacet( String repositoryId, String name )
80 return new TestMetadataFacet( TEST_METADATA_VALUE );
84 // add to ensure we don't accidentally create an empty facet ID.
85 factories.put( "", new MetadataFacetFactory()
87 public MetadataFacet createMetadataFacet()
89 return new TestMetadataFacet( "", TEST_VALUE );
92 public MetadataFacet createMetadataFacet( String repositoryId, String name )
94 return new TestMetadataFacet( "", TEST_VALUE );
100 public void testRootNamespaceWithNoMetadataRepository()
102 Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID );
103 assertEquals( Collections.<String>emptyList(), namespaces );
106 public void testUpdateProjectVersionMetadataWithNoOtherArchives()
108 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
109 metadata.setId( TEST_PROJECT_VERSION );
110 MailingList mailingList = new MailingList();
111 mailingList.setName( "Foo List" );
112 mailingList.setOtherArchives( Collections.<String>emptyList() );
113 metadata.setMailingLists( Collections.singletonList( mailingList ) );
114 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
117 public void testUpdateProjectVersionMetadataIncomplete()
118 throws MetadataResolutionException
120 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
121 metadata.setId( TEST_PROJECT_VERSION );
122 metadata.setIncomplete( true );
123 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
125 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
126 assertEquals( true, metadata.isIncomplete() );
129 public void testUpdateProjectVersionMetadataWithExistingFacets()
130 throws MetadataResolutionException
132 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
133 metadata.setId( TEST_PROJECT_VERSION );
134 MetadataFacet facet = new TestMetadataFacet( "baz" );
135 metadata.addFacet( facet );
136 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
138 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
139 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
141 metadata = new ProjectVersionMetadata();
142 metadata.setId( TEST_PROJECT_VERSION );
143 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
145 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
146 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
147 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
148 assertEquals( "baz", testFacet.getValue() );
151 public void testUpdateProjectVersionMetadataWithNoExistingFacets()
152 throws MetadataResolutionException
154 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
155 metadata.setId( TEST_PROJECT_VERSION );
156 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
158 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
159 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
161 metadata = new ProjectVersionMetadata();
162 metadata.setId( TEST_PROJECT_VERSION );
163 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
165 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
166 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
169 public void testUpdateArtifactMetadataWithExistingFacets()
171 ArtifactMetadata metadata = createArtifact();
172 MetadataFacet facet = new TestMetadataFacet( "baz" );
173 metadata.addFacet( facet );
174 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
176 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
177 TEST_PROJECT_VERSION ).iterator().next();
178 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
180 metadata = createArtifact();
181 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
183 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
184 TEST_PROJECT_VERSION ).iterator().next();
185 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
186 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
187 assertEquals( "baz", testFacet.getValue() );
190 public void testUpdateArtifactMetadataWithNoExistingFacets()
192 ArtifactMetadata metadata = createArtifact();
193 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
195 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
196 TEST_PROJECT_VERSION ).iterator().next();
197 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
199 metadata = createArtifact();
200 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
202 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
203 TEST_PROJECT_VERSION ).iterator().next();
204 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
207 public void testGetMetadataFacet()
209 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
211 assertEquals( new TestMetadataFacet( TEST_VALUE ), repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID,
215 public void testGetMetadataFacetWhenEmpty()
217 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
220 public void testGetMetadataFacetWhenUnknownName()
222 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
224 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) );
227 public void testGetMetadataFacetWhenDefaultValue()
229 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) );
231 assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ), repository.getMetadataFacet( TEST_REPO_ID,
236 public void testGetMetadataFacetWhenUnknownFacetId()
238 assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
241 public void testGetMetadataFacets()
243 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
245 assertEquals( Collections.singletonList( TEST_NAME ), repository.getMetadataFacets( TEST_REPO_ID,
249 public void testGetMetadataFacetsWhenEmpty()
251 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
252 assertTrue( facets.isEmpty() );
255 public void testRemoveFacets()
257 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
259 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
260 assertFalse( facets.isEmpty() );
262 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
264 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
265 assertTrue( facets.isEmpty() );
268 public void testRemoveFacetsWhenEmpty()
270 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
271 assertTrue( facets.isEmpty() );
273 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
275 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
276 assertTrue( facets.isEmpty() );
279 public void testRemoveFacetsWhenUnknown()
281 repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN );
284 public void testRemoveFacet()
286 TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
287 repository.addMetadataFacet( TEST_REPO_ID, metadataFacet );
289 assertEquals( metadataFacet, repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
290 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
291 assertFalse( facets.isEmpty() );
293 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
295 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
296 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
297 assertTrue( facets.isEmpty() );
300 public void testRemoveFacetWhenEmpty()
302 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
303 assertTrue( facets.isEmpty() );
304 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
306 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
308 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
309 assertTrue( facets.isEmpty() );
310 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
313 public void testRemoveFacetWhenUnknown()
315 repository.removeMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME );
318 public void testGetArtifacts()
320 ArtifactMetadata artifact1 = createArtifact();
321 ArtifactMetadata artifact2 = createArtifact( "pom" );
322 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
323 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
325 Collection<ArtifactMetadata> artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
326 TEST_PROJECT_VERSION );
327 ArrayList<ArtifactMetadata> actual = new ArrayList<ArtifactMetadata>( artifacts );
328 Collections.sort( actual, new Comparator<ArtifactMetadata>()
330 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
332 return o1.getId().compareTo( o2.getId() );
335 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
338 public void testGetArtifactVersions()
340 ArtifactMetadata artifact1 = createArtifact();
341 String version1 = "1.0-20091212.012345-1";
342 artifact1.setId( artifact1.getProject() + "-" + version1 + ".jar" );
343 artifact1.setVersion( version1 );
344 ArtifactMetadata artifact2 = createArtifact();
345 String version2 = "1.0-20091212.123456-2";
346 artifact2.setId( artifact2.getProject() + "-" + version2 + ".jar" );
347 artifact2.setVersion( version2 );
348 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
349 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
351 assertEquals( new HashSet<String>( Arrays.asList( version2, version1 ) ), repository.getArtifactVersions(
352 TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
355 public void testGetArtifactVersionsMultipleArtifactsSingleVersion()
357 ArtifactMetadata artifact1 = createArtifact();
358 artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
359 ArtifactMetadata artifact2 = createArtifact();
360 artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
361 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
362 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
364 assertEquals( Collections.singleton( TEST_PROJECT_VERSION ), repository.getArtifactVersions( TEST_REPO_ID,
367 TEST_PROJECT_VERSION ) );
370 public void testGetArtifactsByDateRangeOpen()
372 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
373 repository.updateProject( TEST_REPO_ID, createProject() );
374 ArtifactMetadata artifact = createArtifact();
375 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
377 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, null,
381 public void testGetArtifactsByDateRangeSparseNamespace()
383 String namespace = "org.apache.archiva";
384 repository.updateNamespace( TEST_REPO_ID, namespace );
385 repository.updateProject( TEST_REPO_ID, createProject( namespace ) );
386 ArtifactMetadata artifact = createArtifact();
387 artifact.setNamespace( namespace );
388 repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
390 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, null,
394 public void testGetArtifactsByDateRangeLowerBound()
396 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
397 repository.updateProject( TEST_REPO_ID, createProject() );
398 ArtifactMetadata artifact = createArtifact();
399 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
401 Date date = new Date( artifact.getWhenGathered().getTime() - 10000 );
402 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, date,
406 public void testGetArtifactsByDateRangeLowerBoundOutOfRange()
408 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
409 repository.updateProject( TEST_REPO_ID, createProject() );
410 ArtifactMetadata artifact = createArtifact();
411 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
413 Date date = new Date( artifact.getWhenGathered().getTime() + 10000 );
414 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ).isEmpty() );
417 public void testGetArtifactsByDateRangeLowerAndUpperBound()
419 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
420 repository.updateProject( TEST_REPO_ID, createProject() );
421 ArtifactMetadata artifact = createArtifact();
422 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
424 Date lower = new Date( artifact.getWhenGathered().getTime() - 10000 );
425 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
426 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, lower,
430 public void testGetArtifactsByDateRangeUpperBound()
432 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
433 repository.updateProject( TEST_REPO_ID, createProject() );
434 ArtifactMetadata artifact = createArtifact();
435 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
437 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
438 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, null,
442 public void testGetArtifactsByDateRangeUpperBoundOutOfRange()
444 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
445 repository.updateProject( TEST_REPO_ID, createProject() );
446 ArtifactMetadata artifact = createArtifact();
447 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
449 Date upper = new Date( artifact.getWhenGathered().getTime() - 10000 );
450 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ).isEmpty() );
453 public void testGetNamespacesWithSparseDepth()
455 repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
457 assertEquals( Arrays.asList( "org" ), repository.getRootNamespaces( TEST_REPO_ID ) );
458 assertEquals( Arrays.asList( "apache" ), repository.getNamespaces( TEST_REPO_ID, "org" ) );
459 assertEquals( Arrays.asList( "maven" ), repository.getNamespaces( TEST_REPO_ID, "org.apache" ) );
460 assertEquals( Arrays.asList( "shared" ), repository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) );
463 public void testGetArtifactsByChecksumSingleResultMd5()
465 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
466 repository.updateProject( TEST_REPO_ID, createProject() );
467 ArtifactMetadata artifact = createArtifact();
468 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
470 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByChecksum( TEST_REPO_ID,
474 public void testGetArtifactsByChecksumSingleResultSha1()
476 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
477 repository.updateProject( TEST_REPO_ID, createProject() );
478 ArtifactMetadata artifact = createArtifact();
479 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
481 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByChecksum( TEST_REPO_ID,
485 public void testGetArtifactsByChecksumMultipleResult()
487 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
489 ProjectMetadata projectMetadata = createProject();
490 repository.updateProject( TEST_REPO_ID, projectMetadata );
491 ArtifactMetadata artifact1 = createArtifact();
492 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
494 projectMetadata = createProject();
495 String newProjectId = "another-project";
496 projectMetadata.setId( newProjectId );
497 repository.updateProject( TEST_REPO_ID, projectMetadata );
498 ArtifactMetadata artifact2 = createArtifact();
499 artifact2.setProject( newProjectId );
500 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
502 assertEquals( Arrays.asList( artifact2, artifact1 ), repository.getArtifactsByChecksum( TEST_REPO_ID,
506 public void testGetArtifactsByChecksumNoResult()
508 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
509 repository.updateProject( TEST_REPO_ID, createProject() );
510 ArtifactMetadata artifact = createArtifact();
511 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
513 assertEquals( Collections.<ArtifactMetadata>emptyList(), repository.getArtifactsByChecksum( TEST_REPO_ID,
514 "not a checksum" ) );
517 public void testDeleteArtifact()
519 ArtifactMetadata artifact = createArtifact();
520 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
522 assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>( repository.getArtifacts(
523 TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
525 repository.deleteArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
527 assertTrue( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
528 TEST_PROJECT_VERSION ).isEmpty() );
531 public void testDeleteRepository()
533 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
535 ProjectMetadata project1 = new ProjectMetadata();
536 project1.setNamespace( TEST_NAMESPACE );
537 project1.setId( "project1" );
538 repository.updateProject( TEST_REPO_ID, project1 );
539 ProjectMetadata project2 = new ProjectMetadata();
540 project2.setNamespace( TEST_NAMESPACE );
541 project2.setId( "project2" );
542 repository.updateProject( TEST_REPO_ID, project2 );
544 ArtifactMetadata artifact1 = createArtifact();
545 artifact1.setProject( "project1" );
546 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
547 ArtifactMetadata artifact2 = createArtifact();
548 artifact2.setProject( "project2" );
549 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
551 List<ArtifactMetadata> expected = Arrays.asList( artifact1, artifact2 );
552 Collections.sort( expected, new ArtifactMetadataComparator() );
554 List<ArtifactMetadata> actual = new ArrayList<ArtifactMetadata>( repository.getArtifactsByDateRange(
555 TEST_REPO_ID, null, null ) );
556 Collections.sort( actual, new ArtifactMetadataComparator() );
558 assertEquals( expected, actual );
560 repository.deleteRepository( TEST_REPO_ID );
562 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ).isEmpty() );
565 private ProjectMetadata createProject()
567 return createProject( TEST_NAMESPACE );
570 private ProjectMetadata createProject( String ns )
572 ProjectMetadata project = new ProjectMetadata();
573 project.setId( TEST_PROJECT );
574 project.setNamespace( ns );
578 private ArtifactMetadata createArtifact()
580 return createArtifact( "jar" );
583 private ArtifactMetadata createArtifact( String type )
585 ArtifactMetadata artifact = new ArtifactMetadata();
586 artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
587 artifact.setWhenGathered( new Date() );
588 artifact.setNamespace( TEST_NAMESPACE );
589 artifact.setProject( TEST_PROJECT );
590 artifact.setRepositoryId( TEST_REPO_ID );
591 artifact.setFileLastModified( System.currentTimeMillis() );
592 artifact.setVersion( TEST_PROJECT_VERSION );
593 artifact.setProjectVersion( TEST_PROJECT_VERSION );
594 artifact.setMd5( TEST_MD5 );
595 artifact.setSha1( TEST_SHA1 );
599 private class ArtifactMetadataComparator
600 implements Comparator<ArtifactMetadata>
602 public final int compare( ArtifactMetadata a, ArtifactMetadata b )
604 return a.getProject().compareTo( b.getProject() );
608 private static class TestMetadataFacet
609 implements MetadataFacet
611 private String testFacetId;
613 private TestMetadataFacet( String value )
616 testFacetId = TEST_FACET_ID;
619 private TestMetadataFacet( String facetId, String value )
622 testFacetId = facetId;
625 private String value;
627 public String getFacetId()
632 public String getName()
637 public Map<String, String> toProperties()
641 return Collections.singletonMap( "foo", value );
645 return Collections.emptyMap();
649 public void fromProperties( Map<String, String> properties )
651 String value = properties.get( "foo" );
658 public String getValue()
664 public String toString()
666 return "TestMetadataFacet{" + "value='" + value + '\'' + '}';
670 public boolean equals( Object o )
676 if ( o == null || getClass() != o.getClass() )
681 TestMetadataFacet that = (TestMetadataFacet) o;
683 if ( value != null ? !value.equals( that.value ) : that.value != null )
692 public int hashCode()
694 return value != null ? value.hashCode() : 0;