Return-Path: X-Original-To: apmail-syncope-commits-archive@www.apache.org Delivered-To: apmail-syncope-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2F818101E6 for ; Thu, 12 Feb 2015 09:14:07 +0000 (UTC) Received: (qmail 40577 invoked by uid 500); 12 Feb 2015 09:14:06 -0000 Delivered-To: apmail-syncope-commits-archive@syncope.apache.org Received: (qmail 40456 invoked by uid 500); 12 Feb 2015 09:14:06 -0000 Mailing-List: contact commits-help@syncope.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@syncope.apache.org Delivered-To: mailing list commits@syncope.apache.org Received: (qmail 40119 invoked by uid 99); 12 Feb 2015 09:14:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Feb 2015 09:14:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 23DEFE0777; Thu, 12 Feb 2015 09:14:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ilgrosso@apache.org To: commits@syncope.apache.org Date: Thu, 12 Feb 2015 09:14:12 -0000 Message-Id: In-Reply-To: <64f969544ff44a74afca1584bc629083@git.apache.org> References: <64f969544ff44a74afca1584bc629083@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/54] [abbrv] [partial] syncope git commit: [SYNCOPE-620] Renaming 'server' after 'core', to provide continuity with older releases (especially for archetype) http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/main/resources/userWorkflow.bpmn20.xml ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/main/resources/userWorkflow.bpmn20.xml b/syncope620/fit/core-reference/src/main/resources/userWorkflow.bpmn20.xml new file mode 100644 index 0000000..d26dbe3 --- /dev/null +++ b/syncope620/fit/core-reference/src/main/resources/userWorkflow.bpmn20.xml @@ -0,0 +1,577 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/main/resources/workflow.properties ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/main/resources/workflow.properties b/syncope620/fit/core-reference/src/main/resources/workflow.properties new file mode 100644 index 0000000..9f0e35e --- /dev/null +++ b/syncope620/fit/core-reference/src/main/resources/workflow.properties @@ -0,0 +1,20 @@ +# 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. +wf.directory=${conf.directory} +jobExecutorActivate=false +uwfAdapter=org.apache.syncope.core.workflow.java.DefaultUserWorkflowAdapter +rwfAdapter=org.apache.syncope.core.workflow.java.DefaultRoleWorkflowAdapter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/main/webapp/WEB-INF/glassfish-web.xml ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/main/webapp/WEB-INF/glassfish-web.xml b/syncope620/fit/core-reference/src/main/webapp/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..ab6a9bf --- /dev/null +++ b/syncope620/fit/core-reference/src/main/webapp/WEB-INF/glassfish-web.xml @@ -0,0 +1,33 @@ + + + + + /syncope + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/main/webapp/WEB-INF/jboss-deployment-structure.xml ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/syncope620/fit/core-reference/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000..f47298d --- /dev/null +++ b/syncope620/fit/core-reference/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/main/webapp/WEB-INF/weblogic.xml ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/main/webapp/WEB-INF/weblogic.xml b/syncope620/fit/core-reference/src/main/webapp/WEB-INF/weblogic.xml new file mode 100644 index 0000000..6eeb9c2 --- /dev/null +++ b/syncope620/fit/core-reference/src/main/webapp/WEB-INF/weblogic.xml @@ -0,0 +1,46 @@ + + + + + syncope + + + + javax.ws.rs.* + javax.validation.* + org.hibernate.validator.* + org.apache.cxf.* + org.apache.commons.* + org.apache.openjpa.* + org.slf4j.* + org.apache.logging.log4j.* + com.fasterxml.jackson.* + + + + + + http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/main/webapp/cacheStats.jsp ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/main/webapp/cacheStats.jsp b/syncope620/fit/core-reference/src/main/webapp/cacheStats.jsp new file mode 100644 index 0000000..4e4bf1b --- /dev/null +++ b/syncope620/fit/core-reference/src/main/webapp/cacheStats.jsp @@ -0,0 +1,190 @@ +<%-- +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. +--%> +<%@page import="org.apache.syncope.common.lib.SyncopeConstants"%> +<%@page import="org.apache.syncope.core.misc.spring.ApplicationContextProvider"%> +<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.util.Date"%> +<%@page import="org.apache.openjpa.datacache.CacheStatisticsImpl"%> +<%@page import="javax.persistence.EntityManagerFactory"%> +<%@page import="org.apache.openjpa.persistence.OpenJPAPersistence"%> +<%@page import="org.apache.openjpa.persistence.OpenJPAEntityManagerFactory"%> +<%@page import="org.springframework.context.ConfigurableApplicationContext"%> +<%@page import="org.apache.openjpa.datacache.QueryKey"%> +<%@page import="org.apache.openjpa.kernel.QueryStatistics"%> +<%@page import="org.apache.openjpa.persistence.QueryResultCacheImpl"%> + + + + + Cache Statistics + + + +

+ <% + ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext(); + + EntityManagerFactory emf = context.getBean(EntityManagerFactory.class); + OpenJPAEntityManagerFactory oemf = OpenJPAPersistence.cast(emf); + + QueryStatistics queryStatistics = + ((QueryResultCacheImpl) oemf.getQueryResultCache()).getDelegate().getStatistics(); + + CacheStatisticsImpl statistics = (CacheStatisticsImpl) oemf.getStoreCache().getStatistics(); + + String action = request.getParameter("do"); + StringBuilder info = new StringBuilder(512); + + if ("activate".equals(action) && !statistics.isEnabled()) { + statistics.enable(); + info.append("Statistics enabled\n"); + } else if ("deactivate".equals(action) && !statistics.isEnabled()) { + statistics.disable(); + info.append("Statistics disabled\n"); + } else if ("clear".equals(action)) { + queryStatistics.reset(); + statistics.reset(); + info.append("Statistics cleared\n"); + } + + SimpleDateFormat sdf = new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN); + if (info.length() > 0) { + %> +

+ +
+ <% }%> +

+ Reload +

+ "> + <%=(statistics.isEnabled() ? "DEACTIVATE" : "ACTIVATE")%> + CLEAR +

+ Last update: <%=sdf.format(statistics.since())%>
+ Activation: <%=sdf.format(statistics.start())%>
+

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Hits<%=statistics.getHitCount()%>
Reads<%=statistics.getReadCount()%>
Writes<%=statistics.getWriteCount()%>
Query Hits<%=queryStatistics.getHitCount()%>
Query Executions<%=queryStatistics.getExecutionCount()%>
Query Evictions<%=queryStatistics.getEvictionCount()%>
+

+ + + + + + + + <% + boolean odd = true; + for (QueryKey key : queryStatistics.keys()) { + %> + "> + + + + + <% + odd = !odd; + } + %> +
Query statistics
QueryHitsExecutions
<%=key%><%=queryStatistics.getHitCount(key)%><%=queryStatistics.getExecutionCount(key)%>
+

+ + + + + + + + + <% + odd = true; + for (String className : statistics.classNames()) { + %> + "> + + + + + + <% + odd = !odd; + } + %> +
2nd level cache statistics
RegionHitsReadsWrites
<%=className%><%=statistics.getHitCount(className)%><%=statistics.getReadCount(className)%><%=statistics.getWriteCount(className)%>
+ + http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/main/webapp/db.jsp ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/main/webapp/db.jsp b/syncope620/fit/core-reference/src/main/webapp/db.jsp new file mode 100644 index 0000000..2a4c6ac --- /dev/null +++ b/syncope620/fit/core-reference/src/main/webapp/db.jsp @@ -0,0 +1,36 @@ +<%-- +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. +--%> +<%@page import="java.sql.SQLException"%> +<%@page import="org.h2.tools.Server"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<% + Server h2Datastore = (Server) getServletConfig().getServletContext().getAttribute("H2_DATASTORE"); + if (h2Datastore == null || !h2Datastore.isRunning(true)) { + try { + h2Datastore = Server.createWebServer("-webPort", "8082"); + h2Datastore.start(); + + getServletConfig().getServletContext().setAttribute("H2_DATASTORE", h2Datastore); + } catch (SQLException e) { + getServletConfig().getServletContext().log("Could not start H2 web console (datastore)", e); + } + + response.sendRedirect("http://localhost:8082"); + } +%> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractITCase.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractITCase.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractITCase.java new file mode 100644 index 0000000..0f0560a --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractITCase.java @@ -0,0 +1,388 @@ +/* + * 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.fit.core.reference; + +import static org.junit.Assert.assertNotNull; + +import java.io.InputStream; +import java.net.URI; +import java.util.Hashtable; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.directory.InitialDirContext; +import javax.sql.DataSource; +import javax.ws.rs.core.Response; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.client.lib.SyncopeClientFactoryBean; +import org.apache.syncope.common.lib.mod.AttrMod; +import org.apache.syncope.common.lib.mod.RoleMod; +import org.apache.syncope.common.lib.mod.UserMod; +import org.apache.syncope.common.lib.to.AbstractPolicyTO; +import org.apache.syncope.common.lib.to.AbstractSchemaTO; +import org.apache.syncope.common.lib.to.AttrTO; +import org.apache.syncope.common.lib.to.ResourceTO; +import org.apache.syncope.common.lib.to.RoleTO; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.syncope.common.lib.types.ConnConfProperty; +import org.apache.syncope.common.lib.types.SchemaType; +import org.apache.syncope.common.rest.api.RESTHeaders; +import org.apache.syncope.common.rest.api.service.CamelRouteService; +import org.apache.syncope.common.rest.api.service.ConfigurationService; +import org.apache.syncope.common.rest.api.service.ConnectorService; +import org.apache.syncope.common.rest.api.service.EntitlementService; +import org.apache.syncope.common.rest.api.service.LoggerService; +import org.apache.syncope.common.rest.api.service.NotificationService; +import org.apache.syncope.common.rest.api.service.PolicyService; +import org.apache.syncope.common.rest.api.service.ReportService; +import org.apache.syncope.common.rest.api.service.ResourceService; +import org.apache.syncope.common.rest.api.service.RoleService; +import org.apache.syncope.common.rest.api.service.SchemaService; +import org.apache.syncope.common.rest.api.service.SecurityQuestionService; +import org.apache.syncope.common.rest.api.service.SyncopeService; +import org.apache.syncope.common.rest.api.service.TaskService; +import org.apache.syncope.common.rest.api.service.UserSelfService; +import org.apache.syncope.common.rest.api.service.UserService; +import org.apache.syncope.common.rest.api.service.UserWorkflowService; +import org.apache.syncope.common.rest.api.service.WorkflowService; +import org.identityconnectors.common.security.Encryptor; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "classpath:testJDBCContext.xml" }) +public abstract class AbstractITCase { + + /** + * Logger. + */ + protected static final Logger LOG = LoggerFactory.getLogger(AbstractITCase.class); + + protected static final String ADMIN_UNAME = "admin"; + + protected static final String ADMIN_PWD = "password"; + + private static final String ADDRESS = "http://localhost:9080/syncope/rest"; + + private static final String ENV_KEY_CONTENT_TYPE = "jaxrsContentType"; + + protected static final SyncopeClientFactoryBean clientFactory = new SyncopeClientFactoryBean().setAddress(ADDRESS); + + protected static final String RESOURCE_NAME_WS1 = "ws-target-resource-1"; + + protected static final String RESOURCE_NAME_WS2 = "ws-target-resource-2"; + + protected static final String RESOURCE_NAME_LDAP = "resource-ldap"; + + protected static final String RESOURCE_NAME_TESTDB = "resource-testdb"; + + protected static final String RESOURCE_NAME_TESTDB2 = "resource-testdb2"; + + protected static final String RESOURCE_NAME_CSV = "resource-csv"; + + protected static final String RESOURCE_NAME_DBSYNC = "resource-db-sync"; + + protected static final String RESOURCE_NAME_DBVIRATTR = "resource-db-virattr"; + + protected static final String RESOURCE_NAME_NOPROPAGATION = "ws-target-resource-nopropagation"; + + protected static final String RESOURCE_NAME_NOPROPAGATION2 = "ws-target-resource-nopropagation2"; + + protected static final String RESOURCE_NAME_NOPROPAGATION3 = "ws-target-resource-nopropagation3"; + + protected static final String RESOURCE_NAME_NOPROPAGATION4 = "ws-target-resource-nopropagation4"; + + protected static final String RESOURCE_NAME_RESETSYNCTOKEN = "ws-target-resource-update-resetsynctoken"; + + protected static final String RESOURCE_NAME_TIMEOUT = "ws-target-resource-timeout"; + + protected static final String RESOURCE_NAME_MAPPINGS1 = "ws-target-resource-list-mappings-1"; + + protected static final String RESOURCE_NAME_MAPPINGS2 = "ws-target-resource-list-mappings-2"; + + protected static final String RESOURCE_NAME_CREATE = "ws-target-resource-create"; + + protected static final String RESOURCE_NAME_CREATE_SINGLE = "ws-target-resource-create-single"; + + protected static final String RESOURCE_NAME_CREATE_WRONG = "ws-target-resource-create-wrong"; + + protected static final String RESOURCE_NAME_DELETE = "ws-target-resource-delete"; + + protected static final String RESOURCE_NAME_UPDATE = "ws-target-resource-update"; + + protected static final String RESOURCE_NAME_CREATE_NONE = "ws-target-resource-create-none"; + + protected static String ANONYMOUS_UNAME; + + protected static String ANONYMOUS_KEY; + + protected static SyncopeClient adminClient; + + protected static SyncopeService syncopeService; + + protected static UserService userService; + + protected static UserSelfService userSelfService; + + protected static UserWorkflowService userWorkflowService; + + protected static RoleService roleService; + + protected static ResourceService resourceService; + + protected static EntitlementService entitlementService; + + protected static ConfigurationService configurationService; + + protected static ConnectorService connectorService; + + protected static LoggerService loggerService; + + protected static ReportService reportService; + + protected static TaskService taskService; + + protected static WorkflowService workflowService; + + protected static NotificationService notificationService; + + protected static SchemaService schemaService; + + protected static PolicyService policyService; + + protected static SecurityQuestionService securityQuestionService; + + protected static CamelRouteService camelRouteService; + + @Autowired + protected DataSource testDataSource; + + @BeforeClass + public static void securitySetup() { + InputStream propStream = null; + try { + propStream = Encryptor.class.getResourceAsStream("/security.properties"); + Properties props = new Properties(); + props.load(propStream); + + ANONYMOUS_UNAME = props.getProperty("anonymousUser"); + ANONYMOUS_KEY = props.getProperty("anonymousKey"); + } catch (Exception e) { + LOG.error("Could not read secretKey", e); + } finally { + IOUtils.closeQuietly(propStream); + } + + assertNotNull(ANONYMOUS_UNAME); + assertNotNull(ANONYMOUS_KEY); + } + + @BeforeClass + public static void restSetup() { + final String envContentType = System.getProperty(ENV_KEY_CONTENT_TYPE); + if (StringUtils.isNotBlank(envContentType)) { + clientFactory.setContentType(envContentType); + } + LOG.info("Performing IT with content type {}", clientFactory.getContentType().getMediaType()); + + adminClient = clientFactory.create(ADMIN_UNAME, ADMIN_PWD); + + syncopeService = adminClient.getService(SyncopeService.class); + userService = adminClient.getService(UserService.class); + userSelfService = adminClient.getService(UserSelfService.class); + userWorkflowService = adminClient.getService(UserWorkflowService.class); + roleService = adminClient.getService(RoleService.class); + resourceService = adminClient.getService(ResourceService.class); + entitlementService = adminClient.getService(EntitlementService.class); + configurationService = adminClient.getService(ConfigurationService.class); + connectorService = adminClient.getService(ConnectorService.class); + loggerService = adminClient.getService(LoggerService.class); + reportService = adminClient.getService(ReportService.class); + taskService = adminClient.getService(TaskService.class); + policyService = adminClient.getService(PolicyService.class); + workflowService = adminClient.getService(WorkflowService.class); + notificationService = adminClient.getService(NotificationService.class); + schemaService = adminClient.getService(SchemaService.class); + securityQuestionService = adminClient.getService(SecurityQuestionService.class); + camelRouteService = adminClient.getService(CamelRouteService.class); + } + + protected static String getUUIDString() { + return UUID.randomUUID().toString().substring(0, 8); + } + + protected static AttrTO attrTO(final String schema, final String value) { + AttrTO attr = new AttrTO(); + attr.setSchema(schema); + attr.getValues().add(value); + return attr; + } + + protected static AttrMod attrMod(final String schema, final String valueToBeAdded) { + AttrMod attr = new AttrMod(); + attr.setSchema(schema); + attr.getValuesToBeAdded().add(valueToBeAdded); + return attr; + } + + protected UserTO createUser(final UserTO userTO) { + return createUser(userTO, true); + } + + protected UserTO createUser(final UserTO userTO, final boolean storePassword) { + Response response = userService.create(userTO, storePassword); + if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) { + Exception ex = clientFactory.getExceptionMapper().fromResponse(response); + if (ex != null) { + throw (RuntimeException) ex; + } + } + return response.readEntity(UserTO.class); + } + + protected UserTO readUser(final String username) { + return userService.read(Long.valueOf( + userService.getUserId(username).getHeaderString(RESTHeaders.USER_ID))); + } + + protected UserTO updateUser(final UserMod userMod) { + return userService.update(userMod.getKey(), userMod).readEntity(UserTO.class); + } + + protected UserTO deleteUser(final Long id) { + return userService.delete(id).readEntity(UserTO.class); + } + + public T getObject(final URI location, final Class serviceClass, final Class resultClass) { + WebClient webClient = WebClient.fromClient(WebClient.client(adminClient.getService(serviceClass))); + webClient.accept(clientFactory.getContentType().getMediaType()).to(location.toASCIIString(), false); + + return webClient.get(resultClass); + } + + @SuppressWarnings("unchecked") + protected T createSchema(final AttributableType kind, + final SchemaType type, final T schemaTO) { + + Response response = schemaService.create(kind, type, schemaTO); + if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) { + Exception ex = clientFactory.getExceptionMapper().fromResponse(response); + if (ex != null) { + throw (RuntimeException) ex; + } + } + + return (T) getObject(response.getLocation(), SchemaService.class, schemaTO.getClass()); + } + + protected RoleTO createRole(final RoleTO newRoleTO) { + Response response = roleService.create(newRoleTO); + if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) { + Exception ex = clientFactory.getExceptionMapper().fromResponse(response); + if (ex != null) { + throw (RuntimeException) ex; + } + } + return getObject(response.getLocation(), RoleService.class, RoleTO.class); + } + + protected RoleTO updateRole(final RoleMod roleMod) { + return roleService.update(roleMod.getKey(), roleMod).readEntity(RoleTO.class); + } + + protected RoleTO deleteRole(final Long id) { + return roleService.delete(id).readEntity(RoleTO.class); + } + + @SuppressWarnings("unchecked") + protected T createPolicy(final T policy) { + Response response = policyService.create(policy); + if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) { + Exception ex = clientFactory.getExceptionMapper().fromResponse(response); + if (ex != null) { + throw (RuntimeException) ex; + } + } + return (T) getObject(response.getLocation(), PolicyService.class, policy.getClass()); + } + + protected ResourceTO createResource(final ResourceTO resourceTO) { + Response response = resourceService.create(resourceTO); + if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) { + Exception ex = clientFactory.getExceptionMapper().fromResponse(response); + if (ex != null) { + throw (RuntimeException) ex; + } + } + return getObject(response.getLocation(), ResourceService.class, ResourceTO.class); + } + + @SuppressWarnings({ "unchecked", "rawtypes", "UseOfObsoleteCollectionType" }) + protected InitialDirContext getLdapResourceDirContext(final String bindDn, final String bindPwd) + throws NamingException { + ResourceTO ldapRes = resourceService.read(RESOURCE_NAME_LDAP); + final Map ldapConnConf = + connectorService.read(ldapRes.getConnectorId()).getConfigurationMap(); + + Hashtable env = new Hashtable(); + env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); + env.put(Context.PROVIDER_URL, "ldap://" + ldapConnConf.get("host").getValues().get(0) + + ":" + ldapConnConf.get("port").getValues().get(0) + "/"); + env.put(Context.SECURITY_AUTHENTICATION, "simple"); + env.put(Context.SECURITY_PRINCIPAL, + bindDn == null ? ldapConnConf.get("principal").getValues().get(0) : bindDn); + env.put(Context.SECURITY_CREDENTIALS, + bindPwd == null ? ldapConnConf.get("credentials").getValues().get(0) : bindPwd); + + return new InitialDirContext(env); + } + + protected Object getLdapRemoteObject(final String bindDn, final String bindPwd, final String objectDn) { + InitialDirContext ctx = null; + try { + ctx = getLdapResourceDirContext(bindDn, bindPwd); + return ctx.lookup(objectDn); + } catch (Exception e) { + return null; + } finally { + if (ctx != null) { + try { + ctx.close(); + } catch (NamingException e) { + // ignore + } + } + } + } + + protected Object getLdapRemoteObject(final String objectDn) { + return getLdapRemoteObject(null, null, objectDn); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractTaskITCase.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractTaskITCase.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractTaskITCase.java new file mode 100644 index 0000000..6ba1dd8 --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractTaskITCase.java @@ -0,0 +1,137 @@ +/* + * 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.fit.core.reference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.apache.syncope.common.lib.to.AbstractTaskTO; +import org.apache.syncope.common.lib.to.TaskExecTO; +import org.apache.syncope.common.lib.to.UserTO; + +public abstract class AbstractTaskITCase extends AbstractITCase { + + protected static final Long SYNC_TASK_ID = 4L; + + protected static final Long SCHED_TASK_ID = 5L; + + protected static class ThreadExec implements Callable { + + private final AbstractTaskITCase test; + + private final Long taskKey; + + private final int maxWaitSeconds; + + private final boolean dryRun; + + public ThreadExec(AbstractTaskITCase test, Long taskKey, int maxWaitSeconds, boolean dryRun) { + this.test = test; + this.taskKey = taskKey; + this.maxWaitSeconds = maxWaitSeconds; + this.dryRun = dryRun; + } + + @Override + public TaskExecTO call() throws Exception { + return test.execSyncTask(taskKey, maxWaitSeconds, dryRun); + } + } + + /** + * Remove initial and synchronized users to make test re-runnable. + */ + protected void removeTestUsers() { + for (int i = 0; i < 10; i++) { + String cUserName = "test" + i; + try { + UserTO cUserTO = readUser(cUserName); + userService.delete(cUserTO.getKey()); + } catch (Exception e) { + // Ignore + } + } + } + + protected TaskExecTO execSyncTask(final Long taskKey, final int maxWaitSeconds, final boolean dryRun) { + AbstractTaskTO taskTO = taskService.read(taskKey); + assertNotNull(taskTO); + assertNotNull(taskTO.getExecutions()); + + int preSyncSize = taskTO.getExecutions().size(); + TaskExecTO execution = taskService.execute(taskTO.getKey(), dryRun); + assertEquals("JOB_FIRED", execution.getStatus()); + + int i = 0; + int maxit = maxWaitSeconds; + + // wait for sync completion (executions incremented) + do { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + + taskTO = taskService.read(taskTO.getKey()); + + assertNotNull(taskTO); + assertNotNull(taskTO.getExecutions()); + + i++; + } while (preSyncSize == taskTO.getExecutions().size() && i < maxit); + if (i == maxit) { + fail("Timeout when executing task " + taskKey); + } + return taskTO.getExecutions().get(taskTO.getExecutions().size() - 1); + } + + protected Map execSyncTasks( + final Set taskKeys, final int maxWaitSeconds, final boolean dryRun) throws Exception { + + final ExecutorService service = Executors.newFixedThreadPool(taskKeys.size()); + final List> futures = new ArrayList<>(); + + for (Long key : taskKeys) { + futures.add(service.submit(new ThreadExec(this, key, maxWaitSeconds, dryRun))); + } + + final Map res = new HashMap<>(); + + for (Future future : futures) { + TaskExecTO taskExecTO = future.get(100, TimeUnit.SECONDS); + res.put(taskExecTO.getTask(), taskExecTO); + } + + service.shutdownNow(); + + return res; + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ActivitiDetector.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ActivitiDetector.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ActivitiDetector.java new file mode 100644 index 0000000..f697c19 --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ActivitiDetector.java @@ -0,0 +1,32 @@ +/* + * 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.fit.core.reference; + +import org.apache.syncope.common.rest.api.service.SyncopeService; + +public class ActivitiDetector { + + public static boolean isActivitiEnabledForUsers(final SyncopeService syncopeService) { + return syncopeService.info().getUserWorkflowAdapter().indexOf("Activiti") != -1; + } + + public static boolean isActivitiEnabledForRoles(final SyncopeService syncopeService) { + return syncopeService.info().getRoleWorkflowAdapter().indexOf("Activiti") != -1; + } +}