use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelRepositoryAttachmentTest method testAttachFileWithCustomTag.
@Test
public void testAttachFileWithCustomTag() {
IUserContext erle = createUserContext("erle", "playground");
importModel("Color.type", erle);
try {
Tag myCustomTag = new Tag("myCustom");
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, myCustomTag);
List<Attachment> attachments = repositoryFactory.getRepository(erle).getAttachments(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"));
assertEquals(1, attachments.get(0).getTags().size());
assertEquals(myCustomTag, attachments.get(0).getTags().get(0));
attachments.forEach(System.out::println);
} catch (IOException | FatalModelRepositoryException e) {
e.printStackTrace();
fail("Cannot load sample file");
}
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelRepositoryAttachmentTest method testGetAttachmentsWithTagNotExisting.
@Test
public void testGetAttachmentsWithTagNotExisting() {
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, Attachment.TAG_DOCUMENTATION);
List<Attachment> attachments = repositoryFactory.getRepository(erle).getAttachmentsByTag(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), Attachment.TAG_IMAGE);
assertEquals(0, attachments.size());
} catch (IOException | FatalModelRepositoryException e) {
e.printStackTrace();
fail("Cannot load sample file");
}
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelRepositoryAttachmentTest method testDeleteImportedAttachmentOtherAttachmentsNotExist.
@Test
public void testDeleteImportedAttachmentOtherAttachmentsNotExist() throws Exception {
IUserContext erle = createUserContext("erle", "playground");
importModel("Color.type", erle);
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);
boolean deleteResult = repositoryFactory.getRepository(erle).deleteAttachment(modelId, "backup1.xml");
assertFalse(deleteResult);
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelRepositoryAttachmentTest method testDeleteImportedAttachmentOtherAttachmentsExist.
@Test
public void testDeleteImportedAttachmentOtherAttachmentsExist() throws Exception {
IUserContext erle = createUserContext("erle", "playground");
importModel("Color.type", erle);
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);
repositoryFactory.getRepository(erle).attachFile(modelId, new FileContent("backup-withImages.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup-withImages.xml").getInputStream())), erle);
boolean deleteResultTrue = repositoryFactory.getRepository(erle).deleteAttachment(modelId, "backup-withImages.xml");
assertTrue(deleteResultTrue);
boolean deleteResultFalse = repositoryFactory.getRepository(erle).deleteAttachment(modelId, "backup1.xml");
assertFalse(deleteResultFalse);
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelRepositoryTest method testGetModelWithImage.
/**
* Originally, this only tested that a given persisted model had an image once an image was
* attached. <br/>
* In light of changes to tags (with the introduction of {@link Attachment#TAG_DISPLAY_IMAGE}
* which is unique among a model's images and signifies this is the image to display, the test
* verifies a few more things:
* <ol>
* <li>
* That the both the {@link Attachment#TAG_DISPLAY_IMAGE} and {@link Attachment#TAG_IMAGE} tags
* are present once attached (unfortunately this is rather trivial since the operation is
* directed at controller level).
* </li>
* <li>
* More importantly, that once another image is attached, only one
* {@link Attachment#TAG_DISPLAY_IMAGE} is found, and that it belongs to the latest resource.
* </li>
* </ol>
* @throws Exception
*/
@Test
public void testGetModelWithImage() throws Exception {
IUserContext alex = UserContext.user("alex", "playground");
final ModelId modelId = new ModelId("HueLightStrips", "com.mycompany", "1.0.0");
importModel("Color.type");
importModel("Colorlight.fbmodel");
importModel("Switcher.fbmodel");
importModel("HueLightStrips.infomodel");
// this adds the two tags "image" and "display image" as the controller would do when
// uploading an image attachment
this.repositoryFactory.getRepository(createUserContext("admin")).attachFile(modelId, new FileContent("sample.png", IOUtils.toByteArray(new ClassPathResource("sample_models/sample.png").getInputStream())), alex, Attachment.TAG_IMAGE, Attachment.TAG_DISPLAY_IMAGE);
assertEquals(true, this.repositoryFactory.getRepository(createUserContext("admin")).getById(modelId).isHasImage());
assertEquals(1, this.repositoryFactory.getRepository(createUserContext("admin")).getAttachmentsByTag(modelId, Attachment.TAG_DISPLAY_IMAGE).size());
assertEquals(1, this.repositoryFactory.getRepository(createUserContext("admin")).getAttachmentsByTag(modelId, Attachment.TAG_IMAGE).size());
// adding "another" image - will test if only one has tag display image
this.repositoryFactory.getRepository(createUserContext("admin")).attachFile(modelId, new FileContent("sample2.png", IOUtils.toByteArray(new ClassPathResource("sample_models/sample2.png").getInputStream())), alex, Attachment.TAG_IMAGE, Attachment.TAG_DISPLAY_IMAGE);
// only one display image tag present among attachments
assertEquals(1, this.repositoryFactory.getRepository(createUserContext("admin")).getAttachmentsByTag(modelId, Attachment.TAG_DISPLAY_IMAGE).size());
// two image tags among attachments
assertEquals(2, this.repositoryFactory.getRepository(createUserContext("admin")).getAttachmentsByTag(modelId, Attachment.TAG_IMAGE).size());
// display image tag pertains to latest attachment added
assertEquals(true, this.repositoryFactory.getRepository(createUserContext("admin")).getAttachmentsByTag(modelId, Attachment.TAG_DISPLAY_IMAGE).get(0).getFilename().contains("sample2.png"));
// adding a third non-image resource with custom tags
this.repositoryFactory.getRepository(createUserContext("admin")).attachFile(modelId, new FileContent("backup1.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup1.xml").getInputStream())), alex, new Tag("custom"));
// only one display image tag present among attachments
assertEquals(1, this.repositoryFactory.getRepository(createUserContext("admin")).getAttachmentsByTag(modelId, Attachment.TAG_DISPLAY_IMAGE).size());
// two image tags among attachments
assertEquals(2, this.repositoryFactory.getRepository(createUserContext("admin")).getAttachmentsByTag(modelId, Attachment.TAG_IMAGE).size());
// display image tag pertains to latest attachment added
assertEquals(true, this.repositoryFactory.getRepository(createUserContext("admin")).getAttachmentsByTag(modelId, Attachment.TAG_DISPLAY_IMAGE).get(0).getFilename().contains("sample2.png"));
}
Aggregations