Search in sources :

Example 31 with ModelInfo

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

the class ModelImporterTest method testUploadAndImportZipWithSameNameDifferentVersion.

@Test
public void testUploadAndImportZipWithSameNameDifferentVersion() throws Exception {
    IUserContext alex = createUserContext("alex", "playground");
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("models.zip", IOUtils.toByteArray(new ClassPathResource("sample_models/models_same_name.zip").getInputStream())), Context.create(alex, Optional.of("org.eclipse.vorto")));
    assertTrue(uploadResult.isValid());
    List<ModelInfo> imported = this.importer.doImport(uploadResult.getHandleId(), Context.create(alex, Optional.of("org.eclipse.vorto")));
    assertEquals(2, imported.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 32 with ModelInfo

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

the class ModelImporterTest method testImportFileWithNonMatchingFileName.

@Test
public void testImportFileWithNonMatchingFileName() {
    IUserContext alex = createUserContext("alex", "playground");
    importModel("Color2.type", alex);
    ModelInfo modelInfo = repositoryFactory.getRepository(alex).search("").get(0);
    assertEquals("Color.type", repositoryFactory.getRepository(alex).getById(modelInfo.getId()).getFileName());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Test(org.junit.Test)

Example 33 with ModelInfo

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

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

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

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