[LIB-9] Separate chesshog-hedgefish module
[chesshog.git] / src / test / java / org / hedgecode / chess / wiki / WikiParserTest.java
1 /*
2  * Copyright (c) 2018. Developed by Hedgecode.
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
17 package org.hedgecode.chess.wiki;
18
19 import java.util.LinkedList;
20 import java.util.List;
21
22 import org.apache.commons.configuration.HierarchicalConfiguration;
23 import org.apache.commons.configuration.XMLConfiguration;
24
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28
29 import org.hedgecode.chess.AbstractPositionTest;
30 import org.hedgecode.chess.position.Parser;
31 import org.hedgecode.chess.position.Position;
32
33 /**
34  * Tests for {@link WikiParser}.
35  *
36  * @author Dmitry Samoshin aka gotty
37  */
38 @RunWith(JUnit4.class)
39 public class WikiParserTest extends AbstractPositionTest implements WikiPositionTest {
40
41     @Test
42     public void testParse() throws Exception {
43         Parser wikiParser = WikiParser.getInstance();
44         for (HierarchicalConfiguration testConfig : getXMLConfig().configurationsAt(TESTS)) {
45             setPositionName(
46                     String.format(
47                             MSG_WIKI_POSITION, testConfig.getString(NAME)
48                     )
49             );
50             String wiki = testConfig.getString(WIKI_TAG);
51             Position position = assignPosition(
52                     testConfig.configurationAt(POSITION)
53             );
54             boolean withTemplate = false;
55             if (testConfig.containsKey(WIKI_TEMPLATE)) {
56                 withTemplate = testConfig.getBoolean(WIKI_TEMPLATE);
57             }
58             Wiki.setTemplate(withTemplate);
59             assertDiagramEquals(
60                     position,
61                     wikiParser.parse(wiki)
62             );
63         }
64     }
65
66     @Override
67     public List<XMLConfiguration> getXMLPositions() throws Exception {
68         List<XMLConfiguration> xmlPositions = new LinkedList<>();
69         for (HierarchicalConfiguration testConfig : getXMLConfig().configurationsAt(TESTS)) {
70             xmlPositions.add(
71                     new XMLConfiguration(
72                             testConfig.configurationAt(POSITION)
73                     )
74             );
75         }
76         return xmlPositions;
77     }
78
79 }