Author: adietish
Date: 2011-09-20 07:27:35 -0400 (Tue, 20 Sep 2011)
New Revision: 34877
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/JsonSanitizerTest.java
Log:
[JBIDE-9748] added tests for JsonSanitizer
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/JsonSanitizerTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/JsonSanitizerTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/JsonSanitizerTest.java 2011-09-20
11:27:35 UTC (rev 34877)
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.openshift.test.internal.core;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jboss.dmr.ModelNode;
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
+import org.jboss.ide.eclipse.as.openshift.core.internal.response.JsonSanitizer;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class JsonSanitizerTest {
+
+ @Test
+ public void canSanitizeQuotedJsonObject() throws OpenshiftException {
+ String quotedJsonObject =
+ "\"{"
+ + "\\\"carts\\\":"
+ + "\\\"perl-5.10\\\""
+ + "}\"";
+
+ String sanitizedJson = JsonSanitizer.sanitize(quotedJsonObject);
+ assertEquals("{\"carts\":\"perl-5.10\"}",
sanitizedJson);
+ }
+
+ @Test
+ public void doesNotTuchValidJson() throws OpenshiftException {
+ String quotedJsonObject =
+ "{"
+ + "\"carts\":"
+ + "\"perl-5.10\""
+ + "}";
+
+ String sanitizedJson = JsonSanitizer.sanitize(quotedJsonObject);
+ assertEquals("{\"carts\":\"perl-5.10\"}",
sanitizedJson);
+ }
+
+ @Test
+ public void doesNotRemoveEscapedQuoteInStringValue() throws OpenshiftException {
+ String quotedJsonObject =
+ "{"
+ + "\"property\":"
+ + "\"stringWithA\\\"Quote\""
+ + "}";
+
+ String sanitizedJson = JsonSanitizer.sanitize(quotedJsonObject);
+ assertEquals("{\"property\":\"stringWithA\\\"Quote\"}",
sanitizedJson);
+ ModelNode node = ModelNode.fromJSONString(sanitizedJson);
+ assertEquals("stringWithA\"Quote",
node.get("property").asString());
+ }
+
+}
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/JsonSanitizerTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain