You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by jb...@apache.org on 2013/01/09 10:15:53 UTC
svn commit: r1430743 - in /syncope/trunk:
client/src/main/java/org/apache/syncope/services/
client/src/main/java/org/apache/syncope/services/proxy/
core/src/main/java/org/apache/syncope/core/rest/controller/
core/src/test/java/org/apache/syncope/core/r...
Author: jbernhardt
Date: Wed Jan 9 09:15:52 2013
New Revision: 1430743
URL: http://svn.apache.org/viewvc?rev=1430743&view=rev
Log:
[SYNCOPE-259]
Introduces User Request Service.
Changed visibility from restTemplate in AbstractTest to private and fixed all references in SubClasses.
Added:
syncope/trunk/client/src/main/java/org/apache/syncope/services/UserRequestService.java
syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/UserRequestServiceProxy.java
Modified:
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserRequestController.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
Added: syncope/trunk/client/src/main/java/org/apache/syncope/services/UserRequestService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/services/UserRequestService.java?rev=1430743&view=auto
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/services/UserRequestService.java (added)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/services/UserRequestService.java Wed Jan 9 09:15:52 2013
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.services;
+
+import java.util.List;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+import org.apache.syncope.client.mod.UserMod;
+import org.apache.syncope.client.to.UserRequestTO;
+import org.apache.syncope.client.to.UserTO;
+
+@Path("requests/users")
+public interface UserRequestService {
+
+ @GET
+ @Path("create/allowed")
+ // @RequestMapping(method = RequestMethod.GET, value = "/create/allowed")
+ boolean isCreateAllowed();
+
+ @POST
+ @Path("create")
+ // @RequestMapping(method = RequestMethod.POST, value = "/create")
+ UserRequestTO create(final UserTO userTO);
+
+ @POST
+ @Path("update")
+ // @RequestMapping(method = RequestMethod.POST, value = "/update")
+ UserRequestTO update(final UserMod userMod);
+
+ @POST
+ @Path("delete")
+ // @RequestMapping(method = RequestMethod.GET, value = "/delete/{userId}")
+ UserRequestTO delete(final Long userId);
+
+ @GET
+ // @RequestMapping(method = RequestMethod.GET, value = "/list")
+ List<UserRequestTO> list();
+
+ @GET
+ @Path("{requestId}")
+ // @RequestMapping(method = RequestMethod.GET, value = "/read/{requestId}")
+ UserRequestTO read(@PathParam("requestId") final Long requestId);
+
+ @DELETE
+ @Path("{requestId}")
+ // @RequestMapping(method = RequestMethod.GET, value = "/deleteRequest/{requestId}")
+ UserRequestTO deleteRequest(@PathParam("requestId") final Long requestId);
+
+}
\ No newline at end of file
Added: syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/UserRequestServiceProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/UserRequestServiceProxy.java?rev=1430743&view=auto
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/UserRequestServiceProxy.java (added)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/UserRequestServiceProxy.java Wed Jan 9 09:15:52 2013
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.services.proxy;
+
+import java.util.List;
+
+import org.apache.syncope.client.mod.UserMod;
+import org.apache.syncope.client.to.UserRequestTO;
+import org.apache.syncope.client.to.UserTO;
+import org.apache.syncope.services.UserRequestService;
+import org.springframework.web.client.RestTemplate;
+
+public class UserRequestServiceProxy extends SpringServiceProxy implements UserRequestService {
+
+ public UserRequestServiceProxy(String baseUrl, RestTemplate restTemplate) {
+ super(baseUrl, restTemplate);
+ }
+
+ @Override
+ public boolean isCreateAllowed() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public UserRequestTO create(UserTO userTO) {
+ return restTemplate.postForObject(baseUrl + "user/request/create", userTO, UserRequestTO.class);
+ }
+
+ @Override
+ public UserRequestTO update(UserMod userMod) {
+ return restTemplate.postForObject(baseUrl + "user/request/update", userMod, UserRequestTO.class);
+ }
+
+ @Override
+ public UserRequestTO delete(Long userId) {
+ return restTemplate.getForObject(baseUrl + "user/request/delete/{userId}", UserRequestTO.class,
+ userId);
+ }
+
+ @Override
+ public List<UserRequestTO> list() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public UserRequestTO read(Long requestId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public UserRequestTO deleteRequest(Long requestId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserRequestController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserRequestController.java?rev=1430743&r1=1430742&r2=1430743&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserRequestController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserRequestController.java Wed Jan 9 09:15:52 2013
@@ -20,7 +20,9 @@ package org.apache.syncope.core.rest.con
import java.util.ArrayList;
import java.util.List;
+
import javax.persistence.RollbackException;
+
import org.apache.syncope.client.mod.UserMod;
import org.apache.syncope.client.to.UserRequestTO;
import org.apache.syncope.client.to.UserTO;
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java?rev=1430743&r1=1430742&r2=1430743&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java Wed Jan 9 09:15:52 2013
@@ -35,6 +35,7 @@ import org.apache.syncope.services.Resou
import org.apache.syncope.services.RoleService;
import org.apache.syncope.services.SchemaService;
import org.apache.syncope.services.TaskService;
+import org.apache.syncope.services.UserRequestService;
import org.apache.syncope.services.UserService;
import org.apache.syncope.services.WorkflowService;
import org.apache.syncope.services.proxy.ConfigurationServiceProxy;
@@ -48,6 +49,7 @@ import org.apache.syncope.services.proxy
import org.apache.syncope.services.proxy.RoleServiceProxy;
import org.apache.syncope.services.proxy.SchemaServiceProxy;
import org.apache.syncope.services.proxy.TaskServiceProxy;
+import org.apache.syncope.services.proxy.UserRequestServiceProxy;
import org.apache.syncope.services.proxy.UserServiceProxy;
import org.apache.syncope.services.proxy.WorkflowServiceProxy;
import org.junit.Before;
@@ -91,7 +93,7 @@ public abstract class AbstractTest {
protected PolicyServiceProxy policyService;
@Autowired
- protected RestTemplate restTemplate;
+ private RestTemplate restTemplate;
protected UserService userService;
@@ -117,6 +119,8 @@ public abstract class AbstractTest {
protected SchemaService schemaService;
+ protected UserRequestService userRequestService;
+
@Autowired
protected DataSource testDataSource;
@@ -148,5 +152,6 @@ public abstract class AbstractTest {
workflowService = new WorkflowServiceProxy(BASE_URL, restTemplate);
notificationService = new NotificationServiceProxy(BASE_URL, restTemplate);
schemaService = new SchemaServiceProxy(BASE_URL, restTemplate);
+ userRequestService = new UserRequestServiceProxy(BASE_URL, restTemplate);
}
}
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java?rev=1430743&r1=1430742&r2=1430743&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java Wed Jan 9 09:15:52 2013
@@ -80,8 +80,7 @@ public class AuthenticationTestITCase ex
schemaTO.setMandatoryCondition("false");
schemaTO.setType(SchemaType.String);
- SchemaTO newSchemaTO = restTemplate.postForObject(BASE_URL
- + "schema/user/create", schemaTO, SchemaTO.class);
+ SchemaTO newSchemaTO = schemaService.create("user", schemaTO);
assertEquals(schemaTO, newSchemaTO);
// 2. create an user with the role created above (as admin)
@@ -99,22 +98,19 @@ public class AuthenticationTestITCase ex
assertNotNull(userTO);
// 3. read the schema created above (as admin) - success
- schemaTO = restTemplate.getForObject(BASE_URL
- + "schema/user/read/authTestSchema.json", SchemaTO.class);
+ schemaTO = schemaService.read("user", "authTestSchema", SchemaTO.class);
assertNotNull(schemaTO);
// 4. read the schema created above (as user) - success
super.setupRestTemplate(userTO.getUsername(), "password123");
- schemaTO = restTemplate.getForObject(BASE_URL
- + "schema/user/read/authTestSchema.json", SchemaTO.class);
+ schemaTO = schemaService.read("user", "authTestSchema", SchemaTO.class);
assertNotNull(schemaTO);
// 5. update the schema create above (as user) - failure
HttpClientErrorException exception = null;
try {
- restTemplate.postForObject(BASE_URL + "schema/role/update",
- schemaTO, SchemaTO.class);
+ schemaService.update("role", schemaTO.getName(), schemaTO);
} catch (HttpClientErrorException e) {
exception = e;
}
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java?rev=1430743&r1=1430742&r2=1430743&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java Wed Jan 9 09:15:52 2013
@@ -18,15 +18,17 @@
*/
package org.apache.syncope.core.rest;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
-import org.apache.syncope.client.validation.SyncopeClientCompositeErrorException;
-import java.util.Arrays;
import java.util.List;
+
import org.apache.syncope.client.to.DerivedSchemaTO;
-import org.junit.Test;
+import org.apache.syncope.client.validation.SyncopeClientCompositeErrorException;
import org.apache.syncope.types.SyncopeClientExceptionType;
import org.junit.FixMethodOrder;
+import org.junit.Test;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.JVM)
@@ -38,8 +40,7 @@ public class DerivedSchemaTestITCase ext
@Test
public void list() {
- List<DerivedSchemaTO> derivedSchemas = Arrays.asList(restTemplate.getForObject(BASE_URL
- + "derivedSchema/user/list.json", DerivedSchemaTO[].class));
+ List<DerivedSchemaTO> derivedSchemas = schemaService.list(USER, DerivedSchemaTO[].class);
assertFalse(derivedSchemas.isEmpty());
for (DerivedSchemaTO derivedSchemaTO : derivedSchemas) {
assertNotNull(derivedSchemaTO);
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1430743&r1=1430742&r2=1430743&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java Wed Jan 9 09:15:52 2013
@@ -34,6 +34,7 @@ import org.apache.syncope.client.http.Pr
import org.apache.syncope.client.mod.RoleMod;
import org.apache.syncope.client.to.ConnObjectTO;
import org.apache.syncope.client.to.RoleTO;
+import org.apache.syncope.client.to.SchemaTO;
import org.apache.syncope.client.to.UserTO;
import org.apache.syncope.client.validation.SyncopeClientCompositeErrorException;
import org.apache.syncope.client.validation.SyncopeClientException;
@@ -188,10 +189,7 @@ public class RoleTestITCase extends Abst
assertTrue(userTO.getMembershipMap().containsKey(1L));
assertFalse(userTO.getMembershipMap().containsKey(3L));
- PreemptiveAuthHttpRequestFactory requestFactory = (PreemptiveAuthHttpRequestFactory) restTemplate
- .getRequestFactory();
- ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
- requestFactory.getAuthScope(), new UsernamePasswordCredentials("user1", "password"));
+ super.setupRestTemplate("user1", "password");
SyncopeClientException exception = null;
try {
@@ -316,10 +314,7 @@ public class RoleTestITCase extends Abst
roleMod.setName("Managing Director");
// 3. try to update as user3, not owner of role 7 - fail
- PreemptiveAuthHttpRequestFactory requestFactory = (PreemptiveAuthHttpRequestFactory) restTemplate
- .getRequestFactory();
- ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
- requestFactory.getAuthScope(), new UsernamePasswordCredentials("user2", "password"));
+ setupRestTemplate("user2", "password");
try {
roleService.update(roleMod.getId(), roleMod);
@@ -330,8 +325,7 @@ public class RoleTestITCase extends Abst
// 4. update as user5, owner of role 7 because owner of role 6 with
// inheritance - success
- ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
- requestFactory.getAuthScope(), new UsernamePasswordCredentials("user5", "password"));
+ super.setupRestTemplate("user5", ADMIN_PWD);
roleTO = roleService.update(roleMod.getId(), roleMod);
assertEquals("Managing Director", roleTO.getName());
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java?rev=1430743&r1=1430742&r2=1430743&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java Wed Jan 9 09:15:52 2013
@@ -464,8 +464,7 @@ public class TaskTestITCase extends Abst
notification.setSubject(subject);
notification.setTemplate("optin");
- notification = restTemplate.postForObject(BASE_URL + "notification/create.json", notification,
- NotificationTO.class);
+ notification = notificationService.create(notification);
assertNotNull(notification);
// 2. create user
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java?rev=1430743&r1=1430742&r2=1430743&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java Wed Jan 9 09:15:52 2013
@@ -18,16 +18,14 @@
*/
package org.apache.syncope.core.rest;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import java.util.Arrays;
import java.util.List;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.junit.Test;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.client.HttpStatusCodeException;
-import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory;
+
import org.apache.syncope.client.mod.UserMod;
import org.apache.syncope.client.search.AttributeCond;
import org.apache.syncope.client.search.NodeCond;
@@ -38,7 +36,10 @@ import org.apache.syncope.client.validat
import org.apache.syncope.client.validation.SyncopeClientException;
import org.apache.syncope.types.SyncopeClientExceptionType;
import org.junit.FixMethodOrder;
+import org.junit.Test;
import org.junit.runners.MethodSorters;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.client.HttpStatusCodeException;
@FixMethodOrder(MethodSorters.JVM)
public class UserRequestTestITCase extends AbstractTest {
@@ -50,8 +51,7 @@ public class UserRequestTestITCase exten
configurationTO.setKey("createRequest.allowed");
configurationTO.setValue("false");
- configurationTO = restTemplate.postForObject(BASE_URL + "configuration/create", configurationTO,
- ConfigurationTO.class);
+ configurationTO = configurationService.create(configurationTO);
assertNotNull(configurationTO);
UserTO userTO = UserTestITCase.getSampleTO("selfcreate@syncope.apache.org");
@@ -59,7 +59,7 @@ public class UserRequestTestITCase exten
// 2. get unauthorized when trying to request user create
SyncopeClientException exception = null;
try {
- restTemplate.postForObject(BASE_URL + "user/request/create", userTO, UserRequestTO.class);
+ userRequestService.create(userTO);
fail();
} catch (SyncopeClientCompositeErrorException e) {
exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole);
@@ -69,13 +69,12 @@ public class UserRequestTestITCase exten
// 3. set create request allowed
configurationTO.setValue("true");
- configurationTO = restTemplate.postForObject(BASE_URL + "configuration/create", configurationTO,
- ConfigurationTO.class);
+ configurationTO = configurationService.create(configurationTO);
assertNotNull(configurationTO);
// 4. as anonymous, request user create works
- UserRequestTO request = anonymousRestTemplate().postForObject(BASE_URL + "user/request/create", userTO,
- UserRequestTO.class);
+ UserRequestTO request = anonymousRestTemplate().postForObject(BASE_URL + "user/request/create",
+ userTO, UserRequestTO.class);
assertNotNull(request);
// 5. switch back to admin
@@ -86,12 +85,11 @@ public class UserRequestTestITCase exten
attrCond.setSchema("userId");
attrCond.setExpression("selfcreate@syncope.apache.org");
- final List<UserTO> matchingUsers = Arrays.asList(restTemplate.postForObject(BASE_URL + "user/search", NodeCond.
- getLeafCond(attrCond), UserTO[].class));
+ final List<UserTO> matchingUsers = userService.search(NodeCond.getLeafCond(attrCond));
assertTrue(matchingUsers.isEmpty());
// 7. actually create user
- userTO = restTemplate.postForObject(BASE_URL + "user/create", request.getUserTO(), UserTO.class);
+ userTO = userService.create(request.getUserTO());
assertNotNull(userTO);
}
@@ -101,7 +99,7 @@ public class UserRequestTestITCase exten
UserTO userTO = UserTestITCase.getSampleTO("selfupdate@syncope.apache.org");
String initialPassword = userTO.getPassword();
- userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
+ userTO = userService.create(userTO);
assertNotNull(userTO);
UserMod userMod = new UserMod();
@@ -111,7 +109,7 @@ public class UserRequestTestITCase exten
// 2. try to request user update as admin: failure
SyncopeClientException exception = null;
try {
- restTemplate.postForObject(BASE_URL + "user/request/update", userMod, UserRequestTO.class);
+ userRequestService.update(userMod);
fail();
} catch (SyncopeClientCompositeErrorException e) {
exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole);
@@ -119,15 +117,12 @@ public class UserRequestTestITCase exten
assertNotNull(exception);
// 3. auth as user just created
- PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory) restTemplate.
- getRequestFactory());
- ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
- requestFactory.getAuthScope(), new UsernamePasswordCredentials(userTO.getUsername(), initialPassword));
+ super.setupRestTemplate(userTO.getUsername(), initialPassword);
// 4. update with same password: not matching password policy
exception = null;
try {
- restTemplate.postForObject(BASE_URL + "user/request/update", userMod, UserRequestTO.class);
+ userRequestService.update(userMod);
} catch (SyncopeClientCompositeErrorException scce) {
exception = scce.getException(SyncopeClientExceptionType.InvalidSyncopeUser);
}
@@ -135,26 +130,22 @@ public class UserRequestTestITCase exten
// 5. now request user update works
userMod.setPassword("new" + initialPassword);
- UserRequestTO request = restTemplate.postForObject(BASE_URL + "user/request/update", userMod,
- UserRequestTO.class);
+ UserRequestTO request = userRequestService.update(userMod);
assertNotNull(request);
// 6. switch back to admin
super.resetRestTemplate();
// 7. user password has not changed yet
- Boolean verify = restTemplate.getForObject(BASE_URL + "user/verifyPassword/{username}.json?password="
- + userMod.getPassword(), Boolean.class, userTO.getUsername());
+ Boolean verify = userService.verifyPassword(userTO.getUsername(), userMod.getPassword());
assertFalse(verify);
// 8. actually update user
- userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
+ userTO = userService.update(userMod.getId(), userMod);
assertNotNull(userTO);
// 9. user password has now changed
- verify = restTemplate.getForObject(BASE_URL + "user/verifyPassword/{username}.json?password=" + userMod.
- getPassword(),
- Boolean.class, userTO.getUsername());
+ verify = userService.verifyPassword(userTO.getUsername(), userMod.getPassword());
assertTrue(verify);
}
@@ -164,13 +155,14 @@ public class UserRequestTestITCase exten
UserTO userTO = UserTestITCase.getSampleTO("selfdelete@syncope.apache.org");
String initialPassword = userTO.getPassword();
- userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
+ userTO = userService.create(userTO);
assertNotNull(userTO);
// 2. try to request user delete as admin: failure
SyncopeClientException exception = null;
try {
- restTemplate.getForObject(BASE_URL + "user/request/delete/{userId}", UserRequestTO.class, userTO.getId());
+
+ userRequestService.delete(userTO.getId());
fail();
} catch (SyncopeClientCompositeErrorException e) {
exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole);
@@ -178,29 +170,25 @@ public class UserRequestTestITCase exten
assertNotNull(exception);
// 3. auth as user just created
- PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory) restTemplate.
- getRequestFactory());
- ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
- requestFactory.getAuthScope(), new UsernamePasswordCredentials(userTO.getUsername(), initialPassword));
+ super.setupRestTemplate(userTO.getUsername(), initialPassword);
// 4. now request user delete works
- UserRequestTO request = restTemplate.getForObject(BASE_URL + "user/request/delete/{userId}",
- UserRequestTO.class, userTO.getId());
+ UserRequestTO request = userRequestService.delete(userTO.getId());
assertNotNull(request);
// 5. switch back to admin
super.resetRestTemplate();
// 6. user still exists
- UserTO actual = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class, userTO.getId());
+ UserTO actual = userService.read(userTO.getId());
assertNotNull(actual);
// 7. actually delete user
- restTemplate.getForObject(BASE_URL + "user/delete/{userId}", UserTO.class, userTO.getId());
+ userService.delete(userTO.getId());
// 8. user does not exist any more
try {
- restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class, userTO.getId());
+ userService.read(userTO.getId());
fail();
} catch (HttpStatusCodeException e) {
assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1430743&r1=1430742&r2=1430743&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java Wed Jan 9 09:15:52 2013
@@ -98,10 +98,7 @@ public class UserTestITCase extends Abst
@Test
public void selfRead() {
- PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory) restTemplate.
- getRequestFactory());
- ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
- requestFactory.getAuthScope(), new UsernamePasswordCredentials("user1", "password"));
+ super.setupRestTemplate("user1", ADMIN_PWD);
try {
userService.read(1l);
@@ -593,10 +590,7 @@ public class UserTestITCase extends Abst
assertNull(form.getOwner());
// 3. claim task from user1, not in role 7 (designated for approval in workflow definition): fail
- PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory) restTemplate.
- getRequestFactory());
- ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
- requestFactory.getAuthScope(), new UsernamePasswordCredentials("user1", "password"));
+ super.setupRestTemplate("user1", ADMIN_PWD);
SyncopeClientException sce = null;
try {
@@ -607,8 +601,7 @@ public class UserTestITCase extends Abst
assertNotNull(sce);
// 4. claim task from user4, in role 7
- ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
- requestFactory.getAuthScope(), new UsernamePasswordCredentials("user4", "password"));
+ super.setupRestTemplate("user4", ADMIN_PWD);
form = userService.claimForm(form.getTaskId());
assertNotNull(form);
@@ -1823,7 +1816,7 @@ public class UserTestITCase extends Abst
|| connObjectTO.getAttributeMap().get("NAME").getValues().isEmpty());
// ----------------------------------
}
-
+
@Test
public void issueSYNCOPE267() {
// ----------------------------------