/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2009 INRIA/University of Nice-Sophia Antipolis
 * Contact: proactive@ow2.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or any later version.
 *
 * 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 * ################################################################
 * $$PROACTIVE_INITIAL_DEV$$
 */
package functionalTests.remoteobject.bindings;

import java.net.URI;

import org.objectweb.proactive.api.PARemoteObject;
import org.objectweb.proactive.core.ProActiveException;
import org.objectweb.proactive.core.remoteobject.RemoteObject;
import org.objectweb.proactive.core.remoteobject.RemoteObjectExposer;
import org.objectweb.proactive.core.remoteobject.RemoteObjectHelper;
import org.objectweb.proactive.core.runtime.ProActiveRuntime;
import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;

import functionalTests.FunctionalTest;
import static junit.framework.Assert.assertNotNull;


/**
 * Remote objects : unexport test case
 */
public class RemoteObjectUnexportTest extends FunctionalTest {

    @org.junit.Test(expected = ProActiveException.class)
    public void unexport() throws Exception {
        // get an object
        ProActiveRuntime p = ProActiveRuntimeImpl.getProActiveRuntime();

        // create a remote object exposer for this object
        RemoteObjectExposer<ProActiveRuntime> roe = PARemoteObject.newRemoteObject(ProActiveRuntime.class
                .getName(), p);

        // generate an uri where to rebind the runtime
        URI uri = RemoteObjectHelper.generateUrl("myruntime");

        // let's bind the object on the given endpoint
        PARemoteObject.bind(roe, uri);

        // looking for the remote object
        RemoteObject<ProActiveRuntime> ro = RemoteObjectHelper.lookup(uri);

        assertNotNull(ro);

        roe.unexport(uri);

        RemoteObject<ProActiveRuntime> ro1 = null;

        // looking for the remote object, should fail
        ro1 = RemoteObjectHelper.lookup(uri);

    }
}

@@ -1848,16 +1848,59 @@
 otNull;%0A
+import static junit.framework.Assert.fail;%0A
 %0A%0A/**%0A *
@@ -2027,45 +2027,8 @@
 Test
-(expected = ProActiveException.class)
 %0A   
@@ -2738,20 +2738,19 @@
     
-roe.
+// 
 unexport
 (uri
@@ -2749,65 +2749,60 @@
 port
-(uri);%0A%0A        RemoteObject%3CProActiveRuntime%3E ro1 = null
+ the object located at uri%0A        roe.unexport(uri)
 ;%0A%0A 
@@ -2840,17 +2840,16 @@
 e object
-,
  should 
@@ -2865,13 +2865,25 @@
     
-ro1 =
+try %7B%0A           
  Rem
@@ -2915,13 +2915,327 @@
 i);%0A
-%0A    %7D
+        %7D catch (ProActiveException e) %7B%0A            // this is the expected exception, let's continue%0A        %7D catch (Exception e) %7B%0A            fail(%22the exception's type is not the one expected, caught %22 + e.getClass().getName() +%0A                %22,should be %22 + ProActiveException.class.getName());%0A        %7D%0A    %7D%0A
 %0A%7D%0A

Resolve PROACTIVE-591: RemoteObjectUnexportTest needs rewrite