001 package org.apache.maven.repository.metadata; 002 003 import org.apache.maven.artifact.ArtifactScopeEnum; 004 import org.apache.maven.repository.metadata.ArtifactMetadata; 005 import org.apache.maven.repository.metadata.GraphConflictResolver; 006 import org.apache.maven.repository.metadata.MetadataGraph; 007 import org.apache.maven.repository.metadata.MetadataGraphEdge; 008 import org.apache.maven.repository.metadata.MetadataGraphVertex; 009 import org.codehaus.plexus.PlexusTestCase; 010 import org.codehaus.plexus.logging.Logger; 011 012 /** 013 * 014 * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> 015 * 016 */ 017 018 public class DefaultGraphConflictResolverTest 019 extends PlexusTestCase 020 { 021 Logger log; 022 023 GraphConflictResolver resolver; 024 025 MetadataGraph graph; 026 027 MetadataGraphVertex v1; 028 MetadataGraphVertex v2; 029 MetadataGraphVertex v3; 030 MetadataGraphVertex v4; 031 //------------------------------------------------------------------------------------------ 032 @Override 033 protected void setUp() throws Exception 034 { 035 super.setUp(); 036 resolver = (GraphConflictResolver) lookup( GraphConflictResolver.ROLE, "default" ); 037 038 /* 039 * v2 040 * v1< 041 * v3-v4 042 * 043 */ 044 graph = new MetadataGraph( 4, 3 ); 045 v1 = graph.addVertex(new ArtifactMetadata("g","a1","1.0")); 046 graph.setEntry(v1); 047 v2 = graph.addVertex(new ArtifactMetadata("g","a2","1.0")); 048 v3 = graph.addVertex(new ArtifactMetadata("g","a3","1.0")); 049 v4 = graph.addVertex(new ArtifactMetadata("g","a4","1.0")); 050 051 // v1-->v2 052 graph.addEdge(v1, v2, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) ); 053 graph.addEdge(v1, v2, new MetadataGraphEdge( "1.2", true, null, null, 2, 2 ) ); 054 055 // v1-->v3 056 graph.addEdge(v1, v3, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) ); 057 graph.addEdge(v1, v3, new MetadataGraphEdge( "1.2", true, null, null, 4, 2 ) ); 058 059 // v3-->v4 060 graph.addEdge(v3, v4, new MetadataGraphEdge( "1.1", true, ArtifactScopeEnum.runtime, null, 2, 1 ) ); 061 graph.addEdge(v3, v4, new MetadataGraphEdge( "1.2", true, ArtifactScopeEnum.provided, null, 2, 2 ) ); 062 } 063 //------------------------------------------------------------------------------------------ 064 public void testCompileResolution() 065 throws Exception 066 { 067 MetadataGraph res; 068 069 res = resolver.resolveConflicts( graph, ArtifactScopeEnum.compile ); 070 071 assertNotNull("null graph after resolver", res ); 072 assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() ); 073 074 assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) ); 075 076 assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() ); 077 assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() ); 078 079 assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() ); 080 assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() ); 081 082 assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() ); 083 assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() ); 084 085 assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() ); 086 assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v4).get(0).getVersion() ); 087 } 088 //------------------------------------------------------------------------------------------ 089 public void testRuntimeResolution() 090 throws Exception 091 { 092 MetadataGraph res; 093 094 res = resolver.resolveConflicts( graph, ArtifactScopeEnum.runtime ); 095 096 assertNotNull("null graph after resolver", res ); 097 assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() ); 098 assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) ); 099 100 assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() ); 101 assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() ); 102 103 assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() ); 104 assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() ); 105 106 assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() ); 107 assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() ); 108 109 assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() ); 110 assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v4).get(0).getVersion() ); 111 } 112 //------------------------------------------------------------------------------------------ 113 public void testTestResolution() 114 throws Exception 115 { 116 MetadataGraph res; 117 118 res = resolver.resolveConflicts( graph, ArtifactScopeEnum.test ); 119 120 assertNotNull("null graph after resolver", res ); 121 assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() ); 122 assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) ); 123 124 assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() ); 125 assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() ); 126 127 assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() ); 128 assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() ); 129 130 assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() ); 131 assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() ); 132 133 assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() ); 134 assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v4).get(0).getVersion() ); 135 } 136 //------------------------------------------------------------------------------------------ 137 //------------------------------------------------------------------------------------------ 138 }