From 354fe0a211afd8b2847c1a3881bde9d888b49432 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 13 Jun 2012 13:37:08 +0200 Subject: [PATCH] added unit test for hg cat command --- .../scm/repository/HgContextProvider.java | 56 +++++++++ .../repository/HgRepositoryHandlerTest.java | 24 ---- .../spi/AbstractHgCommandTestBase.java | 117 ++++++++++++++++++ .../scm/repository/spi/HgCatCommandTest.java | 117 ++++++++++++++++++ .../scm/repository/spi/scm-hg-spi-test.zip | Bin 0 -> 6972 bytes 5 files changed, 290 insertions(+), 24 deletions(-) create mode 100644 scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgContextProvider.java create mode 100644 scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/AbstractHgCommandTestBase.java create mode 100644 scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgCatCommandTest.java create mode 100644 scm-plugins/scm-hg-plugin/src/test/resources/sonia/scm/repository/spi/scm-hg-spi-test.zip diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgContextProvider.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgContextProvider.java new file mode 100644 index 0000000000..8c7a5b752d --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgContextProvider.java @@ -0,0 +1,56 @@ +/** + * 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.repository; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.inject.Provider; + +/** + * + * @author Sebastian Sdorra + */ +public class HgContextProvider implements Provider +{ + + /** + * Method description + * + * + * @return + */ + @Override + public HgContext get() + { + return new HgContext(); + } +} diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgRepositoryHandlerTest.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgRepositoryHandlerTest.java index 21d82f0827..ab052525fe 100644 --- a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgRepositoryHandlerTest.java +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgRepositoryHandlerTest.java @@ -104,28 +104,4 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase return handler; } - - //~--- inner classes -------------------------------------------------------- - - /** - * Dummy {@link Provider} for {@link HgContext} - * - * - * @author Sebastian Sdorra - */ - private static class HgContextProvider implements Provider - { - - /** - * Return context for mercurial - * - * - * @return context for mercurial - */ - @Override - public HgContext get() - { - return new HgContext(); - } - } } diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/AbstractHgCommandTestBase.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/AbstractHgCommandTestBase.java new file mode 100644 index 0000000000..53e9101a0d --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/AbstractHgCommandTestBase.java @@ -0,0 +1,117 @@ +/** + * 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.repository.spi; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.Assume; +import org.junit.Before; + +import sonia.scm.SCMContextProvider; +import sonia.scm.io.FileSystem; +import sonia.scm.repository.HgContextProvider; +import sonia.scm.repository.HgRepositoryHandler; +import sonia.scm.store.MemoryStoreFactory; +import sonia.scm.util.MockUtil; + +import static org.mockito.Mockito.*; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +public class AbstractHgCommandTestBase extends ZippedRepositoryTestBase +{ + + /** + * Method description + * + * + * @throws IOException + */ + @Before + public void initHgHandler() throws IOException + { + File folder = tempFolder.newFolder(); + FileSystem fileSystem = mock(FileSystem.class); + + this.handler = new HgRepositoryHandler(new MemoryStoreFactory(), + fileSystem, new HgContextProvider()); + + SCMContextProvider context = MockUtil.getSCMContextProvider(folder); + + this.handler.init(context); + + // skip tests if hg not in path + if (!handler.isConfigured()) + { + System.out.println("WARNING could not find hg, skipping test"); + Assume.assumeTrue(false); + } + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + protected String getType() + { + return "hg"; + } + + /** + * Method description + * + * + * @return + */ + @Override + protected String getZippedRepositoryResource() + { + return "sonia/scm/repository/spi/scm-hg-spi-test.zip"; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + protected HgRepositoryHandler handler; +} diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgCatCommandTest.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgCatCommandTest.java new file mode 100644 index 0000000000..35e718bd44 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgCatCommandTest.java @@ -0,0 +1,117 @@ +/** + * 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.repository.spi; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.Test; + +import sonia.scm.repository.HgContext; +import sonia.scm.repository.RepositoryException; + +import static org.junit.Assert.*; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +public class HgCatCommandTest extends AbstractHgCommandTestBase +{ + + /** + * Method description + * + * + * @throws IOException + * @throws RepositoryException + */ + @Test + public void testCat() throws IOException, RepositoryException + { + CatCommandRequest request = new CatCommandRequest(); + + request.setPath("a.txt"); + request.setRevision("a9bacaf1b7fa"); + assertEquals("a", execute(request)); + } + + /** + * Method description + * + * + * @throws IOException + * @throws RepositoryException + */ + @Test + public void testSimpleCat() throws IOException, RepositoryException + { + CatCommandRequest request = new CatCommandRequest(); + + request.setPath("b.txt"); + assertEquals("b", execute(request)); + } + + /** + * Method description + * + * + * @param request + * + * @return + * + * @throws IOException + * @throws RepositoryException + */ + private String execute(CatCommandRequest request) + throws IOException, RepositoryException + { + String content = null; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + try + { + new HgCatCommand(handler, new HgContext(), repository, + repositoryDirectory).getCatResult(request, baos); + } + finally + { + content = baos.toString().trim(); + } + + return content; + } +} diff --git a/scm-plugins/scm-hg-plugin/src/test/resources/sonia/scm/repository/spi/scm-hg-spi-test.zip b/scm-plugins/scm-hg-plugin/src/test/resources/sonia/scm/repository/spi/scm-hg-spi-test.zip new file mode 100644 index 0000000000000000000000000000000000000000..4896adc9de0d6189f13702c02e5e48520861ed9a GIT binary patch literal 6972 zcmbuE2{=^y|HsERn5o>PDWw{co6;D~$i>a_q-)<*mW;+MxQvmpl%+!5>Xuu#ZWNVn zRJ2kGX>NqdmO`>?LCT(;@H=PDFlUz3|M^eP*XVgVukUC3e$V^!$<9(j5`_Ri!M~Rq zaem?ckVGgUaNb^;+ni((64s%$w)=qc+3 zk!~eZ6I`{@hqpaNiOZHppSAQDGU|CY-GOo~sx)`jEgR*S06BmVa9}>y1WzW@mq8Bn zWpTD=hSb{HiuMG;SOJ)tcxP1^j$a4_Y6cTX_NRDr7zp5bKVb%yMkfdR1);#GK&%h} zlV(^HGR2z)MHaMW&d7p!sbF@A?F8)k8(53E_CO3zj#b_?G8J+UOq2-IVoP%87vSef z<&hlsL?IM5^b=krTRqu&QpJ9_0+loV%Yk&FXR<~@fDvuJ$GS6Uzmn9K6yj7C$z{|a z)KN~hI-q-ny52SCQ`zoe4%ze}0^@D%Slx*|AMW=IOYn*SbaynUbki2V%pJg5z-MX@ z*$c7}bXi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