2014-03-06 09:42:25 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2014 Vyacheslav Blinov
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.xhtmlim.provider;
|
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
2017-12-13 23:10:11 +01:00
|
|
|
import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence;
|
2017-06-14 17:12:43 +02:00
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
2014-07-05 15:04:35 +02:00
|
|
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-03-06 09:42:25 +01:00
|
|
|
import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-03-06 09:42:25 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
|
|
|
|
|
|
|
|
public class XHTMLExtensionProviderTest {
|
|
|
|
public static final String XHTML_EXTENSION_SAMPLE_RESOURCE_NAME = "xhtml.xml";
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void parsesWell() throws IOException, XmlPullParserException {
|
2014-07-05 15:04:35 +02:00
|
|
|
XmlPullParser parser = PacketParserUtils.newXmppParser();
|
2014-03-06 09:42:25 +01:00
|
|
|
parser.setInput(getClass().getResourceAsStream(XHTML_EXTENSION_SAMPLE_RESOURCE_NAME), "UTF-8");
|
|
|
|
parser.next();
|
|
|
|
|
|
|
|
XHTMLExtensionProvider provider = new XHTMLExtensionProvider();
|
2015-02-26 18:41:17 +01:00
|
|
|
ExtensionElement extension = provider.parse(parser, parser.getDepth());
|
2014-03-06 09:42:25 +01:00
|
|
|
|
2014-07-06 21:10:40 +02:00
|
|
|
assertThat(extension, instanceOf(XHTMLExtension.class));
|
2014-03-06 09:42:25 +01:00
|
|
|
XHTMLExtension attachmentsInfo = (XHTMLExtension) extension;
|
|
|
|
|
2014-07-06 21:10:40 +02:00
|
|
|
assertThat(sampleXhtml(), equalsCharSequence(attachmentsInfo.getBodies().get(0)));
|
2014-03-06 09:42:25 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 21:38:21 +01:00
|
|
|
private static String sampleXhtml() {
|
2014-03-06 09:42:25 +01:00
|
|
|
return "<body xmlns='http://www.w3.org/1999/xhtml'>" +
|
|
|
|
"<span style='color: rgb(0, 0, 0); font-family: sans-serif, 'trebuchet ms'" +
|
|
|
|
", 'lucida grande', 'lucida sans unicode', arial, helvetica, " +
|
|
|
|
"sans-serif; font-weight: 600; line-height: 18px;'>Generic family<br/>AnotherLine</span></body>";
|
|
|
|
}
|
|
|
|
}
|