use of org.jboss.staxmapper.XMLExtendedStreamWriter in project wildfly-core by wildfly.
the class PersistentResourceXMLParserTestCase method testSimpleParser.
@Test
public void testSimpleParser() throws Exception {
MyParser parser = new MyParser();
String xml = readResource("simple-subsystem.xml");
StringReader strReader = new StringReader(xml);
XMLMapper mapper = XMLMapper.Factory.create();
mapper.registerRootElement(new QName(MyParser.NAMESPACE, "subsystem"), parser);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader));
List<ModelNode> operations = new ArrayList<>();
mapper.parseDocument(operations, reader);
Assert.assertEquals(4, operations.size());
ModelNode subsystem = opsToModel(operations);
ModelNode resource = subsystem.get("resource", "foo");
ModelNode complexMap = MyParser.COMPLEX_MAP.resolveModelAttribute(ExpressionResolver.TEST_RESOLVER, resource);
Assert.assertEquals("Model type should be map", ModelType.OBJECT, complexMap.getType());
Assert.assertEquals("Map should have 3 elements", 3, complexMap.asList().size());
Assert.assertEquals("some.class1", complexMap.get("key1", "name").asString());
Assert.assertEquals("some.class2", complexMap.get("key2", "name").asString());
Assert.assertEquals("some.module3", complexMap.get("key3", "module").asString());
StringWriter stringWriter = new StringWriter();
XMLExtendedStreamWriter xmlStreamWriter = createXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter));
SubsystemMarshallingContext context = new SubsystemMarshallingContext(subsystem, xmlStreamWriter);
mapper.deparseDocument(parser, context, xmlStreamWriter);
String out = stringWriter.toString();
Assert.assertEquals(normalizeXML(xml), normalizeXML(out));
}
use of org.jboss.staxmapper.XMLExtendedStreamWriter in project keycloak by keycloak.
the class KeycloakAdapterConfigDeploymentProcessor method getXML.
private String getXML(DeploymentUnit deploymentUnit) throws XMLStreamException {
ModelNode node = Configuration.INSTANCE.getSecureDeployment(deploymentUnit);
if (node != null) {
KeycloakSubsystemParser writer = new KeycloakSubsystemParser();
ByteArrayOutputStream output = new ByteArrayOutputStream();
XMLExtendedStreamWriter streamWriter = new FormattingXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(output));
try {
streamWriter.writeStartElement("keycloak-saml-adapter");
writer.writeSps(streamWriter, node);
streamWriter.writeEndElement();
} finally {
streamWriter.close();
}
return new String(output.toByteArray(), Charset.forName("utf-8"));
}
return null;
}
use of org.jboss.staxmapper.XMLExtendedStreamWriter in project keycloak by keycloak.
the class KeycloakAdapterConfigDeploymentProcessor method getXML.
private String getXML(DeploymentUnit deploymentUnit) throws XMLStreamException {
ModelNode node = Configuration.INSTANCE.getSecureDeployment(deploymentUnit);
if (node != null) {
KeycloakSubsystemParser writer = new KeycloakSubsystemParser();
ByteArrayOutputStream output = new ByteArrayOutputStream();
XMLExtendedStreamWriter streamWriter = new FormattingXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(output));
try {
streamWriter.writeStartElement("keycloak-saml-adapter");
writer.writeSps(streamWriter, node);
streamWriter.writeEndElement();
} finally {
streamWriter.close();
}
return new String(output.toByteArray(), Charset.forName("utf-8"));
}
return null;
}
use of org.jboss.staxmapper.XMLExtendedStreamWriter in project wildfly-core by wildfly.
the class PersistentResourceXMLParserTestCase method testServerParser.
@Test
public void testServerParser() throws Exception {
ServerParser parser = new ServerParser();
String xml = readResource("server-subsystem.xml");
StringReader strReader = new StringReader(xml);
XMLMapper mapper = XMLMapper.Factory.create();
mapper.registerRootElement(new QName(MyParser.NAMESPACE, "subsystem"), parser);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader));
List<ModelNode> operations = new ArrayList<>();
mapper.parseDocument(operations, reader);
Assert.assertEquals(4, operations.size());
ModelNode subsystem = opsToModel(operations);
ModelNode server = subsystem.get("server", "default");
ModelNode interceptors = MyParser.INTERCEPTORS.resolveModelAttribute(ExpressionResolver.TEST_RESOLVER, server);
Assert.assertEquals("Model type should be list", ModelType.LIST, interceptors.getType());
Assert.assertEquals("List should have 0 elements", 0, interceptors.asList().size());
// this one should be undefined
ModelNode complexList = MyParser.COMPLEX_LIST.resolveModelAttribute(ExpressionResolver.TEST_RESOLVER, server);
Assert.assertTrue("Should be empty", !complexList.isDefined());
// this one should be undefined
ModelNode complexListWithDefault = MyParser.COMPLEX_LIST_WITH_DEFAULT.resolveModelAttribute(ExpressionResolver.TEST_RESOLVER, server);
Assert.assertEquals("Model type should be list", ModelType.LIST, complexListWithDefault.getType());
Assert.assertEquals("List should have 1 elements", 1, complexListWithDefault.asList().size());
/*List<ModelNode> unwrapped = MyParser.COMPLEX_LIST_WITH_DEFAULT.unwrap(ExpressionResolver.TEST_RESOLVER, server); //this one should be undefined
Assert.assertEquals("it should contain one element", 1, unwrapped.size());*/
StringWriter stringWriter = new StringWriter();
XMLExtendedStreamWriter xmlStreamWriter = createXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter));
SubsystemMarshallingContext context = new SubsystemMarshallingContext(subsystem, xmlStreamWriter);
mapper.deparseDocument(parser, context, xmlStreamWriter);
String out = stringWriter.toString();
Assert.assertEquals(normalizeXML(xml), normalizeXML(out));
}
use of org.jboss.staxmapper.XMLExtendedStreamWriter in project wildfly-core by wildfly.
the class PersistentResourceXMLParserTestCase method testMail.
@Test
public void testMail() throws Exception {
MyParser parser = new MailParser();
String xml = readResource("mail-parser.xml");
StringReader strReader = new StringReader(xml);
XMLMapper mapper = XMLMapper.Factory.create();
mapper.registerRootElement(new QName(MyParser.NAMESPACE, "subsystem"), parser);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader));
List<ModelNode> operations = new ArrayList<>();
mapper.parseDocument(operations, reader);
Assert.assertEquals(4, operations.size());
ModelNode subsystem = opsToModel(operations);
ModelNode propsModel = subsystem.get("mail-session", "custom");
assertTrue("Model should be defined", propsModel.has(MyParser.WRAPPED_PROPERTIES.getName()));
Map<String, String> props = MyParser.WRAPPED_PROPERTIES.unwrap(ExpressionResolver.TEST_RESOLVER, propsModel);
Assert.assertEquals(0, props.size());
StringWriter stringWriter = new StringWriter();
XMLExtendedStreamWriter xmlStreamWriter = createXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter));
SubsystemMarshallingContext context = new SubsystemMarshallingContext(subsystem, xmlStreamWriter);
mapper.deparseDocument(parser, context, xmlStreamWriter);
String out = stringWriter.toString();
Assert.assertEquals(normalizeXML(xml), normalizeXML(out));
}
Aggregations