use of org.eclipse.openvsx.json.UserJson in project openvsx by eclipse.
the class AdminAPITest method testGetNamespaceMembers.
@Test
public void testGetNamespaceMembers() throws Exception {
mockAdminUser();
var namespace = mockNamespace();
var user = new UserData();
user.setLoginName("other_user");
var membership1 = new NamespaceMembership();
membership1.setNamespace(namespace);
membership1.setUser(user);
membership1.setRole(NamespaceMembership.ROLE_OWNER);
Mockito.when(repositories.findMemberships(namespace)).thenReturn(Streamable.of(membership1));
mockMvc.perform(get("/admin/namespace/{namespace}/members", "foobar").with(user("admin_user").authorities(new SimpleGrantedAuthority(("ROLE_ADMIN")))).with(csrf().asHeader())).andExpect(status().isOk()).andExpect(content().json(namespaceMemberJson(nml -> {
var m = new NamespaceMembershipJson();
m.namespace = "foobar";
m.user = new UserJson();
m.user.loginName = "other_user";
m.role = "owner";
nml.namespaceMemberships = Arrays.asList(m);
})));
}
use of org.eclipse.openvsx.json.UserJson in project openvsx by eclipse.
the class UserAPITest method userJson.
private String userJson(Consumer<UserJson> content) throws JsonProcessingException {
var json = new UserJson();
content.accept(json);
return new ObjectMapper().writeValueAsString(json);
}
use of org.eclipse.openvsx.json.UserJson in project openvsx by eclipse.
the class AdminAPITest method testGetUserPublishInfo.
@Test
public void testGetUserPublishInfo() throws Exception {
mockAdminUser();
var versions = mockExtension(1, 0, 0);
var user = new UserData();
user.setLoginName("test");
user.setProvider("github");
Mockito.when(repositories.findUserByLoginName("github", "test")).thenReturn(user);
var token = new PersonalAccessToken();
token.setUser(user);
token.setActive(true);
Mockito.when(repositories.findAccessTokens(user)).thenReturn(Streamable.of(token));
versions.forEach(v -> v.setPublishedWith(token));
Mockito.when(repositories.findVersionsByAccessToken(token)).thenReturn(Streamable.of(versions));
mockMvc.perform(get("/admin/publisher/{provider}/{loginName}", "github", "test").with(user("admin_user").authorities(new SimpleGrantedAuthority(("ROLE_ADMIN")))).with(csrf().asHeader())).andExpect(status().isOk()).andExpect(content().json(publishInfoJson(upi -> {
upi.user = new UserJson();
upi.user.loginName = "test";
upi.activeAccessTokenNum = 1;
var ext1 = new ExtensionJson();
ext1.namespace = "foobar";
ext1.name = "baz";
ext1.version = "1";
upi.extensions = Arrays.asList(ext1);
})));
}
Aggregations