Search in sources :

Example 6 with IUserContext

use of org.eclipse.vorto.repository.core.IUserContext in project vorto by eclipse.

the class WorkflowTest method testApproveModelByAdminInReviewState.

@Test
public void testApproveModelByAdminInReviewState() throws Exception {
    ModelInfo model = importModel("creator", "Color.type");
    IUserContext creator = createUserContext("creator", PLAYGROUND);
    IUserContext promoter = createUserContext("promoter", PLAYGROUND);
    IUserContext reviewer = createUserContext("reviewer", PLAYGROUND);
    workflow.start(model.getId(), creator);
    model = workflow.doAction(model.getId(), promoter, SimpleWorkflowModel.ACTION_RELEASE.getName());
    assertEquals(SimpleWorkflowModel.STATE_IN_REVIEW.getName(), model.getState());
    assertEquals(1, workflow.getPossibleActions(model.getId(), promoter).size());
    assertEquals(2, workflow.getPossibleActions(model.getId(), reviewer).size());
    model = workflow.doAction(model.getId(), reviewer, SimpleWorkflowModel.ACTION_APPROVE.getName());
    assertEquals(1, workflow.getModelsByState(SimpleWorkflowModel.STATE_RELEASED.getName(), creator).size());
    assertEquals(0, workflow.getModelsByState(SimpleWorkflowModel.STATE_IN_REVIEW.getName(), creator).size());
    assertEquals(0, workflow.getModelsByState(SimpleWorkflowModel.STATE_DRAFT.getName(), creator).size());
    assertEquals(0, workflow.getPossibleActions(model.getId(), creator).size());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Test(org.junit.Test)

Example 7 with IUserContext

use of org.eclipse.vorto.repository.core.IUserContext in project vorto by eclipse.

the class WorkflowTest method testGetModelByState.

@Test
public void testGetModelByState() throws Exception {
    IUserContext user = createUserContext("admin", PLAYGROUND);
    ModelInfo model = importModel("Color.type");
    workflow.start(model.getId(), user);
    assertEquals(1, workflow.getModelsByState(SimpleWorkflowModel.STATE_DRAFT.getName(), user).size());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Test(org.junit.Test)

Example 8 with IUserContext

use of org.eclipse.vorto.repository.core.IUserContext in project vorto by eclipse.

the class WorkflowTest method testApproveModelByModelReviewerInReviewState.

@Test
public void testApproveModelByModelReviewerInReviewState() throws Exception {
    ModelInfo model = importModel("creator", "Color.type");
    IUserContext user = createUserContext("creator", PLAYGROUND);
    IUserContext promoter = createUserContext("promoter", PLAYGROUND);
    workflow.start(model.getId(), user);
    model = workflow.doAction(model.getId(), promoter, SimpleWorkflowModel.ACTION_RELEASE.getName());
    assertEquals(SimpleWorkflowModel.STATE_IN_REVIEW.getName(), model.getState());
    assertEquals(1, workflow.getPossibleActions(model.getId(), promoter).size());
    assertEquals(2, workflow.getPossibleActions(model.getId(), createUserContext("reviewer", PLAYGROUND)).size());
    model = workflow.doAction(model.getId(), createUserContext("reviewer", PLAYGROUND), SimpleWorkflowModel.ACTION_APPROVE.getName());
    assertEquals(1, workflow.getModelsByState(SimpleWorkflowModel.STATE_RELEASED.getName(), user).size());
    assertEquals(0, workflow.getModelsByState(SimpleWorkflowModel.STATE_IN_REVIEW.getName(), user).size());
    assertEquals(0, workflow.getModelsByState(SimpleWorkflowModel.STATE_DRAFT.getName(), user).size());
    assertEquals(0, workflow.getPossibleActions(model.getId(), user).size());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Test(org.junit.Test)

Example 9 with IUserContext

use of org.eclipse.vorto.repository.core.IUserContext in project vorto by eclipse.

the class UserAccountServiceTest method testRemoveAccountWithModelsByUser.

@Test
public void testRemoveAccountWithModelsByUser() throws Exception {
    IUserContext alex = createUserContext("alex");
    IUserContext admin = createUserContext("admin");
    this.workflow.start(importModel("Color.type", alex).getId(), alex);
    this.workflow.start(importModel("Colorlight.fbmodel", alex).getId(), alex);
    importModel("Switcher.fbmodel", admin);
    importModel("ColorLightIM.infomodel", admin);
    importModel("HueLightStrips.infomodel", admin);
    assertEquals(2, getModelRepository(alex).search("author:" + alex.getUsername()).size());
    userService.delete("alex", "alex");
    assertEquals(0, getModelRepository(alex).search("author:" + alex.getUsername()).size());
    assertEquals(2, getModelRepository(alex).search("author:anonymous").size());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) Test(org.junit.Test)

Example 10 with IUserContext

use of org.eclipse.vorto.repository.core.IUserContext in project vorto by eclipse.

the class ModelIdToModelContentConverterTest method setupTestDataForLatestTag.

private void setupTestDataForLatestTag() throws WorkflowException {
    IUserContext user = createUserContext("alex", "playground");
    ModelInfo color = importModel("Color.type");
    ModelInfo color6 = importModel("Color6.type");
    importModel("Color7.type");
    importModel("sample.mapping");
    color.setState(ModelState.Released.getName());
    color6.setState(ModelState.Released.getName());
    this.workflow.start(color.getId(), user);
    this.workflow.start(color6.getId(), user);
    setReleaseState(color);
    setReleaseState(color6);
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo)

Aggregations

IUserContext (org.eclipse.vorto.repository.core.IUserContext)54 Test (org.junit.Test)32 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)28 ClassPathResource (org.springframework.core.io.ClassPathResource)18 ResponseEntity (org.springframework.http.ResponseEntity)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 DoesNotExistException (org.eclipse.vorto.repository.services.exceptions.DoesNotExistException)10 OperationForbiddenException (org.eclipse.vorto.repository.services.exceptions.OperationForbiddenException)8 ModelId (org.eclipse.vorto.model.ModelId)7 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)6 User (org.eclipse.vorto.repository.domain.User)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 PutMapping (org.springframework.web.bind.annotation.PutMapping)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Namespace (org.eclipse.vorto.repository.domain.Namespace)4 ApiOperation (io.swagger.annotations.ApiOperation)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 ModelResource (org.eclipse.vorto.repository.core.ModelResource)3 InvalidUserException (org.eclipse.vorto.repository.services.exceptions.InvalidUserException)3