001    package org.apache.maven.artifact.handler;
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    
022    import java.io.File;
023    import java.util.List;
024    
025    import org.codehaus.plexus.PlexusTestCase;
026    import org.codehaus.plexus.util.FileUtils;
027    
028    public class ArtifactHandlerTest
029        extends PlexusTestCase
030    {
031        public void testAptConsistency()
032            throws Exception
033        {
034            File apt = getTestFile( "src/site/apt/artifact-handlers.apt" );
035    
036            @SuppressWarnings( "unchecked" )
037            List<String> lines = FileUtils.loadFile( apt );
038    
039            for ( String line : lines )
040            {
041                if ( line.startsWith( "||" ) )
042                {
043                    String[] cols = line.split( "\\|\\|" );
044                    String[] expected =
045                        new String[] { "", "type", "extension", "packaging", "classifier", "language", "added to classpath",
046                            "includesDependencies", "" };
047    
048                    int i = 0;
049                    for ( String col : cols )
050                    {
051                        assertEquals( "Wrong column header", expected[i++], col.trim() );
052                    }
053                }
054                else if ( line.startsWith( "|" ) )
055                {
056                    String[] cols = line.split( "\\|" );
057    
058                    String type = trimApt( cols[1] );
059                    String extension = trimApt( cols[2], type );
060                    String packaging = trimApt( cols[3], type );
061                    String classifier = trimApt( cols[4] );
062                    String language = trimApt( cols[5] );
063                    String addedToClasspath = trimApt( cols[6] );
064                    String includesDependencies = trimApt( cols[7] );
065    
066                    ArtifactHandler handler = lookup( ArtifactHandler.class, type );
067                    assertEquals( type + " extension", handler.getExtension(), extension );
068                    assertEquals( type + " packaging", handler.getPackaging(), packaging );
069                    assertEquals( type + " classifier", handler.getClassifier(), classifier );
070                    assertEquals( type + " language", handler.getLanguage(), language );
071                    assertEquals( type + " addedToClasspath", handler.isAddedToClasspath() ? "true" : null, addedToClasspath );
072                    assertEquals( type + " includesDependencies", handler.isIncludesDependencies() ? "true" : null, includesDependencies );
073                }
074            }
075        }
076    
077        private String trimApt( String content, String type )
078        {
079            String value = trimApt( content );
080            return "= type".equals( value ) ? type : value;
081        }
082    
083        private String trimApt( String content )
084        {
085            content = content.replace( '<', ' ' ).replace( '>', ' ' ).trim();
086    
087            return ( content.length() == 0 ) ? null : content;
088        }
089    }