mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-08 06:01:07 +01:00
Add support for XEP-0118: UserTune
This commit will enable user to communicate information about music to which user is listening. This feature is less of a requirement and more like fun to me. An attempt at solving SMACK-257. Incase you see any chances of improvement, please let me know :)
This commit is contained in:
parent
8f371c5381
commit
260c5539b5
13 changed files with 835 additions and 0 deletions
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Aditya Borikar.
|
||||
*
|
||||
* 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.usertune;
|
||||
|
||||
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.SmackTestUtil;
|
||||
import org.jivesoftware.smack.test.util.SmackTestUtil.XmlPullParserKind;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
import org.jivesoftware.smackx.usertune.element.UserTuneElement;
|
||||
import org.jivesoftware.smackx.usertune.provider.UserTuneProvider;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
public class UserTuneElementTest extends SmackTestSuite {
|
||||
|
||||
private final String xml = "<tune xmlns='http://jabber.org/protocol/tune'>" +
|
||||
"<artist>Yes</artist>" +
|
||||
"<length>686</length>" +
|
||||
"<rating>8</rating>" +
|
||||
"<source>Yessongs</source>" +
|
||||
"<title>Heart of the Sunrise</title>" +
|
||||
"<track>3</track>" +
|
||||
"<uri>http://www.yesworld.com/lyrics/Fragile.html#9</uri>" +
|
||||
"</tune>";
|
||||
|
||||
@Test
|
||||
public void toXmlTest() throws IOException, XmlPullParserException, SmackParsingException, URISyntaxException {
|
||||
|
||||
URI uri = new URI("http://www.yesworld.com/lyrics/Fragile.html#9");
|
||||
|
||||
UserTuneElement.Builder builder = UserTuneElement.getBuilder();
|
||||
UserTuneElement userTuneElement = builder.setArtist("Yes")
|
||||
.setLength(686)
|
||||
.setRating(8)
|
||||
.setSource("Yessongs")
|
||||
.setTitle("Heart of the Sunrise")
|
||||
.setTrack("3")
|
||||
.setUri(uri)
|
||||
.build();
|
||||
assertXmlSimilar(xml, userTuneElement.toXML().toString());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = SmackTestUtil.XmlPullParserKind.class)
|
||||
public void userTuneElementProviderTest(XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(xml, parserKind);
|
||||
UserTuneElement parsed = UserTuneProvider.INSTANCE.parse(parser);
|
||||
assertXmlSimilar(xml, parsed.toXML().toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Aditya Borikar.
|
||||
*
|
||||
* 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.usertune;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.usertune.element.UserTuneElement;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class UserTuneManagerTest extends SmackTestSuite{
|
||||
|
||||
@Test
|
||||
public void addMessage() throws URISyntaxException {
|
||||
|
||||
UserTuneElement.Builder builder = UserTuneElement.getBuilder();
|
||||
builder.setArtist("Yes");
|
||||
builder.setLength(686);
|
||||
builder.setRating(8);
|
||||
builder.setSource("Yessongs");
|
||||
builder.setTitle("Heart of the Sunrise");
|
||||
builder.setTrack("3");
|
||||
URI uri = new URI("http://www.yesworld.com/lyrics/Fragile.html#9");
|
||||
builder.setUri(uri);
|
||||
UserTuneElement userTuneElement = builder.build();
|
||||
|
||||
Message message = new Message();
|
||||
message.addExtension(userTuneElement);
|
||||
|
||||
assertTrue(message.hasExtension(UserTuneElement.ELEMENT, UserTuneElement.NAMESPACE));
|
||||
assertTrue(UserTuneElement.hasUserTuneElement(message));
|
||||
|
||||
UserTuneElement element = UserTuneElement.from(message);
|
||||
assertNotNull(element);
|
||||
assertEquals(userTuneElement, element);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue