package org.jerrymouse.gaes.mavenPlugin.pomPatch;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;

import junit.framework.Assert;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.maven.model.Parent;
import org.jerrymouse.gaes.mavenPlugin.archetype.Patch;
import org.jerrymouse.gaes.mavenPlugin.archetype.PatchReader;
import org.junit.Before;
import org.junit.Test;

public class PatchReaderTest {
	PatchReader patchReader;
	Log log = LogFactory.getLog(getClass());

	@Before
	public void setUp() throws Exception {
		patchReader = new PatchReader();
	}

	@Test
	public void testAddParent() throws IOException, IllegalAccessException,
			InvocationTargetException, NoSuchMethodException {
		Patch patch = patchReader.read(ClassLoader
				.getSystemResourceAsStream("testAddParent.xml"));
		Parent parent = patch.addParent;
		Assert.assertNotNull(parent);
		log.trace(BeanUtils.describe(parent).toString());
	}

	@Test
	public void testRemoveDistributionManagement() throws IOException,
			IllegalAccessException, InvocationTargetException,
			NoSuchMethodException {
		Patch patch = patchReader
				.read(ClassLoader
						.getSystemResourceAsStream("testRemoveDistributionManagement.xml"));
		boolean removeDistributionManagement = patch.removeDistributionManagement;
		Assert.assertTrue(removeDistributionManagement);
	}

}
