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;
34 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36 import java.text.SimpleDateFormat;
37 import java.time.ZoneId;
38 import java.time.ZonedDateTime;
40 import java.util.stream.Collectors;
41 import java.util.stream.Stream;
43 import static org.assertj.core.api.Assertions.assertThat;
45 @RunWith( SpringJUnit4ClassRunner.class )
46 @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml"} )
47 public abstract class AbstractMetadataRepositoryTest
50 protected static final String OTHER_REPO_ID = "other-repo";
53 protected static final String TEST_REPO_ID = "test";
55 protected static final String TEST_PROJECT = "myproject";
57 protected static final String TEST_NAMESPACE = "mytest";
59 protected static final String TEST_PROJECT_VERSION = "1.0";
61 private static final String TEST_PROJECT_VERSION_2_0 = "2.0";
63 protected static final String TEST_URL = "http://archiva.apache.org";
65 private static final Organization TEST_ORGANIZATION = new Organization( "Apache", "http://apache.org" );
67 private static final String TEST_FACET_ID = "test-facet-id";
69 private static final String TEST_NAME = "test/name";
71 private static final String TEST_VALUE = "test-value";
73 private static final String UNKNOWN = "unknown";
75 private static final String TEST_SHA256 = "e43857b4e75e04a09d167564ca9a4636e5d233035483ba4ecf1243e34325d565";
77 private static final String TEST_MD5 = "bd4a9b642562547754086de2dab26b7d";
79 private static final String TEST_SHA1 = "2e5daf0201ddeb068a62d5e08da18657ab2c6be9";
81 private static final String TEST_METADATA_KEY = "testkey";
83 private static final String TEST_METADATA_VALUE = "testmetadata";
85 protected Logger log = LoggerFactory.getLogger( getClass( ) );
87 protected int assertMaxTries =10;
88 protected int assertRetrySleepMs=500;
91 * Used by tryAssert to allow to throw exceptions in the lambda expression.
94 protected interface AssertFunction
96 void accept( ) throws Exception;
99 protected void tryAssert( AssertFunction func ) throws Exception
101 tryAssert( func, assertMaxTries, assertRetrySleepMs );
105 protected abstract RepositorySessionFactory getSessionFactory( );
107 protected abstract MetadataRepository getRepository( );
110 * Runs the assert method until the assert is successful or the number of retries
111 * is reached. This is needed because the JCR Oak index update is asynchronous, so updates
112 * may not be visible immediately after the modification.
114 private void tryAssert( AssertFunction func, int retries, int sleepMillis ) throws Exception
118 while ( retry-- > 0 )
125 catch ( Exception | AssertionError e )
128 Thread.currentThread( ).sleep( sleepMillis );
129 log.warn( "Retrying assert {}: {}", retry, e.getMessage( ) );
132 log.warn( "Retries: {}, Exception: {}", retry, t.getMessage( ) );
133 if ( retry <= 0 && t != null )
135 if ( t instanceof RuntimeException )
137 throw (RuntimeException) t;
139 else if ( t instanceof Exception )
143 else if ( t instanceof Error )
151 public static List<MetadataFacetFactory> createTestMetadataFacetFactories( )
153 List<MetadataFacetFactory> factories = new ArrayList<>( );
154 factories.add( new MetadataFacetFactory<TestMetadataFacet>( )
157 public TestMetadataFacet createMetadataFacet( )
159 return new TestMetadataFacet( TEST_METADATA_VALUE );
163 public TestMetadataFacet createMetadataFacet( String repositoryId, String name )
165 return new TestMetadataFacet( TEST_FACET_ID, TEST_METADATA_VALUE, name );
169 public Class<TestMetadataFacet> getFacetClass( )
171 return TestMetadataFacet.class;
175 public String getFacetId( )
177 return TEST_FACET_ID;
181 // for the getArtifactsByProjectVersionFacet tests
182 factories.add( new GenericMetadataFacetFactory( ) );
189 public void testRootNamespaceWithNoMetadataRepository( )
192 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
195 Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
196 assertThat( namespaces ).isNotNull( ).isEmpty( );
202 public void testGetNamespaceOnly( )
205 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
208 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
210 getRepository( ).updateNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
213 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isNotEmpty( ).contains(
214 TEST_NAMESPACE ).hasSize( 1 );
216 getRepository( ).removeNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
219 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
225 public void testGetProjectOnly( )
228 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
232 assertNull( getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
233 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
236 ProjectMetadata project = new ProjectMetadata( );
237 project.setId( TEST_PROJECT );
238 project.setNamespace( TEST_NAMESPACE );
240 getRepository( ).updateProject( session, TEST_REPO_ID, project );
243 ProjectMetadata proj = getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
244 assertEquals( TEST_PROJECT, proj.getId( ) );
245 assertEquals( TEST_NAMESPACE, proj.getNamespace( ) );
248 // test that namespace is also constructed
252 Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
254 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).contains( TEST_NAMESPACE ).hasSize( 1 );
260 public void testGetProjectVersionOnly( )
263 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
267 assertNull( getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
268 assertNull( getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
269 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
272 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
273 metadata.setId( TEST_PROJECT_VERSION );
275 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
277 metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
278 assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
282 // test that namespace and project is also constructed
283 Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
285 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_NAMESPACE );
291 ProjectMetadata projectMetadata = getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
292 assertNotNull( projectMetadata );
293 assertEquals( TEST_PROJECT, projectMetadata.getId( ) );
294 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace( ) );
300 public void testGetArtifactOnly( )
303 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
307 assertThat( new ArrayList<>(
308 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
309 TEST_PROJECT, TEST_PROJECT_VERSION ) ) ).isNotNull( ).isEmpty( );
311 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull( );
312 assertThat( getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) ).isNull( );
314 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
318 ArtifactMetadata metadata = createArtifact( );
320 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
323 Collection<ArtifactMetadata> artifacts =
324 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
325 //assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
326 assertThat( artifacts ).containsExactly( metadata );
327 // test that namespace, project and project version is also constructed
329 assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isNotEmpty( ).contains(
330 TEST_NAMESPACE ).hasSize( 1 );
332 ProjectMetadata projectMetadata = getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
333 assertEquals( TEST_PROJECT, projectMetadata.getId( ) );
334 assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace( ) );
336 ProjectVersionMetadata projectVersionMetadata =
337 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
338 assertEquals( TEST_PROJECT_VERSION, projectVersionMetadata.getId( ) );
344 public void testUpdateProjectVersionMetadataWithNoOtherArchives( )
347 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
350 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
351 metadata.setId( TEST_PROJECT_VERSION );
352 MailingList mailingList = new MailingList( );
353 mailingList.setName( "Foo List" );
354 mailingList.setOtherArchives( Collections.<String>emptyList( ) );
355 metadata.setMailingLists( Arrays.asList( mailingList ) );
356 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
358 metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
359 assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
361 List<MailingList> mailingLists = metadata.getMailingLists( );
363 assertThat( mailingLists ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
365 mailingList = metadata.getMailingLists( ).get( 0 );
366 assertEquals( "Foo List", mailingList.getName( ) );
368 List<String> others = mailingList.getOtherArchives( );
369 assertThat( others ).isNotNull( ).isEmpty( );
374 public void testUpdateProjectVersionMetadataWithAllElements( )
378 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
381 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
382 metadata.setId( TEST_PROJECT_VERSION );
384 metadata.setName( "project name" );
385 metadata.setDescription( "project description" );
386 metadata.setUrl( "the url" );
388 MailingList mailingList = new MailingList( );
389 mailingList.setName( "Foo List" );
390 mailingList.setUnsubscribeAddress( "UnsubscribeAddress" );
391 mailingList.setSubscribeAddress( "SubscribeAddress" );
392 mailingList.setPostAddress( "PostAddress" );
393 mailingList.setMainArchiveUrl( "MainArchiveUrl" );
394 mailingList.setOtherArchives( Arrays.asList( "other archive" ) );
395 metadata.setMailingLists( Arrays.asList( mailingList ) );
397 Scm scm = new Scm( );
398 scm.setConnection( "connection" );
399 scm.setDeveloperConnection( "dev conn" );
401 metadata.setScm( scm );
403 CiManagement ci = new CiManagement( );
404 ci.setSystem( "system" );
405 ci.setUrl( "ci url" );
406 metadata.setCiManagement( ci );
408 IssueManagement tracker = new IssueManagement( );
409 tracker.setSystem( "system" );
410 tracker.setUrl( "issue tracker url" );
411 metadata.setIssueManagement( tracker );
413 metadata.setOrganization( TEST_ORGANIZATION );
415 License l = new License( );
416 l.setName( "license name" );
417 l.setUrl( "license url" );
418 metadata.addLicense( l );
420 Dependency d = new Dependency( );
421 d.setArtifactId( "artifactId" );
422 d.setClassifier( "classifier" );
423 d.setNamespace( "groupId" );
424 d.setScope( "scope" );
425 d.setSystemPath( "system path" );
427 d.setVersion( "version" );
428 d.setOptional( true );
429 metadata.addDependency( d );
431 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
433 metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
434 assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
435 assertEquals( TEST_PROJECT_VERSION, metadata.getVersion( ) );
436 assertEquals( "project name", metadata.getName( ) );
437 assertEquals( "project description", metadata.getDescription( ) );
438 assertEquals( "the url", metadata.getUrl( ) );
440 assertEquals( "connection", metadata.getScm( ).getConnection( ) );
441 assertEquals( "dev conn", metadata.getScm( ).getDeveloperConnection( ) );
442 assertEquals( "url", metadata.getScm( ).getUrl( ) );
444 assertEquals( "system", metadata.getCiManagement( ).getSystem( ) );
445 assertEquals( "ci url", metadata.getCiManagement( ).getUrl( ) );
447 assertEquals( "system", metadata.getIssueManagement( ).getSystem( ) );
448 assertEquals( "issue tracker url", metadata.getIssueManagement( ).getUrl( ) );
450 assertEquals( TEST_ORGANIZATION.getName( ), metadata.getOrganization( ).getName( ) );
451 assertEquals( TEST_ORGANIZATION.getUrl( ), metadata.getOrganization( ).getUrl( ) );
453 assertEquals( 1, metadata.getMailingLists( ).size( ) );
454 MailingList retrievedMailingList = metadata.getMailingLists( ).get( 0 );
455 assertEquals( mailingList.getName( ), retrievedMailingList.getName( ) );
456 assertEquals( mailingList.getMainArchiveUrl( ), retrievedMailingList.getMainArchiveUrl( ) );
457 assertEquals( mailingList.getPostAddress( ), retrievedMailingList.getPostAddress( ) );
458 assertEquals( mailingList.getSubscribeAddress( ), retrievedMailingList.getSubscribeAddress( ) );
459 assertEquals( mailingList.getUnsubscribeAddress( ), retrievedMailingList.getUnsubscribeAddress( ) );
460 assertThat( retrievedMailingList.getOtherArchives( ) ) //
464 .contains( "other archive" );
466 assertEquals( 1, metadata.getLicenses( ).size( ) );
467 l = metadata.getLicenses( ).get( 0 );
468 assertEquals( "license name", l.getName( ) );
469 assertEquals( "license url", l.getUrl( ) );
471 assertEquals( 1, metadata.getDependencies( ).size( ) );
472 d = metadata.getDependencies( ).get( 0 );
473 assertEquals( "artifactId", d.getArtifactId( ) );
474 assertEquals( "classifier", d.getClassifier( ) );
475 assertEquals( "groupId", d.getNamespace( ) );
476 assertEquals( "scope", d.getScope( ) );
477 assertEquals( "system path", d.getSystemPath( ) );
478 assertEquals( "type", d.getType( ) );
479 assertEquals( "version", d.getVersion( ) );
480 assertTrue( d.isOptional( ) );
485 public void testUpdateProjectVersionMetadataIncomplete( )
488 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
491 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
492 metadata.setId( TEST_PROJECT_VERSION );
493 metadata.setIncomplete( true );
494 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
497 ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
498 assertEquals( true, metadata1.isIncomplete( ) );
499 assertNull( metadata1.getCiManagement( ) );
500 assertNull( metadata1.getScm( ) );
501 assertNull( metadata1.getIssueManagement( ) );
502 assertNull( metadata1.getOrganization( ) );
503 assertTrue( metadata1.getDescription( )==null || "".equals(metadata1.getDescription()) );
504 assertTrue( metadata1.getName( )==null || "".equals(metadata1.getName()) );
505 assertEquals( TEST_PROJECT_VERSION, metadata1.getId( ) );
506 assertEquals( TEST_PROJECT_VERSION, metadata1.getVersion( ) );
507 assertTrue( metadata1.getMailingLists( ).isEmpty( ) );
508 assertTrue( metadata1.getLicenses( ).isEmpty( ) );
509 assertTrue( metadata1.getDependencies( ).isEmpty( ) );
515 public void testUpdateProjectVersionMetadataWithExistingFacets( )
518 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
521 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
522 metadata.setId( TEST_PROJECT_VERSION );
523 MetadataFacet facet = new TestMetadataFacet( "baz" );
524 metadata.addFacet( facet );
525 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
529 ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
530 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata1.getFacetIds( ) );
533 metadata = new ProjectVersionMetadata( );
534 metadata.setId( TEST_PROJECT_VERSION );
535 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
539 ProjectVersionMetadata metadata2 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
540 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata2.getFacetIds( ) );
541 TestMetadataFacet testFacet = (TestMetadataFacet) metadata2.getFacet( TEST_FACET_ID );
542 assertEquals( "baz", testFacet.getValue( ) );
548 public void testUpdateProjectVersionMetadataWithNoExistingFacets( )
551 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
554 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
555 metadata.setId( TEST_PROJECT_VERSION );
556 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
560 ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
562 assertThat( metadata1.getFacetIds( ) ).isNotNull( ).isEmpty( );
565 ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
566 metadata = new ProjectVersionMetadata( );
567 metadata.setId( TEST_PROJECT_VERSION );
568 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
571 ProjectVersionMetadata metadata2 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
572 assertThat( metadata2.getFacetIds( ) ).isNotNull( ).isEmpty( );
578 public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved( )
581 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
584 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
585 metadata.setId( TEST_PROJECT_VERSION );
587 Map<String, String> additionalProps = new HashMap<>( );
588 additionalProps.put( "deleteKey", "deleteValue" );
590 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
591 metadata.addFacet( facet );
592 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
597 ProjectVersionMetadata metad = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
599 assertThat( metad.getFacetIds( ) ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
604 ProjectVersionMetadata metad = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
605 TestMetadataFacet testFacet = (TestMetadataFacet) metad.getFacet( TEST_FACET_ID );
606 Map<String, String> facetProperties = testFacet.toProperties( );
608 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
610 facetProperties.remove( "deleteKey" );
612 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue( ), facetProperties );
613 metadata.addFacet( newTestFacet );
615 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
619 ProjectVersionMetadata metad2 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
621 assertThat( metad2.getFacetIds( ) ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
622 TestMetadataFacet testFacet2 = (TestMetadataFacet) metad2.getFacet( TEST_FACET_ID );
623 assertFalse( testFacet2.toProperties( ).containsKey( "deleteKey" ) );
629 public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets( )
632 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
635 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata( );
636 versionMetadata.setId( TEST_PROJECT_VERSION );
638 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz" );
639 versionMetadata.addFacet( facet );
640 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata );
641 ArtifactMetadata artifactMetadata = createArtifact( );
642 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata );
648 Collection<ArtifactMetadata> artifacts =
649 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
650 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
652 artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID );
653 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
655 artifacts = getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 );
656 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
658 artifacts = getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 );
659 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
661 artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
662 assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
668 public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved( )
671 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
674 ArtifactMetadata metadata = createArtifact( );
676 Map<String, String> additionalProps = new HashMap<>( );
677 additionalProps.put( "deleteKey", "deleteValue" );
679 MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
680 metadata.addFacet( facet );
681 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
684 Collection<ArtifactMetadata> artifacts =
685 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
687 assertThat( artifacts ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
690 Collection<ArtifactMetadata> artifacts =
691 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
692 metadata = artifacts.iterator( ).next( );
694 Collection<String> ids = metadata.getFacetIds( );
695 assertThat( ids ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
697 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
698 Map<String, String> facetProperties = testFacet.toProperties( );
700 assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
702 facetProperties.remove( "deleteKey" );
704 TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue( ), facetProperties );
705 metadata.addFacet( newTestFacet );
707 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
711 Collection<ArtifactMetadata> artifacts1 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
713 assertThat( artifacts1 ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
715 Collection<ArtifactMetadata> artifacts1 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
716 metadata = artifacts.iterator( ).next( );
718 ids = metadata.getFacetIds( );
719 assertThat( ids ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
721 testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
723 Map<String, String> props = testFacet.toProperties( );
724 assertThat( props ).isNotNull( ).doesNotContainKey( "deleteKey" );
729 public void testUpdateArtifactMetadataWithExistingFacets( )
732 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
735 ArtifactMetadata metadata = createArtifact( );
736 MetadataFacet facet = new TestMetadataFacet( "baz" );
737 metadata.addFacet( facet );
738 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
740 metadata = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
741 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
742 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds( ) );
744 metadata = createArtifact( );
745 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
747 metadata = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
748 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
749 assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds( ) );
750 TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
751 assertEquals( "baz", testFacet.getValue( ) );
756 public void testUpdateArtifactMetadataWithNoExistingFacets( )
759 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
761 ArtifactMetadata metadata = createArtifact( );
762 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
766 ArtifactMetadata metadata2 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
767 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
768 assertEquals( Collections.<String>emptyList( ), new ArrayList<String>( metadata2.getFacetIds( ) ) );
772 metadata = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
773 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
774 metadata = createArtifact( );
775 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
779 ArtifactMetadata metadata3 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
780 TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
781 assertEquals( Collections.<String>emptyList( ), new ArrayList<String>( metadata3.getFacetIds( ) ) );
787 public void testGetMetadataFacet( )
790 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
792 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
794 TestMetadataFacet test =
795 (TestMetadataFacet) getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
797 assertEquals( new TestMetadataFacet( TEST_VALUE ), test );
803 public void testGetMetadataFacetByClass( )
806 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
808 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
810 TestMetadataFacet test =
811 (TestMetadataFacet) getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TestMetadataFacet.class, TEST_NAME );
813 assertEquals( new TestMetadataFacet( TEST_VALUE ), test );
819 public void testGetMetadataFacetWhenEmpty( )
822 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
824 tryAssert( ( ) -> assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ) );
829 public void testGetMetadataFacetWhenUnknownName( )
832 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
834 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
836 tryAssert( ( ) -> assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) ) );
841 public void testGetMetadataFacetWhenDefaultValue( )
844 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
846 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( null ) );
849 MetadataFacet metadataFacet = getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
851 assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ), metadataFacet );
858 public void testGetMetadataFacetWhenUnknownFacetId( )
861 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
863 assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
869 public void testGetMetadataFacets( )
872 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
874 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
876 assertEquals( Collections.singletonList( TEST_NAME ),
877 getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID ) );
883 public void testGetMetadataFacetsStream( )
886 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
888 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
891 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
894 Stream<TestMetadataFacet> str = getRepository( ).getMetadataFacetStream( session, TEST_REPO_ID, TestMetadataFacet.class );
895 assertNotNull( str );
896 List<TestMetadataFacet> result = str.collect( Collectors.toList( ) );
897 assertEquals( 1, result.size( ) );
898 assertNotNull( result.get( 0 ) );
899 assertEquals( TEST_NAME, result.get( 0 ).getName( ) );
906 public void testGetMetadataFacetsStreamWithLimit( )
909 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
911 for (int i = 0; i<500; i++)
913 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_FACET_ID, TEST_VALUE, TEST_NAME+"/"+String.format("%03d",i) ) );
917 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
919 session.refreshAndDiscard();
921 Stream<TestMetadataFacet> str = getRepository( ).getMetadataFacetStream( session, TEST_REPO_ID, TestMetadataFacet.class, new QueryParameter(0, 100));
922 assertNotNull( str );
923 List<TestMetadataFacet> result = str.collect( Collectors.toList( ) );
924 assertEquals( 100, result.size( ) );
925 assertNotNull( result.get( 0 ) );
926 for (int i=0; i<10; i++) {
927 assertEquals(TEST_NAME + "/" + String.format("%03d",i), result.get(i).getName());
935 public void testGetMetadataFacetsStreamWithOffset( )
938 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
940 for (int i = 0; i<100; i++)
942 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_FACET_ID, TEST_VALUE, TEST_NAME+"/"+String.format("%03d", i) ) );
946 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
948 session.refreshAndDiscard();
950 Stream<TestMetadataFacet> str = getRepository( ).getMetadataFacetStream( session, TEST_REPO_ID, TestMetadataFacet.class, new QueryParameter(5, 10));
951 assertNotNull( str );
952 List<TestMetadataFacet> result = str.collect( Collectors.toList( ) );
953 assertEquals( 10, result.size( ) );
954 assertNotNull( result.get( 0 ) );
955 for (int i=0; i<10; i++) {
956 assertEquals(TEST_NAME + "/" + String.format("%03d",i+5), result.get(i).getName());
964 public void testGetArtifactsByDateRangeStreamLowerAndUpperBound( )
967 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
969 final ArtifactMetadata artifact1 = createArtifact( );
970 artifact1.setWhenGathered(ZonedDateTime.now().minusDays(1));
971 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
973 ZonedDateTime gatheredNow = ZonedDateTime.now();
974 final ArtifactMetadata artifact2 = createArtifact( );
975 String artifact2Id = artifact2.getId() + "-2";
976 artifact2.setId(artifact2Id);
977 artifact2.setVersion(TEST_PROJECT_VERSION+"-2");
978 artifact2.setWhenGathered(gatheredNow);
979 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
980 final ArtifactMetadata artifact3 = createArtifact();
981 String artifact3Id = artifact3.getId() + "-3";
982 artifact3.setId(artifact3Id);
983 artifact3.setVersion(TEST_PROJECT_VERSION+"-3");
984 artifact3.setWhenGathered(gatheredNow.minusSeconds(5));
986 final ArtifactMetadata artifact4 = createArtifact();
987 artifact4.setId(artifact4.getId()+"-4");
988 artifact4.setVersion(TEST_PROJECT_VERSION+"-4");
989 artifact4.setWhenGathered(gatheredNow.plusDays(1));
991 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact3 );
994 ZonedDateTime lower = artifact2.getWhenGathered().minusSeconds(10);
995 ZonedDateTime upper = artifact2.getWhenGathered().plusSeconds(10);
998 Stream<ArtifactMetadata> stream = getRepository().getArtifactByDateRangeStream(session, TEST_REPO_ID, lower, upper, new QueryParameter());
999 assertNotNull(stream);
1001 List<ArtifactMetadata> artifacts = stream.collect(Collectors.toList());
1002 assertEquals(2, artifacts.size());
1003 assertEquals(artifact3Id, artifacts.get(0).getId());
1004 assertEquals(artifact2Id, artifacts.get(1).getId());
1011 public void testGetMetadataFacetsWhenEmpty( )
1015 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1019 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1020 assertTrue( facets.isEmpty( ) );
1026 public void testRemoveFacets( )
1029 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1031 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
1033 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1034 assertFalse( facets.isEmpty( ) );
1036 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1038 facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1039 assertTrue( facets.isEmpty( ) );
1045 public void testRemoveFacetsWhenEmpty( )
1048 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1050 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1051 assertTrue( facets.isEmpty( ) );
1053 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1056 List<String> facets1 = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1057 assertTrue( facets1.isEmpty( ) );
1063 public void testRemoveFacetsWhenUnknown( )
1066 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1068 // testing no exception
1069 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, UNKNOWN );
1075 public void testRemoveFacetWhenUnknown( )
1078 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1080 // testing no exception
1081 getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, UNKNOWN, TEST_NAME );
1087 public void testRemoveFacet( )
1090 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1092 TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
1093 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, metadataFacet );
1095 assertEquals( metadataFacet, getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
1096 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1097 assertFalse( facets.isEmpty( ) );
1099 getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
1101 assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
1102 facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1103 assertTrue( facets.isEmpty( ) );
1109 public void testRemoveFacetWhenEmpty( )
1112 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1116 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1117 assertThat( facets ).isNotNull( ).isEmpty( );
1118 assertThat( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull( );
1121 getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
1125 List<String> facets2 = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
1126 assertThat( facets2 ).isNotNull( ).isEmpty( );
1127 assertThat( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull( );
1134 public void hasMetadataFacetStart( )
1137 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1139 assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1146 public void hasMetadataFacet( )
1150 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1152 assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1154 Calendar cal = Calendar.getInstance( );
1156 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "first", cal.getTime( ) ) );
1158 assertTrue( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1160 cal.add( Calendar.MINUTE, 2 );
1162 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "second", cal.getTime( ) ) );
1164 cal.add( Calendar.MINUTE, 2 );
1166 getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "third", cal.getTime( ) ) );
1168 List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
1170 assertThat( facets ).isNotNull( ).isNotEmpty( ).hasSize( 3 );
1172 assertTrue( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1174 getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
1176 assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
1178 facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
1180 assertThat( facets ).isNotNull( ).isEmpty( );
1188 public void testGetArtifacts( )
1191 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1193 ArtifactMetadata artifact1 = createArtifact( );
1194 ArtifactMetadata artifact2 = createArtifact( "pom" );
1195 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1196 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1199 Collection<ArtifactMetadata> artifacts =
1200 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1201 ArrayList<ArtifactMetadata> actual = new ArrayList<>( artifacts );
1202 Collections.sort( actual, ( o1, o2 ) -> o1.getId( ).compareTo( o2.getId( ) ) );
1203 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
1210 public void testGetArtifactStream( )
1213 ArtifactMetadata artifact1 = createArtifact( );
1214 ArtifactMetadata artifact2 = createArtifact( "pom" );
1215 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1218 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1219 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1221 try ( RepositorySession session = getSessionFactory( ).createSession( ) ) {
1223 Stream<ArtifactMetadata> artifacts =
1224 getRepository( ).getArtifactStream( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1225 assertNotNull( artifacts );
1226 List<ArtifactMetadata> actual = artifacts
1227 .sorted( ( o1, o2 ) -> o1.getId( ).compareTo( o2.getId( ) ) ).collect( Collectors.toList( ) );
1228 assertEquals( 2, actual.size( ) );
1229 assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
1236 public void testGetArtifactVersions( )
1239 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1241 ArtifactMetadata artifact1 = createArtifact( );
1242 String version1 = "1.0-20091212.012345-1";
1243 artifact1.setId( artifact1.getProject( ) + "-" + version1 + ".jar" );
1244 artifact1.setVersion( version1 );
1245 ArtifactMetadata artifact2 = createArtifact( );
1246 String version2 = "1.0-20091212.123456-2";
1247 artifact2.setId( artifact2.getProject( ) + "-" + version2 + ".jar" );
1248 artifact2.setVersion( version2 );
1249 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1250 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1253 Collection<String> versions =
1254 getRepository( ).getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1256 assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( version1, version2 );
1263 public void testGetArtifactVersionsMultipleArtifactsSingleVersion( )
1266 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1268 ArtifactMetadata artifact1 = createArtifact( );
1269 artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1270 ArtifactMetadata artifact2 = createArtifact( );
1271 artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
1272 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1273 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
1276 Collection<String> versions =
1277 getRepository( ).getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1279 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).containsExactly( TEST_PROJECT_VERSION );
1287 public void testGetArtifactsByDateRangeOpen( )
1290 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1292 ArtifactMetadata artifact = createArtifact( );
1293 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1297 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
1299 assertEquals( Collections.singletonList( artifact ), artifacts );
1305 public void testGetArtifactsByDateRangeSparseNamespace( )
1308 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1310 String namespace = "org.apache.archiva";
1311 ArtifactMetadata artifact = createArtifact( );
1312 artifact.setNamespace( namespace );
1313 getRepository( ).updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1317 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
1319 tryAssert( ( ) -> assertEquals( Collections.singletonList( artifact ), artifacts ) );
1325 public void testGetArtifactsByDateRangeLowerBound( )
1328 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1330 ArtifactMetadata artifact = createArtifact( );
1331 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1334 ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
1337 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
1339 assertEquals( Collections.singletonList( artifact ), artifacts );
1345 public void testGetArtifactsByDateRangeLowerBoundOutOfRange( )
1348 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1350 ArtifactMetadata artifact = createArtifact( );
1351 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1353 ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);
1356 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
1358 assertThat( artifacts ).isNotNull( ).isEmpty( );
1364 public void testGetArtifactsByDateRangeLowerAndUpperBound( )
1367 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1369 ArtifactMetadata artifact = createArtifact( );
1370 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1373 ZonedDateTime lower = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
1374 ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);
1377 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, lower, upper );
1379 assertEquals( Collections.singletonList( artifact ), artifacts );
1385 public void testGetArtifactsByDateRangeUpperBound( )
1388 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1390 ArtifactMetadata artifact = createArtifact( );
1391 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1394 ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);
1397 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
1399 assertEquals( Collections.singletonList( artifact ), artifacts );
1405 public void testGetArtifactsByDateRangeUpperBoundOutOfRange( )
1408 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1410 ArtifactMetadata artifact = createArtifact( );
1411 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1414 ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
1417 List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
1419 assertThat( artifacts ).isNotNull( ).isEmpty( );
1425 public void testGetArtifactsByRepoId( )
1428 ArtifactMetadata artifact;
1429 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1431 artifact = createArtifact( );
1432 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1435 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1438 session.refreshAndDiscard( );
1439 List<ArtifactMetadata> artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID );
1440 assertEquals( Collections.singletonList( artifact ), artifacts );
1447 public void testGetArtifactsByRepoIdMultipleCopies( )
1450 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1452 ArtifactMetadata artifact = createArtifact( );
1453 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1455 ArtifactMetadata secondArtifact = createArtifact( );
1456 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1457 getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1460 // test it restricts to the appropriate repository
1462 List<ArtifactMetadata> artifact1 = getRepository( ).getArtifacts( session, TEST_REPO_ID );
1463 assertEquals( Collections.singletonList( artifact ), artifact1 );
1464 assertEquals( Collections.singletonList( secondArtifact ), getRepository( ).getArtifacts( session, OTHER_REPO_ID ) );
1472 public void testGetArtifactsByDateRangeMultipleCopies( )
1475 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1477 ArtifactMetadata artifact = createArtifact( );
1478 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1480 ArtifactMetadata secondArtifact = createArtifact( );
1481 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1482 getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1486 // test it restricts to the appropriate repository
1487 assertEquals( Collections.singletonList( artifact ),
1488 getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null ) );
1491 assertEquals( Collections.singletonList( secondArtifact ),
1492 getRepository( ).getArtifactsByDateRange( session, OTHER_REPO_ID, null, null ) );
1498 public void testGetArtifactsByChecksumMultipleCopies( )
1501 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1503 ArtifactMetadata artifact = createArtifact( );
1504 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1506 ArtifactMetadata secondArtifact = createArtifact( );
1507 secondArtifact.setRepositoryId( OTHER_REPO_ID );
1508 getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
1512 // test it restricts to the appropriate repository
1513 assertEquals( Collections.singletonList( artifact ),
1514 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
1517 assertEquals( Collections.singletonList( secondArtifact ), new ArrayList<>(
1518 getRepository( ).getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_SHA1 ) ) );
1521 assertEquals( Collections.singletonList( artifact ),
1522 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
1525 assertEquals( Collections.singletonList( secondArtifact ),
1526 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_MD5 ) ) );
1533 public void testGetNamespacesWithSparseDepth( )
1536 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1538 getRepository( ).updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared" );
1542 Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
1544 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "org" );
1546 namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, "org" );
1547 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "apache" );
1549 namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, "org.apache" );
1550 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "maven" );
1552 namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, "org.apache.maven" );
1553 assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "shared" );
1560 public void testGetNamespacesWithProjectsPresent( )
1563 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1565 String namespace = "org.apache.maven.shared";
1566 getRepository( ).updateNamespace( session, TEST_REPO_ID, namespace );
1568 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
1569 metadata.setId( TEST_PROJECT_VERSION );
1570 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, namespace, TEST_PROJECT, metadata );
1572 Collection<String> namespaces = getRepository( ).getChildNamespaces( session, TEST_REPO_ID, namespace );
1574 assertThat( namespaces ).isNotNull( ).isEmpty( );
1581 public void testGetProjectsWithOtherNamespacesPresent( )
1584 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1586 ProjectMetadata projectMetadata = new ProjectMetadata( );
1587 projectMetadata.setId( TEST_PROJECT );
1588 projectMetadata.setNamespace( "org.apache.maven" );
1589 getRepository( ).updateProject( session, TEST_REPO_ID, projectMetadata );
1591 getRepository( ).updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared" );
1593 Collection<String> projects = getRepository( ).getProjects( session, TEST_REPO_ID, "org.apache.maven" );
1595 assertThat( projects ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_PROJECT );
1601 public void testGetProjectVersionsWithOtherNamespacesPresent( )
1604 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1606 // an unusual case but technically possible where a project namespace matches another project's name
1608 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata( );
1609 versionMetadata.setId( TEST_PROJECT_VERSION );
1610 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT, versionMetadata );
1612 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT,
1613 "other-project", versionMetadata );
1615 Collection<String> versions =
1616 getRepository( ).getProjectVersions( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT, "other-project" );
1617 assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( TEST_PROJECT_VERSION );
1619 versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT );
1621 assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( TEST_PROJECT_VERSION );
1627 public void testGetArtifactsByChecksumSingleResultSha256( )
1630 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1632 ArtifactMetadata artifact = createArtifact( );
1633 artifact.setChecksum( ChecksumAlgorithm.SHA256, TEST_SHA256);
1634 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1638 assertEquals( Collections.singletonList( artifact ),
1639 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA256 ) ))
1646 public void testGetArtifactsByChecksumSingleResultMd5( )
1649 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1651 ArtifactMetadata artifact = createArtifact( );
1652 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1655 assertEquals( Collections.singletonList( artifact ),
1656 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
1662 public void testGetArtifactsByChecksumSingleResultSha1( )
1665 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1667 ArtifactMetadata artifact = createArtifact( );
1668 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1671 assertEquals( Collections.singletonList( artifact ),
1672 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
1678 public void testGetArtifactsByChecksumDeepNamespace( )
1681 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1683 ArtifactMetadata artifact = createArtifact( );
1684 String namespace = "multi.level.ns";
1685 artifact.setNamespace( namespace );
1686 getRepository( ).updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1691 assertEquals( Collections.singletonList( artifact ),
1692 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
1693 assertEquals( Collections.singletonList( artifact ),
1694 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
1701 public void testGetArtifactsByChecksumMultipleResult( )
1705 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1707 ArtifactMetadata artifact1 = createArtifact( );
1708 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
1710 String newProjectId = "another-project";
1711 ArtifactMetadata artifact2 = createArtifact( );
1712 artifact2.setProject( newProjectId );
1713 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
1717 List<ArtifactMetadata> artifacts =
1718 new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) );
1719 Collections.sort( artifacts, new ArtifactMetadataComparator( ) );
1720 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1724 ArrayList<ArtifactMetadata> artifacts = new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) );
1725 Collections.sort( artifacts, new ArtifactMetadataComparator( ) );
1726 assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
1732 public void testGetArtifactsByChecksumNoResult( )
1735 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1737 ArtifactMetadata artifact = createArtifact( );
1738 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1741 Collection<ArtifactMetadata> artifactsByChecksum =
1742 getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, "not checksum" );
1744 assertThat( artifactsByChecksum ).isNotNull( ).isEmpty( );
1751 public void testGetArtifactsByProjectVersionMetadata( )
1754 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1756 createArtifactWithGenericMetadataFacet( session, 10 );
1759 Collection<ArtifactMetadata> artifactsByMetadata =
1760 getRepository( ).getArtifactsByProjectVersionFacet( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, TEST_REPO_ID );
1762 assertThat( artifactsByMetadata ).hasSize( 1 );
1763 ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator( ).next( );
1764 assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1765 assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
1766 assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
1772 public void testGetArtifactsByProjectVersionMetadataNoRepository( )
1775 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1777 createArtifactWithGenericMetadataFacet( session );
1780 Collection<ArtifactMetadata> artifactsByMetadata =
1781 getRepository( ).getArtifactsByProjectVersionFacet( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
1782 assertThat( artifactsByMetadata ).hasSize( 1 );
1783 assertThat( artifactsByMetadata.iterator( ).next( ).getRepositoryId( ) ).isNotNull( ).isNotEmpty( );
1789 public void testGetArtifactsByProjectVersionMetadataAllRepositories( )
1792 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1794 createArtifactWithGenericMetadataFacet( session );
1797 Collection<ArtifactMetadata> artifactsByMetadata =
1798 getRepository( ).getArtifactsByProjectVersionFacet( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
1799 assertThat( artifactsByMetadata ).hasSize( 1 );
1805 public void testGetArtifactsByMetadataAllRepositories( )
1808 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1810 createArtifactWithMavenArtifactFacet( session );
1812 Collection<ArtifactMetadata> artifactsByMetadata =
1813 getRepository( ).getArtifactsByAttribute( session, "foo", TEST_METADATA_VALUE, null );
1814 assertThat( artifactsByMetadata ).hasSize( 1 );
1815 ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator( ).next( );
1816 assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1817 assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
1818 assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
1819 MetadataFacet facet = artifactMetadata.getFacet( TEST_FACET_ID );
1820 assertThat( facet ).isNotNull( );
1821 assertThat( facet.toProperties( ).get("foo").equals(TEST_METADATA_VALUE) );
1827 public void testGetArtifactsByPropertySingleResult( )
1830 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1832 createArtifactWithData( session );
1833 // only works on JCR implementation
1834 // Collection<ArtifactMetadata> artifactsByProperty = getRepository().getArtifactsByProjectVersionAttribute( "org.name", TEST_ORGANIZATION.getName(), TEST_REPO_ID );
1837 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).getArtifactsByProjectVersionAttribute( session, "url", TEST_URL, TEST_REPO_ID );
1838 assertThat( artifactsByProperty ).hasSize( 1 );
1839 ArtifactMetadata artifactMetadata = artifactsByProperty.iterator( ).next( );
1840 assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
1841 assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
1842 assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
1849 public void testDeleteRepository( )
1852 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1855 getRepository( ).updateNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
1857 ProjectMetadata project1 = new ProjectMetadata( );
1858 project1.setNamespace( TEST_NAMESPACE );
1859 project1.setId( "project1" );
1860 getRepository( ).updateProject( session, TEST_REPO_ID, project1 );
1861 ProjectMetadata project2 = new ProjectMetadata( );
1862 project2.setNamespace( TEST_NAMESPACE );
1863 project2.setId( "project2" );
1864 getRepository( ).updateProject( session, TEST_REPO_ID, project2 );
1866 ArtifactMetadata artifact1 = createArtifact( );
1867 artifact1.setProject( "project1" );
1868 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
1869 ArtifactMetadata artifact2 = createArtifact( );
1870 artifact2.setProject( "project2" );
1871 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
1874 List<ArtifactMetadata> expected = Arrays.asList( artifact1, artifact2 );
1875 Collections.sort( expected, new ArtifactMetadataComparator( ) );
1879 List<ArtifactMetadata> actual =
1880 new ArrayList<>( getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null ) );
1881 Collections.sort( actual, new ArtifactMetadataComparator( ) );
1882 assertEquals( expected, actual );
1885 getRepository( ).removeRepository( session, TEST_REPO_ID );
1888 assertTrue( getRepository( ).getArtifacts( session, TEST_REPO_ID ).isEmpty( ) );
1889 assertTrue( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ).isEmpty( ) );
1896 public void testDeleteArtifact( )
1899 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1902 ArtifactMetadata artifact = createArtifact( );
1903 artifact.addFacet( new TestMetadataFacet( "value" ) );
1905 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1907 assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
1908 TEST_PROJECT, TEST_PROJECT_VERSION ) ).containsExactly( artifact );
1910 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact );
1912 Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1914 log.info( "versions {}", versions );
1916 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 2 ).contains( "1.0", "2.0" );
1918 getRepository( ).removeArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId( ) );
1920 versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1922 log.info( "versions {}", versions );
1924 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "2.0" );
1926 assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
1927 TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNotNull( ).isEmpty( );
1929 assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
1930 TEST_PROJECT, TEST_PROJECT_VERSION_2_0 ) ).isNotEmpty( ).hasSize( 1 );
1935 public void deleteArtifact( )
1938 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1940 ArtifactMetadata artifact = createArtifact( );
1941 artifact.addFacet( new TestMetadataFacet( "value" ) );
1943 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1945 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1948 Collection<ArtifactMetadata> artifacts =
1949 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1951 assertEquals( Collections.singletonList( artifact ), new ArrayList<>( artifacts ) );
1955 getRepository( ).removeArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId( ) );
1958 Collection<ArtifactMetadata> artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1960 assertThat( artifacts ).isNotNull( ).isEmpty( );
1967 public void deleteVersion( )
1970 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
1972 ArtifactMetadata artifact = createArtifact( );
1973 artifact.addFacet( new TestMetadataFacet( "value" ) );
1975 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1977 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
1981 Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1983 assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
1986 getRepository( ).removeProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
1990 Collection<String> versions1 = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
1992 assertThat( versions1 ).isNotNull( ).isEmpty( );
1998 public void deleteProject( )
2001 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2003 ArtifactMetadata artifact = createArtifact( );
2004 artifact.addFacet( new TestMetadataFacet( "value" ) );
2006 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2008 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2010 assertEquals( 1, getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ).size( ) );
2012 getRepository( ).removeProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
2014 Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
2016 assertThat( versions ).isNotNull( ).isEmpty( );
2023 public void deleteSnapshotVersion( )
2026 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2029 ArtifactMetadata artifactOne = createArtifact( );
2030 artifactOne.setVersion( "2.0-20120618.214127-1" );
2031 artifactOne.setProjectVersion( "2.0-SNAPSHOT" );
2032 artifactOne.addFacet( new TestMetadataFacet( "value" ) );
2033 artifactOne.setId( TEST_PROJECT + "-" + "2.0-20120618.214127-1" + "." + "jar" );
2035 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactOne );
2037 ArtifactMetadata artifactTwo = createArtifact( );
2038 artifactTwo.setVersion( "2.0-20120618.214135-2" );
2039 artifactTwo.setProjectVersion( "2.0-SNAPSHOT" );
2040 artifactTwo.addFacet( new TestMetadataFacet( "value" ) );
2041 artifactTwo.setId( TEST_PROJECT + "-" + "2.0-20120618.214135-2" + "." + "jar" );
2043 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactTwo );
2045 Collection<ArtifactMetadata> artifactMetadatas =
2046 getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
2048 assertThat( artifactMetadatas ).isNotNull( ).isNotEmpty( ).hasSize( 2 );
2050 log.info( "artifactMetadatas: {}", artifactMetadatas );
2052 getRepository( ).removeTimestampedArtifact( session, artifactOne, "2.0-SNAPSHOT" );
2054 artifactMetadatas = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
2056 assertThat( artifactMetadatas ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
2058 getRepository( ).removeTimestampedArtifact( session, artifactTwo, "2.0-SNAPSHOT" );
2060 artifactMetadatas = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
2062 assertThat( artifactMetadatas ).isNotNull( ).isEmpty( );
2068 public void testgetProjectReferences( )
2071 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2074 ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
2075 metadata.setId( TEST_PROJECT_VERSION );
2077 metadata.setName( "project name" );
2078 metadata.setDescription( "project description" );
2079 metadata.setUrl( "the url" );
2081 Dependency d = new Dependency( );
2082 d.setArtifactId( "artifactId" );
2083 d.setClassifier( "classifier" );
2084 d.setNamespace( "groupId" );
2085 d.setScope( "scope" );
2086 d.setSystemPath( "system path" );
2087 d.setType( "type" );
2088 d.setVersion( "version" );
2089 d.setOptional( true );
2090 metadata.addDependency( d );
2092 d = new Dependency( );
2093 d.setArtifactId( "artifactId1" );
2094 d.setClassifier( "classifier" );
2095 d.setNamespace( "groupId" );
2096 d.setScope( "scope" );
2097 d.setSystemPath( "system path" );
2098 d.setType( "type" );
2099 d.setVersion( "version1" );
2100 d.setOptional( true );
2101 metadata.addDependency( d );
2103 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
2107 metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
2108 final Dependency dd = d;
2113 Collection<ProjectVersionReference> references =
2114 getRepository( ).getProjectReferences( session, TEST_REPO_ID, dd.getNamespace( ), dd.getArtifactId( ), dd.getVersion( ) );
2115 log.info( "references: {}", references );
2116 assertThat( references ).isNotNull( ).hasSize( 1 ).contains(
2117 new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY, TEST_PROJECT, TEST_NAMESPACE,
2118 TEST_PROJECT_VERSION ));
2126 public void testSearchArtifactsByKey( )
2129 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2131 createArtifactWithData( session );
2134 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2136 session.refreshAndDiscard( );
2138 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, false );
2139 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2145 public void testSearchArtifactsByKeyExact( )
2148 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2150 createArtifactWithData( session );
2152 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2154 session.refreshAndDiscard( );
2156 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, true );
2157 assertThat( artifactsByProperty ).describedAs( "Artifact search by url=%s must give a result.", TEST_URL ).isNotNull( ).isNotEmpty( );
2158 artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "org.name", "pache", true );
2159 assertThat( artifactsByProperty ).describedAs( "Artifact search by text org.name='pache' must be empty" ).isNotNull( ).isEmpty( );
2165 public void testSearchArtifactsByFacetKey( )
2168 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2170 createArtifactWithGenericMetadataFacet( session );
2172 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_KEY, TEST_METADATA_VALUE, false );
2173 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2180 public void testSearchArtifactsByFacetKeyAllRepos( )
2183 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2186 createArtifactWithGenericMetadataFacet( session );
2188 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, null, TEST_METADATA_KEY, TEST_METADATA_VALUE, false );
2189 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2195 public void testSearchArtifactsFullText( )
2198 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2200 createArtifactWithGenericMetadataFacet( session );
2201 // only works in JCR
2202 // Collection<ArtifactMetadata> artifactsByProperty = getRepository().searchArtifacts( TEST_URL, TEST_REPO_ID, false );
2204 Collection<ArtifactMetadata> artifactsByProperty =
2205 getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false );
2206 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2213 public void testSearchArtifactsFullTextExact( )
2216 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2218 createArtifactWithGenericMetadataFacet( session );
2219 // only works in JCR
2220 // Collection<ArtifactMetadata> artifactsByProperty = getRepository().searchArtifacts( TEST_URL, TEST_REPO_ID, true );
2223 Collection<ArtifactMetadata> artifactsByProperty =
2224 getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, true );
2225 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2229 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE.substring( 2 ), true );
2230 assertThat( artifactsByProperty ).isNotNull( ).isEmpty( );
2236 public void testSearchArtifactsFullTextByFacet( )
2239 try ( RepositorySession session = getSessionFactory( ).createSession( ) )
2241 createArtifactWithGenericMetadataFacet( session );
2243 Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false );
2244 assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
2250 private static ProjectMetadata createProject( )
2252 return createProject( TEST_NAMESPACE );
2255 private static ProjectMetadata createProject( String ns )
2257 ProjectMetadata project = new ProjectMetadata( );
2258 project.setId( TEST_PROJECT );
2259 project.setNamespace( ns );
2263 private void createArtifactWithGenericMetadataFacet( RepositorySession session )
2264 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2266 createArtifactWithGenericMetadataFacet( session, 1 );
2269 private void createArtifactWithGenericMetadataFacet( RepositorySession session, int artifacts )
2270 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2272 MetadataFacet metadataFacet = new GenericMetadataFacet( );
2273 Map<String, String> properties = new HashMap<>( );
2274 properties.put( TEST_METADATA_KEY, TEST_METADATA_VALUE );
2275 metadataFacet.fromProperties( properties );
2276 createArtifactWithFacet( session, artifacts, null, metadataFacet );
2279 private void createArtifactWithMavenArtifactFacet( RepositorySession session )
2280 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2282 createArtifactWithMavenArtifactFacet( session, 1 );
2285 private void createArtifactWithMavenArtifactFacet( RepositorySession session, int artifacts )
2286 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2288 TestMetadataFacet facet = new TestMetadataFacet( TEST_METADATA_VALUE );
2289 createArtifactWithFacet( session, artifacts, facet, null );
2292 private void createArtifactWithFacet( RepositorySession session, int artifacts, MetadataFacet artifactFacet,
2293 MetadataFacet projectVersionMetadataFacet )
2294 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2296 for ( int i = 0; i < artifacts; i++ )
2298 ArtifactMetadata artifact = createArtifact( );
2299 if ( artifactFacet != null )
2301 artifact.addFacet( artifactFacet );
2303 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2305 if ( projectVersionMetadataFacet != null )
2307 ProjectVersionMetadata metadata =
2308 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
2309 metadata.addFacet( projectVersionMetadataFacet );
2310 metadata.setOrganization( TEST_ORGANIZATION );
2311 metadata.setUrl( TEST_URL );
2312 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
2317 protected void createArtifactWithData( RepositorySession session )
2318 throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
2320 ArtifactMetadata artifact = createArtifact( );
2321 getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
2322 ProjectVersionMetadata metadata =
2323 getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
2324 metadata.setOrganization( TEST_ORGANIZATION );
2325 metadata.setUrl( TEST_URL );
2327 getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
2331 private static ArtifactMetadata createArtifact( )
2333 return createArtifact( "jar" );
2336 private static ArtifactMetadata createArtifact( String type )
2338 ArtifactMetadata artifact = new ArtifactMetadata( );
2339 artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
2340 artifact.setWhenGathered( ZonedDateTime.now() );
2341 artifact.setNamespace( TEST_NAMESPACE );
2342 artifact.setProject( TEST_PROJECT );
2343 artifact.setRepositoryId( TEST_REPO_ID );
2344 artifact.setFileLastModified( System.currentTimeMillis( ) );
2345 artifact.setVersion( TEST_PROJECT_VERSION );
2346 artifact.setProjectVersion( TEST_PROJECT_VERSION );
2347 artifact.setMd5( TEST_MD5 );
2348 artifact.setSha1( TEST_SHA1 );
2352 private static class ArtifactMetadataComparator
2353 implements Comparator<ArtifactMetadata>
2356 public final int compare( ArtifactMetadata a, ArtifactMetadata b )
2358 return a.getProject( ).compareTo( b.getProject( ) );
2362 private static class KindOfRepositoryStatistics
2363 implements MetadataFacet
2365 private String value;
2369 static final String SCAN_TIMESTAMP_FORMAT = "yyyy/MM/dd/HHmmss.SSS";
2371 private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
2373 private KindOfRepositoryStatistics( String value, Date date )
2380 public String getName( )
2382 return createNameFormat( ).format( date );
2385 private static SimpleDateFormat createNameFormat( )
2387 SimpleDateFormat fmt = new SimpleDateFormat( SCAN_TIMESTAMP_FORMAT );
2388 fmt.setTimeZone( UTC_TIME_ZONE );
2393 public String getFacetId( )
2395 return KindOfRepositoryStatistics.class.getName( );
2399 public Map<String, String> toProperties( )
2401 return Collections.emptyMap( );
2405 public void fromProperties( Map<String, String> properties )
2411 private static class TestMetadataFacet
2412 implements MetadataFacet
2414 private String testFacetId;
2416 private Map<String, String> additionalProps;
2418 private String value;
2420 private String name = TEST_NAME;
2422 private TestMetadataFacet( String value )
2425 testFacetId = TEST_FACET_ID;
2430 private TestMetadataFacet( String facetId, String value )
2433 testFacetId = facetId;
2436 private TestMetadataFacet( String facetId, String value, String name)
2439 testFacetId = facetId;
2443 private TestMetadataFacet( String facetId, String value, String name, Map<String, String> additionalProps )
2445 this( facetId, value, name );
2446 this.additionalProps = additionalProps;
2450 private TestMetadataFacet( String facetId, String value, Map<String, String> additionalProps )
2452 this( facetId, value );
2453 this.additionalProps = additionalProps;
2457 public String getFacetId( )
2463 public String getName( )
2469 public Map<String, String> toProperties( )
2471 if ( value != null )
2473 if ( additionalProps == null )
2475 return Collections.singletonMap( "foo", value );
2479 Map<String, String> props = new HashMap<>( );
2480 props.put( "foo", value );
2482 for ( String key : additionalProps.keySet( ) )
2484 props.put( key, additionalProps.get( key ) );
2491 return Collections.emptyMap( );
2496 public void fromProperties( Map<String, String> properties )
2498 String value = properties.get( "foo" );
2499 if ( value != null )
2504 properties.remove( "foo" );
2506 if ( additionalProps == null )
2508 additionalProps = new HashMap<>( );
2511 for ( String key : properties.keySet( ) )
2513 additionalProps.put( key, properties.get( key ) );
2517 public String getValue( )
2523 public String toString( )
2525 return "TestMetadataFacet{ name='"+ name+ "' value='" + value + '\'' + '}';
2529 public boolean equals( Object o )
2535 if ( o == null || getClass( ) != o.getClass( ) )
2540 TestMetadataFacet that = (TestMetadataFacet) o;
2542 if ( value != null ? !value.equals( that.value ) : that.value != null )
2551 public int hashCode( )
2553 return value != null ? value.hashCode( ) : 0;