syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/8] syncope git commit: [SYNCOPE-627] adding Camel integration test
Date Thu, 15 Jan 2015 14:27:00 GMT
Repository: syncope
Updated Branches:
  refs/heads/1_2_X 970c0d0ed -> 9ceb71a33
  refs/heads/2_0_X b015c443b -> 3dc03b231
  refs/heads/master 5e1fe6108 -> 7570a5fc8


[SYNCOPE-627] adding Camel integration test


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/f7554cad
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/f7554cad
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/f7554cad

Branch: refs/heads/2_0_X
Commit: f7554cadd5e80c379158aa9a291f2a978267c9ab
Parents: 25bb5c9
Author: giacomolm <giacomolm@hotmail.it>
Authored: Mon Jan 12 17:06:33 2015 +0100
Committer: giacomolm <giacomolm@hotmail.it>
Committed: Mon Jan 12 17:06:33 2015 +0100

----------------------------------------------------------------------
 core/pom.xml                                    |   4 +
 .../apache/syncope/core/rest/AbstractTest.java  |   4 +
 .../syncope/core/rest/CamelTestITCase.java      | 161 +++++++++++++++++++
 pom.xml                                         |   9 +-
 4 files changed, 176 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/f7554cad/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index 1628184..f2cfbb7 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -127,6 +127,10 @@ under the License.
       <artifactId>camel-spring</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-script</artifactId>
+    </dependency>    
+    <dependency>
       <groupId>javax.xml.bind</groupId>
       <artifactId>jaxb-api</artifactId>
       <version>2.2.7</version>

http://git-wip-us.apache.org/repos/asf/syncope/blob/f7554cad/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java b/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
index 785734d..13cc27b 100644
--- a/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
+++ b/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
@@ -47,6 +47,7 @@ import org.apache.syncope.common.services.PolicyService;
 import org.apache.syncope.common.services.ReportService;
 import org.apache.syncope.common.services.ResourceService;
 import org.apache.syncope.common.services.RoleService;
+import org.apache.syncope.common.services.RouteService;
 import org.apache.syncope.common.services.SchemaService;
 import org.apache.syncope.common.services.SecurityQuestionService;
 import org.apache.syncope.common.services.TaskService;
@@ -173,6 +174,8 @@ public abstract class AbstractTest {
     protected static PolicyService policyService;
 
     protected static SecurityQuestionService securityQuestionService;
+    
+    protected static RouteService routeService;
 
     @Autowired
     protected DataSource testDataSource;
@@ -223,6 +226,7 @@ public abstract class AbstractTest {
         notificationService = adminClient.getService(NotificationService.class);
         schemaService = adminClient.getService(SchemaService.class);
         securityQuestionService = adminClient.getService(SecurityQuestionService.class);
+        routeService = adminClient.getService(RouteService.class);
     }
 
     protected static String getUUIDString() {

http://git-wip-us.apache.org/repos/asf/syncope/blob/f7554cad/core/src/test/java/org/apache/syncope/core/rest/CamelTestITCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/rest/CamelTestITCase.java b/core/src/test/java/org/apache/syncope/core/rest/CamelTestITCase.java
new file mode 100644
index 0000000..57e010c
--- /dev/null
+++ b/core/src/test/java/org/apache/syncope/core/rest/CamelTestITCase.java
@@ -0,0 +1,161 @@
+/*
+ * 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.apache.syncope.core.rest.AbstractTest.adminClient;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+import org.apache.syncope.common.to.RouteTO;
+import org.apache.syncope.common.to.SchemaTO;
+import org.apache.syncope.common.to.UserTO;
+import org.apache.syncope.common.types.AttributableType;
+import org.apache.syncope.common.types.AttributeSchemaType;
+import org.apache.syncope.common.types.SchemaType;
+import org.apache.syncope.common.types.SubjectType;
+import org.apache.syncope.core.provisioning.camel.CamelDetector;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class CamelTestITCase extends AbstractTest{
+    
+    @Test
+    public void isCamelEnabled(){
+        assertEquals(CamelDetector.isCamelEnabledForUsers(),
+                adminClient.isCamelEnabledFor(SubjectType.USER));
+        
+        assertEquals(CamelDetector.isCamelEnabledForRoles(),
+                adminClient.isCamelEnabledFor(SubjectType.ROLE));
+    }
+    
+    @Test
+    public void userRoutes() {
+        List<RouteTO> userRoutes = routeService.getRoutes(SubjectType.USER);
+        Assert.assertNotNull(userRoutes);
+        Assert.assertEquals(15, userRoutes.size());
+        for(int i=0; i<userRoutes.size(); i++){
+            Assert.assertNotNull(userRoutes.get(i).getRouteContent());
+        }
+    }
+    
+    @Test
+    public void roleRoutes() {
+        List<RouteTO> roleRoutes = routeService.getRoutes(SubjectType.ROLE);
+        Assert.assertNotNull(roleRoutes);
+        Assert.assertEquals(7, roleRoutes.size());
+        for(int i=0; i<roleRoutes.size(); i++){
+            Assert.assertNotNull(roleRoutes.get(i).getRouteContent());
+        }
+    }
+   
+    
+    public RouteTO updateRoute(Long id, String content){
+        RouteTO route = routeService.getRoute(SubjectType.USER, id);
+        route.setRouteContent(content);
+        routeService.importRoute(SubjectType.USER, route.getId(), route);
+        //getting new route definition
+        return routeService.getRoute(SubjectType.USER, id);        
+    }
+    
+    @Test
+    public void updateRoute(){
+        RouteTO oldRoute = routeService.getRoute(SubjectType.USER, new Long(0));
+        String routeContent =   "<route id=\"createUser\">\n" +
+                                "  <from uri=\"direct:createUser\"/>\n" +
+                                "  <setProperty propertyName=\"actual\">\n" +
+                                "    <simple>${body}</simple>\n" +
+                                "  </setProperty>\n" +
+                                "  <doTry>\n" +
+                                "    <bean ref=\"uwfAdapter\" method=\"create(${body},${property.disablePwdPolicyCheck},\n"
+
+                                "                             ${property.enabled},${property.storePassword})\"/>\n"
+
+                                "    <process ref=\"defaultUserCreatePropagation\" />\n"
+
+                                "    <to uri=\"direct:createPort\"/>\n" +
+                                "    <to uri=\"log:myLog\"/>\n" +
+                                "    <doCatch>        \n" +
+                                "      <exception>java.lang.RuntimeException</exception>\n"
+
+                                "      <handled>\n" +
+                                "        <constant>false</constant>\n" +
+                                "      </handled>\n" +
+                                "      <to uri=\"direct:createPort\"/>\n" +
+                                "    </doCatch>\n" +
+                                "  </doTry>\n" +
+                                "</route>";
+        RouteTO route =  updateRoute(new Long(0), routeContent);
+        assertEquals(routeContent, route.getRouteContent());
+        
+        updateRoute(oldRoute.getId(), oldRoute.getRouteContent());
+    }
+    
+    @Test
+    public void checkRouteUpdate(){
+        //Getting original route content
+        RouteTO oldRoute = routeService.getRoute(SubjectType.USER, new Long(0));
+        //updating route content including new attribute management
+        String routeContent =   "<route id=\"createUser\">\n" +
+                                "  <from uri=\"direct:createUser\"/>\n" +
+                                "  <setProperty propertyName=\"actual\">\n" +
+                                "    <simple>${body}</simple>\n" +
+                                "  </setProperty>\n" +                            
   
+                                "  <setBody>\n"+
+                                "   <groovy>\n"+
+                                "       request.body.getAttrs().get(3).getValues().set(0,\"true\")\n"+
+                                "       return request.body\n"+
+                                "   </groovy>\n"+
+                                "  </setBody>\n"+
+                                "  <doTry>\n" +
+                                "      <bean ref=\"uwfAdapter\" method=\"create(${body},${property.disablePwdPolicyCheck},\n"
+
+                                "                            ${property.enabled},${property.storePassword})\"/>\n"
+
+                                "      <process ref=\"defaultUserCreatePropagation\" />\n"
+
+                                "      <to uri=\"direct:createPort\"/>\n" +
+                                "      <doCatch>        \n" +
+                                "      <exception>java.lang.RuntimeException</exception>\n"
+
+                                "          <handled>\n" +
+                                "           <constant>false</constant>\n" +
+                                "          </handled>\n" +
+                                "      <to uri=\"direct:createPort\"/>\n" +
+                                "      </doCatch>\n" +
+                                "   </doTry>\n" +                                
+                                "</route>";
+        updateRoute(new Long(0), routeContent);
+        //creating new schema attribute for user
+        SchemaTO schemaTO = new SchemaTO();
+        schemaTO.setName("camelAttribute");
+        schemaTO.setType(AttributeSchemaType.String);       
+        createSchema(AttributableType.USER, SchemaType.NORMAL, schemaTO);
+        
+        UserTO userTO = new UserTO();
+        String userId = getUUIDString() + "camelUser@syncope.apache.org";
+        userTO.setUsername(userId);
+        userTO.setPassword("password");
+        userTO.getAttrs().add(attributeTO("userId", userId));
+        userTO.getAttrs().add(attributeTO("fullname", userId));
+        userTO.getAttrs().add(attributeTO("surname", userId));
+        userTO.getAttrs().add(attributeTO("camelAttribute", "false"));
+
+        userTO = createUser(userTO);        
+        Assert.assertNotNull(userTO);
+        assertEquals("true",userTO.getAttrs().get(3).getValues().get(0));
+        
+        updateRoute(oldRoute.getId(), oldRoute.getRouteContent());
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/f7554cad/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 772fa35..bb2ac10 100644
--- a/pom.xml
+++ b/pom.xml
@@ -726,8 +726,13 @@ under the License.
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
-       <artifactId>camel-spring</artifactId>
-       <version>${camel.version}</version>
+        <artifactId>camel-spring</artifactId>
+        <version>${camel.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-script</artifactId>
+        <version>${camel.version}</version>
       </dependency>
       <!-- /Camel -->
 


Mime
View raw message