// Path: src/test/java/org/springframework/data/cloudant/TestSpringBootApplication.java
// @EnableAutoConfiguration
// @SpringBootApplication
// public class TestSpringBootApplication {
// 
//     @Autowired
//     TestCloudantSettings testCloudantSettings;
// 
// //    @Bean
// //    public CloudantClient getCloudantClient(){
// //        return new CloudantConnector(testCloudantSettings).getClient();
// //    };
// 
//     @Bean
//     public CloudantTemplate getCloudantTemplate(){
//         return new CloudantTemplate(new CloudantConnector(testCloudantSettings));
//     }
// }
// 
// Path: src/main/java/org/springframework/data/cloudant/core/model/BaseDocument.java
// @JsonInclude(JsonInclude.Include.ALWAYS)
// public class BaseDocument {
// 
//     @SerializedName("_id")
//     @Id
//     private String id;
// 
//     @SerializedName("_rev")
//     private String revision;
// 
//     //json ignore
//     @JsonIgnore
//     private Map<String, Object> unmappedFields;
// 
//     @JsonProperty("_id")
//     public String getId() {
//         return id;
//     }
// 
//     @JsonProperty("_id")
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     @JsonProperty("_rev")
//     public String getRevision() {
//         return revision;
//     }
// 
//     @JsonProperty("_rev")
//     public void setRevision(String revision) {
//         this.revision = revision;
//     }
// 
//     public void setUnmappedFields(Map<String, Object> unmappedFields) {
//         this.unmappedFields = unmappedFields;
//     }
// 
//     public Map<String, Object> getUnmappedFields() {
//         return unmappedFields;
//     }
// 
//     public void addUnmappedField(String key, Object value) {
//         if (unmappedFields == null) {
//             unmappedFields = new HashMap<String, Object>();
//         }
//         unmappedFields.put(key,value);
//     }
// }


import com.cloudant.client.api.CloudantClient;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.lightcouch.DocumentConflictException;
import org.lightcouch.NoDocumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.cloudant.TestSpringBootApplication;
import org.springframework.data.cloudant.core.model.BaseDocument;
import org.springframework.data.cloudant.core.model.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
        template.save(car);
        car = (Car) template.findById(id, Car.class);
        assertNotNull(car);
        assertEquals(false, car.getRunnning());
        assertEquals(name, car.getName());
        assertEquals(id, car.getId());
    }

    @Test
    public void saveUnMappedDataAdapter() throws Exception {
        String id = "cars:fast-car111 23";
        String name = "The Fast Car";
        tryRemoveObjectById(id, Car.class);

        boolean running = false;
        Car car = new Car(id).setName(name).setRunning(running);
        HashMap<String, Object> unmap = new HashMap<String, Object>();
        unmap.put("TESTING", "VALUE");
        car.setUnmappedFields(unmap);
        template.setUnmappedDataAdapter();

        template.save(car);

        car = (Car) template.findById(id, Car.class);
        assertNotNull(car);
        assertEquals(unmap.size(), car.getUnmappedFields().size());
        assertEquals("VALUE", car.getUnmappedFields().get("TESTING"));
    }


// Path: src/test/java/org/springframework/data/cloudant/TestSpringBootApplication.java
// @EnableAutoConfiguration
// @SpringBootApplication
// public class TestSpringBootApplication {
// 
//     @Autowired
//     TestCloudantSettings testCloudantSettings;
// 
// //    @Bean
// //    public CloudantClient getCloudantClient(){
// //        return new CloudantConnector(testCloudantSettings).getClient();
// //    };
// 
//     @Bean
//     public CloudantTemplate getCloudantTemplate(){
//         return new CloudantTemplate(new CloudantConnector(testCloudantSettings));
//     }
// }
// 
// Path: src/main/java/org/springframework/data/cloudant/core/model/BaseDocument.java
// @JsonInclude(JsonInclude.Include.ALWAYS)
// public class BaseDocument {
// 
//     @SerializedName("_id")
//     @Id
//     private String id;
// 
//     @SerializedName("_rev")
//     private String revision;
// 
//     //json ignore
//     @JsonIgnore
//     private Map<String, Object> unmappedFields;
// 
//     @JsonProperty("_id")
//     public String getId() {
//         return id;
//     }
// 
//     @JsonProperty("_id")
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     @JsonProperty("_rev")
//     public String getRevision() {
//         return revision;
//     }
// 
//     @JsonProperty("_rev")
//     public void setRevision(String revision) {
//         this.revision = revision;
//     }
// 
//     public void setUnmappedFields(Map<String, Object> unmappedFields) {
//         this.unmappedFields = unmappedFields;
//     }
// 
//     public Map<String, Object> getUnmappedFields() {
//         return unmappedFields;
//     }
// 
//     public void addUnmappedField(String key, Object value) {
//         if (unmappedFields == null) {
//             unmappedFields = new HashMap<String, Object>();
//         }
//         unmappedFields.put(key,value);
//     }
// }


// Path: src/test/java/org/springframework/data/cloudant/core/CloudantTemplateTests.java
import com.cloudant.client.api.CloudantClient;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.lightcouch.DocumentConflictException;
import org.lightcouch.NoDocumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.cloudant.TestSpringBootApplication;
import org.springframework.data.cloudant.core.model.BaseDocument;
import org.springframework.data.cloudant.core.model.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

        template.save(car);
        car = (Car) template.findById(id, Car.class);
        assertNotNull(car);
        assertEquals(false, car.getRunnning());
        assertEquals(name, car.getName());
        assertEquals(id, car.getId());
    }

    @Test
    public void saveUnMappedDataAdapter() throws Exception {
        String id = "cars:fast-car111 23";
        String name = "The Fast Car";
        tryRemoveObjectById(id, Car.class);

        boolean running = false;
        Car car = new Car(id).setName(name).setRunning(running);
        HashMap<String, Object> unmap = new HashMap<String, Object>();
        unmap.put("TESTING", "VALUE");
        car.setUnmappedFields(unmap);
        template.setUnmappedDataAdapter();

        template.save(car);

        car = (Car) template.findById(id, Car.class);
        assertNotNull(car);
        assertEquals(unmap.size(), car.getUnmappedFields().size());
        assertEquals("VALUE", car.getUnmappedFields().get("TESTING"));
    }


    private void tryRemoveObjectById(String id, Class<? extends BaseDocument> entityClass) {