use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.
the class NamespaceControllerIntegrationTest method updateCollaborator.
@Test
public void updateCollaborator() throws Exception {
// creates and adds a collaborator
Collaborator collaborator = new Collaborator(USER_MODEL_CREATOR_NAME, GITHUB, "none", Lists.newArrayList("model_viewer", "model_creator"));
repositoryServer.perform(put("/rest/namespaces/com.mycompany/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isOk());
// checks the collaborator's roles are returned correctly
checkCollaboratorRoles("com.mycompany", USER_MODEL_CREATOR_NAME, "model_viewer", "model_creator");
// creates and adds another collaborator with different roles
collaborator = new Collaborator(USER_MODEL_VIEWER_NAME, GITHUB, "none", Lists.newArrayList("model_viewer"));
repositoryServer.perform(put("/rest/namespaces/com.mycompany/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isOk());
// checks the collaborator's roles are returned correctly
checkCollaboratorRoles("com.mycompany", USER_MODEL_VIEWER_NAME, "model_viewer");
}
use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.
the class NamespaceControllerIntegrationTest method updateCollaboratorUnknownProvider.
/**
* The difference between POST and PUT operations on collaborators essentially boils down to:
* <ul>
* <li>
* POST ops mean creating a new technical user, and therefore validate the whole collaborator
* payload but assume the user does not exist.
* </li>
* <li>
* PUT ops mean adding an existing user to the namespace, and therefore only perform minimal
* validation (i.e. the user name), yet assume the user exists and fail otherwise.
* </li>
* </ul>
*
* @throws Exception
*/
@Test
public void updateCollaboratorUnknownProvider() throws Exception {
// creates the collaborator payload and the existing user
String otherUser = "userstandard2";
Collaborator collaborator = new Collaborator(otherUser, "unknownProvider", null, Lists.newArrayList("model_viewer", "model_creator"));
userRepository.save(new UserBuilder().withName(otherUser).withAuthenticationProviderID(GITHUB).build());
repositoryServer.perform(put("/rest/namespaces/com.mycompany/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isOk());
}
use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.
the class NamespaceControllerIntegrationTest method testAddNamespaceUserWithOneRole.
/**
* Simply tests that adding an existing user to a namespace with a basic role works as intended.
*
* @throws Exception
*/
@Test
public void testAddNamespaceUserWithOneRole() throws Exception {
// first, creates the namespace for the admin user
createNamespaceSuccessfully("myAdminNamespace", userSysadmin);
// then, add the creator user
Collaborator userModelCreatorCollaborator = new Collaborator();
// you would think a user called "userModelCreator" has a username called "userModelCreator", but
// the way it has been mapped to in the parent class is "user3" instead
userModelCreatorCollaborator.setUserId(USER_MODEL_CREATOR_NAME);
Set<String> roles = new HashSet<>();
roles.add("model_viewer");
userModelCreatorCollaborator.setRoles(roles);
repositoryServer.perform(put("/rest/namespaces/myAdminNamespace/users").contentType("application/json").content(objectMapper.writeValueAsString(userModelCreatorCollaborator)).with(userSysadmin)).andExpect(status().isOk()).andExpect(content().string("true"));
}
use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.
the class IntegrationTestBase method checkCollaboratorRoles.
protected void checkCollaboratorRoles(String namespaceName, String collaboratorName, String... roles) throws Exception {
repositoryServer.perform(get(String.format("/rest/namespaces/%s/users", namespaceName)).with(userSysadmin)).andDo(handler -> {
Collection<Collaborator> collaborators = objectMapper.readValue(handler.getResponse().getContentAsString(), new TypeReference<Collection<Collaborator>>() {
});
Optional<Collaborator> maybeTarget = collaborators.stream().filter(c -> c.getUserId().equals(collaboratorName)).findAny();
assertTrue(maybeTarget.isPresent());
if (maybeTarget.isPresent()) {
Collaborator target = maybeTarget.get();
assertEquals(Arrays.asList(roles), target.getRoles());
}
});
}
use of org.eclipse.vorto.repository.web.api.v1.dto.Collaborator in project vorto by eclipse.
the class IntegrationTestBase method userModelCreatorCollaborator.
protected Collaborator userModelCreatorCollaborator() {
Collaborator collaborator = new Collaborator();
collaborator.setUserId(USER_MODEL_CREATOR_NAME);
collaborator.setRoles(Sets.newHashSet("model_creator", "model_viewer"));
collaborator.setAuthenticationProviderId("GITHUB");
collaborator.setTechnicalUser(false);
return collaborator;
}
Aggregations