mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
Use provider for group sub resources
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package sonia.scm.api.v2.resources;
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Provider;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
@Path(GroupRootResource.GROUPS_PATH_V2)
|
@Path(GroupRootResource.GROUPS_PATH_V2)
|
||||||
@@ -8,22 +9,23 @@ public class GroupRootResource {
|
|||||||
|
|
||||||
public static final String GROUPS_PATH_V2 = "v2/groups/";
|
public static final String GROUPS_PATH_V2 = "v2/groups/";
|
||||||
|
|
||||||
private final GroupCollectionResource groupCollectionResource;
|
private final Provider<GroupCollectionResource> groupCollectionResource;
|
||||||
private final GroupResource groupResource;
|
private final Provider<GroupResource> groupResource;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GroupRootResource(GroupCollectionResource groupCollectionResource, GroupResource groupResource) {
|
public GroupRootResource(Provider<GroupCollectionResource> groupCollectionResource,
|
||||||
|
Provider<GroupResource> groupResource) {
|
||||||
this.groupCollectionResource = groupCollectionResource;
|
this.groupCollectionResource = groupCollectionResource;
|
||||||
this.groupResource = groupResource;
|
this.groupResource = groupResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("")
|
@Path("")
|
||||||
public GroupCollectionResource getGroupCollectionResource() {
|
public GroupCollectionResource getGroupCollectionResource() {
|
||||||
return groupCollectionResource;
|
return groupCollectionResource.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public GroupResource getGroupResource() {
|
public GroupResource getGroupResource() {
|
||||||
return groupResource;
|
return groupResource.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,36 +45,33 @@ public class GroupRootResourceTest {
|
|||||||
|
|
||||||
private Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
|
private Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
|
||||||
|
|
||||||
@Mock
|
|
||||||
private GroupManager groupManager;
|
|
||||||
@Mock
|
@Mock
|
||||||
private UriInfo uriInfo;
|
private UriInfo uriInfo;
|
||||||
@Mock
|
@Mock
|
||||||
private UriInfoStore uriInfoStore;
|
private UriInfoStore uriInfoStore;
|
||||||
@InjectMocks
|
|
||||||
GroupDtoToGroupMapperImpl dtoToGroupMapper;
|
|
||||||
@InjectMocks
|
|
||||||
GroupToGroupDtoMapperImpl groupToDtoMapper;
|
|
||||||
@InjectMocks
|
|
||||||
GroupCollectionToDtoMapper groupCollectionToDtoMapper;
|
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private GroupManager groupManager;
|
||||||
|
@InjectMocks
|
||||||
|
private GroupDtoToGroupMapperImpl dtoToGroupMapper;
|
||||||
|
@InjectMocks
|
||||||
|
private GroupToGroupDtoMapperImpl groupToDtoMapper;
|
||||||
|
@InjectMocks
|
||||||
|
private GroupCollectionToDtoMapper groupCollectionToDtoMapper;
|
||||||
|
|
||||||
ArgumentCaptor<Group> groupCaptor = ArgumentCaptor.forClass(Group.class);
|
private ArgumentCaptor<Group> groupCaptor = ArgumentCaptor.forClass(Group.class);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepareEnvironment() throws IOException, GroupException {
|
public void prepareEnvironment() throws IOException, GroupException {
|
||||||
initMocks(this);
|
initMocks(this);
|
||||||
doNothing().when(groupManager).create(groupCaptor.capture());
|
doNothing().when(groupManager).create(groupCaptor.capture());
|
||||||
|
|
||||||
Group group = new Group();
|
Group group = createDummyGroup();
|
||||||
group.setName("admin");
|
|
||||||
group.setCreationDate(0L);
|
|
||||||
group.setMembers(Collections.singletonList("user"));
|
|
||||||
when(groupManager.get("admin")).thenReturn(group);
|
when(groupManager.get("admin")).thenReturn(group);
|
||||||
|
|
||||||
GroupCollectionResource groupCollectionResource = new GroupCollectionResource(groupManager, dtoToGroupMapper, groupToDtoMapper, groupCollectionToDtoMapper);
|
GroupCollectionResource groupCollectionResource = new GroupCollectionResource(groupManager, dtoToGroupMapper, groupToDtoMapper, groupCollectionToDtoMapper);
|
||||||
GroupResource groupResource = new GroupResource(groupManager, groupToDtoMapper);
|
GroupResource groupResource = new GroupResource(groupManager, groupToDtoMapper);
|
||||||
GroupRootResource groupRootResource = new GroupRootResource(groupCollectionResource, groupResource);
|
GroupRootResource groupRootResource = new GroupRootResource(MockProvider.of(groupCollectionResource), MockProvider.of(groupResource));
|
||||||
|
|
||||||
dispatcher.getRegistry().addSingletonResource(groupRootResource);
|
dispatcher.getRegistry().addSingletonResource(groupRootResource);
|
||||||
|
|
||||||
@@ -105,10 +102,7 @@ public class GroupRootResourceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldGetGroup() throws URISyntaxException {
|
public void shouldGetGroup() throws URISyntaxException {
|
||||||
Group group = new Group();
|
Group group = createDummyGroup();
|
||||||
group.setName("admin");
|
|
||||||
group.setCreationDate(0L);
|
|
||||||
group.setMembers(Collections.singletonList("user"));
|
|
||||||
when(groupManager.get("admin")).thenReturn(group);
|
when(groupManager.get("admin")).thenReturn(group);
|
||||||
|
|
||||||
MockHttpRequest request = MockHttpRequest.get("/" + GroupRootResource.GROUPS_PATH_V2 + "admin");
|
MockHttpRequest request = MockHttpRequest.get("/" + GroupRootResource.GROUPS_PATH_V2 + "admin");
|
||||||
@@ -142,4 +136,12 @@ public class GroupRootResourceTest {
|
|||||||
assertEquals(2, createdGroup.getMembers().size());
|
assertEquals(2, createdGroup.getMembers().size());
|
||||||
assertEquals("user1", createdGroup.getMembers().get(0));
|
assertEquals("user1", createdGroup.getMembers().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Group createDummyGroup() {
|
||||||
|
Group group = new Group();
|
||||||
|
group.setName("admin");
|
||||||
|
group.setCreationDate(0L);
|
||||||
|
group.setMembers(Collections.singletonList("user"));
|
||||||
|
return group;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user