Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for escape/unescape methods
- Loading branch information
1 parent
35930a8
commit fca915f
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...n/bridge/bridge-api/src/test/java/com/sun/messaging/bridge/api/StompFrameMessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2022 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package com.sun.messaging.bridge.api; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class StompFrameMessageTest { | ||
|
||
/* | ||
* "All frames except the CONNECT and CONNECTED frames will also escape any carriage return, line feed or colon | ||
* found in the resulting UTF-8 encoded headers." | ||
* - https://stomp.github.io/stomp-specification-1.2.html#Value_Encoding | ||
*/ | ||
@Test | ||
void unescapeSpecialChars() { | ||
// carriage return, line feed, colon and backslash | ||
assertEquals("\r\n:\\", StompFrameMessage.unescapeSpecialChars("\\r\\n\\c\\\\")); | ||
|
||
// opposite order | ||
assertEquals("\\:\n\r", StompFrameMessage.unescapeSpecialChars("\\\\\\c\\n\\r")); | ||
|
||
// real world examples | ||
assertEquals("c:\\Users", StompFrameMessage.unescapeSpecialChars("c\\c\\\\Users")); | ||
assertEquals("http:\\\\server:port", StompFrameMessage.unescapeSpecialChars("http\\c\\\\\\\\server\\cport")); | ||
} | ||
|
||
@Test | ||
void escapeSpecialChars() { | ||
// carriage return, line feed, colon and backslash | ||
assertEquals("\\r\\n\\c\\\\", StompFrameMessage.escapeSpecialChars("\r\n:\\")); | ||
|
||
// opposite order | ||
assertEquals("\\\\\\c\\n\\r", StompFrameMessage.escapeSpecialChars("\\:\n\r")); | ||
|
||
// real world examples | ||
assertEquals("c\\c\\\\Users", StompFrameMessage.escapeSpecialChars("c:\\Users")); | ||
assertEquals("http\\c\\\\\\\\server\\cport", StompFrameMessage.escapeSpecialChars("http:\\\\server:port")); | ||
} | ||
} |