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());
}
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;
}
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());
}
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());
}
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"));
}
Aggregations