package co.jirm.mapper.definition;

import static org.junit.Assert.*;

import javax.persistence.Column;
import javax.persistence.Id;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
import org.junit.Before;
import org.junit.Test;

import co.jirm.mapper.SqlObjectConfig;


public class SqlObjectDefinitionTest {

	@Before
	public void setUp() throws Exception {}

	@Test
	public void testFromClass() {
		SqlObjectDefinition<ProtectedConsTest> d = 
				SqlObjectDefinition.fromClass(ProtectedConsTest.class, SqlObjectConfig.DEFAULT);
		assertTrue(d.getIdParameters().containsKey("id"));
		assertEquals("no_colum_name", d.getParameters().get("noColumName").sqlName());
		
	}
	
	public static class ProtectedConsTest {
		@Id
		@Column(length = 8192)
		private final String id;
		
		@Column(length = 8192)
		private final String noColumName;
		

		@JsonCreator
		protected ProtectedConsTest(@JsonProperty("id") String id, @JsonProperty("noColumName") String noColumName) {
			super();
			this.id = id;
			this.noColumName = noColumName;
		}
		
		public String getId() {
			return id;
		}
		
		public String getNoColumName() {
			return noColumName;
		}
		
	}

}

@@ -277,16 +277,66 @@
 .Test;%0A%0A
+import co.jirm.core.JirmIllegalArgumentException;%0A
 import c
@@ -366,16 +366,16 @@
 Config;%0A
-
 %0A%0Apublic
@@ -763,17 +763,183 @@
 me());%0A%09
-%09
+%7D%0A%09%0A%09@Test(expected=JirmIllegalArgumentException.class)%0A%09public void testNoDefinitionFailure() %7B%0A%09%09SqlObjectDefinition.fromClass(NoDef.class, SqlObjectConfig.DEFAULT);
 %0A%09%7D%0A%09%0A%09p
@@ -1413,14 +1413,46 @@
 %0A%09%09%7D%0A%09%09%0A
-
 %09%7D
+%0A%09%0A%09public static class NoDef %7B%7D
 %0A%0A%7D%0A

Test for failure of object having no definition.