1 package org.apache.archiva.metadata.repository;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import junit.framework.TestCase;
23 import org.apache.archiva.checksum.ChecksumAlgorithm;
24 import org.apache.archiva.metadata.QueryParameter;
25 import org.apache.archiva.metadata.generic.GenericMetadataFacet;
26 import org.apache.archiva.metadata.generic.GenericMetadataFacetFactory;
27 import org.apache.archiva.metadata.model.*;
28 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.test.context.ContextConfiguration;
35 import java.text.SimpleDateFormat;
36 import java.time.ZoneId;
37 import java.time.ZonedDateTime;
39 import java.util.stream.Collectors;
40 import java.util.stream.Stream;
42 import static org.assertj.core.api.Assertions.assertThat;
44 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
45 @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml"} )
46 public abstract class AbstractMetadataRepositoryTest
49 protected static final String OTHER_REPO_ID = "other-repo";
52 protected static final String TEST_REPO_ID = "test";
54 protected static final String TEST_PROJECT = "myproject";
56 protected static final String TEST_NAMESPACE = "mytest";
58 protected static final String TEST_PROJECT_VERSION = "1.0";
60 private static final String TEST_PROJECT_VERSION_2_0 = "2.0";
62 protected static final String TEST_URL = "http://archiva.apache.org";
64 private static final Organization TEST_ORGANIZATION = new Organization( "Apache", "http://apache.org" );
66 private static final String TEST_FACET_ID = "test-facet-id";
68 private static final String TEST_NAME = "test/name";
70 private static final String TEST_VALUE = "test-value";
72 private static final String UNKNOWN = "unknown";
74 private static final String TEST_SHA256 = "e43857b4e75e04a09d167564ca9a4636e5d233035483ba4ecf1243e34325d565";
76 private static final String TEST_MD5 = "bd4a9b642562547754086de2dab26b7d";
78 private static final String TEST_SHA1 = "2e5daf0201ddeb068a62d5e08da18657ab2c6be9";
80 private static final String TEST_METADATA_KEY = "testkey";
82 private static final String TEST_METADATA_VALUE = "testmetadata";
84 protected Logger log = LoggerFactory.getLogger( getClass( ) );
86 protected int assertMaxTries =10;
87 protected int assertRetrySleepMs=500;
90 * Used by tryAssert to allow to throw exceptions in the lambda expression.
93 protected interface AssertFunction
95 void accept( ) throws Exception;
98 protected void tryAssert( AssertFunction func ) throws Exception
100 tryAssert( func, assertMaxTries, assertRetrySleepMs );
104 protected abstract RepositorySessionFactory getSessionFactory( );
106 protected abstract MetadataRepository getRepository( );
109 * Runs the assert method until the assert is successful or the number of retries
110 * is reached. This is needed because the JCR Oak index update is asynchronous, so updates
111 * may not be visible immediately after the modification.
113 private void tryAssert( AssertFunction func, int retries, int sleepMillis ) throws Exception
117 while ( retry-- > 0 )
124 catch ( Exception | AssertionError e )
127 Thread.currentThread( ).sleep( sleepMillis );
128 log.warn( "Retrying assert {}: {}", retry, e.getMessage( ) );
131 log.warn( "Retries: {}, Exception: {}", retry, t.getMessage( ) );
132 if ( retry <= 0 && t != null )
134 if ( t instanceof RuntimeException )
136 throw (RuntimeException) t;
138 else if ( t instanceof Exception )
142 else if ( t instanceof Error )
150 public static List<MetadataFacetFactory> createTestMetadataFacetFactories( )
152 List<MetadataFacetFactory> factories = new ArrayList<>( );
153 factories.add( new MetadataFacetFactory<TestMetadataFacet>( )
156 public TestMetadataFacet createMetadataFacet( )
158 return new TestMetadataFacet( TEST_METADATA_VALUE );
162 public TestMetadataFacet createMetadataFacet( String repositoryId, String name )
164 return new TestMetadataFacet( TEST_FACET_ID, TEST_METADATA_VALUE, name );
168 public Class<TestMetadataFacet> getFacetClass( )
170 return TestMetadataFacet.class;
174 public String getFacetId( )
176 return TEST_FACET_ID;
180 // for the getArtifactsByProjectVersionFacet tests
181 factories.add( new GenericMetadataFacetFactory( ) );
188 public void testRootNamespaceWithNoMetadataRepository( )
191 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
194 Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
195 assertThat( namespaces ).isNotNull( ).isEmpty( );
201 public void testGetNamespaceOnly( )
204 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
207 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
209 getRepository( ).updateNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
212 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isNotEmpty( ).contains(
213 TEST_NAMESPACE ).hasSize( 1 );
215 getRepository( ).removeNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
218 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
224 public void testGetProjectOnly( )
227 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
231 assertNull( getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
232 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
235 ProjectMetadata project = new ProjectMetadata( );
236 project.setId( TEST_PROJECT );
237 project.setNamespace( TEST_NAMESPACE );
239 getRepository( ).updateProject( session, TEST_REPO_ID, project );
242 ProjectMetadata proj = getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
243 assertEquals( TEST_PROJECT, proj.getId( ) );
244 assertEquals( TEST_NAMESPACE, proj.getNamespace( ) );
247 // test that namespace is also constructed
251 Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
253 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).contains( TEST_NAMESPACE ).hasSize( 1 );
259 public void testGetProjectVersionOnly( )
262 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
266 assertNull( getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
267 assertNull( getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
268 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
271 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
272 metadata.setId( TEST_PROJECT_VERSION );
274 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
276 metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
277 assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
281 // test that namespace and project is also constructed
282 Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
284 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_NAMESPACE );
290 ProjectMetadata projectMetadata = getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
291 assertNotNull( projectMetadata );
292 assertEquals( TEST_PROJECT, projectMetadata.getId( ) );
293 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace( ) );
299 public void testGetArtifactOnly( )
302 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
306 assertThat( new ArrayList<>(
307 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
308 TEST_PROJECT, TEST_PROJECT_VERSION ) ) ).isNotNull( ).isEmpty( );
310 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull( );
311 assertThat( getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) ).isNull( );
313 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
317 ArtifactMetadata metadata = createArtifact( );
319 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
322 Collection<ArtifactMetadata> artifacts =
323 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
324 //assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
325 assertThat( artifacts ).containsExactly( metadata );
326 // test that namespace, project and project version is also constructed
328 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isNotEmpty( ).contains(
329 TEST_NAMESPACE ).hasSize( 1 );
331 ProjectMetadata projectMetadata = getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
332 assertEquals( TEST_PROJECT, projectMetadata.getId( ) );
333 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace( ) );
335 ProjectVersionMetadata projectVersionMetadata =
336 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
337 assertEquals( TEST_PROJECT_VERSION, projectVersionMetadata.getId( ) );
343 public void testUpdateProjectVersionMetadataWithNoOtherArchives( )
346 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
349 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
350 metadata.setId( TEST_PROJECT_VERSION );
351 MailingList mailingList = new MailingList( );
352 mailingList.setName( "Foo List" );
353 mailingList.setOtherArchives( Collections.<String>emptyList( ) );
354 metadata.setMailingLists( Arrays.asList( mailingList ) );
355 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
357 metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
358 assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
360 List<MailingList> mailingLists = metadata.getMailingLists( );
362 assertThat( mailingLists ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
364 mailingList = metadata.getMailingLists( ).get( 0 );
365 assertEquals( "Foo List", mailingList.getName( ) );
367 List<String> others = mailingList.getOtherArchives( );
368 assertThat( others ).isNotNull( ).isEmpty( );
373 public void testUpdateProjectVersionMetadataWithAllElements( )
377 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
380 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
381 metadata.setId( TEST_PROJECT_VERSION );
383 metadata.setName( "project name" );
384 metadata.setDescription( "project description" );
385 metadata.setUrl( "the url" );
387 MailingList mailingList = new MailingList( );
388 mailingList.setName( "Foo List" );
389 mailingList.setUnsubscribeAddress( "UnsubscribeAddress" );
390 mailingList.setSubscribeAddress( "SubscribeAddress" );
391 mailingList.setPostAddress( "PostAddress" );
392 mailingList.setMainArchiveUrl( "MainArchiveUrl" );
393 mailingList.setOtherArchives( Arrays.asList( "other archive" ) );
394 metadata.setMailingLists( Arrays.asList( mailingList ) );
396 Scm scm = new Scm( );
397 scm.setConnection( "connection" );
398 scm.setDeveloperConnection( "dev conn" );
400 metadata.setScm( scm );
402 CiManagement ci = new CiManagement( );
403 ci.setSystem( "system" );
404 ci.setUrl( "ci url" );
405 metadata.setCiManagement( ci );
407 IssueManagement tracker = new IssueManagement( );
408 tracker.setSystem( "system" );
409 tracker.setUrl( "issue tracker url" );
410 metadata.setIssueManagement( tracker );
412 metadata.setOrganization( TEST_ORGANIZATION );
414 License l = new License( );
415 l.setName( "license name" );
416 l.setUrl( "license url" );
417 metadata.addLicense( l );
419 Dependency d = new Dependency( );
420 d.setArtifactId( "artifactId" );
421 d.setClassifier( "classifier" );
422 d.setNamespace( "groupId" );
423 d.setScope( "scope" );
424 d.setSystemPath( "system path" );
426 d.setVersion( "version" );
427 d.setOptional( true );
428 metadata.addDependency( d );
430 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
432 metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
433 assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
434 assertEquals( TEST_PROJECT_VERSION, metadata.getVersion( ) );
435 assertEquals( "project name", metadata.getName( ) );
436 assertEquals( "project description", metadata.getDescription( ) );
437 assertEquals( "the url", metadata.getUrl( ) );
439 assertEquals( "connection", metadata.getScm( ).getConnection( ) );
440 assertEquals( "dev conn", metadata.getScm( ).getDeveloperConnection( ) );
441 assertEquals( "url", metadata.getScm( ).getUrl( ) );
443 assertEquals( "system", metadata.getCiManagement( ).getSystem( ) );
444 assertEquals( "ci url", metadata.getCiManagement( ).getUrl( ) );
446 assertEquals( "system", metadata.getIssueManagement( ).getSystem( ) );
447 assertEquals( "issue tracker url", metadata.getIssueManagement( ).getUrl( ) );
449 assertEquals( TEST_ORGANIZATION.getName( ), metadata.getOrganization( ).getName( ) );
450 assertEquals( TEST_ORGANIZATION.getUrl( ), metadata.getOrganization( ).getUrl( ) );
452 assertEquals( 1, metadata.getMailingLists( ).size( ) );
453 MailingList retrievedMailingList = metadata.getMailingLists( ).get( 0 );
454 assertEquals( mailingList.getName( ), retrievedMailingList.getName( ) );
455 assertEquals( mailingList.getMainArchiveUrl( ), retrievedMailingList.getMainArchiveUrl( ) );
456 assertEquals( mailingList.getPostAddress( ), retrievedMailingList.getPostAddress( ) );
457 assertEquals( mailingList.getSubscribeAddress( ), retrievedMailingList.getSubscribeAddress( ) );
458 assertEquals( mailingList.getUnsubscribeAddress( ), retrievedMailingList.getUnsubscribeAddress( ) );
459 assertThat( retrievedMailingList.getOtherArchives( ) ) //
463 .contains( "other archive" );
465 assertEquals( 1, metadata.getLicenses( ).size( ) );
466 l = metadata.getLicenses( ).get( 0 );
467 assertEquals( "license name", l.getName( ) );
468 assertEquals( "license url", l.getUrl( ) );
470 assertEquals( 1, metadata.getDependencies( ).size( ) );
471 d = metadata.getDependencies( ).get( 0 );
472 assertEquals( "artifactId", d.getArtifactId( ) );
473 assertEquals( "classifier", d.getClassifier( ) );
474 assertEquals( "groupId", d.getNamespace( ) );
475 assertEquals( "scope", d.getScope( ) );
476 assertEquals( "system path", d.getSystemPath( ) );
477 assertEquals( "type", d.getType( ) );
478 assertEquals( "version", d.getVersion( ) );
479 assertTrue( d.isOptional( ) );
484 public void testUpdateProjectVersionMetadataIncomplete( )
487 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
490 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
491 metadata.setId( TEST_PROJECT_VERSION );
492 metadata.setIncomplete( true );
493 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
496 ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
497 assertEquals( true, metadata1.isIncomplete( ) );
498 assertNull( metadata1.getCiManagement( ) );
499 assertNull( metadata1.getScm( ) );
500 assertNull( metadata1.getIssueManagement( ) );
501 assertNull( metadata1.getOrganization( ) );
502 assertTrue( metadata1.getDescription( )==null || "".equals(metadata1.getDescription()) );
503 assertTrue( metadata1.getName( )==null || "".equals(metadata1.getName()) );
504 assertEquals( TEST_PROJECT_VERSION, metadata1.getId( ) );
505 assertEquals( TEST_PROJECT_VERSION, metadata1.getVersion( ) );
506 assertTrue( metadata1.getMailingLists( ).isEmpty( ) );
507 assertTrue( metadata1.getLicenses( ).isEmpty( ) );
508 assertTrue( metadata1.getDependencies( ).isEmpty( ) );
514 public void testUpdateProjectVersionMetadataWithExistingFacets( )
517 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
520 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
521 metadata.setId( TEST_PROJECT_VERSION );
522 MetadataFacet facet = new TestMetadataFacet( "baz" );
523 metadata.addFacet( facet );
524 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
528 ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
529 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata1.getFacetIds( ) );
532 metadata = new ProjectVersionMetadata( );
533 metadata.setId( TEST_PROJECT_VERSION );
534 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
538 ProjectVersionMetadata metadata2 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
539 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata2.getFacetIds( ) );
540 TestMetadataFacet testFacet = (TestMetadataFacet) metadata2.getFacet( TEST_FACET_ID );
541 assertEquals( "baz", testFacet.getValue( ) );
547 public void testUpdateProjectVersionMetadataWithNoExistingFacets( )
550 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
553 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
554 metadata.setId( TEST_PROJECT_VERSION );
555 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
559 ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
561 assertThat( metadata1.getFacetIds( ) ).isNotNull( ).isEmpty( );
564 ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
565 metadata = new ProjectVersionMetadata( );
566 metadata.setId( TEST_PROJECT_VERSION );
567 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
570 ProjectVersionMetadata metadata2 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
571 assertThat( metadata2.getFacetIds( ) ).isNotNull( ).isEmpty( );
577 public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved( )
580 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
583 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
584 metadata.setId( TEST_PROJECT_VERSION );
586 Map<String, String> additionalProps = new HashMap<>( );
587 additionalProps.put( "deleteKey", "deleteValue" );
589 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
590 metadata.addFacet( facet );
591 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
596 ProjectVersionMetadata metad = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
598 assertThat( metad.getFacetIds( ) ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
603 ProjectVersionMetadata metad = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
604 TestMetadataFacet testFacet = (TestMetadataFacet) metad.getFacet( TEST_FACET_ID );
605 Map<String, String> facetProperties = testFacet.toProperties( );
607 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
609 facetProperties.remove( "deleteKey" );
611 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue( ), facetProperties );
612 metadata.addFacet( newTestFacet );
614 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
618 ProjectVersionMetadata metad2 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
620 assertThat( metad2.getFacetIds( ) ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
621 TestMetadataFacet testFacet2 = (TestMetadataFacet) metad2.getFacet( TEST_FACET_ID );
622 assertFalse( testFacet2.toProperties( ).containsKey( "deleteKey" ) );
628 public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets( )
631 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
634 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata( );
635 versionMetadata.setId( TEST_PROJECT_VERSION );
637 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz" );
638 versionMetadata.addFacet( facet );
639 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata );
640 ArtifactMetadata artifactMetadata = createArtifact( );
641 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata );
647 Collection<ArtifactMetadata> artifacts =
648 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
649 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
651 artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID );
652 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
654 artifacts = getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 );
655 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
657 artifacts = getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 );
658 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
660 artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
661 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
667 public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved( )
670 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
673 ArtifactMetadata metadata = createArtifact( );
675 Map<String, String> additionalProps = new HashMap<>( );
676 additionalProps.put( "deleteKey", "deleteValue" );
678 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
679 metadata.addFacet( facet );
680 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
683 Collection<ArtifactMetadata> artifacts =
684 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
686 assertThat( artifacts ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
689 Collection<ArtifactMetadata> artifacts =
690 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
691 metadata = artifacts.iterator( ).next( );
693 Collection<String> ids = metadata.getFacetIds( );
694 assertThat( ids ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
696 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
697 Map<String, String> facetProperties = testFacet.toProperties( );
699 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
701 facetProperties.remove( "deleteKey" );
703 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue( ), facetProperties );
704 metadata.addFacet( newTestFacet );
706 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
710 Collection<ArtifactMetadata> artifacts1 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
712 assertThat( artifacts1 ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
714 Collection<ArtifactMetadata> artifacts1 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
715 metadata = artifacts.iterator( ).next( );
717 ids = metadata.getFacetIds( );
718 assertThat( ids ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
720 testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
722 Map<String, String> props = testFacet.toProperties( );
723 assertThat( props ).isNotNull( ).doesNotContainKey( "deleteKey" );
728 public void testUpdateArtifactMetadataWithExistingFacets( )
731 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
734 ArtifactMetadata metadata = createArtifact( );
735 MetadataFacet facet = new TestMetadataFacet( "baz" );
736 metadata.addFacet( facet );
737 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
739 metadata = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
740 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
741 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds( ) );
743 metadata = createArtifact( );
744 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
746 metadata = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
747 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
748 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds( ) );
749 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
750 assertEquals( "baz", testFacet.getValue( ) );
755 public void testUpdateArtifactMetadataWithNoExistingFacets( )
758 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
760 ArtifactMetadata metadata = createArtifact( );
761 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
765 ArtifactMetadata metadata2 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
766 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
767 assertEquals( Collections.<String>emptyList( ), new ArrayList<String>( metadata2.getFacetIds( ) ) );
771 metadata = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
772 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
773 metadata = createArtifact( );
774 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
778 ArtifactMetadata metadata3 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
779 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
780 assertEquals( Collections.<String>emptyList( ), new ArrayList<String>( metadata3.getFacetIds( ) ) );
786 public void testGetMetadataFacet( )
789 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
791 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
793 TestMetadataFacet test =
794 (TestMetadataFacet) getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
796 assertEquals( new TestMetadataFacet( TEST_VALUE ), test );
802 public void testGetMetadataFacetByClass( )
805 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
807 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
809 TestMetadataFacet test =
810 (TestMetadataFacet) getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TestMetadataFacet.class, TEST_NAME );
812 assertEquals( new TestMetadataFacet( TEST_VALUE ), test );
818 public void testGetMetadataFacetWhenEmpty( )
821 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
823 tryAssert( ( ) -> assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ) );
828 public void testGetMetadataFacetWhenUnknownName( )
831 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
833 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
835 tryAssert( ( ) -> assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) ) );
840 public void testGetMetadataFacetWhenDefaultValue( )
843 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
845 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( null ) );
848 MetadataFacet metadataFacet = getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
850 assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ), metadataFacet );
857 public void testGetMetadataFacetWhenUnknownFacetId( )
860 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
862 assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
868 public void testGetMetadataFacets( )
871 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
873 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
875 assertEquals( Collections.singletonList( TEST_NAME ),
876 getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID ) );
882 public void testGetMetadataFacetsStream( )
885 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
887 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
890 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
893 Stream<TestMetadataFacet> str = getRepository( ).getMetadataFacetStream( session, TEST_REPO_ID, TestMetadataFacet.class );
894 assertNotNull( str );
895 List<TestMetadataFacet> result = str.collect( Collectors.toList( ) );
896 assertEquals( 1, result.size( ) );
897 assertNotNull( result.get( 0 ) );
898 assertEquals( TEST_NAME, result.get( 0 ).getName( ) );
905 public void testGetMetadataFacetsStreamWithLimit( )
908 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
910 for (int i = 0; i<500; i++)
912 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_FACET_ID, TEST_VALUE, TEST_NAME+"/"+String.format("%03d",i) ) );
916 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
918 session.refreshAndDiscard();
920 Stream<TestMetadataFacet> str = getRepository( ).getMetadataFacetStream( session, TEST_REPO_ID, TestMetadataFacet.class, new QueryParameter(0, 100));
921 assertNotNull( str );
922 List<TestMetadataFacet> result = str.collect( Collectors.toList( ) );
923 assertEquals( 100, result.size( ) );
924 assertNotNull( result.get( 0 ) );
925 for (int i=0; i<10; i++) {
926 assertEquals(TEST_NAME + "/" + String.format("%03d",i), result.get(i).getName());
934 public void testGetMetadataFacetsStreamWithOffset( )
937 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
939 for (int i = 0; i<100; i++)
941 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_FACET_ID, TEST_VALUE, TEST_NAME+"/"+String.format("%03d", i) ) );
945 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
947 session.refreshAndDiscard();
949 Stream<TestMetadataFacet> str = getRepository( ).getMetadataFacetStream( session, TEST_REPO_ID, TestMetadataFacet.class, new QueryParameter(5, 10));
950 assertNotNull( str );
951 List<TestMetadataFacet> result = str.collect( Collectors.toList( ) );
952 assertEquals( 10, result.size( ) );
953 assertNotNull( result.get( 0 ) );
954 for (int i=0; i<10; i++) {
955 assertEquals(TEST_NAME + "/" + String.format("%03d",i+5), result.get(i).getName());
963 public void testGetArtifactsByDateRangeStreamLowerAndUpperBound( )
966 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
968 final ArtifactMetadata artifact1 = createArtifact( );
969 artifact1.setWhenGathered(ZonedDateTime.now().minusDays(1));
970 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
972 ZonedDateTime gatheredNow = ZonedDateTime.now();
973 final ArtifactMetadata artifact2 = createArtifact( );
974 String artifact2Id = artifact2.getId() + "-2";
975 artifact2.setId(artifact2Id);
976 artifact2.setVersion(TEST_PROJECT_VERSION+"-2");
977 artifact2.setWhenGathered(gatheredNow);
978 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
979 final ArtifactMetadata artifact3 = createArtifact();
980 String artifact3Id = artifact3.getId() + "-3";
981 artifact3.setId(artifact3Id);
982 artifact3.setVersion(TEST_PROJECT_VERSION+"-3");
983 artifact3.setWhenGathered(gatheredNow.minusSeconds(5));
985 final ArtifactMetadata artifact4 = createArtifact();
986 artifact4.setId(artifact4.getId()+"-4");
987 artifact4.setVersion(TEST_PROJECT_VERSION+"-4");
988 artifact4.setWhenGathered(gatheredNow.plusDays(1));
990 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact3 );
993 ZonedDateTime lower = artifact2.getWhenGathered().minusSeconds(10);
994 ZonedDateTime upper = artifact2.getWhenGathered().plusSeconds(10);
997 Stream<ArtifactMetadata> stream = getRepository().getArtifactByDateRangeStream(session, TEST_REPO_ID, lower, upper, new QueryParameter());
998 assertNotNull(stream);
1000 List<ArtifactMetadata> artifacts = stream.collect(Collectors.toList());
1001 assertEquals(2, artifacts.size());
1002 assertEquals(artifact3Id, artifacts.get(0).getId());
1003 assertEquals(artifact2Id, artifacts.get(1).getId());
1010 public void testGetMetadataFacetsWhenEmpty( )
1014 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1018 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1019 assertTrue( facets.isEmpty( ) );
1025 public void testRemoveFacets( )
1028 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1030 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
1032 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1033 assertFalse( facets.isEmpty( ) );
1035 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1037 facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1038 assertTrue( facets.isEmpty( ) );
1044 public void testRemoveFacetsWhenEmpty( )
1047 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1049 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1050 assertTrue( facets.isEmpty( ) );
1052 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1055 List<String> facets1 = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1056 assertTrue( facets1.isEmpty( ) );
1062 public void testRemoveFacetsWhenUnknown( )
1065 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1067 // testing no exception
1068 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, UNKNOWN );
1074 public void testRemoveFacetWhenUnknown( )
1077 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1079 // testing no exception
1080 getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, UNKNOWN, TEST_NAME );
1086 public void testRemoveFacet( )
1089 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1091 TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
1092 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, metadataFacet );
1094 assertEquals( metadataFacet, getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
1095 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1096 assertFalse( facets.isEmpty( ) );
1098 getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
1100 assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
1101 facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1102 assertTrue( facets.isEmpty( ) );
1108 public void testRemoveFacetWhenEmpty( )
1111 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1115 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1116 assertThat( facets ).isNotNull( ).isEmpty( );
1117 assertThat( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull( );
1120 getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
1124 List<String> facets2 = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1125 assertThat( facets2 ).isNotNull( ).isEmpty( );
1126 assertThat( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull( );
1133 public void hasMetadataFacetStart( )
1136 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1138 assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1145 public void hasMetadataFacet( )
1149 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1151 assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1153 Calendar cal = Calendar.getInstance( );
1155 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "first", cal.getTime( ) ) );
1157 assertTrue( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1159 cal.add( Calendar.MINUTE, 2 );
1161 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "second", cal.getTime( ) ) );
1163 cal.add( Calendar.MINUTE, 2 );
1165 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "third", cal.getTime( ) ) );
1167 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
1169 assertThat( facets ).isNotNull( ).isNotEmpty( ).hasSize( 3 );
1171 assertTrue( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1173 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
1175 assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1177 facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
1179 assertThat( facets ).isNotNull( ).isEmpty( );
1187 public void testGetArtifacts( )
1190 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1192 ArtifactMetadata artifact1 = createArtifact( );
1193 ArtifactMetadata artifact2 = createArtifact( "pom" );
1194 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1195 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1198 Collection<ArtifactMetadata> artifacts =
1199 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1200 ArrayList<ArtifactMetadata> actual = new ArrayList<>( artifacts );
1201 Collections.sort( actual, ( o1, o2 ) -> o1.getId( ).compareTo( o2.getId( ) ) );
1202 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
1209 public void testGetArtifactStream( )
1212 ArtifactMetadata artifact1 = createArtifact( );
1213 ArtifactMetadata artifact2 = createArtifact( "pom" );
1214 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1217 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1218 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1220 try ( RepositorySession session = getSessionFactory( ).createSession( ) ) {
1222 Stream<ArtifactMetadata> artifacts =
1223 getRepository( ).getArtifactStream( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1224 assertNotNull( artifacts );
1225 List<ArtifactMetadata> actual = artifacts
1226 .sorted( ( o1, o2 ) -> o1.getId( ).compareTo( o2.getId( ) ) ).collect( Collectors.toList( ) );
1227 assertEquals( 2, actual.size( ) );
1228 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
1235 public void testGetArtifactVersions( )
1238 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1240 ArtifactMetadata artifact1 = createArtifact( );
1241 String version1 = "1.0-20091212.012345-1";
1242 artifact1.setId( artifact1.getProject( ) + "-" + version1 + ".jar" );
1243 artifact1.setVersion( version1 );
1244 ArtifactMetadata artifact2 = createArtifact( );
1245 String version2 = "1.0-20091212.123456-2";
1246 artifact2.setId( artifact2.getProject( ) + "-" + version2 + ".jar" );
1247 artifact2.setVersion( version2 );
1248 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1249 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1252 Collection<String> versions =
1253 getRepository( ).getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1255 assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( version1, version2 );
1262 public void testGetArtifactVersionsMultipleArtifactsSingleVersion( )
1265 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1267 ArtifactMetadata artifact1 = createArtifact( );
1268 artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1269 ArtifactMetadata artifact2 = createArtifact( );
1270 artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
1271 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1272 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1275 Collection<String> versions =
1276 getRepository( ).getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1278 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).containsExactly( TEST_PROJECT_VERSION );
1286 public void testGetArtifactsByDateRangeOpen( )
1289 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1291 ArtifactMetadata artifact = createArtifact( );
1292 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1296 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
1298 assertEquals( Collections.singletonList( artifact ), artifacts );
1304 public void testGetArtifactsByDateRangeSparseNamespace( )
1307 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1309 String namespace = "org.apache.archiva";
1310 ArtifactMetadata artifact = createArtifact( );
1311 artifact.setNamespace( namespace );
1312 getRepository( ).updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1316 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
1318 tryAssert( ( ) -> assertEquals( Collections.singletonList( artifact ), artifacts ) );
1324 public void testGetArtifactsByDateRangeLowerBound( )
1327 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1329 ArtifactMetadata artifact = createArtifact( );
1330 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1333 ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
1336 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
1338 assertEquals( Collections.singletonList( artifact ), artifacts );
1344 public void testGetArtifactsByDateRangeLowerBoundOutOfRange( )
1347 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1349 ArtifactMetadata artifact = createArtifact( );
1350 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1352 ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);
1355 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
1357 assertThat( artifacts ).isNotNull( ).isEmpty( );
1363 public void testGetArtifactsByDateRangeLowerAndUpperBound( )
1366 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1368 ArtifactMetadata artifact = createArtifact( );
1369 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1372 ZonedDateTime lower = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
1373 ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);
1376 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, lower, upper );
1378 assertEquals( Collections.singletonList( artifact ), artifacts );
1384 public void testGetArtifactsByDateRangeUpperBound( )
1387 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1389 ArtifactMetadata artifact = createArtifact( );
1390 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1393 ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);
1396 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
1398 assertEquals( Collections.singletonList( artifact ), artifacts );
1404 public void testGetArtifactsByDateRangeUpperBoundOutOfRange( )
1407 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1409 ArtifactMetadata artifact = createArtifact( );
1410 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1413 ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
1416 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
1418 assertThat( artifacts ).isNotNull( ).isEmpty( );
1424 public void testGetArtifactsByRepoId( )
1427 ArtifactMetadata artifact;
1428 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1430 artifact = createArtifact( );
1431 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1434 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1437 session.refreshAndDiscard( );
1438 List<ArtifactMetadata> artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID );
1439 assertEquals( Collections.singletonList( artifact ), artifacts );
1446 public void testGetArtifactsByRepoIdMultipleCopies( )
1449 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1451 ArtifactMetadata artifact = createArtifact( );
1452 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1454 ArtifactMetadata secondArtifact = createArtifact( );
1455 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1456 getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1459 // test it restricts to the appropriate repository
1461 List<ArtifactMetadata> artifact1 = getRepository( ).getArtifacts( session, TEST_REPO_ID );
1462 assertEquals( Collections.singletonList( artifact ), artifact1 );
1463 assertEquals( Collections.singletonList( secondArtifact ), getRepository( ).getArtifacts( session, OTHER_REPO_ID ) );
1471 public void testGetArtifactsByDateRangeMultipleCopies( )
1474 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1476 ArtifactMetadata artifact = createArtifact( );
1477 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1479 ArtifactMetadata secondArtifact = createArtifact( );
1480 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1481 getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1485 // test it restricts to the appropriate repository
1486 assertEquals( Collections.singletonList( artifact ),
1487 getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null ) );
1490 assertEquals( Collections.singletonList( secondArtifact ),
1491 getRepository( ).getArtifactsByDateRange( session, OTHER_REPO_ID, null, null ) );
1497 public void testGetArtifactsByChecksumMultipleCopies( )
1500 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1502 ArtifactMetadata artifact = createArtifact( );
1503 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1505 ArtifactMetadata secondArtifact = createArtifact( );
1506 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1507 getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1511 // test it restricts to the appropriate repository
1512 assertEquals( Collections.singletonList( artifact ),
1513 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
1516 assertEquals( Collections.singletonList( secondArtifact ), new ArrayList<>(
1517 getRepository( ).getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_SHA1 ) ) );
1520 assertEquals( Collections.singletonList( artifact ),
1521 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
1524 assertEquals( Collections.singletonList( secondArtifact ),
1525 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_MD5 ) ) );
1532 public void testGetNamespacesWithSparseDepth( )
1535 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1537 getRepository( ).updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared" );
1541 Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
1543 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "org" );
1545 namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, "org" );
1546 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "apache" );
1548 namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, "org.apache" );
1549 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "maven" );
1551 namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, "org.apache.maven" );
1552 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "shared" );
1559 public void testGetNamespacesWithProjectsPresent( )
1562 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1564 String namespace = "org.apache.maven.shared";
1565 getRepository( ).updateNamespace( session, TEST_REPO_ID, namespace );
1567 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
1568 metadata.setId( TEST_PROJECT_VERSION );
1569 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, namespace, TEST_PROJECT, metadata );
1571 Collection<String> namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, namespace );
1573 assertThat( namespaces ).isNotNull( ).isEmpty( );
1580 public void testGetProjectsWithOtherNamespacesPresent( )
1583 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1585 ProjectMetadata projectMetadata = new ProjectMetadata( );
1586 projectMetadata.setId( TEST_PROJECT );
1587 projectMetadata.setNamespace( "org.apache.maven" );
1588 getRepository( ).updateProject( session, TEST_REPO_ID, projectMetadata );
1590 getRepository( ).updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared" );
1592 Collection<String> projects = getRepository( ).getProjects( session, TEST_REPO_ID, "org.apache.maven" );
1594 assertThat( projects ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_PROJECT );
1600 public void testGetProjectVersionsWithOtherNamespacesPresent( )
1603 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1605 // an unusual case but technically possible where a project namespace matches another project's name
1607 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata( );
1608 versionMetadata.setId( TEST_PROJECT_VERSION );
1609 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT, versionMetadata );
1611 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT,
1612 "other-project", versionMetadata );
1614 Collection<String> versions =
1615 getRepository( ).getProjectVersions( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT, "other-project" );
1616 assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( TEST_PROJECT_VERSION );
1618 versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT );
1620 assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( TEST_PROJECT_VERSION );
1626 public void testGetArtifactsByChecksumSingleResultSha256( )
1629 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1631 ArtifactMetadata artifact = createArtifact( );
1632 artifact.setChecksum( ChecksumAlgorithm.SHA256, TEST_SHA256);
1633 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1637 assertEquals( Collections.singletonList( artifact ),
1638 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA256 ) ))
1645 public void testGetArtifactsByChecksumSingleResultMd5( )
1648 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1650 ArtifactMetadata artifact = createArtifact( );
1651 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1654 assertEquals( Collections.singletonList( artifact ),
1655 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
1661 public void testGetArtifactsByChecksumSingleResultSha1( )
1664 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1666 ArtifactMetadata artifact = createArtifact( );
1667 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1670 assertEquals( Collections.singletonList( artifact ),
1671 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
1677 public void testGetArtifactsByChecksumDeepNamespace( )
1680 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1682 ArtifactMetadata artifact = createArtifact( );
1683 String namespace = "multi.level.ns";
1684 artifact.setNamespace( namespace );
1685 getRepository( ).updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1690 assertEquals( Collections.singletonList( artifact ),
1691 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
1692 assertEquals( Collections.singletonList( artifact ),
1693 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
1700 public void testGetArtifactsByChecksumMultipleResult( )
1704 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1706 ArtifactMetadata artifact1 = createArtifact( );
1707 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1709 String newProjectId = "another-project";
1710 ArtifactMetadata artifact2 = createArtifact( );
1711 artifact2.setProject( newProjectId );
1712 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
1716 List<ArtifactMetadata> artifacts =
1717 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) );
1718 Collections.sort( artifacts, new ArtifactMetadataComparator( ) );
1719 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1723 ArrayList<ArtifactMetadata> artifacts = new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) );
1724 Collections.sort( artifacts, new ArtifactMetadataComparator( ) );
1725 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1731 public void testGetArtifactsByChecksumNoResult( )
1734 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1736 ArtifactMetadata artifact = createArtifact( );
1737 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1740 Collection<ArtifactMetadata> artifactsByChecksum =
1741 getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, "not checksum" );
1743 assertThat( artifactsByChecksum ).isNotNull( ).isEmpty( );
1750 public void testGetArtifactsByProjectVersionMetadata( )
1753 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1755 createArtifactWithGenericMetadataFacet( session, 10 );
1758 Collection<ArtifactMetadata> artifactsByMetadata =
1759 getRepository( ).getArtifactsByProjectVersionFacet( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, TEST_REPO_ID );
1761 assertThat( artifactsByMetadata ).hasSize( 1 );
1762 ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator( ).next( );
1763 assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1764 assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
1765 assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
1771 public void testGetArtifactsByProjectVersionMetadataNoRepository( )
1774 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1776 createArtifactWithGenericMetadataFacet( session );
1779 Collection<ArtifactMetadata> artifactsByMetadata =
1780 getRepository( ).getArtifactsByProjectVersionFacet( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
1781 assertThat( artifactsByMetadata ).hasSize( 1 );
1782 assertThat( artifactsByMetadata.iterator( ).next( ).getRepositoryId( ) ).isNotNull( ).isNotEmpty( );
1788 public void testGetArtifactsByProjectVersionMetadataAllRepositories( )
1791 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1793 createArtifactWithGenericMetadataFacet( session );
1796 Collection<ArtifactMetadata> artifactsByMetadata =
1797 getRepository( ).getArtifactsByProjectVersionFacet( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
1798 assertThat( artifactsByMetadata ).hasSize( 1 );
1804 public void testGetArtifactsByMetadataAllRepositories( )
1807 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1809 createArtifactWithMavenArtifactFacet( session );
1811 Collection<ArtifactMetadata> artifactsByMetadata =
1812 getRepository( ).getArtifactsByAttribute( session, "foo", TEST_METADATA_VALUE, null );
1813 assertThat( artifactsByMetadata ).hasSize( 1 );
1814 ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator( ).next( );
1815 assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1816 assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
1817 assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
1818 MetadataFacet facet = artifactMetadata.getFacet( TEST_FACET_ID );
1819 assertThat( facet ).isNotNull( );
1820 assertThat( facet.toProperties( ).get("foo").equals(TEST_METADATA_VALUE) );
1826 public void testGetArtifactsByPropertySingleResult( )
1829 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1831 createArtifactWithData( session );
1832 // only works on JCR implementation
1833 // Collection<ArtifactMetadata> artifactsByProperty = getRepository().getArtifactsByProjectVersionAttribute( "org.name", TEST_ORGANIZATION.getName(), TEST_REPO_ID );
1836 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).getArtifactsByProjectVersionAttribute( session, "url", TEST_URL, TEST_REPO_ID );
1837 assertThat( artifactsByProperty ).hasSize( 1 );
1838 ArtifactMetadata artifactMetadata = artifactsByProperty.iterator( ).next( );
1839 assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1840 assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
1841 assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
1848 public void testDeleteRepository( )
1851 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1854 getRepository( ).updateNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
1856 ProjectMetadata project1 = new ProjectMetadata( );
1857 project1.setNamespace( TEST_NAMESPACE );
1858 project1.setId( "project1" );
1859 getRepository( ).updateProject( session, TEST_REPO_ID, project1 );
1860 ProjectMetadata project2 = new ProjectMetadata( );
1861 project2.setNamespace( TEST_NAMESPACE );
1862 project2.setId( "project2" );
1863 getRepository( ).updateProject( session, TEST_REPO_ID, project2 );
1865 ArtifactMetadata artifact1 = createArtifact( );
1866 artifact1.setProject( "project1" );
1867 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
1868 ArtifactMetadata artifact2 = createArtifact( );
1869 artifact2.setProject( "project2" );
1870 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
1873 List<ArtifactMetadata> expected = Arrays.asList( artifact1, artifact2 );
1874 Collections.sort( expected, new ArtifactMetadataComparator( ) );
1878 List<ArtifactMetadata> actual =
1879 new ArrayList<>( getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null ) );
1880 Collections.sort( actual, new ArtifactMetadataComparator( ) );
1881 assertEquals( expected, actual );
1884 getRepository( ).removeRepository( session, TEST_REPO_ID );
1887 assertTrue( getRepository( ).getArtifacts( session, TEST_REPO_ID ).isEmpty( ) );
1888 assertTrue( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ).isEmpty( ) );
1895 public void testDeleteArtifact( )
1898 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1901 ArtifactMetadata artifact = createArtifact( );
1902 artifact.addFacet( new TestMetadataFacet( "value" ) );
1904 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1906 assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
1907 TEST_PROJECT, TEST_PROJECT_VERSION ) ).containsExactly( artifact );
1909 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact );
1911 Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1913 log.info( "versions {}", versions );
1915 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 2 ).contains( "1.0", "2.0" );
1917 getRepository( ).removeArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId( ) );
1919 versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1921 log.info( "versions {}", versions );
1923 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "2.0" );
1925 assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
1926 TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNotNull( ).isEmpty( );
1928 assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
1929 TEST_PROJECT, TEST_PROJECT_VERSION_2_0 ) ).isNotEmpty( ).hasSize( 1 );
1934 public void deleteArtifact( )
1937 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1939 ArtifactMetadata artifact = createArtifact( );
1940 artifact.addFacet( new TestMetadataFacet( "value" ) );
1942 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1944 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1947 Collection<ArtifactMetadata> artifacts =
1948 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1950 assertEquals( Collections.singletonList( artifact ), new ArrayList<>( artifacts ) );
1954 getRepository( ).removeArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId( ) );
1957 Collection<ArtifactMetadata> artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1959 assertThat( artifacts ).isNotNull( ).isEmpty( );
1966 public void deleteVersion( )
1969 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1971 ArtifactMetadata artifact = createArtifact( );
1972 artifact.addFacet( new TestMetadataFacet( "value" ) );
1974 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1976 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1980 Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1982 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
1985 getRepository( ).removeProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1989 Collection<String> versions1 = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1991 assertThat( versions1 ).isNotNull( ).isEmpty( );
1997 public void deleteProject( )
2000 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2002 ArtifactMetadata artifact = createArtifact( );
2003 artifact.addFacet( new TestMetadataFacet( "value" ) );
2005 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2007 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2009 assertEquals( 1, getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ).size( ) );
2011 getRepository( ).removeProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
2013 Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
2015 assertThat( versions ).isNotNull( ).isEmpty( );
2022 public void deleteSnapshotVersion( )
2025 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2028 ArtifactMetadata artifactOne = createArtifact( );
2029 artifactOne.setVersion( "2.0-20120618.214127-1" );
2030 artifactOne.setProjectVersion( "2.0-SNAPSHOT" );
2031 artifactOne.addFacet( new TestMetadataFacet( "value" ) );
2032 artifactOne.setId( TEST_PROJECT + "-" + "2.0-20120618.214127-1" + "." + "jar" );
2034 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactOne );
2036 ArtifactMetadata artifactTwo = createArtifact( );
2037 artifactTwo.setVersion( "2.0-20120618.214135-2" );
2038 artifactTwo.setProjectVersion( "2.0-SNAPSHOT" );
2039 artifactTwo.addFacet( new TestMetadataFacet( "value" ) );
2040 artifactTwo.setId( TEST_PROJECT + "-" + "2.0-20120618.214135-2" + "." + "jar" );
2042 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactTwo );
2044 Collection<ArtifactMetadata> artifactMetadatas =
2045 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
2047 assertThat( artifactMetadatas ).isNotNull( ).isNotEmpty( ).hasSize( 2 );
2049 log.info( "artifactMetadatas: {}", artifactMetadatas );
2051 getRepository( ).removeTimestampedArtifact( session, artifactOne, "2.0-SNAPSHOT" );
2053 artifactMetadatas = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
2055 assertThat( artifactMetadatas ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
2057 getRepository( ).removeTimestampedArtifact( session, artifactTwo, "2.0-SNAPSHOT" );
2059 artifactMetadatas = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
2061 assertThat( artifactMetadatas ).isNotNull( ).isEmpty( );
2067 public void testgetProjectReferences( )
2070 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2073 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
2074 metadata.setId( TEST_PROJECT_VERSION );
2076 metadata.setName( "project name" );
2077 metadata.setDescription( "project description" );
2078 metadata.setUrl( "the url" );
2080 Dependency d = new Dependency( );
2081 d.setArtifactId( "artifactId" );
2082 d.setClassifier( "classifier" );
2083 d.setNamespace( "groupId" );
2084 d.setScope( "scope" );
2085 d.setSystemPath( "system path" );
2086 d.setType( "type" );
2087 d.setVersion( "version" );
2088 d.setOptional( true );
2089 metadata.addDependency( d );
2091 d = new Dependency( );
2092 d.setArtifactId( "artifactId1" );
2093 d.setClassifier( "classifier" );
2094 d.setNamespace( "groupId" );
2095 d.setScope( "scope" );
2096 d.setSystemPath( "system path" );
2097 d.setType( "type" );
2098 d.setVersion( "version1" );
2099 d.setOptional( true );
2100 metadata.addDependency( d );
2102 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
2106 metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
2107 final Dependency dd = d;
2112 Collection<ProjectVersionReference> references =
2113 getRepository( ).getProjectReferences( session, TEST_REPO_ID, dd.getNamespace( ), dd.getArtifactId( ), dd.getVersion( ) );
2114 log.info( "references: {}", references );
2115 assertThat( references ).isNotNull( ).hasSize( 1 ).contains(
2116 new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY, TEST_PROJECT, TEST_NAMESPACE,
2117 TEST_PROJECT_VERSION ));
2125 public void testSearchArtifactsByKey( )
2128 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2130 createArtifactWithData( session );
2133 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2135 session.refreshAndDiscard( );
2137 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, false );
2138 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2144 public void testSearchArtifactsByKeyExact( )
2147 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2149 createArtifactWithData( session );
2151 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2153 session.refreshAndDiscard( );
2155 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, true );
2156 assertThat( artifactsByProperty ).describedAs( "Artifact search by url=%s must give a result.", TEST_URL ).isNotNull( ).isNotEmpty( );
2157 artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "org.name", "pache", true );
2158 assertThat( artifactsByProperty ).describedAs( "Artifact search by text org.name='pache' must be empty" ).isNotNull( ).isEmpty( );
2164 public void testSearchArtifactsByFacetKey( )
2167 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2169 createArtifactWithGenericMetadataFacet( session );
2171 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_KEY, TEST_METADATA_VALUE, false );
2172 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2179 public void testSearchArtifactsByFacetKeyAllRepos( )
2182 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2185 createArtifactWithGenericMetadataFacet( session );
2187 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, null, TEST_METADATA_KEY, TEST_METADATA_VALUE, false );
2188 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2194 public void testSearchArtifactsFullText( )
2197 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2199 createArtifactWithGenericMetadataFacet( session );
2200 // only works in JCR
2201 // Collection<ArtifactMetadata> artifactsByProperty = getRepository().searchArtifacts( TEST_URL, TEST_REPO_ID, false );
2203 Collection<ArtifactMetadata> artifactsByProperty =
2204 getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false );
2205 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2212 public void testSearchArtifactsFullTextExact( )
2215 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2217 createArtifactWithGenericMetadataFacet( session );
2218 // only works in JCR
2219 // Collection<ArtifactMetadata> artifactsByProperty = getRepository().searchArtifacts( TEST_URL, TEST_REPO_ID, true );
2222 Collection<ArtifactMetadata> artifactsByProperty =
2223 getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, true );
2224 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2228 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE.substring( 2 ), true );
2229 assertThat( artifactsByProperty ).isNotNull( ).isEmpty( );
2235 public void testSearchArtifactsFullTextByFacet( )
2238 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2240 createArtifactWithGenericMetadataFacet( session );
2242 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false );
2243 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2249 private static ProjectMetadata createProject( )
2251 return createProject( TEST_NAMESPACE );
2254 private static ProjectMetadata createProject( String ns )
2256 ProjectMetadata project = new ProjectMetadata( );
2257 project.setId( TEST_PROJECT );
2258 project.setNamespace( ns );
2262 private void createArtifactWithGenericMetadataFacet( RepositorySession session )
2263 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2265 createArtifactWithGenericMetadataFacet( session, 1 );
2268 private void createArtifactWithGenericMetadataFacet( RepositorySession session, int artifacts )
2269 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2271 MetadataFacet metadataFacet = new GenericMetadataFacet( );
2272 Map<String, String> properties = new HashMap<>( );
2273 properties.put( TEST_METADATA_KEY, TEST_METADATA_VALUE );
2274 metadataFacet.fromProperties( properties );
2275 createArtifactWithFacet( session, artifacts, null, metadataFacet );
2278 private void createArtifactWithMavenArtifactFacet( RepositorySession session )
2279 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2281 createArtifactWithMavenArtifactFacet( session, 1 );
2284 private void createArtifactWithMavenArtifactFacet( RepositorySession session, int artifacts )
2285 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2287 TestMetadataFacet facet = new TestMetadataFacet( TEST_METADATA_VALUE );
2288 createArtifactWithFacet( session, artifacts, facet, null );
2291 private void createArtifactWithFacet( RepositorySession session, int artifacts, MetadataFacet artifactFacet,
2292 MetadataFacet projectVersionMetadataFacet )
2293 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2295 for ( int i = 0; i < artifacts; i++ )
2297 ArtifactMetadata artifact = createArtifact( );
2298 if ( artifactFacet != null )
2300 artifact.addFacet( artifactFacet );
2302 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2304 if ( projectVersionMetadataFacet != null )
2306 ProjectVersionMetadata metadata =
2307 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
2308 metadata.addFacet( projectVersionMetadataFacet );
2309 metadata.setOrganization( TEST_ORGANIZATION );
2310 metadata.setUrl( TEST_URL );
2311 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
2316 protected void createArtifactWithData( RepositorySession session )
2317 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2319 ArtifactMetadata artifact = createArtifact( );
2320 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2321 ProjectVersionMetadata metadata =
2322 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
2323 metadata.setOrganization( TEST_ORGANIZATION );
2324 metadata.setUrl( TEST_URL );
2326 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
2330 private static ArtifactMetadata createArtifact( )
2332 return createArtifact( "jar" );
2335 private static ArtifactMetadata createArtifact( String type )
2337 ArtifactMetadata artifact = new ArtifactMetadata( );
2338 artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
2339 artifact.setWhenGathered( ZonedDateTime.now() );
2340 artifact.setNamespace( TEST_NAMESPACE );
2341 artifact.setProject( TEST_PROJECT );
2342 artifact.setRepositoryId( TEST_REPO_ID );
2343 artifact.setFileLastModified( System.currentTimeMillis( ) );
2344 artifact.setVersion( TEST_PROJECT_VERSION );
2345 artifact.setProjectVersion( TEST_PROJECT_VERSION );
2346 artifact.setMd5( TEST_MD5 );
2347 artifact.setSha1( TEST_SHA1 );
2351 private static class ArtifactMetadataComparator
2352 implements Comparator<ArtifactMetadata>
2355 public final int compare( ArtifactMetadata a, ArtifactMetadata b )
2357 return a.getProject( ).compareTo( b.getProject( ) );
2361 private static class KindOfRepositoryStatistics
2362 implements MetadataFacet
2364 private String value;
2368 static final String SCAN_TIMESTAMP_FORMAT = "yyyy/MM/dd/HHmmss.SSS";
2370 private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
2372 private KindOfRepositoryStatistics( String value, Date date )
2379 public String getName( )
2381 return createNameFormat( ).format( date );
2384 private static SimpleDateFormat createNameFormat( )
2386 SimpleDateFormat fmt = new SimpleDateFormat( SCAN_TIMESTAMP_FORMAT );
2387 fmt.setTimeZone( UTC_TIME_ZONE );
2392 public String getFacetId( )
2394 return KindOfRepositoryStatistics.class.getName( );
2398 public Map<String, String> toProperties( )
2400 return Collections.emptyMap( );
2404 public void fromProperties( Map<String, String> properties )
2410 private static class TestMetadataFacet
2411 implements MetadataFacet
2413 private String testFacetId;
2415 private Map<String, String> additionalProps;
2417 private String value;
2419 private String name = TEST_NAME;
2421 private TestMetadataFacet( String value )
2424 testFacetId = TEST_FACET_ID;
2429 private TestMetadataFacet( String facetId, String value )
2432 testFacetId = facetId;
2435 private TestMetadataFacet( String facetId, String value, String name)
2438 testFacetId = facetId;
2442 private TestMetadataFacet( String facetId, String value, String name, Map<String, String> additionalProps )
2444 this( facetId, value, name );
2445 this.additionalProps = additionalProps;
2449 private TestMetadataFacet( String facetId, String value, Map<String, String> additionalProps )
2451 this( facetId, value );
2452 this.additionalProps = additionalProps;
2456 public String getFacetId( )
2462 public String getName( )
2468 public Map<String, String> toProperties( )
2470 if ( value != null )
2472 if ( additionalProps == null )
2474 return Collections.singletonMap( "foo", value );
2478 Map<String, String> props = new HashMap<>( );
2479 props.put( "foo", value );
2481 for ( String key : additionalProps.keySet( ) )
2483 props.put( key, additionalProps.get( key ) );
2490 return Collections.emptyMap( );
2495 public void fromProperties( Map<String, String> properties )
2497 String value = properties.get( "foo" );
2498 if ( value != null )
2503 properties.remove( "foo" );
2505 if ( additionalProps == null )
2507 additionalProps = new HashMap<>( );
2510 for ( String key : properties.keySet( ) )
2512 additionalProps.put( key, properties.get( key ) );
2516 public String getValue( )
2522 public String toString( )
2524 return "TestMetadataFacet{ name='"+ name+ "' value='" + value + '\'' + '}';
2528 public boolean equals( Object o )
2534 if ( o == null || getClass( ) != o.getClass( ) )
2539 TestMetadataFacet that = (TestMetadataFacet) o;
2541 if ( value != null ? !value.equals( that.value ) : that.value != null )
2550 public int hashCode( )
2552 return value != null ? value.hashCode( ) : 0;