Author: rezan
Date: Mon Oct 20 23:15:02 2014
New Revision: 1633254
URL: http://svn.apache.org/r1633254
Log:
xml unit tests
Added:
incubator/devicemap/trunk/devicemap/java/classifier/src/test/java/org/apache/devicemap/loader/
incubator/devicemap/trunk/devicemap/java/classifier/src/test/java/org/apache/devicemap/loader/parser/
incubator/devicemap/trunk/devicemap/java/classifier/src/test/java/org/apache/devicemap/loader/parser/XMLParserTest.java
(with props)
Modified:
incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/parser/XMLParser.java
Modified:
incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/parser/XMLParser.java
URL:
http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/parser/XMLParser.java?rev=1633254&r1=1633253&r2=1633254&view=diff
==============================================================================
---
incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/parser/XMLParser.java
(original)
+++
incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/parser/XMLParser.java
Mon Oct 20 23:15:02 2014
@@ -61,8 +61,12 @@ public class XMLParser {
}
}
- if(ret.lastIndexOf("<!--") == 0 && (ret.lastIndexOf("-->") + 3) !=
ret.length()) {
- return "";
+ if(ret.lastIndexOf("<!--") == 0) {
+ if((ret.lastIndexOf("-->") + 3) == ret.length()) {
+ return getNextTag();
+ } else {
+ return "";
+ }
}
return ret.toString();
Added:
incubator/devicemap/trunk/devicemap/java/classifier/src/test/java/org/apache/devicemap/loader/parser/XMLParserTest.java
URL:
http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/java/classifier/src/test/java/org/apache/devicemap/loader/parser/XMLParserTest.java?rev=1633254&view=auto
==============================================================================
---
incubator/devicemap/trunk/devicemap/java/classifier/src/test/java/org/apache/devicemap/loader/parser/XMLParserTest.java
(added)
+++
incubator/devicemap/trunk/devicemap/java/classifier/src/test/java/org/apache/devicemap/loader/parser/XMLParserTest.java
Mon Oct 20 23:15:02 2014
@@ -0,0 +1,51 @@
+/*
+ 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 org.apache.devicemap.loader.parser;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class XMLParserTest {
+
+ @Test
+ public void parserTest() throws Exception {
+ final String firstTag = "<tag attr=\"att"rv\">";
+ final String xml = firstTag +
+ "</tag>\n" +
+ "<!-- <comment>\n" +
+ "something here -->" +
+ "<real>"value"&here<</real>" +
+ "<!-- bye ";
+
+ XMLParser parser = new XMLParser(new InputStreamReader(new
ByteArrayInputStream(xml.getBytes("UTF-8"))));
+
+ String tag = parser.getNextTag();
+
+ Assert.assertEquals("First tag isnt <tag>", firstTag, tag);
+ Assert.assertEquals("<tag> attribute is correct", "att\"rv",
XMLParser.getAttribute(tag, "attr"));
+ Assert.assertEquals("2ns tag isnt </tag>", "</tag>",
parser.getNextTag());
+ Assert.assertEquals("3rd tag isnt <real>", "<real>",
parser.getNextTag());
+ Assert.assertEquals("3rd tag value is incorrect", "\"value\"&here<",
parser.getTagValue());
+ Assert.assertEquals("4th tag isnt </real>", "</real>",
parser.getNextTag());
+ Assert.assertEquals("Parser didnt return empty", "",
parser.getNextTag());
+ Assert.assertEquals("Parser didnt return empty second time", "",
parser.getNextTag());
+ }
+}
Propchange:
incubator/devicemap/trunk/devicemap/java/classifier/src/test/java/org/apache/devicemap/loader/parser/XMLParserTest.java
------------------------------------------------------------------------------
svn:executable = *