diff --git a/scm-core/src/test/java/sonia/scm/url/JSONRestModelUrlProviderTest.java b/scm-core/src/test/java/sonia/scm/url/JSONRestModelUrlProviderTest.java new file mode 100644 index 0000000000..bfbee4ada9 --- /dev/null +++ b/scm-core/src/test/java/sonia/scm/url/JSONRestModelUrlProviderTest.java @@ -0,0 +1,69 @@ +/** + * 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.url; + +/** + * + * @author Sebastian Sdorra + */ +public class JSONRestModelUrlProviderTest extends RestModelUrlProviderTestBase +{ + + /** + * Method description + * + * + * @param baseUrl + * + * @return + */ + @Override + protected UrlProvider createUrlProvider(String baseUrl) + { + return UrlProviderFactory.createUrlProvider(baseUrl, + UrlProviderFactory.TYPE_RESTAPI_JSON); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + protected String getExtension() + { + return EXTENSION_JSON; + } +} diff --git a/scm-core/src/test/java/sonia/scm/url/JSONRestUrlProviderTest.java b/scm-core/src/test/java/sonia/scm/url/JSONRestUrlProviderTest.java index 52226e63f4..04f01a544b 100644 --- a/scm-core/src/test/java/sonia/scm/url/JSONRestUrlProviderTest.java +++ b/scm-core/src/test/java/sonia/scm/url/JSONRestUrlProviderTest.java @@ -38,11 +38,6 @@ package sonia.scm.url; public class JSONRestUrlProviderTest extends RestUrlProviderTestBase { - /** Field description */ - public static final String EXTENSION = ".json"; - - //~--- methods -------------------------------------------------------------- - /** * Method description * @@ -69,6 +64,6 @@ public class JSONRestUrlProviderTest extends RestUrlProviderTestBase @Override protected String getExtension() { - return EXTENSION; + return EXTENSION_JSON; } } diff --git a/scm-core/src/test/java/sonia/scm/url/ModelUrlProviderTestBase.java b/scm-core/src/test/java/sonia/scm/url/ModelUrlProviderTestBase.java new file mode 100644 index 0000000000..c367808a76 --- /dev/null +++ b/scm-core/src/test/java/sonia/scm/url/ModelUrlProviderTestBase.java @@ -0,0 +1,183 @@ +/** + * 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.url; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * + * @author Sebastian Sdorra + */ +public abstract class ModelUrlProviderTestBase extends UrlTestBase +{ + + /** Field description */ + public static final String ITEM = "hitchhiker"; + + /** Field description */ + public static final String MODEL_GROUPS = "groups"; + + /** Field description */ + public static final String MODEL_REPOSITORY = "repositories"; + + /** Field description */ + public static final String MODEL_USERS = "users"; + + /** Field description */ + private static final String[] MODELS = new String[] { MODEL_REPOSITORY, + MODEL_USERS, MODEL_GROUPS }; + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * + * @param baseUrl + * @return + */ + protected abstract ModelUrlProvider createGroupModelUrlProvider( + String baseUrl); + + /** + * Method description + * + * + * + * @param baseUrl + * @return + */ + protected abstract ModelUrlProvider createRepositoryModelUrlProvider( + String baseUrl); + + /** + * Method description + * + * + * + * @param baseUrl + * @return + */ + protected abstract ModelUrlProvider createUserModelUrlProvider( + String baseUrl); + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param baseUrl + * @param model + * + * @return + */ + protected abstract String getExpectedAllUrl(String baseUrl, String model); + + /** + * Method description + * + * + * @param baseUrl + * @param model + * @param item + * + * @return + */ + protected abstract String getExpectedDetailUrl(String baseUrl, String model, + String item); + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + */ + @Test + public void testGetAllUrl() + { + for (String model : MODELS) + { + assertEquals(getExpectedAllUrl(BASEURL, model), + createModelUrlProvider(BASEURL, model).getAllUrl()); + } + } + + /** + * Method description + * + */ + @Test + public void testGetDetailUrl() + { + for (String model : MODELS) + { + assertEquals(getExpectedDetailUrl(BASEURL, model, ITEM), + createModelUrlProvider(BASEURL, model).getDetailUrl(ITEM)); + } + } + + /** + * Method description + * + * + * + * @param baseUrl + * @param model + * + * @return + */ + private ModelUrlProvider createModelUrlProvider(String baseUrl, String model) + { + ModelUrlProvider urlProvider = null; + + if (MODEL_REPOSITORY.equals(model)) + { + urlProvider = createRepositoryModelUrlProvider(baseUrl); + } + else if (MODEL_USERS.equals(model)) + { + urlProvider = createUserModelUrlProvider(baseUrl); + } + else if (MODEL_GROUPS.equals(model)) + { + urlProvider = createGroupModelUrlProvider(baseUrl); + } + + return urlProvider; + } +} diff --git a/scm-core/src/test/java/sonia/scm/url/RestModelUrlProviderTestBase.java b/scm-core/src/test/java/sonia/scm/url/RestModelUrlProviderTestBase.java new file mode 100644 index 0000000000..f0b6bbbfaf --- /dev/null +++ b/scm-core/src/test/java/sonia/scm/url/RestModelUrlProviderTestBase.java @@ -0,0 +1,158 @@ +/** + * 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.url; + +//~--- non-JDK imports -------------------------------------------------------- + +import sonia.scm.util.HttpUtil; + +/** + * + * @author Sebastian Sdorra + */ +public abstract class RestModelUrlProviderTestBase + extends ModelUrlProviderTestBase +{ + + /** + * Method description + * + * + * @param baseUrl + * + * @return + */ + protected abstract UrlProvider createUrlProvider(String baseUrl); + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + protected abstract String getExtension(); + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param baseUrl + * + * @return + */ + @Override + protected ModelUrlProvider createGroupModelUrlProvider(String baseUrl) + { + return createUrlProvider(baseUrl).getGroupUrlProvider(); + } + + /** + * Method description + * + * + * @param baseUrl + * + * @return + */ + @Override + protected ModelUrlProvider createRepositoryModelUrlProvider(String baseUrl) + { + return createUrlProvider(baseUrl).getRepositoryUrlProvider(); + } + + /** + * Method description + * + * + * @param baseUrl + * @param urlPart + * + * @return + */ + protected String createRestUrl(String baseUrl, String urlPart) + { + return createRestUrl(baseUrl, urlPart, getExtension()); + } + + /** + * Method description + * + * + * @param baseUrl + * + * @return + */ + @Override + protected ModelUrlProvider createUserModelUrlProvider(String baseUrl) + { + return createUrlProvider(baseUrl).getUserUrlProvider(); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param baseUrl + * @param model + * + * @return + */ + @Override + protected String getExpectedAllUrl(String baseUrl, String model) + { + return createRestUrl(baseUrl, model); + } + + /** + * Method description + * + * + * @param baseUrl + * @param model + * @param item + * + * @return + */ + @Override + protected String getExpectedDetailUrl(String baseUrl, String model, + String item) + { + return createRestUrl(baseUrl, + model.concat(HttpUtil.SEPARATOR_PATH).concat(item)); + } +} diff --git a/scm-core/src/test/java/sonia/scm/url/RestUrlProviderTestBase.java b/scm-core/src/test/java/sonia/scm/url/RestUrlProviderTestBase.java index 04b25feb2d..827310b312 100644 --- a/scm-core/src/test/java/sonia/scm/url/RestUrlProviderTestBase.java +++ b/scm-core/src/test/java/sonia/scm/url/RestUrlProviderTestBase.java @@ -38,11 +38,6 @@ package sonia.scm.url; public abstract class RestUrlProviderTestBase extends UrlProviderTestBase { - /** Field description */ - public static final String URLSUFFIX_RESTAPI = "/api/rest/"; - - //~--- get methods ---------------------------------------------------------- - /** * Method description * @@ -51,6 +46,24 @@ public abstract class RestUrlProviderTestBase extends UrlProviderTestBase */ protected abstract String getExtension(); + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param baseUrl + * @param urlPart + * + * @return + */ + protected String createRestUrl(String baseUrl, String urlPart) + { + return createRestUrl(baseUrl, urlPart, getExtension()); + } + + //~--- get methods ---------------------------------------------------------- + /** * Method description * @@ -92,33 +105,4 @@ public abstract class RestUrlProviderTestBase extends UrlProviderTestBase { return createRestUrl(baseUrl, "authentication"); } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * @param baseUrl - * - * @return - */ - private String createBaseRestUrl(String baseUrl) - { - return baseUrl.concat(URLSUFFIX_RESTAPI); - } - - /** - * Method description - * - * - * @param baseUrl - * @param urlPart - * - * @return - */ - private String createRestUrl(String baseUrl, String urlPart) - { - return createBaseRestUrl(baseUrl).concat(urlPart).concat(getExtension()); - } } diff --git a/scm-core/src/test/java/sonia/scm/url/UrlProviderTestBase.java b/scm-core/src/test/java/sonia/scm/url/UrlProviderTestBase.java index 55dbf13729..3c0bf3c59b 100644 --- a/scm-core/src/test/java/sonia/scm/url/UrlProviderTestBase.java +++ b/scm-core/src/test/java/sonia/scm/url/UrlProviderTestBase.java @@ -41,12 +41,9 @@ import static org.junit.Assert.*; * * @author Sebastian Sdorra */ -public abstract class UrlProviderTestBase +public abstract class UrlProviderTestBase extends UrlTestBase { - /** Field description */ - private static final String BASEURL = "http://scm.scm-manager.org/scm"; - //~--- methods -------------------------------------------------------------- /** diff --git a/scm-core/src/test/java/sonia/scm/url/UrlTestBase.java b/scm-core/src/test/java/sonia/scm/url/UrlTestBase.java new file mode 100644 index 0000000000..884f9f6a30 --- /dev/null +++ b/scm-core/src/test/java/sonia/scm/url/UrlTestBase.java @@ -0,0 +1,83 @@ +/** + * 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.url; + +/** + * + * @author Sebastian Sdorra + */ +public abstract class UrlTestBase +{ + + /** Field description */ + public static final String EXTENSION_JSON = ".json"; + + /** Field description */ + public static final String EXTENSION_XML = ".xml"; + + /** Field description */ + public static final String URLSUFFIX_RESTAPI = "/api/rest/"; + + /** Field description */ + protected static final String BASEURL = "http://scm.scm-manager.org/scm"; + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param baseUrl + * + * @return + */ + protected String createBaseRestUrl(String baseUrl) + { + return baseUrl.concat(URLSUFFIX_RESTAPI); + } + + /** + * Method description + * + * + * @param baseUrl + * @param urlPart + * @param extension + * + * @return + */ + protected String createRestUrl(String baseUrl, String urlPart, + String extension) + { + return createBaseRestUrl(baseUrl).concat(urlPart).concat(extension); + } +} diff --git a/scm-core/src/test/java/sonia/scm/url/XMLRestModelUrlProviderTest.java b/scm-core/src/test/java/sonia/scm/url/XMLRestModelUrlProviderTest.java new file mode 100644 index 0000000000..38e293e55a --- /dev/null +++ b/scm-core/src/test/java/sonia/scm/url/XMLRestModelUrlProviderTest.java @@ -0,0 +1,69 @@ +/** + * 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.url; + +/** + * + * @author Sebastian Sdorra + */ +public class XMLRestModelUrlProviderTest extends RestModelUrlProviderTestBase +{ + + /** + * Method description + * + * + * @param baseUrl + * + * @return + */ + @Override + protected UrlProvider createUrlProvider(String baseUrl) + { + return UrlProviderFactory.createUrlProvider(baseUrl, + UrlProviderFactory.TYPE_RESTAPI_XML); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + protected String getExtension() + { + return EXTENSION_XML; + } +} diff --git a/scm-core/src/test/java/sonia/scm/url/XMLRestUrlProviderTest.java b/scm-core/src/test/java/sonia/scm/url/XMLRestUrlProviderTest.java index 821ee17508..b23f370367 100644 --- a/scm-core/src/test/java/sonia/scm/url/XMLRestUrlProviderTest.java +++ b/scm-core/src/test/java/sonia/scm/url/XMLRestUrlProviderTest.java @@ -38,11 +38,6 @@ package sonia.scm.url; public class XMLRestUrlProviderTest extends RestUrlProviderTestBase { - /** Field description */ - public static final String EXTENSION = ".xml"; - - //~--- methods -------------------------------------------------------------- - /** * Method description * @@ -69,6 +64,6 @@ public class XMLRestUrlProviderTest extends RestUrlProviderTestBase @Override protected String getExtension() { - return EXTENSION; + return EXTENSION_XML; } }