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());
}
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) ]"));
}
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) ]"));
}
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());
}
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));
}
Aggregations