mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
Renames User resource classes
This commit is contained in:
@@ -59,19 +59,19 @@ class ResourceLinks {
|
|||||||
private final LinkBuilder userLinkBuilder;
|
private final LinkBuilder userLinkBuilder;
|
||||||
|
|
||||||
private UserLinks(UriInfo uriInfo) {
|
private UserLinks(UriInfo uriInfo) {
|
||||||
userLinkBuilder = new LinkBuilder(uriInfo, UserV2Resource.class, UserSubResource.class);
|
userLinkBuilder = new LinkBuilder(uriInfo, UserRootResource.class, UserResource.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
String self(String name) {
|
String self(String name) {
|
||||||
return userLinkBuilder.method("getUserSubResource").parameters(name).method("get").parameters().href();
|
return userLinkBuilder.method("getUserResource").parameters(name).method("get").parameters().href();
|
||||||
}
|
}
|
||||||
|
|
||||||
String delete(String name) {
|
String delete(String name) {
|
||||||
return userLinkBuilder.method("getUserSubResource").parameters(name).method("delete").parameters().href();
|
return userLinkBuilder.method("getUserResource").parameters(name).method("delete").parameters().href();
|
||||||
}
|
}
|
||||||
|
|
||||||
String update(String name) {
|
String update(String name) {
|
||||||
return userLinkBuilder.method("getUserSubResource").parameters(name).method("update").parameters().href();
|
return userLinkBuilder.method("getUserResource").parameters(name).method("update").parameters().href();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ class ResourceLinks {
|
|||||||
private final LinkBuilder collectionLinkBuilder;
|
private final LinkBuilder collectionLinkBuilder;
|
||||||
|
|
||||||
private UserCollectionLinks(UriInfo uriInfo) {
|
private UserCollectionLinks(UriInfo uriInfo) {
|
||||||
collectionLinkBuilder = new LinkBuilder(uriInfo, UserV2Resource.class, UserCollectionResource.class);
|
collectionLinkBuilder = new LinkBuilder(uriInfo, UserRootResource.class, UserCollectionResource.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
String self() {
|
String self() {
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ public class UserCollectionToDtoMapper {
|
|||||||
public UserCollectionToDtoMapper() {
|
public UserCollectionToDtoMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public UserCollectionDto map(int pageNumber, int pageSize, PageResult<User> pageResult) {
|
public UserCollectionDto map(int pageNumber, int pageSize, PageResult<User> pageResult) {
|
||||||
NumberedPaging paging = zeroBasedNumberedPaging(pageNumber, pageSize, pageResult.hasMore());
|
NumberedPaging paging = zeroBasedNumberedPaging(pageNumber, pageSize, pageResult.hasMore());
|
||||||
List<UserDto> dtos = pageResult.getEntities().stream().map(userToDtoMapper::map).collect(Collectors.toList());
|
List<UserDto> dtos = pageResult.getEntities().stream().map(userToDtoMapper::map).collect(Collectors.toList());
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ import java.util.Collection;
|
|||||||
|
|
||||||
|
|
||||||
@Produces(VndMediaType.USER)
|
@Produces(VndMediaType.USER)
|
||||||
public class UserSubResource extends AbstractManagerResource<User, UserException> {
|
public class UserResource extends AbstractManagerResource<User, UserException> {
|
||||||
private final UserDtoToUserMapper dtoToUserMapper;
|
private final UserDtoToUserMapper dtoToUserMapper;
|
||||||
private final UserToUserDtoMapper userToDtoMapper;
|
private final UserToUserDtoMapper userToDtoMapper;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public UserSubResource(UserDtoToUserMapper dtoToUserMapper, UserToUserDtoMapper userToDtoMapper, UserManager manager) {
|
public UserResource(UserDtoToUserMapper dtoToUserMapper, UserToUserDtoMapper userToDtoMapper, UserManager manager) {
|
||||||
super(manager);
|
super(manager);
|
||||||
this.dtoToUserMapper = dtoToUserMapper;
|
this.dtoToUserMapper = dtoToUserMapper;
|
||||||
this.userToDtoMapper = userToDtoMapper;
|
this.userToDtoMapper = userToDtoMapper;
|
||||||
@@ -4,17 +4,17 @@ import com.google.inject.Inject;
|
|||||||
|
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
@Path(UserV2Resource.USERS_PATH_V2)
|
@Path(UserRootResource.USERS_PATH_V2)
|
||||||
public class UserV2Resource {
|
public class UserRootResource {
|
||||||
|
|
||||||
public static final String USERS_PATH_V2 = "v2/users/";
|
public static final String USERS_PATH_V2 = "v2/users/";
|
||||||
private final UserCollectionResource userCollectionResource;
|
private final UserCollectionResource userCollectionResource;
|
||||||
private final UserSubResource userSubResource;
|
private final UserResource userResource;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public UserV2Resource(UserCollectionResource userCollectionResource, UserSubResource userSubResource) {
|
public UserRootResource(UserCollectionResource userCollectionResource, UserResource userResource) {
|
||||||
this.userCollectionResource = userCollectionResource;
|
this.userCollectionResource = userCollectionResource;
|
||||||
this.userSubResource = userSubResource;
|
this.userResource = userResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("")
|
@Path("")
|
||||||
@@ -23,7 +23,7 @@ public class UserV2Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public UserSubResource getUserSubResource() {
|
public UserResource getUserResource() {
|
||||||
return userSubResource;
|
return userResource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,31 +22,31 @@ public class ResourceLinksTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldCreateCorrectUserSelfUrl() {
|
public void shouldCreateCorrectUserSelfUrl() {
|
||||||
String url = user(uriInfo).self("ich");
|
String url = user(uriInfo).self("ich");
|
||||||
assertEquals(BASE_URL + UserV2Resource.USERS_PATH_V2 + "ich", url);
|
assertEquals(BASE_URL + UserRootResource.USERS_PATH_V2 + "ich", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateCorrectUserDeleteUrl() {
|
public void shouldCreateCorrectUserDeleteUrl() {
|
||||||
String url = user(uriInfo).delete("ich");
|
String url = user(uriInfo).delete("ich");
|
||||||
assertEquals(BASE_URL + UserV2Resource.USERS_PATH_V2 + "ich", url);
|
assertEquals(BASE_URL + UserRootResource.USERS_PATH_V2 + "ich", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateCorrectUserUpdateUrl() {
|
public void shouldCreateCorrectUserUpdateUrl() {
|
||||||
String url = user(uriInfo).update("ich");
|
String url = user(uriInfo).update("ich");
|
||||||
assertEquals(BASE_URL + UserV2Resource.USERS_PATH_V2 + "ich", url);
|
assertEquals(BASE_URL + UserRootResource.USERS_PATH_V2 + "ich", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateCorrectUserCreateUrl() {
|
public void shouldCreateCorrectUserCreateUrl() {
|
||||||
String url = userCollection(uriInfo).create();
|
String url = userCollection(uriInfo).create();
|
||||||
assertEquals(BASE_URL + UserV2Resource.USERS_PATH_V2, url);
|
assertEquals(BASE_URL + UserRootResource.USERS_PATH_V2, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateCorrectUserCollectionUrl() {
|
public void shouldCreateCorrectUserCollectionUrl() {
|
||||||
String url = userCollection(uriInfo).self();
|
String url = userCollection(uriInfo).self();
|
||||||
assertEquals(BASE_URL + UserV2Resource.USERS_PATH_V2, url);
|
assertEquals(BASE_URL + UserRootResource.USERS_PATH_V2, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class UserCollectionToDtoMapperTest {
|
|||||||
public void init() throws URISyntaxException {
|
public void init() throws URISyntaxException {
|
||||||
initMocks(this);
|
initMocks(this);
|
||||||
URI baseUri = new URI("http://example.com/base/");
|
URI baseUri = new URI("http://example.com/base/");
|
||||||
expectedBaseUri = baseUri.resolve(UserV2Resource.USERS_PATH_V2 + "/");
|
expectedBaseUri = baseUri.resolve(UserRootResource.USERS_PATH_V2 + "/");
|
||||||
when(uriInfo.getBaseUri()).thenReturn(baseUri);
|
when(uriInfo.getBaseUri()).thenReturn(baseUri);
|
||||||
when(uriInfoStore.get()).thenReturn(uriInfo);
|
when(uriInfoStore.get()).thenReturn(uriInfo);
|
||||||
subjectThreadState.bind();
|
subjectThreadState.bind();
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
|||||||
password = "secret",
|
password = "secret",
|
||||||
configuration = "classpath:sonia/scm/repository/shiro.ini"
|
configuration = "classpath:sonia/scm/repository/shiro.ini"
|
||||||
)
|
)
|
||||||
public class UserV2ResourceTest {
|
public class UserRootResourceTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ShiroRule shiro = new ShiroRule();
|
public ShiroRule shiro = new ShiroRule();
|
||||||
@@ -78,17 +78,17 @@ public class UserV2ResourceTest {
|
|||||||
|
|
||||||
userCollectionToDtoMapper = new UserCollectionToDtoMapper(userToDtoMapper, uriInfoStore);
|
userCollectionToDtoMapper = new UserCollectionToDtoMapper(userToDtoMapper, uriInfoStore);
|
||||||
UserCollectionResource userCollectionResource = new UserCollectionResource(userManager, dtoToUserMapper, userToDtoMapper, userCollectionToDtoMapper);
|
UserCollectionResource userCollectionResource = new UserCollectionResource(userManager, dtoToUserMapper, userToDtoMapper, userCollectionToDtoMapper);
|
||||||
UserSubResource userSubResource = new UserSubResource(dtoToUserMapper, userToDtoMapper, userManager);
|
UserResource userResource = new UserResource(dtoToUserMapper, userToDtoMapper, userManager);
|
||||||
UserV2Resource userV2Resource = new UserV2Resource(userCollectionResource, userSubResource);
|
UserRootResource userRootResource = new UserRootResource(userCollectionResource, userResource);
|
||||||
|
|
||||||
dispatcher.getRegistry().addSingletonResource(userV2Resource);
|
dispatcher.getRegistry().addSingletonResource(userRootResource);
|
||||||
when(uriInfo.getBaseUri()).thenReturn(URI.create("/"));
|
when(uriInfo.getBaseUri()).thenReturn(URI.create("/"));
|
||||||
when(uriInfoStore.get()).thenReturn(uriInfo);
|
when(uriInfoStore.get()).thenReturn(uriInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateFullResponseForAdmin() throws URISyntaxException {
|
public void shouldCreateFullResponseForAdmin() throws URISyntaxException {
|
||||||
MockHttpRequest request = MockHttpRequest.get("/" + UserV2Resource.USERS_PATH_V2 + "Neo");
|
MockHttpRequest request = MockHttpRequest.get("/" + UserRootResource.USERS_PATH_V2 + "Neo");
|
||||||
MockHttpResponse response = new MockHttpResponse();
|
MockHttpResponse response = new MockHttpResponse();
|
||||||
|
|
||||||
dispatcher.invoke(request, response);
|
dispatcher.invoke(request, response);
|
||||||
@@ -104,7 +104,7 @@ public class UserV2ResourceTest {
|
|||||||
@Test
|
@Test
|
||||||
@SubjectAware(username = "unpriv")
|
@SubjectAware(username = "unpriv")
|
||||||
public void shouldCreateLimitedResponseForSimpleUser() throws URISyntaxException {
|
public void shouldCreateLimitedResponseForSimpleUser() throws URISyntaxException {
|
||||||
MockHttpRequest request = MockHttpRequest.get("/" + UserV2Resource.USERS_PATH_V2);
|
MockHttpRequest request = MockHttpRequest.get("/" + UserRootResource.USERS_PATH_V2);
|
||||||
MockHttpResponse response = new MockHttpResponse();
|
MockHttpResponse response = new MockHttpResponse();
|
||||||
|
|
||||||
dispatcher.invoke(request, response);
|
dispatcher.invoke(request, response);
|
||||||
@@ -119,7 +119,7 @@ public class UserV2ResourceTest {
|
|||||||
@Test
|
@Test
|
||||||
@SubjectAware(username = "unpriv")
|
@SubjectAware(username = "unpriv")
|
||||||
public void shouldNotGetSingleUserForSimpleUser() throws URISyntaxException {
|
public void shouldNotGetSingleUserForSimpleUser() throws URISyntaxException {
|
||||||
MockHttpRequest request = MockHttpRequest.get("/" + UserV2Resource.USERS_PATH_V2 + "Neo");
|
MockHttpRequest request = MockHttpRequest.get("/" + UserRootResource.USERS_PATH_V2 + "Neo");
|
||||||
MockHttpResponse response = new MockHttpResponse();
|
MockHttpResponse response = new MockHttpResponse();
|
||||||
|
|
||||||
dispatcher.invoke(request, response);
|
dispatcher.invoke(request, response);
|
||||||
@@ -133,7 +133,7 @@ public class UserV2ResourceTest {
|
|||||||
byte[] userJson = Resources.toByteArray(url);
|
byte[] userJson = Resources.toByteArray(url);
|
||||||
|
|
||||||
MockHttpRequest request = MockHttpRequest
|
MockHttpRequest request = MockHttpRequest
|
||||||
.post("/" + UserV2Resource.USERS_PATH_V2)
|
.post("/" + UserRootResource.USERS_PATH_V2)
|
||||||
.contentType(VndMediaType.USER)
|
.contentType(VndMediaType.USER)
|
||||||
.content(userJson);
|
.content(userJson);
|
||||||
MockHttpResponse response = new MockHttpResponse();
|
MockHttpResponse response = new MockHttpResponse();
|
||||||
@@ -150,7 +150,7 @@ public class UserV2ResourceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldFailForMissingContent() throws URISyntaxException {
|
public void shouldFailForMissingContent() throws URISyntaxException {
|
||||||
MockHttpRequest request = MockHttpRequest
|
MockHttpRequest request = MockHttpRequest
|
||||||
.post("/" + UserV2Resource.USERS_PATH_V2)
|
.post("/" + UserRootResource.USERS_PATH_V2)
|
||||||
.contentType(VndMediaType.USER)
|
.contentType(VndMediaType.USER)
|
||||||
.content(new byte[] {});
|
.content(new byte[] {});
|
||||||
MockHttpResponse response = new MockHttpResponse();
|
MockHttpResponse response = new MockHttpResponse();
|
||||||
@@ -42,7 +42,7 @@ public class UserToUserDtoMapperTest {
|
|||||||
public void init() throws URISyntaxException {
|
public void init() throws URISyntaxException {
|
||||||
initMocks(this);
|
initMocks(this);
|
||||||
URI baseUri = new URI("http://example.com/base/");
|
URI baseUri = new URI("http://example.com/base/");
|
||||||
expectedBaseUri = baseUri.resolve(UserV2Resource.USERS_PATH_V2 + "/");
|
expectedBaseUri = baseUri.resolve(UserRootResource.USERS_PATH_V2 + "/");
|
||||||
when(uriInfo.getBaseUri()).thenReturn(baseUri);
|
when(uriInfo.getBaseUri()).thenReturn(baseUri);
|
||||||
when(uriInfoStore.get()).thenReturn(uriInfo);
|
when(uriInfoStore.get()).thenReturn(uriInfo);
|
||||||
subjectThreadState.bind();
|
subjectThreadState.bind();
|
||||||
|
|||||||
Reference in New Issue
Block a user