Skip to content

Commit

Permalink
chore(namespaces): Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed May 28, 2024
1 parent 3850301 commit fe12b91
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/java/com/github/olivergondza/saxeed/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import com.github.olivergondza.saxeed.ex.FailedTransforming;
import org.junit.jupiter.api.Test;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -315,4 +318,29 @@ void nsSubscribe() {
"plain>default>A:a>d>", "d(DEFAULT)"
), namespaced.visited);
}

@Test
void processRealistic() {
Subscribed subs = Subscribed.to().namespaceUris("http://www.w3.org/2001/XMLSchema").build();

class Visitor implements UpdatingVisitor {
public final Set<String> qualifiedNames = new HashSet<>();

@Override
public void startTag(Tag.Start tag) throws FailedTransforming {
qualifiedNames.add(tag.getName().getQualifiedName());
}
}
Visitor visitor = new Visitor();
TransformationBuilder tb = new TransformationBuilder().add(subs, visitor);
new Saxeed()
.setInput(Path.of("src/test/resources/schema.xsd"))
.addTransformation(tb)
.transform()
;

assertEquals(Set.of(
"xs:schema", "xs:element", "xs:complexType", "xs:sequence", "xs:attribute"
), visitor.qualifiedNames);
}
}
31 changes: 31 additions & 0 deletions src/test/resources/schema.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

0 comments on commit fe12b91

Please sign in to comment.