Search in sources :

Example 26 with ModelInfo

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

the class IndexingTest method updatingAModelStateShouldUpdateTheIndex.

@Test
public void updatingAModelStateShouldUpdateTheIndex() {
    IUserContext creator = createUserContext("creator", "playground");
    importModel("creator", "ColorEnum.type");
    repositoryFactory.getRepository(creator).updateState(MODEL_ID, ModelState.Draft.getName());
    ArgumentCaptor<ModelInfo> captor = ArgumentCaptor.forClass(ModelInfo.class);
    Mockito.verify(indexingService, Mockito.times(1)).updateIndex(captor.capture());
    ModelInfo savedModel = captor.getValue();
    assertEquals(savedModel.getState(), ModelState.Draft.getName());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Test(org.junit.Test)

Example 27 with ModelInfo

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

the class IndexingTest method savingAModelShouldIndexIt.

@Test
public void savingAModelShouldIndexIt() {
    IUserContext creator = createUserContext("creator", "playground");
    try {
        repositoryFactory.getRepository(creator).save(MODEL_ID, IOUtils.toByteArray(new ClassPathResource("sample_models/ColorEnum.type").getInputStream()), "ColorEnum.type", creator);
        ArgumentCaptor<ModelInfo> captor = ArgumentCaptor.forClass(ModelInfo.class);
        Mockito.verify(indexingService, Mockito.times(1)).indexModel(captor.capture(), Mockito.endsWith("playground"));
        ModelInfo savedModel = captor.getValue();
        assertEquals(savedModel.getId().getNamespace(), "org.eclipse.vorto.examples.type");
        assertEquals(savedModel.getId().getName(), "ColorEnum");
        assertEquals(savedModel.getId().getVersion(), "1.0.0");
        assertEquals(savedModel.getType(), ModelType.Datatype);
        assertEquals(savedModel.getAuthor(), "creator");
        assertNull(savedModel.getState());
    } catch (IOException e) {
        fail();
    }
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 28 with ModelInfo

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

the class IndexingTest method updatingAModelShouldUpdateTheIndex.

@Test
public void updatingAModelShouldUpdateTheIndex() {
    IUserContext creator = createUserContext("creator", "playground");
    importModel("creator", "ColorEnum.type");
    ModelInfo modelInfo = repositoryFactory.getRepository(creator).getById(MODEL_ID);
    modelInfo.setAuthor("newauthor");
    repositoryFactory.getRepository(creator).updateMeta(modelInfo);
    ArgumentCaptor<ModelInfo> captor = ArgumentCaptor.forClass(ModelInfo.class);
    Mockito.verify(indexingService, Mockito.times(1)).updateIndex(captor.capture());
    ModelInfo savedModel = captor.getValue();
    assertEquals(savedModel.getAuthor(), "newauthor");
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Test(org.junit.Test)

Example 29 with ModelInfo

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

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

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