/* Copyright (C) 2012  Egon Willighagen <egonw@users.sf.net>
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.bitbucket.nanojava.io;

import java.io.IOException;

import junit.framework.Assert;

import nu.xom.ParsingException;

import org.bitbucket.nanojava.data.MaterialType;
import org.bitbucket.nanojava.data.Nanomaterial;
import org.bitbucket.nanojava.data.measurement.MeasurementValue;
import org.junit.Test;

public class DeserializationTest {

	@Test
	public void readType() throws ParsingException, IOException {
		String input = "<molecule xmlns=\"http://www.xml-cml.org/schema\" xmlns:nano=\"http://.../\" convention=\"nano:material\"><scalar dictRef=\"nano:type\" dataType=\"xsd:string\">GRAPHENE</scalar></molecule>";
		Nanomaterial material = Deserializer.fromCMLString(input);
		Assert.assertNotNull(material);
		Assert.assertEquals(MaterialType.GRAPHENE, material.getType());
	}
	
	@Test
	public void readSize() throws ParsingException, IOException {
		String input = "<molecule xmlns=\"http://www.xml-cml.org/schema\" xmlns:nano=\"http://.../\" convention=\"nano:material\"><scalar dictRef=\"nano:type\" dataType=\"xsd:string\">METALOXIDE</scalar><property dictRef=\"nano:dimension\"><scalar units=\"qudt:nm\" dataType=\"xsd:double\">20.0</scalar></property></molecule>";
		Nanomaterial material = Deserializer.fromCMLString(input);
		Assert.assertNotNull(material);
		Assert.assertEquals(20.0, ((MeasurementValue)material.getSize()).getValue(), 0.1);
	}
	
	@Test
	public void readZetaPotential() throws ParsingException, IOException {
		String input = "<molecule xmlns=\"http://www.xml-cml.org/schema\" xmlns:nano=\"http://.../\" convention=\"nano:material\"><scalar dictRef=\"nano:type\" dataType=\"xsd:string\">METALOXIDE</scalar><property dictRef=\"nano:zetaPotential\"><scalar units=\"qudt:eV\" dataType=\"xsd:double\">-45.0</scalar></property></molecule>";
		Nanomaterial material = Deserializer.fromCMLString(input);
		Assert.assertNotNull(material);
		Assert.assertEquals(-45.0, ((MeasurementValue)material.getZetaPotential()).getValue(), 0.1);
	}
	


}

@@ -893,17 +893,16 @@
 Assert;%0A
-%0A
 import n
@@ -1024,16 +1024,91 @@
 terial;%0A
+import org.bitbucket.nanojava.data.measurement.IErrorlessMeasurementValue;%0A
 import o
@@ -2182,24 +2182,34 @@
 als(20.0, ((
+IErrorless
 MeasurementV
@@ -2788,16 +2788,26 @@
 45.0, ((
+IErrorless
 Measurem

Use the more general interface