cleanup
[taxeditor.git] / eu.etaxonomy.taxeditor.test / src / test / java / eu / etaxonomy / taxeditor / httpinvoker / HttpInvokerServicesTest.java
index fdb7311084f1320e5839d816921e863c93ec11b5..45a58486350028c91ea2e972a48d28c4b95e8cfd 100644 (file)
@@ -12,14 +12,17 @@ import org.apache.log4j.Logger;
 import org.junit.Assert;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.springframework.remoting.RemoteAccessException;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.service.ITestService;
 import eu.etaxonomy.cdm.config.CdmSourceException;
 import eu.etaxonomy.cdm.model.description.PolytomousKey;
 
 /**
  * Class to test the HttpInvoker services exposed by the CDM Sever
- *
  */
 public class HttpInvokerServicesTest extends BaseRemotingTest {
     private static final Logger logger = Logger.getLogger(HttpInvokerServicesTest.class);
@@ -33,8 +36,6 @@ public class HttpInvokerServicesTest extends BaseRemotingTest {
             //getRemoteApplicationController().getDatabaseService();
             String dbSchemaVersion = getRemoteApplicationController().getDatabaseService().getDbSchemaVersion();
             logger.info("dbSchemaVersion is " + dbSchemaVersion);
-
-
         } catch (CdmSourceException e) {
             Assert.fail("pinging database service on active cdm server should not have thrown CdmSourceException");
         }
@@ -42,6 +43,23 @@ public class HttpInvokerServicesTest extends BaseRemotingTest {
         getRemoteApplicationController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
     }
 
+    @Ignore
+    @Test
+    public void whenCallingMethodsOnRemoteServicesThenFailIfNotAuthenticated() {
+
+        SecurityContext context = SecurityContextHolder.getContext();
+
+        CdmApplicationState.setCurrentSecurityContext(null);
+        try {
+            getRemoteApplicationController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
+            Assert.fail("service call should fail as it is not authenticated");
+        }catch (RemoteAccessException rae) {
+
+        }
+
+        CdmApplicationState.setCurrentSecurityContext(context);
+    }
+
     // should be kept at ignore and only used for manual testing
     // otherwise tests will take too much time
     @Ignore
@@ -49,5 +67,4 @@ public class HttpInvokerServicesTest extends BaseRemotingTest {
     public void testDisableReadTimeout() throws InterruptedException  {
         testService.waitFor((long) 120000.0);
     }
-
 }