1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 09:09:38 +02:00

Merge remote-tracking branch 'my/master'

This commit is contained in:
Florian Schmaus 2016-12-07 21:20:02 +01:00
commit b558a128c3
30 changed files with 203 additions and 136 deletions

View file

@ -169,7 +169,7 @@ public final class BlockingCommandManager extends Manager {
BlockListIQ blockListIQ = new BlockListIQ();
BlockListIQ blockListIQResult = connection().createPacketCollectorAndSend(blockListIQ).nextResultOrThrow();
blockListCached = blockListIQResult.getJids();
blockListCached = blockListIQResult.getBlockedJidsCopy();
return Collections.unmodifiableList(blockListCached);
}

View file

@ -16,6 +16,7 @@
*/
package org.jivesoftware.smackx.blocking.element;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -52,9 +53,10 @@ public class BlockListIQ extends IQ {
public BlockListIQ(List<Jid> jids) {
super(ELEMENT, NAMESPACE);
if (jids == null) {
jids = Collections.emptyList();
this.jids = Collections.emptyList();
} else {
this.jids = Collections.unmodifiableList(jids);
}
this.jids = jids;
}
/**
@ -65,14 +67,23 @@ public class BlockListIQ extends IQ {
}
/**
* Get the JIDs.
* Get the JIDs as unmodifiable list.
*
* @return the JIDs
* @return the blocked JIDs
*/
public List<Jid> getJids() {
public List<Jid> getBlockedJids() {
return jids;
}
/**
* Get a copy of the blocked list JIDs. This copy is modifiable.
*
* @return the blocked JIDs
*/
public List<Jid> getBlockedJidsCopy() {
return new ArrayList<>(getBlockedJids());
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
if (jids.isEmpty()) {

View file

@ -280,7 +280,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
XMPPError.Builder error = XMPPError.from(XMPPError.Condition.item_not_found, errorMessage);
IQ errorIQ = IQ.createErrorResponse(this.bytestreamRequest, error);
this.manager.getConnection().sendStanza(errorIQ);
throw new XMPPErrorException(error);
throw new XMPPErrorException(errorIQ, error.build());
}
/**

View file

@ -615,6 +615,7 @@ public final class AdHocCommandManager extends Manager {
* @return the command instance to execute.
* @throws XMPPErrorException if there is problem creating the new instance.
*/
@SuppressWarnings("deprecation")
private LocalCommand newInstanceOfCmd(String commandNode, String sessionID) throws XMPPErrorException
{
AdHocCommandInfo commandInfo = commands.get(commandNode);

View file

@ -95,8 +95,14 @@ public class AdHocCommandDataProvider extends IQProvider<AdHocCommandData> {
adHocCommandData.setForm(dataFormProvider.parse(parser));
}
else if (parser.getName().equals("note")) {
AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf(
parser.getAttributeValue("", "type"));
String typeString = parser.getAttributeValue("", "type");
AdHocCommandNote.Type type;
if (typeString != null) {
type = AdHocCommandNote.Type.valueOf(typeString);
} else {
// Type is optional and 'info' if not present.
type = AdHocCommandNote.Type.info;
}
String value = parser.nextText();
adHocCommandData.addNote(new AdHocCommandNote(type, value));
}

View file

@ -327,7 +327,7 @@ public final class FileTransferNegotiator extends Manager {
}
else {
throw new XMPPErrorException(iqResponse.getError());
throw new XMPPErrorException(iqResponse, iqResponse.getError());
}
}
else {

View file

@ -36,6 +36,6 @@ public class ValidationConsistencyException extends IllegalArgumentException {
* @param message
*/
public ValidationConsistencyException(String message) {
super( message);
super(message);
}
}

View file

@ -47,13 +47,13 @@ public class GetBlockingListTest {
public void checkBlockListIQ() throws Exception {
IQ iq = (IQ) PacketParserUtils.parseStanza(blockListIQExample);
BlockListIQ blockListIQ = (BlockListIQ) iq;
Assert.assertEquals(2, blockListIQ.getJids().size());
Assert.assertEquals(JidCreate.from("romeo@montague.net"), blockListIQ.getJids().get(0));
Assert.assertEquals(JidCreate.from("iago@shakespeare.lit"), blockListIQ.getJids().get(1));
Assert.assertEquals(2, blockListIQ.getBlockedJids().size());
Assert.assertEquals(JidCreate.from("romeo@montague.net"), blockListIQ.getBlockedJids().get(0));
Assert.assertEquals(JidCreate.from("iago@shakespeare.lit"), blockListIQ.getBlockedJids().get(1));
IQ iq2 = (IQ) PacketParserUtils.parseStanza(emptyBlockListIQExample);
BlockListIQ emptyBlockListIQ = (BlockListIQ) iq2;
Assert.assertEquals(0, emptyBlockListIQ.getJids().size());
Assert.assertEquals(0, emptyBlockListIQ.getBlockedJids().size());
}
}

View file

@ -55,7 +55,7 @@ public class DataFormTest {
FormField field = new FormField("testField1");
df.addField(field);
assertNotNull( df.toXML());
assertNotNull(df.toXML());
String output = df.toXML().toString();
assertEquals(TEST_OUTPUT_1, output);
@ -65,10 +65,10 @@ public class DataFormTest {
assertNotNull(df);
assertNotNull(df.getFields());
assertEquals(1 , df.getFields().size() );
assertEquals(1 , df.getFields().size());
assertEquals(1 , df.getInstructions().size());
assertNotNull( df.toXML());
assertNotNull(df.toXML());
output = df.toXML().toString();
assertEquals(TEST_OUTPUT_1, output);
}
@ -93,7 +93,7 @@ public class DataFormTest {
df.addExtensionElement(layout);
assertNotNull( df.toXML());
assertNotNull(df.toXML());
String output = df.toXML().toString();
assertEquals(TEST_OUTPUT_2, output);
@ -103,14 +103,14 @@ public class DataFormTest {
assertNotNull(df);
assertNotNull(df.getExtensionElements());
assertEquals(1 , df.getExtensionElements().size() );
assertEquals(1 , df.getExtensionElements().size());
Element element = df.getExtensionElements().get(0);
assertNotNull(element);
layout = (DataLayout) element;
assertEquals(3 , layout.getPageLayout().size());
assertNotNull( df.toXML());
assertNotNull(df.toXML());
output = df.toXML().toString();
assertEquals(TEST_OUTPUT_2, output);
}
@ -127,7 +127,7 @@ public class DataFormTest {
ValidateElement dv = new RangeValidateElement("xs:integer","1111", "9999");
field.setValidateElement(dv);
assertNotNull( df.toXML());
assertNotNull(df.toXML());
String output = df.toXML().toString();
assertEquals(TEST_OUTPUT_3, output);
@ -137,14 +137,14 @@ public class DataFormTest {
assertNotNull(df);
assertNotNull(df.getFields());
assertEquals(1 , df.getFields().size() );
assertEquals(1 , df.getFields().size());
Element element = df.getFields().get(0).getValidateElement();
assertNotNull(element);
dv = (ValidateElement) element;
assertEquals("xs:integer" , dv.getDatatype());
assertNotNull( df.toXML());
assertNotNull(df.toXML());
output = df.toXML().toString();
assertEquals(TEST_OUTPUT_3, output);
}

View file

@ -76,9 +76,9 @@ public class DataLayoutTest {
Section section = new Section("section Label");
section.getSectionLayout().add(new Text("SectionText"));
layout.getPageLayout().add(section);
layout.getPageLayout().add(new Text( "PageText"));
layout.getPageLayout().add(new Text("PageText"));
assertNotNull( layout.toXML());
assertNotNull(layout.toXML());
String output = layout.toXML().toString();
assertEquals(TEST_OUTPUT_2, output);
@ -89,7 +89,7 @@ public class DataLayoutTest {
assertEquals(3 , layout.getPageLayout().size());
assertEquals("Label", layout.getLabel());
assertNotNull( layout.toXML());
assertNotNull(layout.toXML());
output = layout.toXML().toString();
assertEquals(TEST_OUTPUT_2, output);
}
@ -101,18 +101,18 @@ public class DataLayoutTest {
Fieldref reffield = new Fieldref("testField1");
layout.getPageLayout().add(reffield);
Section section = new Section("section Label - & \u00E9 \u00E1 ");
section.getSectionLayout().add(new Text( "SectionText - & \u00E9 \u00E1 "));
section.getSectionLayout().add(new Text("SectionText - & \u00E9 \u00E1 "));
layout.getPageLayout().add(section);
layout.getPageLayout().add(new Text( "PageText - & \u00E9 \u00E1 "));
layout.getPageLayout().add(new Text("PageText - & \u00E9 \u00E1 "));
section = new Section("<html>Number of Persons by<br/> Nationality and Status</html>");
section.getSectionLayout().add(new Reportedref());
layout.getPageLayout().add(section);
layout.getPageLayout().add(new Text( "<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>"));
layout.getPageLayout().add(new Text("<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>"));
assertNotNull( layout.toXML());
assertNotNull(layout.toXML());
String output = layout.toXML().toString();
assertEquals(TEST_OUTPUT_SPECIAL, output);
@ -132,7 +132,7 @@ public class DataLayoutTest {
assertEquals("<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>", text.getText());
assertNotNull( layout.toXML());
assertNotNull(layout.toXML());
output = layout.toXML().toString();
assertEquals(TEST_OUTPUT_SPECIAL, output);
}
@ -146,7 +146,7 @@ public class DataLayoutTest {
parser.next();
DataForm form = pr.parse(parser);
assertNotNull( form);
assertNotNull(form);
assertEquals(1 , form.getExtensionElements().size());
DataLayout layout = (DataLayout) form.getExtensionElements().get(0);
@ -163,7 +163,7 @@ public class DataLayoutTest {
assertEquals("<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>", text.getText());
assertNotNull( layout.toXML());
assertNotNull(layout.toXML());
String output = layout.toXML().toString();
assertEquals(TEST_OUTPUT_SPECIAL, output);
}

View file

@ -48,7 +48,7 @@ public class DataValidationTest {
ValidateElement dv = new BasicValidateElement(null);
assertNotNull( dv.toXML());
assertNotNull(dv.toXML());
String output = dv.toXML().toString();
assertEquals(TEST_OUTPUT_MIN, output);
@ -58,9 +58,9 @@ public class DataValidationTest {
assertNotNull(dv);
assertEquals("xs:string", dv.getDatatype());
assertTrue( dv instanceof BasicValidateElement);
assertTrue(dv instanceof BasicValidateElement);
assertNotNull( dv.toXML());
assertNotNull(dv.toXML());
output = dv.toXML().toString();
assertEquals(TEST_OUTPUT_MIN, output);
}
@ -71,9 +71,9 @@ public class DataValidationTest {
ValidateElement dv = new RangeValidateElement("xs:string", "min-val", "max-val");
ListRange listRange = new ListRange(111L, 999L);
dv.setListRange(listRange );
dv.setListRange(listRange);
assertNotNull( dv.toXML());
assertNotNull(dv.toXML());
String output = dv.toXML().toString();
assertEquals(TEST_OUTPUT_RANGE, output);
@ -83,7 +83,7 @@ public class DataValidationTest {
assertNotNull(dv);
assertEquals("xs:string", dv.getDatatype());
assertTrue(dv instanceof RangeValidateElement );
assertTrue(dv instanceof RangeValidateElement);
RangeValidateElement rdv = (RangeValidateElement) dv;
assertEquals("min-val", rdv.getMin());
assertEquals("max-val", rdv.getMax());
@ -92,7 +92,7 @@ public class DataValidationTest {
assertEquals(999, rdv.getListRange().getMax().intValue());
assertNotNull( dv.toXML());
assertNotNull(dv.toXML());
output = dv.toXML().toString();
assertEquals(TEST_OUTPUT_RANGE, output);
}
@ -102,7 +102,7 @@ public class DataValidationTest {
ValidateElement dv = new RangeValidateElement(null, null, null);
assertNotNull( dv.toXML());
assertNotNull(dv.toXML());
String output = dv.toXML().toString();
assertEquals(TEST_OUTPUT_RANGE2, output);
@ -112,12 +112,12 @@ public class DataValidationTest {
assertNotNull(dv);
assertEquals("xs:string", dv.getDatatype());
assertTrue(dv instanceof RangeValidateElement );
assertTrue(dv instanceof RangeValidateElement);
RangeValidateElement rdv = (RangeValidateElement) dv;
assertEquals(null, rdv.getMin());
assertEquals(null, rdv.getMax());
assertNotNull( rdv.toXML());
assertNotNull(rdv.toXML());
output = rdv.toXML().toString();
assertEquals(TEST_OUTPUT_RANGE2, output);
}

View file

@ -30,7 +30,6 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityFullJid;
@ -113,8 +112,7 @@ public class ConnectionUtils {
public Stanza answer(InvocationOnMock invocation) throws Throwable {
Stanza packet = protocol.getResponses().poll();
if (packet == null) return packet;
XMPPError xmppError = packet.getError();
if (xmppError != null) throw new XMPPErrorException(xmppError);
XMPPErrorException.ifHasErrorThenThrow(packet);
return packet;
}
};