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/07 17:47:25 UTC

svn commit: r1429889 - in /syncope/trunk: client/src/main/java/org/apache/syncope/services/ core/src/test/java/org/apache/syncope/core/rest/

Author: jbernhardt
Date: Mon Jan  7 16:47:24 2013
New Revision: 1429889

URL: http://svn.apache.org/viewvc?rev=1429889&view=rev
Log:
[SYNCOPE-259]
Introduces Workflow Service.
Test Case needs to be extended to be of real value!

Added:
    syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowService.java
    syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowServiceProxy.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/WorkflowTestITCase.java
Modified:
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java

Added: syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowService.java?rev=1429889&view=auto
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowService.java (added)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowService.java Mon Jan  7 16:47:24 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+import org.apache.syncope.client.to.WorkflowDefinitionTO;
+
+@Path("workflows")
+public interface WorkflowService {
+
+    @GET
+    @Path("{type}")
+    //    @RequestMapping(method = RequestMethod.GET, value = "/definition/user")
+    //    @RequestMapping(method = RequestMethod.GET, value = "/definition/role")
+    WorkflowDefinitionTO getDefinition(@PathParam("type") final String type);
+
+
+
+    @PUT
+    @Path("{type}")
+//    @RequestMapping(method = RequestMethod.PUT, value = "/definition/user")
+//    @RequestMapping(method = RequestMethod.PUT, value = "/definition/role")
+    void updateDefinition(@PathParam("type") final String type, final WorkflowDefinitionTO definition);
+
+    @GET
+    @Path("{type}/tasks")
+//    @RequestMapping(method = RequestMethod.GET, value = "/tasks/user")
+    List<String> getDefinedTasks(@PathParam("type") final String type);
+}
\ No newline at end of file

Added: syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowServiceProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowServiceProxy.java?rev=1429889&view=auto
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowServiceProxy.java (added)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/services/WorkflowServiceProxy.java Mon Jan  7 16:47:24 2013
@@ -0,0 +1,49 @@
+/*
+ * 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.Arrays;
+import java.util.List;
+
+import org.apache.syncope.client.to.WorkflowDefinitionTO;
+import org.springframework.web.client.RestTemplate;
+
+public class WorkflowServiceProxy extends SpringServiceProxy implements WorkflowService {
+
+    public WorkflowServiceProxy(String baseUrl, RestTemplate restTemplate) {
+        super(baseUrl, restTemplate);
+    }
+
+    @Override
+    public WorkflowDefinitionTO getDefinition(String type) {
+        return restTemplate
+                .getForObject(BASE_URL + "workflow/definition/" + type, WorkflowDefinitionTO.class);
+    }
+
+    @Override
+    public void updateDefinition(String type, WorkflowDefinitionTO definition) {
+        restTemplate.put(BASE_URL + "workflow/definition/" + type, definition);
+    }
+
+    @Override
+    public List<String> getDefinedTasks(final String type) {
+        return Arrays.asList(restTemplate.getForObject(BASE_URL + "workflow/tasks/" + type, String.class));
+    }
+
+}

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=1429889&r1=1429888&r2=1429889&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 Mon Jan  7 16:47:24 2013
@@ -35,6 +35,7 @@ import org.apache.syncope.services.RoleS
 import org.apache.syncope.services.TaskServiceProxy;
 import org.apache.syncope.services.UserServiceProxy;
 import org.apache.syncope.services.PolicyServiceProxy;
+import org.apache.syncope.services.WorkflowServiceProxy;
 import org.junit.Before;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
@@ -45,90 +46,87 @@ import org.springframework.test.context.
 import org.springframework.web.client.RestTemplate;
 
 @RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "classpath:restClientContext.xml",
-		"classpath:testJDBCContext.xml" })
+@ContextConfiguration(locations = { "classpath:restClientContext.xml", "classpath:testJDBCContext.xml" })
 public abstract class AbstractTest {
 
-	protected static AttributeTO attributeTO(final String schema,
-			final String value) {
-		AttributeTO attr = new AttributeTO();
-		attr.setSchema(schema);
-		attr.addValue(value);
-		return attr;
-	}
+    protected static AttributeTO attributeTO(final String schema, final String value) {
+        AttributeTO attr = new AttributeTO();
+        attr.setSchema(schema);
+        attr.addValue(value);
+        return attr;
+    }
 
-	protected static AttributeMod attributeMod(final String schema,
-			final String valueToBeAdded) {
-		AttributeMod attr = new AttributeMod();
-		attr.setSchema(schema);
-		attr.addValueToBeAdded(valueToBeAdded);
-		return attr;
-	}
+    protected static AttributeMod attributeMod(final String schema, final String valueToBeAdded) {
+        AttributeMod attr = new AttributeMod();
+        attr.setSchema(schema);
+        attr.addValueToBeAdded(valueToBeAdded);
+        return attr;
+    }
 
-	/**
-	 * Logger.
-	 */
-	protected static final Logger LOG = LoggerFactory
-			.getLogger(AbstractTest.class);
+    /**
+     * Logger.
+     */
+    protected static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class);
 
-	protected static final String BASE_URL = "http://localhost:9080/syncope/rest/";
+    protected static final String BASE_URL = "http://localhost:9080/syncope/rest/";
 
-	public static final String ADMIN_UID = "admin";
+    public static final String ADMIN_UID = "admin";
 
-	public static final String ADMIN_PWD = "password";
+    public static final String ADMIN_PWD = "password";
 
-	protected PolicyServiceProxy policyService;
+    protected PolicyServiceProxy policyService;
 
-	@Autowired
-	protected RestTemplate restTemplate;
+    @Autowired
+    protected RestTemplate restTemplate;
 
-	protected UserServiceProxy userService;
+    protected UserServiceProxy userService;
 
-	protected RoleServiceProxy roleService;
+    protected RoleServiceProxy roleService;
 
-	protected ResourceServiceProxy resourceService;
+    protected ResourceServiceProxy resourceService;
 
-	protected EntitlementServiceProxy entitlementService;
+    protected EntitlementServiceProxy entitlementService;
 
-	protected ConfigurationServiceProxy configurationService;
+    protected ConfigurationServiceProxy configurationService;
 
-	protected ConnectorServiceProxy connectorService;
+    protected ConnectorServiceProxy connectorService;
 
-	protected LoggerServiceProxy loggerService;
+    protected LoggerServiceProxy loggerService;
 
-	protected ReportServiceProxy reportService;
+    protected ReportServiceProxy reportService;
 
-	protected TaskServiceProxy taskService;
+    protected TaskServiceProxy taskService;
 
-	@Autowired
-	protected DataSource testDataSource;
+    protected WorkflowServiceProxy workflowService;
 
-	protected RestTemplate anonymousRestTemplate() {
-		return new RestTemplate();
-	}
+    @Autowired
+    protected DataSource testDataSource;
 
-	public void setupRestTemplate(final String uid, final String pwd) {
-		PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory) restTemplate
-				.getRequestFactory());
+    protected RestTemplate anonymousRestTemplate() {
+        return new RestTemplate();
+    }
 
-		((DefaultHttpClient) requestFactory.getHttpClient())
-				.getCredentialsProvider().setCredentials(
-						requestFactory.getAuthScope(),
-						new UsernamePasswordCredentials(uid, pwd));
-	}
+    public void setupRestTemplate(final String uid, final String pwd) {
+        PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory) restTemplate
+                .getRequestFactory());
 
-	@Before
-	public void resetRestTemplate() {
-		setupRestTemplate(ADMIN_UID, ADMIN_PWD);
-		userService = new UserServiceProxy(BASE_URL, restTemplate);
-		roleService = new RoleServiceProxy(BASE_URL, restTemplate);
-		resourceService = new ResourceServiceProxy(BASE_URL, restTemplate);
-		entitlementService = new EntitlementServiceProxy(BASE_URL, restTemplate);
-		configurationService = new ConfigurationServiceProxy(BASE_URL, restTemplate);
-		connectorService = new ConnectorServiceProxy(BASE_URL, restTemplate);
-		loggerService = new LoggerServiceProxy(BASE_URL, restTemplate);
-		reportService = new ReportServiceProxy(BASE_URL, restTemplate);
-		taskService = new TaskServiceProxy(BASE_URL, restTemplate);
-		policyService = new PolicyServiceProxy(BASE_URL, restTemplate);
-	}
+        ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
+                requestFactory.getAuthScope(), new UsernamePasswordCredentials(uid, pwd));
+    }
+
+    @Before
+    public void resetRestTemplate() {
+        setupRestTemplate(ADMIN_UID, ADMIN_PWD);
+        userService = new UserServiceProxy(BASE_URL, restTemplate);
+        roleService = new RoleServiceProxy(BASE_URL, restTemplate);
+        resourceService = new ResourceServiceProxy(BASE_URL, restTemplate);
+        entitlementService = new EntitlementServiceProxy(BASE_URL, restTemplate);
+        configurationService = new ConfigurationServiceProxy(BASE_URL, restTemplate);
+        connectorService = new ConnectorServiceProxy(BASE_URL, restTemplate);
+        loggerService = new LoggerServiceProxy(BASE_URL, restTemplate);
+        reportService = new ReportServiceProxy(BASE_URL, restTemplate);
+        taskService = new TaskServiceProxy(BASE_URL, restTemplate);
+        policyService = new PolicyServiceProxy(BASE_URL, restTemplate);
+        workflowService = new WorkflowServiceProxy(BASE_URL, restTemplate);
+    }
 }

Added: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/WorkflowTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/WorkflowTestITCase.java?rev=1429889&view=auto
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/WorkflowTestITCase.java (added)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/WorkflowTestITCase.java Mon Jan  7 16:47:24 2013
@@ -0,0 +1,91 @@
+/*
+ * 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.core.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.syncope.client.to.WorkflowDefinitionTO;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class WorkflowTestITCase extends AbstractTest {
+
+    public static final String ROLE_TYPE = "role";
+
+    public static final String USER_TYPE = "role";
+
+    @Test //TODO TestCase needs to be extended
+    public void testGetUserDefinition() {
+        WorkflowDefinitionTO definition = workflowService.getDefinition(USER_TYPE);
+        assertNotNull(definition);
+    }
+
+    @Test //TODO TestCase needs to be extended
+    public void testGetRoleDefinition() {
+        WorkflowDefinitionTO definition = workflowService.getDefinition(ROLE_TYPE);
+        assertNotNull(definition);
+    }
+
+    @Test
+    @Ignore //TODO TestCase needs to be extended
+    public void testUpdateUserDefinition() {
+        WorkflowDefinitionTO definition = workflowService.getDefinition(USER_TYPE);
+        assertNotNull(definition);
+        String newID = (definition.getId() != null)
+                ? definition.getId() + "1"
+                : "1";
+        definition.setId(newID);
+        workflowService.updateDefinition(USER_TYPE, definition);
+        WorkflowDefinitionTO newDefinition = workflowService.getDefinition(USER_TYPE);
+        assertEquals(newID, newDefinition.getId());
+    }
+
+    @Test
+    @Ignore //TODO TestCase needs to be extended
+    public void testUpdateRoleDefinition() {
+        WorkflowDefinitionTO definition = workflowService.getDefinition(ROLE_TYPE);
+        assertNotNull(definition);
+        String newID = (definition.getId() != null)
+                ? definition.getId() + "1"
+                : "1";
+        definition.setId(newID);
+        workflowService.updateDefinition(ROLE_TYPE, definition);
+        WorkflowDefinitionTO newDefinition = workflowService.getDefinition(ROLE_TYPE);
+        assertEquals(newID, newDefinition.getId());
+    }
+
+    @Test
+    public void testGetUserTasks() {
+        List<String> tasks = workflowService.getDefinedTasks(USER_TYPE);
+        assertNotNull(tasks);
+        assertTrue(tasks.size() > 0);
+    }
+
+    @Test
+    public void testGetRoleTasks() {
+        List<String> tasks = workflowService.getDefinedTasks(ROLE_TYPE);
+        assertNotNull(tasks);
+        assertTrue(tasks.size() > 0);
+    }
+
+}
\ No newline at end of file