/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.xpn.xwiki.internal.model.reference;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.web.Utils;
import org.junit.Assert;
import org.junit.Before;
import org.xwiki.context.Execution;
import org.xwiki.model.EntityType;
import org.xwiki.model.reference.EntityReference;
import org.xwiki.model.reference.EntityReferenceResolver;
import org.xwiki.test.AbstractComponentTestCase;

/**
 * Unit tests for {@link CurrentMixedStringDocumentReferenceResolver}.
 *
 * @version $Id$
 * @since 2.2M1
 */
public class CurrentMixedStringDocumentReferenceResolverTest extends AbstractComponentTestCase
{
    private static final String CURRENT_WIKI = "currentwiki";

    private static final String CURRENT_SPACE = "currentspace";

    private EntityReferenceResolver resolver;

    private XWikiContext context;

    @Before
    public void setUp() throws Exception
    {
        super.setUp();

        this.context = new XWikiContext();

        Execution execution = getComponentManager().lookup(Execution.class);
        execution.getContext().setProperty("xwikicontext", this.context);
        Utils.setComponentManager(getComponentManager());

        this.resolver = getComponentManager().lookup(EntityReferenceResolver.class, "currentmixed");
    }

    @org.junit.Test
    public void testResolveDocumentReferenceWhenContextDocument() throws Exception
    {
        this.context.setDoc(new XWikiDocument(CURRENT_WIKI, CURRENT_SPACE, "notused"));

        EntityReference reference = resolver.resolve("", EntityType.DOCUMENT);
        Assert.assertEquals(CURRENT_WIKI, reference.extractReference(EntityType.WIKI).getName());
        Assert.assertEquals(CURRENT_SPACE, reference.extractReference(EntityType.SPACE).getName());
        Assert.assertEquals("WebHome", reference.getName());
    }
}

@@ -1059,44 +1059,167 @@
 rg.j
-unit.Assert;%0Aimport org.junit.Before
+mock.Expectations;%0Aimport org.jmock.Mockery;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.xwiki.component.descriptor.DefaultComponentDescriptor
 ;%0Aim
@@ -1287,16 +1287,53 @@
 tyType;%0A
+import org.xwiki.model.ModelContext;%0A
 import o
@@ -1432,16 +1432,64 @@
 solver;%0A
+import org.xwiki.model.reference.WikiReference;%0A
 import o
@@ -1746,71 +1746,8 @@
 e%0A%7B%0A
-    private static final String CURRENT_WIKI = %22currentwiki%22;%0A%0A
     
@@ -1807,16 +1807,66 @@
 pace%22;%0A%0A
+    private Mockery mockery = new Mockery();%0A    %0A
     priv
@@ -1939,16 +1939,64 @@
 ntext;%0A%0A
+    private ModelContext mockModelContext;%0A    %0A
     @Bef
@@ -2320,24 +2320,341 @@
 anager());%0A%0A
+        this.mockModelContext = mockery.mock(ModelContext.class);%0A        DefaultComponentDescriptor%3CModelContext%3E descriptor = new DefaultComponentDescriptor%3CModelContext%3E();%0A        descriptor.setRole(ModelContext.class);%0A        getComponentManager().registerComponent(descriptor, this.mockModelContext);%0A        %0A
         this
@@ -2904,28 +2904,26 @@
 ocument(
-CURRENT_WIKI
+%22not used%22
 , CURREN
@@ -2941,24 +2941,206 @@
 otused%22));%0A%0A
+        mockery.checking(new Expectations() %7B%7B%0A            allowing(mockModelContext).getCurrentEntityReference(); will(returnValue(new WikiReference(%22currentwiki%22)));%0A        %7D%7D);%0A%0A
         Enti
@@ -3238,20 +3238,21 @@
 als(
-CURRENT_WIKI
+%22currentwiki%22
 , re

Introduce new Model module