package org.mongodb.morphia.mapping;


import org.bson.types.ObjectId;
import org.junit.Assert;
import org.junit.Test;
import org.mongodb.morphia.TestBase;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.PreSave;


/**
 * @author Uwe Schaefer, (us@thomas-daily.de)
 */
public class EnumMappingTest extends TestBase {
    public static class ContainsEnum {
        @Id
        private ObjectId id;
        private Foo foo = Foo.BAR;

        @PreSave
        void testMapping() {

        }
    }

    enum Foo {
        BAR() {
        },
        BAZ
    }

    @Test
    public void testEnumMapping() throws Exception {
        getMorphia().map(ContainsEnum.class);

        getDs().save(new ContainsEnum());
        Assert.assertEquals(1, getDs().createQuery(ContainsEnum.class).field("foo").equal(Foo.BAR).countAll());
        Assert.assertEquals(1, getDs().createQuery(ContainsEnum.class).filter("foo", Foo.BAR).countAll());
        Assert.assertEquals(1, getDs().createQuery(ContainsEnum.class).disableValidation().filter("foo", Foo.BAR).countAll());
    }

}

@@ -149,16 +149,112 @@
 stBase;%0A
+import org.mongodb.morphia.annotations.Embedded;%0Aimport org.mongodb.morphia.annotations.Entity;%0A
 import o
@@ -337,16 +337,65 @@
 eSave;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 %0A/**%0A * 
@@ -726,24 +726,2071 @@
  BAZ%0A    %7D%0A%0A
+%0A    public enum WebTemplateType %7B%0A        CrewContract(%22Contract%22),%0A        CrewContractHeader(%22Contract Header%22);%0A%0A        private String text;%0A%0A        private WebTemplateType(final String text) %7B%0A            this.text = text;%0A        %7D%0A%0A        public String getText() %7B%0A            return text;%0A        %7D%0A%0A    %7D%0A%0A    @Embedded%0A    public static class WebTemplate %7B%0A        private ObjectId id = new ObjectId();%0A        private String templateName;%0A        private String content;%0A%0A        public WebTemplate() %7B%0A        %7D%0A%0A        public WebTemplate(final String content) %7B%0A            this.content = content;%0A        %7D%0A%0A        @Override%0A        public boolean equals(final Object o) %7B%0A            if (this == o) %7B%0A                return true;%0A            %7D%0A            if (o == null %7C%7C getClass() != o.getClass()) %7B%0A                return false;%0A            %7D%0A%0A            final WebTemplate that = (WebTemplate) o;%0A%0A            if (content != null ? !content.equals(that.content) : that.content != null) %7B%0A                return false;%0A            %7D%0A            if (id != null ? !id.equals(that.id) : that.id != null) %7B%0A                return false;%0A            %7D%0A            if (templateName != null ? !templateName.equals(that.templateName) : that.templateName != null) %7B%0A                return false;%0A            %7D%0A%0A            return true;%0A        %7D%0A%0A        @Override%0A        public int hashCode() %7B%0A            int result = id != null ? id.hashCode() : 0;%0A            result = 31 * result + (templateName != null ? templateName.hashCode() : 0);%0A            result = 31 * result + (content != null ? content.hashCode() : 0);%0A            return result;%0A        %7D%0A    %7D%0A%0A    @Entity(noClassnameStored = true)%0A    public static class Customer %7B%0A        @Id%0A        private ObjectId id;%0A        private final Map%3CWebTemplateType, WebTemplate%3E map = new HashMap%3CWebTemplateType, WebTemplate%3E();%0A        %0A        public void add(final WebTemplateType type, final WebTemplate template) %7B%0A            map.put(type, template);%0A        %7D%0A    %7D%0A%0A
     @Test%0A  
@@ -3282,10 +3282,422 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testCustomer() %7B%0A        Customer customer = new Customer();%0A        customer.add(WebTemplateType.CrewContract, new WebTemplate(%22template #1%22));%0A        customer.add(WebTemplateType.CrewContractHeader, new WebTemplate(%22template #2%22));%0A        %0A        getDs().save(customer);%0A        Customer loaded = getDs().get(customer);%0A        Assert.assertEquals(customer.map, loaded.map);%0A    %7D%0A
 %7D%0A

new test. validates #534