Clover Coverage Report - ARESTC 0.1.7-SNAPSHOT
Coverage timestamp: Fri Aug 27 2010 19:12:04 CEST
50   244   19   3.85
0   120   0.38   13
13     1.46  
1    
 
  BaseServiceTest       Line # 40 50 0% 19 12 81% 0.8095238
 
  (11)
 
1    /*
2    *
3    * (C)opyright 2010, Nikolaos Georgosopoulos
4    *
5    * This file is part of ARESTC.
6    *
7    * ARESTC is free software: you can redistribute it and/or modify it under the
8    * terms of the Lesser General Public License as published by the Free Software
9    * Foundation, either version 3 of the License, or (at your option) any later
10    * version.
11    *
12    * ARESTC is distributed in the hope that it will be useful, but WITHOUT ANY
13    * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14    * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15    *
16    * You should have received a copy of the Lesser General Public License along
17    * with ARESTC. If not, see <http://www.gnu.org/licenses/>.
18    */
19    package net.sf.arestc.configuration.services;
20   
21    import java.util.HashMap;
22    import java.util.Map;
23   
24    import junit.framework.TestCase;
25    import net.sf.arestc.configuration.ServicesConfigurationFactory;
26    import net.sf.arestc.core.services.BaseService;
27    import net.sf.arestc.core.services.HTTPMethods;
28    import net.sf.arestc.core.services.ServiceParameterTypes;
29   
30    import org.apache.commons.configuration.ConfigurationException;
31    import org.apache.commons.httpclient.UsernamePasswordCredentials;
32    import org.apache.log4j.Logger;
33   
34    // TODO: Auto-generated Javadoc
35    /**
36    * The Class BaseServiceTest.
37    *
38    * @author georgosn
39    */
 
40    public class BaseServiceTest extends TestCase {
41   
42    /** The Constant LOGGER. */
43    private static final Logger LOGGER = Logger.getLogger(BaseServiceTest.class
44    .getName());
45   
46    /** The service. */
47    private BaseService service;
48   
49    /*
50    * (non-Javadoc)
51    *
52    * @see junit.framework.TestCase#setUp()
53    */
 
54  11 toggle @Override
55    protected void setUp() throws Exception {
56  11 super.setUp();
57  11 service = (BaseService) ServicesConfigurationFactory._instance
58    .configure().get("login");
59    }
60   
61    /*
62    * (non-Javadoc)
63    *
64    * @see junit.framework.TestCase#tearDown()
65    */
 
66  11 toggle @Override
67    protected void tearDown() throws Exception {
68  11 service = null;
69  11 super.tearDown();
70    }
71   
72    /**
73    * Test method for.
74    *
75    * {@link net.sf.arestc.core.services.BaseService#addParameter(java.lang.String, java.lang.Object)}
76    * .
77    */
 
78  1 toggle public void testAddParameter() {
79   
80  1 service.addParameter("none", ServiceParameterTypes.URL);
81   
82  1 assertTrue(service.getParameters().get(ServiceParameterTypes.URL)
83    .contains("none"));
84    }
85   
86    /**
87    * Test method for.
88    *
89    * {@link net.sf.arestc.core.services.BaseService#getAdminPassword()} .
90    */
 
91  1 toggle public void testGetAdminPassword() {
92  1 assertNull(service.getAdminCredentials());
93  1 try {
94  1 final BaseService localService = (BaseService) ServicesConfigurationFactory._instance
95    .configure().get("nodeRetrieve");
96  1 assertEquals("admin",
97    ((UsernamePasswordCredentials) localService
98    .getAdminCredentials()).getPassword());
99    } catch (final ConfigurationException e) {
100   
101  0 LOGGER.error("Error occured in testGetURLParameters:", e);
102  0 fail("nodeRetrieval test fail");
103    }
104    }
105   
106    /**
107    * Test method for.
108    *
109    * {@link net.sf.arestc.core.services.BaseService#getAdminUser()}.
110    */
 
111  1 toggle public void testGetAdminUser() {
112  1 assertNull(service.getAdminCredentials());
113  1 try {
114  1 final BaseService localService = (BaseService) ServicesConfigurationFactory._instance
115    .configure().get("nodeRetrieve");
116  1 assertEquals("admin",
117    ((UsernamePasswordCredentials) localService
118    .getAdminCredentials()).getUserName());
119    } catch (final ConfigurationException e) {
120   
121  0 LOGGER.error("Error occured in testGetURLParameters:", e);
122  0 fail("nodeRetrieval test fail");
123    }
124    }
125   
126    /**
127    * Test method for.
128    *
129    * {@link net.sf.arestc.core.services.BaseService#getAuthenticatingUser()} .
130    */
 
131  1 toggle public void testGetAuthenticatingUser() {
132  1 assertNull(service.getAuthenticatingUser());
133  1 try {
134  1 final BaseService localService = (BaseService) ServicesConfigurationFactory._instance
135    .configure().get("nodeRetrieve");
136  1 assertEquals("admin", localService.getAuthenticatingUser());
137    } catch (final ConfigurationException e) {
138   
139  0 LOGGER.error("Error occured in testGetURLParameters:", e);
140  0 fail("nodeRetrieval test fail");
141    }
142    }
143   
144    /**
145    * Test method for.
146    *
147    * {@link net.sf.arestc.core.services.BaseService#getContextPath()} .
148    */
 
149  1 toggle public void testGetContextPath() {
150  1 assertEquals("alfresco/service/api/login", service.getContextPath());
151    }
152   
153    /**
154    * Test method for.
155    *
156    * {@link net.sf.arestc.core.services.BaseService#getMethod()}.
157    */
 
158  1 toggle public void testGetMethod() {
159  1 assertEquals(HTTPMethods.GET, service.getMethod());
160    }
161   
162    /**
163    * Test method for.
164    *
165    * {@link net.sf.arestc.core.services.BaseService#getName()}.
166    */
 
167  1 toggle public void testGetName() {
168  1 assertEquals("login", service.getName());
169    }
170   
171    /**
172    * Test method for.
173    *
174    * {@link net.sf.arestc.core.services.BaseService#getParameters()}.
175    */
 
176  1 toggle public void testGetParameters() {
177  1 assertNotNull(service.getParameters());
178    }
179   
180    /**
181    * Test method for.
182    *
183    * {@link net.sf.arestc.core.services.BaseService#getServiceURL(java.util.Map)}
184    * .
185    */
 
186  1 toggle public void testGetServiceURL() {
187  1 final Map<String, Object> params = new HashMap<String, Object>();
188   
189  1 try {
190  1 params.clear();
191  1 params.put("store_type", "workspace");
192  1 params.put("store_id", "SpacesStore");
193  1 params.put("id", "41508ea0-c3f6-412e-a4b1-59f186c83b4f");
194  1 final BaseService localService = (BaseService) ServicesConfigurationFactory._instance
195    .configure().get("nodeRetrieve");
196  1 assertEquals(
197    "http://localhost:9090/alfresco/service/api/node/workspace/SpacesStore/41508ea0-c3f6-412e-a4b1-59f186c83b4f/permissions",
198    localService.getServiceURL(params).toString());
199   
200    } catch (final ConfigurationException e) {
201   
202  0 LOGGER.error("Error occured in testGetURLParameters:", e);
203  0 fail("nodeRetrieval test fail");
204    }
205    }
206   
207    /**
208    * Test method for.
209    *
210    * {@link net.sf.arestc.core.services.BaseService#getURLParameters()} .
211    */
 
212  1 toggle public void testGetURLParameters() {
213  1 assertTrue(service.getURLParameters().isEmpty());
214  1 try {
215  1 final BaseService localService = (BaseService) ServicesConfigurationFactory._instance
216    .configure().get("nodeRetrieve");
217  1 assertFalse(localService.getURLParameters().isEmpty());
218    } catch (final ConfigurationException e) {
219   
220  0 LOGGER.error("Error occured in testGetURLParameters:", e);
221  0 fail("nodeRetrieval test fail");
222    }
223    }
224   
225    /**
226    * Test method for.
227    *
228    * {@link net.sf.arestc.core.services.BaseService#isAuthenticationRequired()}
229    * .
230    */
 
231  1 toggle public void testIsAuthenticationRequired() {
232  1 assertFalse(service.isAuthenticationRequired());
233  1 try {
234  1 final BaseService localService = (BaseService) ServicesConfigurationFactory._instance
235    .configure().get("nodeRetrieve");
236  1 assertTrue(localService.isAuthenticationRequired());
237    } catch (final ConfigurationException e) {
238   
239  0 LOGGER.error("Error occured in testGetURLParameters:", e);
240  0 fail("nodeRetrieval test fail");
241    }
242    }
243   
244    }