Search in sources :

Example 6 with Attachment

use of org.mamute.model.Attachment in project mamute by caelum.

the class AttachmentRepositoryTest method should_detach_from_answer.

@Test
public void should_detach_from_answer() {
    final User author = user("question owner", "question@owner.local");
    session.save(author);
    final Attachment attachment = createAttachment("test");
    attachmentRepository.save(attachment);
    final Tag tag = tag("testtag");
    session.save(tag);
    final Question question = question(author, tag);
    session.save(question);
    final Answer answer = answer("answer answer answer answer answer", question, author);
    answer.getAttachments().add(attachment);
    session.save(answer);
    attachmentRepository.delete(answer.getAttachments());
    assertEquals(0, answer.getAttachments().size());
}
Also used : Answer(org.mamute.model.Answer) User(org.mamute.model.User) Attachment(org.mamute.model.Attachment) Question(org.mamute.model.Question) Tag(org.mamute.model.Tag) Test(org.junit.Test)

Example 7 with Attachment

use of org.mamute.model.Attachment in project mamute by caelum.

the class AttachmentRepositoryTest method should_detach_from_question.

@Test
public void should_detach_from_question() {
    final User author = user("question owner", "question@owner.local");
    session.save(author);
    final Attachment attachment = createAttachment("test");
    attachmentRepository.save(attachment);
    final Tag tag = tag("testtag");
    session.save(tag);
    final Question question = question(author, tag);
    question.getAttachments().add(attachment);
    session.save(question);
    attachmentRepository.delete(question.getAttachments());
    assertEquals(0, question.getAttachments().size());
}
Also used : User(org.mamute.model.User) Attachment(org.mamute.model.Attachment) Question(org.mamute.model.Question) Tag(org.mamute.model.Tag) Test(org.junit.Test)

Example 8 with Attachment

use of org.mamute.model.Attachment in project mamute by caelum.

the class AttachmentRepositoryTest method createAttachment.

private Attachment createAttachment(final String content) {
    final User owner = user("attachment owner", "attachment@owner.local");
    session.save(owner);
    final UploadedFile file = new DefaultUploadedFile(IOUtils.toInputStream(content), "hello.txt", "text/plain", content.length());
    final Attachment attachment = new Attachment(file, owner, "127.0.0.1");
    return attachment;
}
Also used : User(org.mamute.model.User) UploadedFile(br.com.caelum.vraptor.observer.upload.UploadedFile) DefaultUploadedFile(br.com.caelum.vraptor.observer.upload.DefaultUploadedFile) DefaultUploadedFile(br.com.caelum.vraptor.observer.upload.DefaultUploadedFile) Attachment(org.mamute.model.Attachment)

Aggregations

Attachment (org.mamute.model.Attachment)8 Test (org.junit.Test)5 User (org.mamute.model.User)3 DefaultUploadedFile (br.com.caelum.vraptor.observer.upload.DefaultUploadedFile)2 Question (org.mamute.model.Question)2 Tag (org.mamute.model.Tag)2 UploadedFile (br.com.caelum.vraptor.observer.upload.UploadedFile)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 Answer (org.mamute.model.Answer)1