mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
fix problem with xml representation of collections
This commit is contained in:
@@ -60,6 +60,7 @@ import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.EntityTag;
|
||||
import javax.ws.rs.core.GenericEntity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Request;
|
||||
import javax.ws.rs.core.Response;
|
||||
@@ -93,6 +94,19 @@ public abstract class AbstractManagerResource<T extends ModelObject,
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param items
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract GenericEntity<Collection<T>> createGenericEntity(
|
||||
Collection<T> items);
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -271,14 +285,15 @@ public abstract class AbstractManagerResource<T extends ModelObject,
|
||||
}
|
||||
|
||||
Response response = null;
|
||||
Object entity = createGenericEntity(items);
|
||||
|
||||
if (disableCache)
|
||||
{
|
||||
response = Response.ok(items).build();
|
||||
response = Response.ok(entity).build();
|
||||
}
|
||||
else
|
||||
{
|
||||
response = createCacheResponse(request, manager, items);
|
||||
response = createCacheResponse(request, manager, entity);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
@@ -44,7 +44,10 @@ import sonia.scm.group.GroupManager;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.GenericEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -73,6 +76,24 @@ public class GroupResource
|
||||
super(groupManager);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param items
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected GenericEntity<Collection<Group>> createGenericEntity(
|
||||
Collection<Group> items)
|
||||
{
|
||||
return new GenericEntity<Collection<Group>>(items) {}
|
||||
;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,6 +58,7 @@ import java.util.Collection;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.GenericEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -99,6 +100,22 @@ public class RepositoryResource
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param items
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected GenericEntity<Collection<Repository>> createGenericEntity(
|
||||
Collection<Repository> items)
|
||||
{
|
||||
return new GenericEntity<Collection<Repository>>(items) {}
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -50,6 +50,7 @@ import sonia.scm.util.Util;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.GenericEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -85,6 +86,22 @@ public class UserResource extends AbstractManagerResource<User, UserException>
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param items
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected GenericEntity<Collection<User>> createGenericEntity(
|
||||
Collection<User> items)
|
||||
{
|
||||
return new GenericEntity<Collection<User>>(items) {}
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -46,7 +46,6 @@ import static org.junit.Assert.*;
|
||||
import com.sun.jersey.api.client.Client;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import com.sun.jersey.api.client.config.ClientConfig;
|
||||
import com.sun.jersey.client.apache.ApacheHttpClient;
|
||||
import com.sun.jersey.client.apache.config.ApacheHttpClientConfig;
|
||||
import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;
|
||||
@@ -65,7 +64,10 @@ public class AbstractITCaseBase
|
||||
|
||||
/** Field description */
|
||||
public static final String BASE_URL =
|
||||
"http://localhost:8081/scm-webapp/api/rest/";
|
||||
"http://localhost:8080/scm-webapp/api/rest/";
|
||||
|
||||
/** Field description */
|
||||
public static final String EXTENSION = ".xml";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -103,7 +105,7 @@ public class AbstractITCaseBase
|
||||
*/
|
||||
protected Client createClient()
|
||||
{
|
||||
ClientConfig config = new DefaultApacheHttpClientConfig();
|
||||
DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig();
|
||||
|
||||
config.getProperties().put(ApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES,
|
||||
true);
|
||||
@@ -122,7 +124,7 @@ public class AbstractITCaseBase
|
||||
*/
|
||||
protected WebResource createResource(Client client, String url)
|
||||
{
|
||||
return client.resource(BASE_URL.concat(url));
|
||||
return client.resource(BASE_URL.concat(url).concat(EXTENSION));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,7 +140,7 @@ public class AbstractITCaseBase
|
||||
protected ClientResponse login(Client client, String username,
|
||||
String password)
|
||||
{
|
||||
WebResource wr = createResource(client, "authentication/login.json");
|
||||
WebResource wr = createResource(client, "authentication/login");
|
||||
MultivaluedMap<String, String> formData = new MultivaluedMapImpl();
|
||||
|
||||
formData.add("username", username);
|
||||
@@ -156,7 +158,7 @@ public class AbstractITCaseBase
|
||||
*/
|
||||
protected void logout(Client client)
|
||||
{
|
||||
WebResource wr = createResource(client, "authentication/logout.json");
|
||||
WebResource wr = createResource(client, "authentication/logout");
|
||||
ClientResponse response = wr.get(ClientResponse.class);
|
||||
|
||||
assertNotNull(response);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class UserITCase extends AbstractITCaseBase
|
||||
@Test
|
||||
public void get()
|
||||
{
|
||||
WebResource wr = createResource(client, "users/scmadmin.json");
|
||||
WebResource wr = createResource(client, "users/scmadmin");
|
||||
ClientResponse respone = wr.get(ClientResponse.class);
|
||||
|
||||
assertNotNull(respone);
|
||||
@@ -102,11 +102,12 @@ public class UserITCase extends AbstractITCaseBase
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* @Test
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void getAll()
|
||||
{
|
||||
WebResource wr = createResource(client, "users.json");
|
||||
WebResource wr = createResource(client, "users");
|
||||
ClientResponse respone = wr.get(ClientResponse.class);
|
||||
|
||||
assertNotNull(respone);
|
||||
|
||||
Reference in New Issue
Block a user