/*
 * Copyright 2013, The OpenNMS Group
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.opennms.lucidity;


import static com.opennms.lucidity.annotations.IndexType.INVERTED;

import java.io.PrintStream;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.junit.Test;

import com.opennms.lucidity.annotations.Column;
import com.opennms.lucidity.annotations.EmbeddedCollection;
import com.opennms.lucidity.annotations.Entity;
import com.opennms.lucidity.annotations.Id;
import com.opennms.lucidity.annotations.Index;


public class SchemaTest {

    @Entity static class InvalidConstructor {
        InvalidConstructor(String argument) {}
    }

    @Entity static class InvalidID {
        @Id private String id;
        @Column String name;
    }

    @Entity static class InvalidColumn {
        @Id private UUID id;
        @Column PrintStream stream;
    }

    @Entity static class NoColumn {
        @Id private UUID id;
    }

    @Entity static class WithIndexedMap {
        @Id private UUID id;
        @Index(type=INVERTED) @EmbeddedCollection @Column Map<String, String> food;
    }

    @Entity static class WithBadMapType {
        @Id private UUID id;
        @EmbeddedCollection @Column Map<String, Runnable> runners;
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNoArgConstructor() {
        Schema.fromClass(InvalidConstructor.class);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testIDType() {
        Schema.fromClass(InvalidID.class);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testBadType() {
        Schema.fromClass(InvalidColumn.class);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testMissingColumn() {
        Schema.fromClass(NoColumn.class);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testWithIndexedMap() {
        Schema.fromClass(WithIndexedMap.class);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testWithBadMapType() {
        Schema.fromClass(WithBadMapType.class);
    }

    @Entity static class BadListColumn {
        @Id private UUID id;
        @EmbeddedCollection List<Double> things;
    }
    
    @Test(expected = IllegalArgumentException.class)
    public void testBadListColumn() {
        Schema.fromClass(BadListColumn.class);
    }
    
}

@@ -1208,98 +1208,147 @@
    @
-Entity static class InvalidID %7B%0A        @Id private String id;%0A        @Column String name
+Test(expected = IllegalArgumentException.class)%0A    public void testNoArgConstructor() %7B%0A        Schema.fromClass(InvalidConstructor.class)
 ;%0A  
@@ -1384,22 +1384,18 @@
  Invalid
-Column
+ID
  %7B%0A     
@@ -1401,36 +1401,38 @@
     @Id private 
-UUID
+String
  id;%0A        @Co
@@ -1440,26 +1440,19 @@
 umn 
-PrintStream stre
+String n
 am
+e
 ;%0A  
@@ -1465,228 +1465,131 @@
    @
-Entity static class NoColumn %7B%0A        @Id private UUID id;%0A    %7D%0A%0A    @Entity static class WithIndexedMap %7B%0A        @Id private UUID id;%0A        @Index(type=INVERTED) @EmbeddedCollection @Column Map%3CString, String%3E food
+Test(expected = IllegalArgumentException.class)%0A    public void testInvalidID() %7B%0A        Schema.fromClass(InvalidID.class)
 ;%0A  
@@ -1618,30 +1618,29 @@
 c class 
-WithBadMapType
+InvalidColumn
  %7B%0A     
@@ -1676,64 +1676,33 @@
    @
-EmbeddedCollection @Column Map%3CString, Runnable%3E runners
+Column PrintStream stream
 ;%0A  
@@ -1779,32 +1779,29 @@
 oid test
-NoArgConstructor
+InvalidColumn
 () %7B%0A   
@@ -1827,33 +1827,28 @@
 ss(InvalidCo
-nstructor
+lumn
 .class);%0A   
@@ -1860,128 +1860,71 @@
    @
-Test(expected = IllegalArgumentException.class)%0A    public void testIDType() %7B%0A        Schema.fromClass(InvalidID.class)
+Entity static class MissingColumn %7B%0A        @Id private UUID id
 ;%0A  
@@ -2005,15 +2005,21 @@
 test
-BadType
+MissingColumn
 () %7B
@@ -2036,39 +2036,39 @@
 chema.fromClass(
-Invalid
+Missing
 Column.class);%0A 
@@ -2082,134 +2082,156 @@
    @
-Test(expected = IllegalArgumentException.class)%0A    public void testMissingColumn() %7B%0A        Schema.fromClass(NoColumn.class)
+Entity static class WithIndexedMap %7B%0A        @Id private UUID id;%0A        @Index(type=INVERTED) @EmbeddedCollection @Column Map%3CString, String%3E food
 ;%0A  
@@ -2374,32 +2374,177 @@
 .class);%0A    %7D%0A%0A
+    @Entity static class WithBadMapType %7B%0A        @Id private UUID id;%0A        @EmbeddedCollection @Column Map%3CString, Runnable%3E runners;%0A    %7D%0A%0A
     @Test(expect
@@ -2948,15 +2948,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

reorganize test class