2016-07-21 16:40:26 +02:00
|
|
|
/**
|
|
|
|
*
|
2020-05-13 20:14:41 +02:00
|
|
|
* Copyright 2016 Fernando Ramirez, 2018-2020 Florian Schmaus
|
2016-07-21 16:40:26 +02:00
|
|
|
*
|
|
|
|
* 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.mam;
|
|
|
|
|
2018-06-09 15:03:14 +02:00
|
|
|
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;
|
2019-05-06 22:06:13 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2016-07-21 16:40:26 +02:00
|
|
|
|
2018-05-09 16:53:08 +02:00
|
|
|
import org.jivesoftware.smack.packet.StreamOpen;
|
|
|
|
|
2018-06-09 15:03:14 +02:00
|
|
|
import org.jivesoftware.smackx.mam.MamManager.MamQueryArgs;
|
2016-07-21 16:40:26 +02:00
|
|
|
import org.jivesoftware.smackx.mam.element.MamElements;
|
|
|
|
import org.jivesoftware.smackx.mam.element.MamQueryIQ;
|
|
|
|
import org.jivesoftware.smackx.xdata.FormField;
|
|
|
|
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2020-05-13 20:14:41 +02:00
|
|
|
import org.jxmpp.jid.JidTestUtil;
|
2016-07-21 16:40:26 +02:00
|
|
|
|
|
|
|
public class RetrieveFormFieldsTest extends MamTest {
|
|
|
|
|
2016-07-23 15:45:45 +02:00
|
|
|
private static final String retrieveFormFieldStanza = "<iq id='sarasa' type='get'>" + "<query xmlns='" + MamElements.NAMESPACE
|
2016-07-21 16:40:26 +02:00
|
|
|
+ "' queryid='testid'></query>" + "</iq>";
|
|
|
|
|
2020-05-13 20:14:41 +02:00
|
|
|
private static final String additionalFieldsStanza = "<x xmlns='jabber:x:data' type='submit'>" + "<field var='FORM_TYPE'>"
|
2016-07-21 16:40:26 +02:00
|
|
|
+ "<value>" + MamElements.NAMESPACE + "</value>" + "</field>"
|
2019-06-10 16:58:38 +02:00
|
|
|
+ "<field var='urn:example:xmpp:free-text-search'>" + "<value>Hi</value>" + "</field>"
|
2020-05-13 20:14:41 +02:00
|
|
|
+ "<field var='urn:example:xmpp:stanza-content'>" + "<value>one@exampleone.org</value>" + "</field>"
|
2016-07-21 16:40:26 +02:00
|
|
|
+ "</x>";
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkRetrieveFormFieldsStanza() throws Exception {
|
2016-07-23 15:45:45 +02:00
|
|
|
MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId);
|
2016-07-21 16:40:26 +02:00
|
|
|
mamQueryIQ.setStanzaId("sarasa");
|
|
|
|
|
2018-06-09 15:03:14 +02:00
|
|
|
assertEquals(retrieveFormFieldStanza, mamQueryIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
|
2016-07-21 16:40:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkAddAdditionalFieldsStanza() throws Exception {
|
2019-06-10 16:58:38 +02:00
|
|
|
FormField field1 = FormField.builder("urn:example:xmpp:free-text-search")
|
2020-05-13 20:14:41 +02:00
|
|
|
.setValue("Hi")
|
2019-06-10 16:58:38 +02:00
|
|
|
.build();
|
2016-07-21 16:40:26 +02:00
|
|
|
|
2020-05-13 20:14:41 +02:00
|
|
|
FormField field2 = FormField.jidSingleBuilder("urn:example:xmpp:stanza-content")
|
|
|
|
.setValue(JidTestUtil.BARE_JID_1)
|
2019-06-10 16:58:38 +02:00
|
|
|
.build();
|
2016-07-21 16:40:26 +02:00
|
|
|
|
2018-06-09 15:03:14 +02:00
|
|
|
MamQueryArgs mamQueryArgs = MamQueryArgs.builder()
|
|
|
|
.withAdditionalFormField(field1)
|
|
|
|
.withAdditionalFormField(field2)
|
|
|
|
.build();
|
|
|
|
DataForm dataForm = mamQueryArgs.getDataForm();
|
2016-07-21 16:40:26 +02:00
|
|
|
|
2019-02-04 13:27:41 +01:00
|
|
|
String dataFormResult = dataForm.toXML().toString();
|
2016-07-21 16:40:26 +02:00
|
|
|
|
2018-06-09 15:03:14 +02:00
|
|
|
assertXmlSimilar(additionalFieldsStanza, dataFormResult);
|
2016-07-21 16:40:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|