001package org.eclipse.aether.util.graph.transformer;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 * 
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 * 
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.junit.Assert.*;
023
024import org.eclipse.aether.collection.DependencyGraphTransformer;
025import org.eclipse.aether.graph.DependencyNode;
026import org.eclipse.aether.internal.test.util.DependencyGraphParser;
027import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
028import org.junit.Test;
029
030/**
031 */
032public class JavaDependencyContextRefinerTest
033    extends AbstractDependencyGraphTransformerTest
034{
035
036    @Override
037    protected DependencyGraphTransformer newTransformer()
038    {
039        return new JavaDependencyContextRefiner();
040    }
041
042    @Override
043    protected DependencyGraphParser newParser()
044    {
045        return new DependencyGraphParser( "transformer/context-refiner/" );
046    }
047
048    @Test
049    public void testDoNotRefineOtherContext()
050        throws Exception
051    {
052        DependencyNode node = parseLiteral( "gid:aid:cls:ver" );
053        node.setRequestContext( "otherContext" );
054
055        DependencyNode refinedNode = transform( node );
056        assertEquals( node, refinedNode );
057    }
058
059    @Test
060    public void testRefineToCompile()
061        throws Exception
062    {
063        String expected = "project/compile";
064
065        DependencyNode node = parseLiteral( "gid:aid:ver compile" );
066        node.setRequestContext( "project" );
067        DependencyNode refinedNode = transform( node );
068        assertEquals( expected, refinedNode.getRequestContext() );
069
070        node = parseLiteral( "gid:aid:ver system" );
071        node.setRequestContext( "project" );
072        refinedNode = transform( node );
073        assertEquals( expected, refinedNode.getRequestContext() );
074
075        node = parseLiteral( "gid:aid:ver provided" );
076        node.setRequestContext( "project" );
077        refinedNode = transform( node );
078        assertEquals( expected, refinedNode.getRequestContext() );
079    }
080
081    @Test
082    public void testRefineToTest()
083        throws Exception
084    {
085        String expected = "project/test";
086
087        DependencyNode node = parseLiteral( "gid:aid:ver test" );
088        node.setRequestContext( "project" );
089        DependencyNode refinedNode = transform( node );
090        assertEquals( expected, refinedNode.getRequestContext() );
091    }
092
093    @Test
094    public void testRefineToRuntime()
095        throws Exception
096    {
097        String expected = "project/runtime";
098
099        DependencyNode node = parseLiteral( "gid:aid:ver runtime" );
100        node.setRequestContext( "project" );
101        DependencyNode refinedNode = transform( node );
102        assertEquals( expected, refinedNode.getRequestContext() );
103    }
104
105    @Test
106    public void testDoNotRefineUnknownScopes()
107        throws Exception
108    {
109        String expected = "project";
110
111        DependencyNode node = parseLiteral( "gid:aid:ver unknownScope" );
112        node.setRequestContext( "project" );
113        DependencyNode refinedNode = transform( node );
114        assertEquals( expected, refinedNode.getRequestContext() );
115    }
116
117}