1 package org.apache.maven.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
22 import org.apache.commons.io.IOUtils;
25 import java.io.FileInputStream;
26 import java.io.IOException;
27 import java.util.zip.GZIPInputStream;
29 import junit.framework.TestCase;
36 public class BannerTest
39 private static final String eol = System.getProperty("line.separator");
41 private void assertEncodeDecode( String encoded, String decoded )
43 assertEquals( "Encoding: ", encoded, Banner.encode( decoded ) );
44 assertEquals( "Decoding: ", decoded, Banner.decode( encoded ) );
47 public void testEncodeDecode()
49 assertEncodeDecode( "[$10 ]", "[ ]" );
50 assertEncodeDecode( "$$$5_$n$5_", "$_____"+eol+"_____" );
51 assertEncodeDecode( "$${Refgjuvyr}", "${Erstwhile}" );
54 public void testInjectVersion()
56 assertEquals( "[ 1.0 ]", Banner.injectVersion( "[#####]", "1.0" ) );
57 assertEquals( ".\\ 1.0-SNAPSHOT \\._____", Banner.injectVersion( ".\\################\\._____",
59 assertEquals( "Archiva:\"+eol+\" ( 1.0-alpha-1 )", Banner
60 .injectVersion( "Archiva:\"+eol+\" (##############)", "1.0-alpha-1" ) );
63 public void testGetBanner()
66 String version = "1.0-alpha-1-SNAPSHOT";
67 String banner = Banner.getBanner( version );
68 assertNotNull( "Banner should not be null.", banner );
69 assertTrue( "Banner contains version.", banner.indexOf( version ) > 0 );
71 /* Want to make a new banner?
73 * 1) Edit the src/test/resources/banner.gz file.
74 * 2) Save it compressed.
75 * 3) Add (to this test method) ...
76 * System.out.println( "\"" + Banner.encode( getRawBanner() ) + "\"" );
78 * 5) Copy / Paste the encoded form into the Banner.getBanner() method.
82 public String getRawBanner()
85 File gzBanner = new File( "src/test/resources/banner.gz" );
86 assertTrue( "File [" + gzBanner.getPath() + "] not found.", gzBanner.exists() );
87 FileInputStream fis = new FileInputStream( gzBanner );
88 GZIPInputStream gzis = new GZIPInputStream( fis );
89 return IOUtils.toString( gzis );