Repository: syncope
Updated Branches:
  refs/heads/master e6e2a4718 -> 986f2085d


[SYNCOPE-727] Adjusting test execution


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

Branch: refs/heads/master
Commit: 986f2085d36a272737d852912456e2cb97356191
Parents: e6e2a47
Author: Francesco Chicchiriccò <[email protected]>
Authored: Fri Nov 20 15:36:22 2015 +0100
Committer: Francesco Chicchiriccò <[email protected]>
Committed: Fri Nov 20 15:44:07 2015 +0100

----------------------------------------------------------------------
 fit/core-reference/pom.xml                      |  27 +---
 .../syncope/fit/core/reference/CLIITCase.java   | 133 +++++++++++--------
 .../src/test/resources/cli-test.properties      |  17 +++
 .../src/test/resources/log4j2.xml               | 133 -------------------
 4 files changed, 97 insertions(+), 213 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/986f2085/fit/core-reference/pom.xml
----------------------------------------------------------------------
diff --git a/fit/core-reference/pom.xml b/fit/core-reference/pom.xml
index fb98efe..223c611 100644
--- a/fit/core-reference/pom.xml
+++ b/fit/core-reference/pom.xml
@@ -38,7 +38,7 @@ under the License.
     <jdbcdriver.artifactId>h2</jdbcdriver.artifactId>
     
     <rootpom.basedir>${basedir}/../..</rootpom.basedir>
-    <work.dir>${project.build.directory}/cli-test</work.dir>
+    <cli-test.dir>${project.build.directory}/cli-test</cli-test.dir>
   </properties>
 
   <dependencies>
@@ -153,26 +153,6 @@ under the License.
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-antrun-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>cli-test</id>
-            <goals>
-              <goal>run</goal>
-            </goals>
-            <phase>pre-integration-test</phase>
-            <configuration>
-              <target>
-                <mkdir dir="${work.dir}" />
-                <unzip 
src="../../client/cli/target/syncope-client-cli-${project.version}.zip" 
dest="${work.dir}"/>
-              </target>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-      
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-war-plugin</artifactId>
         <inherited>true</inherited>
         <configuration>
@@ -201,11 +181,14 @@ under the License.
         <inherited>true</inherited>
         <executions>
           <execution>
-            <id>setupCSV</id>
+            <id>setupCSV_CLI</id>
             <phase>pre-integration-test</phase>
             <configuration>
               <target>
                 <copy file="${project.build.directory}/test-classes/test.csv" 
todir="${test.csvdir.path}" overwrite="true"/>
+
+                <mkdir dir="${cli-test.dir}"/>
+                <unzip 
src="${basedir}/../../client/cli/target/syncope-client-cli-${project.version}.zip"
 dest="${cli-test.dir}"/>
               </target>
             </configuration>
             <goals>

http://git-wip-us.apache.org/repos/asf/syncope/blob/986f2085/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/CLIITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/CLIITCase.java
 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/CLIITCase.java
index 1f9c752..f2cbf11 100644
--- 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/CLIITCase.java
+++ 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/CLIITCase.java
@@ -22,11 +22,16 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.Predicate;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.SystemUtils;
 import org.junit.BeforeClass;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
@@ -35,93 +40,105 @@ import org.junit.runners.MethodSorters;
 @FixMethodOrder(MethodSorters.JVM)
 public class CLIITCase extends AbstractITCase {
 
-    private static final String LINUX_SCRIPT_DIR = 
"/target/cli-test/syncope-client-cli-2.0.0-SNAPSHOT";
+    private static final String SCRIPT_FILENAME = "syncopeadm";
 
-    private static final String LINUX_SCRIPT_FILENAME = "syncopeadm.sh";
-
-    private static ProcessBuilder processBuilder;
+    private static ProcessBuilder PROCESS_BUILDER;
 
     @BeforeClass
     public static void install() {
+        Properties props = new Properties();
+        InputStream propStream = null;
         try {
-            final File f = new File(".");
-            final File buildDirectory = new File(f.getCanonicalPath() + 
LINUX_SCRIPT_DIR);
-            processBuilder = new ProcessBuilder();
-            processBuilder.directory(buildDirectory);
-            final String[] command = {"/bin/bash", LINUX_SCRIPT_FILENAME, 
"install", "--setup-debug"};
-            processBuilder.command(command);
-            final Process process = processBuilder.start();
+            propStream = 
ExceptionMapperITCase.class.getResourceAsStream("/cli-test.properties");
+            props.load(propStream);
+
+            File workDir = new File(props.getProperty("cli-work.dir"));
+            PROCESS_BUILDER = new ProcessBuilder();
+            PROCESS_BUILDER.directory(workDir);
+
+            PROCESS_BUILDER.command(getCommand("install", "--setup-debug"));
+            Process process = PROCESS_BUILDER.start();
             process.waitFor();
-            final File cliPropertiesFile = new File(buildDirectory + 
"/cli.properties");
+
+            File cliPropertiesFile = new File(workDir + File.separator + 
"cli.properties");
             assertTrue(cliPropertiesFile.exists());
-        } catch (final IOException | InterruptedException ex) {
-            fail(ex.getMessage());
+        } catch (IOException | InterruptedException e) {
+            fail(e.getMessage());
+        } finally {
+            IOUtils.closeQuietly(propStream);
+        }
+    }
+
+    private static String[] getCommand(final String... arguments) {
+        List<String> command = new ArrayList<>();
+
+        if (SystemUtils.IS_OS_WINDOWS) {
+            command.add("cmd");
+            command.add(SCRIPT_FILENAME + ".bat");
+        } else {
+            command.add("/bin/bash");
+            command.add(SCRIPT_FILENAME + ".sh");
         }
+
+        CollectionUtils.addAll(command, arguments);
+
+        return command.toArray(new String[command.size()]);
     }
 
     @Test
     public void runScriptWithoutOptions() {
         try {
-            final String[] command = {"/bin/bash", LINUX_SCRIPT_FILENAME};
-            processBuilder.command(command);
-            final Process process = processBuilder.start();
-            final String result = readScriptOutput(process.getInputStream());
+            PROCESS_BUILDER.command(getCommand());
+            Process process = PROCESS_BUILDER.start();
+
+            String result = IOUtils.toString(process.getInputStream());
             assertTrue(result.startsWith("\nUsage: Main [options]"));
             assertTrue(result.contains("entitlement --help"));
             assertTrue(result.contains("group --help"));
+
             process.destroy();
-        } catch (IOException ex) {
-            fail(ex.getMessage());
+        } catch (IOException e) {
+            fail(e.getMessage());
         }
     }
 
     @Test
     public void entitlementCount() {
         try {
-            final String[] command = {"/bin/bash", LINUX_SCRIPT_FILENAME, 
"entitlement", "--list"};
-            processBuilder.command(command);
-            final Process process = processBuilder.start();
-            final BufferedReader br = new BufferedReader(new 
InputStreamReader(process.getInputStream()));
-            int entitlementsNumber = 0;
-            String line;
-            while ((line = br.readLine()) != null) {
-                if (line.startsWith("-")) {
-                    entitlementsNumber++;
+            PROCESS_BUILDER.command(getCommand("entitlement", "--list"));
+            Process process = PROCESS_BUILDER.start();
+
+            int entitlements = 
CollectionUtils.countMatches(IOUtils.readLines(process.getInputStream()),
+                    new Predicate<String>() {
+
+                @Override
+                public boolean evaluate(final String line) {
+                    return line.startsWith("-");
                 }
-            }
-            assertEquals(112, entitlementsNumber);
-        } catch (IOException ex) {
-            fail(ex.getMessage());
+            });
+            assertEquals(syncopeService.info().getEntitlements().size(), 
entitlements);
+        } catch (IOException e) {
+            fail(e.getMessage());
         }
     }
 
     @Test
     public void connectorCount() {
         try {
-            final String[] command = {"/bin/bash", LINUX_SCRIPT_FILENAME, 
"connector", "--list-bundles"};
-            processBuilder.command(command);
-            final Process process = processBuilder.start();
-            final BufferedReader br = new BufferedReader(new 
InputStreamReader(process.getInputStream()));
-            int bundlesNumber = 0;
-            String line;
-            while ((line = br.readLine()) != null) {
-                if (line.startsWith(" > BUNDLE NAME:")) {
-                    bundlesNumber++;
-                }
-            }
-            assertEquals(8, bundlesNumber);
-        } catch (IOException ex) {
-            fail(ex.getMessage());
-        }
-    }
+            PROCESS_BUILDER.command(getCommand("connector", "--list-bundles"));
+            Process process = PROCESS_BUILDER.start();
 
-    private static String readScriptOutput(final InputStream inputStream) 
throws IOException {
-        final BufferedReader br = new BufferedReader(new 
InputStreamReader(inputStream));
-        final StringBuilder resultBuilder = new StringBuilder();
-        String line;
-        while ((line = br.readLine()) != null) {
-            resultBuilder.append(line).append("\n");
+            int bundles = 
CollectionUtils.countMatches(IOUtils.readLines(process.getInputStream()),
+                    new Predicate<String>() {
+
+                @Override
+                public boolean evaluate(final String line) {
+                    return line.startsWith(" > BUNDLE NAME:");
+                }
+            });
+            assertEquals(connectorService.getBundles(null).size(), bundles);
+        } catch (IOException e) {
+            fail(e.getMessage());
         }
-        return resultBuilder.toString();
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/986f2085/fit/core-reference/src/test/resources/cli-test.properties
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/resources/cli-test.properties 
b/fit/core-reference/src/test/resources/cli-test.properties
new file mode 100644
index 0000000..3cc61fc
--- /dev/null
+++ b/fit/core-reference/src/test/resources/cli-test.properties
@@ -0,0 +1,17 @@
+# 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.
+cli-work.dir=${cli-test.dir}/syncope-client-cli-${project.version}

http://git-wip-us.apache.org/repos/asf/syncope/blob/986f2085/fit/core-reference/src/test/resources/log4j2.xml
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/resources/log4j2.xml 
b/fit/core-reference/src/test/resources/log4j2.xml
deleted file mode 100644
index 4811c94..0000000
--- a/fit/core-reference/src/test/resources/log4j2.xml
+++ /dev/null
@@ -1,133 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
-<configuration status="WARN" shutdownHook="disable">
-
-  <appenders>
-    
-    <RollingRandomAccessFile name="main" fileName="${log.directory}/core.log"
-                             
filePattern="${log.directory}/core-%d{yyyy-MM-dd}.log.gz"
-                             immediateFlush="false" append="true">
-      <PatternLayout>
-        <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
-      </PatternLayout>
-      <Policies>
-        <TimeBasedTriggeringPolicy/>
-        <SizeBasedTriggeringPolicy size="250 MB"/>
-      </Policies>
-    </RollingRandomAccessFile>
-
-    <RollingRandomAccessFile name="persistence" 
fileName="${log.directory}/core-persistence.log"
-                             
filePattern="${log.directory}/core-persistence-%d{yyyy-MM-dd}.log.gz"
-                             immediateFlush="false" append="true">
-      <PatternLayout>
-        <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
-      </PatternLayout>
-      <Policies>
-        <TimeBasedTriggeringPolicy/>
-        <SizeBasedTriggeringPolicy size="250 MB"/>
-      </Policies>
-    </RollingRandomAccessFile>
-
-    <RollingRandomAccessFile name="rest" 
fileName="${log.directory}/core-rest.log"
-                             
filePattern="${log.directory}/core-rest-%d{yyyy-MM-dd}.log.gz"
-                             immediateFlush="false" append="true">
-      <PatternLayout>
-        <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
-      </PatternLayout>
-      <Policies>
-        <TimeBasedTriggeringPolicy/>
-        <SizeBasedTriggeringPolicy size="250 MB"/>
-      </Policies>
-    </RollingRandomAccessFile>
-
-    <RollingRandomAccessFile name="connid" 
fileName="${log.directory}/core-connid.log"
-                             
filePattern="${log.directory}/core-connid-%d{yyyy-MM-dd}.log.gz"
-                             immediateFlush="false" append="true">
-      <PatternLayout>
-        <pattern>%d{HH:mm:ss.SSS} %-5level %msg%n</pattern>
-      </PatternLayout>
-      <Policies>
-        <TimeBasedTriggeringPolicy/>
-        <SizeBasedTriggeringPolicy size="250 MB"/>
-      </Policies>
-    </RollingRandomAccessFile>
-    
-  </appenders>
-  
-  <loggers>
-    
-    <asyncLogger name="org.apache.syncope.core.persistence" additivity="false" 
level="INFO">
-      <appender-ref ref="persistence"/>
-    </asyncLogger>
-    <asyncLogger name="org.springframework.orm" additivity="false" 
level="INFO">
-      <appender-ref ref="persistence"/>
-    </asyncLogger>
-    
-    <asyncLogger name="org.apache.syncope.core.rest" additivity="false" 
level="INFO">
-      <appender-ref ref="rest"/>
-    </asyncLogger>
-    <asyncLogger name="org.springframework.web" additivity="false" 
level="INFO">
-      <appender-ref ref="rest"/>
-    </asyncLogger>
-    <asyncLogger name="org.apache.http" additivity="false" level="INFO">
-      <appender-ref ref="rest"/>
-    </asyncLogger>
-    <asyncLogger name="org.apache.cxf" additivity="false" level="ERROR">
-      <appender-ref ref="rest"/>
-    </asyncLogger>
-    
-    <asyncLogger name="org.identityconnectors" additivity="false" 
level="DEBUG">
-      <appender-ref ref="connid"/>
-    </asyncLogger>
-    <asyncLogger name="net.tirasa.connid" additivity="false" level="DEBUG">
-      <appender-ref ref="connid"/>
-    </asyncLogger>
-    <asyncLogger 
name="org.apache.syncope.core.provisioning.api.ConnIdBundleManager" 
additivity="false" level="INFO">
-      <appender-ref ref="connid"/>
-    </asyncLogger>
-    
-    <asyncLogger name="org.apache.syncope" additivity="false" level="INFO">
-      <appender-ref ref="main"/>
-    </asyncLogger>
-    <asyncLogger name="org.apache.syncope.core.provisioning" 
additivity="false" level="INFO">
-      <appender-ref ref="main"/>
-    </asyncLogger>
-    <asyncLogger name="org.apache.syncope.core.logic" additivity="false" 
level="INFO">
-      <appender-ref ref="main"/>
-    </asyncLogger>
-    <asyncLogger name="org.springframework" additivity="false" level="INFO">
-      <appender-ref ref="main"/>
-    </asyncLogger>
-    <asyncLogger name="org.quartz" additivity="false" level="INFO">
-      <appender-ref ref="main"/>
-    </asyncLogger>
-    <asyncLogger name="org.activiti" additivity="false" level="ERROR">
-      <appender-ref ref="main"/>
-    </asyncLogger>
-    <asyncLogger name="org.apache.camel" additivity="false" level="ERROR">
-      <appender-ref ref="main"/>
-    </asyncLogger>
-    
-    <root level="INFO">
-      <appender-ref ref="main"/>
-    </root>
-    
-  </loggers>
-</configuration>

Reply via email to