merge from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.test / src / test / java / eu / etaxonomy / taxeditor / httpinvoker / HttpInvokerServicesTest.java
index b05d362e99c5daf70eb36269de5d1710f38cf924..be22f3a7fca79170f93ab2ab9390d389113c09ef 100644 (file)
@@ -1,34 +1,61 @@
 /**
-* Copyright (C) 2014 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2014 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 package eu.etaxonomy.taxeditor.httpinvoker;
 
+import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.junit.Assert;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.context.SecurityContextImpl;
 
 import eu.etaxonomy.cdm.config.CdmSourceException;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
 
 /**
  * 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);
-
-       @Test
-       public void whenCallingMethodsOnRemoteServicesThenSuceed() {
-               try {
-                       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");
-               }
-       }
+    private static final Logger logger = Logger.getLogger(HttpInvokerServicesTest.class);
+
+    @BeforeClass
+    public static void initializeHttpInvokerServicesTest() {
+        logger.setLevel(Level.INFO);
+        initializeController("default", "127.0.0.1", 8080, "", NomenclaturalCode.ICNAFP);
+    }
+
+    @Test
+    public void whenCallingMethodsOnRemoteServicesThenSucceed() {
+        try {
+            SecurityContextHolder.clearContext();
+
+            String username = "admin";
+            String pw = "kups366+RU";
+
+            SecurityContextImpl sc = new SecurityContextImpl();
+            Authentication token = new UsernamePasswordAuthenticationToken(username,pw);
+            Authentication authentication = getRemoteApplicationController().getAuthenticationManager().authenticate(token);
+
+            authentication = new UsernamePasswordAuthenticationToken(username,pw, authentication.getAuthorities());
+            sc.setAuthentication(authentication);
+
+            SecurityContextHolder.setContext(sc);
+            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");
+        }
+    }
 
 }