Refactor xml examples
This commit is contained in:
parent
330c8680c9
commit
40ed303abc
|
@ -1,20 +1,22 @@
|
|||
package com.baeldung.xml;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DefaultParserTest {
|
||||
|
||||
final String fileName = "src/test/resources/example.xml";
|
||||
private final String fileName = "src/test/resources/example.xml";
|
||||
|
||||
final String fileNameSpace = "src/test/resources/example_namespace.xml";
|
||||
private final String fileNameSpace = "src/test/resources/example_namespace.xml";
|
||||
|
||||
DefaultParser parser;
|
||||
private DefaultParser parser;
|
||||
|
||||
@Test
|
||||
public void getFirstLevelNodeListTest() {
|
||||
|
@ -30,7 +32,7 @@ public class DefaultParserTest {
|
|||
parser = new DefaultParser(new File(fileName));
|
||||
NodeList list = parser.getNodeListByTitle("XML");
|
||||
|
||||
for (int i = 0; null != list && i < list.getLength(); i++) {
|
||||
for (int i = 0; i < list.getLength(); i++) {
|
||||
Node nod = list.item(i);
|
||||
assertEquals("java", nod.getAttributes().getNamedItem("type").getTextContent());
|
||||
assertEquals("02", nod.getAttributes().getNamedItem("tutId").getTextContent());
|
||||
|
@ -56,7 +58,7 @@ public class DefaultParserTest {
|
|||
public void getNodeListByDateTest(){
|
||||
parser = new DefaultParser(new File(fileName));
|
||||
NodeList list = parser.getNodeListByTitle("04022016");
|
||||
for (int i = 0; null != list && i < list.getLength(); i++) {
|
||||
for (int i = 0; i < list.getLength(); i++) {
|
||||
Node nod = list.item(i);
|
||||
assertEquals("java", nod.getAttributes().getNamedItem("type").getTextContent());
|
||||
assertEquals("04", nod.getAttributes().getNamedItem("tutId").getTextContent());
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
package com.baeldung.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.Node;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class Dom4JParserTest {
|
||||
|
||||
final String fileName = "src/test/resources/example.xml";
|
||||
private static final String FILE_NAME = "src/test/resources/example.xml";
|
||||
|
||||
Dom4JParser parser;
|
||||
private Dom4JParser parser;
|
||||
|
||||
@Test
|
||||
public void getRootElementTest() {
|
||||
parser = new Dom4JParser(new File(fileName));
|
||||
parser = new Dom4JParser(new File(FILE_NAME));
|
||||
Element root = parser.getRootElement();
|
||||
|
||||
assertNotNull(root);
|
||||
|
@ -28,7 +28,7 @@ public class Dom4JParserTest {
|
|||
|
||||
@Test
|
||||
public void getFirstElementListTest() {
|
||||
parser = new Dom4JParser(new File(fileName));
|
||||
parser = new Dom4JParser(new File(FILE_NAME));
|
||||
List<Element> firstList = parser.getFirstElementList();
|
||||
|
||||
assertNotNull(firstList);
|
||||
|
@ -38,7 +38,7 @@ public class Dom4JParserTest {
|
|||
|
||||
@Test
|
||||
public void getElementByIdTest() {
|
||||
parser = new Dom4JParser(new File(fileName));
|
||||
parser = new Dom4JParser(new File(FILE_NAME));
|
||||
Node element = parser.getNodeById("03");
|
||||
|
||||
String type = element.valueOf("@type");
|
||||
|
@ -47,7 +47,7 @@ public class Dom4JParserTest {
|
|||
|
||||
@Test
|
||||
public void getElementsListByTitleTest() {
|
||||
parser = new Dom4JParser(new File(fileName));
|
||||
parser = new Dom4JParser(new File(FILE_NAME));
|
||||
Node element = parser.getElementsListByTitle("XML");
|
||||
|
||||
assertEquals("java", element.valueOf("@type"));
|
||||
|
@ -58,7 +58,7 @@ public class Dom4JParserTest {
|
|||
|
||||
@Test
|
||||
public void generateModifiedDocumentTest() {
|
||||
parser = new Dom4JParser(new File(fileName));
|
||||
parser = new Dom4JParser(new File(FILE_NAME));
|
||||
parser.generateModifiedDocument();
|
||||
|
||||
File generatedFile = new File("src/test/resources/example_updated.xml");
|
||||
|
@ -73,7 +73,7 @@ public class Dom4JParserTest {
|
|||
|
||||
@Test
|
||||
public void generateNewDocumentTest() {
|
||||
parser = new Dom4JParser(new File(fileName));
|
||||
parser = new Dom4JParser(new File(FILE_NAME));
|
||||
parser.generateNewDocument();
|
||||
|
||||
File newFile = new File("src/test/resources/example_new.xml");
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
package com.baeldung.xml;
|
||||
|
||||
import org.jdom2.Element;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom2.Element;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JDomParserTest {
|
||||
|
||||
final String fileName = "src/test/resources/example.xml";
|
||||
private final String fileName = "src/test/resources/example.xml";
|
||||
|
||||
JDomParser parser;
|
||||
private JDomParser parser;
|
||||
|
||||
@Test
|
||||
public void getFirstElementListTest() {
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
package com.baeldung.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.baeldung.xml.binding.Tutorials;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.dom4j.Node;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.xml.binding.Tutorials;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class JaxbParserTest {
|
||||
|
||||
|
||||
final String fileName = "src/test/resources/example.xml";
|
||||
private final String fileName = "src/test/resources/example.xml";
|
||||
|
||||
JaxbParser parser;
|
||||
private JaxbParser parser;
|
||||
|
||||
@Test
|
||||
public void getFullDocumentTest(){
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package com.baeldung.xml;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class JaxenDemoTest {
|
||||
|
||||
final String fileName = "src/test/resources/example.xml";
|
||||
private final String fileName = "src/test/resources/example.xml";
|
||||
|
||||
JaxenDemo jaxenDemo;
|
||||
private JaxenDemo jaxenDemo;
|
||||
|
||||
@Test
|
||||
public void getFirstLevelNodeListTest() {
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
package com.baeldung.xml;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.baeldung.xml.model.Tutorial;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.xml.model.Tutorial;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class StaxParserTest {
|
||||
|
||||
final String fileName = "src/test/resources/example.xml";
|
||||
private final String fileName = "src/test/resources/example.xml";
|
||||
|
||||
StaxParser parser;
|
||||
private StaxParser parser;
|
||||
|
||||
@Test
|
||||
public void getAllTutorialsTest(){
|
||||
|
|
Loading…
Reference in New Issue