JavaDependencyContextRefiner implements DependencyGraphTransformer { public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ) throws RepositoryException { String ctx = node.getRequestContext(); if ( "project".equals( ctx ) ) { String scope = getClasspathScope( node ); if ( scope != null ) { ctx += '/' + scope; node.setRequestContext( ctx ); } } for ( DependencyNode child : node.getChildren() ) { transformGraph( child, context ); } return node; }  DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context );  }
@Test public void testDoNotRefineOtherContext() throws IOException, RepositoryException { DependencyNode node = parser.parseLiteral( "gid:aid:ext:cls:ver" ); node.setRequestContext( "otherContext" ); DependencyNode refinedNode = refiner.transformGraph( node, context ); assertEquals( node, refinedNode ); }
@Test public void testRefineToCompile() throws IOException, RepositoryException { String expected = "project/compile"; DependencyNode node = parser.parseLiteral( "gid:aid:ext:ver:compile" ); node.setRequestContext( "project" ); DependencyNode refinedNode = refiner.transformGraph( node, context ); assertEquals( expected, refinedNode.getRequestContext() ); node = parser.parseLiteral( "gid:aid:ext:ver:system" ); node.setRequestContext( "project" ); refinedNode = refiner.transformGraph( node, context ); assertEquals( expected, refinedNode.getRequestContext() ); node = parser.parseLiteral( "gid:aid:ext:ver:provided" ); node.setRequestContext( "project" ); refinedNode = refiner.transformGraph( node, context ); assertEquals( expected, refinedNode.getRequestContext() ); }
@Test public void testRefineToTest() throws IOException, RepositoryException { String expected = "project/test"; DependencyNode node = parser.parseLiteral( "gid:aid:ext:ver:test" ); node.setRequestContext( "project" ); DependencyNode refinedNode = refiner.transformGraph( node, context ); assertEquals( expected, refinedNode.getRequestContext() ); }
@Test public void testRefineToRuntime() throws IOException, RepositoryException { String expected = "project/runtime"; DependencyNode node = parser.parseLiteral( "gid:aid:ext:ver:runtime" ); node.setRequestContext( "project" ); DependencyNode refinedNode = refiner.transformGraph( node, context ); assertEquals( expected, refinedNode.getRequestContext() ); }
@Test public void testDoNotRefineUnknownScopes() throws IOException, RepositoryException { String expected = "project"; DependencyNode node = parser.parseLiteral( "gid:aid:ext:ver:unknownScope" ); node.setRequestContext( "project" ); DependencyNode refinedNode = refiner.transformGraph( node, context ); assertEquals( expected, refinedNode.getRequestContext() ); }