test for escapeHTML - test added - StringBuffer replaced with StringBuilder
Signed-off-by: Laszlo Hornyak <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/726d8fc3 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/726d8fc3 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/726d8fc3 Branch: refs/heads/master Commit: 726d8fc3fcb7afc393a767894d4997fad1e994a1 Parents: 78507c0 Author: Laszlo Hornyak <[email protected]> Authored: Wed Apr 30 21:32:56 2014 +0200 Committer: Laszlo Hornyak <[email protected]> Committed: Fri May 2 21:19:49 2014 +0200 ---------------------------------------------------------------------- .../com/cloud/servlet/ConsoleProxyServlet.java | 2 +- .../cloud/servlet/ConsoleProxyServletTest.java | 35 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/726d8fc3/server/src/com/cloud/servlet/ConsoleProxyServlet.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/servlet/ConsoleProxyServlet.java b/server/src/com/cloud/servlet/ConsoleProxyServlet.java index ff8453b..8e5dfbe 100644 --- a/server/src/com/cloud/servlet/ConsoleProxyServlet.java +++ b/server/src/com/cloud/servlet/ConsoleProxyServlet.java @@ -674,7 +674,7 @@ public class ConsoleProxyServlet extends HttpServlet { if (content == null || content.isEmpty()) return content; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < content.length(); i++) { char c = content.charAt(i); switch (c) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/726d8fc3/server/test/com/cloud/servlet/ConsoleProxyServletTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/servlet/ConsoleProxyServletTest.java b/server/test/com/cloud/servlet/ConsoleProxyServletTest.java new file mode 100644 index 0000000..1fc95d2 --- /dev/null +++ b/server/test/com/cloud/servlet/ConsoleProxyServletTest.java @@ -0,0 +1,35 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 com.cloud.servlet; + +import org.junit.Assert; +import org.junit.Test; + +public class ConsoleProxyServletTest { + @Test + public void escapeHTML() { + Assert.assertNull(ConsoleProxyServlet.escapeHTML(null)); + Assert.assertEquals("", ConsoleProxyServlet.escapeHTML("")); + Assert.assertEquals("<strangevmname>", + ConsoleProxyServlet.escapeHTML("<strangevmname>")); + Assert.assertEquals(""strange vm"", + ConsoleProxyServlet.escapeHTML("\"strange vm\"")); + Assert.assertEquals("Nothing-extraordinary-anyway.", + ConsoleProxyServlet.escapeHTML("Nothing-extraordinary-anyway.")); + } +}
