Merge pull request #340 from adiaholic/XEP-0232

Add support for XEP-0232 : Software Information
This commit is contained in:
Florian Schmaus 2020-05-16 12:08:35 +02:00 committed by GitHub
commit f00acbff89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 762 additions and 0 deletions

View File

@ -82,6 +82,7 @@ Smack Extensions and currently supported XEPs of smack-extensions
| Data Forms Media Element | [XEP-0221](https://xmpp.org/extensions/xep-0221.html) | n/a | Allows to include media data in XEP-0004 data forms. |
| Attention | [XEP-0224](https://xmpp.org/extensions/xep-0224.html) | n/a | Getting attention of another user. |
| Bits of Binary | [XEP-0231](https://xmpp.org/extensions/xep-0231.html) | n/a | Including or referring to small bits of binary data in an XML stanza. |
| Software Information | [XEP-0232](https://xmpp.org/extensions/xep-0232.html) | 0.3 | Allows an entity to provide detailed data about itself in Service Discovery responses. |
| Best Practices for Resource Locking | [XEP-0296](https://xmpp.org/extensions/xep-0296.html) | n/a | Specifies best practices to be followed by Jabber/XMPP clients about when to lock into, and unlock away from, resources. |
| Stanza Forwarding | [XEP-0297](https://xmpp.org/extensions/xep-0297.html) | n/a | Allows forwarding of Stanzas. |
| Last Message Correction | [XEP-0308](https://xmpp.org/extensions/xep-0308.html) | n/a | Provides a method for indicating that a message is a correction of the last sent message. |

View File

@ -0,0 +1,112 @@
/**
*
* Copyright 2020 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.softwareinfo;
import java.io.IOException;
import java.util.Map;
import java.util.WeakHashMap;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException.FeatureNotSupportedException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.softwareinfo.form.SoftwareInfoForm;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jxmpp.jid.Jid;
/**
* Entry point for Smack's API for XEP-0232: Software Information.
* <br>
* @see <a href="https://xmpp.org/extensions/xep-0232.html">
* XEP-0232 : Software Information.
* </a>
*/
public final class SoftwareInfoManager extends Manager {
private static final String FEATURE = "http://jabber.org/protocol/disco";
private static final Map<XMPPConnection, SoftwareInfoManager> INSTANCES = new WeakHashMap<>();
private final ServiceDiscoveryManager serviceDiscoveryManager;
public static synchronized SoftwareInfoManager getInstanceFor (XMPPConnection connection) throws IOException, XmlPullParserException, SmackParsingException {
SoftwareInfoManager manager = INSTANCES.get(connection);
if (manager == null) {
manager = new SoftwareInfoManager(connection);
INSTANCES.put(connection, manager);
}
return manager;
}
private SoftwareInfoManager(XMPPConnection connection) throws IOException, XmlPullParserException, SmackParsingException {
super(connection);
serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
}
/**
* Returns true if the feature is supported by the Jid.
* <br>
* @param jid Jid to be checked for support
* @return boolean
* @throws NoResponseException if there was no response from the remote entity
* @throws XMPPErrorException if there was an XMPP error returned
* @throws NotConnectedException if the XMPP connection is not connected
* @throws InterruptedException if the calling thread was interrupted
*/
public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return serviceDiscoveryManager.supportsFeatures(jid, FEATURE);
}
/**
* Publishes the provided {@link SoftwareInfoForm} as an extended info.
* <br>
* @param softwareInfoForm form to be added as an extended info
*/
public void publishSoftwareInformationForm(SoftwareInfoForm softwareInfoForm) {
serviceDiscoveryManager.addExtendedInfo(softwareInfoForm.getDataForm());
}
/**
* Get SoftwareInfoForm from Jid provided.
* <br>
* @param jid jid to get software information from
* @return {@link SoftwareInfoForm} Form containing software information
* @throws NoResponseException if there was no response from the remote entity
* @throws XMPPErrorException if there was an XMPP error returned
* @throws NotConnectedException if the XMPP connection is not connected
* @throws InterruptedException if the calling thread was interrupted
* @throws FeatureNotSupportedException if the feature is not supported
*/
public SoftwareInfoForm fromJid(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, FeatureNotSupportedException {
if (!isSupported(jid)) {
throw new FeatureNotSupportedException(SoftwareInfoForm.FORM_TYPE, jid);
}
DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(jid);
DataForm dataForm = DataForm.from(discoverInfo, SoftwareInfoForm.FORM_TYPE);
if (dataForm == null) {
return null;
}
return SoftwareInfoForm.getBuilder()
.setDataForm(dataForm)
.build();
}
}

View File

@ -0,0 +1,268 @@
/**
*
* Copyright 2020 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.softwareinfo.form;
import java.util.List;
import org.jivesoftware.smack.util.EqualsUtil;
import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smackx.mediaelement.element.MediaElement;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.FormFieldChildElement;
import org.jivesoftware.smackx.xdata.TextSingleFormField;
import org.jivesoftware.smackx.xdata.form.FilledForm;
import org.jivesoftware.smackx.xdata.form.Form;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jivesoftware.smackx.xdata.packet.DataForm.Type;
/**
* {@link Form} that contains the software information.
* <br>
* Instance of {@link SoftwareInfoForm} can be created using {@link Builder#build()} method.
* <br>
* To obtain an instance of {@link Builder}, use {@link SoftwareInfoForm#getBuilder()} method.
* <br>
* An example to illustrate is provided inside SoftwareInfoFormTest inside the test package.
*/
public final class SoftwareInfoForm extends FilledForm {
public static final String FORM_TYPE = "urn:xmpp:dataforms:softwareinfo";
public static final String OS = "os";
public static final String OS_VERSION = "os_version";
public static final String SOFTWARE = "software";
public static final String SOFTWARE_VERSION = "software_version";
public static final String ICON = "icon";
private SoftwareInfoForm(DataForm dataForm) {
super(dataForm);
}
/**
* Returns name of the OS used by client.
* <br>
* @return os
*/
public String getOS() {
return readFirstValue(OS);
}
/**
* Returns version of the OS used by client.
* <br>
* @return os_version
*/
public String getOSVersion() {
return readFirstValue(OS_VERSION);
}
/**
* Returns name of the software used by client.
* <br>
* @return software
*/
public String getSoftwareName() {
return readFirstValue(SOFTWARE);
}
/**
* Returns version of the software used by client.
* <br>
* @return software_version
*/
public String getSoftwareVersion () {
return readFirstValue(SOFTWARE_VERSION);
}
/**
* Returns the software icon if used by client.
* <br>
* @return {@link MediaElement} MediaElement or null
*/
public MediaElement getIcon () {
FormField field = getField(ICON);
if (field == null) {
return null;
}
FormFieldChildElement media = field.getFormFieldChildElement(MediaElement.QNAME);
if (media == null) {
return null;
}
return (MediaElement) media;
}
@Override
public boolean equals(Object obj) {
return EqualsUtil.equals(this, obj, (equalsBuilder, otherObj) -> {
equalsBuilder.append(getDataForm().getType(), otherObj.getDataForm().getType())
.append(getDataForm().getTitle(), otherObj.getDataForm().getTitle())
.append(getDataForm().getReportedData(), otherObj.getDataForm().getReportedData())
.append(getDataForm().getItems(), otherObj.getDataForm().getItems())
.append(getDataForm().getFields(), otherObj.getDataForm().getFields())
.append(getDataForm().getExtensionElements(), otherObj.getDataForm().getExtensionElements());
});
}
@Override
public int hashCode() {
HashCode.Builder builder = HashCode.builder();
builder.append(getDataForm().getFields());
builder.append(getDataForm().getItems());
builder.append(getDataForm().getExtensionElements());
return builder.build();
}
/**
* Returns a new instance of {@link Builder}.
* <br>
* @return Builder
*/
public static Builder getBuilder() {
return new Builder();
}
/**
* Builder class for {@link SoftwareInfoForm}.
* <br>
* To obtain an instance of {@link Builder}, use {@link SoftwareInfoForm#getBuilder()} method.
* <br>
* Use appropriate setters to include information inside SoftwareInfoForms.
*/
public static final class Builder {
DataForm.Builder dataFormBuilder;
private Builder() {
dataFormBuilder = DataForm.builder(Type.result);
TextSingleFormField formField = FormField.buildHiddenFormType(FORM_TYPE);
dataFormBuilder.addField(formField);
}
/**
* This will allow to include Icon using height, width and Uri's as a
* {@link FormField}.
* <br>
* @param height Height of the image
* @param width Width of the image
* @param uriList List of URIs
* @return Builder
*/
public Builder setIcon(int height, int width, List<MediaElement.Uri> uriList) {
MediaElement.Builder mediaBuilder = MediaElement.builder();
for (MediaElement.Uri uri : uriList) {
mediaBuilder.addUri(uri);
}
MediaElement mediaElement = mediaBuilder.setHeightAndWidth(height, width).build();
return setIcon(mediaElement);
}
/**
* This will allow to include {@link MediaElement} directly as a
* {@link FormField}.
* <br>
* @param mediaElement MediaElement to be included
* @return Builder
*/
public Builder setIcon(MediaElement mediaElement) {
FormField.Builder<?, ?> builder = FormField.builder(ICON);
builder.addFormFieldChildElement(mediaElement);
dataFormBuilder.addField(builder.build());
return this;
}
/**
* Include Operating System's name as a {@link FormField}.
* <br>
* @param os Name of the OS
* @return Builder
*/
public Builder setOS(String os) {
TextSingleFormField.Builder builder = FormField.builder(OS);
builder.setValue(os);
dataFormBuilder.addField(builder.build());
return this;
}
/**
* Include Operating System's version as a {@link FormField}.
* <br>
* @param os_version Version of OS
* @return Builder
*/
public Builder setOSVersion(String os_version) {
TextSingleFormField.Builder builder = FormField.builder(OS_VERSION);
builder.setValue(os_version);
dataFormBuilder.addField(builder.build());
return this;
}
/**
* Include Software name as a {@link FormField}.
* <br>
* @param software Name of the software
* @return Builder
*/
public Builder setSoftware(String software) {
TextSingleFormField.Builder builder = FormField.builder(SOFTWARE);
builder.setValue(software);
dataFormBuilder.addField(builder.build());
return this;
}
/**
* Include Software Version as a {@link FormField}.
* <br>
* @param softwareVersion Version of the Software in use
* @return Builder
*/
public Builder setSoftwareVersion(String softwareVersion) {
TextSingleFormField.Builder builder = FormField.builder(SOFTWARE_VERSION);
builder.setValue(softwareVersion);
dataFormBuilder.addField(builder.build());
return this;
}
/**
* Include {@link DataForm} to be encapsulated under SoftwareInfoForm.
* <br>
* @param dataForm The dataform containing Software Information
* @return Builder
*/
public Builder setDataForm(DataForm dataForm) {
if (dataForm.getTitle() != null || !dataForm.getItems().isEmpty()
|| dataForm.getReportedData() != null || !dataForm.getInstructions().isEmpty()) {
throw new IllegalArgumentException("Illegal Arguements for SoftwareInformation");
}
String formTypeValue = dataForm.getFormType();
if (formTypeValue == null) {
throw new IllegalArgumentException("FORM_TYPE Formfield missing");
}
if (!formTypeValue.equals(SoftwareInfoForm.FORM_TYPE)) {
throw new IllegalArgumentException("Malformed FORM_TYPE Formfield encountered");
}
this.dataFormBuilder = dataForm.asBuilder();
return this;
}
/**
* This method is called to build a {@link SoftwareInfoForm}.
* <br>
* @return Builder
*/
public SoftwareInfoForm build() {
return new SoftwareInfoForm(dataFormBuilder.build());
}
}
}

View File

@ -0,0 +1,21 @@
/**
*
* Copyright 2020 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.
*/
/**
* Form class needed for <a href="https://xmpp.org/extensions/xep-0232.html"> XEP-0232: Software Information</a>.
*/
package org.jivesoftware.smackx.softwareinfo.form;

View File

@ -0,0 +1,21 @@
/**
*
* Copyright 2020 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.
*/
/**
* Smacks implementation of XEP-0232: Software Information.
*/
package org.jivesoftware.smackx.softwareinfo;

View File

@ -0,0 +1,143 @@
/**
*
* Copyright 2020 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.softwareinfo;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.URI;
import java.net.URISyntaxException;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.mediaelement.element.MediaElement;
import org.jivesoftware.smackx.softwareinfo.form.SoftwareInfoForm;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.TextSingleFormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jivesoftware.smackx.xdata.packet.DataForm.Type;
import org.junit.jupiter.api.Test;
public class SoftwareInfoFormTest extends SmackTestSuite {
private final String xml =
"<x xmlns='jabber:x:data' type='result'>" +
"<field var='FORM_TYPE' type='hidden'>" +
"<value>urn:xmpp:dataforms:softwareinfo</value>" +
"</field>" +
"<field var='icon'>" +
"<media xmlns='urn:xmpp:media-element' height='80' width='290'>" +
"<uri type='image/jpeg'>" +
"http://www.shakespeare.lit/clients/exodus.jpg" +
"</uri>" +
"<uri type='image/jpeg'>" +
"cid:sha1+f24030b8d91d233bac14777be5ab531ca3b9f102@bob.xmpp.org" +
"</uri>" +
"</media>" +
"</field>" +
"<field var='os'>" +
"<value>Windows</value>" +
"</field>" +
"<field var='os_version'>" +
"<value>XP</value>" +
"</field>" +
"<field var='software'>" +
"<value>Exodus</value>" +
"</field>" +
"<field var='software_version'>" +
"<value>0.9.1</value>" +
"</field>" +
"</x>";
@Test
public void softwareInfoBuilderTest() throws URISyntaxException {
SoftwareInfoForm softwareInfoForm = createSoftwareInfoForm();
assertXmlSimilar(xml, softwareInfoForm.getDataForm().toXML());
softwareInfoForm = createSoftwareInfoFormUsingDataForm();
assertXmlSimilar(xml, softwareInfoForm.getDataForm().toXML());
}
@Test
public void getInfoFromSoftwareInfoFormTest() throws URISyntaxException {
SoftwareInfoForm softwareInfoForm = createSoftwareInfoForm();
assertEquals("Windows", softwareInfoForm.getOS());
assertEquals("XP", softwareInfoForm.getOSVersion());
assertEquals("Exodus", softwareInfoForm.getSoftwareName());
assertEquals("0.9.1", softwareInfoForm.getSoftwareVersion());
assertXmlSimilar(createMediaElement().toXML(), softwareInfoForm.getIcon().toXML());
}
@Test
public void faultySoftwareInfoFormsTest() {
DataForm.Builder dataFormbuilder = DataForm.builder(Type.result);
TextSingleFormField formField = FormField.buildHiddenFormType("faulty_formtype");
dataFormbuilder.addField(formField);
assertThrows(IllegalArgumentException.class, () -> {
SoftwareInfoForm.getBuilder().setDataForm(dataFormbuilder.build()).build();
});
DataForm.Builder builderWithoutFormType = DataForm.builder(Type.result);
assertThrows(IllegalArgumentException.class, () -> {
SoftwareInfoForm.getBuilder().setDataForm(builderWithoutFormType.build()).build();
});
}
public static SoftwareInfoForm createSoftwareInfoFormUsingDataForm() throws URISyntaxException {
DataForm.Builder dataFormBuilder = DataForm.builder(Type.result);
TextSingleFormField formField = FormField.buildHiddenFormType(SoftwareInfoForm.FORM_TYPE);
dataFormBuilder.addField(formField);
dataFormBuilder.addField(FormField.builder("icon")
.addFormFieldChildElement(createMediaElement())
.build());
dataFormBuilder.addField(FormField.builder("os")
.setValue("Windows")
.build());
dataFormBuilder.addField(FormField.builder("os_version")
.setValue("XP")
.build());
dataFormBuilder.addField(FormField.builder("software")
.setValue("Exodus")
.build());
dataFormBuilder.addField(FormField.builder("software_version")
.setValue("0.9.1")
.build());
SoftwareInfoForm softwareInfoForm = SoftwareInfoForm.getBuilder().setDataForm(dataFormBuilder.build()).build();
return softwareInfoForm;
}
public static SoftwareInfoForm createSoftwareInfoForm() throws URISyntaxException {
return SoftwareInfoForm.getBuilder()
.setIcon(createMediaElement())
.setOS("Windows")
.setOSVersion("XP")
.setSoftware("Exodus")
.setSoftwareVersion("0.9.1")
.build();
}
public static MediaElement createMediaElement() throws URISyntaxException {
return MediaElement.builder()
.addUri(new URI("http://www.shakespeare.lit/clients/exodus.jpg"), "image/jpeg")
.addUri(new URI("cid:sha1+f24030b8d91d233bac14777be5ab531ca3b9f102@bob.xmpp.org"), "image/jpeg")
.setHeightAndWidth(80, 290)
.build();
}
}

View File

@ -0,0 +1,102 @@
/**
*
* Copyright 2020 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.softwareinfo;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mediaelement.element.MediaElement;
import org.jivesoftware.smackx.softwareinfo.form.SoftwareInfoForm;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jivesoftware.smackx.xdata.packet.DataForm.Type;
import org.jivesoftware.util.ConnectionUtils;
import org.jivesoftware.util.Protocol;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.JidTestUtil;
public class SoftwareInfoManagerTest {
private static final EntityFullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
private XMPPConnection connection;
private Protocol protocol;
@BeforeEach
public void setup() throws XMPPException, SmackException, InterruptedException {
protocol = new Protocol();
connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
}
@Test
public void softwareInfoManagerTest() throws IOException, XmlPullParserException, SmackParsingException, URISyntaxException {
SoftwareInfoManager manager = SoftwareInfoManager.getInstanceFor(connection);
manager.publishSoftwareInformationForm(buildSoftwareInfoFormUsingBuilder());
manager.publishSoftwareInformationForm(buildSoftwareInfoFromDataForm());
}
public static SoftwareInfoForm buildSoftwareInfoFormUsingBuilder() throws URISyntaxException {
SoftwareInfoForm.Builder builder = SoftwareInfoForm.getBuilder();
MediaElement mediaElement = createMediaElement();
builder.setIcon(mediaElement);
builder.setOS("Windows");
builder.setOSVersion("XP");
builder.setSoftware("Exodus");
builder.setSoftwareVersion("0.9.1");
return builder.build();
}
public static SoftwareInfoForm buildSoftwareInfoFromDataForm() throws URISyntaxException {
DataForm.Builder dataFormBuilder = DataForm.builder(Type.result);
dataFormBuilder.addField(FormField.buildHiddenFormType(SoftwareInfoForm.FORM_TYPE));
dataFormBuilder.addField(FormField.builder("icon")
.addFormFieldChildElement(createMediaElement())
.build());
dataFormBuilder.addField(FormField.builder("os")
.setValue("Windows")
.build());
dataFormBuilder.addField(FormField.builder("os_version")
.setValue("XP")
.build());
dataFormBuilder.addField(FormField.builder("software")
.setValue("Exodus")
.build());
dataFormBuilder.addField(FormField.builder("software_version")
.setValue("0.9.1")
.build());
SoftwareInfoForm softwareInfoForm = SoftwareInfoForm.getBuilder()
.setDataForm(dataFormBuilder.build())
.build();
return softwareInfoForm;
}
public static MediaElement createMediaElement() throws URISyntaxException {
return MediaElement.builder()
.addUri(new MediaElement.Uri(new URI("http://example.org"), "test-type"))
.setHeightAndWidth(16, 16)
.build();
}
}

View File

@ -0,0 +1,77 @@
/**
*
* Copyright 2020 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.softwareInfo;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mediaelement.element.MediaElement;
import org.jivesoftware.smackx.softwareinfo.SoftwareInfoManager;
import org.jivesoftware.smackx.softwareinfo.form.SoftwareInfoForm;
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
import org.igniterealtime.smack.inttest.annotations.BeforeClass;
import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;
import org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil;
public class SoftwareInfoIntegrationTest extends AbstractSmackIntegrationTest {
public final SoftwareInfoManager sim1;
public final SoftwareInfoManager sim2;
public SoftwareInfoIntegrationTest(SmackIntegrationTestEnvironment environment)
throws IOException, XmlPullParserException, SmackParsingException {
super(environment);
sim1 = SoftwareInfoManager.getInstanceFor(conOne);
sim2 = SoftwareInfoManager.getInstanceFor(conTwo);
}
@BeforeClass
public void setUp() throws Exception {
IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
}
@SmackIntegrationTest
public void test() throws Exception {
SoftwareInfoForm softwareInfoSent = createSoftwareInfoForm();
sim1.publishSoftwareInformationForm(softwareInfoSent);
SoftwareInfoForm softwareInfoFormReceived = sim2.fromJid(conOne.getUser());
assertTrue(softwareInfoFormReceived.equals(softwareInfoSent));
}
private static SoftwareInfoForm createSoftwareInfoForm() throws URISyntaxException {
SoftwareInfoForm.Builder builder = SoftwareInfoForm.getBuilder();
MediaElement mediaElement = MediaElement.builder()
.addUri(new MediaElement.Uri(new URI("http://example.org"), "test-type"))
.setHeightAndWidth(16, 16)
.build();
SoftwareInfoForm softwareInfoForm = builder.setIcon(mediaElement)
.setOS("Windows")
.setOSVersion("XP")
.setSoftware("Exodus")
.setSoftwareVersion("0.9.1")
.build();
return softwareInfoForm;
}
}

View File

@ -0,0 +1,17 @@
/**
*
* Copyright 2020 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.softwareInfo;