added integration test for JerseyUserClientHandler

This commit is contained in:
Sebastian Sdorra
2011-05-13 18:40:19 +02:00
parent 7eeb476748
commit 8f52e2db5e
6 changed files with 192 additions and 26 deletions

View File

@@ -123,7 +123,15 @@ public abstract class AbstractClientHandler<T extends ModelObject>
{ {
response = resource.post(ClientResponse.class, item); response = resource.post(ClientResponse.class, item);
ClientUtil.checkResponse(response, 201); 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 finally
{ {
@@ -250,8 +258,9 @@ public abstract class AbstractClientHandler<T extends ModelObject>
* *
* @param response * @param response
* @param item * @param item
* @param newItem
*/ */
protected void postCreate(ClientResponse response, T item) {} protected void postCreate(ClientResponse response, T item, T newItem) {}
/** /**
* Method description * Method description
@@ -311,4 +320,6 @@ public abstract class AbstractClientHandler<T extends ModelObject>
/** Field description */ /** Field description */
private Class<T> itemClass; private Class<T> itemClass;
;
} }

View File

@@ -39,6 +39,7 @@ import sonia.scm.group.Group;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.GenericType;
import java.util.List; import java.util.List;
@@ -77,6 +78,20 @@ public class JerseyGroupClientHandler extends AbstractClientHandler<Group>
; ;
} }
/**
* Method description
*
*
* @param response
* @param item
* @param newItem
*/
@Override
protected void postCreate(ClientResponse response, Group item, Group newItem)
{
newItem.copyProperties(item);
}
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**

View File

@@ -92,7 +92,8 @@ public class JerseyRepositoryClientHandler
@Override @Override
protected GenericType<List<Repository>> createGenericListType() protected GenericType<List<Repository>> createGenericListType()
{ {
return new GenericType<List<Repository>>() {}; return new GenericType<List<Repository>>() {}
;
} }
/** /**
@@ -101,17 +102,12 @@ public class JerseyRepositoryClientHandler
* *
* @param response * @param response
* @param repository * @param repository
* @param newRepository
*/ */
@Override @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); newRepository.copyProperties(repository);
// copyProperties does not copy the repository id // copyProperties does not copy the repository id

View File

@@ -39,6 +39,7 @@ import sonia.scm.user.User;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.GenericType;
import java.util.List; import java.util.List;
@@ -77,6 +78,20 @@ public class JerseyUserClientHandler extends AbstractClientHandler<User>
; ;
} }
/**
* Method description
*
*
* @param response
* @param item
* @param newItem
*/
@Override
protected void postCreate(ClientResponse response, User item, User newItem)
{
newItem.copyProperties(item);
}
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**

View File

@@ -56,19 +56,6 @@ import static sonia.scm.client.it.TestUtil.*;
public abstract class AbstractClientHandlerTestBase<T extends ModelObject> public abstract class AbstractClientHandlerTestBase<T extends ModelObject>
{ {
/**
* Method description
*
*
* @param item
*/
protected void assertIsValid(T item)
{
assertNotNull(item);
assertNotNull(item.getId());
assertTrue( item.getId().length() > 0 );
}
/** /**
* Method description * Method description
* *
@@ -117,7 +104,7 @@ public abstract class AbstractClientHandlerTestBase<T extends ModelObject>
T o = handler.get(id); T o = handler.get(id);
assertNotNull(o); assertNotNull(o);
assertEquals(item, o); assertEquals(item.getId(), o.getId());
session.close(); session.close();
} }
@@ -242,6 +229,7 @@ public abstract class AbstractClientHandlerTestBase<T extends ModelObject>
handler.create(item); handler.create(item);
assertIsValid(item); assertIsValid(item);
item = handler.get(item.getId());
ModifyTest<T> mt = createModifyTest(); ModifyTest<T> mt = createModifyTest();
@@ -257,6 +245,19 @@ public abstract class AbstractClientHandlerTestBase<T extends ModelObject>
session.close(); session.close();
} }
/**
* Method description
*
*
* @param item
*/
protected void assertIsValid(T item)
{
assertNotNull(item);
assertNotNull(item.getId());
assertTrue(item.getId().length() > 0);
}
//~--- inner interfaces ----------------------------------------------------- //~--- inner interfaces -----------------------------------------------------
/** /**

View File

@@ -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<User>
{
/**
* Method description
*
*
* @param session
*
* @return
*/
@Override
protected ClientHandler<User> createHandler(JerseyClientSession session)
{
return session.getUserHandler();
}
/**
* Method description
*
*
* @return
*/
@Override
protected ModifyTest<User> createModifyTest()
{
return new ModifyTest<User>()
{
@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;
}
}