All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
at.spardat.xma.boot.test.VersionNumberTest Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
/*
* @(#) $Id: VersionNumberTest.java 2548 2008-04-21 13:06:32Z gub $
*/
package at.spardat.xma.boot.test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;
import at.spardat.xma.boot.cache.VersionNumber;
import at.spardat.xma.boot.transform.HashChecksum;
import junit.framework.Assert;
import junit.framework.TestCase;
/**
* @author s2877
* @since version_number
*/
public class VersionNumberTest extends TestCase {
public VersionNumberTest(String arg0) {
super(arg0);
}
public void testVersionNumber() {
Assert.assertEquals("1.2.3",new VersionNumber(1,2,3).toString());
}
public void testParse() {
Assert.assertEquals("1.4.0",VersionNumber.parse("clientrt_1.4.0.jar").toString());
Assert.assertEquals("5.0.123",VersionNumber.parse("subdir/krimiShell_5.0.123.jar").toString());
Assert.assertNull(VersionNumber.parse("itext-1.4.jar"));
Assert.assertEquals("1.4.6",VersionNumber.parse("itext-1.4.6.jar").toString());
}
public void testSearchPattern() {
Pattern search = VersionNumber.searchPattern("clientrt_1.4.0.jar");
String str = search.pattern();
Assert.assertTrue(search.matcher("clientrt_1.2.3.jar").matches());
Assert.assertTrue(!search.matcher("clientrt_1.2.3.jar.bak").matches());
Assert.assertTrue(!search.matcher("newclientrt_1.2.3.jar").matches());
Assert.assertTrue(search.matcher("clientrt_1.2.3.e5150d4822dd4415ed8a254c2bb84695.jar").matches());
Assert.assertTrue(search.matcher("clientrt_0.20.143.0483723e22dd44948372254c2bb84695.jar").matches());
Assert.assertTrue(!search.matcher("clientrumpelt_1.2.3.jar").matches());
Assert.assertEquals("^clientrt[_-](\\d+)\\.(\\d+)\\.(\\d+)\\.([0-9a-f]{32}\\.)?jar$",str);
search = VersionNumber.searchPattern("clientrt_1.4.0.optimized.jar");
str = search.pattern();
Assert.assertTrue(search.matcher("clientrt_1.2.3.optimized.jar").matches());
Assert.assertTrue(search.matcher("clientrt_1.2.3.optimized.e5150d4822dd4415ed8a254c2bb84695.jar").matches());
Assert.assertEquals("^clientrt[_-](\\d+)\\.(\\d+)\\.(\\d+)\\.optimized\\.([0-9a-f]{32}\\.)?jar$",str);
String hash = HashChecksum.calcCheckSum(new byte[]{13});
String newName = VersionNumber.insertHash("test_99.99.99.tst.jar",hash);
search = VersionNumber.searchPattern(newName);
str = search.pattern();
Assert.assertTrue(search.matcher("test_1.0.0.tst.jar").matches());
hash = HashChecksum.calcCheckSum(new byte[]{47,11});
String oldName = VersionNumber.insertHash("test_1.0.0.tst.jar",hash);
Assert.assertTrue(search.matcher(oldName).matches());
Assert.assertTrue(!search.matcher("test_1.0.0.tst1jar").matches());
}
public void testInsertAsDelta() throws MalformedURLException {
String delta = new VersionNumber(1,2,3).insertAsDelta(new URL("http://localhost:8080/testapp/clientrt/clientrt_1.4.0.jar")).toString();
Assert.assertEquals("http://localhost:8080/testapp/clientrt/clientrt_1.2.3-1.4.0.xdelta.jar",delta);
delta = new VersionNumber(1,2,3).insertAsDelta(new URL("http://localhost:8080/testapp/clientrt/clientrt-2.0.3.jar")).toString();
Assert.assertEquals("http://localhost:8080/testapp/clientrt/clientrt_1.2.3-2.0.3.xdelta.jar",delta);
}
public void testInsertHash() {
String name = VersionNumber.insertHash("clientrt_1.4.0.jar","e5150d4822dd4415ed8a254c2bb84695");
Assert.assertEquals("clientrt_1.4.0.e5150d4822dd4415ed8a254c2bb84695.jar",name);
name = VersionNumber.insertHash("clientrt.jar","e5150d4822dd4415ed8a254c2bb84695");
Assert.assertEquals("clientrt.e5150d4822dd4415ed8a254c2bb84695.jar",name);
name = VersionNumber.insertHash("clientrt","e5150d4822dd4415ed8a254c2bb84695");
Assert.assertEquals("clientrt.e5150d4822dd4415ed8a254c2bb84695",name);
}
public void testmatchWithoutHashPattern() {
String name = VersionNumber.insertHash("nativelib.dll","e5150d4822dd4415ed8a254c2bb84695");
Pattern pattern = VersionNumber.matchWithoutHashPattern(name);
Assert.assertTrue(pattern.matcher(name).find());
name = VersionNumber.insertHash("native.lib.dll","e5150d4822dd4415ed8a254c2bb84695");
pattern = VersionNumber.matchWithoutHashPattern(name);
Assert.assertTrue(pattern.matcher(name).find());
Assert.assertTrue(!pattern.matcher("native1lib.dll").find());
name = VersionNumber.insertHash("naive","e5150d4822dd4415ed8a254c2bb84695");
pattern = VersionNumber.matchWithoutHashPattern(name);
Assert.assertTrue(pattern.matcher(name).find());
name = "nativelib.dll";
pattern = VersionNumber.matchWithoutHashPattern(name);
Assert.assertTrue(pattern.matcher(name).find());
Assert.assertTrue(!pattern.matcher("nativelibXdll").find());
}
/*
* Class under test for String toString()
*/
public void testToString() {
Assert.assertEquals("1.2.3",new VersionNumber(1,2,3).toString());
}
public void testCompareTo() {
VersionNumber v1 = new VersionNumber(1,1,0);
VersionNumber v2 = new VersionNumber(1,2,0);
VersionNumber v2b = new VersionNumber(1,2,0);
Assert.assertTrue(v1.compareTo(v2)==-1);
Assert.assertTrue(v2.compareTo(v1)==1);
Assert.assertTrue(v2.compareTo(v2b)==0);
}
/**
* Method main.
*
* @param args
*/
public static void main(String[] args) {
junit.awtui.TestRunner.main(new String[] { VersionNumberTest.class.getName(), "-noloading" });
}
}