Search in sources :

Example 21 with IUserContext

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

the class ModelImporterTest method testUploadSameModelTwiceByAuthorWhichIsInDraftState.

@Test
public void testUploadSameModelTwiceByAuthorWhichIsInDraftState() throws Exception {
    IUserContext alex = createUserContext("alex", "playground");
    ModelInfo info = importModel("Color.type", alex);
    this.workflow.start(info.getId(), alex);
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color2.type").getInputStream())), Context.create(alex, Optional.empty()));
    assertTrue(uploadResult.hasWarnings());
    assertTrue(uploadResult.isValid());
    assertTrue(uploadResult.getReport().get(0).isValid());
    assertEquals(ValidationReport.WARNING_MODEL_ALREADY_EXISTS, uploadResult.getReport().get(0).getMessage());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 22 with IUserContext

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

the class ModelImporterTest method testUploadSameModelByAdminDraftState.

@Test
public void testUploadSameModelByAdminDraftState() throws Exception {
    when(userRepositoryRoleService.isSysadmin(any(User.class))).thenReturn(true);
    IUserContext alex = createUserContext("alex", "playground");
    ModelInfo info = importModel("Color.type", alex);
    this.workflow.start(info.getId(), alex);
    IUserContext admin = createUserContext("admin", "playground");
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color2.type").getInputStream())), Context.create(admin, Optional.empty()));
    this.importer.doImport(uploadResult.getHandleId(), Context.create(admin, Optional.empty()));
    ModelFileContent content = repositoryFactory.getRepository(admin).getModelContent(uploadResult.getReports().get(0).getModel().getId(), true);
    assertTrue(uploadResult.hasWarnings());
    assertTrue(new String(content.getContent(), "utf-8").contains("mandatory b as int"));
    assertTrue(uploadResult.isValid());
    assertTrue(uploadResult.getReport().get(0).isValid());
    assertEquals(ValidationReport.WARNING_MODEL_ALREADY_EXISTS, uploadResult.getReport().get(0).getMessage());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelFileContent(org.eclipse.vorto.repository.core.ModelFileContent) User(org.eclipse.vorto.repository.domain.User) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 23 with IUserContext

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

the class ModelImporterTest method testCheckinValidModel.

@Test
public void testCheckinValidModel() throws Exception {
    IUserContext admin = createUserContext("admin", "playground");
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color.type").getInputStream())), Context.create(admin, Optional.empty()));
    assertEquals(true, uploadResult.isValid());
    assertEquals(0, repositoryFactory.getRepository(admin).search("*").size());
    List<ModelInfo> modelInfos = importer.doImport(uploadResult.getHandleId(), Context.create(createUserContext("alex", "playground"), Optional.empty()));
    modelInfos.forEach(resource -> assertEquals(false, resource.getImported()));
    Thread.sleep(1000);
    assertEquals(1, repositoryFactory.getRepository(admin).search("*").size());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 24 with IUserContext

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

the class ModelImporterTest method testUploadSameModelByAdminReleasedState.

@Test
public void testUploadSameModelByAdminReleasedState() throws Exception {
    ModelInfo info = importModel("Color.type", createUserContext("alex", "playground"));
    this.workflow.start(info.getId(), createUserContext("alex", "playground"));
    setReleaseState(info);
    IUserContext admin = createUserContext("admin", "playground");
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color2.type").getInputStream())), Context.create(admin, Optional.empty()));
    assertFalse(uploadResult.hasWarnings());
    assertFalse(uploadResult.isValid());
    assertFalse(uploadResult.getReport().get(0).isValid());
    assertEquals(ValidationReport.ERROR_MODEL_ALREADY_RELEASED, uploadResult.getReport().get(0).getMessage());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 25 with IUserContext

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

the class ModelImporterTest method testUploadSameModelTwiceByAuthorAlreadyReleased.

@Test
public void testUploadSameModelTwiceByAuthorAlreadyReleased() throws Exception {
    IUserContext alex = createUserContext("alex", "playground");
    ModelInfo info = importModel("Color.type", alex);
    this.workflow.start(info.getId(), alex);
    setReleaseState(info);
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color2.type").getInputStream())), Context.create(alex, Optional.empty()));
    assertFalse(uploadResult.hasWarnings());
    assertFalse(uploadResult.isValid());
    assertFalse(uploadResult.getReport().get(0).isValid());
    assertEquals(ValidationReport.ERROR_MODEL_ALREADY_RELEASED, uploadResult.getReport().get(0).getMessage());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

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