/*
 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Quentin Lamerand <qlamerand@nuxeo.com>
 */

package org.nuxeo.ecm.platform.userpreferences.test;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.test.CoreFeature;
import org.nuxeo.ecm.core.test.DefaultRepositoryInit;
import org.nuxeo.ecm.core.test.annotations.BackendType;
import org.nuxeo.ecm.core.test.annotations.Granularity;
import org.nuxeo.ecm.core.test.annotations.RepositoryConfig;
import org.nuxeo.ecm.platform.userpreferences.SimpleUserPreferences;
import org.nuxeo.ecm.platform.userpreferences.UserPreferencesService;
import org.nuxeo.ecm.platform.userworkspace.api.UserWorkspaceService;
import org.nuxeo.runtime.test.runner.Deploy;
import org.nuxeo.runtime.test.runner.Features;
import org.nuxeo.runtime.test.runner.FeaturesRunner;

import com.google.inject.Inject;

/**
 * Tests for {@link UserPreferencesService}
 *
 * @author <a href="mailto:qlamerand@nuxeo.com">Quentin Lamerand</a>
 * @since 5.4.3
 */
@RunWith(FeaturesRunner.class)
@Features(CoreFeature.class)
@RepositoryConfig(repositoryName = "default", type = BackendType.H2, init = DefaultRepositoryInit.class, user = "Administrator", cleanup = Granularity.METHOD)
@Deploy( { "org.nuxeo.ecm.platform.userworkspace.types",
        "org.nuxeo.ecm.platform.userworkspace.api",
        "org.nuxeo.ecm.platform.userworkspace.core",
        "org.nuxeo.ecm.platform.localconfiguration.simple",
        "org.nuxeo.ecm.platform.userpreferences" })
public class TestUserPreferencesService {

    @Inject
    CoreSession session;

    @Inject
    UserPreferencesService userPreferencesService;

    @Inject
    UserWorkspaceService userWorkspaceService;

    @Test
    public void testGetSimpleUserPreferences() throws Exception {
        SimpleUserPreferences simpleUserPref = userPreferencesService.getSimpleUserPreferences(session);
        DocumentModel userWorkspace = userWorkspaceService.getCurrentUserPersonalWorkspace(
                session, null);
        assertEquals(userWorkspace.getRef(), simpleUserPref.getDocumentRef());
        simpleUserPref.put("foo", "bar");
        simpleUserPref.save(session);
        simpleUserPref = userPreferencesService.getSimpleUserPreferences(session);
        assertEquals("bar", simpleUserPref.get("foo"));
    }

}

@@ -2142,24 +2142,233 @@
 on.simple%22,%0A
+        %22org.nuxeo.ecm.platform.usermanager%22,%0A        %22org.nuxeo.ecm.platform.usermanager.api%22,%0A        %22org.nuxeo.ecm.directory.api%22,%0A        %22org.nuxeo.ecm.directory%22,%0A        %22org.nuxeo.ecm.directory.sql%22,%0A
         %22org

deploy missing modules