Search in sources :

Example 81 with ModelId

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

the class ModelRepositoryTest method testGetLatestModelVersionId.

@Test
public void testGetLatestModelVersionId() throws Exception {
    IUserContext user = createUserContext("alex", "playground");
    ModelInfo color = importModel("Color.type");
    ModelInfo color6 = importModel("Color6.type");
    importModel("Color7.type");
    importModel("sample.mapping");
    color.setState(ModelState.Released.getName());
    color6.setState(ModelState.Released.getName());
    this.workflow.start(color.getId(), user);
    this.workflow.start(color6.getId(), user);
    setReleaseState(color);
    setReleaseState(color6);
    ModelId id = this.repositoryFactory.getRepository(createUserContext("admin")).getLatestModelVersionIfLatestTagIsSet(ModelId.fromReference("org.eclipse.vorto.examples.type.Color", "latest"));
    assertEquals("org.eclipse.vorto.examples.type:Color:1.0.1", id.getPrettyFormat());
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 82 with ModelId

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

the class DependencyManagerTest method create.

protected ModelInfo create(String name, ModelType type, ModelInfo... references) {
    final ModelId id = new ModelId(name, "org.eclipse.vorto", "1.0.0");
    ModelInfo resource = new ModelInfo(id, type);
    resource.setReferences(Arrays.asList(references).stream().map(reference -> reference.getId()).collect(Collectors.toList()));
    Arrays.asList(references).stream().forEach(it -> it.addReferencedBy(id));
    return resource;
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelId(org.eclipse.vorto.model.ModelId)

Example 83 with ModelId

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

the class GeneratedOutputAttachmentHandlerTest method attachGeneratedOutput.

@Test
public void attachGeneratedOutput() {
    // setup
    String filename = "thiswasgenerated.json";
    byte[] content = { 0x01 };
    List<Attachment> attList = new ArrayList<>();
    ModelId id = new ModelId();
    id.setName("TestInfoModel");
    attList.add(Attachment.newInstance(id, filename));
    when(repository.getAttachmentsByTags(any(), any())).thenReturn(attList);
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setId(id);
    Map<String, String> requestParams = new HashMap<>();
    GeneratorPluginConfiguration plugin = GeneratorPluginConfiguration.of("eclipseditto", "v2", "http://localhost:8888", "1.0.0");
    when(repository.getAttachmentContent(any(), any())).thenReturn(Optional.of(new FileContent(filename, content)));
    when(modelRepositoryFactory.getRepositoryByModel(any(), any())).thenReturn(repository);
    IUserContext userContext = new IUserContext() {

        @Override
        public Authentication getAuthentication() {
            return null;
        }

        @Override
        public String getUsername() {
            return "testuser";
        }

        @Override
        public String getWorkspaceId() {
            return null;
        }

        @Override
        public String getHashedUsername() {
            return null;
        }

        @Override
        public boolean isAnonymous() {
            return false;
        }

        @Override
        public boolean isSysAdmin() {
            return false;
        }
    };
    GeneratedOutput generatedOutput = sut.getGeneratedOutputFromAttachment(modelInfo, requestParams, plugin, repository).get();
    // execute
    GeneratedOutput result = sut.attachGeneratedOutput(userContext, modelInfo.getId(), "eclipseditto", requestParams, generatedOutput, plugin);
    // verify
    assertNotNull(result);
    assertEquals(1, result.getSize());
    assertEquals("generated_eclipseditto_1.0.0_TestInfoModel.json", result.getFileName());
    assertEquals(content, result.getContent());
}
Also used : GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration) GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 84 with ModelId

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

the class GeneratedOutputAttachmentHandlerTest method getGeneratedOutputFromAttachment.

@Test
public void getGeneratedOutputFromAttachment() {
    // setup
    String filename = "thiswasgenerated.json";
    byte[] content = { 0x01 };
    List<Attachment> attList = new ArrayList<>();
    ModelId id = new ModelId();
    id.setName("TestInfoModel");
    attList.add(Attachment.newInstance(id, filename));
    when(repository.getAttachmentsByTags(any(), any())).thenReturn(attList);
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setId(id);
    Map<String, String> requestParams = new HashMap<>();
    GeneratorPluginConfiguration plugin = GeneratorPluginConfiguration.of("eclipseditto", "v2", "http://localhost:8888", "1.0.0");
    when(repository.getAttachmentContent(any(), any())).thenReturn(Optional.of(new FileContent(filename, content)));
    // execute
    Optional<GeneratedOutput> result = sut.getGeneratedOutputFromAttachment(modelInfo, requestParams, plugin, repository);
    // verify
    assertTrue(result.isPresent());
    assertEquals(content, result.get().getContent());
    assertEquals(filename, result.get().getFileName());
    assertEquals(1, result.get().getSize());
}
Also used : GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration) GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 85 with ModelId

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

the class UserReferenceSearchSimpleTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    testInfrastructure = new SearchTestInfrastructure();
    testInfrastructure.importModel(testInfrastructure.DATATYPE_MODEL);
    List<ModelInfo> model = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("alex")).search("*");
    // this is arguably over-cautious, as the next statement would fail all tests anyway
    if (model.isEmpty()) {
        fail("Model is empty after importing.");
    }
    // "reviewer" user updates the only imported model's visibility to public, i.e.
    // "lastModifiedBy" -> reviewer
    ModelId updated = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("reviewer")).updateVisibility(model.get(0).getId(), "Public");
    // "control group": importing another model as another user
    testInfrastructure.importModel("HueLightStrips.infomodel", testInfrastructure.createUserContext("erle", "playground"));
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelId(org.eclipse.vorto.model.ModelId) BeforeClass(org.junit.BeforeClass)

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