package org.lantern.state;

import static org.junit.Assert.assertEquals;

import java.io.File;

import org.apache.commons.lang.SystemUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import org.lantern.TestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ModelIoTest {

    private static Logger LOG = LoggerFactory.getLogger(ModelIoTest.class);

    private static File testFile;

    @BeforeClass
    public static void setup() throws Exception {
        testFile = new File("modelTest");
        testFile.delete();
        testFile.deleteOnExit();
    }
    
    @Test
    public void testModelIo() throws Exception {
        ModelIo io =
            new ModelIo(testFile, TestUtils.getEncryptedFileService(), null);

        Model model = io.get();
        
        final String id = model.getNodeId();
        SystemData system = model.getSystem();
        Settings settings = model.getSettings();
        Connectivity connectivity = model.getConnectivity();
        assertEquals("", connectivity.getIp());
        
        final String ip = "30.2.2.2";
        //connectivity.setIp(ip);
        
        assertEquals(0, model.getNinvites());
        model.setNinvites(10);
        assertEquals(10, model.getNinvites());
        
        if ("en".equalsIgnoreCase(SystemUtils.USER_LANGUAGE)) {
            assertEquals("en", system.getLang());
        }
        io.write();

        io = new ModelIo(testFile, TestUtils.getEncryptedFileService(), null);
        model = io.get();
        system = model.getSystem();
        settings = model.getSettings();
        connectivity = model.getConnectivity();
        assertEquals(10, model.getNinvites());
        
        // The user's IP address should not persist to disk
        assertEquals("", connectivity.getIp());
        
        assertEquals("ID should persist across sessions", 
            id, model.getNodeId());
        
    }

}

@@ -890,57 +890,8 @@
 ();%0A
-        Settings settings = model.getSettings();%0A
     
@@ -999,97 +999,8 @@
 ));%0A
-        %0A        final String ip = %2230.2.2.2%22;%0A        //connectivity.setIp(ip);%0A        
 %0A   
@@ -1017,17 +1017,18 @@
 tEquals(
-0
+-1
 , model.
@@ -1420,48 +1420,8 @@
 ();%0A
-        settings = model.getSettings();%0A
     

make test match new notification code