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.apache.maven.repository.metadata;
20  
21  import javax.inject.Inject;
22  
23  import org.apache.maven.artifact.ArtifactScopeEnum;
24  import org.codehaus.plexus.testing.PlexusTest;
25  import org.junit.jupiter.api.BeforeEach;
26  import org.junit.jupiter.api.Test;
27  
28  import static org.junit.jupiter.api.Assertions.assertEquals;
29  import static org.junit.jupiter.api.Assertions.assertNotNull;
30  
31  /**
32   *
33   *
34   */
35  @PlexusTest
36  @Deprecated
37  class DefaultClasspathTransformationTestType {
38      @Inject
39      ClasspathTransformation transform;
40  
41      MetadataGraph graph;
42  
43      MetadataGraphVertex v1;
44      MetadataGraphVertex v2;
45      MetadataGraphVertex v3;
46      MetadataGraphVertex v4;
47  
48      // ------------------------------------------------------------------------------------------
49      @BeforeEach
50      void setUp() throws Exception {
51          graph = new MetadataGraph(4, 3);
52          /*
53           *       v2
54           *   v1<
55           *       v3-v4
56           *
57           */
58          v1 = graph.addVertex(new ArtifactMetadata("g", "a1", "1.0"));
59          graph.setEntry(v1);
60          v2 = graph.addVertex(new ArtifactMetadata("g", "a2", "1.0"));
61          v3 = graph.addVertex(new ArtifactMetadata("g", "a3", "1.0"));
62          v4 = graph.addVertex(new ArtifactMetadata("g", "a4", "1.0"));
63  
64          // v1-->v2
65          graph.addEdge(v1, v2, new MetadataGraphEdge("1.1", true, null, null, 2, 1));
66          graph.addEdge(v1, v2, new MetadataGraphEdge("1.2", true, null, null, 2, 2));
67  
68          // v1-->v3
69          graph.addEdge(v1, v3, new MetadataGraphEdge("1.1", true, null, null, 2, 1));
70          graph.addEdge(v1, v3, new MetadataGraphEdge("1.2", true, null, null, 4, 2));
71  
72          // v3-->v4
73          graph.addEdge(v3, v4, new MetadataGraphEdge("1.1", true, ArtifactScopeEnum.runtime, null, 2, 2));
74          graph.addEdge(v3, v4, new MetadataGraphEdge("1.2", true, ArtifactScopeEnum.test, null, 2, 2));
75      }
76  
77      // ------------------------------------------------------------------------------------------
78      @Test
79      void testCompileClasspathTransform() throws Exception {
80          ClasspathContainer res;
81  
82          res = transform.transform(graph, ArtifactScopeEnum.compile, false);
83  
84          assertNotNull(res, "null classpath container after compile transform");
85          assertNotNull(res.getClasspath(), "null classpath after compile transform");
86          assertEquals(3, res.getClasspath().size(), "compile classpath should have 3 entries");
87      }
88  
89      // ------------------------------------------------------------------------------------------
90      @Test
91      void testRuntimeClasspathTransform() throws Exception {
92          ClasspathContainer res;
93  
94          res = transform.transform(graph, ArtifactScopeEnum.runtime, false);
95  
96          assertNotNull(res, "null classpath container after runtime transform");
97          assertNotNull(res.getClasspath(), "null classpath after runtime transform");
98          assertEquals(4, res.getClasspath().size(), "runtime classpath should have 4 entries");
99  
100         ArtifactMetadata md = res.getClasspath().get(3);
101         assertEquals("1.1", md.getVersion(), "runtime artifact version should be 1.1");
102     }
103 
104     // ------------------------------------------------------------------------------------------
105     @Test
106     void testTestClasspathTransform() throws Exception {
107         ClasspathContainer res;
108 
109         res = transform.transform(graph, ArtifactScopeEnum.test, false);
110 
111         assertNotNull(res, "null classpath container after test transform");
112         assertNotNull(res.getClasspath(), "null classpath after test transform");
113         assertEquals(4, res.getClasspath().size(), "test classpath should have 4 entries");
114 
115         ArtifactMetadata md = res.getClasspath().get(3);
116         assertEquals("1.2", md.getVersion(), "test artifact version should be 1.2");
117     }
118     // ------------------------------------------------------------------------------------------
119     // ------------------------------------------------------------------------------------------
120 }