From 199311eda16b7b6a3457129fe0f1585bb6289293 Mon Sep 17 00:00:00 2001 From: Ingo Bauersachs Date: Sat, 5 Aug 2017 17:05:40 +0200 Subject: [PATCH 1/2] Fix error Condition to Type mappings to match RFC 6120 Synchronize the Javadoc table to match the actual implementation. --- .../org/jivesoftware/smack/packet/XMPPError.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java index 3913fe374..fc96cbbfa 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java @@ -39,14 +39,14 @@ import org.jivesoftware.smack.util.XmlStringBuilder; * conflictCANCEL8.3.3.2 * feature-not-implementedCANCEL8.3.3.3 * forbiddenAUTH8.3.3.4 - * goneMODIFY8.3.3.5 + * goneCANCEL8.3.3.5 * internal-server-errorWAIT8.3.3.6 * item-not-foundCANCEL8.3.3.7 * jid-malformedMODIFY8.3.3.8 - * not-acceptable MODIFY8.3.3.9 + * not-acceptableMODIFY8.3.3.9 * not-allowedCANCEL8.3.3.10 * not-authorizedAUTH8.3.3.11 - * policy-violationAUTH8.3.3.12 + * policy-violationMODIFY8.3.3.12 * recipient-unavailableWAIT8.3.3.13 * redirectMODIFY8.3.3.14 * registration-requiredAUTH8.3.3.15 @@ -55,7 +55,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder; * resource-constraintWAIT8.3.3.18 * service-unavailableCANCEL8.3.3.19 * subscription-requiredAUTH8.3.3.20 - * undefined-conditionWAIT8.3.3.21 + * undefined-conditionMODIFY8.3.3.21 * unexpected-requestWAIT8.3.3.22 * * @@ -91,9 +91,10 @@ public class XMPPError extends AbstractError { CONDITION_TO_TYPE.put(Condition.remote_server_not_found, Type.CANCEL); CONDITION_TO_TYPE.put(Condition.remote_server_timeout, Type.WAIT); CONDITION_TO_TYPE.put(Condition.resource_constraint, Type.WAIT); - CONDITION_TO_TYPE.put(Condition.service_unavailable, Type.WAIT); - CONDITION_TO_TYPE.put(Condition.subscription_required, Type.WAIT); - CONDITION_TO_TYPE.put(Condition.unexpected_request, Type.MODIFY); + CONDITION_TO_TYPE.put(Condition.service_unavailable, Type.CANCEL); + CONDITION_TO_TYPE.put(Condition.subscription_required, Type.AUTH); + CONDITION_TO_TYPE.put(Condition.undefined_condition, Type.MODIFY); + CONDITION_TO_TYPE.put(Condition.unexpected_request, Type.WAIT); } private final Condition condition; From 25114b3fc1b3510a734524139080e970eb8b45ee Mon Sep 17 00:00:00 2001 From: Ingo Bauersachs Date: Sat, 5 Aug 2017 17:06:13 +0200 Subject: [PATCH 2/2] Add a test to ensure all Conditions have a Type mapping --- .../jivesoftware/smack/packet/XMPPError.java | 2 +- .../smack/packet/XMPPErrorTest.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 smack-core/src/test/java/org/jivesoftware/smack/packet/XMPPErrorTest.java diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java index fc96cbbfa..54d40a47a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java @@ -70,7 +70,7 @@ public class XMPPError extends AbstractError { public static final String ERROR = "error"; private static final Logger LOGGER = Logger.getLogger(XMPPError.class.getName()); - private static final Map CONDITION_TO_TYPE = new HashMap(); + static final Map CONDITION_TO_TYPE = new HashMap(); static { CONDITION_TO_TYPE.put(Condition.bad_request, Type.MODIFY); diff --git a/smack-core/src/test/java/org/jivesoftware/smack/packet/XMPPErrorTest.java b/smack-core/src/test/java/org/jivesoftware/smack/packet/XMPPErrorTest.java new file mode 100644 index 000000000..f2e84a3f7 --- /dev/null +++ b/smack-core/src/test/java/org/jivesoftware/smack/packet/XMPPErrorTest.java @@ -0,0 +1,35 @@ +/** + * + * Copyright © 2017 Ingo Bauersachs + * + * 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.smack.packet; + +import static org.jivesoftware.smack.packet.XMPPError.Condition; +import static org.jivesoftware.smack.packet.XMPPError.Type; +import static org.junit.Assert.assertEquals; + +import java.util.Map; + +import org.junit.Test; + +public class XMPPErrorTest { + @Test + public void testConditionHasDefaultTypeMapping() throws NoSuchFieldException, IllegalAccessException { + Map conditionToTypeMap = XMPPError.CONDITION_TO_TYPE; + assertEquals("CONDITION_TO_TYPE map is likely out of sync with Condition enum", + Condition.values().length, + conditionToTypeMap.size()); + } +}