1 package org.apache.archiva.metadata.repository.file;
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
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.Date;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.List;
33 import org.apache.archiva.metadata.model.ArtifactMetadata;
34 import org.apache.archiva.metadata.model.MailingList;
35 import org.apache.archiva.metadata.model.MetadataFacet;
36 import org.apache.archiva.metadata.model.MetadataFacetFactory;
37 import org.apache.archiva.metadata.model.ProjectMetadata;
38 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
39 import org.apache.commons.io.FileUtils;
40 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
41 import org.apache.maven.archiva.configuration.Configuration;
42 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
43 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
44 import org.easymock.MockControl;
47 * @todo should this be a generic MetadataRepository implementation test?
49 public class FileMetadataRepositoryTest
50 extends PlexusInSpringTestCase
52 private FileMetadataRepository repository;
54 private static final String TEST_REPO_ID = "test";
56 private static final String TEST_PROJECT = "projectId";
58 private static final String TEST_NAMESPACE = "namespace";
60 private static final String TEST_PROJECT_VERSION = "1.0";
62 private static final String TEST_FACET_ID = "test-facet-id";
64 private static final String TEST_NAME = "test/name";
66 private static final String TEST_VALUE = "test-value";
68 private static final String UNKNOWN = "unknown";
70 private static final String OTHER_REPO = "other-repo";
72 private static final String TEST_MD5 = "bd4a9b642562547754086de2dab26b7d";
74 private static final String TEST_SHA1 = "2e5daf0201ddeb068a62d5e08da18657ab2c6be9";
76 private static final String TEST_METADATA_VALUE = "test-metadata";
83 repository = new FileMetadataRepository();
84 File directory = getTestFile( "target/test-repositories" );
85 FileUtils.deleteDirectory( directory );
87 MockControl control = MockControl.createControl( ArchivaConfiguration.class );
88 ArchivaConfiguration config = (ArchivaConfiguration) control.getMock();
89 Configuration configData = new Configuration();
90 configData.addManagedRepository( createManagedRepository( TEST_REPO_ID, directory ) );
91 configData.addManagedRepository( createManagedRepository( OTHER_REPO, directory ) );
92 control.expectAndDefaultReturn( config.getConfiguration(), configData );
94 repository.setConfiguration( config );
96 Map<String, MetadataFacetFactory> factories = new HashMap<String, MetadataFacetFactory>();
97 factories.put( TEST_FACET_ID, new MetadataFacetFactory()
99 public MetadataFacet createMetadataFacet()
101 return new TestMetadataFacet( TEST_METADATA_VALUE );
104 public MetadataFacet createMetadataFacet( String repositoryId, String name )
106 return new TestMetadataFacet( TEST_METADATA_VALUE );
110 // add to ensure we don't accidentally create an empty facet ID.
111 factories.put( "", new MetadataFacetFactory()
113 public MetadataFacet createMetadataFacet()
115 return new TestMetadataFacet( "", TEST_VALUE );
118 public MetadataFacet createMetadataFacet( String repositoryId, String name )
120 return new TestMetadataFacet( "", TEST_VALUE );
123 repository.setMetadataFacetFactories( factories );
126 private static ManagedRepositoryConfiguration createManagedRepository( String repoId, File directory )
128 ManagedRepositoryConfiguration managedRepository = new ManagedRepositoryConfiguration();
129 managedRepository.setId( repoId );
130 managedRepository.setLocation( new File( directory, repoId ).getAbsolutePath() );
131 return managedRepository;
134 public void testRootNamespaceWithNoMetadataRepository()
136 Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID );
137 assertEquals( Collections.<String>emptyList(), namespaces );
140 public void testUpdateProjectVersionMetadataWithNoOtherArchives()
142 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
143 metadata.setId( TEST_PROJECT_VERSION );
144 MailingList mailingList = new MailingList();
145 mailingList.setName( "Foo List" );
146 mailingList.setOtherArchives( Collections.<String>emptyList() );
147 metadata.setMailingLists( Collections.singletonList( mailingList ) );
148 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
151 public void testUpdateProjectVersionMetadataIncomplete()
153 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
154 metadata.setId( TEST_PROJECT_VERSION );
155 metadata.setIncomplete( true );
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( true, metadata.isIncomplete() );
162 public void testUpdateProjectVersionMetadataWithExistingFacets()
164 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
165 metadata.setId( TEST_PROJECT_VERSION );
166 MetadataFacet facet = new TestMetadataFacet( "baz" );
167 metadata.addFacet( facet );
168 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
170 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
171 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
173 metadata = new ProjectVersionMetadata();
174 metadata.setId( TEST_PROJECT_VERSION );
175 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
177 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
178 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
179 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
180 assertEquals( "baz", testFacet.getValue() );
183 public void testUpdateProjectVersionMetadataWithNoExistingFacets()
185 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
186 metadata.setId( TEST_PROJECT_VERSION );
187 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
189 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
190 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
192 metadata = new ProjectVersionMetadata();
193 metadata.setId( TEST_PROJECT_VERSION );
194 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
196 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
197 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
200 public void testGetMetadataFacet()
202 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
204 assertEquals( new TestMetadataFacet( TEST_VALUE ),
205 repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
208 public void testGetMetadataFacetWhenEmpty()
210 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
213 public void testGetMetadataFacetWhenUnknownName()
215 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
217 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) );
220 public void testGetMetadataFacetWhenDefaultValue()
222 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) );
224 assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ),
225 repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
228 public void testGetMetadataFacetWhenUnknownFacetId()
230 assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
233 public void testGetMetadataFacets()
235 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
237 assertEquals( Collections.singletonList( TEST_NAME ),
238 repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ) );
241 public void testGetMetadataFacetsWhenEmpty()
243 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
244 assertTrue( facets.isEmpty() );
247 public void testRemoveFacets()
249 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
251 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
252 assertFalse( facets.isEmpty() );
254 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
256 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
257 assertTrue( facets.isEmpty() );
260 public void testRemoveFacetsWhenEmpty()
262 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
263 assertTrue( facets.isEmpty() );
265 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
267 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
268 assertTrue( facets.isEmpty() );
271 public void testRemoveFacetsWhenUnknown()
273 repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN );
276 public void testRemoveFacet()
278 TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
279 repository.addMetadataFacet( TEST_REPO_ID, metadataFacet );
281 assertEquals( metadataFacet, repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
282 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
283 assertFalse( facets.isEmpty() );
285 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
287 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
288 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
289 assertTrue( facets.isEmpty() );
292 public void testRemoveFacetWhenEmpty()
294 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
295 assertTrue( facets.isEmpty() );
296 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
298 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
300 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
301 assertTrue( facets.isEmpty() );
302 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
305 public void testRemoveFacetWhenUnknown()
307 repository.removeMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME );
310 public void testGetArtifacts()
312 ArtifactMetadata artifact1 = createArtifact();
313 ArtifactMetadata artifact2 = createArtifact( "pom" );
314 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
315 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
317 assertEquals( Arrays.asList( artifact2, artifact1 ), new ArrayList<ArtifactMetadata>(
318 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
321 public void testGetArtifactVersions()
323 ArtifactMetadata artifact1 = createArtifact();
324 String version1 = "1.0-20091212.012345-1";
325 artifact1.setId( artifact1.getProject() + "-" + version1 + ".jar" );
326 artifact1.setVersion( version1 );
327 ArtifactMetadata artifact2 = createArtifact();
328 String version2 = "1.0-20091212.123456-2";
329 artifact2.setId( artifact2.getProject() + "-" + version2 + ".jar" );
330 artifact2.setVersion( version2 );
331 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
332 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
334 assertEquals( new HashSet<String>( Arrays.asList( version2, version1 ) ),
335 repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
336 TEST_PROJECT_VERSION ) );
339 public void testGetArtifactVersionsMultipleArtifactsSingleVersion()
341 ArtifactMetadata artifact1 = createArtifact();
342 artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
343 ArtifactMetadata artifact2 = createArtifact();
344 artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
345 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
346 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
348 assertEquals( Collections.singleton( TEST_PROJECT_VERSION ),
349 repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
350 TEST_PROJECT_VERSION ) );
353 public void testGetArtifactsByDateRangeOpen()
355 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
356 repository.updateProject( TEST_REPO_ID, createProject() );
357 ArtifactMetadata artifact = createArtifact();
358 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
360 assertEquals( Collections.singletonList( artifact ),
361 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
364 public void testGetArtifactsByDateRangeSparseNamespace()
366 String namespace = "org.apache.archiva";
367 repository.updateNamespace( TEST_REPO_ID, namespace );
368 repository.updateProject( TEST_REPO_ID, createProject( namespace ) );
369 ArtifactMetadata artifact = createArtifact();
370 artifact.setNamespace( namespace );
371 repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
373 assertEquals( Collections.singletonList( artifact ),
374 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
377 public void testGetArtifactsByDateRangeLowerBound()
379 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
380 repository.updateProject( TEST_REPO_ID, createProject() );
381 ArtifactMetadata artifact = createArtifact();
382 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
384 Date date = new Date( artifact.getWhenGathered().getTime() - 10000 );
385 assertEquals( Collections.singletonList( artifact ),
386 repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ) );
389 public void testGetArtifactsByDateRangeLowerBoundOutOfRange()
391 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
392 repository.updateProject( TEST_REPO_ID, createProject() );
393 ArtifactMetadata artifact = createArtifact();
394 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
396 Date date = new Date( artifact.getWhenGathered().getTime() + 10000 );
397 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ).isEmpty() );
400 public void testGetArtifactsByDateRangeLowerAndUpperBound()
402 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
403 repository.updateProject( TEST_REPO_ID, createProject() );
404 ArtifactMetadata artifact = createArtifact();
405 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
407 Date lower = new Date( artifact.getWhenGathered().getTime() - 10000 );
408 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
409 assertEquals( Collections.singletonList( artifact ),
410 repository.getArtifactsByDateRange( TEST_REPO_ID, lower, upper ) );
413 public void testGetArtifactsByDateRangeUpperBound()
415 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
416 repository.updateProject( TEST_REPO_ID, createProject() );
417 ArtifactMetadata artifact = createArtifact();
418 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
420 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
421 assertEquals( Collections.singletonList( artifact ),
422 repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ) );
425 public void testGetArtifactsByDateRangeUpperBoundOutOfRange()
427 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
428 repository.updateProject( TEST_REPO_ID, createProject() );
429 ArtifactMetadata artifact = createArtifact();
430 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
432 Date upper = new Date( artifact.getWhenGathered().getTime() - 10000 );
433 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ).isEmpty() );
436 public void testGetNamespacesWithSparseDepth()
438 repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
440 assertEquals( Arrays.asList( "org" ), repository.getRootNamespaces( TEST_REPO_ID ) );
441 assertEquals( Arrays.asList( "apache" ), repository.getNamespaces( TEST_REPO_ID, "org" ) );
442 assertEquals( Arrays.asList( "maven" ), repository.getNamespaces( TEST_REPO_ID, "org.apache" ) );
443 assertEquals( Arrays.asList( "shared" ), repository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) );
446 public void testGetArtifactsByChecksumSingleResultMd5()
448 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
449 repository.updateProject( TEST_REPO_ID, createProject() );
450 ArtifactMetadata artifact = createArtifact();
451 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
453 assertEquals( Collections.singletonList( artifact ),
454 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
457 public void testGetArtifactsByChecksumSingleResultSha1()
459 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
460 repository.updateProject( TEST_REPO_ID, createProject() );
461 ArtifactMetadata artifact = createArtifact();
462 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
464 assertEquals( Collections.singletonList( artifact ),
465 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
468 public void testGetArtifactsByChecksumMultipleResult()
470 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
472 ProjectMetadata projectMetadata = createProject();
473 repository.updateProject( TEST_REPO_ID, projectMetadata );
474 ArtifactMetadata artifact1 = createArtifact();
475 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
477 projectMetadata = createProject();
478 String newProjectId = "another-project";
479 projectMetadata.setId( newProjectId );
480 repository.updateProject( TEST_REPO_ID, projectMetadata );
481 ArtifactMetadata artifact2 = createArtifact();
482 artifact2.setProject( newProjectId );
483 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
485 assertEquals( Arrays.asList( artifact2, artifact1 ),
486 repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
489 public void testGetArtifactsByChecksumNoResult()
491 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
492 repository.updateProject( TEST_REPO_ID, createProject() );
493 ArtifactMetadata artifact = createArtifact();
494 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
496 assertEquals( Collections.<ArtifactMetadata>emptyList(),
497 repository.getArtifactsByChecksum( TEST_REPO_ID, "not a checksum" ) );
500 public void testDeleteArtifact()
502 ArtifactMetadata artifact = createArtifact();
503 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
505 assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>(
506 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
508 repository.deleteArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
511 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() );
514 public void testDeleteRepository()
516 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
518 ProjectMetadata project1 = new ProjectMetadata();
519 project1.setNamespace( TEST_NAMESPACE );
520 project1.setId( "project1" );
521 repository.updateProject( TEST_REPO_ID, project1 );
522 ProjectMetadata project2 = new ProjectMetadata();
523 project2.setNamespace( TEST_NAMESPACE );
524 project2.setId( "project2" );
525 repository.updateProject( TEST_REPO_ID, project2 );
527 ArtifactMetadata artifact1 = createArtifact();
528 artifact1.setProject( "project1" );
529 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
530 ArtifactMetadata artifact2 = createArtifact();
531 artifact2.setProject( "project2" );
532 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
534 assertEquals( Arrays.asList( artifact1, artifact2 ), new ArrayList<ArtifactMetadata>(
535 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) ) );
537 repository.deleteRepository( TEST_REPO_ID );
539 assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ).isEmpty() );
542 private ProjectMetadata createProject()
544 return createProject( TEST_NAMESPACE );
547 private ProjectMetadata createProject( String ns )
549 ProjectMetadata project = new ProjectMetadata();
550 project.setId( TEST_PROJECT );
551 project.setNamespace( ns );
555 private ArtifactMetadata createArtifact()
557 return createArtifact( "jar" );
560 private ArtifactMetadata createArtifact( String type )
562 ArtifactMetadata artifact = new ArtifactMetadata();
563 artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
564 artifact.setWhenGathered( new Date() );
565 artifact.setNamespace( TEST_NAMESPACE );
566 artifact.setProject( TEST_PROJECT );
567 artifact.setRepositoryId( TEST_REPO_ID );
568 artifact.setFileLastModified( System.currentTimeMillis() );
569 artifact.setVersion( TEST_PROJECT_VERSION );
570 artifact.setMd5( TEST_MD5 );
571 artifact.setSha1( TEST_SHA1 );
575 private static class TestMetadataFacet
576 implements MetadataFacet
578 private String testFacetId;
580 private TestMetadataFacet( String value )
583 testFacetId = TEST_FACET_ID;
586 private TestMetadataFacet( String facetId, String value )
589 testFacetId = facetId;
592 private String value;
594 public String getFacetId()
599 public String getName()
604 public Map<String, String> toProperties()
608 return Collections.singletonMap( testFacetId + ":foo", value );
612 return Collections.emptyMap();
616 public void fromProperties( Map<String, String> properties )
618 String value = properties.get( testFacetId + ":foo" );
625 public String getValue()
631 public String toString()
633 return "TestMetadataFacet{" + "value='" + value + '\'' + '}';
637 public boolean equals( Object o )
643 if ( o == null || getClass() != o.getClass() )
648 TestMetadataFacet that = (TestMetadataFacet) o;
650 if ( value != null ? !value.equals( that.value ) : that.value != null )
659 public int hashCode()
661 return value != null ? value.hashCode() : 0;