merge from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.test / src / test / java / eu / etaxonomy / taxeditor / httpinvoker / HttpInvokerServicesTest.java
1 /**
2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.httpinvoker;
10
11 import org.apache.log4j.Level;
12 import org.apache.log4j.Logger;
13 import org.junit.Assert;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
17 import org.springframework.security.core.Authentication;
18 import org.springframework.security.core.context.SecurityContextHolder;
19 import org.springframework.security.core.context.SecurityContextImpl;
20
21 import eu.etaxonomy.cdm.config.CdmSourceException;
22 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
23
24 /**
25 * Class to test the HttpInvoker services exposed by the CDM Sever
26 *
27 */
28 public class HttpInvokerServicesTest extends BaseRemotingTest {
29 private static final Logger logger = Logger.getLogger(HttpInvokerServicesTest.class);
30
31 @BeforeClass
32 public static void initializeHttpInvokerServicesTest() {
33 logger.setLevel(Level.INFO);
34 initializeController("default", "127.0.0.1", 8080, "", NomenclaturalCode.ICNAFP);
35 }
36
37 @Test
38 public void whenCallingMethodsOnRemoteServicesThenSucceed() {
39 try {
40 SecurityContextHolder.clearContext();
41
42 String username = "admin";
43 String pw = "kups366+RU";
44
45 SecurityContextImpl sc = new SecurityContextImpl();
46 Authentication token = new UsernamePasswordAuthenticationToken(username,pw);
47 Authentication authentication = getRemoteApplicationController().getAuthenticationManager().authenticate(token);
48
49 authentication = new UsernamePasswordAuthenticationToken(username,pw, authentication.getAuthorities());
50 sc.setAuthentication(authentication);
51
52 SecurityContextHolder.setContext(sc);
53 getRemoteApplicationController().getDatabaseService();
54 String dbSchemaVersion = getRemoteApplicationController().getDatabaseService().getDbSchemaVersion();
55 logger.info("dbSchemaVersion is " + dbSchemaVersion);
56 } catch (CdmSourceException e) {
57 Assert.fail("pinging database service on active cdm server should not have thrown CdmSourceException");
58 }
59 }
60
61 }