Search in sources :

Example 16 with ModelInfo

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

the class WorkflowTest method testStartReleaseModelWithReleasedDependencies.

@Test
public void testStartReleaseModelWithReleasedDependencies() throws Exception {
    ModelInfo typeModel = importModel("Color.type");
    workflow.start(typeModel.getId(), createUserContext("alex", PLAYGROUND));
    ModelInfo fbModel = importModel("Colorlight.fbmodel");
    workflow.start(fbModel.getId(), createUserContext("alex", PLAYGROUND));
    setReleaseState(typeModel);
    when(userRepository.findByUsername(createUserContext(getCallerId(), PLAYGROUND).getUsername())).thenReturn(new UserBuilder().withName(getCallerId()).withAuthenticationProviderID(GITHUB).build());
    fbModel = workflow.doAction(fbModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName());
    assertEquals(SimpleWorkflowModel.STATE_IN_REVIEW.getName(), fbModel.getState());
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 17 with ModelInfo

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

the class WorkflowTest method testTransitionWorkflowInvalidAction.

@Test(expected = WorkflowException.class)
public void testTransitionWorkflowInvalidAction() throws Exception {
    ModelInfo model = importModel("Color.type");
    workflow.start(model.getId(), createUserContext("alex", PLAYGROUND));
    model = workflow.doAction(model.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_APPROVE.getName());
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Test(org.junit.Test)

Example 18 with ModelInfo

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

the class WorkflowTest method testStartReleaseModelWithNonReleasedDependencies.

@Test
public void testStartReleaseModelWithNonReleasedDependencies() throws Exception {
    ModelInfo typeModel = importModel("Color.type");
    workflow.start(typeModel.getId(), createUserContext("alex", PLAYGROUND));
    ModelInfo fbModel = importModel("Colorlight.fbmodel");
    workflow.start(fbModel.getId(), createUserContext("alex", PLAYGROUND));
    when(userRepository.findByUsername(createUserContext(getCallerId(), PLAYGROUND).getUsername())).thenReturn(new UserBuilder().withName(getCallerId()).withAuthenticationProviderID(GITHUB).build());
    workflow.doAction(fbModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName());
    assertEquals("InReview", this.repositoryFactory.getRepositoryByModel(typeModel.getId()).getById(typeModel.getId()).getState());
    assertEquals("InReview", this.repositoryFactory.getRepositoryByModel(fbModel.getId()).getById(fbModel.getId()).getState());
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 19 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo 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 20 with ModelInfo

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

the class WorkflowTest method testGetPossibleActionsForDraftState.

@Test
public void testGetPossibleActionsForDraftState() throws Exception {
    ModelInfo model = importModel("Color.type");
    workflow.start(model.getId(), createUserContext("alex", PLAYGROUND));
    assertEquals(1, workflow.getPossibleActions(model.getId(), createUserContext(getCallerId(), PLAYGROUND)).size());
    assertEquals(SimpleWorkflowModel.ACTION_RELEASE.getName(), workflow.getPossibleActions(model.getId(), createUserContext(getCallerId(), PLAYGROUND)).get(0));
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Test(org.junit.Test)

Aggregations

ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)89 Test (org.junit.Test)33 IUserContext (org.eclipse.vorto.repository.core.IUserContext)32 ModelId (org.eclipse.vorto.model.ModelId)28 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)21 FileContent (org.eclipse.vorto.repository.core.FileContent)11 ClassPathResource (org.springframework.core.io.ClassPathResource)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ModelNotFoundException (org.eclipse.vorto.repository.core.ModelNotFoundException)8 WorkflowException (org.eclipse.vorto.repository.workflow.WorkflowException)8 BeforeClass (org.junit.BeforeClass)7 ResponseEntity (org.springframework.http.ResponseEntity)7 List (java.util.List)6 Optional (java.util.Optional)6 ModelAlreadyExistsException (org.eclipse.vorto.repository.core.ModelAlreadyExistsException)6 NotAuthorizedException (org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)6 DependencyManager (org.eclipse.vorto.repository.core.impl.utils.DependencyManager)5