PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/security/src/test/java/org/jboss/as/security/test/SubsystemParsingUnitTestCase.java

#
Java | 115 lines | 73 code | 18 blank | 24 comment | 4 complexity | 817bf30be5b472c4cc4a3daddb997c72 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2010, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.security.test;
  23. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
  24. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
  25. import static org.jboss.as.security.Constants.SECURITY_DOMAIN;
  26. import static org.junit.Assert.assertEquals;
  27. import static org.junit.Assert.assertNotNull;
  28. import static org.junit.Assert.fail;
  29. import java.io.BufferedReader;
  30. import java.io.IOException;
  31. import java.io.InputStreamReader;
  32. import java.net.URL;
  33. import java.util.ArrayList;
  34. import java.util.List;
  35. import javax.xml.namespace.QName;
  36. import javax.xml.stream.XMLInputFactory;
  37. import javax.xml.stream.XMLStreamException;
  38. import org.jboss.as.security.SecuritySubsystemParser;
  39. import org.jboss.dmr.ModelNode;
  40. import org.jboss.dmr.Property;
  41. import org.jboss.staxmapper.XMLMapper;
  42. import org.junit.Assert;
  43. import org.junit.Test;
  44. /**
  45. * @author anil saldhana
  46. */
  47. public class SubsystemParsingUnitTestCase {
  48. private static final String namespace = "urn:jboss:domain:security:1.0";
  49. private static final SecuritySubsystemParser parser = SecuritySubsystemParser.getInstance();
  50. @Test
  51. public void test() throws Exception {
  52. List<ModelNode> operations = parse("subsystem.xml");
  53. assertNotNull(operations);
  54. ModelNode props = operations.get(0);
  55. assertNotNull(props);
  56. ModelNode node = operations.get(1);
  57. assertNotNull(node);
  58. ModelNode address = node.get(OP_ADDR);
  59. List<Property> properties = address.asPropertyList();
  60. assertEquals(2, properties.size());
  61. for (Property prop : properties) {
  62. String propName = prop.getName();
  63. if (!(propName.equals(SUBSYSTEM) || propName.equals(SECURITY_DOMAIN)))
  64. fail("either subsystem or security-domain expected");
  65. if (propName.equals(SECURITY_DOMAIN)) {
  66. ModelNode securityDomainValue = prop.getValue();
  67. String value = securityDomainValue.asString();
  68. assertEquals("other", value);
  69. }
  70. }
  71. node = operations.get(2);
  72. assertNotNull(node);
  73. address = node.get(OP_ADDR);
  74. properties = address.asPropertyList();
  75. assertEquals(3, properties.size());
  76. assertEquals("authentication", properties.get(2).getName());
  77. assertEquals("classic", properties.get(2).getValue().asString());
  78. List<ModelNode> loginNodes = node.get("login-modules").asList();
  79. assertEquals(1, loginNodes.size());
  80. ModelNode modelNode = loginNodes.get(0);
  81. ModelNode code = modelNode.get("code");
  82. assertEquals("UsersRoles", code.asString());
  83. ModelNode flag = modelNode.get("flag");
  84. assertEquals("required", flag.asString());
  85. }
  86. List<ModelNode> parse(final String name) throws XMLStreamException, IOException {
  87. final List<ModelNode> operations = new ArrayList<ModelNode>();
  88. XMLMapper mapper = XMLMapper.Factory.create();
  89. mapper.registerRootElement(new QName(namespace, "subsystem"), parser);
  90. URL configURL = getClass().getResource(name);
  91. Assert.assertNotNull(name + " url is not null", configURL);
  92. System.out.println("configURL = " + configURL);
  93. BufferedReader reader = new BufferedReader(new InputStreamReader(configURL.openStream()));
  94. mapper.parseDocument(operations, XMLInputFactory.newInstance().createXMLStreamReader(reader));
  95. return operations;
  96. }
  97. }