-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New GroupProvider for the Invite app
- Loading branch information
Showing
10 changed files
with
152 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package voot.provider; | ||
|
||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.RequestEntity; | ||
import org.springframework.http.ResponseEntity; | ||
import voot.model.Group; | ||
import voot.model.Member; | ||
import voot.model.Membership; | ||
|
||
import java.net.URI; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
public class InviteProvider extends AbstractProvider { | ||
|
||
private final String groupMembershipsUrlTemplate; | ||
|
||
public InviteProvider(Configuration configuration) { | ||
super(configuration); | ||
groupMembershipsUrlTemplate = "%s/api/voot/%s"; | ||
} | ||
|
||
@Override | ||
public boolean shouldBeQueriedForMemberships(String schacHomeOrganization) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Set<Group> getGroupMemberships(String uid) { | ||
String uri = String.format(groupMembershipsUrlTemplate, configuration.url, uid); | ||
RequestEntity<List<Map<String, String>>> requestEntity = new RequestEntity<>(HttpMethod.GET, URI.create(uri)); | ||
return restTemplate.exchange(requestEntity, new ParameterizedTypeReference<List<Map<String, String>>>() { | ||
}).getBody().stream() | ||
.map(this::parseGroup) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
private Group parseGroup(Map<String, String> map) { | ||
String name = map.get("name"); | ||
return new Group(map.get("urn"), name, name, "Invite", Membership.MEMBER); | ||
} | ||
|
||
@Override | ||
public Set<Group> getAllGroups() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public Optional<Group> getGroupMembership(String uid, String groupId) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Set<Member> getMembers(String groupId) { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public Set<Member> getMembers(String personId, String groupId) { | ||
return Collections.emptySet(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package voot.provider; | ||
|
||
import com.nimbusds.jose.util.IOUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.core.io.ClassPathResource; | ||
import voot.AbstractTest; | ||
import voot.model.Group; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
|
||
class InviteProviderTest extends AbstractTest { | ||
|
||
private final InviteProvider subject = new InviteProvider( | ||
new Provider.Configuration(GroupProviderType.INVITE, "http://localhost:8889", | ||
new Provider.Configuration.Credentials("user", "password"), | ||
2000, "N/A", "invite")); | ||
|
||
@Test | ||
void getGroupMemberships() throws IOException { | ||
String json = IOUtils.readInputStreamToString(new ClassPathResource("json/invite/group_memberships.json").getInputStream()); | ||
String urn = "urn:collab:person:example.com:admin"; | ||
stubFor(get(urlPathEqualTo("/api/voot/" + urn)) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-type", "application/json"). | ||
withBody(json))); | ||
Set<Group> groupMemberships = subject.getGroupMemberships(urn); | ||
assertEquals(2, groupMemberships.size()); | ||
} | ||
|
||
@Test | ||
void getAllGroups() { | ||
assertEquals(0, subject.getAllGroups().size()); | ||
} | ||
|
||
@Test | ||
void getGroupMembership() { | ||
assertFalse(subject.getGroupMembership("uid", "groupId").isPresent()); | ||
|
||
} | ||
|
||
@Test | ||
void getMembers() { | ||
assertEquals(0, subject.getMembers("groupId").size()); | ||
} | ||
|
||
@Test | ||
void getMembersByPersonId() { | ||
assertEquals(0, subject.getMembers("personId", "groupId").size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"urn": "urn1", | ||
"name": "administrator" | ||
}, | ||
{ | ||
"urn": "urn2", | ||
"name": "guest" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters