| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 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 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@author |
| 39 |
|
|
|
|
|
| 81% |
Uncovered Elements: 12 (63) |
Complexity: 19 |
Complexity Density: 0.38 |
|
| 40 |
|
public class BaseServiceTest extends TestCase { |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
private static final Logger LOGGER = Logger.getLogger(BaseServiceTest.class |
| 44 |
|
.getName()); |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
private BaseService service; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@see |
| 53 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 54 |
11
|
@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 |
|
|
| 63 |
|
|
| 64 |
|
@see |
| 65 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 66 |
11
|
@Override... |
| 67 |
|
protected void tearDown() throws Exception { |
| 68 |
11
|
service = null; |
| 69 |
11
|
super.tearDown(); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
@link |
| 76 |
|
|
| 77 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1
PASS
|
|
| 78 |
1
|
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 |
|
|
| 88 |
|
|
| 89 |
|
@link |
| 90 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1
PASS
|
|
| 91 |
1
|
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 |
|
|
| 108 |
|
|
| 109 |
|
@link |
| 110 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1
PASS
|
|
| 111 |
1
|
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 |
|
|
| 128 |
|
|
| 129 |
|
@link |
| 130 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1
PASS
|
|
| 131 |
1
|
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 |
|
|
| 146 |
|
|
| 147 |
|
@link |
| 148 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 149 |
1
|
public void testGetContextPath() {... |
| 150 |
1
|
assertEquals("alfresco/service/api/login", service.getContextPath()); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
|
@link |
| 157 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 158 |
1
|
public void testGetMethod() {... |
| 159 |
1
|
assertEquals(HTTPMethods.GET, service.getMethod()); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
@link |
| 166 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 167 |
1
|
public void testGetName() {... |
| 168 |
1
|
assertEquals("login", service.getName()); |
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
@link |
| 175 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 176 |
1
|
public void testGetParameters() {... |
| 177 |
1
|
assertNotNull(service.getParameters()); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
@link |
| 184 |
|
|
| 185 |
|
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
1
PASS
|
|
| 186 |
1
|
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 |
|
|
| 209 |
|
|
| 210 |
|
@link |
| 211 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1
PASS
|
|
| 212 |
1
|
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 |
|
|
| 227 |
|
|
| 228 |
|
@link |
| 229 |
|
|
| 230 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1
PASS
|
|
| 231 |
1
|
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 |
|
} |