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.List;
40 public abstract class AbstractMetadataRepositoryTest
41 extends PlexusInSpringTestCase
43 protected MetadataRepository repository;
45 protected static final String TEST_REPO_ID = "test";
47 private static final String TEST_PROJECT = "projectId";
49 private static final String TEST_NAMESPACE = "namespace";
51 private static final String TEST_PROJECT_VERSION = "1.0";
53 private static final String TEST_FACET_ID = "test-facet-id";
55 private static final String TEST_NAME = "test/name";
57 private static final String TEST_VALUE = "test-value";
59 private static final String UNKNOWN = "unknown";
61 private static final String TEST_MD5 = "bd4a9b642562547754086de2dab26b7d";
63 private static final String TEST_SHA1 = "2e5daf0201ddeb068a62d5e08da18657ab2c6be9";
65 private static final String TEST_METADATA_VALUE = "test-metadata";
67 protected static Map<String, MetadataFacetFactory> createTestMetadataFacetFactories()
69 Map<String, MetadataFacetFactory> factories = new HashMap<String, MetadataFacetFactory>();
70 factories.put( TEST_FACET_ID, new MetadataFacetFactory()
72 public MetadataFacet createMetadataFacet()
74 return new TestMetadataFacet( TEST_METADATA_VALUE );
77 public MetadataFacet createMetadataFacet( String repositoryId, String name )
79 return new TestMetadataFacet( TEST_METADATA_VALUE );
83 // add to ensure we don't accidentally create an empty facet ID.
84 factories.put( "", new MetadataFacetFactory()
86 public MetadataFacet createMetadataFacet()
88 return new TestMetadataFacet( "", TEST_VALUE );
91 public MetadataFacet createMetadataFacet( String repositoryId, String name )
93 return new TestMetadataFacet( "", TEST_VALUE );
99 public void testRootNamespaceWithNoMetadataRepository()
101 Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID );
102 assertEquals( Collections.<String>emptyList(), namespaces );
105 public void testUpdateProjectVersionMetadataWithNoOtherArchives()
107 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
108 metadata.setId( TEST_PROJECT_VERSION );
109 MailingList mailingList = new MailingList();
110 mailingList.setName( "Foo List" );
111 mailingList.setOtherArchives( Collections.<String>emptyList() );
112 metadata.setMailingLists( Collections.singletonList( mailingList ) );
113 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
116 public void testUpdateProjectVersionMetadataIncomplete()
117 throws MetadataResolutionException
119 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
120 metadata.setId( TEST_PROJECT_VERSION );
121 metadata.setIncomplete( true );
122 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
124 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
125 assertEquals( true, metadata.isIncomplete() );
128 public void testUpdateProjectVersionMetadataWithExistingFacets()
129 throws MetadataResolutionException
131 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
132 metadata.setId( TEST_PROJECT_VERSION );
133 MetadataFacet facet = new TestMetadataFacet( "baz" );
134 metadata.addFacet( facet );
135 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
137 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
138 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
140 metadata = new ProjectVersionMetadata();
141 metadata.setId( TEST_PROJECT_VERSION );
142 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
144 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
145 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
146 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
147 assertEquals( "baz", testFacet.getValue() );
150 public void testUpdateProjectVersionMetadataWithNoExistingFacets()
151 throws MetadataResolutionException
153 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
154 metadata.setId( TEST_PROJECT_VERSION );
155 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
157 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
158 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
160 metadata = new ProjectVersionMetadata();
161 metadata.setId( TEST_PROJECT_VERSION );
162 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
164 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
165 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
168 public void testUpdateArtifactMetadataWithExistingFacets()
170 ArtifactMetadata metadata = createArtifact();
171 MetadataFacet facet = new TestMetadataFacet( "baz" );
172 metadata.addFacet( facet );
173 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
175 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
176 TEST_PROJECT_VERSION ).iterator().next();
177 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
179 metadata = createArtifact();
180 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
182 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
183 TEST_PROJECT_VERSION ).iterator().next();
184 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
185 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
186 assertEquals( "baz", testFacet.getValue() );
189 public void testUpdateArtifactMetadataWithNoExistingFacets()
191 ArtifactMetadata metadata = createArtifact();
192 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
194 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
195 TEST_PROJECT_VERSION ).iterator().next();
196 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
198 metadata = createArtifact();
199 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
201 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
202 TEST_PROJECT_VERSION ).iterator().next();
203 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
206 public void testGetMetadataFacet()
208 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
210 assertEquals( new TestMetadataFacet( TEST_VALUE ), repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID,
214 public void testGetMetadataFacetWhenEmpty()
216 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
219 public void testGetMetadataFacetWhenUnknownName()
221 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
223 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) );
226 public void testGetMetadataFacetWhenDefaultValue()
228 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) );
230 assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ), repository.getMetadataFacet( TEST_REPO_ID,
235 public void testGetMetadataFacetWhenUnknownFacetId()
237 assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
240 public void testGetMetadataFacets()
242 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
244 assertEquals( Collections.singletonList( TEST_NAME ), repository.getMetadataFacets( TEST_REPO_ID,
248 public void testGetMetadataFacetsWhenEmpty()
250 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
251 assertTrue( facets.isEmpty() );
254 public void testRemoveFacets()
256 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
258 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
259 assertFalse( facets.isEmpty() );
261 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
263 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
264 assertTrue( facets.isEmpty() );
267 public void testRemoveFacetsWhenEmpty()
269 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
270 assertTrue( facets.isEmpty() );
272 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
274 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
275 assertTrue( facets.isEmpty() );
278 public void testRemoveFacetsWhenUnknown()
280 repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN );
283 public void testRemoveFacet()
285 TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
286 repository.addMetadataFacet( TEST_REPO_ID, metadataFacet );
288 assertEquals( metadataFacet, repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
289 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
290 assertFalse( facets.isEmpty() );
292 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
294 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
295 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
296 assertTrue( facets.isEmpty() );
299 public void testRemoveFacetWhenEmpty()
301 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
302 assertTrue( facets.isEmpty() );
303 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
305 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
307 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
308 assertTrue( facets.isEmpty() );
309 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
312 public void testRemoveFacetWhenUnknown()
314 repository.removeMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME );
317 public void testGetArtifacts()
319 ArtifactMetadata artifact1 = createArtifact();
320 ArtifactMetadata artifact2 = createArtifact( "pom" );
321 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
322 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
324 Collection<ArtifactMetadata> artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
325 TEST_PROJECT_VERSION );
326 ArrayList<ArtifactMetadata> actual = new ArrayList<ArtifactMetadata>( artifacts );
327 Collections.sort( actual, new Comparator<ArtifactMetadata>()
329 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
331 return o1.getId().compareTo( o2.getId() );
334 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
337 public void testGetArtifactVersions()
339 ArtifactMetadata artifact1 = createArtifact();
340 String version1 = "1.0-20091212.012345-1";
341 artifact1.setId( artifact1.getProject() + "-" + version1 + ".jar" );
342 artifact1.setVersion( version1 );
343 ArtifactMetadata artifact2 = createArtifact();
344 String version2 = "1.0-20091212.123456-2";
345 artifact2.setId( artifact2.getProject() + "-" + version2 + ".jar" );
346 artifact2.setVersion( version2 );
347 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
348 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
350 List<String> versions = new ArrayList<String>( repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE,
352 TEST_PROJECT_VERSION ) );
353 Collections.sort( versions );
354 assertEquals( Arrays.asList( version1, version2 ), versions );
357 public void testGetArtifactVersionsMultipleArtifactsSingleVersion()
359 ArtifactMetadata artifact1 = createArtifact();
360 artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
361 ArtifactMetadata artifact2 = createArtifact();
362 artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
363 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
364 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
366 assertEquals( Collections.singleton( TEST_PROJECT_VERSION ), repository.getArtifactVersions( TEST_REPO_ID,
369 TEST_PROJECT_VERSION ) );
372 public void testGetArtifactsByDateRangeOpen()
374 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
375 repository.updateProject( TEST_REPO_ID, createProject() );
376 ArtifactMetadata artifact = createArtifact();
377 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
379 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, null,
383 public void testGetArtifactsByDateRangeSparseNamespace()
385 String namespace = "org.apache.archiva";
386 repository.updateNamespace( TEST_REPO_ID, namespace );
387 repository.updateProject( TEST_REPO_ID, createProject( namespace ) );
388 ArtifactMetadata artifact = createArtifact();
389 artifact.setNamespace( namespace );
390 repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
392 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, null,
396 public void testGetArtifactsByDateRangeLowerBound()
398 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
399 repository.updateProject( TEST_REPO_ID, createProject() );
400 ArtifactMetadata artifact = createArtifact();
401 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
403 Date date = new Date( artifact.getWhenGathered().getTime() - 10000 );
404 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, date,
408 public void testGetArtifactsByDateRangeLowerBoundOutOfRange()
410 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
411 repository.updateProject( TEST_REPO_ID, createProject() );
412 ArtifactMetadata artifact = createArtifact();
413 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
415 Date date = new Date( artifact.getWhenGathered().getTime() + 10000 );
416 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ).isEmpty() );
419 public void testGetArtifactsByDateRangeLowerAndUpperBound()
421 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
422 repository.updateProject( TEST_REPO_ID, createProject() );
423 ArtifactMetadata artifact = createArtifact();
424 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
426 Date lower = new Date( artifact.getWhenGathered().getTime() - 10000 );
427 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
428 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, lower,
432 public void testGetArtifactsByDateRangeUpperBound()
434 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
435 repository.updateProject( TEST_REPO_ID, createProject() );
436 ArtifactMetadata artifact = createArtifact();
437 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
439 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
440 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByDateRange( TEST_REPO_ID, null,
444 public void testGetArtifactsByDateRangeUpperBoundOutOfRange()
446 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
447 repository.updateProject( TEST_REPO_ID, createProject() );
448 ArtifactMetadata artifact = createArtifact();
449 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
451 Date upper = new Date( artifact.getWhenGathered().getTime() - 10000 );
452 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ).isEmpty() );
455 public void testGetNamespacesWithSparseDepth()
457 repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
459 assertEquals( Arrays.asList( "org" ), repository.getRootNamespaces( TEST_REPO_ID ) );
460 assertEquals( Arrays.asList( "apache" ), repository.getNamespaces( TEST_REPO_ID, "org" ) );
461 assertEquals( Arrays.asList( "maven" ), repository.getNamespaces( TEST_REPO_ID, "org.apache" ) );
462 assertEquals( Arrays.asList( "shared" ), repository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) );
465 public void testGetArtifactsByChecksumSingleResultMd5()
467 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
468 repository.updateProject( TEST_REPO_ID, createProject() );
469 ArtifactMetadata artifact = createArtifact();
470 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
472 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByChecksum( TEST_REPO_ID,
476 public void testGetArtifactsByChecksumSingleResultSha1()
478 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
479 repository.updateProject( TEST_REPO_ID, createProject() );
480 ArtifactMetadata artifact = createArtifact();
481 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
483 assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByChecksum( TEST_REPO_ID,
487 public void testGetArtifactsByChecksumMultipleResult()
489 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
491 ProjectMetadata projectMetadata = createProject();
492 repository.updateProject( TEST_REPO_ID, projectMetadata );
493 ArtifactMetadata artifact1 = createArtifact();
494 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
496 projectMetadata = createProject();
497 String newProjectId = "another-project";
498 projectMetadata.setId( newProjectId );
499 repository.updateProject( TEST_REPO_ID, projectMetadata );
500 ArtifactMetadata artifact2 = createArtifact();
501 artifact2.setProject( newProjectId );
502 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
504 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum(
505 TEST_REPO_ID, TEST_SHA1 ) );
506 Collections.sort( artifacts, new ArtifactMetadataComparator() );
507 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
510 public void testGetArtifactsByChecksumNoResult()
512 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
513 repository.updateProject( TEST_REPO_ID, createProject() );
514 ArtifactMetadata artifact = createArtifact();
515 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
517 assertEquals( Collections.<ArtifactMetadata>emptyList(), repository.getArtifactsByChecksum( TEST_REPO_ID,
518 "not a checksum" ) );
521 public void testDeleteArtifact()
523 ArtifactMetadata artifact = createArtifact();
524 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
526 assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>( repository.getArtifacts(
527 TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
529 repository.deleteArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
531 assertTrue( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
532 TEST_PROJECT_VERSION ).isEmpty() );
535 public void testDeleteRepository()
537 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
539 ProjectMetadata project1 = new ProjectMetadata();
540 project1.setNamespace( TEST_NAMESPACE );
541 project1.setId( "project1" );
542 repository.updateProject( TEST_REPO_ID, project1 );
543 ProjectMetadata project2 = new ProjectMetadata();
544 project2.setNamespace( TEST_NAMESPACE );
545 project2.setId( "project2" );
546 repository.updateProject( TEST_REPO_ID, project2 );
548 ArtifactMetadata artifact1 = createArtifact();
549 artifact1.setProject( "project1" );
550 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
551 ArtifactMetadata artifact2 = createArtifact();
552 artifact2.setProject( "project2" );
553 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
555 List<ArtifactMetadata> expected = Arrays.asList( artifact1, artifact2 );
556 Collections.sort( expected, new ArtifactMetadataComparator() );
558 List<ArtifactMetadata> actual = new ArrayList<ArtifactMetadata>( repository.getArtifactsByDateRange(
559 TEST_REPO_ID, null, null ) );
560 Collections.sort( actual, new ArtifactMetadataComparator() );
562 assertEquals( expected, actual );
564 repository.deleteRepository( TEST_REPO_ID );
566 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ).isEmpty() );
569 private ProjectMetadata createProject()
571 return createProject( TEST_NAMESPACE );
574 private ProjectMetadata createProject( String ns )
576 ProjectMetadata project = new ProjectMetadata();
577 project.setId( TEST_PROJECT );
578 project.setNamespace( ns );
582 private ArtifactMetadata createArtifact()
584 return createArtifact( "jar" );
587 private ArtifactMetadata createArtifact( String type )
589 ArtifactMetadata artifact = new ArtifactMetadata();
590 artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
591 artifact.setWhenGathered( new Date() );
592 artifact.setNamespace( TEST_NAMESPACE );
593 artifact.setProject( TEST_PROJECT );
594 artifact.setRepositoryId( TEST_REPO_ID );
595 artifact.setFileLastModified( System.currentTimeMillis() );
596 artifact.setVersion( TEST_PROJECT_VERSION );
597 artifact.setProjectVersion( TEST_PROJECT_VERSION );
598 artifact.setMd5( TEST_MD5 );
599 artifact.setSha1( TEST_SHA1 );
603 private class ArtifactMetadataComparator
604 implements Comparator<ArtifactMetadata>
606 public final int compare( ArtifactMetadata a, ArtifactMetadata b )
608 return a.getProject().compareTo( b.getProject() );
612 private static class TestMetadataFacet
613 implements MetadataFacet
615 private String testFacetId;
617 private TestMetadataFacet( String value )
620 testFacetId = TEST_FACET_ID;
623 private TestMetadataFacet( String facetId, String value )
626 testFacetId = facetId;
629 private String value;
631 public String getFacetId()
636 public String getName()
641 public Map<String, String> toProperties()
645 return Collections.singletonMap( "foo", value );
649 return Collections.emptyMap();
653 public void fromProperties( Map<String, String> properties )
655 String value = properties.get( "foo" );
662 public String getValue()
668 public String toString()
670 return "TestMetadataFacet{" + "value='" + value + '\'' + '}';
674 public boolean equals( Object o )
680 if ( o == null || getClass() != o.getClass() )
685 TestMetadataFacet that = (TestMetadataFacet) o;
687 if ( value != null ? !value.equals( that.value ) : that.value != null )
696 public int hashCode()
698 return value != null ? value.hashCode() : 0;