You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by ma...@apache.org on 2015/11/20 11:10:30 UTC
syncope git commit: Added unit tests, SYNCOPE-727
Repository: syncope
Updated Branches:
refs/heads/master 9b033aa1b -> 444182f72
Added unit tests, SYNCOPE-727
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/444182f7
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/444182f7
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/444182f7
Branch: refs/heads/master
Commit: 444182f724a4fc9a9f2985244f630aa30659e4c8
Parents: 9b033aa
Author: massi <ma...@tirasa.net>
Authored: Fri Nov 20 11:10:08 2015 +0100
Committer: massi <ma...@tirasa.net>
Committed: Fri Nov 20 11:10:08 2015 +0100
----------------------------------------------------------------------
client/cli/pom.xml | 5 ++
.../syncope/client/cli/util/CommandUtils.java | 2 +-
.../client/cli/util/FileSystemUtils.java | 40 -------------
.../syncope/client/cli/util/JasyptUtils.java | 4 +-
.../client/cli/util/CommandUtilsTest.java | 62 ++++++++++++++++++++
.../client/cli/util/JasyptUtilsTest.java | 42 +++++++++++++
6 files changed, 113 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/444182f7/client/cli/pom.xml
----------------------------------------------------------------------
diff --git a/client/cli/pom.xml b/client/cli/pom.xml
index 447d7f7..61282ce 100644
--- a/client/cli/pom.xml
+++ b/client/cli/pom.xml
@@ -81,6 +81,11 @@ under the License.
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/syncope/blob/444182f7/client/cli/src/main/java/org/apache/syncope/client/cli/util/CommandUtils.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/util/CommandUtils.java b/client/cli/src/main/java/org/apache/syncope/client/cli/util/CommandUtils.java
index 8085380..9b401a6 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/util/CommandUtils.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/util/CommandUtils.java
@@ -75,7 +75,7 @@ public final class CommandUtils {
}
return types;
}
-
+
public static String helpMessage(final String command, final List<String> options) {
final StringBuilder helpMessageBuilder = new StringBuilder(String.format("\nUsage: %s [options]\n", command));
helpMessageBuilder.append(" Options:\n");
http://git-wip-us.apache.org/repos/asf/syncope/blob/444182f7/client/cli/src/main/java/org/apache/syncope/client/cli/util/FileSystemUtils.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/util/FileSystemUtils.java b/client/cli/src/main/java/org/apache/syncope/client/cli/util/FileSystemUtils.java
index 8fc779c..6ed7a9b 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/util/FileSystemUtils.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/util/FileSystemUtils.java
@@ -18,30 +18,13 @@
*/
package org.apache.syncope.client.cli.util;
-import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.attribute.PosixFilePermission;
-import java.util.HashSet;
-import java.util.ResourceBundle;
-import java.util.Set;
-import org.apache.syncope.client.cli.commands.install.InstallConfigFileTemplate;
public final class FileSystemUtils {
- private static final ResourceBundle CONF = ResourceBundle.getBundle("configuration");
-
- public static void createNewDirectory(final String directoryToCreate) {
- final File directory = new File(directoryToCreate);
- directory.mkdirs();
- }
-
public static void createFileWith(final String filePath, final String content)
throws FileNotFoundException, UnsupportedEncodingException {
try (PrintWriter writer = new PrintWriter(filePath, "UTF-8")) {
@@ -59,29 +42,6 @@ public final class FileSystemUtils {
return installationDirectory.exists();
}
- public static void createScriptFile() throws FileNotFoundException, UnsupportedEncodingException, IOException {
- final File file = new File(InstallConfigFileTemplate.scriptFilePath());
- file.setExecutable(true);
- file.setReadable(true);
- file.setWritable(true);
- file.createNewFile();
- final FileWriter fw = new FileWriter(file.getAbsoluteFile());
- final BufferedWriter bw = new BufferedWriter(fw);
- if (isWindows()) {
- bw.write(CONF.getString("script.file.windows"));
- } else {
- bw.write(CONF.getString("script.file.linux"));
- final Set<PosixFilePermission> perms = new HashSet<>();
- perms.add(PosixFilePermission.OWNER_READ);
- perms.add(PosixFilePermission.OWNER_WRITE);
- perms.add(PosixFilePermission.OWNER_EXECUTE);
- perms.add(PosixFilePermission.GROUP_READ);
- perms.add(PosixFilePermission.OTHERS_READ);
- Files.setPosixFilePermissions(Paths.get(file.getAbsolutePath()), perms);
- }
- bw.close();
- }
-
public static boolean isWindows() {
return (System.getProperty("os.name").toLowerCase().contains("win"));
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/444182f7/client/cli/src/main/java/org/apache/syncope/client/cli/util/JasyptUtils.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/util/JasyptUtils.java b/client/cli/src/main/java/org/apache/syncope/client/cli/util/JasyptUtils.java
index 0f9d592..fe99971 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/util/JasyptUtils.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/util/JasyptUtils.java
@@ -22,6 +22,8 @@ import org.jasypt.util.text.BasicTextEncryptor;
public final class JasyptUtils {
+ private static final String JASYPT_KEY = "Ka9s8yadaisj9mud87ssdaifansy";
+
private final BasicTextEncryptor textEncryptor;
private static JasyptUtils JASYPT_UTILS = null;
@@ -35,7 +37,7 @@ public final class JasyptUtils {
private JasyptUtils() {
textEncryptor = new BasicTextEncryptor();
- textEncryptor.setPassword("Ka9s8yadaisj9mud87ssdaifansy");
+ textEncryptor.setPassword(JASYPT_KEY);
}
public String encrypt(final String password) {
http://git-wip-us.apache.org/repos/asf/syncope/blob/444182f7/client/cli/src/test/java/org/apache/syncope/client/cli/util/CommandUtilsTest.java
----------------------------------------------------------------------
diff --git a/client/cli/src/test/java/org/apache/syncope/client/cli/util/CommandUtilsTest.java b/client/cli/src/test/java/org/apache/syncope/client/cli/util/CommandUtilsTest.java
new file mode 100644
index 0000000..60be06f
--- /dev/null
+++ b/client/cli/src/test/java/org/apache/syncope/client/cli/util/CommandUtilsTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.client.cli.util;
+
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.util.List;
+import org.apache.syncope.client.cli.Command;
+import org.apache.syncope.client.cli.commands.AbstractCommand;
+import org.junit.Test;
+
+public class CommandUtilsTest {
+
+ @Test
+ public void fromArgs() {
+ final String commandName = "logger";
+ try {
+ final AbstractCommand command = CommandUtils.fromArgs(commandName);
+ assertEquals(commandName, command.getClass().getAnnotation(Command.class).name());
+ } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException ex) {
+ fail(ex.getMessage());
+ }
+
+ final String wrongCommandName = "wrong";
+ try {
+ CommandUtils.fromArgs(wrongCommandName);
+ fail(wrongCommandName + " isn't a right command, why you are here?");
+ } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException ex) {
+ assertEquals(IllegalArgumentException.class, ex.getClass());
+ assertEquals(wrongCommandName + " is not a valid command", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void commands() {
+ try {
+ final List<AbstractCommand> commands = CommandUtils.commands();
+ assertFalse(commands.isEmpty());
+ assertEquals(21, commands.size());
+ } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException ex) {
+ fail(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/444182f7/client/cli/src/test/java/org/apache/syncope/client/cli/util/JasyptUtilsTest.java
----------------------------------------------------------------------
diff --git a/client/cli/src/test/java/org/apache/syncope/client/cli/util/JasyptUtilsTest.java b/client/cli/src/test/java/org/apache/syncope/client/cli/util/JasyptUtilsTest.java
new file mode 100644
index 0000000..2c4b963
--- /dev/null
+++ b/client/cli/src/test/java/org/apache/syncope/client/cli/util/JasyptUtilsTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.client.cli.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class JasyptUtilsTest {
+
+ @Test
+ public void singleton() {
+ final JasyptUtils jasyptUtils = JasyptUtils.getJasyptUtils();
+ final JasyptUtils jasyptUtils2 = JasyptUtils.getJasyptUtils();
+ assertEquals(jasyptUtils, jasyptUtils2);
+ }
+
+ @Test
+ public void encryption() {
+ final String password = "password";
+ final JasyptUtils jasyptUtils = JasyptUtils.getJasyptUtils();
+ final String encPassword = jasyptUtils.encrypt(password);
+ final String decPassword = jasyptUtils.decrypt(encPassword);
+ assertEquals(password, decPassword);
+ }
+}