PageRenderTime 34ms CodeModel.GetById 18ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/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
17package com.hazelcast.config;
18
19import org.junit.Before;
20import org.junit.Test;
21import org.junit.runner.RunWith;
22import org.w3c.dom.Document;
23import org.w3c.dom.Node;
24import org.w3c.dom.NodeList;
25import org.xml.sax.SAXException;
26
27import javax.xml.parsers.DocumentBuilder;
28import javax.xml.parsers.DocumentBuilderFactory;
29import javax.xml.parsers.ParserConfigurationException;
30import java.io.ByteArrayInputStream;
31import java.io.IOException;
32
33import static org.junit.Assert.*;
34
35/**
36 *
37 */
38@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
39public class IterableNodeListTest {
40
41    private Document document;
42
43    @Before
44    public void setupNodeList() throws ParserConfigurationException, SAXException, IOException {
45        final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
46        final String testXml = "<root><element></element><element></element><element></element></root>";
47        document = builder.parse(new ByteArrayInputStream(testXml.getBytes()));
48    }
49
50    /**
51     * Test method for {@link com.hazelcast.config.XmlConfigBuilder.IterableNodeList#IterableNodeList(org.w3c.dom.NodeList)}.
52     */
53    @Test
54    public void testIterableNodeList() {
55        NodeList nodeList = document.getFirstChild().getChildNodes();
56        int count = 0;
57        for (Node node : new XmlConfigBuilder.IterableNodeList(nodeList)) {
58            count += (node != null) ? 1 : 0;
59        }
60        assertEquals(3, count);
61    }
62
63    /**
64     * Test method for {@link com.hazelcast.config.XmlConfigBuilder.IterableNodeList#hasNext()}.
65     */
66    @Test
67    public void testHasNext() {
68        NodeList nodeList = document.getChildNodes();
69        assertTrue(new XmlConfigBuilder.IterableNodeList(nodeList).iterator().hasNext());
70    }
71
72    /**
73     * Test method for {@link com.hazelcast.config.XmlConfigBuilder.IterableNodeList#next()}.
74     */
75    @Test
76    public void testNext() {
77        NodeList nodeList = document.getChildNodes();
78        assertNotNull(new XmlConfigBuilder.IterableNodeList(nodeList).iterator().next());
79    }
80
81    /**
82     * Test method for {@link com.hazelcast.config.XmlConfigBuilder.IterableNodeList#remove()}.
83     */
84    @Test(expected = UnsupportedOperationException.class)
85    public void testRemove() {
86        NodeList nodeList = document.getChildNodes();
87        new XmlConfigBuilder.IterableNodeList(nodeList).iterator().remove();
88    }
89}