Search in sources :

Example 31 with InvalidParserConfigurationException

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

the class TestAnnotationSystem method testMissingAnnotations.

@Test
void testMissingAnnotations() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, MissingAnnotations::new);
    assertEquals("You MUST specify at least 1 field to extract.", exception.getMessage());
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Example 32 with InvalidParserConfigurationException

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

the class TestAnnotationSystem method testWrongTypeParameters1.

@Test
void testWrongTypeParameters1() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, WrongTypeParameters1::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 33 with InvalidParserConfigurationException

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

the class TestAnnotationSystem method testTooManyParameters.

@Test
void testTooManyParameters() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, TooManyParameters::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 34 with InvalidParserConfigurationException

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

the class TestUserAgentAnalysisDoFnRaw method testImpossibleField.

@Test
public void testImpossibleField() {
    Exception exception = assertThrows(Exception.class, () -> {
        DoFn<TestRecord, TestRecord> fn = new UserAgentAnalysisDoFn<TestRecord>() {

            @Override
            public String getUserAgentString(TestRecord record) {
                return record.useragent;
            }

            // Called via the annotation
            @SuppressWarnings("unused")
            @YauaaField("NielsBasjes")
            public void setImpossibleField(TestRecord record, String value) {
                record.agentNameVersion = value;
            }
        };
        String userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/48.0.2564.82 Safari/537.36";
        TestRecord testInput = new TestRecord(userAgent);
        PCollection<TestRecord> input = pipeline.apply("Create", Create.of(testInput));
        PCollection<TestRecord> testOutputs = input.apply(ParDo.of(fn));
        pipeline.run();
    // The actual class thrown here turns out to be
    // org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.UncheckedExecutionException
    // which is a repackaged version of a Guava class.
    // which is the same class that was thrown in Beam 2.4.0 but in a DIFFERENT package.
    // Turns out Apache Beam 2.5.0 made a total mess of this because they repackaged this class in at least 5 package names
    // in the beam-runners-direct-java and also in the beam-sdks-java-core.
    // So to reduce the mess at this end I'm simply taking the underlying cause class ( org.apache.beam.sdk.util.UserCodeException )
    // and pulling the real exception my code throws to do the check.
    // throw e.getCause().getCause();
    });
    Throwable userCodeException = exception.getCause();
    assertTrue(userCodeException instanceof UserCodeException);
    Throwable myException = userCodeException.getCause();
    assertTrue(myException instanceof InvalidParserConfigurationException);
    assertEquals("We cannot provide these fields:[NielsBasjes]", myException.getMessage());
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) UserCodeException(org.apache.beam.sdk.util.UserCodeException) UserCodeException(org.apache.beam.sdk.util.UserCodeException) InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.Test)

Example 35 with InvalidParserConfigurationException

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

the class TestYamlParsing method runTest.

private void runTest(String inputFilename, String message) {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> UserAgentAnalyzer.newBuilder().dropDefaultResources().keepTests().addResources("classpath*:YamlParsingTests/" + inputFilename).delayInitialization().build());
    assertTrue(exception.getMessage().contains(message));
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException)

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