mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-07 05:31:08 +01:00
Merge branch '4.2'
This commit is contained in:
commit
f42d9137b5
17 changed files with 537 additions and 69 deletions
|
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Paul Schaub
|
||||
*
|
||||
* 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.reference;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.reference.element.ReferenceElement;
|
||||
import org.jivesoftware.smackx.reference.provider.ReferenceProvider;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ReferenceTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void providerMentionTest() throws Exception {
|
||||
String xml = "<reference xmlns='urn:xmpp:reference:0' " +
|
||||
"begin='72' " +
|
||||
"end='78' " +
|
||||
"type='mention' " +
|
||||
"uri='xmpp:juliet@capulet.lit' />";
|
||||
URI uri = new URI("xmpp:juliet@capulet.lit");
|
||||
ReferenceElement element = new ReferenceElement(72, 78, ReferenceElement.Type.mention, null, uri);
|
||||
assertXMLEqual(xml, element.toXML().toString());
|
||||
assertEquals(72, (int) element.getBegin());
|
||||
assertEquals(78, (int) element.getEnd());
|
||||
assertEquals(ReferenceElement.Type.mention, element.getType());
|
||||
assertNull(element.getAnchor());
|
||||
assertEquals(uri, element.getUri());
|
||||
|
||||
ReferenceElement parsed = ReferenceProvider.TEST_PROVIDER.parse(TestUtils.getParser(xml));
|
||||
assertXMLEqual(xml, parsed.toXML().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: The uri might not be following the XMPP schema.
|
||||
* That shouldn't matter though.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void providerDataTest() throws Exception {
|
||||
String xml = "<reference xmlns='urn:xmpp:reference:0' " +
|
||||
"type='data' " +
|
||||
"uri='xmpp:fdp.shakespeare.lit?;node=fdp/submitted/stan.isode.net/accidentreport;item=ndina872be' />";
|
||||
URI uri = new URI("xmpp:fdp.shakespeare.lit?;node=fdp/submitted/stan.isode.net/accidentreport;item=ndina872be");
|
||||
ReferenceElement element = new ReferenceElement(null, null, ReferenceElement.Type.data, null, uri);
|
||||
assertXMLEqual(xml, element.toXML().toString());
|
||||
|
||||
assertNull(element.getBegin());
|
||||
assertNull(element.getEnd());
|
||||
assertNull(element.getAnchor());
|
||||
assertEquals(ReferenceElement.Type.data, element.getType());
|
||||
assertEquals(uri, element.getUri());
|
||||
|
||||
ReferenceElement parsed = ReferenceProvider.TEST_PROVIDER.parse(TestUtils.getParser(xml));
|
||||
assertXMLEqual(xml, parsed.toXML().toString());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void beginGreaterEndIllegalTest() throws URISyntaxException {
|
||||
new ReferenceElement(100, 10, ReferenceElement.Type.mention, null, new URI("xmpp:test@test.test"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void beginSmallerZeroTest() throws URISyntaxException {
|
||||
new ReferenceElement(-1, 12, ReferenceElement.Type.data, null, new URI("xmpp:test@test.test"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void endSmallerZeroTest() throws URISyntaxException {
|
||||
new ReferenceElement(12, -2, ReferenceElement.Type.mention, null, new URI("xmpp:test@test.test"));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void typeArgumentNullTest() throws URISyntaxException {
|
||||
new ReferenceElement(1, 2, null, null, new URI("xmpp:test@test.test"));
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Later maybe remove this test in case the uri attribute becomes optional.
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void uriArgumentNullTest() {
|
||||
new ReferenceElement(1, 2, ReferenceElement.Type.mention, null, null);
|
||||
}
|
||||
*/
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue