/hazelcast/src/test/java/com/hazelcast/config/IterableNodeListTest.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 89 lines · 48 code · 11 blank · 30 comment · 2 complexity · 0e9939ce79086807ce2a3c4523bfb594 MD5 · raw file

  1. /*
  2. * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.hazelcast.config;
  17. import org.junit.Before;
  18. import org.junit.Test;
  19. import org.junit.runner.RunWith;
  20. import org.w3c.dom.Document;
  21. import org.w3c.dom.Node;
  22. import org.w3c.dom.NodeList;
  23. import org.xml.sax.SAXException;
  24. import javax.xml.parsers.DocumentBuilder;
  25. import javax.xml.parsers.DocumentBuilderFactory;
  26. import javax.xml.parsers.ParserConfigurationException;
  27. import java.io.ByteArrayInputStream;
  28. import java.io.IOException;
  29. import static org.junit.Assert.*;
  30. /**
  31. *
  32. */
  33. @RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
  34. public class IterableNodeListTest {
  35. private Document document;
  36. @Before
  37. public void setupNodeList() throws ParserConfigurationException, SAXException, IOException {
  38. final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  39. final String testXml = "<root><element></element><element></element><element></element></root>";
  40. document = builder.parse(new ByteArrayInputStream(testXml.getBytes()));
  41. }
  42. /**
  43. * Test method for {@link com.hazelcast.config.XmlConfigBuilder.IterableNodeList#IterableNodeList(org.w3c.dom.NodeList)}.
  44. */
  45. @Test
  46. public void testIterableNodeList() {
  47. NodeList nodeList = document.getFirstChild().getChildNodes();
  48. int count = 0;
  49. for (Node node : new XmlConfigBuilder.IterableNodeList(nodeList)) {
  50. count += (node != null) ? 1 : 0;
  51. }
  52. assertEquals(3, count);
  53. }
  54. /**
  55. * Test method for {@link com.hazelcast.config.XmlConfigBuilder.IterableNodeList#hasNext()}.
  56. */
  57. @Test
  58. public void testHasNext() {
  59. NodeList nodeList = document.getChildNodes();
  60. assertTrue(new XmlConfigBuilder.IterableNodeList(nodeList).iterator().hasNext());
  61. }
  62. /**
  63. * Test method for {@link com.hazelcast.config.XmlConfigBuilder.IterableNodeList#next()}.
  64. */
  65. @Test
  66. public void testNext() {
  67. NodeList nodeList = document.getChildNodes();
  68. assertNotNull(new XmlConfigBuilder.IterableNodeList(nodeList).iterator().next());
  69. }
  70. /**
  71. * Test method for {@link com.hazelcast.config.XmlConfigBuilder.IterableNodeList#remove()}.
  72. */
  73. @Test(expected = UnsupportedOperationException.class)
  74. public void testRemove() {
  75. NodeList nodeList = document.getChildNodes();
  76. new XmlConfigBuilder.IterableNodeList(nodeList).iterator().remove();
  77. }
  78. }