Search in sources :

Example 31 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method structured_extra_end.

/**
 * Asserts that a warning should be thrown when an unmatched END property is
 * found.
 */
@Test
public void structured_extra_end() throws Exception {
    // @formatter:off
    String string = "BEGIN:COMP1\r\n" + "PROP:value\r\n" + "END:COMP2\r\n" + "END:COMP1\r\n";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        VObjectReader reader = reader(string, style);
        VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
        reader.parse(listener);
        InOrder inorder = inOrder(listener);
        inorder.verify(listener).onComponentBegin(eq("COMP1"), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").value("value").build()), any(Context.class));
        inorder.verify(listener).onWarning(eq(Warning.UNMATCHED_END), isNull(VObjectProperty.class), isNull(Exception.class), any(Context.class));
        inorder.verify(listener).onComponentEnd(eq("COMP1"), any(Context.class));
        // @formatter:off
        String[] lines = string.split("\r\n");
        int line = 0;
        assertContexts(listener, context(lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(lines[line], ++line));
    // @formatter:on
    }
}
Also used : InOrder(org.mockito.InOrder) VObjectProperty(com.github.mangstadt.vinnie.VObjectProperty) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) DecoderException(com.github.mangstadt.vinnie.codec.DecoderException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Test(org.junit.Test)

Example 32 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method special_chars_in_parameter_name.

/**
 * When a parameter name has special characters.
 */
@Test
public void special_chars_in_parameter_name() throws Exception {
    // @formatter:off
    String string = "PROP;P,.\"ARAM=value:value";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        VObjectReader reader = reader(string, style);
        VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
        reader.parse(listener);
        InOrder inorder = inOrder(listener);
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("P,.\"ARAM", "value").value("value").build()), any(Context.class));
        // @formatter:off
        String[] lines = string.split("\r\n");
        int line = 0;
        assertContexts(listener, context(lines[line], ++line));
    // @formatter:on
    }
}
Also used : InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 33 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method structure_components_out_of_order.

/**
 * Asserts what happens when BEGIN/END components are not nested correctly.
 */
@Test
public void structure_components_out_of_order() throws Exception {
    // @formatter:off
    String string = "BEGIN:COMP1\r\n" + "PROP1:value1\r\n" + "BEGIN:COMP2\r\n" + "PROP2:value2\r\n" + // this also ends COMP2
    "END:COMP1\r\n" + "PROP3:value3\r\n" + "END:COMP2\r\n";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        VObjectReader reader = reader(string, style);
        VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
        reader.parse(listener);
        InOrder inorder = inOrder(listener);
        inorder.verify(listener).onComponentBegin(eq("COMP1"), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP1").value("value1").build()), any(Context.class));
        inorder.verify(listener).onComponentBegin(eq("COMP2"), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP2").value("value2").build()), any(Context.class));
        /*
			 * COMP2 is ended even though its END property wasn't reached
			 * because COMP1 ended and COMP2 is nested inside of COMP1.
			 */
        inorder.verify(listener).onComponentEnd(eq("COMP2"), any(Context.class));
        inorder.verify(listener).onComponentEnd(eq("COMP1"), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP3").value("value3").build()), any(Context.class));
        inorder.verify(listener).onWarning(eq(Warning.UNMATCHED_END), isNull(VObjectProperty.class), isNull(Exception.class), any(Context.class));
        // @formatter:off
        String[] lines = string.split("\r\n");
        int line = 0;
        assertContexts(listener, context(lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(asList("COMP1", "COMP2"), lines[line], ++line), context(asList("COMP1"), lines[line], line + 1), context(lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line));
    // @formatter:on
    }
}
Also used : InOrder(org.mockito.InOrder) VObjectProperty(com.github.mangstadt.vinnie.VObjectProperty) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) DecoderException(com.github.mangstadt.vinnie.codec.DecoderException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Test(org.junit.Test)

Example 34 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method quoted_printable.

/**
 * Tests quoted-printable encoding.
 */
@Test
public void quoted_printable() throws Exception {
    // @formatter:off
    String string = "PROP;QUOTED-PRINTABLE:one=0D=0Atwo\r\n" + "PROP;quoted-printable:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE:one=0D=0Atwo\r\n" + "PROP;ENCODING=quoted-printable:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE:=XX\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=invalid:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=illegal name:one=0D=0Atwo";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        VObjectReader reader = reader(string, style);
        VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
        reader.parse(listener);
        InOrder inorder = inOrder(listener);
        inorder.verify(listener).onProperty(eq(property().name("PROP").param(null, "QUOTED-PRINTABLE").value("one\r\ntwo").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param(null, "quoted-printable").value("one\r\ntwo").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").value("one\r\ntwo").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "quoted-printable").value("one\r\ntwo").build()), any(Context.class));
        VObjectProperty errorDecoding = property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").value("=XX").build();
        inorder.verify(listener).onWarning(eq(Warning.QUOTED_PRINTABLE_ERROR), eq(errorDecoding), any(DecoderException.class), any(Context.class));
        inorder.verify(listener).onProperty(eq(errorDecoding), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").param("CHARSET", "UTF-8").value("one\r\ntwo").build()), any(Context.class));
        VObjectProperty invalidCharset = property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").param("CHARSET", "invalid").value("one\r\ntwo").build();
        inorder.verify(listener).onWarning(eq(Warning.UNKNOWN_CHARSET), eq(invalidCharset), any(UnsupportedCharsetException.class), any(Context.class));
        inorder.verify(listener).onProperty(eq(invalidCharset), any(Context.class));
        VObjectProperty illegalName = property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").param("CHARSET", "illegal name").value("one\r\ntwo").build();
        inorder.verify(listener).onWarning(eq(Warning.UNKNOWN_CHARSET), eq(illegalName), any(IllegalCharsetNameException.class), any(Context.class));
        inorder.verify(listener).onProperty(eq(illegalName), any(Context.class));
        // @formatter:off
        String[] lines = string.split("\r\n");
        int line = 0;
        assertContexts(listener, context(lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line), context(lines[line], line + 1), context(lines[line], ++line), context(lines[line], ++line), context(lines[line], line + 1), context(lines[line], ++line), context(lines[line], line + 1), context(lines[line], ++line));
    // @formatter:on
    }
}
Also used : DecoderException(com.github.mangstadt.vinnie.codec.DecoderException) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) InOrder(org.mockito.InOrder) VObjectProperty(com.github.mangstadt.vinnie.VObjectProperty) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 35 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method empty_group_and_property_names.

/**
 * When the group and/or property names are empty.
 */
@Test
public void empty_group_and_property_names() throws Exception {
    // @formatter:off
    String string = ":value\r\n" + ".:value\r\n" + "group.:value\r\n" + ".PROP:value";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        VObjectReader reader = reader(string, style);
        VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
        reader.parse(listener);
        InOrder inorder = inOrder(listener);
        inorder.verify(listener).onProperty(eq(property().name("").value("value").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().group("").name("").value("value").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().group("group").name("").value("value").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().group("").name("PROP").value("value").build()), any(Context.class));
        // @formatter:off
        String[] lines = string.split("\r\n");
        int line = 0;
        assertContexts(listener, context(lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line));
    // @formatter:on
    }
}
Also used : InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Aggregations

SyntaxStyle (com.github.mangstadt.vinnie.SyntaxStyle)50 Test (org.junit.Test)45 InOrder (org.mockito.InOrder)24 StringWriter (java.io.StringWriter)21 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)15 VObjectProperty (com.github.mangstadt.vinnie.VObjectProperty)12 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)7 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)7 DecoderException (com.github.mangstadt.vinnie.codec.DecoderException)6 ArrayList (java.util.ArrayList)4 AllowedCharacters (com.github.mangstadt.vinnie.validate.AllowedCharacters)3 ValidationWarning (ezvcard.ValidationWarning)3 HashMap (java.util.HashMap)3 Map (java.util.Map)2 VCardDataType (ezvcard.VCardDataType)1 VCardVersion (ezvcard.VCardVersion)1 ClientPidMap (ezvcard.property.ClientPidMap)1 SortString (ezvcard.property.SortString)1 AbstractList (java.util.AbstractList)1 EnumSet (java.util.EnumSet)1