Search in sources :

Example 16 with IUserContext

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

the class RepositoryAdminTest method testBackupFilesNoImages.

@Test
public void testBackupFilesNoImages() throws Exception {
    importModel("Color.type");
    importModel("Colorlight.fbmodel");
    importModel("Switcher.fbmodel");
    importModel("HueLightStrips.infomodel");
    IUserContext admin = createUserContext("admin");
    byte[] backedUpContent = getRepoManager(admin).backup();
    assertNotNull(backedUpContent);
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) Test(org.junit.Test)

Example 17 with IUserContext

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

the class ModelImporterTest method tesUploadValidModel.

@Test
public void tesUploadValidModel() throws IOException {
    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(MessageSeverity.INFO, uploadResult.getReports().get(0).getMessage().getSeverity());
    assertNotNull(uploadResult.getHandleId());
    ModelInfo resource = uploadResult.getReports().get(0).getModel();
    assertEquals("org.eclipse.vorto.examples.type", resource.getId().getNamespace());
    assertEquals("Color", resource.getId().getName());
    assertEquals("1.0.0", resource.getId().getVersion());
    assertEquals(ModelType.Datatype, resource.getType());
    assertEquals(0, resource.getReferences().size());
    assertEquals("Color", resource.getDisplayName());
    assertNull(resource.getDescription());
    assertEquals(0, 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 18 with IUserContext

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

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

the class ModelImporterTest method testUploadFileWithOwnedTargetNamespace.

@Test
public void testUploadFileWithOwnedTargetNamespace() throws Exception {
    IUserContext alex = createUserContext("alex", "playground");
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/vortoprivateColor.type").getInputStream())), Context.create(alex, Optional.of("org.eclipse.vorto")));
    assertEquals(true, uploadResult.isValid());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 20 with IUserContext

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

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