package com.github.error418.opennms.client.parameter;

import java.util.List;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.github.error418.opennms.client.exception.ParameterValidationException;
import com.github.error418.opennms.client.transfer.Parameter;


public class ParameterCollectionTest {
	
	private CustomParameterCollection parameters;
	
	@Before
	public void init() {
		parameters = new CustomParameterCollection();
		parameters.setFirstParameter("this is a required parameter");
	}
	
	@Test
	public void testParameterOrder() throws Exception {
		List<Parameter> params = parameters.buildParameterList();
		
		Assert.assertEquals(params.get(0).getParameterName(), CustomParameterCollection.FIRST_PARAM);
		Assert.assertEquals(params.get(1).getParameterName(), CustomParameterCollection.SECOND_PARAM);
		Assert.assertEquals(params.get(2).getParameterName(), CustomParameterCollection.THIRD_PARAM);
	}
	
	@Test
	public void testDefaultValuesAndAccessors() throws Exception {
		DefaultValueParameterCollection collection = new DefaultValueParameterCollection();
		
		Assert.assertEquals("1", collection.getValue("one"));
		Assert.assertEquals("2", collection.getValue("two"));
		Assert.assertTrue(collection.isParameterNull("tree"));
	}
	
	@Test(expected=ParameterValidationException.class)
	public void testValidationException() throws Exception {
		parameters.setFirstParameter(null);
		parameters.buildParameterList();
	}
	
	@Test
	public void testWithoutValidationException() throws Exception {
		parameters.setFirstParameter("it's okay now");
		parameters.buildParameterList();
	}
	
	@Test(expected=IllegalArgumentException.class)
	public void testDuplicateConfiguration() throws Exception {
		new FailParameterCollection();
	}
}

@@ -1775,10 +1775,692 @@
 n();%0A%09%7D%0A
+%09%0A%09@Test%0A%09public void testIsNull() throws Exception %7B%0A%09%09parameters.setFirstParameter(null);%0A%09%09Assert.assertTrue(parameters.isParameterNull(CustomParameterCollection.FIRST_PARAM));%0A%09%09%0A%09%09parameters.setFirstParameter(%22not null anymore!%22);%0A%09%09Assert.assertFalse(parameters.isParameterNull(CustomParameterCollection.FIRST_PARAM));%0A%09%7D%0A%09%0A%09@Test%0A%09public void testGetValue() throws Exception %7B%0A%09%09parameters.setFirstParameter(%22Some value%22);%0A%09%09Assert.assertEquals(%22Some value%22, parameters.getValue(CustomParameterCollection.FIRST_PARAM));%0A%09%09%0A%09%09parameters.setFirstParameter(%22Another value%22);%0A%09%09Assert.assertEquals(%22Another value%22, parameters.getValue(CustomParameterCollection.FIRST_PARAM));%0A%09%7D%0A
 %7D%0A

add test cases