Search in sources :

Example 26 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestAnnotationSystemAnonymous method testSetterFailure.

// ----------------------------------------------------------------
@Test
void testSetterFailure() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> record = new MyErrorMapper() {

        // Called via the annotation
        @SuppressWarnings("unused")
        @YauaaField("DeviceClass")
        public void failingSetter(TestRecord testRecord, String value) {
            throw new IllegalStateException("Just testing the error handling");
        }
    }.enrich(record));
    assertEquals("A problem occurred while calling the requested setter", exception.getMessage());
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Example 27 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestAnnotationSystemAnonymous method testImpossibleField.

@Test
void testImpossibleField() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> record = new MyErrorMapper() {

        // Called via the annotation
        @SuppressWarnings("unused")
        @YauaaField("NielsBasjes")
        public void setImpossibleField(TestRecord testRecord, String value) {
            fail("May NEVER call this method");
        }
    }.enrich(record));
    assertEquals("We cannot provide these fields:[NielsBasjes]", exception.getMessage());
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Example 28 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestVersionCollisionChecks method testDoubleLoadedResources.

@Test
void testDoubleLoadedResources() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> UserAgentAnalyzer.newBuilder().delayInitialization().addResources("classpath*:UserAgents/**/*.yaml").build());
    assertTrue(exception.getMessage().startsWith("Trying to load "));
    assertTrue(exception.getMessage().endsWith(" resources for the second time"));
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Example 29 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestAnnotationSystem method testWrongTypeParameters2.

@Test
void testWrongTypeParameters2() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, WrongTypeParameters2::new);
    assertTrue(exception.getMessage().contains("the method [wrongSetter] has been annotated with YauaaField but it has the wrong method signature. " + "It must look like [ public void wrongSetter(TestRecord record, String value) ]"));
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Example 30 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestAnnotationSystem method testBadGeneric.

// ----------------------------------------------------------------
// Here we deliberately created some bad code to check the behavior.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void testBadGeneric() {
    UserAgentAnnotationAnalyzer userAgentAnalyzer = new UserAgentAnnotationAnalyzer();
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> assertNull(userAgentAnalyzer.map("Foo")));
    assertEquals("[Map] The mapper instance is null.", exception.getMessage());
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Aggregations

InvalidParserConfigurationException (nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException)35 Test (org.junit.jupiter.api.Test)24 YamlUtils.getKeyAsString (nl.basjes.parse.useragent.utils.YamlUtils.getKeyAsString)5 YamlUtils.getValueAsString (nl.basjes.parse.useragent.utils.YamlUtils.getValueAsString)5 YamlUtils.getExactlyOneNodeTuple (nl.basjes.parse.useragent.utils.YamlUtils.getExactlyOneNodeTuple)4 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Matcher (nl.basjes.parse.useragent.analyze.Matcher)2 ConfigLine (nl.basjes.parse.useragent.config.MatcherConfig.ConfigLine)2 YamlUtils.getValueAsMappingNode (nl.basjes.parse.useragent.utils.YamlUtils.getValueAsMappingNode)2 YamlUtils.getValueAsSequenceNode (nl.basjes.parse.useragent.utils.YamlUtils.getValueAsSequenceNode)2 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)2 Node (org.yaml.snakeyaml.nodes.Node)2 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)2