1 package com.atlassian.seraph.util;
2
3 import junit.framework.TestCase;
4
5 import static com.atlassian.seraph.util.ServerInformationParser.ServerInformation;
6
7 public class TestServerInformationParser extends TestCase
8 {
9 public void testNameVersionWithoutOtherInformation()
10 {
11 ServerInformation info = ServerInformationParser.parse("Apache Tomcat/6.0.20");
12 assertEquals("Apache Tomcat", info.getName());
13 assertEquals("6.0.20", info.getVersion());
14 assertEquals(null, info.getOtherInformation());
15 assertEquals(true, info.isApacheTomcat());
16 }
17
18 public void testNameVersionWithOtherInformation()
19 {
20 ServerInformation info = ServerInformationParser.parse("Apache Tomcat/6.0.20 (JDK 1.6.0)");
21 assertEquals("Apache Tomcat", info.getName());
22 assertEquals("6.0.20", info.getVersion());
23 assertEquals("JDK 1.6.0", info.getOtherInformation());
24 assertEquals(true, info.isApacheTomcat());
25 }
26 public void testNonApacheTomcatServer()
27 {
28 ServerInformation info = ServerInformationParser.parse("Other Application Server/1.2.3");
29 assertEquals(false, info.isApacheTomcat());
30 }
31
32 public void testMalformedStringFails()
33 {
34 try
35 {
36 ServerInformationParser.parse("malformed server information string");
37 fail("Exception should have been thrown upon detecting illegal argument");
38 }
39 catch (IllegalArgumentException e)
40 {
41 assertTrue(true);
42 }
43 }
44 }