View Javadoc

1   /*
2    * Copyright 2011 Vincent Behar
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.rundeck.api.parser;
17  
18  import java.io.InputStream;
19  import java.util.Date;
20  import org.dom4j.Document;
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.rundeck.api.domain.RundeckSystemInfo;
24  
25  /**
26   * Test the {@link SystemInfoParser}
27   * 
28   * @author Vincent Behar
29   */
30  public class SystemInfoParserTest {
31  
32      @Test
33      public void parseProject() throws Exception {
34          InputStream input = getClass().getResourceAsStream("system-info.xml");
35          Document document = ParserHelper.loadDocument(input);
36  
37          RundeckSystemInfo info = new SystemInfoParser("result/system").parseXmlNode(document);
38  
39          Assert.assertEquals(new Date(1310051857605L), info.getDate());
40          Assert.assertEquals("1.2.1", info.getVersion());
41          Assert.assertEquals("1.2.1-1", info.getBuild());
42          Assert.assertEquals("strongbad", info.getNode());
43          Assert.assertEquals("/opt/rundeck/rundeck-1.2.1", info.getBaseDir());
44          Assert.assertEquals("i386", info.getOsArch());
45          Assert.assertEquals("Linux", info.getOsName());
46          Assert.assertEquals("2.6.35-30-generic-pae", info.getOsVersion());
47          Assert.assertEquals("Java HotSpot(TM) Server VM", info.getJvmName());
48          Assert.assertEquals("Sun Microsystems Inc.", info.getJvmVendor());
49          Assert.assertEquals("19.1-b02", info.getJvmVersion());
50          Assert.assertEquals(new Date(1310032513574L), info.getStartDate());
51          Assert.assertEquals(new Long(19344031), info.getUptimeInMillis());
52          Assert.assertEquals("5 hours 22 minutes 24 seconds", info.getUptime());
53          Assert.assertEquals("0.1 %", info.getCpuLoadAverage());
54          Assert.assertEquals(new Long(954466304), info.getMaxMemoryInBytes());
55          Assert.assertEquals(new Long(159576592), info.getFreeMemoryInBytes());
56          Assert.assertEquals(new Long(271384576), info.getTotalMemoryInBytes());
57          Assert.assertEquals(new Integer(0), info.getRunningJobs());
58          Assert.assertEquals(new Integer(25), info.getActiveThreads());
59      }
60  
61  }