View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.internal.impl.filter;
20  
21  import java.io.IOException;
22  import java.io.UncheckedIOException;
23  import java.nio.file.Files;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import org.eclipse.aether.DefaultRepositorySystemSession;
28  import org.eclipse.aether.artifact.Artifact;
29  import org.eclipse.aether.internal.impl.DefaultRepositorySystemLifecycle;
30  import org.eclipse.aether.repository.RemoteRepository;
31  import org.eclipse.aether.resolution.ArtifactRequest;
32  import org.eclipse.aether.resolution.ArtifactResult;
33  
34  /**
35   * UT for {@link GroupIdRemoteRepositoryFilterSource}.
36   */
37  public class GroupIdRemoteRepositoryFilterSourceTest extends RemoteRepositoryFilterSourceTestSupport {
38      private GroupIdRemoteRepositoryFilterSource groupIdRemoteRepositoryFilterSource;
39  
40      @Override
41      protected GroupIdRemoteRepositoryFilterSource getRemoteRepositoryFilterSource(
42              DefaultRepositorySystemSession session, RemoteRepository remoteRepository) {
43          return groupIdRemoteRepositoryFilterSource =
44                  new GroupIdRemoteRepositoryFilterSource(new DefaultRepositorySystemLifecycle());
45      }
46  
47      @Override
48      protected void enableSource(DefaultRepositorySystemSession session) {
49          session.setConfigProperty(
50                  "aether.remoteRepositoryFilter." + GroupIdRemoteRepositoryFilterSource.NAME, Boolean.TRUE.toString());
51      }
52  
53      protected void allowArtifact(
54              DefaultRepositorySystemSession session, RemoteRepository remoteRepository, Artifact artifact) {
55          DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
56          try {
57              Artifact resolvedArtifact =
58                      artifact.setFile(Files.createTempFile("test", "tmp").toFile());
59              ArtifactResult artifactResult = new ArtifactResult(
60                      new ArtifactRequest(resolvedArtifact, Collections.singletonList(remoteRepository), "context"));
61              artifactResult.setArtifact(resolvedArtifact);
62              artifactResult.setRepository(remoteRepository);
63              List<ArtifactResult> artifactResults = Collections.singletonList(artifactResult);
64              enableSource(newSession);
65              newSession.setConfigProperty(
66                      "aether.remoteRepositoryFilter." + GroupIdRemoteRepositoryFilterSource.NAME + ".record",
67                      Boolean.TRUE.toString());
68              groupIdRemoteRepositoryFilterSource.postProcess(newSession, artifactResults);
69          } catch (IOException e) {
70              throw new UncheckedIOException(e);
71          }
72      }
73  }