| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package net.sf.arestc.core.validations; |
| 20 |
|
|
| 21 |
|
import java.util.Collection; |
| 22 |
|
import java.util.EnumMap; |
| 23 |
|
import java.util.HashMap; |
| 24 |
|
import java.util.HashSet; |
| 25 |
|
import java.util.Map; |
| 26 |
|
|
| 27 |
|
import junit.framework.TestCase; |
| 28 |
|
import net.sf.arestc.core.services.BaseService; |
| 29 |
|
import net.sf.arestc.core.services.HTTPMethods; |
| 30 |
|
import net.sf.arestc.core.services.RESTService; |
| 31 |
|
import net.sf.arestc.core.services.ReturnedTypes; |
| 32 |
|
import net.sf.arestc.core.services.ServiceAuthenticationData; |
| 33 |
|
import net.sf.arestc.core.services.ServiceConnectionData; |
| 34 |
|
import net.sf.arestc.core.services.ServiceConnectorData; |
| 35 |
|
import net.sf.arestc.core.services.ServiceParameterTypes; |
| 36 |
|
|
| 37 |
|
import org.apache.commons.httpclient.UsernamePasswordCredentials; |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
@author |
| 44 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (108) |
Complexity: 13 |
Complexity Density: 0.14 |
|
| 45 |
|
public class RequestValidatorTest extends TestCase { |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
private RequestValidator validator; |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
@see |
| 54 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 55 |
11
|
@Override... |
| 56 |
|
protected void setUp() throws Exception { |
| 57 |
11
|
super.setUp(); |
| 58 |
11
|
validator = new RequestValidator(); |
| 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
|
validator = null; |
| 69 |
11
|
super.tearDown(); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 75 |
1
|
public void testValidateRequestAuthenticationAdminAdminCred() {... |
| 76 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 77 |
|
"http://localhost", 8080, "/{p}", HTTPMethods.GET); |
| 78 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 79 |
|
true, "admin", |
| 80 |
|
new UsernamePasswordCredentials("admin", "admin")); |
| 81 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 82 |
|
null, ReturnedTypes.NOBODY); |
| 83 |
|
|
| 84 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 85 |
|
ServiceParameterTypes.class); |
| 86 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 87 |
1
|
pars1.get(ServiceParameterTypes.URL).add("p"); |
| 88 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 89 |
|
connectionData, authData, connectorData); |
| 90 |
|
|
| 91 |
1
|
final Map<String, Object> params = new HashMap<String, Object>(); |
| 92 |
1
|
params.put("p", "admin"); |
| 93 |
|
|
| 94 |
1
|
assertTrue(validator.isValidRequest(params, null, service)); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 100 |
1
|
public void testValidateRequestAuthenticationAdminNoCred() {... |
| 101 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 102 |
|
"http://localhost", 8080, "/{p}", HTTPMethods.GET); |
| 103 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 104 |
|
true, "admin", null); |
| 105 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 106 |
|
null, ReturnedTypes.NOBODY); |
| 107 |
|
|
| 108 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 109 |
|
ServiceParameterTypes.class); |
| 110 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 111 |
1
|
pars1.get(ServiceParameterTypes.URL).add("p"); |
| 112 |
|
|
| 113 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 114 |
|
connectionData, authData, connectorData); |
| 115 |
|
|
| 116 |
1
|
final Map<String, Object> params = new HashMap<String, Object>(); |
| 117 |
1
|
params.put("p", "url"); |
| 118 |
|
|
| 119 |
1
|
assertFalse(validator.isValidRequest(params, null, service)); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 125 |
1
|
public void testValidateRequestAuthenticationNoCred() {... |
| 126 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 127 |
|
"http://localhost", 8080, "/{p}", HTTPMethods.GET); |
| 128 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 129 |
|
true, "admin", null); |
| 130 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 131 |
|
null, ReturnedTypes.NOBODY); |
| 132 |
|
|
| 133 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 134 |
|
ServiceParameterTypes.class); |
| 135 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 136 |
1
|
pars1.get(ServiceParameterTypes.URL).add("p"); |
| 137 |
|
|
| 138 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 139 |
|
connectionData, authData, connectorData); |
| 140 |
|
|
| 141 |
1
|
final Map<String, Object> params = new HashMap<String, Object>(); |
| 142 |
1
|
params.put("p", "admin"); |
| 143 |
|
|
| 144 |
1
|
assertFalse(validator.isValidRequest(params, null, service)); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 150 |
1
|
public void testValidateRequestAuthenticationUserCred() {... |
| 151 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 152 |
|
"http://localhost", 8080, "/{p}", HTTPMethods.GET); |
| 153 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 154 |
|
true, "user", null); |
| 155 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 156 |
|
null, ReturnedTypes.NOBODY); |
| 157 |
|
|
| 158 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 159 |
|
ServiceParameterTypes.class); |
| 160 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 161 |
1
|
pars1.get(ServiceParameterTypes.URL).add("p"); |
| 162 |
|
|
| 163 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 164 |
|
connectionData, authData, connectorData); |
| 165 |
|
|
| 166 |
1
|
final Map<String, Object> params = new HashMap<String, Object>(); |
| 167 |
1
|
params.put("p", "admin"); |
| 168 |
|
|
| 169 |
1
|
assertTrue(validator.isValidRequest(params, |
| 170 |
|
new UsernamePasswordCredentials("nick", "nick"), service)); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 176 |
1
|
public void testValidateRequestAuthenticationUserNoCred() {... |
| 177 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 178 |
|
"http://localhost", 8080, "/{p}", HTTPMethods.GET); |
| 179 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 180 |
|
true, "user", null); |
| 181 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 182 |
|
null, ReturnedTypes.NOBODY); |
| 183 |
|
|
| 184 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 185 |
|
ServiceParameterTypes.class); |
| 186 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 187 |
1
|
pars1.get(ServiceParameterTypes.URL).add("p"); |
| 188 |
|
|
| 189 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 190 |
|
connectionData, authData, connectorData); |
| 191 |
|
|
| 192 |
1
|
final Map<String, Object> params = new HashMap<String, Object>(); |
| 193 |
1
|
params.put("p", "admin"); |
| 194 |
|
|
| 195 |
1
|
assertFalse(validator.isValidRequest(params, null, service)); |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 201 |
1
|
public void testValidateRequestFullParams() {... |
| 202 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 203 |
|
"http://localhost", 8080, "/{p}", HTTPMethods.GET); |
| 204 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 205 |
|
true, "admin", |
| 206 |
|
new UsernamePasswordCredentials("admin", "admin")); |
| 207 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 208 |
|
null, ReturnedTypes.NOBODY); |
| 209 |
|
|
| 210 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 211 |
|
ServiceParameterTypes.class); |
| 212 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 213 |
1
|
pars1.get(ServiceParameterTypes.URL).add("p"); |
| 214 |
|
|
| 215 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 216 |
|
connectionData, authData, connectorData); |
| 217 |
|
|
| 218 |
1
|
final Map<String, Object> params = new HashMap<String, Object>(); |
| 219 |
1
|
params.put("p", "admin"); |
| 220 |
|
|
| 221 |
1
|
assertTrue(validator.isValidRequest(params, null, service)); |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1
PASS
|
|
| 227 |
1
|
public void testValidateRequestFullServiceParams() {... |
| 228 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 229 |
|
"http://localhost", 8080, "/{p}", HTTPMethods.GET); |
| 230 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 231 |
|
true, "admin", |
| 232 |
|
new UsernamePasswordCredentials("admin", "admin")); |
| 233 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 234 |
|
null, ReturnedTypes.NOBODY); |
| 235 |
|
|
| 236 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 237 |
|
ServiceParameterTypes.class); |
| 238 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 239 |
1
|
pars1.get(ServiceParameterTypes.URL).add("p"); |
| 240 |
|
|
| 241 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 242 |
|
connectionData, authData, connectorData); |
| 243 |
|
|
| 244 |
1
|
assertFalse(validator.isValidRequest(new HashMap<String, Object>(), |
| 245 |
|
null, service)); |
| 246 |
|
} |
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
| 251 |
1
|
public void testValidateRequestNotNullServiceParams() {... |
| 252 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 253 |
|
"http://localhost", 8080, "/", HTTPMethods.GET); |
| 254 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 255 |
|
true, "admin", |
| 256 |
|
new UsernamePasswordCredentials("admin", "admin")); |
| 257 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 258 |
|
null, ReturnedTypes.NOBODY); |
| 259 |
|
|
| 260 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 261 |
|
ServiceParameterTypes.class); |
| 262 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 263 |
|
|
| 264 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 265 |
|
connectionData, authData, connectorData); |
| 266 |
|
|
| 267 |
1
|
assertTrue(validator.isValidRequest(new HashMap<String, Object>(), |
| 268 |
|
null, service)); |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
|
| 272 |
|
|
| 273 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
| 274 |
1
|
public void testValidateRequestNullParameters() {... |
| 275 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 276 |
|
"http://localhost", 8080, "/", HTTPMethods.GET); |
| 277 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 278 |
|
true, "admin", |
| 279 |
|
new UsernamePasswordCredentials("admin", "admin")); |
| 280 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 281 |
|
null, ReturnedTypes.NOBODY); |
| 282 |
|
|
| 283 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 284 |
|
ServiceParameterTypes.class); |
| 285 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 286 |
|
|
| 287 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 288 |
|
connectionData, authData, connectorData); |
| 289 |
|
|
| 290 |
1
|
assertFalse(validator.isValidRequest(null, null, service)); |
| 291 |
|
} |
| 292 |
|
|
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| 296 |
|
@link |
| 297 |
|
|
| 298 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 299 |
1
|
public void testValidateRequestNullService() {... |
| 300 |
1
|
assertFalse(validator.isValidRequest(null, null, null)); |
| 301 |
|
} |
| 302 |
|
|
| 303 |
|
|
| 304 |
|
|
| 305 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1
PASS
|
|
| 306 |
1
|
public void testValidateRequestNullServiceParams() {... |
| 307 |
1
|
final ServiceConnectionData connectionData = new ServiceConnectionData( |
| 308 |
|
"http://localhost", 8080, "/{p}", HTTPMethods.GET); |
| 309 |
1
|
final ServiceAuthenticationData authData = new ServiceAuthenticationData( |
| 310 |
|
true, "admin", |
| 311 |
|
new UsernamePasswordCredentials("admin", "admin")); |
| 312 |
1
|
final ServiceConnectorData connectorData = new ServiceConnectorData( |
| 313 |
|
null, ReturnedTypes.NOBODY); |
| 314 |
|
|
| 315 |
1
|
final EnumMap<ServiceParameterTypes, Collection<String>> pars1 = new EnumMap<ServiceParameterTypes, Collection<String>>( |
| 316 |
|
ServiceParameterTypes.class); |
| 317 |
1
|
pars1.put(ServiceParameterTypes.URL, new HashSet<String>()); |
| 318 |
1
|
pars1.get(ServiceParameterTypes.URL).add("p"); |
| 319 |
|
|
| 320 |
1
|
final RESTService service = new BaseService("dummyService", pars1, |
| 321 |
|
connectionData, authData, connectorData); |
| 322 |
|
|
| 323 |
1
|
assertFalse(validator.isValidRequest(new HashMap<String, Object>(), |
| 324 |
|
null, service)); |
| 325 |
|
} |
| 326 |
|
} |