Search in sources :

Example 36 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryDiagnosticsTest method testGetModelIdOnFileNode.

@Test
public void testGetModelIdOnFileNode() {
    ModelId modelId = NodeDiagnosticUtils.getModelId("/com/ipso/smartobjects/load_control/1.1.0/Load_Control.fbmodel").get();
    assertEquals("load_control", modelId.getName());
    assertEquals("com.ipso.smartobjects", modelId.getNamespace());
    assertEquals("1.1.0", modelId.getVersion());
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 37 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class IndexingTest method deletingAModelShouldUpdateTheIndex.

@Test
public void deletingAModelShouldUpdateTheIndex() {
    IUserContext creator = createUserContext("creator", "playground");
    importModel("creator", "ColorEnum.type");
    repositoryFactory.getRepository(creator).removeModel(MODEL_ID);
    ArgumentCaptor<ModelId> captor = ArgumentCaptor.forClass(ModelId.class);
    Mockito.verify(indexingService, Mockito.times(1)).deleteIndex(captor.capture());
    ModelId modelId = captor.getValue();
    assertEquals(modelId.getNamespace(), "org.eclipse.vorto.examples.type");
    assertEquals(modelId.getName(), "ColorEnum");
    assertEquals(modelId.getVersion(), "1.0.0");
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 38 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class BulkOperationServiceTest method makeModelPublic.

@Test
public void makeModelPublic() {
    importModel("creator", "officialprefix_point3d.type");
    try {
        releaseModel(ModelId.fromPrettyFormat("com.mycompany:Point3d:1.0.0"), createUserContext("creator"));
    } catch (WorkflowException e) {
        fail("Cannot release newly imported model?");
    }
    checkCorrectness("com.mycompany:Point3d:1.0.0", "private", "Released");
    IBulkOperationsService modelService = getModelService("publisher");
    List<ModelId> result = modelService.makeModelPublic(ModelId.fromPrettyFormat("com.mycompany:Point3d:1.0.0"));
    assertEquals(1, result.size());
    ModelInfo modelInfo = getModelRepository(createUserContext("creator")).getById(ModelId.fromPrettyFormat("com.mycompany:Point3d:1.0.0"));
    assertEquals("public", modelInfo.getVisibility());
    assertTrue(hasAnonymousPolicy("com.mycompany:Point3d:1.0.0"));
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 39 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryAttachmentTest method testDeleteModelWithImportedAttachment.

@Test
public void testDeleteModelWithImportedAttachment() throws Exception {
    IUserContext erle = createUserContext("erle", "playground");
    importModel("Color.type", erle);
    assertEquals(1, repositoryFactory.getRepository(erle).search("*").size());
    ModelId modelId = new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0");
    repositoryFactory.getRepository(erle).attachFile(modelId, new FileContent("backup1.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup1.xml").getInputStream())), erle, Attachment.TAG_IMPORTED);
    this.repositoryFactory.getRepository(erle).removeModel(modelId);
    assertEquals(0, repositoryFactory.getRepository(erle).search("*").size());
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 40 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryAttachmentTest method testAttachNewFile.

@Test
public void testAttachNewFile() {
    IUserContext erle = createUserContext("erle", "playground");
    importModel("Color.type", erle);
    try {
        repositoryFactory.getRepository(erle).attachFile(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), new FileContent("backup1.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup1.xml").getInputStream())), erle);
        List<Attachment> attachments = repositoryFactory.getRepository(erle).getAttachments(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"));
        assertEquals(1, attachments.size());
        assertEquals("backup1.xml", attachments.get(0).getFilename());
        assertEquals(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), attachments.get(0).getModelId());
        assertEquals(0, attachments.get(0).getTags().size());
    } catch (IOException | FatalModelRepositoryException e) {
        e.printStackTrace();
        fail("Cannot load sample file");
    }
}
Also used : IOException(java.io.IOException) ModelId(org.eclipse.vorto.model.ModelId) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

ModelId (org.eclipse.vorto.model.ModelId)124 Test (org.junit.Test)48 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)29 IOException (java.io.IOException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)19 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ResponseEntity (org.springframework.http.ResponseEntity)14 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)13 ModelType (org.eclipse.vorto.model.ModelType)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)12 Autowired (org.springframework.beans.factory.annotation.Autowired)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 Optional (java.util.Optional)10 List (java.util.List)9 IOUtils (org.apache.commons.io.IOUtils)9 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)9 ModelLink (org.eclipse.vorto.repository.web.api.v1.dto.ModelLink)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ApiOperation (io.swagger.annotations.ApiOperation)8