001package org.apache.maven.wagon.tck.http;
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 junit.framework.Assert.assertEquals;
023import static org.codehaus.plexus.util.FileUtils.fileRead;
024
025import org.codehaus.plexus.util.IOUtil;
026
027import java.io.File;
028import java.io.IOException;
029import java.io.InputStream;
030
031/**
032 * 
033 */
034public final class Assertions
035{
036
037    public static void assertFileContentsFromResource( final String resourceBase, final String resourceName,
038                                                       final File output, final String whyWouldItFail )
039        throws IOException
040    {
041        String content = readResource( resourceBase, resourceName );
042        String test = fileRead( output );
043
044        assertEquals( whyWouldItFail, content, test );
045    }
046
047    private static String readResource( final String base, final String name )
048        throws IOException
049    {
050        String url = base;
051        if ( !url.endsWith( "/" ) && !name.startsWith( "/" ) )
052        {
053            url += "/";
054        }
055        url += name;
056
057        ClassLoader cloader = Thread.currentThread().getContextClassLoader();
058        InputStream stream = cloader.getResourceAsStream( url );
059
060        if ( stream == null )
061        {
062            return null;
063        }
064
065        return IOUtil.toString( stream );
066    }
067
068}