-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from mmalmeida/fix26
Fix26
- Loading branch information
Showing
7 changed files
with
190 additions
and
18 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
69 changes: 69 additions & 0 deletions
69
...e-provider/src/test/java/com/lyncode/xoai/serviceprovider/parsers/ListSetsParserTest.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,69 @@ | ||
package com.lyncode.xoai.serviceprovider.parsers; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import com.lyncode.xml.XmlReader; | ||
import com.lyncode.xml.exceptions.XmlReaderException; | ||
import com.lyncode.xoai.model.oaipmh.Set; | ||
|
||
public class ListSetsParserTest { | ||
|
||
private static final String OAI_DC_SETS_CDATA_XML = "test/oai_dc/listsets/oai_dc-sets-CDATA.xml"; | ||
|
||
@Test | ||
public void normalParsing(){ | ||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream( | ||
"test/oai_dc/listsets/oai_dc-sets.xml"); | ||
|
||
List<Set> sets = parseXML(inputStream); | ||
assertEquals(2,sets.size()); | ||
assertEquals("setOne",sets.get(0).getSpec()); | ||
assertEquals("Set One",sets.get(0).getName()); | ||
assertEquals("setTwo",sets.get(1).getSpec()); | ||
assertEquals("Set Two",sets.get(1).getName()); | ||
} | ||
|
||
@Test | ||
public void cdataIsParsed(){ | ||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream( | ||
OAI_DC_SETS_CDATA_XML); | ||
|
||
List<Set> sets = parseXML(inputStream); | ||
assertEquals("cdataSPEC",sets.get(0).getSpec()); | ||
assertEquals("Set with CDATA",sets.get(0).getName()); | ||
|
||
} | ||
|
||
@Test | ||
public void multipleCDATAParsed(){ | ||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream( | ||
OAI_DC_SETS_CDATA_XML); | ||
|
||
List<Set> sets = parseXML(inputStream); | ||
assertEquals(2,sets.size()); | ||
assertEquals("First CDATA, Set 2 with CDATA",sets.get(1).getName()); | ||
} | ||
|
||
|
||
private List<Set> parseXML(InputStream inputStream){ | ||
XmlReader reader; | ||
try { | ||
reader = new XmlReader(inputStream); | ||
ListSetsParser parser = new ListSetsParser(reader ); | ||
List<Set> sets = parser.parse(); | ||
return sets; | ||
|
||
} catch (XmlReaderException e) { | ||
fail("unexpected exception reading the xml: "+ e.getCause().toString()); | ||
} | ||
return null; | ||
|
||
} | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
xoai-service-provider/src/test/resources/test/oai_dc-CDATA.xml
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,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-stylesheet type="text/xsl" href="http://spmfrjournal.org/lib/pkp/xml/oai2.xsl" ?> | ||
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ | ||
http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> | ||
<responseDate>2014-07-29T13:34:25Z</responseDate> | ||
<request verb="GetRecord" metadataPrefix="oai_dc" identifier="oai:ojs.spmfrjournal.org:article/88">http://spmfrjournal.org/index.php/spmfr/oai</request> | ||
<GetRecord> | ||
<record> | ||
<header> | ||
<identifier>oai:ojs.spmfrjournal.org:article/88</identifier> | ||
<datestamp>2013-10-14T06:01:49Z</datestamp> | ||
<setSpec>spmfr:EDI</setSpec> | ||
<setSpec>driver</setSpec> | ||
</header> | ||
<metadata> | ||
<oai_dc:dc | ||
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" | ||
xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ | ||
http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> | ||
<dc:title><![CDATA[Article Title]]><![CDATA[-additional CDATA]]></dc:title> | ||
</oai_dc:dc> | ||
</metadata> | ||
</record> | ||
</GetRecord> | ||
</OAI-PMH> |
18 changes: 18 additions & 0 deletions
18
xoai-service-provider/src/test/resources/test/oai_dc/listsets/oai_dc-sets-CDATA.xml
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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ | ||
http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> | ||
<responseDate>2014-07-31T09:25:24Z</responseDate> | ||
<request verb="ListSets">http://www.scielo.br/oai/scielo-oai.php</request> | ||
<ListSets> | ||
|
||
<set> | ||
<setSpec><![CDATA[cdataSPEC]]></setSpec> | ||
<setName><![CDATA[Set with CDATA]]></setName> | ||
</set> | ||
<set> | ||
<setSpec>setTwo</setSpec> | ||
<setName><![CDATA[First CDATA, ]]><![CDATA[Set 2 with CDATA]]></setName> | ||
</set> | ||
</ListSets> | ||
</OAI-PMH> |
18 changes: 18 additions & 0 deletions
18
xoai-service-provider/src/test/resources/test/oai_dc/listsets/oai_dc-sets.xml
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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ | ||
http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> | ||
<responseDate>2014-07-31T09:25:24Z</responseDate> | ||
<request verb="ListSets">http://www.scielo.br/oai/scielo-oai.php</request> | ||
<ListSets> | ||
|
||
<set> | ||
<setSpec>setOne</setSpec> | ||
<setName>Set One</setName> | ||
</set> | ||
<set> | ||
<setSpec>setTwo</setSpec> | ||
<setName>Set Two</setName> | ||
</set> | ||
</ListSets> | ||
</OAI-PMH> |