001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.protocol.http.parser;
020:
021: import org.apache.jmeter.config.Argument;
022: import org.apache.jmeter.junit.JMeterTestCase;
023: import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
024: import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
025:
026: // TODO: need more tests
027: public final class TestHtmlParsingUtils extends JMeterTestCase {
028:
029: public TestHtmlParsingUtils(String name) {
030: super (name);
031: }
032:
033: protected void setUp() {
034: }
035:
036: public void testGetParser() throws Exception {
037: HtmlParsingUtils.getParser();
038: }
039:
040: public void testGetDom() throws Exception {
041: HtmlParsingUtils.getDOM("<HTML></HTML>");
042: HtmlParsingUtils.getDOM("");
043: }
044:
045: public void testIsArgumentMatched() throws Exception {
046: Argument arg = new Argument();
047: Argument argp = new Argument();
048: assertTrue(HtmlParsingUtils.isArgumentMatched(arg, argp));
049:
050: arg = new Argument("test", "abcd");
051: argp = new Argument("test", "a.*d");
052: assertTrue(HtmlParsingUtils.isArgumentMatched(arg, argp));
053:
054: arg = new Argument("test", "abcd");
055: argp = new Argument("test", "a.*e");
056: assertFalse(HtmlParsingUtils.isArgumentMatched(arg, argp));
057: }
058:
059: public void testIsAnchorMatched() throws Exception {
060: HTTPSamplerBase target = new HTTPNullSampler();
061: HTTPSamplerBase pattern = new HTTPNullSampler();
062:
063: assertTrue(HtmlParsingUtils.isAnchorMatched(target, pattern));
064:
065: target.setProtocol("http:");
066: assertFalse(HtmlParsingUtils.isAnchorMatched(target, pattern));
067:
068: pattern.setProtocol(".*");
069: assertTrue(HtmlParsingUtils.isAnchorMatched(target, pattern));
070:
071: target.setDomain("a.b.c");
072: assertTrue(HtmlParsingUtils.isAnchorMatched(target, pattern));
073:
074: pattern.setDomain(".*");
075: assertTrue(HtmlParsingUtils.isAnchorMatched(target, pattern));
076:
077: target.setPath("/abc");
078: assertFalse(HtmlParsingUtils.isAnchorMatched(target, pattern));
079:
080: pattern.setPath(".*");
081: assertTrue(HtmlParsingUtils.isAnchorMatched(target, pattern));
082:
083: target.addArgument("param2", "value2", "=");
084: assertTrue(HtmlParsingUtils.isAnchorMatched(target, pattern));
085:
086: pattern.addArgument("param1", ".*", "=");
087: assertFalse(HtmlParsingUtils.isAnchorMatched(target, pattern));
088:
089: target.addArgument("param1", "value1", "=");
090: assertTrue(HtmlParsingUtils.isAnchorMatched(target, pattern));
091: }
092:
093: public void testisEqualOrMatches() throws Exception {
094: assertTrue(HtmlParsingUtils.isEqualOrMatches("http:", "http:"));
095: assertFalse(HtmlParsingUtils.isEqualOrMatches("http:", "htTp:"));
096: assertTrue(HtmlParsingUtils.isEqualOrMatches("http:", "ht+p:"));
097: assertFalse(HtmlParsingUtils.isEqualOrMatches("ht+p:", "http:"));
098: }
099:
100: public void testisEqualOrMatchesCaseBlind() throws Exception {
101: assertTrue(HtmlParsingUtils.isEqualOrMatchesCaseBlind("http:",
102: "http:"));
103: assertTrue(HtmlParsingUtils.isEqualOrMatchesCaseBlind("http:",
104: "htTp:"));
105: assertTrue(HtmlParsingUtils.isEqualOrMatches("http:", "ht+p:"));
106: assertFalse(HtmlParsingUtils.isEqualOrMatches("ht+p:", "http:"));
107: }
108: }
|