BAEL-3219

This commit is contained in:
YassinHajaj 2019-09-06 16:01:11 +00:00 committed by Yassin Hajaj
parent 59729b7e23
commit f82e007672
5 changed files with 40 additions and 25 deletions

View File

@ -111,13 +111,6 @@
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
@ -332,7 +325,7 @@
</configuration>
</plugin>
<plugin>
<!-- NOTE: We don't need a groupId specification
<!-- NOTE: We don't need a groupId specification
because the group is org.apache.maven.plugins ...which is assumed by default. -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
@ -352,9 +345,9 @@
</configuration>
<executions>
<execution>
<id>make-assembly</id><!-- this is used for
<id>make-assembly</id><!-- this is used for
inheritance merges -->
<phase>package</phase><!-- append to the
<phase>package</phase><!-- append to the
packaging phase. -->
<goals>
<goal>attached</goal><!-- goals == mojos -->

View File

@ -1,7 +1,5 @@
package com.baeldung.sax;
import lombok.Data;
import lombok.ToString;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@ -23,7 +21,7 @@ public class SaxParserMain {
System.out.println(baeldungHandler.getWebsite());
}
@ToString
//@ToString
public static class BaeldungHandler extends DefaultHandler {
private static final String ARTICLES = "articles";
private static final String ARTICLE = "article";
@ -77,14 +75,38 @@ public class SaxParserMain {
}
}
@Data
//@Data
public static class Baeldung {
private List<BaeldungArticle> articleList;
public void setArticleList(List<BaeldungArticle> articleList) {
this.articleList = articleList;
}
public List<BaeldungArticle> getArticleList() {
return this.articleList;
}
}
@Data
//@Data
public static class BaeldungArticle {
private String title;
private String content;
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return this.title;
}
public void setContent(String content) {
this.content = content;
}
public String getContent() {
return this.content;
}
}
}

View File

@ -2,15 +2,15 @@
<articles>
<article>
<title>Parsing an XML File Using SAX Parser</title>
<content>Lorem ipsum...</content>
<content>SAX Parser's Lorem ipsum...</content>
</article>
<article>
<title>Parsing an XML File Using DOM Parser</title>
<content>Lorem ipsum...</content>
<content>DOM Parser's Lorem ipsum...</content>
</article>
<article>
<title>Parsing an XML File Using StAX Parser</title>
<content>Lorem ipsum...</content>
<content>StAX Parser's Lorem ipsum...</content>
</article>
</articles>
</baeldung>

View File

@ -14,7 +14,7 @@ import static org.junit.Assert.*;
public class SaxParserMainUnitTest {
@Test
public void parse_baeldung_xml_document() throws IOException, SAXException, ParserConfigurationException {
public void givenAProperXMLFile_whenItIsParsed_ThenAnObjectContainsAllItsElements() throws IOException, SAXException, ParserConfigurationException {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
@ -31,14 +31,14 @@ public class SaxParserMainUnitTest {
SaxParserMain.BaeldungArticle articleOne = articles.get(0);
assertEquals("Parsing an XML File Using SAX Parser", articleOne.getTitle());
assertEquals("Lorem ipsum...", articleOne.getContent());
assertEquals("SAX Parser's Lorem ipsum...", articleOne.getContent());
SaxParserMain.BaeldungArticle articleTwo = articles.get(1);
assertEquals("Parsing an XML File Using DOM Parser", articleTwo.getTitle());
assertEquals("Lorem ipsum...", articleTwo.getContent());
assertEquals("DOM Parser's Lorem ipsum...", articleTwo.getContent());
SaxParserMain.BaeldungArticle articleThree = articles.get(2);
assertEquals("Parsing an XML File Using StAX Parser", articleThree.getTitle());
assertEquals("Lorem ipsum...", articleThree.getContent());
assertEquals("StAX Parser's Lorem ipsum...", articleThree.getContent());
}
}

View File

@ -2,15 +2,15 @@
<articles>
<article>
<title>Parsing an XML File Using SAX Parser</title>
<content>Lorem ipsum...</content>
<content>SAX Parser's Lorem ipsum...</content>
</article>
<article>
<title>Parsing an XML File Using DOM Parser</title>
<content>Lorem ipsum...</content>
<content>DOM Parser's Lorem ipsum...</content>
</article>
<article>
<title>Parsing an XML File Using StAX Parser</title>
<content>Lorem ipsum...</content>
<content>StAX Parser's Lorem ipsum...</content>
</article>
</articles>
</baeldung>