From 8f52e2db5e8983620b7c61244f4b96a638fae411 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 13 May 2011 18:40:19 +0200 Subject: [PATCH] added integration test for JerseyUserClientHandler --- .../scm/client/AbstractClientHandler.java | 15 +- .../scm/client/JerseyGroupClientHandler.java | 15 ++ .../client/JerseyRepositoryClientHandler.java | 14 +- .../scm/client/JerseyUserClientHandler.java | 15 ++ .../it/AbstractClientHandlerTestBase.java | 31 +++-- .../it/JerseyUserClientHandlerITCase.java | 128 ++++++++++++++++++ 6 files changed, 192 insertions(+), 26 deletions(-) create mode 100644 scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/JerseyUserClientHandlerITCase.java diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java index 56ca60e3bb..eb4d8a9f15 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java @@ -123,7 +123,15 @@ public abstract class AbstractClientHandler { response = resource.post(ClientResponse.class, item); ClientUtil.checkResponse(response, 201); - postCreate(response, item); + + String url = response.getHeaders().get("Location").get(0); + + AssertUtil.assertIsNotEmpty(url); + + T newItem = getItemByUrl(url); + + AssertUtil.assertIsNotNull(newItem); + postCreate(response, item, newItem); } finally { @@ -250,8 +258,9 @@ public abstract class AbstractClientHandler * * @param response * @param item + * @param newItem */ - protected void postCreate(ClientResponse response, T item) {} + protected void postCreate(ClientResponse response, T item, T newItem) {} /** * Method description @@ -311,4 +320,6 @@ public abstract class AbstractClientHandler /** Field description */ private Class itemClass; + + ; } diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyGroupClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyGroupClientHandler.java index ef68d7936f..5f3969ffc7 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyGroupClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyGroupClientHandler.java @@ -39,6 +39,7 @@ import sonia.scm.group.Group; //~--- JDK imports ------------------------------------------------------------ +import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.GenericType; import java.util.List; @@ -77,6 +78,20 @@ public class JerseyGroupClientHandler extends AbstractClientHandler ; } + /** + * Method description + * + * + * @param response + * @param item + * @param newItem + */ + @Override + protected void postCreate(ClientResponse response, Group item, Group newItem) + { + newItem.copyProperties(item); + } + //~--- get methods ---------------------------------------------------------- /** diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyRepositoryClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyRepositoryClientHandler.java index 2797e8eeee..d0316b19d7 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyRepositoryClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyRepositoryClientHandler.java @@ -92,7 +92,8 @@ public class JerseyRepositoryClientHandler @Override protected GenericType> createGenericListType() { - return new GenericType>() {}; + return new GenericType>() {} + ; } /** @@ -101,17 +102,12 @@ public class JerseyRepositoryClientHandler * * @param response * @param repository + * @param newRepository */ @Override - protected void postCreate(ClientResponse response, Repository repository) + protected void postCreate(ClientResponse response, Repository repository, + Repository newRepository) { - String url = response.getHeaders().get("Location").get(0); - - AssertUtil.assertIsNotEmpty(url); - - Repository newRepository = getItemByUrl(url); - - AssertUtil.assertIsNotNull(newRepository); newRepository.copyProperties(repository); // copyProperties does not copy the repository id diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyUserClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyUserClientHandler.java index 2b60649297..c28d3eda70 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyUserClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyUserClientHandler.java @@ -39,6 +39,7 @@ import sonia.scm.user.User; //~--- JDK imports ------------------------------------------------------------ +import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.GenericType; import java.util.List; @@ -77,6 +78,20 @@ public class JerseyUserClientHandler extends AbstractClientHandler ; } + /** + * Method description + * + * + * @param response + * @param item + * @param newItem + */ + @Override + protected void postCreate(ClientResponse response, User item, User newItem) + { + newItem.copyProperties(item); + } + //~--- get methods ---------------------------------------------------------- /** diff --git a/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/AbstractClientHandlerTestBase.java b/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/AbstractClientHandlerTestBase.java index 54e6be2575..7a4a851cb8 100644 --- a/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/AbstractClientHandlerTestBase.java +++ b/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/AbstractClientHandlerTestBase.java @@ -56,19 +56,6 @@ import static sonia.scm.client.it.TestUtil.*; public abstract class AbstractClientHandlerTestBase { - /** - * Method description - * - * - * @param item - */ - protected void assertIsValid(T item) - { - assertNotNull(item); - assertNotNull(item.getId()); - assertTrue( item.getId().length() > 0 ); - } - /** * Method description * @@ -117,7 +104,7 @@ public abstract class AbstractClientHandlerTestBase T o = handler.get(id); assertNotNull(o); - assertEquals(item, o); + assertEquals(item.getId(), o.getId()); session.close(); } @@ -242,6 +229,7 @@ public abstract class AbstractClientHandlerTestBase handler.create(item); assertIsValid(item); + item = handler.get(item.getId()); ModifyTest mt = createModifyTest(); @@ -257,6 +245,19 @@ public abstract class AbstractClientHandlerTestBase session.close(); } + /** + * Method description + * + * + * @param item + */ + protected void assertIsValid(T item) + { + assertNotNull(item); + assertNotNull(item.getId()); + assertTrue(item.getId().length() > 0); + } + //~--- inner interfaces ----------------------------------------------------- /** @@ -266,7 +267,7 @@ public abstract class AbstractClientHandlerTestBase * @param * * @version Enter version here..., 11/05/13 - * @author Enter your name here... + * @author Enter your name here... */ protected interface ModifyTest { diff --git a/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/JerseyUserClientHandlerITCase.java b/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/JerseyUserClientHandlerITCase.java new file mode 100644 index 0000000000..d84deabb42 --- /dev/null +++ b/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/JerseyUserClientHandlerITCase.java @@ -0,0 +1,128 @@ +/** + * 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.client.it; + +//~--- non-JDK imports -------------------------------------------------------- + +import sonia.scm.client.ClientHandler; +import sonia.scm.client.JerseyClientSession; +import sonia.scm.client.it.AbstractClientHandlerTestBase.ModifyTest; +import sonia.scm.user.User; +import sonia.scm.user.UserTestData; + +/** + * + * @author Sebastian Sdorra + */ +public class JerseyUserClientHandlerITCase + extends AbstractClientHandlerTestBase +{ + + /** + * Method description + * + * + * @param session + * + * @return + */ + @Override + protected ClientHandler createHandler(JerseyClientSession session) + { + return session.getUserHandler(); + } + + /** + * Method description + * + * + * @return + */ + @Override + protected ModifyTest createModifyTest() + { + return new ModifyTest() + { + @Override + public void modify(User item) + { + item.setDisplayName("Modified DisplayName"); + } + @Override + public boolean isCorrectModified(User item) + { + return "Modified DisplayName".equals(item.getDisplayName()); + } + }; + } + + /** + * Method description + * + * + * @param number + * + * @return + */ + @Override + protected User createTestData(int number) + { + User user = null; + + switch (number) + { + case 1 : + user = UserTestData.createAdams(); + + break; + + case 2 : + user = UserTestData.createDent(); + + break; + + case 3 : + user = UserTestData.createMarvin(); + + break; + + case 4 : + user = UserTestData.createPerfect(); + + break; + } + + return user; + } +}