package org.cinchapi.runway;

import org.cinchapi.concourse.test.ClientServerTest;
import org.cinchapi.runway.Record;
import org.cinchapi.runway.Unique;
import org.junit.Assert;
import org.junit.Test;

public class RecordTest extends ClientServerTest {

    @Override
    protected String getServerVersion() {
        return "0.4.1";
    }

    @Override
    public void beforeEachTest() {
        Record.setConnectionInformation("localhost",
                this.server.getClientPort(), "admin", "admin");
    }
    
    @Test
    public void testCannotAddDuplicateValuesForUniqueVariable(){
        Mock person = Record.create(Mock.class);
        person.name = "Jeff Nelson";
        Assert.assertTrue(person.save());
        
        Mock person2 = Record.create(Mock.class);
        person2.name = "Jeff Nelson";
        Assert.assertFalse(person2.save());
        
        person2.name = "Jeffery Nelson";
        Assert.assertTrue(person2.save());      
    }
    
    @Test
    public void testCannotSaveNullValueForRequiredVariable(){
        Mock person = Mock.create(Mock.class);
        person.age = 23;
        Assert.assertFalse(person.save());
    }
    
    @Test
    public void testNoPartialSaveWhenRequiredVariableIsNull(){
        Mock person = Mock.create(Mock.class);
        person.age = 23;
        person.save();
        Assert.assertTrue(client.describe(person.getId()).isEmpty());
    }

    class Mock extends Record {

        @Unique
        @Required
        public String name;
        
        public Integer age;

    }

}

@@ -1402,24 +1402,344 @@
 ty());%0A    %7D
+%0A    %0A    @Test%0A    public void testBooleanIsNotStoredAsBase64()%7B%0A        Mock person = Mock.create(Mock.class);%0A        person.name = %22John Doe%22;%0A        person.age = 100;%0A        person.save();%0A        long id = person.getId();%0A        person = Mock.load(Mock.class, id);%0A        Assert.assertTrue(person.alive);%0A    %7D
 %0A%0A    class 
@@ -1859,16 +1859,62 @@
 ger age;
+%0A        %0A        public boolean alive = true;
 %0A%0A    %7D%0A

add test case