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;
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2018-06-09 15:03:14 +02:00
|
|
|
|
2016-07-21 16:40:26 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
|
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.xdata.packet.DataForm;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2016-07-21 16:40:26 +02:00
|
|
|
import org.jxmpp.jid.Jid;
|
2018-06-09 15:03:14 +02:00
|
|
|
import org.jxmpp.jid.JidTestUtil;
|
2016-07-21 16:40:26 +02:00
|
|
|
import org.jxmpp.util.XmppDateTime;
|
|
|
|
|
|
|
|
public class FiltersTest extends MamTest {
|
|
|
|
|
2018-06-09 15:03:14 +02:00
|
|
|
private static String getMamXMemberWith(List<String> fieldsNames, List<? extends CharSequence> fieldsValues) {
|
2020-05-13 20:14:41 +02:00
|
|
|
String xml = "<x xmlns='jabber:x:data' type='submit'>" + "<field var='FORM_TYPE'>" + "<value>"
|
2016-07-21 16:40:26 +02:00
|
|
|
+ MamElements.NAMESPACE + "</value>" + "</field>";
|
|
|
|
|
|
|
|
for (int i = 0; i < fieldsNames.size() && i < fieldsValues.size(); i++) {
|
|
|
|
xml += "<field var='" + fieldsNames.get(i) + "'>" + "<value>" + fieldsValues.get(i) + "</value>"
|
|
|
|
+ "</field>";
|
|
|
|
}
|
|
|
|
|
|
|
|
xml += "</x>";
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkStartDateFilter() throws Exception {
|
|
|
|
Date date = new Date();
|
2018-06-09 15:03:14 +02:00
|
|
|
|
|
|
|
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsSince(date).build();
|
|
|
|
DataForm dataForm = mamQueryArgs.getDataForm();
|
2016-07-21 16:40:26 +02:00
|
|
|
|
|
|
|
List<String> fields = new ArrayList<>();
|
|
|
|
fields.add("start");
|
|
|
|
List<String> values = new ArrayList<>();
|
|
|
|
values.add(XmppDateTime.formatXEP0082Date(date));
|
|
|
|
|
2019-02-04 13:27:41 +01:00
|
|
|
assertEquals(getMamXMemberWith(fields, values), dataForm.toXML().toString());
|
2016-07-21 16:40:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkEndDateFilter() throws Exception {
|
|
|
|
Date date = new Date();
|
2018-06-09 15:03:14 +02:00
|
|
|
|
|
|
|
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsBefore(date).build();
|
|
|
|
DataForm dataForm = mamQueryArgs.getDataForm();
|
2016-07-21 16:40:26 +02:00
|
|
|
|
|
|
|
List<String> fields = new ArrayList<>();
|
|
|
|
fields.add("end");
|
|
|
|
List<String> values = new ArrayList<>();
|
|
|
|
values.add(XmppDateTime.formatXEP0082Date(date));
|
|
|
|
|
2019-02-04 13:27:41 +01:00
|
|
|
assertEquals(getMamXMemberWith(fields, values), dataForm.toXML().toString());
|
2016-07-21 16:40:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkWithJidFilter() throws Exception {
|
2018-06-09 15:03:14 +02:00
|
|
|
Jid jid = JidTestUtil.BARE_JID_1;
|
2016-07-21 16:40:26 +02:00
|
|
|
|
2018-06-09 15:03:14 +02:00
|
|
|
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsToJid(jid).build();
|
|
|
|
DataForm dataForm = mamQueryArgs.getDataForm();
|
2016-07-21 16:40:26 +02:00
|
|
|
|
|
|
|
List<String> fields = new ArrayList<>();
|
|
|
|
fields.add("with");
|
2018-06-09 15:03:14 +02:00
|
|
|
List<CharSequence> values = new ArrayList<>();
|
2016-07-21 16:40:26 +02:00
|
|
|
values.add(jid);
|
|
|
|
|
2019-02-04 13:27:41 +01:00
|
|
|
assertEquals(getMamXMemberWith(fields, values), dataForm.toXML().toString());
|
2016-07-21 16:40:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|