1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.jk.status;
19 import java.io.IOException;
20 import java.io.StringReader;
22 import junit.framework.TestCase;
24 import org.apache.tomcat.util.digester.Digester;
25 import org.xml.sax.SAXException;
28 * @author Peter Rossbach
31 public class JkStatusParserTest extends TestCase {
33 public void testDigester() throws IOException, SAXException {
34 Digester digester = JkStatusParser.createDigester();
35 String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
36 + "<jk:status xmlns:jk=\"http://tomcat.apache.org\">"
37 + "<jk:server name=\"localhost\" port=\"80\" software=\"Apache/2.0.58 (Unix) mod_jk/1.2.19\" version=\"1.2.19\" />"
39 + "<jk:balancer id=\"0\" name=\"loadbalancer\" type=\"lb\" sticky=\"True\" stickyforce=\"False\" retries=\"2\" recover=\"60\" >"
40 + "<jk:member id=\"0\" name=\"node1\" type=\"ajp13\" host=\"localhost\" port=\"9012\" address=\"127.0.0.1:9012\" activation=\"ACT\" state=\"OK/IDLE\" distance=\"0\" lbfactor=\"1\" lbmult=\"1\" lbvalue=\"0\" elected=\"0\" errors=\"0\" transferred=\"0\" readed=\"0\" busy=\"0\" maxbusy=\"0\" jvm_route=\"node1\" />"
41 + "<jk:member id=\"0\" name=\"node2\" type=\"ajp13\" host=\"localhost\" port=\"9022\" address=\"127.0.0.1:9022\" activation=\"ACT\" state=\"OK/IDLE\" distance=\"0\" lbfactor=\"1\" lbmult=\"1\" lbvalue=\"0\" elected=\"0\" errors=\"0\" transferred=\"0\" readed=\"0\" busy=\"0\" maxbusy=\"0\" jvm_route=\"node2\" />"
42 + "<jk:map type=\"Wildchar\" uri=\"/ClusterTest/*\" context=\"/ClusterTest/*\" />"
43 + "<jk:map type=\"Exact\" uri=\"/ClusterTest\" context=\"/ClusterTest\" />"
44 + "<jk:map type=\"Wildchar\" uri=\"/myapps/*\" context=\"/myapps/*\" />"
45 + "<jk:map type=\"Exact\" uri=\"/myapps\" context=\"/myapps\" />"
50 StringReader reader = new StringReader(example);
51 JkStatus status = (JkStatus) digester
53 assertNotNull(status);
54 assertNotNull(status.getServer());
55 assertEquals(1,status.getBalancers().size());
56 JkBalancer balancer = (JkBalancer)status.getBalancers().get(0);
57 assertEquals(2,balancer.getBalancerMembers().size());
58 assertEquals("node1",((JkBalancerMember)balancer.getBalancerMembers().get(0)).getName());
59 assertEquals("node2",((JkBalancerMember)balancer.getBalancerMembers().get(1)).getName());
60 assertEquals(4,balancer.getBalancerMappings().size());