View Javadoc
1   package org.apache.archiva.webtest.memory;
2   
3   /*
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
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Collections;
25  import java.util.Date;
26  import java.util.List;
27  
28  import org.apache.archiva.metadata.model.ArtifactMetadata;
29  import org.apache.archiva.metadata.repository.AbstractMetadataRepository;
30  
31  public class TestMetadataRepository
32      extends AbstractMetadataRepository
33  {
34      private static final String TEST_REPO = "test-repo";
35  
36      private static final String TEST_NAMESPACE = "org.apache.archiva";
37  
38      private List<ArtifactMetadata> artifacts = new ArrayList<>();
39  
40      private List<String> versions = new ArrayList<>();
41  
42      public TestMetadataRepository()
43      {
44          Date whenGathered = new Date( 123456789 );
45  
46          addArtifact( "artifact-one", "1.0", whenGathered );
47          addArtifact( "artifact-one", "1.1", whenGathered );
48          addArtifact( "artifact-one", "2.0", whenGathered );
49          addArtifact( "artifact-two", "1.0.1", whenGathered );
50          addArtifact( "artifact-two", "1.0.2", whenGathered );
51          addArtifact( "artifact-two", "1.0.3-SNAPSHOT", whenGathered );
52          addArtifact( "artifact-three", "2.0-SNAPSHOT", whenGathered );
53          addArtifact( "artifact-four", "1.1-beta-2", whenGathered );
54      }
55  
56      private void addArtifact( String projectId, String projectVersion, Date whenGathered )
57      {
58          ArtifactMetadata artifact = new ArtifactMetadata();
59          artifact.setFileLastModified( System.currentTimeMillis() );
60          artifact.setNamespace( TEST_NAMESPACE );
61          artifact.setProjectVersion( projectVersion );
62          artifact.setVersion( projectVersion );
63          artifact.setId( projectId + "-" + projectVersion + ".jar" );
64          artifact.setProject( projectId );
65          artifact.setRepositoryId( TEST_REPO );
66          artifact.setWhenGathered( whenGathered );
67          artifacts.add( artifact );
68  
69          versions.add( projectVersion );
70      }
71  
72      @Override
73      public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
74      {
75          return versions;
76      }
77  
78      @Override
79      public List<String> getMetadataFacets( String repodId, String facetId )
80      {
81          return Collections.emptyList();
82      }
83  
84      @Override
85      public void removeMetadataFacet( String repoId, String facetId, String name )
86      {
87          //To change body of implemented methods use File | Settings | File Templates.
88      }
89  
90      @Override
91      public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
92      {
93          return artifacts;
94      }
95  
96      @Override
97      public Collection<String> getRepositories()
98      {
99          return Collections.singletonList( TEST_REPO );
100     }
101 
102     @Override
103     public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
104                                                       String projectVersion )
105     {
106         return artifacts;
107     }
108 
109     @Override
110     public List<ArtifactMetadata> getArtifacts( String repositoryId )
111     {
112         return artifacts;
113     }
114 
115 }