Search in sources :

Example 1 with UserJson

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);
    })));
}
Also used : UserJson(org.eclipse.openvsx.json.UserJson) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) NamespaceMembershipJson(org.eclipse.openvsx.json.NamespaceMembershipJson) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 2 with UserJson

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);
}
Also used : UserJson(org.eclipse.openvsx.json.UserJson) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with UserJson

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);
    })));
}
Also used : UserJson(org.eclipse.openvsx.json.UserJson) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ExtensionJson(org.eclipse.openvsx.json.ExtensionJson) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Aggregations

UserJson (org.eclipse.openvsx.json.UserJson)3 Test (org.junit.jupiter.api.Test)2 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ExtensionJson (org.eclipse.openvsx.json.ExtensionJson)1 NamespaceMembershipJson (org.eclipse.openvsx.json.NamespaceMembershipJson)1