/**
*
* Copyright 2021 Florian Schmaus
*
* 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.xdata.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.List;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.junit.jupiter.api.Test;
public class DataFormProviderTest {
@Test
public void testRetrieveFieldTypeFromReported() throws XmlPullParserException, IOException, SmackParsingException {
String firstForm =
"" +
" Advanced User Search" +
" The following fields are available for searching. Wildcard (*) characters are allowed as part of the query." +
" " +
" jabber:iq:search" +
" " +
" " +
" " +
" " +
" " +
" true" +
" " +
" " +
" true" +
" " +
" " +
" true" +
" " +
"";
XmlPullParser parser = PacketParserUtils.getParserFor(firstForm);
DataForm firstDataForm = DataFormProvider.INSTANCE.parse(parser);
FormField usernameFormField = firstDataForm.getField("Username");
assertEquals(FormField.Type.bool, usernameFormField.getType());
String secondForm =
"" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" - " +
" " +
" " +
" 0" +
" " +
" " +
" " +
" frank@orphu" +
" " +
" " +
" " +
" frank" +
" " +
" " +
" " +
" " +
" 0" +
" " +
" " +
"
" +
" - " +
" " +
" " +
" " +
" " +
" " +
" frank2@orphu" +
" " +
" " +
" " +
" frank2" +
" " +
" " +
" " +
" " +
" " +
" " +
"
" +
"";
parser = PacketParserUtils.getParserFor(secondForm);
DataForm secondDataForm = DataFormProvider.INSTANCE.parse(parser);
List items = secondDataForm.getItems();
assertEquals(2, items.size());
}
}