/*******************************************************************************
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
 * which accompanies this distribution. 
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at 
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *     Denise Smith  June 05, 2009 - Initial implementation
 ******************************************************************************/
package org.eclipse.persistence.testing.jaxb.listofobjects;

import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

public class JAXBCharArrayTestCases extends JAXBListOfObjectsTestCases {
	protected final static String XML_RESOURCE = "org/eclipse/persistence/testing/jaxb/listofobjects/charArray.xml";
	private final static String XML_RESOURCE_NO_XSI_TYPE = "org/eclipse/persistence/testing/jaxb/listofobjects/charArrayNoXsiType.xml";

	public JAXBCharArrayTestCases(String name) throws Exception {
		super(name);
		init();
	}

	public void init() throws Exception {
		setControlDocument(XML_RESOURCE);
		Class[] classes = new Class[1];
		classes[0] = char[].class;
		setClasses(classes);

	}

    public  Map<String, InputStream> getControlSchemaFiles(){
		
	    InputStream instream = ClassLoader.getSystemResourceAsStream("org/eclipse/persistence/testing/jaxb/listofobjects/charArray.xsd");
		
		Map<String,InputStream> controlSchema = new HashMap<String, InputStream>();
		controlSchema.put("http://jaxb.dev.java.net/array",instream);
		return controlSchema;
	}

	protected Type getTypeToUnmarshalTo() {
		return char[].class;
	}

	protected Object getControlObject() {
		char[] chars = new char[4];
		chars[0] = 'a';
		chars[1] = 'b';
		chars[2] = 'c';
		chars[3] = 'd';

		QName qname = new QName("examplenamespace", "root");
		JAXBElement jaxbElement = new JAXBElement(qname, chars.getClass(), null);
		jaxbElement.setValue(chars);

		return jaxbElement;
	}

	protected void comparePrimitiveArrays(Object controlValue, Object testValue) {
		char[] controlArray = (char[]) controlValue;
		char[] testArray = (char[]) testValue;

		assertEquals(controlArray.length, testArray.length);
		for (int i = 0; i < controlArray.length; i++) {
			assertEquals(controlArray[i], testArray[i]);
		}
	}

	protected String getNoXsiTypeControlResourceName() {
		return XML_RESOURCE_NO_XSI_TYPE;
	}
}
