

package eu.cdevreeze.yaidom.queryapitests.simple

import eu.cdevreeze.yaidom.convert.ScalaXmlConversions.convertToElem
import eu.cdevreeze.yaidom.queryapitests.AbstractAlternativeQueryTest
import eu.cdevreeze.yaidom.simple.Elem

/**
 * Alternative query test case for standard Elems.
 *
 * @author Chris de Vreeze
 */
class AlternativeQueryTest extends AbstractAlternativeQueryTest {

  final type E = Elem

  protected val catalogElem: E = {
    val xml =
      <catalog>
        <product dept="WMN">
          <number>557</number>
          <name language="en">Fleece Pullover</name>
          <colorChoices>navy black</colorChoices>
        </product>
        <product dept="ACC">
          <number>563</number>
          <name language="en">Floppy Sun Hat</name>
        </product>
        <product dept="ACC">
          <number>443</number>
          <name language="en">Deluxe Travel Bag</name>
        </product>
        <product dept="MEN">
          <number>784</number>
          <name language="en">Cotton Dress Shirt</name>
          <colorChoices>white gray</colorChoices>
          <desc>Our <i>favorite</i> shirt!</desc>
        </product>
      </catalog>

    convertToElem(xml)
  }

  protected val pricesElem: E = {
    val xml =
      <prices>
        <priceList effDate="2006-11-15">
          <prod num="557">
            <price currency="USD">29.99</price>
            <discount type="CLR">10.00</discount>
          </prod>
          <prod num="563">
            <price currency="USD">69.99</price>
          </prod>
          <prod num="443">
            <price currency="USD">39.99</price>
            <discount type="CLR">3.99</discount>
          </prod>
        </priceList>
      </prices>

    convertToElem(xml)
  }

  protected val orderElem: E = {
    val xml =
      <order num="00299432" date="2006-09-15" cust="0221A">
        <item dept="WMN" num="557" quantity="1" color="navy"/>
        <item dept="ACC" num="563" quantity="1"/>
        <item dept="ACC" num="443" quantity="2"/>
        <item dept="MEN" num="784" quantity="1" color="white"/>
        <item dept="MEN" num="784" quantity="1" color="gray"/>
        <item dept="WMN" num="557" quantity="1" color="black"/>
      </order>

    convertToElem(xml)
  }

  protected def fromScalaElem(elem: scala.xml.Elem): E = convertToElem(elem)
}
