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.setGroupId( "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.getGroupId( ) );
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( ) )
919 Stream<TestMetadataFacet> str = getRepository( ).getMetadataFacetStream( session, TEST_REPO_ID, TestMetadataFacet.class, new QueryParameter(0, 100));
920 assertNotNull( str );
921 List<TestMetadataFacet> result = str.collect( Collectors.toList( ) );
922 assertEquals( 100, result.size( ) );
923 assertNotNull( result.get( 0 ) );
924 for (int i=0; i<10; i++) {
925 assertEquals(TEST_NAME + "/" + String.format("%03d",i), result.get(i).getName());
933 public void testGetMetadataFacetsStreamWithOffset( )
936 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
938 for (int i = 0; i<100; i++)
940 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_FACET_ID, TEST_VALUE, TEST_NAME+"/"+String.format("%03d", i) ) );
944 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
947 Stream<TestMetadataFacet> str = getRepository( ).getMetadataFacetStream( session, TEST_REPO_ID, TestMetadataFacet.class, new QueryParameter(5, 10));
948 assertNotNull( str );
949 List<TestMetadataFacet> result = str.collect( Collectors.toList( ) );
950 assertEquals( 10, result.size( ) );
951 assertNotNull( result.get( 0 ) );
952 for (int i=0; i<10; i++) {
953 assertEquals(TEST_NAME + "/" + String.format("%03d",i+5), result.get(i).getName());
961 public void testGetArtifactsByDateRangeStreamLowerAndUpperBound( )
964 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
966 final ArtifactMetadata artifact1 = createArtifact( );
967 artifact1.setWhenGathered(ZonedDateTime.now().minusDays(1));
968 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
970 ZonedDateTime gatheredNow = ZonedDateTime.now();
971 final ArtifactMetadata artifact2 = createArtifact( );
972 String artifact2Id = artifact2.getId() + "-2";
973 artifact2.setId(artifact2Id);
974 artifact2.setVersion(TEST_PROJECT_VERSION+"-2");
975 artifact2.setWhenGathered(gatheredNow);
976 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
977 final ArtifactMetadata artifact3 = createArtifact();
978 String artifact3Id = artifact3.getId() + "-3";
979 artifact3.setId(artifact3Id);
980 artifact3.setVersion(TEST_PROJECT_VERSION+"-3");
981 artifact3.setWhenGathered(gatheredNow.minusSeconds(5));
983 final ArtifactMetadata artifact4 = createArtifact();
984 artifact4.setId(artifact4.getId()+"-4");
985 artifact4.setVersion(TEST_PROJECT_VERSION+"-4");
986 artifact4.setWhenGathered(gatheredNow.plusDays(1));
988 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact3 );
991 ZonedDateTime lower = artifact2.getWhenGathered().minusSeconds(10);
992 ZonedDateTime upper = artifact2.getWhenGathered().plusSeconds(10);
995 Stream<ArtifactMetadata> stream = getRepository().getArtifactByDateRangeStream(session, TEST_REPO_ID, lower, upper, new QueryParameter());
996 assertNotNull(stream);
998 List<ArtifactMetadata> artifacts = stream.collect(Collectors.toList());
999 assertEquals(2, artifacts.size());
1000 assertEquals(artifact3Id, artifacts.get(0).getId());
1001 assertEquals(artifact2Id, artifacts.get(1).getId());
1008 public void testGetMetadataFacetsWhenEmpty( )
1012 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1016 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1017 assertTrue( facets.isEmpty( ) );
1023 public void testRemoveFacets( )
1026 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1028 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
1030 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1031 assertFalse( facets.isEmpty( ) );
1033 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1035 facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1036 assertTrue( facets.isEmpty( ) );
1042 public void testRemoveFacetsWhenEmpty( )
1045 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1047 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1048 assertTrue( facets.isEmpty( ) );
1050 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1053 List<String> facets1 = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1054 assertTrue( facets1.isEmpty( ) );
1060 public void testRemoveFacetsWhenUnknown( )
1063 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1065 // testing no exception
1066 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, UNKNOWN );
1072 public void testRemoveFacetWhenUnknown( )
1075 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1077 // testing no exception
1078 getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, UNKNOWN, TEST_NAME );
1084 public void testRemoveFacet( )
1087 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1089 TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
1090 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, metadataFacet );
1092 assertEquals( metadataFacet, getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
1093 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1094 assertFalse( facets.isEmpty( ) );
1096 getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
1098 assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
1099 facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1100 assertTrue( facets.isEmpty( ) );
1106 public void testRemoveFacetWhenEmpty( )
1109 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1113 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1114 assertThat( facets ).isNotNull( ).isEmpty( );
1115 assertThat( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull( );
1118 getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
1122 List<String> facets2 = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1123 assertThat( facets2 ).isNotNull( ).isEmpty( );
1124 assertThat( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull( );
1131 public void hasMetadataFacetStart( )
1134 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1136 assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1143 public void hasMetadataFacet( )
1147 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1149 assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1151 Calendar cal = Calendar.getInstance( );
1153 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "first", cal.getTime( ) ) );
1155 assertTrue( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1157 cal.add( Calendar.MINUTE, 2 );
1159 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "second", cal.getTime( ) ) );
1161 cal.add( Calendar.MINUTE, 2 );
1163 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "third", cal.getTime( ) ) );
1165 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
1167 assertThat( facets ).isNotNull( ).isNotEmpty( ).hasSize( 3 );
1169 assertTrue( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1171 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
1173 assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1175 facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
1177 assertThat( facets ).isNotNull( ).isEmpty( );
1185 public void testGetArtifacts( )
1188 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1190 ArtifactMetadata artifact1 = createArtifact( );
1191 ArtifactMetadata artifact2 = createArtifact( "pom" );
1192 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1193 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1196 Collection<ArtifactMetadata> artifacts =
1197 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1198 ArrayList<ArtifactMetadata> actual = new ArrayList<>( artifacts );
1199 Collections.sort( actual, ( o1, o2 ) -> o1.getId( ).compareTo( o2.getId( ) ) );
1200 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
1207 public void testGetArtifactStream( )
1210 ArtifactMetadata artifact1 = createArtifact( );
1211 ArtifactMetadata artifact2 = createArtifact( "pom" );
1212 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1215 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1216 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1218 try ( RepositorySession session = getSessionFactory( ).createSession( ) ) {
1220 Stream<ArtifactMetadata> artifacts =
1221 getRepository( ).getArtifactStream( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1222 assertNotNull( artifacts );
1223 List<ArtifactMetadata> actual = artifacts
1224 .sorted( ( o1, o2 ) -> o1.getId( ).compareTo( o2.getId( ) ) ).collect( Collectors.toList( ) );
1225 assertEquals( 2, actual.size( ) );
1226 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
1233 public void testGetArtifactVersions( )
1236 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1238 ArtifactMetadata artifact1 = createArtifact( );
1239 String version1 = "1.0-20091212.012345-1";
1240 artifact1.setId( artifact1.getProject( ) + "-" + version1 + ".jar" );
1241 artifact1.setVersion( version1 );
1242 ArtifactMetadata artifact2 = createArtifact( );
1243 String version2 = "1.0-20091212.123456-2";
1244 artifact2.setId( artifact2.getProject( ) + "-" + version2 + ".jar" );
1245 artifact2.setVersion( version2 );
1246 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1247 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1250 Collection<String> versions =
1251 getRepository( ).getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1253 assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( version1, version2 );
1260 public void testGetArtifactVersionsMultipleArtifactsSingleVersion( )
1263 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1265 ArtifactMetadata artifact1 = createArtifact( );
1266 artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1267 ArtifactMetadata artifact2 = createArtifact( );
1268 artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
1269 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1270 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1273 Collection<String> versions =
1274 getRepository( ).getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1276 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).containsExactly( TEST_PROJECT_VERSION );
1284 public void testGetArtifactsByDateRangeOpen( )
1287 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1289 ArtifactMetadata artifact = createArtifact( );
1290 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1294 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
1296 assertEquals( Collections.singletonList( artifact ), artifacts );
1302 public void testGetArtifactsByDateRangeSparseNamespace( )
1305 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1307 String namespace = "org.apache.archiva";
1308 ArtifactMetadata artifact = createArtifact( );
1309 artifact.setNamespace( namespace );
1310 getRepository( ).updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1314 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
1316 tryAssert( ( ) -> assertEquals( Collections.singletonList( artifact ), artifacts ) );
1322 public void testGetArtifactsByDateRangeLowerBound( )
1325 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1327 ArtifactMetadata artifact = createArtifact( );
1328 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1331 ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
1334 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
1336 assertEquals( Collections.singletonList( artifact ), artifacts );
1342 public void testGetArtifactsByDateRangeLowerBoundOutOfRange( )
1345 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1347 ArtifactMetadata artifact = createArtifact( );
1348 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1350 ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);
1353 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
1355 assertThat( artifacts ).isNotNull( ).isEmpty( );
1361 public void testGetArtifactsByDateRangeLowerAndUpperBound( )
1364 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1366 ArtifactMetadata artifact = createArtifact( );
1367 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1370 ZonedDateTime lower = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
1371 ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);
1374 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, lower, upper );
1376 assertEquals( Collections.singletonList( artifact ), artifacts );
1382 public void testGetArtifactsByDateRangeUpperBound( )
1385 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1387 ArtifactMetadata artifact = createArtifact( );
1388 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1391 ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);
1394 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
1396 assertEquals( Collections.singletonList( artifact ), artifacts );
1402 public void testGetArtifactsByDateRangeUpperBoundOutOfRange( )
1405 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1407 ArtifactMetadata artifact = createArtifact( );
1408 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1411 ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
1414 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
1416 assertThat( artifacts ).isNotNull( ).isEmpty( );
1422 public void testGetArtifactsByRepoId( )
1425 ArtifactMetadata artifact;
1426 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1428 artifact = createArtifact( );
1429 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1432 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1435 session.refreshAndDiscard( );
1436 List<ArtifactMetadata> artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID );
1437 assertEquals( Collections.singletonList( artifact ), artifacts );
1444 public void testGetArtifactsByRepoIdMultipleCopies( )
1447 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1449 ArtifactMetadata artifact = createArtifact( );
1450 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1452 ArtifactMetadata secondArtifact = createArtifact( );
1453 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1454 getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1457 // test it restricts to the appropriate repository
1459 List<ArtifactMetadata> artifact1 = getRepository( ).getArtifacts( session, TEST_REPO_ID );
1460 assertEquals( Collections.singletonList( artifact ), artifact1 );
1461 assertEquals( Collections.singletonList( secondArtifact ), getRepository( ).getArtifacts( session, OTHER_REPO_ID ) );
1469 public void testGetArtifactsByDateRangeMultipleCopies( )
1472 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1474 ArtifactMetadata artifact = createArtifact( );
1475 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1477 ArtifactMetadata secondArtifact = createArtifact( );
1478 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1479 getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1483 // test it restricts to the appropriate repository
1484 assertEquals( Collections.singletonList( artifact ),
1485 getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null ) );
1488 assertEquals( Collections.singletonList( secondArtifact ),
1489 getRepository( ).getArtifactsByDateRange( session, OTHER_REPO_ID, null, null ) );
1495 public void testGetArtifactsByChecksumMultipleCopies( )
1498 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1500 ArtifactMetadata artifact = createArtifact( );
1501 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1503 ArtifactMetadata secondArtifact = createArtifact( );
1504 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1505 getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1509 // test it restricts to the appropriate repository
1510 assertEquals( Collections.singletonList( artifact ),
1511 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
1514 assertEquals( Collections.singletonList( secondArtifact ), new ArrayList<>(
1515 getRepository( ).getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_SHA1 ) ) );
1518 assertEquals( Collections.singletonList( artifact ),
1519 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
1522 assertEquals( Collections.singletonList( secondArtifact ),
1523 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_MD5 ) ) );
1530 public void testGetNamespacesWithSparseDepth( )
1533 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1535 getRepository( ).updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared" );
1539 Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
1541 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "org" );
1543 namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, "org" );
1544 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "apache" );
1546 namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, "org.apache" );
1547 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "maven" );
1549 namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, "org.apache.maven" );
1550 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "shared" );
1557 public void testGetNamespacesWithProjectsPresent( )
1560 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1562 String namespace = "org.apache.maven.shared";
1563 getRepository( ).updateNamespace( session, TEST_REPO_ID, namespace );
1565 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
1566 metadata.setId( TEST_PROJECT_VERSION );
1567 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, namespace, TEST_PROJECT, metadata );
1569 Collection<String> namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, namespace );
1571 assertThat( namespaces ).isNotNull( ).isEmpty( );
1578 public void testGetProjectsWithOtherNamespacesPresent( )
1581 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1583 ProjectMetadata projectMetadata = new ProjectMetadata( );
1584 projectMetadata.setId( TEST_PROJECT );
1585 projectMetadata.setNamespace( "org.apache.maven" );
1586 getRepository( ).updateProject( session, TEST_REPO_ID, projectMetadata );
1588 getRepository( ).updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared" );
1590 Collection<String> projects = getRepository( ).getProjects( session, TEST_REPO_ID, "org.apache.maven" );
1592 assertThat( projects ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_PROJECT );
1598 public void testGetProjectVersionsWithOtherNamespacesPresent( )
1601 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1603 // an unusual case but technically possible where a project namespace matches another project's name
1605 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata( );
1606 versionMetadata.setId( TEST_PROJECT_VERSION );
1607 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT, versionMetadata );
1609 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT,
1610 "other-project", versionMetadata );
1612 Collection<String> versions =
1613 getRepository( ).getProjectVersions( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT, "other-project" );
1614 assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( TEST_PROJECT_VERSION );
1616 versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT );
1618 assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( TEST_PROJECT_VERSION );
1624 public void testGetArtifactsByChecksumSingleResultSha256( )
1627 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1629 ArtifactMetadata artifact = createArtifact( );
1630 artifact.setChecksum( ChecksumAlgorithm.SHA256, TEST_SHA256);
1631 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1635 assertEquals( Collections.singletonList( artifact ),
1636 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA256 ) ))
1643 public void testGetArtifactsByChecksumSingleResultMd5( )
1646 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1648 ArtifactMetadata artifact = createArtifact( );
1649 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1652 assertEquals( Collections.singletonList( artifact ),
1653 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
1659 public void testGetArtifactsByChecksumSingleResultSha1( )
1662 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1664 ArtifactMetadata artifact = createArtifact( );
1665 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1668 assertEquals( Collections.singletonList( artifact ),
1669 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
1675 public void testGetArtifactsByChecksumDeepNamespace( )
1678 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1680 ArtifactMetadata artifact = createArtifact( );
1681 String namespace = "multi.level.ns";
1682 artifact.setNamespace( namespace );
1683 getRepository( ).updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1688 assertEquals( Collections.singletonList( artifact ),
1689 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
1690 assertEquals( Collections.singletonList( artifact ),
1691 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
1698 public void testGetArtifactsByChecksumMultipleResult( )
1702 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1704 ArtifactMetadata artifact1 = createArtifact( );
1705 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1707 String newProjectId = "another-project";
1708 ArtifactMetadata artifact2 = createArtifact( );
1709 artifact2.setProject( newProjectId );
1710 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
1714 List<ArtifactMetadata> artifacts =
1715 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) );
1716 Collections.sort( artifacts, new ArtifactMetadataComparator( ) );
1717 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1721 ArrayList<ArtifactMetadata> artifacts = new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) );
1722 Collections.sort( artifacts, new ArtifactMetadataComparator( ) );
1723 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1729 public void testGetArtifactsByChecksumNoResult( )
1732 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1734 ArtifactMetadata artifact = createArtifact( );
1735 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1738 Collection<ArtifactMetadata> artifactsByChecksum =
1739 getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, "not checksum" );
1741 assertThat( artifactsByChecksum ).isNotNull( ).isEmpty( );
1748 public void testGetArtifactsByProjectVersionMetadata( )
1751 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1753 createArtifactWithGenericMetadataFacet( session, 10 );
1756 Collection<ArtifactMetadata> artifactsByMetadata =
1757 getRepository( ).getArtifactsByProjectVersionFacet( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, TEST_REPO_ID );
1759 assertThat( artifactsByMetadata ).hasSize( 1 );
1760 ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator( ).next( );
1761 assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1762 assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
1763 assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
1769 public void testGetArtifactsByProjectVersionMetadataNoRepository( )
1772 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1774 createArtifactWithGenericMetadataFacet( session );
1777 Collection<ArtifactMetadata> artifactsByMetadata =
1778 getRepository( ).getArtifactsByProjectVersionFacet( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
1779 assertThat( artifactsByMetadata ).hasSize( 1 );
1780 assertThat( artifactsByMetadata.iterator( ).next( ).getRepositoryId( ) ).isNotNull( ).isNotEmpty( );
1786 public void testGetArtifactsByProjectVersionMetadataAllRepositories( )
1789 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1791 createArtifactWithGenericMetadataFacet( session );
1794 Collection<ArtifactMetadata> artifactsByMetadata =
1795 getRepository( ).getArtifactsByProjectVersionFacet( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
1796 assertThat( artifactsByMetadata ).hasSize( 1 );
1802 public void testGetArtifactsByMetadataAllRepositories( )
1805 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1807 createArtifactWithMavenArtifactFacet( session );
1809 Collection<ArtifactMetadata> artifactsByMetadata =
1810 getRepository( ).getArtifactsByAttribute( session, "foo", TEST_METADATA_VALUE, null );
1811 assertThat( artifactsByMetadata ).hasSize( 1 );
1812 ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator( ).next( );
1813 assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1814 assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
1815 assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
1816 MetadataFacet facet = artifactMetadata.getFacet( TEST_FACET_ID );
1817 assertThat( facet ).isNotNull( );
1818 assertThat( facet.toProperties( ).get("foo").equals(TEST_METADATA_VALUE) );
1824 public void testGetArtifactsByPropertySingleResult( )
1827 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1829 createArtifactWithData( session );
1830 // only works on JCR implementation
1831 // Collection<ArtifactMetadata> artifactsByProperty = getRepository().getArtifactsByProjectVersionAttribute( "org.name", TEST_ORGANIZATION.getName(), TEST_REPO_ID );
1834 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).getArtifactsByProjectVersionAttribute( session, "url", TEST_URL, TEST_REPO_ID );
1835 assertThat( artifactsByProperty ).hasSize( 1 );
1836 ArtifactMetadata artifactMetadata = artifactsByProperty.iterator( ).next( );
1837 assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1838 assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
1839 assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
1846 public void testDeleteRepository( )
1849 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1852 getRepository( ).updateNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
1854 ProjectMetadata project1 = new ProjectMetadata( );
1855 project1.setNamespace( TEST_NAMESPACE );
1856 project1.setId( "project1" );
1857 getRepository( ).updateProject( session, TEST_REPO_ID, project1 );
1858 ProjectMetadata project2 = new ProjectMetadata( );
1859 project2.setNamespace( TEST_NAMESPACE );
1860 project2.setId( "project2" );
1861 getRepository( ).updateProject( session, TEST_REPO_ID, project2 );
1863 ArtifactMetadata artifact1 = createArtifact( );
1864 artifact1.setProject( "project1" );
1865 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
1866 ArtifactMetadata artifact2 = createArtifact( );
1867 artifact2.setProject( "project2" );
1868 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
1871 List<ArtifactMetadata> expected = Arrays.asList( artifact1, artifact2 );
1872 Collections.sort( expected, new ArtifactMetadataComparator( ) );
1876 List<ArtifactMetadata> actual =
1877 new ArrayList<>( getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null ) );
1878 Collections.sort( actual, new ArtifactMetadataComparator( ) );
1879 assertEquals( expected, actual );
1882 getRepository( ).removeRepository( session, TEST_REPO_ID );
1885 assertTrue( getRepository( ).getArtifacts( session, TEST_REPO_ID ).isEmpty( ) );
1886 assertTrue( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ).isEmpty( ) );
1893 public void testDeleteArtifact( )
1896 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1899 ArtifactMetadata artifact = createArtifact( );
1900 artifact.addFacet( new TestMetadataFacet( "value" ) );
1902 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1904 assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
1905 TEST_PROJECT, TEST_PROJECT_VERSION ) ).containsExactly( artifact );
1907 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact );
1909 Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1911 log.info( "versions {}", versions );
1913 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 2 ).contains( "1.0", "2.0" );
1915 getRepository( ).removeArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId( ) );
1917 versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1919 log.info( "versions {}", versions );
1921 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "2.0" );
1923 assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
1924 TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNotNull( ).isEmpty( );
1926 assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
1927 TEST_PROJECT, TEST_PROJECT_VERSION_2_0 ) ).isNotEmpty( ).hasSize( 1 );
1932 public void deleteArtifact( )
1935 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1937 ArtifactMetadata artifact = createArtifact( );
1938 artifact.addFacet( new TestMetadataFacet( "value" ) );
1940 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1942 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1945 Collection<ArtifactMetadata> artifacts =
1946 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1948 assertEquals( Collections.singletonList( artifact ), new ArrayList<>( artifacts ) );
1952 getRepository( ).removeArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId( ) );
1955 Collection<ArtifactMetadata> artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1957 assertThat( artifacts ).isNotNull( ).isEmpty( );
1964 public void deleteVersion( )
1967 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1969 ArtifactMetadata artifact = createArtifact( );
1970 artifact.addFacet( new TestMetadataFacet( "value" ) );
1972 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1974 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1978 Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1980 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
1983 getRepository( ).removeProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1987 Collection<String> versions1 = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1989 assertThat( versions1 ).isNotNull( ).isEmpty( );
1995 public void deleteProject( )
1998 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2000 ArtifactMetadata artifact = createArtifact( );
2001 artifact.addFacet( new TestMetadataFacet( "value" ) );
2003 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2005 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2007 assertEquals( 1, getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ).size( ) );
2009 getRepository( ).removeProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
2011 Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
2013 assertThat( versions ).isNotNull( ).isEmpty( );
2020 public void deleteSnapshotVersion( )
2023 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2026 ArtifactMetadata artifactOne = createArtifact( );
2027 artifactOne.setVersion( "2.0-20120618.214127-1" );
2028 artifactOne.setProjectVersion( "2.0-SNAPSHOT" );
2029 artifactOne.addFacet( new TestMetadataFacet( "value" ) );
2030 artifactOne.setId( TEST_PROJECT + "-" + "2.0-20120618.214127-1" + "." + "jar" );
2032 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactOne );
2034 ArtifactMetadata artifactTwo = createArtifact( );
2035 artifactTwo.setVersion( "2.0-20120618.214135-2" );
2036 artifactTwo.setProjectVersion( "2.0-SNAPSHOT" );
2037 artifactTwo.addFacet( new TestMetadataFacet( "value" ) );
2038 artifactTwo.setId( TEST_PROJECT + "-" + "2.0-20120618.214135-2" + "." + "jar" );
2040 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactTwo );
2042 Collection<ArtifactMetadata> artifactMetadatas =
2043 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
2045 assertThat( artifactMetadatas ).isNotNull( ).isNotEmpty( ).hasSize( 2 );
2047 log.info( "artifactMetadatas: {}", artifactMetadatas );
2049 getRepository( ).removeTimestampedArtifact( session, artifactOne, "2.0-SNAPSHOT" );
2051 artifactMetadatas = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
2053 assertThat( artifactMetadatas ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
2055 getRepository( ).removeTimestampedArtifact( session, artifactTwo, "2.0-SNAPSHOT" );
2057 artifactMetadatas = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
2059 assertThat( artifactMetadatas ).isNotNull( ).isEmpty( );
2065 public void testgetProjectReferences( )
2068 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2071 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
2072 metadata.setId( TEST_PROJECT_VERSION );
2074 metadata.setName( "project name" );
2075 metadata.setDescription( "project description" );
2076 metadata.setUrl( "the url" );
2078 Dependency d = new Dependency( );
2079 d.setArtifactId( "artifactId" );
2080 d.setClassifier( "classifier" );
2081 d.setGroupId( "groupId" );
2082 d.setScope( "scope" );
2083 d.setSystemPath( "system path" );
2084 d.setType( "type" );
2085 d.setVersion( "version" );
2086 d.setOptional( true );
2087 metadata.addDependency( d );
2089 d = new Dependency( );
2090 d.setArtifactId( "artifactId1" );
2091 d.setClassifier( "classifier" );
2092 d.setGroupId( "groupId" );
2093 d.setScope( "scope" );
2094 d.setSystemPath( "system path" );
2095 d.setType( "type" );
2096 d.setVersion( "version1" );
2097 d.setOptional( true );
2098 metadata.addDependency( d );
2100 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
2104 metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
2105 final Dependency dd = d;
2110 Collection<ProjectVersionReference> references =
2111 getRepository( ).getProjectReferences( session, TEST_REPO_ID, dd.getGroupId( ), dd.getArtifactId( ), dd.getVersion( ) );
2112 log.info( "references: {}", references );
2113 assertThat( references ).isNotNull( ).hasSize( 1 ).contains(
2114 new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY, TEST_PROJECT, TEST_NAMESPACE,
2115 TEST_PROJECT_VERSION ));
2123 public void testSearchArtifactsByKey( )
2126 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2128 createArtifactWithData( session );
2131 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2133 session.refreshAndDiscard( );
2135 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, false );
2136 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2142 public void testSearchArtifactsByKeyExact( )
2145 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2147 createArtifactWithData( session );
2149 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2151 session.refreshAndDiscard( );
2153 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, true );
2154 assertThat( artifactsByProperty ).describedAs( "Artifact search by url=%s must give a result.", TEST_URL ).isNotNull( ).isNotEmpty( );
2155 artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "org.name", "pache", true );
2156 assertThat( artifactsByProperty ).describedAs( "Artifact search by text org.name='pache' must be empty" ).isNotNull( ).isEmpty( );
2162 public void testSearchArtifactsByFacetKey( )
2165 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2167 createArtifactWithGenericMetadataFacet( session );
2169 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_KEY, TEST_METADATA_VALUE, false );
2170 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2177 public void testSearchArtifactsByFacetKeyAllRepos( )
2180 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2183 createArtifactWithGenericMetadataFacet( session );
2185 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, null, TEST_METADATA_KEY, TEST_METADATA_VALUE, false );
2186 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2192 public void testSearchArtifactsFullText( )
2195 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2197 createArtifactWithGenericMetadataFacet( session );
2198 // only works in JCR
2199 // Collection<ArtifactMetadata> artifactsByProperty = getRepository().searchArtifacts( TEST_URL, TEST_REPO_ID, false );
2201 Collection<ArtifactMetadata> artifactsByProperty =
2202 getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false );
2203 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2210 public void testSearchArtifactsFullTextExact( )
2213 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2215 createArtifactWithGenericMetadataFacet( session );
2216 // only works in JCR
2217 // Collection<ArtifactMetadata> artifactsByProperty = getRepository().searchArtifacts( TEST_URL, TEST_REPO_ID, true );
2220 Collection<ArtifactMetadata> artifactsByProperty =
2221 getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, true );
2222 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2226 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE.substring( 2 ), true );
2227 assertThat( artifactsByProperty ).isNotNull( ).isEmpty( );
2233 public void testSearchArtifactsFullTextByFacet( )
2236 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2238 createArtifactWithGenericMetadataFacet( session );
2240 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false );
2241 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2247 private static ProjectMetadata createProject( )
2249 return createProject( TEST_NAMESPACE );
2252 private static ProjectMetadata createProject( String ns )
2254 ProjectMetadata project = new ProjectMetadata( );
2255 project.setId( TEST_PROJECT );
2256 project.setNamespace( ns );
2260 private void createArtifactWithGenericMetadataFacet( RepositorySession session )
2261 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2263 createArtifactWithGenericMetadataFacet( session, 1 );
2266 private void createArtifactWithGenericMetadataFacet( RepositorySession session, int artifacts )
2267 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2269 MetadataFacet metadataFacet = new GenericMetadataFacet( );
2270 Map<String, String> properties = new HashMap<>( );
2271 properties.put( TEST_METADATA_KEY, TEST_METADATA_VALUE );
2272 metadataFacet.fromProperties( properties );
2273 createArtifactWithFacet( session, artifacts, null, metadataFacet );
2276 private void createArtifactWithMavenArtifactFacet( RepositorySession session )
2277 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2279 createArtifactWithMavenArtifactFacet( session, 1 );
2282 private void createArtifactWithMavenArtifactFacet( RepositorySession session, int artifacts )
2283 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2285 TestMetadataFacet facet = new TestMetadataFacet( TEST_METADATA_VALUE );
2286 createArtifactWithFacet( session, artifacts, facet, null );
2289 private void createArtifactWithFacet( RepositorySession session, int artifacts, MetadataFacet artifactFacet,
2290 MetadataFacet projectVersionMetadataFacet )
2291 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2293 for ( int i = 0; i < artifacts; i++ )
2295 ArtifactMetadata artifact = createArtifact( );
2296 if ( artifactFacet != null )
2298 artifact.addFacet( artifactFacet );
2300 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2302 if ( projectVersionMetadataFacet != null )
2304 ProjectVersionMetadata metadata =
2305 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
2306 metadata.addFacet( projectVersionMetadataFacet );
2307 metadata.setOrganization( TEST_ORGANIZATION );
2308 metadata.setUrl( TEST_URL );
2309 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
2314 protected void createArtifactWithData( RepositorySession session )
2315 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2317 ArtifactMetadata artifact = createArtifact( );
2318 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2319 ProjectVersionMetadata metadata =
2320 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
2321 metadata.setOrganization( TEST_ORGANIZATION );
2322 metadata.setUrl( TEST_URL );
2324 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
2328 private static ArtifactMetadata createArtifact( )
2330 return createArtifact( "jar" );
2333 private static ArtifactMetadata createArtifact( String type )
2335 ArtifactMetadata artifact = new ArtifactMetadata( );
2336 artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
2337 artifact.setWhenGathered( ZonedDateTime.now() );
2338 artifact.setNamespace( TEST_NAMESPACE );
2339 artifact.setProject( TEST_PROJECT );
2340 artifact.setRepositoryId( TEST_REPO_ID );
2341 artifact.setFileLastModified( System.currentTimeMillis( ) );
2342 artifact.setVersion( TEST_PROJECT_VERSION );
2343 artifact.setProjectVersion( TEST_PROJECT_VERSION );
2344 artifact.setMd5( TEST_MD5 );
2345 artifact.setSha1( TEST_SHA1 );
2349 private static class ArtifactMetadataComparator
2350 implements Comparator<ArtifactMetadata>
2353 public final int compare( ArtifactMetadata a, ArtifactMetadata b )
2355 return a.getProject( ).compareTo( b.getProject( ) );
2359 private static class KindOfRepositoryStatistics
2360 implements MetadataFacet
2362 private String value;
2366 static final String SCAN_TIMESTAMP_FORMAT = "yyyy/MM/dd/HHmmss.SSS";
2368 private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
2370 private KindOfRepositoryStatistics( String value, Date date )
2377 public String getName( )
2379 return createNameFormat( ).format( date );
2382 private static SimpleDateFormat createNameFormat( )
2384 SimpleDateFormat fmt = new SimpleDateFormat( SCAN_TIMESTAMP_FORMAT );
2385 fmt.setTimeZone( UTC_TIME_ZONE );
2390 public String getFacetId( )
2392 return KindOfRepositoryStatistics.class.getName( );
2396 public Map<String, String> toProperties( )
2398 return Collections.emptyMap( );
2402 public void fromProperties( Map<String, String> properties )
2408 private static class TestMetadataFacet
2409 implements MetadataFacet
2411 private String testFacetId;
2413 private Map<String, String> additionalProps;
2415 private String value;
2417 private String name = TEST_NAME;
2419 private TestMetadataFacet( String value )
2422 testFacetId = TEST_FACET_ID;
2427 private TestMetadataFacet( String facetId, String value )
2430 testFacetId = facetId;
2433 private TestMetadataFacet( String facetId, String value, String name)
2436 testFacetId = facetId;
2440 private TestMetadataFacet( String facetId, String value, String name, Map<String, String> additionalProps )
2442 this( facetId, value, name );
2443 this.additionalProps = additionalProps;
2447 private TestMetadataFacet( String facetId, String value, Map<String, String> additionalProps )
2449 this( facetId, value );
2450 this.additionalProps = additionalProps;
2454 public String getFacetId( )
2460 public String getName( )
2466 public Map<String, String> toProperties( )
2468 if ( value != null )
2470 if ( additionalProps == null )
2472 return Collections.singletonMap( "foo", value );
2476 Map<String, String> props = new HashMap<>( );
2477 props.put( "foo", value );
2479 for ( String key : additionalProps.keySet( ) )
2481 props.put( key, additionalProps.get( key ) );
2488 return Collections.emptyMap( );
2493 public void fromProperties( Map<String, String> properties )
2495 String value = properties.get( "foo" );
2496 if ( value != null )
2501 properties.remove( "foo" );
2503 if ( additionalProps == null )
2505 additionalProps = new HashMap<>( );
2508 for ( String key : properties.keySet( ) )
2510 additionalProps.put( key, properties.get( key ) );
2514 public String getValue( )
2520 public String toString( )
2522 return "TestMetadataFacet{ name='"+ name+ "' value='" + value + '\'' + '}';
2526 public boolean equals( Object o )
2532 if ( o == null || getClass( ) != o.getClass( ) )
2537 TestMetadataFacet that = (TestMetadataFacet) o;
2539 if ( value != null ? !value.equals( that.value ) : that.value != null )
2548 public int hashCode( )
2550 return value != null ? value.hashCode( ) : 0;