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 static org.assertj.core.api.Assertions.assertThat;
24 import java.text.SimpleDateFormat;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Calendar;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.Comparator;
31 import java.util.Date;
32 import java.util.HashMap;
33 import java.util.LinkedHashSet;
34 import java.util.List;
36 import java.util.TimeZone;
38 import junit.framework.TestCase;
40 import org.apache.archiva.metadata.generic.GenericMetadataFacet;
41 import org.apache.archiva.metadata.generic.GenericMetadataFacetFactory;
42 import org.apache.archiva.metadata.model.ArtifactMetadata;
43 import org.apache.archiva.metadata.model.CiManagement;
44 import org.apache.archiva.metadata.model.Dependency;
45 import org.apache.archiva.metadata.model.IssueManagement;
46 import org.apache.archiva.metadata.model.License;
47 import org.apache.archiva.metadata.model.MailingList;
48 import org.apache.archiva.metadata.model.MetadataFacet;
49 import org.apache.archiva.metadata.model.MetadataFacetFactory;
50 import org.apache.archiva.metadata.model.Organization;
51 import org.apache.archiva.metadata.model.ProjectMetadata;
52 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
53 import org.apache.archiva.metadata.model.ProjectVersionReference;
54 import org.apache.archiva.metadata.model.Scm;
55 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
56 import org.assertj.core.util.Sets;
57 import org.junit.Test;
58 import org.junit.runner.RunWith;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
61 import org.springframework.test.context.ContextConfiguration;
63 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
64 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
65 public abstract class AbstractMetadataRepositoryTest
68 protected static final String OTHER_REPO_ID = "other-repo";
70 protected MetadataRepository repository;
72 protected static final String TEST_REPO_ID = "test";
74 protected static final String TEST_PROJECT = "projectId";
76 protected static final String TEST_NAMESPACE = "namespace";
78 protected static final String TEST_PROJECT_VERSION = "1.0";
80 private static final String TEST_PROJECT_VERSION_2_0 = "2.0";
82 private static final String TEST_URL = "http://archiva.apache.org";
84 private static final Organization TEST_ORGANIZATION = new Organization( "Apache", "http://apache.org" );
86 private static final String TEST_FACET_ID = "test-facet-id";
88 private static final String TEST_NAME = "test/name";
90 private static final String TEST_VALUE = "test-value";
92 private static final String UNKNOWN = "unknown";
94 private static final String TEST_MD5 = "bd4a9b642562547754086de2dab26b7d";
96 private static final String TEST_SHA1 = "2e5daf0201ddeb068a62d5e08da18657ab2c6be9";
98 private static final String TEST_METADATA_KEY = "testkey";
100 private static final String TEST_METADATA_VALUE = "testmetadata";
102 protected Logger log = LoggerFactory.getLogger( getClass() );
104 protected static Map<String, MetadataFacetFactory> createTestMetadataFacetFactories()
106 Map<String, MetadataFacetFactory> factories = new HashMap<>();
107 factories.put( TEST_FACET_ID, new MetadataFacetFactory()
110 public MetadataFacet createMetadataFacet()
112 return new TestMetadataFacet( TEST_METADATA_VALUE );
116 public MetadataFacet createMetadataFacet( String repositoryId, String name )
118 return new TestMetadataFacet( TEST_METADATA_VALUE );
122 // add to ensure we don't accidentally create an empty facet ID.
123 factories.put( "", new MetadataFacetFactory()
126 public MetadataFacet createMetadataFacet()
128 return new TestMetadataFacet( "", TEST_VALUE );
132 public MetadataFacet createMetadataFacet( String repositoryId, String name )
134 return new TestMetadataFacet( "", TEST_VALUE );
138 // for the getArtifactsByProjectVersionMetadata tests
139 factories.put( GenericMetadataFacet.FACET_ID, new GenericMetadataFacetFactory() );
145 public void testRootNamespaceWithNoMetadataRepository()
148 Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID );
149 assertThat( namespaces ).isNotNull().isEmpty();
153 public void testGetNamespaceOnly()
156 assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isEmpty();
158 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
160 assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isNotEmpty().contains(
161 TEST_NAMESPACE ).hasSize( 1 );
163 repository.removeNamespace( TEST_REPO_ID, TEST_NAMESPACE );
165 assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isEmpty();
170 public void testGetProjectOnly()
173 assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
174 assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isEmpty();
176 ProjectMetadata project = new ProjectMetadata();
177 project.setId( TEST_PROJECT );
178 project.setNamespace( TEST_NAMESPACE );
180 repository.updateProject( TEST_REPO_ID, project );
182 project = repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
183 assertEquals( TEST_PROJECT, project.getId() );
184 assertEquals( TEST_NAMESPACE, project.getNamespace() );
186 // test that namespace is also constructed
188 Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID );
190 assertThat( namespaces ).isNotNull().isNotEmpty().contains( TEST_NAMESPACE ).hasSize( 1 );
194 public void testGetProjectVersionOnly()
197 assertNull( repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
198 assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
199 assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isEmpty();
201 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
202 metadata.setId( TEST_PROJECT_VERSION );
204 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
206 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
207 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
209 // test that namespace and project is also constructed
210 Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID );
212 assertThat( namespaces ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_NAMESPACE );
214 ProjectMetadata projectMetadata = repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
215 assertNotNull( projectMetadata );
216 assertEquals( TEST_PROJECT, projectMetadata.getId() );
217 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace() );
221 public void testGetArtifactOnly()
224 assertThat( new ArrayList<>(
225 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
226 TEST_PROJECT_VERSION ) ) ).isNotNull().isEmpty();
228 repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull();
229 assertThat( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) ).isNull();
231 assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isEmpty();
233 ArtifactMetadata metadata = createArtifact();
235 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
237 Collection<ArtifactMetadata> artifacts =
238 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
239 //assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
240 assertThat( artifacts ).containsExactly( metadata );
241 // test that namespace, project and project version is also constructed
243 assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isNotEmpty().contains(
244 TEST_NAMESPACE ).hasSize( 1 );
246 ProjectMetadata projectMetadata = repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
247 assertEquals( TEST_PROJECT, projectMetadata.getId() );
248 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace() );
250 ProjectVersionMetadata projectVersionMetadata =
251 repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
252 assertEquals( TEST_PROJECT_VERSION, projectVersionMetadata.getId() );
256 public void testUpdateProjectVersionMetadataWithNoOtherArchives()
259 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
260 metadata.setId( TEST_PROJECT_VERSION );
261 MailingList mailingList = new MailingList();
262 mailingList.setName( "Foo List" );
263 mailingList.setOtherArchives( Collections.<String>emptyList() );
264 metadata.setMailingLists( Arrays.asList( mailingList ) );
265 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
267 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
268 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
270 List<MailingList> mailingLists = metadata.getMailingLists();
272 assertThat( mailingLists ).isNotNull().isNotEmpty().hasSize( 1 );
274 mailingList = metadata.getMailingLists().get( 0 );
275 assertEquals( "Foo List", mailingList.getName() );
277 List<String> others = mailingList.getOtherArchives();
278 assertThat( others ).isNotNull().isEmpty();
282 public void testUpdateProjectVersionMetadataWithAllElements()
285 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
286 metadata.setId( TEST_PROJECT_VERSION );
288 metadata.setName( "project name" );
289 metadata.setDescription( "project description" );
290 metadata.setUrl( "the url" );
292 MailingList mailingList = new MailingList();
293 mailingList.setName( "Foo List" );
294 mailingList.setUnsubscribeAddress( "UnsubscribeAddress" );
295 mailingList.setSubscribeAddress( "SubscribeAddress" );
296 mailingList.setPostAddress( "PostAddress" );
297 mailingList.setMainArchiveUrl( "MainArchiveUrl" );
298 mailingList.setOtherArchives( Arrays.asList( "other archive" ) );
299 metadata.setMailingLists( Arrays.asList( mailingList ) );
302 scm.setConnection( "connection" );
303 scm.setDeveloperConnection( "dev conn" );
305 metadata.setScm( scm );
307 CiManagement ci = new CiManagement();
308 ci.setSystem( "system" );
309 ci.setUrl( "ci url" );
310 metadata.setCiManagement( ci );
312 IssueManagement tracker = new IssueManagement();
313 tracker.setSystem( "system" );
314 tracker.setUrl( "issue tracker url" );
315 metadata.setIssueManagement( tracker );
317 metadata.setOrganization( TEST_ORGANIZATION );
319 License l = new License();
320 l.setName( "license name" );
321 l.setUrl( "license url" );
322 metadata.addLicense( l );
324 Dependency d = new Dependency();
325 d.setArtifactId( "artifactId" );
326 d.setClassifier( "classifier" );
327 d.setGroupId( "groupId" );
328 d.setScope( "scope" );
329 d.setSystemPath( "system path" );
331 d.setVersion( "version" );
332 d.setOptional( true );
333 metadata.addDependency( d );
335 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
337 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
338 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
339 assertEquals( TEST_PROJECT_VERSION, metadata.getVersion() );
340 assertEquals( "project name", metadata.getName() );
341 assertEquals( "project description", metadata.getDescription() );
342 assertEquals( "the url", metadata.getUrl() );
344 assertEquals( "connection", metadata.getScm().getConnection() );
345 assertEquals( "dev conn", metadata.getScm().getDeveloperConnection() );
346 assertEquals( "url", metadata.getScm().getUrl() );
348 assertEquals( "system", metadata.getCiManagement().getSystem() );
349 assertEquals( "ci url", metadata.getCiManagement().getUrl() );
351 assertEquals( "system", metadata.getIssueManagement().getSystem() );
352 assertEquals( "issue tracker url", metadata.getIssueManagement().getUrl() );
354 assertEquals( TEST_ORGANIZATION.getName(), metadata.getOrganization().getName() );
355 assertEquals( TEST_ORGANIZATION.getUrl(), metadata.getOrganization().getUrl() );
357 assertEquals( 1, metadata.getMailingLists().size() );
358 MailingList retrievedMailingList = metadata.getMailingLists().get( 0 );
359 assertEquals( mailingList.getName(), retrievedMailingList.getName() );
360 assertEquals( mailingList.getMainArchiveUrl(), retrievedMailingList.getMainArchiveUrl() );
361 assertEquals( mailingList.getPostAddress(), retrievedMailingList.getPostAddress() );
362 assertEquals( mailingList.getSubscribeAddress(), retrievedMailingList.getSubscribeAddress() );
363 assertEquals( mailingList.getUnsubscribeAddress(), retrievedMailingList.getUnsubscribeAddress() );
364 assertThat( retrievedMailingList.getOtherArchives() ) //
368 .contains( "other archive" );
370 assertEquals( 1, metadata.getLicenses().size() );
371 l = metadata.getLicenses().get( 0 );
372 assertEquals( "license name", l.getName() );
373 assertEquals( "license url", l.getUrl() );
375 assertEquals( 1, metadata.getDependencies().size() );
376 d = metadata.getDependencies().get( 0 );
377 assertEquals( "artifactId", d.getArtifactId() );
378 assertEquals( "classifier", d.getClassifier() );
379 assertEquals( "groupId", d.getGroupId() );
380 assertEquals( "scope", d.getScope() );
381 assertEquals( "system path", d.getSystemPath() );
382 assertEquals( "type", d.getType() );
383 assertEquals( "version", d.getVersion() );
384 assertTrue( d.isOptional() );
388 public void testGetRepositories()
391 // currently set up this way so the behaviour of both the test and the mock config return the same repository
392 // set as the File implementation just uses the config rather than the content
393 repository.updateNamespace( TEST_REPO_ID, "namespace" );
394 repository.updateNamespace( OTHER_REPO_ID, "namespace" );
396 Collection<String> repositories = repository.getRepositories();
398 assertEquals( "repository.getRepositories() -> " + repositories, //
399 Sets.newLinkedHashSet( TEST_REPO_ID, OTHER_REPO_ID ), //
400 new LinkedHashSet<String>( repositories ) ); //
404 public void testUpdateProjectVersionMetadataIncomplete()
407 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
408 metadata.setId( TEST_PROJECT_VERSION );
409 metadata.setIncomplete( true );
410 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
412 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
413 assertEquals( true, metadata.isIncomplete() );
414 assertNull( metadata.getCiManagement() );
415 assertNull( metadata.getScm() );
416 assertNull( metadata.getIssueManagement() );
417 assertNull( metadata.getOrganization() );
418 assertNull( metadata.getDescription() );
419 assertNull( metadata.getName() );
420 assertEquals( TEST_PROJECT_VERSION, metadata.getId() );
421 assertEquals( TEST_PROJECT_VERSION, metadata.getVersion() );
422 assertTrue( metadata.getMailingLists().isEmpty() );
423 assertTrue( metadata.getLicenses().isEmpty() );
424 assertTrue( metadata.getDependencies().isEmpty() );
428 public void testUpdateProjectVersionMetadataWithExistingFacets()
431 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
432 metadata.setId( TEST_PROJECT_VERSION );
433 MetadataFacet facet = new TestMetadataFacet( "baz" );
434 metadata.addFacet( facet );
435 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
437 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
438 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
440 metadata = new ProjectVersionMetadata();
441 metadata.setId( TEST_PROJECT_VERSION );
442 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
444 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
445 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
446 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
447 assertEquals( "baz", testFacet.getValue() );
451 public void testUpdateProjectVersionMetadataWithNoExistingFacets()
454 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
455 metadata.setId( TEST_PROJECT_VERSION );
456 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
458 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
460 assertThat( metadata.getFacetIds() ).isNotNull().isEmpty();
462 metadata = new ProjectVersionMetadata();
463 metadata.setId( TEST_PROJECT_VERSION );
464 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
466 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
467 assertThat( metadata.getFacetIds() ).isNotNull().isEmpty();
472 public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved()
475 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
476 metadata.setId( TEST_PROJECT_VERSION );
478 Map<String, String> additionalProps = new HashMap<>();
479 additionalProps.put( "deleteKey", "deleteValue" );
481 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
482 metadata.addFacet( facet );
483 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
485 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
487 assertThat( metadata.getFacetIds() ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_FACET_ID );
489 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
490 Map<String, String> facetProperties = testFacet.toProperties();
492 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
494 facetProperties.remove( "deleteKey" );
496 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue(), facetProperties );
497 metadata.addFacet( newTestFacet );
499 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
501 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
503 assertThat( metadata.getFacetIds() ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_FACET_ID );
504 testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
505 assertFalse( testFacet.toProperties().containsKey( "deleteKey" ) );
509 public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets()
512 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
513 versionMetadata.setId( TEST_PROJECT_VERSION );
515 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz" );
516 versionMetadata.addFacet( facet );
517 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata );
519 ArtifactMetadata artifactMetadata = createArtifact();
520 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata );
523 Collection<ArtifactMetadata> artifacts =
524 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
525 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
527 artifacts = repository.getArtifacts( TEST_REPO_ID );
528 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
530 artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 );
531 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
533 artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 );
534 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
536 artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, null, null );
537 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
541 public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved()
544 ArtifactMetadata metadata = createArtifact();
546 Map<String, String> additionalProps = new HashMap<>();
547 additionalProps.put( "deleteKey", "deleteValue" );
549 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
550 metadata.addFacet( facet );
551 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
553 Collection<ArtifactMetadata> artifacts =
554 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
556 assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );
557 metadata = artifacts.iterator().next();
559 Collection<String> ids = metadata.getFacetIds();
560 assertThat( ids ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_FACET_ID );
562 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
563 Map<String, String> facetProperties = testFacet.toProperties();
565 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
567 facetProperties.remove( "deleteKey" );
569 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue(), facetProperties );
570 metadata.addFacet( newTestFacet );
572 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
574 artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
576 assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );
577 metadata = artifacts.iterator().next();
579 ids = metadata.getFacetIds();
580 assertThat( ids ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_FACET_ID );
582 testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
584 Map<String, String> props = testFacet.toProperties();
585 assertThat( props ).isNotNull().doesNotContainKey( "deleteKey" );
589 public void testUpdateArtifactMetadataWithExistingFacets()
592 ArtifactMetadata metadata = createArtifact();
593 MetadataFacet facet = new TestMetadataFacet( "baz" );
594 metadata.addFacet( facet );
595 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
597 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
598 TEST_PROJECT_VERSION ).iterator().next();
599 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
601 metadata = createArtifact();
602 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
604 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
605 TEST_PROJECT_VERSION ).iterator().next();
606 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
607 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
608 assertEquals( "baz", testFacet.getValue() );
612 public void testUpdateArtifactMetadataWithNoExistingFacets()
615 ArtifactMetadata metadata = createArtifact();
616 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
618 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
619 TEST_PROJECT_VERSION ).iterator().next();
620 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
622 metadata = createArtifact();
623 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
625 metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
626 TEST_PROJECT_VERSION ).iterator().next();
627 assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
631 public void testGetMetadataFacet()
634 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
636 TestMetadataFacet test =
637 (TestMetadataFacet) repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
639 assertEquals( new TestMetadataFacet( TEST_VALUE ), test );
643 public void testGetMetadataFacetWhenEmpty()
646 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
650 public void testGetMetadataFacetWhenUnknownName()
653 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
655 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) );
659 public void testGetMetadataFacetWhenDefaultValue()
662 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) );
664 MetadataFacet metadataFacet = repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
666 assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ), metadataFacet );
670 public void testGetMetadataFacetWhenUnknownFacetId()
673 assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
677 public void testGetMetadataFacets()
680 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
682 assertEquals( Collections.singletonList( TEST_NAME ),
683 repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ) );
687 public void testGetMetadataFacetsWhenEmpty()
691 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
692 assertTrue( facets.isEmpty() );
696 public void testRemoveFacets()
699 repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
701 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
702 assertFalse( facets.isEmpty() );
704 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
706 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
707 assertTrue( facets.isEmpty() );
711 public void testRemoveFacetsWhenEmpty()
714 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
715 assertTrue( facets.isEmpty() );
717 repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
719 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
720 assertTrue( facets.isEmpty() );
724 public void testRemoveFacetsWhenUnknown()
727 // testing no exception
728 repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN );
732 public void testRemoveFacetWhenUnknown()
735 // testing no exception
736 repository.removeMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME );
740 public void testRemoveFacet()
743 TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
744 repository.addMetadataFacet( TEST_REPO_ID, metadataFacet );
746 assertEquals( metadataFacet, repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
747 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
748 assertFalse( facets.isEmpty() );
750 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
752 assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
753 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
754 assertTrue( facets.isEmpty() );
758 public void testRemoveFacetWhenEmpty()
761 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
762 assertThat( facets ).isNotNull().isEmpty();
763 assertThat( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull();
765 repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
767 facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
768 assertThat( facets ).isNotNull().isEmpty();
769 assertThat( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull();
773 public void hasMetadataFacetStart()
776 assertFalse( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) );
781 public void hasMetadataFacet()
785 assertFalse( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) );
787 Calendar cal = Calendar.getInstance();
789 repository.addMetadataFacet( TEST_REPO_ID, new KindOfRepositoryStatistics( "first", cal.getTime() ) );
791 assertTrue( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) );
793 cal.add( Calendar.MINUTE, 2 );
795 repository.addMetadataFacet( TEST_REPO_ID, new KindOfRepositoryStatistics( "second", cal.getTime() ) );
797 cal.add( Calendar.MINUTE, 2 );
799 repository.addMetadataFacet( TEST_REPO_ID, new KindOfRepositoryStatistics( "third", cal.getTime() ) );
801 List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() );
803 assertThat( facets ).isNotNull().isNotEmpty().hasSize( 3 );
805 assertTrue( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) );
807 repository.removeMetadataFacets( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() );
809 assertFalse( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) );
811 facets = repository.getMetadataFacets( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() );
813 assertThat( facets ).isNotNull().isEmpty();
819 public void testGetArtifacts()
822 ArtifactMetadata artifact1 = createArtifact();
823 ArtifactMetadata artifact2 = createArtifact( "pom" );
824 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
825 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
827 Collection<ArtifactMetadata> artifacts =
828 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
829 ArrayList<ArtifactMetadata> actual = new ArrayList<>( artifacts );
830 Collections.sort( actual, new Comparator<ArtifactMetadata>()
833 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
835 return o1.getId().compareTo( o2.getId() );
838 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
842 public void testGetArtifactVersions()
845 ArtifactMetadata artifact1 = createArtifact();
846 String version1 = "1.0-20091212.012345-1";
847 artifact1.setId( artifact1.getProject() + "-" + version1 + ".jar" );
848 artifact1.setVersion( version1 );
849 ArtifactMetadata artifact2 = createArtifact();
850 String version2 = "1.0-20091212.123456-2";
851 artifact2.setId( artifact2.getProject() + "-" + version2 + ".jar" );
852 artifact2.setVersion( version2 );
853 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
854 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
856 Collection<String> versions =
857 repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
859 assertThat( versions ).isNotNull().isNotEmpty().contains( version1, version2 );
863 public void testGetArtifactVersionsMultipleArtifactsSingleVersion()
866 ArtifactMetadata artifact1 = createArtifact();
867 artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
868 ArtifactMetadata artifact2 = createArtifact();
869 artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
870 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
871 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
873 Collection<String> versions =
874 repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
876 assertThat( versions ).isNotNull().isNotEmpty().hasSize( 1 ).containsExactly( TEST_PROJECT_VERSION );
881 public void testGetArtifactsByDateRangeOpen()
884 ArtifactMetadata artifact = createArtifact();
885 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
888 List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, null, null );
890 assertEquals( Collections.singletonList( artifact ), artifacts );
894 public void testGetArtifactsByDateRangeSparseNamespace()
897 String namespace = "org.apache.archiva";
898 ArtifactMetadata artifact = createArtifact();
899 artifact.setNamespace( namespace );
900 repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
903 List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, null, null );
905 assertEquals( Collections.singletonList( artifact ), artifacts );
909 public void testGetArtifactsByDateRangeLowerBound()
912 ArtifactMetadata artifact = createArtifact();
913 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
916 Date date = new Date( artifact.getWhenGathered().getTime() - 10000 );
918 List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, date, null );
920 assertEquals( Collections.singletonList( artifact ), artifacts );
924 public void testGetArtifactsByDateRangeLowerBoundOutOfRange()
927 ArtifactMetadata artifact = createArtifact();
928 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
930 Date date = new Date( artifact.getWhenGathered().getTime() + 10000 );
932 List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, date, null );
934 assertThat( artifacts ).isNotNull().isEmpty();
938 public void testGetArtifactsByDateRangeLowerAndUpperBound()
941 ArtifactMetadata artifact = createArtifact();
942 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
945 Date lower = new Date( artifact.getWhenGathered().getTime() - 10000 );
946 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
948 List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, lower, upper );
950 assertEquals( Collections.singletonList( artifact ), artifacts );
954 public void testGetArtifactsByDateRangeUpperBound()
957 ArtifactMetadata artifact = createArtifact();
958 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
961 Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
963 List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper );
965 assertEquals( Collections.singletonList( artifact ), artifacts );
969 public void testGetArtifactsByDateRangeUpperBoundOutOfRange()
972 ArtifactMetadata artifact = createArtifact();
973 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
976 Date upper = new Date( artifact.getWhenGathered().getTime() - 10000 );
978 List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper );
980 assertThat( artifacts ).isNotNull().isEmpty();
984 public void testGetArtifactsByRepoId()
987 ArtifactMetadata artifact = createArtifact();
988 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
991 List<ArtifactMetadata> artifacts = repository.getArtifacts( TEST_REPO_ID );
993 assertEquals( Collections.singletonList( artifact ), artifacts );
997 public void testGetArtifactsByRepoIdMultipleCopies()
1000 ArtifactMetadata artifact = createArtifact();
1001 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1003 ArtifactMetadata secondArtifact = createArtifact();
1004 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1005 repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1008 // test it restricts to the appropriate repository
1009 assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) );
1010 assertEquals( Collections.singletonList( secondArtifact ), repository.getArtifacts( OTHER_REPO_ID ) );
1014 public void testGetArtifactsByDateRangeMultipleCopies()
1017 ArtifactMetadata artifact = createArtifact();
1018 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1020 ArtifactMetadata secondArtifact = createArtifact();
1021 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1022 repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1025 // test it restricts to the appropriate repository
1026 assertEquals( Collections.singletonList( artifact ),
1027 repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
1028 assertEquals( Collections.singletonList( secondArtifact ),
1029 repository.getArtifactsByDateRange( OTHER_REPO_ID, null, null ) );
1033 public void testGetArtifactsByChecksumMultipleCopies()
1036 ArtifactMetadata artifact = createArtifact();
1037 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1039 ArtifactMetadata secondArtifact = createArtifact();
1040 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1041 repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1044 // test it restricts to the appropriate repository
1045 assertEquals( Collections.singletonList( artifact ),
1046 new ArrayList<>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ) );
1047 assertEquals( Collections.singletonList( secondArtifact ), new ArrayList<>(
1048 repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_SHA1 ) ) );
1049 assertEquals( Collections.singletonList( artifact ),
1050 new ArrayList<>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ) );
1051 assertEquals( Collections.singletonList( secondArtifact ),
1052 new ArrayList<>( repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_MD5 ) ) );
1056 public void testGetNamespacesWithSparseDepth()
1059 repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
1061 Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID );
1063 assertThat( namespaces ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "org" );
1065 namespaces = repository.getNamespaces( TEST_REPO_ID, "org" );
1066 assertThat( namespaces ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "apache" );
1068 namespaces = repository.getNamespaces( TEST_REPO_ID, "org.apache" );
1069 assertThat( namespaces ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "maven" );
1071 namespaces = repository.getNamespaces( TEST_REPO_ID, "org.apache.maven" );
1072 assertThat( namespaces ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "shared" );
1076 public void testGetNamespacesWithProjectsPresent()
1079 String namespace = "org.apache.maven.shared";
1080 repository.updateNamespace( TEST_REPO_ID, namespace );
1082 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
1083 metadata.setId( TEST_PROJECT_VERSION );
1084 repository.updateProjectVersion( TEST_REPO_ID, namespace, TEST_PROJECT, metadata );
1086 Collection<String> namespaces = repository.getNamespaces( TEST_REPO_ID, namespace );
1088 assertThat( namespaces ).isNotNull().isEmpty();
1093 public void testGetProjectsWithOtherNamespacesPresent()
1096 ProjectMetadata projectMetadata = new ProjectMetadata();
1097 projectMetadata.setId( TEST_PROJECT );
1098 projectMetadata.setNamespace( "org.apache.maven" );
1099 repository.updateProject( TEST_REPO_ID, projectMetadata );
1101 repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
1103 Collection<String> projects = repository.getProjects( TEST_REPO_ID, "org.apache.maven" );
1105 assertThat( projects ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_PROJECT );
1109 public void testGetProjectVersionsWithOtherNamespacesPresent()
1112 // an unusual case but technically possible where a project namespace matches another project's name
1114 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
1115 versionMetadata.setId( TEST_PROJECT_VERSION );
1116 repository.updateProjectVersion( TEST_REPO_ID, "org.apache.maven", TEST_PROJECT, versionMetadata );
1118 repository.updateProjectVersion( TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT, "other-project",
1121 Collection<String> versions =
1122 repository.getProjectVersions( TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT, "other-project" );
1123 assertThat( versions ).isNotNull().isNotEmpty().contains( TEST_PROJECT_VERSION );
1125 versions = repository.getProjectVersions( TEST_REPO_ID, "org.apache.maven", TEST_PROJECT );
1127 assertThat( versions ).isNotNull().isNotEmpty().contains( TEST_PROJECT_VERSION );
1131 public void testGetArtifactsByChecksumSingleResultMd5()
1134 ArtifactMetadata artifact = createArtifact();
1135 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1138 assertEquals( Collections.singletonList( artifact ),
1139 new ArrayList<>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ) );
1143 public void testGetArtifactsByChecksumSingleResultSha1()
1146 ArtifactMetadata artifact = createArtifact();
1147 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1150 assertEquals( Collections.singletonList( artifact ),
1151 new ArrayList<>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ) );
1155 public void testGetArtifactsByChecksumDeepNamespace()
1158 ArtifactMetadata artifact = createArtifact();
1159 String namespace = "multi.level.ns";
1160 artifact.setNamespace( namespace );
1161 repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1164 assertEquals( Collections.singletonList( artifact ),
1165 new ArrayList<>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ) );
1166 assertEquals( Collections.singletonList( artifact ),
1167 new ArrayList<>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ) );
1171 public void testGetArtifactsByChecksumMultipleResult()
1174 ArtifactMetadata artifact1 = createArtifact();
1175 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1177 String newProjectId = "another-project";
1178 ArtifactMetadata artifact2 = createArtifact();
1179 artifact2.setProject( newProjectId );
1180 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
1183 List<ArtifactMetadata> artifacts =
1184 new ArrayList<>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) );
1185 Collections.sort( artifacts, new ArtifactMetadataComparator() );
1186 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1188 artifacts = new ArrayList<>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) );
1189 Collections.sort( artifacts, new ArtifactMetadataComparator() );
1190 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1194 public void testGetArtifactsByChecksumNoResult()
1197 ArtifactMetadata artifact = createArtifact();
1198 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1200 Collection<ArtifactMetadata> artifactsByChecksum =
1201 repository.getArtifactsByChecksum( TEST_REPO_ID, "not checksum" );
1202 assertThat( artifactsByChecksum ).isNotNull().isEmpty();
1206 public void testGetArtifactsByProjectVersionMetadata()
1209 createArtifactWithGenericMetadataFacet( 10 );
1210 Collection<ArtifactMetadata> artifactsByMetadata =
1211 repository.getArtifactsByProjectVersionMetadata( TEST_METADATA_KEY, TEST_METADATA_VALUE, TEST_REPO_ID );
1212 assertThat( artifactsByMetadata ).hasSize( 1 );
1213 ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator().next();
1214 assertThat( artifactMetadata.getId() ).isEqualTo( "projectId-1.0.jar" );
1215 assertThat( artifactMetadata.getSha1() ).isEqualTo( TEST_SHA1 );
1216 assertThat( artifactMetadata.getRepositoryId() ).isEqualTo( TEST_REPO_ID );
1220 public void testGetArtifactsByProjectVersionMetadataNoRepository()
1223 createArtifactWithGenericMetadataFacet();
1224 Collection<ArtifactMetadata> artifactsByMetadata =
1225 repository.getArtifactsByProjectVersionMetadata( TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
1226 assertThat( artifactsByMetadata ).hasSize( 1 );
1227 assertThat( artifactsByMetadata.iterator().next().getRepositoryId() ).isNotNull().isNotEmpty();
1231 public void testGetArtifactsByProjectVersionMetadataAllRepositories()
1234 createArtifactWithGenericMetadataFacet();
1235 Collection<ArtifactMetadata> artifactsByMetadata =
1236 repository.getArtifactsByProjectVersionMetadata( TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
1237 assertThat( artifactsByMetadata ).hasSize( 1 );
1241 public void testGetArtifactsByMetadataAllRepositories()
1244 createArtifactWithMavenArtifactFacet();
1245 Collection<ArtifactMetadata> artifactsByMetadata =
1246 repository.getArtifactsByMetadata( "foo", TEST_METADATA_VALUE, null );
1247 assertThat( artifactsByMetadata ).hasSize( 1 );
1248 ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator().next();
1249 assertThat( artifactMetadata.getId() ).isEqualTo( "projectId-1.0.jar" );
1250 assertThat( artifactMetadata.getSha1() ).isEqualTo( TEST_SHA1 );
1251 assertThat( artifactMetadata.getRepositoryId() ).isEqualTo( TEST_REPO_ID );
1252 MetadataFacet facet = artifactMetadata.getFacet( TEST_FACET_ID );
1253 assertThat( facet ).isNotNull();
1254 assertThat( facet.toProperties() ).isEqualTo( Collections.singletonMap( "foo", TEST_METADATA_VALUE ) );
1258 public void testGetArtifactsByPropertySingleResult()
1261 createArtifactWithData();
1262 // only works on JCR implementation
1263 // Collection<ArtifactMetadata> artifactsByProperty = repository.getArtifactsByProperty( "org.name", TEST_ORGANIZATION.getName(), TEST_REPO_ID );
1264 Collection<ArtifactMetadata> artifactsByProperty = repository.getArtifactsByProperty( "url", TEST_URL, TEST_REPO_ID );
1265 assertThat( artifactsByProperty ).hasSize( 1 );
1266 ArtifactMetadata artifactMetadata = artifactsByProperty.iterator().next();
1267 assertThat( artifactMetadata.getId() ).isEqualTo( "projectId-1.0.jar" );
1268 assertThat( artifactMetadata.getSha1() ).isEqualTo( TEST_SHA1 );
1269 assertThat( artifactMetadata.getRepositoryId() ).isEqualTo( TEST_REPO_ID );
1273 public void testDeleteRepository()
1276 repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
1278 ProjectMetadata project1 = new ProjectMetadata();
1279 project1.setNamespace( TEST_NAMESPACE );
1280 project1.setId( "project1" );
1281 repository.updateProject( TEST_REPO_ID, project1 );
1282 ProjectMetadata project2 = new ProjectMetadata();
1283 project2.setNamespace( TEST_NAMESPACE );
1284 project2.setId( "project2" );
1285 repository.updateProject( TEST_REPO_ID, project2 );
1287 ArtifactMetadata artifact1 = createArtifact();
1288 artifact1.setProject( "project1" );
1289 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
1290 ArtifactMetadata artifact2 = createArtifact();
1291 artifact2.setProject( "project2" );
1292 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
1295 List<ArtifactMetadata> expected = Arrays.asList( artifact1, artifact2 );
1296 Collections.sort( expected, new ArtifactMetadataComparator() );
1298 List<ArtifactMetadata> actual =
1299 new ArrayList<>( repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
1300 Collections.sort( actual, new ArtifactMetadataComparator() );
1302 assertEquals( expected, actual );
1304 repository.removeRepository( TEST_REPO_ID );
1306 assertTrue( repository.getArtifacts( TEST_REPO_ID ).isEmpty() );
1307 assertTrue( repository.getRootNamespaces( TEST_REPO_ID ).isEmpty() );
1312 public void testDeleteArtifact()
1315 ArtifactMetadata artifact = createArtifact();
1316 artifact.addFacet( new TestMetadataFacet( "value" ) );
1318 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1320 assertThat( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
1321 TEST_PROJECT_VERSION ) ).containsExactly( artifact );
1323 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact );
1325 Collection<String> versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1327 log.info( "versions {}", versions );
1329 assertThat( versions ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "1.0", "2.0" );
1331 repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
1333 versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1335 log.info( "versions {}", versions );
1337 assertThat( versions ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "2.0" );
1339 assertThat( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
1340 TEST_PROJECT_VERSION ) ).isNotNull().isEmpty();
1342 assertThat( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
1343 TEST_PROJECT_VERSION_2_0 ) ).isNotEmpty().hasSize( 1 );
1347 public void deleteArtifact()
1350 ArtifactMetadata artifact = createArtifact();
1351 artifact.addFacet( new TestMetadataFacet( "value" ) );
1353 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1355 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1357 Collection<ArtifactMetadata> artifacts =
1358 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1360 assertEquals( Collections.singletonList( artifact ), new ArrayList<>( artifacts ) );
1362 repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
1364 artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1366 assertThat( artifacts ).isNotNull().isEmpty();
1370 public void deleteVersion()
1373 ArtifactMetadata artifact = createArtifact();
1374 artifact.addFacet( new TestMetadataFacet( "value" ) );
1376 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1378 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1380 Collection<String> versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1382 assertThat( versions ).isNotNull().isNotEmpty().hasSize( 1 );
1384 repository.removeProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1386 versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1388 assertThat( versions ).isNotNull().isEmpty();
1392 public void deleteProject()
1395 ArtifactMetadata artifact = createArtifact();
1396 artifact.addFacet( new TestMetadataFacet( "value" ) );
1398 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1400 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1402 assertEquals( 1, repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ).size() );
1404 repository.removeProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1406 Collection<String> versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1408 assertThat( versions ).isNotNull().isEmpty();
1413 public void deleteSnapshotVersion()
1416 ArtifactMetadata artifactOne = createArtifact();
1417 artifactOne.setVersion( "2.0-20120618.214127-1" );
1418 artifactOne.setProjectVersion( "2.0-SNAPSHOT" );
1419 artifactOne.addFacet( new TestMetadataFacet( "value" ) );
1420 artifactOne.setId( TEST_PROJECT + "-" + "2.0-20120618.214127-1" + "." + "jar" );
1422 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactOne );
1424 ArtifactMetadata artifactTwo = createArtifact();
1425 artifactTwo.setVersion( "2.0-20120618.214135-2" );
1426 artifactTwo.setProjectVersion( "2.0-SNAPSHOT" );
1427 artifactTwo.addFacet( new TestMetadataFacet( "value" ) );
1428 artifactTwo.setId( TEST_PROJECT + "-" + "2.0-20120618.214135-2" + "." + "jar" );
1430 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactTwo );
1432 Collection<ArtifactMetadata> artifactMetadatas =
1433 repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
1435 assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 2 );
1437 log.info( "artifactMetadatas: {}", artifactMetadatas );
1439 repository.removeArtifact( artifactOne, "2.0-SNAPSHOT" );
1441 artifactMetadatas = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
1443 assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 1 );
1445 repository.removeArtifact( artifactTwo, "2.0-SNAPSHOT" );
1447 artifactMetadatas = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
1449 assertThat( artifactMetadatas ).isNotNull().isEmpty();
1454 public void testgetProjectReferences()
1457 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
1458 metadata.setId( TEST_PROJECT_VERSION );
1460 metadata.setName( "project name" );
1461 metadata.setDescription( "project description" );
1462 metadata.setUrl( "the url" );
1464 Dependency d = new Dependency();
1465 d.setArtifactId( "artifactId" );
1466 d.setClassifier( "classifier" );
1467 d.setGroupId( "groupId" );
1468 d.setScope( "scope" );
1469 d.setSystemPath( "system path" );
1470 d.setType( "type" );
1471 d.setVersion( "version" );
1472 d.setOptional( true );
1473 metadata.addDependency( d );
1475 d = new Dependency();
1476 d.setArtifactId( "artifactId1" );
1477 d.setClassifier( "classifier" );
1478 d.setGroupId( "groupId" );
1479 d.setScope( "scope" );
1480 d.setSystemPath( "system path" );
1481 d.setType( "type" );
1482 d.setVersion( "version1" );
1483 d.setOptional( true );
1484 metadata.addDependency( d );
1486 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
1490 metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1492 Collection<ProjectVersionReference> references =
1493 repository.getProjectReferences( TEST_REPO_ID, d.getGroupId(), d.getArtifactId(), d.getVersion() );
1495 log.info( "references: {}", references );
1497 assertThat( references ).isNotNull().hasSize( 1 ).contains(
1498 new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY, TEST_PROJECT, TEST_NAMESPACE,
1499 TEST_PROJECT_VERSION ) );
1504 public void testSearchArtifactsByKey()
1507 createArtifactWithData();
1508 Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( "url", TEST_URL, TEST_REPO_ID, false );
1509 assertThat( artifactsByProperty ).isNotNull().isNotEmpty();
1513 public void testSearchArtifactsByKeyExact()
1516 createArtifactWithData();
1517 Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( "url", TEST_URL, TEST_REPO_ID, true );
1518 assertThat( artifactsByProperty ).isNotNull().isNotEmpty();
1519 artifactsByProperty = repository.searchArtifacts( "org.name", "pache", TEST_REPO_ID, true );
1520 assertThat( artifactsByProperty ).isNotNull().isEmpty();
1524 public void testSearchArtifactsByFacetKey()
1527 createArtifactWithGenericMetadataFacet();
1528 Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( TEST_METADATA_KEY, TEST_METADATA_VALUE, TEST_REPO_ID, false );
1529 assertThat( artifactsByProperty ).isNotNull().isNotEmpty();
1533 public void testSearchArtifactsByFacetKeyAllRepos()
1536 createArtifactWithGenericMetadataFacet();
1537 Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( TEST_METADATA_KEY, TEST_METADATA_VALUE, null, false );
1538 assertThat( artifactsByProperty ).isNotNull().isNotEmpty();
1542 public void testSearchArtifactsFullText()
1545 createArtifactWithGenericMetadataFacet();
1546 // only works in JCR
1547 // Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( TEST_URL, TEST_REPO_ID, false );
1548 Collection<ArtifactMetadata> artifactsByProperty =
1549 repository.searchArtifacts( TEST_METADATA_VALUE, TEST_REPO_ID, false );
1550 assertThat( artifactsByProperty ).isNotNull().isNotEmpty();
1554 public void testSearchArtifactsFullTextExact()
1557 createArtifactWithGenericMetadataFacet();
1558 // only works in JCR
1559 // Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( TEST_URL, TEST_REPO_ID, true );
1560 Collection<ArtifactMetadata> artifactsByProperty =
1561 repository.searchArtifacts( TEST_METADATA_VALUE, TEST_REPO_ID, true );
1562 assertThat( artifactsByProperty ).isNotNull().isNotEmpty();
1563 artifactsByProperty = repository.searchArtifacts( TEST_METADATA_VALUE.substring( 2 ), TEST_REPO_ID, true );
1564 assertThat( artifactsByProperty ).isNotNull().isEmpty();
1568 public void testSearchArtifactsFullTextByFacet()
1571 createArtifactWithGenericMetadataFacet();
1572 Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( TEST_METADATA_VALUE, TEST_REPO_ID, false );
1573 assertThat( artifactsByProperty ).isNotNull().isNotEmpty();
1576 private static ProjectMetadata createProject()
1578 return createProject( TEST_NAMESPACE );
1581 private static ProjectMetadata createProject( String ns )
1583 ProjectMetadata project = new ProjectMetadata();
1584 project.setId( TEST_PROJECT );
1585 project.setNamespace( ns );
1589 private void createArtifactWithGenericMetadataFacet()
1590 throws MetadataRepositoryException, MetadataResolutionException
1592 createArtifactWithGenericMetadataFacet( 1 );
1595 private void createArtifactWithGenericMetadataFacet( int artifacts )
1596 throws MetadataRepositoryException, MetadataResolutionException
1598 MetadataFacet metadataFacet = new GenericMetadataFacet();
1599 Map<String, String> properties = new HashMap<>();
1600 properties.put( TEST_METADATA_KEY, TEST_METADATA_VALUE );
1601 metadataFacet.fromProperties( properties );
1602 createArtifactWithFacet( artifacts, null, metadataFacet );
1605 private void createArtifactWithMavenArtifactFacet()
1606 throws MetadataRepositoryException, MetadataResolutionException
1608 createArtifactWithMavenArtifactFacet( 1 );
1611 private void createArtifactWithMavenArtifactFacet( int artifacts )
1612 throws MetadataRepositoryException, MetadataResolutionException
1614 TestMetadataFacet facet = new TestMetadataFacet( TEST_METADATA_VALUE );
1615 createArtifactWithFacet( artifacts, facet, null );
1618 private void createArtifactWithFacet( int artifacts, MetadataFacet artifactFacet,
1619 MetadataFacet projectVersionMetadataFacet )
1620 throws MetadataRepositoryException, MetadataResolutionException
1622 for ( int i = 0; i < artifacts; i++ )
1624 ArtifactMetadata artifact = createArtifact();
1625 if ( artifactFacet != null )
1627 artifact.addFacet( artifactFacet );
1629 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1631 if ( projectVersionMetadataFacet != null )
1633 ProjectVersionMetadata metadata =
1634 repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1635 metadata.addFacet( projectVersionMetadataFacet );
1636 metadata.setOrganization( TEST_ORGANIZATION );
1637 metadata.setUrl( TEST_URL );
1638 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
1643 private void createArtifactWithData()
1644 throws MetadataRepositoryException, MetadataResolutionException
1646 ArtifactMetadata artifact = createArtifact();
1647 repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1648 ProjectVersionMetadata metadata =
1649 repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1650 metadata.setOrganization( TEST_ORGANIZATION );
1651 metadata.setUrl( TEST_URL );
1653 repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
1657 private static ArtifactMetadata createArtifact()
1659 return createArtifact( "jar" );
1662 private static ArtifactMetadata createArtifact( String type )
1664 ArtifactMetadata artifact = new ArtifactMetadata();
1665 artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
1666 artifact.setWhenGathered( new Date() );
1667 artifact.setNamespace( TEST_NAMESPACE );
1668 artifact.setProject( TEST_PROJECT );
1669 artifact.setRepositoryId( TEST_REPO_ID );
1670 artifact.setFileLastModified( System.currentTimeMillis() );
1671 artifact.setVersion( TEST_PROJECT_VERSION );
1672 artifact.setProjectVersion( TEST_PROJECT_VERSION );
1673 artifact.setMd5( TEST_MD5 );
1674 artifact.setSha1( TEST_SHA1 );
1678 private static class ArtifactMetadataComparator
1679 implements Comparator<ArtifactMetadata>
1682 public final int compare( ArtifactMetadata a, ArtifactMetadata b )
1684 return a.getProject().compareTo( b.getProject() );
1688 private static class KindOfRepositoryStatistics
1689 implements MetadataFacet
1691 private String value;
1695 static final String SCAN_TIMESTAMP_FORMAT = "yyyy/MM/dd/HHmmss.SSS";
1697 private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
1699 private KindOfRepositoryStatistics( String value, Date date )
1706 public String getName()
1708 return createNameFormat().format( date );
1711 private static SimpleDateFormat createNameFormat()
1713 SimpleDateFormat fmt = new SimpleDateFormat( SCAN_TIMESTAMP_FORMAT );
1714 fmt.setTimeZone( UTC_TIME_ZONE );
1719 public String getFacetId()
1721 return KindOfRepositoryStatistics.class.getName();
1725 public Map<String, String> toProperties()
1727 return Collections.emptyMap();
1731 public void fromProperties( Map<String, String> properties )
1737 private static class TestMetadataFacet
1738 implements MetadataFacet
1740 private String testFacetId;
1742 private Map<String, String> additionalProps;
1744 private String value;
1746 private TestMetadataFacet( String value )
1749 testFacetId = TEST_FACET_ID;
1752 private TestMetadataFacet( String facetId, String value )
1755 testFacetId = facetId;
1758 private TestMetadataFacet( String facetId, String value, Map<String, String> additionalProps )
1760 this( facetId, value );
1761 this.additionalProps = additionalProps;
1765 public String getFacetId()
1771 public String getName()
1777 public Map<String, String> toProperties()
1779 if ( value != null )
1781 if ( additionalProps == null )
1783 return Collections.singletonMap( "foo", value );
1787 Map<String, String> props = new HashMap<>();
1788 props.put( "foo", value );
1790 for ( String key : additionalProps.keySet() )
1792 props.put( key, additionalProps.get( key ) );
1799 return Collections.emptyMap();
1804 public void fromProperties( Map<String, String> properties )
1806 String value = properties.get( "foo" );
1807 if ( value != null )
1812 properties.remove( "foo" );
1814 if ( additionalProps == null )
1816 additionalProps = new HashMap<>();
1819 for ( String key : properties.keySet() )
1821 additionalProps.put( key, properties.get( key ) );
1825 public String getValue()
1831 public String toString()
1833 return "TestMetadataFacet{" + "value='" + value + '\'' + '}';
1837 public boolean equals( Object o )
1843 if ( o == null || getClass() != o.getClass() )
1848 TestMetadataFacet that = (TestMetadataFacet) o;
1850 if ( value != null ? !value.equals( that.value ) : that.value != null )
1859 public int hashCode()
1861 return value != null ? value.hashCode() : 0;