Java Code Examples for org.jboss.staxmapper.XMLMapper#registerRootElement()
The following examples show how to use
org.jboss.staxmapper.XMLMapper#registerRootElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Jbas9020TestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testFSExploded() throws Exception { final String xml = "<?xml version='1.0' encoding='UTF-8'?>" + "<server name=\"example\" xmlns=\"urn:jboss:domain:1.0\">" + " <deployments>" + " <deployment name=\"test.war\" runtime-name=\"test-run.war\">" + " <fs-exploded path=\"deployments/test.jar\" relative-to=\"jboss.server.base.dir\"/>" + " </deployment>" + " </deployments>" + "</server>"; final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml)); final StandaloneXml parser = new StandaloneXml(null, null, null, null); final List<ModelNode> operationList = new ArrayList<ModelNode>(); final XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(new QName(namespace, "server"), parser); mapper.parseDocument(operationList, reader); final ModelNode content = operationList.get(1).get("content"); assertEquals(false, content.get(0).get("archive").asBoolean()); assertEquals("deployments/test.jar", content.get(0).get("path").asString()); assertEquals("jboss.server.base.dir", content.get(0).get("relative-to").asString()); }
Example 2
Source File: Jbas9020TestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testFSArchive() throws Exception { final String xml = "<?xml version='1.0' encoding='UTF-8'?>" + "<server name=\"example\" xmlns=\"urn:jboss:domain:1.0\">" + " <deployments>" + " <deployment name=\"test.war\" runtime-name=\"test-run.war\">" + " <fs-archive path=\"${jboss.home}/content/welcome.jar\"/>" + " </deployment>" + " </deployments>" + "</server>"; final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml)); final StandaloneXml parser = new StandaloneXml(null, null, null, null); final List<ModelNode> operationList = new ArrayList<ModelNode>(); final XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(new QName(namespace, "server"), parser); mapper.parseDocument(operationList, reader); System.out.println(operationList.get(1)); final ModelNode content = operationList.get(1).get("content"); assertEquals(true, content.get(0).get("archive").asBoolean()); assertEquals("${jboss.home}/content/welcome.jar", content.get(0).get("path").asString()); }
Example 3
Source File: Jbas9020TestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testContent() throws Exception { final String xml = "<?xml version='1.0' encoding='UTF-8'?>" + "<server name=\"example\" xmlns=\"urn:jboss:domain:1.0\">" + " <deployments>" + " <deployment name=\"test.war\" runtime-name=\"test-run.war\">" + " <content sha1=\"1234\"/>" + " </deployment>" + " </deployments>" + "</server>"; final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml)); final StandaloneXml parser = new StandaloneXml(null, null, null, null); final List<ModelNode> operationList = new ArrayList<ModelNode>(); final XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(new QName(namespace, "server"), parser); mapper.parseDocument(operationList, reader); final ModelNode content = operationList.get(1).get("content"); assertArrayEquals(new byte[] { 0x12, 0x34 }, content.get(0).get("hash").asBytes()); }
Example 4
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testComplexAttributesStuff() throws Exception { CoreParser parser = new CoreParser(); String xml = readResource("core-subsystem.xml"); StringReader strReader = new StringReader(xml); XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(new QName("urn:jboss:domain:core:1.0", "subsystem"), parser); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader)); List<ModelNode> operations = new ArrayList<>(); mapper.parseDocument(operations, reader); Assert.assertEquals(2, operations.size()); Assert.assertEquals(2, operations.get(1).get("listeners").asList().size()); ModelNode subsystem = opsToModel(operations); 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)); }
Example 5
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testChildlessResource() throws Exception { MyParser parser = new ChildlessParser(); String xml = "<subsystem xmlns=\"" + MyParser.NAMESPACE + "\">" + " <cluster attr1=\"alice\"/>" + "</subsystem>"; 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); ModelNode subsystem = opsToModel(operations); 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)); }
Example 6
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testORBSubsystem() throws Exception { IIOPSubsystemParser parser = new IIOPSubsystemParser(); String xml = readResource("orb-subsystem.xml"); StringReader strReader = new StringReader(xml); XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(new QName("urn:jboss:domain:orb-test:1.0", "subsystem"), parser); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader)); List<ModelNode> operations = new ArrayList<>(); mapper.parseDocument(operations, reader); Assert.assertEquals(1, operations.size()); ModelNode subsystem = opsToModel(operations); 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)); }
Example 7
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testElementParsers() throws Exception { MyParser parser = new MyParser(); String xml = readResource("elements.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(5, operations.size()); ModelNode subsystem = opsToModel(operations); 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)); }
Example 8
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testServerWithComplexAttributeParser() throws Exception { ServerParser parser = new ServerParser(); String xml = readResource("server-complex-attribute.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(5, operations.size()); ModelNode subsystem = opsToModel(operations); 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)); }
Example 9
Source File: TestParser.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static TestParser create(ExtensionRegistry registry, XMLMapper xmlMapper, TestModelType type) { TestParser testParser; String root; if (type == TestModelType.STANDALONE) { StandaloneXml standaloneXml = new StandaloneXml(null, Executors.newCachedThreadPool(), registry); testParser = new TestParser(type, standaloneXml, standaloneXml); root = "server"; } else if (type == TestModelType.DOMAIN) { DomainXml domainXml = new DomainXml(null, Executors.newCachedThreadPool(), registry); testParser = new TestParser(type, domainXml, domainXml); root = "domain"; } else if (type == TestModelType.HOST) { HostXml hostXml = new HostXml("master", RunningMode.NORMAL, false, null, Executors.newCachedThreadPool(), registry); testParser = new TestParser(type, hostXml, hostXml); root = "host"; } else { throw new IllegalArgumentException("Unknown type " + type); } try { for (Namespace ns : Namespace.ALL_NAMESPACES) { xmlMapper.registerRootElement(new QName(ns.getUriString(), root), testParser); } } catch (NoSuchFieldError e) { //7.1.2 does not have the ALL_NAMESPACES field xmlMapper.registerRootElement(new QName(Namespace.DOMAIN_1_0.getUriString(), root), testParser); xmlMapper.registerRootElement(new QName(Namespace.DOMAIN_1_1.getUriString(), root), testParser); xmlMapper.registerRootElement(new QName(Namespace.DOMAIN_1_2.getUriString(), root), testParser); } return testParser; }
Example 10
Source File: SystemPropertiesParsingTest.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testSystemPropertyAlreadyExistIsCalled() throws Exception { // assign two properties in the system System.setProperty("org.jboss.as.server.parsing.test", "test-value"); System.setProperty("org.jboss.as.server.parsing.secret", "super-secret-value"); System.setProperty("org.jboss.as.server.parsing.secret-nested", "super-secret-value"); try { final String xml = "<?xml version='1.0' encoding='UTF-8'?>" + "<server name=\"example\" xmlns=\"urn:jboss:domain:8.0\">" + " <system-properties>\n" + " <property name=\"org.jboss.as.server.parsing.secret\" value=\"${VAULT::vb::password::1}\"/>\n" + " <property name=\"org.jboss.as.server.parsing.secret-nested\" value=\"${VAULT::vb::${not-found:password}::1}\"/>\n" + " <property name=\"org.jboss.as.server.parsing.test\" value=\"other-value\"/>\n" + " </system-properties>\n" + "</server>"; final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml)); final ExtensionRegistry extensionRegistry = new ExtensionRegistry(ProcessType.STANDALONE_SERVER, new RunningModeControl(RunningMode.NORMAL), null, null, null, RuntimeHostControllerInfoAccessor.SERVER); final StandaloneXml parser = new StandaloneXml(null, null, extensionRegistry); final List<ModelNode> operationList = new ArrayList<>(); final XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(new QName(namespace, "server"), parser); mapper.parseDocument(operationList, reader); // assert the method is called only once for test Mockito.verify(mockedLogger, Mockito.times(1)).systemPropertyAlreadyExist(Mockito.anyString()); Mockito.verify(mockedLogger, Mockito.times(1)).systemPropertyAlreadyExist(Mockito.eq("org.jboss.as.server.parsing.test")); } finally { System.clearProperty("org.jboss.as.server.parsing.test"); System.clearProperty("org.jboss.as.server.parsing.secret"); System.clearProperty("org.jboss.as.server.parsing.secret-nested"); } }
Example 11
Source File: JBossAllXMLParsingProcessor.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); VirtualFile descriptor = null; for (final String loc : DEPLOYMENT_STRUCTURE_DESCRIPTOR_LOCATIONS) { final VirtualFile file = root.getRoot().getChild(loc); if (file.exists()) { descriptor = file; break; } } if(descriptor == null) { return; } final XMLMapper mapper = XMLMapper.Factory.create(); final Map<QName, AttachmentKey<?>> namespaceAttachments = new HashMap<QName, AttachmentKey<?>>(); for(final JBossAllXMLParserDescription<?> parser : deploymentUnit.getAttachmentList(JBossAllXMLParserDescription.ATTACHMENT_KEY)) { namespaceAttachments.put(parser.getRootElement(), parser.getAttachmentKey()); mapper.registerRootElement(parser.getRootElement(), new JBossAllXMLElementReader(parser)); } mapper.registerRootElement(new QName(Namespace.JBOSS_1_0.getUriString(), JBOSS), Parser.INSTANCE); mapper.registerRootElement(new QName(Namespace.NONE.getUriString(), JBOSS), Parser.INSTANCE); final JBossAllXmlParseContext context = new JBossAllXmlParseContext(deploymentUnit); parse(descriptor, mapper, context); //we use this map to detect the presence of two different but functionally equivalent namespaces final Map<AttachmentKey<?>, QName> usedNamespaces = new HashMap<AttachmentKey<?>, QName>(); for(Map.Entry<QName, Object> entry : context.getParseResults().entrySet()) { final AttachmentKey attachmentKey = namespaceAttachments.get(entry.getKey()); if(usedNamespaces.containsKey(attachmentKey)) { throw ServerLogger.ROOT_LOGGER.equivalentNamespacesInJBossXml(entry.getKey(), usedNamespaces.get(attachmentKey)); } usedNamespaces.put(attachmentKey, entry.getKey()); deploymentUnit.putAttachment(attachmentKey, entry.getValue()); } }
Example 12
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@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()); ModelNode complexList = MyParser.COMPLEX_LIST.resolveModelAttribute(ExpressionResolver.TEST_RESOLVER, server); //this one should be undefined Assert.assertTrue("Should be empty", !complexList.isDefined()); ModelNode complexListWithDefault = MyParser.COMPLEX_LIST_WITH_DEFAULT.resolveModelAttribute(ExpressionResolver.TEST_RESOLVER, server); //this one should be undefined 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)); }
Example 13
Source File: TestParserUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Builds the utils needed to parse the document * * @return the test parser utils */ public TestParserUtils build() { XMLMapper xmlMapper = XMLMapper.Factory.create(); ExtensionRegistry extensionParsingRegistry = new ExtensionRegistry(processType, new RunningModeControl(runningMode), null, null, null, hostControllerInfoAccessor); TestParser testParser = new TestParser(subsystemName, extensionParsingRegistry); xmlMapper.registerRootElement(new QName(namespace, "test"), testParser); extension.initializeParsers(extensionParsingRegistry.getExtensionParsingContext("Test", xmlMapper)); String wrappedXml = "<" + rootWrapperName + " xmlns=\"" + namespace + "\">" + subsystemXml + "</test>"; return new TestParserUtils(xmlMapper, wrappedXml); }
Example 14
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@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)); }
Example 15
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test(expected = XMLStreamException.class) public void testInvalidGroups() throws Exception { MyParser parser = new AttributeGroupParser(); String xml = "<subsystem xmlns=\"" + MyParser.NAMESPACE + "\">" + " <invalid/>" + "</subsystem>"; 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); }
Example 16
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test(expected = XMLStreamValidationException.class) public void testInvalidMultipleObjectTypes() throws Exception { MyParser parser = new AttributeGroupParser(); String xml = readResource("invalid-multiple-object-type-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); }
Example 17
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test(expected = XMLStreamValidationException.class) public void testInvalidMultipleGroups() throws Exception { MyParser parser = new AttributeGroupParser(); String xml = readResource("invalid-multiple-groups-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); }
Example 18
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testGroups() throws Exception { MyParser parser = new AttributeGroupParser(); String xml = readResource("groups-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); ModelNode subsystem = opsToModel(operations); assertEquals("bar", subsystem.get("resource", "foo", "cluster-attr1").asString()); assertEquals("baz", subsystem.get("resource", "foo", "cluster-attr2").asString()); assertEquals("alice", subsystem.get("resource", "foo", "security-my-attr1").asString()); assertEquals("bob", subsystem.get("resource", "foo", "security-my-attr2").asString()); assertEquals("val", subsystem.get("resource", "foo", "props", "prop").asString()); assertEquals("val", subsystem.get("resource", "foo", "wrapped-properties", "prop").asString()); assertEquals("bar2", subsystem.get("resource", "foo2", "cluster-attr1").asString()); assertEquals("baz2", subsystem.get("resource", "foo2", "cluster-attr2").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)); }
Example 19
Source File: PersistentResourceXMLParserTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testWrappersAndGroups() throws Exception { MyParser parser = new MyParser(); String xml = readResource("groups-wrappers-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); ModelNode subsystem = opsToModel(operations); assertEquals("bar", subsystem.get("resource", "foo", "cluster-attr1").asString()); assertEquals("baz", subsystem.get("resource", "foo", "cluster-attr2").asString()); assertEquals("alice", subsystem.get("resource", "foo", "security-my-attr1").asString()); assertEquals("bob", subsystem.get("resource", "foo", "security-my-attr2").asString()); assertEquals("bar2", subsystem.get("resource", "foo2", "cluster-attr1").asString()); assertEquals("baz2", subsystem.get("resource", "foo2", "cluster-attr2").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)); }
Example 20
Source File: AbstractMgmtTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static List<ModelNode> xmlToModelOperations(String xml, String nameSpaceUriString, XMLElementReader<List<ModelNode>> parser) throws Exception { XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(new QName(nameSpaceUriString, "subsystem"), parser); StringReader strReader = new StringReader(xml); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader)); List<ModelNode> newList = new ArrayList<ModelNode>(); mapper.parseDocument(newList, reader); return newList; }