001package org.apache.maven.repository.metadata; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 005 * agreements. See the NOTICE file distributed with this work for additional information regarding 006 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance with the License. You may obtain a 008 * copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed under the License 013 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 014 * or implied. See the License for the specific language governing permissions and limitations under 015 * the License. 016 */ 017 018import org.apache.maven.artifact.ArtifactScopeEnum; 019import org.apache.maven.repository.metadata.ArtifactMetadata; 020import org.apache.maven.repository.metadata.GraphConflictResolver; 021import org.apache.maven.repository.metadata.MetadataGraph; 022import org.apache.maven.repository.metadata.MetadataGraphEdge; 023import org.apache.maven.repository.metadata.MetadataGraphVertex; 024import org.codehaus.plexus.PlexusTestCase; 025import org.codehaus.plexus.logging.Logger; 026 027/** 028 * 029 * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> 030 * 031 */ 032 033public class DefaultGraphConflictResolverTest 034extends PlexusTestCase 035{ 036 Logger log; 037 038 GraphConflictResolver resolver; 039 040 MetadataGraph graph; 041 042 MetadataGraphVertex v1; 043 MetadataGraphVertex v2; 044 MetadataGraphVertex v3; 045 MetadataGraphVertex v4; 046 //------------------------------------------------------------------------------------------ 047 @Override 048 protected void setUp() throws Exception 049 { 050 super.setUp(); 051 resolver = (GraphConflictResolver) lookup( GraphConflictResolver.ROLE, "default" ); 052 053 /* 054 * v2 055 * v1< 056 * v3-v4 057 * 058 */ 059 graph = new MetadataGraph( 4, 3 ); 060 v1 = graph.addVertex(new ArtifactMetadata("g","a1","1.0")); 061 graph.setEntry(v1); 062 v2 = graph.addVertex(new ArtifactMetadata("g","a2","1.0")); 063 v3 = graph.addVertex(new ArtifactMetadata("g","a3","1.0")); 064 v4 = graph.addVertex(new ArtifactMetadata("g","a4","1.0")); 065 066 // v1-->v2 067 graph.addEdge(v1, v2, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) ); 068 graph.addEdge(v1, v2, new MetadataGraphEdge( "1.2", true, null, null, 2, 2 ) ); 069 070 // v1-->v3 071 graph.addEdge(v1, v3, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) ); 072 graph.addEdge(v1, v3, new MetadataGraphEdge( "1.2", true, null, null, 4, 2 ) ); 073 074 // v3-->v4 075 graph.addEdge(v3, v4, new MetadataGraphEdge( "1.1", true, ArtifactScopeEnum.runtime, null, 2, 1 ) ); 076 graph.addEdge(v3, v4, new MetadataGraphEdge( "1.2", true, ArtifactScopeEnum.provided, null, 2, 2 ) ); 077 } 078 //------------------------------------------------------------------------------------------ 079 public void testCompileResolution() 080 throws Exception 081 { 082 MetadataGraph res; 083 084 res = resolver.resolveConflicts( graph, ArtifactScopeEnum.compile ); 085 086 assertNotNull("null graph after resolver", res ); 087 assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() ); 088 089 assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) ); 090 091 assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() ); 092 assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() ); 093 094 assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() ); 095 assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() ); 096 097 assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() ); 098 assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() ); 099 100 assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() ); 101 assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v4).get(0).getVersion() ); 102 } 103 //------------------------------------------------------------------------------------------ 104 public void testRuntimeResolution() 105 throws Exception 106 { 107 MetadataGraph res; 108 109 res = resolver.resolveConflicts( graph, ArtifactScopeEnum.runtime ); 110 111 assertNotNull("null graph after resolver", res ); 112 assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() ); 113 assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) ); 114 115 assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() ); 116 assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() ); 117 118 assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() ); 119 assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() ); 120 121 assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() ); 122 assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() ); 123 124 assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() ); 125 assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v4).get(0).getVersion() ); 126 } 127 //------------------------------------------------------------------------------------------ 128 public void testTestResolution() 129 throws Exception 130 { 131 MetadataGraph res; 132 133 res = resolver.resolveConflicts( graph, ArtifactScopeEnum.test ); 134 135 assertNotNull("null graph after resolver", res ); 136 assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() ); 137 assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) ); 138 139 assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() ); 140 assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() ); 141 142 assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() ); 143 assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() ); 144 145 assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() ); 146 assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() ); 147 148 assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() ); 149 assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v4).get(0).getVersion() ); 150 } 151 //------------------------------------------------------------------------------------------ 152 //------------------------------------------------------------------------------------------ 153}