1 package org.apache.archiva.web.startup;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.util.zip.GZIPInputStream;
27 import org.apache.commons.io.IOUtils;
29 import junit.framework.TestCase;
30 import org.apache.archiva.test.ArchivaBlockJUnit4ClassRunner;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
38 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
39 public class BannerTest
42 private static final String eol = System.getProperty( "line.separator" );
44 private void assertEncodeDecode( String encoded, String decoded )
46 assertEquals( "Encoding: ", encoded, Banner.encode( decoded ) );
47 assertEquals( "Decoding: ", decoded, Banner.decode( encoded ) );
51 public void testEncodeDecode()
53 assertEncodeDecode( "[$10 ]", "[ ]" );
54 assertEncodeDecode( "$$$5_$n$5_", "$_____" + eol + "_____" );
55 assertEncodeDecode( "$${Refgjuvyr}", "${Erstwhile}" );
59 public void testInjectVersion()
61 assertEquals( "[ 1.0 ]", Banner.injectVersion( "[#####]", "1.0" ) );
62 assertEquals( ".\\ 1.0-SNAPSHOT \\._____",
63 Banner.injectVersion( ".\\################\\._____", "1.0-SNAPSHOT" ) );
64 assertEquals( "Archiva:\"+eol+\" ( 1.0-alpha-1 )",
65 Banner.injectVersion( "Archiva:\"+eol+\" (##############)", "1.0-alpha-1" ) );
69 public void testGetBanner()
72 String version = "1.0-alpha-1-SNAPSHOT";
73 String banner = Banner.getBanner( version );
74 assertNotNull( "Banner should not be null.", banner );
75 assertTrue( "Banner contains version.", banner.indexOf( version ) > 0 );
77 /* Want to make a new banner?
79 * 1) Edit the src/test/resources/banner.gz file.
80 * 2) Save it compressed.
81 * 3) Add (to this test method) ...
82 * System.out.println( "\"" + Banner.encode( getRawBanner() ) + "\"" );
84 * 5) Copy / Paste the encoded form into the Banner.getBanner() method.
88 public String getRawBanner()
91 File gzBanner = new File( "src/test/resources/banner.gz" );
92 assertTrue( "File [" + gzBanner.getPath() + "] not found.", gzBanner.exists() );
93 FileInputStream fis = new FileInputStream( gzBanner );
94 GZIPInputStream gzis = new GZIPInputStream( fis );
95 String str = IOUtils.toString( gzis );
96 IOUtils.closeQuietly( gzis );