From 0ce1bb1f447acc2458b3f9b5798a319f1f99285a Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 4 May 2014 15:06:45 +0200 Subject: [PATCH] added some simple integration tests for the scm-cli-client --- scm-clients/scm-cli-client/pom.xml | 118 ++++++++++++++++ .../sonia/scm/cli/AbstractITCaseBase.java | 129 ++++++++++++++++++ .../sonia/scm/cli/RepositoriesITCase.java | 86 ++++++++++++ .../sonia/scm/cli/ServerVersionITCase.java | 70 ++++++++++ .../test/java/sonia/scm/cli/UsersITCase.java | 72 ++++++++++ .../java/sonia/scm/cli/VersionITCase.java | 65 +++++++++ 6 files changed, 540 insertions(+) create mode 100644 scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/AbstractITCaseBase.java create mode 100644 scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/RepositoriesITCase.java create mode 100644 scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/ServerVersionITCase.java create mode 100644 scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/UsersITCase.java create mode 100644 scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/VersionITCase.java diff --git a/scm-clients/scm-cli-client/pom.xml b/scm-clients/scm-cli-client/pom.xml index 4840737e6b..13a618e0b4 100644 --- a/scm-clients/scm-cli-client/pom.xml +++ b/scm-clients/scm-cli-client/pom.xml @@ -106,6 +106,124 @@ + + + + it + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.4 + + + package + + copy + + + + + sonia.scm + scm-webapp + ${project.version} + war + ${project.build.directory}/webapp + scm-webapp.war + + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.12 + + + ${project.version} + + + + + integration-test + + integration-test + + + + verify + + verify + + + + + + + org.mortbay.jetty + jetty-maven-plugin + ${jetty.version} + + 8085 + STOP + + + scm.home + target/scm-it + + + file.encoding + UTF-8 + + + + + 8081 + 60000 + 16384 + + + + /scm + + ${project.build.directory}/webapp/scm-webapp.war + ${project.build.javaLevel} + ${project.build.javaLevel} + ${project.build.sourceEncoding} + 0 + true + + + + start-jetty + pre-integration-test + + deploy-war + + + + stop-jetty + post-integration-test + + stop + + + + + + + + + + + + diff --git a/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/AbstractITCaseBase.java b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/AbstractITCaseBase.java new file mode 100644 index 0000000000..5184ea37ed --- /dev/null +++ b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/AbstractITCaseBase.java @@ -0,0 +1,129 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.cli; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.common.collect.Lists; +import com.google.common.io.Closeables; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import java.util.Arrays; +import java.util.List; + +/** + * + * @author Sebastian Sdorra + */ +public abstract class AbstractITCaseBase +{ + + /** + * Method description + * + * + * @param cmd + * + * @return + * + * @throws IOException + */ + protected String execute(String... cmd) throws IOException + { + String result = null; + ByteArrayInputStream inputStream = null; + ByteArrayOutputStream outputStream = null; + + try + { + inputStream = new ByteArrayInputStream(new byte[0]); + outputStream = new ByteArrayOutputStream(); + + App app = new App(inputStream, outputStream); + + app.run(cmd); + + outputStream.flush(); + result = outputStream.toString().trim(); + } + finally + { + Closeables.close(inputStream, true); + Closeables.close(outputStream, true); + } + + return result; + } + + /** + * Method description + * + * + * @param cmd + * + * @return + * + * @throws IOException + */ + protected String executeServer(String... cmd) throws IOException + { + List cmdList = Lists.newArrayList(); + + cmdList.add("--server"); + cmdList.add("http://localhost:8081/scm"); + cmdList.add("--user"); + cmdList.add("scmadmin"); + cmdList.add("--password"); + cmdList.add("scmadmin"); + cmdList.addAll(Arrays.asList(cmd)); + + return execute(cmdList.toArray(new String[cmdList.size()])); + } + + /** + * Method description + * + * + * @param values + * + * @return + */ + protected String prepareForTest(String values) + { + return values.replaceAll("\\n", ";").replaceAll("\\s+", ""); + } +} diff --git a/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/RepositoriesITCase.java b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/RepositoriesITCase.java new file mode 100644 index 0000000000..d09e912157 --- /dev/null +++ b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/RepositoriesITCase.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.cli; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.Test; + +import static org.hamcrest.Matchers.*; + +import static org.junit.Assert.*; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.IOException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * + * @author Sebastian Sdorra + */ +public class RepositoriesITCase extends AbstractITCaseBase +{ + + /** + * Method description + * + * + * @throws IOException + */ + @Test + public void listRepositoriesTest() throws IOException + { + executeServer("create-repository", "--type", "git", "--name", "hobbo", + "--description", "Test Repo"); + + String repositories = prepareForTest(executeServer("list-repositories")); + + assertThat(repositories, containsString("Name:hobbo;")); + assertThat(repositories, containsString("Description:TestRepo;")); + assertThat(repositories, containsString("Type:git;")); + + Pattern pattern = Pattern.compile("ID:([^;]+);"); + Matcher matcher = pattern.matcher(repositories); + + if (!matcher.find()) + { + fail("could not extract id of repository"); + } + + String id = matcher.group(1); + + executeServer("delete-repository", id); + } +} diff --git a/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/ServerVersionITCase.java b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/ServerVersionITCase.java new file mode 100644 index 0000000000..7e424587fb --- /dev/null +++ b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/ServerVersionITCase.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.cli; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assume.assumeTrue; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +public class ServerVersionITCase extends AbstractITCaseBase +{ + + /** + * Method description + * + * + * @throws IOException + */ + @Test + public void testServerVersion() throws IOException + { + String systemVersion = System.getProperty("scm.version"); + + assumeTrue("skip test, because system property scm.version is not set", + systemVersion != null); + + String version = executeServer("server-version"); + + assertEquals("scm-manager version: ".concat(systemVersion), version); + } +} diff --git a/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/UsersITCase.java b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/UsersITCase.java new file mode 100644 index 0000000000..e5b29457a9 --- /dev/null +++ b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/UsersITCase.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.cli; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.Test; + +import static org.hamcrest.Matchers.*; + +import static org.junit.Assert.*; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +public class UsersITCase extends AbstractITCaseBase +{ + + /** + * Method description + * + * + * @throws IOException + */ + @Test + public void listUsersTest() throws IOException + { + String users = prepareForTest(executeServer("list-users")); + + assertThat(users, containsString("Name:scmadmin;")); + assertThat(users, containsString("DisplayName:SCMAdministrator;")); + assertThat(users, containsString("Type:xml;")); + assertThat(users, containsString("E-Mail:scm-admin@scm-manager.org;")); + assertThat(users, containsString("Active:true;")); + assertThat(users, containsString("Administrator:true;")); + System.out.println(users); + } +} diff --git a/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/VersionITCase.java b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/VersionITCase.java new file mode 100644 index 0000000000..3d9563c34e --- /dev/null +++ b/scm-clients/scm-cli-client/src/test/java/sonia/scm/cli/VersionITCase.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.cli; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.Test; + +import static org.junit.Assert.*; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +public class VersionITCase extends AbstractITCaseBase +{ + + /** + * Method description + * + * + * @throws IOException + */ + @Test + public void testVersion() throws IOException + { + // maven properties are not available during it tests + String version = execute("version"); + + assertEquals("scm-cli-client version: unknown", version); + } +}