Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* |
9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
10 |
* |
11 |
* Unless required by applicable law or agreed to in writing, software |
12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
* See the License for the specific language governing permissions and |
15 |
* limitations under the License. |
16 |
* |
17 |
*/ |
18 |
|
19 |
package org.apache.jmeter.protocol.http.parser; |
20 |
|
21 |
import static org.junit.Assert.assertThat; |
22 |
|
23 |
import java.net.MalformedURLException; |
24 |
import java.net.URL; |
25 |
import java.nio.charset.StandardCharsets; |
26 |
import java.util.List; |
27 |
|
28 |
import org.apache.commons.collections.IteratorUtils; |
29 |
import org.apache.jmeter.junit.JMeterTestCase; |
30 |
import org.hamcrest.CoreMatchers; |
31 |
import org.junit.Test; |
32 |
|
33 |
public class TestCssParser extends JMeterTestCase { |
34 |
|
35 |
private final CssParser parser = new CssParser(); |
36 |
|
37 |
@Test |
38 |
public void testGetEmbeddedResourceURLsNoUrls() throws Exception { |
39 |
CssParser nonIgnoreParser = new CssParser(); |
40 |
List<?> result = extractUrls(nonIgnoreParser, ".."); |
41 |
assertThat(result.isEmpty(), CoreMatchers.is(true)); |
42 |
} |
43 |
|
44 |
@Test |
45 |
public void testGetEmbeddedResourceURLsnOneUrl() throws Exception { |
46 |
List<?> result; |
47 |
result = extractUrls("@import url(http://example.com/abc.css);"); |
48 |
assertThat(result.isEmpty(), CoreMatchers.is(false)); |
49 |
} |
50 |
|
51 |
@Test |
52 |
public void testIsReusable() { |
53 |
assertThat(parser.isReusable(), CoreMatchers.is(true)); |
54 |
} |
55 |
|
56 |
private List<?> extractUrls(String css) throws LinkExtractorParseException, |
57 |
MalformedURLException { |
58 |
return extractUrls(parser, css); |
59 |
} |
60 |
|
61 |
private List<?> extractUrls(CssParser parser, String css) |
62 |
throws LinkExtractorParseException, MalformedURLException { |
63 |
List<?> result = IteratorUtils.toList(parser.getEmbeddedResourceURLs( |
64 |
"Mozilla", css.getBytes(StandardCharsets.UTF_8), new URL( |
65 |
"http://example.org/"), StandardCharsets.UTF_8 |
66 |
.displayName())); |
67 |
return result; |
68 |
} |
69 |
} |