Package org.apache.james.mime4j.message

Examples of org.apache.james.mime4j.message.BodyPart


        assertSame(body, entity.getBody());
        assertSame(entity, body.getParent());
    }

    public void testSetBodyTwice() throws Exception {
        Entity entity = new BodyPart();

        Body b1 = new BasicBodyFactory().textBody("foo");
        Body b2 = new BasicBodyFactory().textBody("bar");

        entity.setBody(b1);
        try {
            entity.setBody(b2);
            fail();
        } catch (IllegalStateException expected) {
        }
    }
View Full Code Here


        } catch (IllegalStateException expected) {
        }
    }

    public void testRemoveBody() throws Exception {
        Entity entity = new BodyPart();
        Body body = new BasicBodyFactory().textBody("test");
        entity.setBody(body);

        Body removed = entity.removeBody();
        assertSame(body, removed);

        assertNull(entity.getBody());
        assertNull(removed.getParent());
    }
View Full Code Here

        assertNull(entity.getBody());
        assertNull(removed.getParent());
    }

    public void testGetDispositionType() throws Exception {
        BodyPart entity = new BodyPart();

        assertNull(entity.getDispositionType());

        Header header = new HeaderImpl();
        header.setField(DefaultFieldParser.parse("Content-Disposition: inline"));
        entity.setHeader(header);

        assertEquals("inline", entity.getDispositionType());
    }
View Full Code Here

        assertEquals("inline", entity.getDispositionType());
    }

    public void testSetContentDispositionType() throws Exception {
        BodyPart entity = new BodyPart();

        entity.setContentDisposition("attachment");

        assertEquals("attachment", entity.getHeader().getField(
                "Content-Disposition").getBody());
    }
View Full Code Here

        assertNull(copy.getParent());
    }

    public void testCopyEmptyBodyPart() throws Exception {
        BodyPart original = new BodyPart();

        DefaultMessageBuilder builder = new DefaultMessageBuilder();
        BodyPart copy = builder.copy(original);

        assertNull(copy.getHeader());
        assertNull(copy.getBody());
        assertNull(copy.getParent());
    }
View Full Code Here

    public void testCopyBodyPart() throws Exception {
        MessageImpl parent = new MessageImpl();
        Header header = new HeaderImpl();
        Body body = new BasicBodyFactory().textBody("test");

        BodyPart original = new BodyPart();
        original.setHeader(header);
        original.setBody(body);
        original.setParent(parent);

        DefaultMessageBuilder builder = new DefaultMessageBuilder();
        BodyPart copy = builder.copy(original);

        assertNotNull(copy.getHeader());
        assertNotSame(header, copy.getHeader());

        assertNotNull(copy.getBody());
        assertNotSame(body, copy.getBody());

        assertSame(copy, copy.getBody().getParent());

        assertNull(copy.getParent());
    }
View Full Code Here

        assertNull(copy.getParent());
    }

    public void testCopyMultipart() throws Exception {
        MessageImpl parent = new MessageImpl();
        BodyPart bodyPart = new BodyPart();

        MultipartImpl original = new MultipartImpl("mixed");
        original.setPreamble("preamble");
        original.setEpilogue("epilogue");
        original.setParent(parent);
        original.addBodyPart(bodyPart);

        DefaultMessageBuilder builder = new DefaultMessageBuilder();
        Multipart copy = builder.copy(original);

        assertSame(original.getPreamble(), copy.getPreamble());
        assertSame(original.getEpilogue(), copy.getEpilogue());
        assertSame(original.getSubType(), copy.getSubType());
        assertEquals(1, copy.getBodyParts().size());
        assertNull(copy.getParent());

        Entity bodyPartCopy = copy.getBodyParts().iterator().next();
        assertNotSame(bodyPart, bodyPartCopy);

        assertSame(parent, bodyPart.getParent());
        assertNull(bodyPartCopy.getParent());
    }
View Full Code Here

        assertSame(parent, bodyPart.getParent());
        assertNull(bodyPartCopy.getParent());
    }

    public void testCopyMultipartMessage() throws Exception {
        BodyPart bodyPart1 = new BodyPart();
        BodyPart bodyPart2 = new BodyPart();

        Multipart multipart = new MultipartImpl("mixed");
        multipart.addBodyPart(bodyPart1);
        multipart.addBodyPart(bodyPart2);

        MessageImpl original = new MessageImpl();
        original.setHeader(new HeaderImpl());
        original.setBody(multipart);

        DefaultMessageBuilder builder = new DefaultMessageBuilder();
        Message copy = builder.copy(original);

        Multipart multipartCopy = (Multipart) copy.getBody();
        List<Entity> bodyParts = multipartCopy.getBodyParts();
        Entity bodyPartCopy1 = bodyParts.get(0);
        Entity bodyPartCopy2 = bodyParts.get(1);

        assertNotSame(bodyPart1, bodyPartCopy1);
        assertEquals(original, bodyPart1.getParent());
        assertEquals(copy, bodyPartCopy1.getParent());

        assertNotSame(bodyPart2, bodyPartCopy2);
        assertEquals(original, bodyPart2.getParent());
        assertEquals(copy, bodyPartCopy2.getParent());
    }
View Full Code Here

        assertEquals("attachment", entity.getHeader().getField(
                "Content-Disposition").getBody());
    }

    public void testSetContentDispositionTypeFilename() throws Exception {
        BodyPart entity = new BodyPart();

        entity.setContentDisposition("attachment", "some file.dat");

        assertEquals("attachment; filename=\"some file.dat\"", entity
                .getHeader().getField("Content-Disposition").getBody());
    }
View Full Code Here

        assertEquals("attachment; filename=\"some file.dat\"", entity
                .getHeader().getField("Content-Disposition").getBody());
    }

    public void testGetFilename() throws Exception {
        BodyPart entity = new BodyPart();

        assertNull(entity.getFilename());

        Header header = new HeaderImpl();
        header.setField(DefaultFieldParser.parse("Content-Disposition: attachment; "
                + "filename=\"some file.dat\""));
        entity.setHeader(header);

        assertEquals("some file.dat", entity.getFilename());
    }
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.message.BodyPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.