-
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1116: GetRecords hardcoded prefixes in TypeNames check
- Loading branch information
1 parent
bb778f8
commit 5f7fe25
Showing
3 changed files
with
196 additions
and
7 deletions.
There are no files selected for viewing
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
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,53 @@ | ||
package org.fao.geonet.test; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Useful extensions to Junit TestCase. | ||
* | ||
* @author heikki doeleman | ||
*/ | ||
public class TestCase extends junit.framework.TestCase { | ||
|
||
/** | ||
* Just to prevent junit.framework.AssertionFailedError: No tests found in org.fao.geonet.test.TestCase. | ||
*/ | ||
public void testNothing() {} | ||
|
||
/** | ||
* Whether something is in a collection. | ||
* | ||
* @param msg | ||
* @param o | ||
* @param c | ||
*/ | ||
public static void assertContains(String msg, Object o, Collection c) { | ||
for(Object in : c) { | ||
if(o.equals(in)) { | ||
return; | ||
} | ||
} | ||
fail(msg); | ||
} | ||
|
||
/** | ||
* No-arg constructor to enable serialization. This method is not intended to be used by mere mortals without | ||
* calling setName(). | ||
*/ | ||
public TestCase() { | ||
super(); | ||
} | ||
/** | ||
* Constructs a test case with the given name. | ||
*/ | ||
public TestCase(String name) { | ||
super(name); | ||
} | ||
/** | ||
* Sets the name of a TestCase. | ||
* @param name the name to set | ||
*/ | ||
public void setName(String name) { | ||
super.setName(name); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
web/src/test/java/org/fao/geonet/util/xml/NamespaceUtilsTest.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,90 @@ | ||
package org.fao.geonet.util.xml; | ||
|
||
import jeeves.utils.Xml; | ||
import org.fao.geonet.test.TestCase; | ||
import org.jdom.Element; | ||
import org.jdom.Namespace; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* Unit test for NamespaceUtils. | ||
* | ||
* @author heikki doeleman | ||
* | ||
*/ | ||
public class NamespaceUtilsTest extends TestCase { | ||
|
||
public NamespaceUtilsTest(String name) throws Exception { | ||
super(name); | ||
} | ||
|
||
public void testNamespaceInScope() throws Exception { | ||
String xml = "<?xml version=\"1.0\"?><root " + | ||
"xmlns:a=\"http://aaa\" " + | ||
"xmlns:b=\"http://bbb\" " + | ||
"xmlns:c=\"http://ccc\" " + | ||
"xmlns:d=\"http://ddd\">" + | ||
"<a:a/></root>"; | ||
Element xmle = Xml.loadString(xml, false); | ||
List<Namespace> inScope = NamespaceUtils.getNamespacesInScope(xmle); | ||
|
||
assertContains("Expected inscope namespace " + Namespace.NO_NAMESPACE , Namespace.NO_NAMESPACE, inScope); | ||
assertContains("Expected inscope namespace " + Namespace.getNamespace("a", "http://aaa") , Namespace.getNamespace("a", "http://aaa"), inScope); | ||
assertContains("Expected inscope namespace " + Namespace.getNamespace("b", "http://bbb"), Namespace.getNamespace("b", "http://bbb"), inScope); | ||
assertContains("Expected inscope namespace " + Namespace.getNamespace("c", "http://ccc"), Namespace.getNamespace("c", "http://ccc"), inScope); | ||
assertContains("Expected inscope namespace " + Namespace.getNamespace("d", "http://ddd"), Namespace.getNamespace("d", "http://ddd"), inScope); | ||
|
||
Element a = xmle.getChild("a", Namespace.getNamespace("a", "http://aaa")); | ||
inScope = NamespaceUtils.getNamespacesInScope(a); | ||
|
||
assertContains("Expected inscope namespace " + Namespace.NO_NAMESPACE , Namespace.NO_NAMESPACE, inScope); | ||
assertContains("Expected inscope namespace " + Namespace.getNamespace("a", "http://aaa") , Namespace.getNamespace("a", "http://aaa"), inScope); | ||
assertContains("Expected inscope namespace " + Namespace.getNamespace("b", "http://bbb"), Namespace.getNamespace("b", "http://bbb"), inScope); | ||
assertContains("Expected inscope namespace " + Namespace.getNamespace("c", "http://ccc"), Namespace.getNamespace("c", "http://ccc"), inScope); | ||
assertContains("Expected inscope namespace " + Namespace.getNamespace("d", "http://ddd"), Namespace.getNamespace("d", "http://ddd"), inScope); | ||
} | ||
|
||
public void testNamespaceInherited() throws Exception { | ||
String xml = "<?xml version=\"1.0\"?><root " + | ||
"xmlns:a=\"http://aaa\" " + | ||
"xmlns:b=\"http://bbb\" " + | ||
"xmlns:c=\"http://ccc\" " + | ||
"xmlns:d=\"http://ddd\">" + | ||
"<a:a/></root>"; | ||
Element xmle = Xml.loadString(xml, false); | ||
List<Namespace> inHerited = NamespaceUtils.getNamespacesInherited(xmle); | ||
|
||
assertContains("Expected inherited namespace " + Namespace.NO_NAMESPACE , Namespace.NO_NAMESPACE, inHerited); | ||
assertContains("Expected inherited namespace " + Namespace.XML_NAMESPACE , Namespace.XML_NAMESPACE, inHerited); | ||
|
||
Element a = xmle.getChild("a", Namespace.getNamespace("a", "http://aaa")); | ||
inHerited = NamespaceUtils.getNamespacesInherited(a); | ||
|
||
assertContains("Expected inherited namespace " + Namespace.NO_NAMESPACE , Namespace.NO_NAMESPACE, inHerited); | ||
assertContains("Expected inherited namespace " + Namespace.XML_NAMESPACE , Namespace.XML_NAMESPACE, inHerited); | ||
} | ||
|
||
public void testNamespaceIntroduced() throws Exception { | ||
String xml = "<?xml version=\"1.0\"?><root " + | ||
"xmlns:a=\"http://aaa\" " + | ||
"xmlns:b=\"http://bbb\" " + | ||
"xmlns:c=\"http://ccc\" " + | ||
"xmlns:d=\"http://ddd\">" + | ||
"<a:a/></root>"; | ||
Element xmle = Xml.loadString(xml, false); | ||
List<Namespace> introduced = NamespaceUtils.getNamespacesIntroduced(xmle); | ||
|
||
assertContains("Expected introduced namespace " + Namespace.getNamespace("a", "http://aaa") , Namespace.getNamespace("a", "http://aaa"), introduced); | ||
assertContains("Expected introduced namespace " + Namespace.getNamespace("b", "http://bbb"), Namespace.getNamespace("b", "http://bbb"), introduced); | ||
assertContains("Expected introduced namespace " + Namespace.getNamespace("c", "http://ccc"), Namespace.getNamespace("c", "http://ccc"), introduced); | ||
assertContains("Expected introduced namespace " + Namespace.getNamespace("d", "http://ddd"), Namespace.getNamespace("d", "http://ddd"), introduced); | ||
|
||
Element a = xmle.getChild("a", Namespace.getNamespace("a", "http://aaa")); | ||
introduced = NamespaceUtils.getNamespacesIntroduced(a); | ||
|
||
assertEquals("Expected 0 introduced namespaces", 0, introduced.size()); | ||
|
||
} | ||
} |