/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.csstudio.opibuilder.converter.writer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.csstudio.opibuilder.converter.model.EdmAttribute;
import org.csstudio.opibuilder.converter.model.EdmBoolean;
import org.csstudio.opibuilder.converter.model.EdmException;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class OpiBooleanTest {

    @Test
    public void testOpiBoolean() throws EdmException {

        // init document
        Document doc = XMLFileHandler.createDomDocument();

        // OpiBoolean data
        String name = "someBooleanElement";
        EdmBoolean bT = new EdmBoolean(new EdmAttribute(), false);    //[TRUE]
        EdmBoolean bF = new EdmBoolean(null, false);                //[FALSE]

        // instantiating OpiBoolean
        Element parent = doc.createElement("root");
        doc.appendChild(parent);
        Context context = new Context(doc, parent, null, 0, 0);
        OpiBoolean o = new OpiBoolean(context, name, bT);
        assertTrue(o instanceof OpiAttribute);
        new OpiBoolean(context, name, bF);

        // testing
        Element x = (Element)doc.getElementsByTagName(name).item(0);
        assertEquals("true", x.getTextContent());
        x = (Element)doc.getElementsByTagName(name).item(1);
        assertEquals("false", x.getTextContent());

        //XMLFileHandler.writeXML(doc);

    }

}

@@ -1084,19 +1084,87 @@
 ing 
-name = %22som
+trueBooleanName = %22trueBooleanElement%22;%0A        String falseBooleanName = %22fals
 eBoo
@@ -1563,25 +1563,36 @@
 an(context, 
-n
+trueBooleanN
 ame, bT);%0A  
@@ -1668,17 +1668,29 @@
 ontext, 
-n
+falseBooleanN
 ame, bF)
@@ -1757,33 +1757,44 @@
 ementsByTagName(
-n
+trueBooleanN
 ame).item(0);%0A  
@@ -1887,17 +1887,29 @@
 TagName(
-n
+falseBooleanN
 ame).ite
@@ -1910,17 +1910,17 @@
 e).item(
-1
+0
 );%0A     

Fix failing OpiBoolean test