Search in sources :

Example 26 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.

the class TestPredefinedBrowsers method makeSureWeDoNotHaveDuplicateTests.

@Test
void makeSureWeDoNotHaveDuplicateTests() {
    UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().build();
    Map<String, List<String>> allTestInputs = new HashMap<>(2000);
    Set<String> duplicates = new HashSet<>();
    for (TestCase testCase : uaa.getTestCases()) {
        String input = testCase.getUserAgent();
        String location = testCase.getMetadata().get("filename") + ":" + testCase.getMetadata().get("fileline");
        List<String> locations = allTestInputs.get(input);
        if (locations == null) {
            locations = new ArrayList<>();
        }
        locations.add(location);
        if (locations.size() > 1) {
            duplicates.add(input);
        }
        allTestInputs.put(input, locations);
    }
    if (duplicates.size() == 0) {
        LOG.info("No duplicate tests were found.");
        // We're done and all is fine.
        return;
    }
    StringBuilder sb = new StringBuilder(1024);
    for (String duplicate : duplicates) {
        sb.append("======================================================\n").append("Testcase > ").append(duplicate).append("\n");
        int count = 0;
        for (String location : allTestInputs.get(duplicate)) {
            sb.append(">Location ").append(++count).append(".(").append(location).append(")\n");
        }
    }
    fail("Found " + duplicates.size() + " testcases multiple times: \n" + sb);
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) HashMap(java.util.HashMap) TestCase(nl.basjes.parse.useragent.config.TestCase) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 27 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.

the class TestPredefinedBrowsers method validateAllPredefinedBrowsersViaTestCase.

@Test
void validateAllPredefinedBrowsersViaTestCase() {
    UserAgentAnalyzerTester uaa;
    uaa = UserAgentAnalyzerTester.newBuilder().immediateInitialization().build();
    LOG.info("==============================================================");
    LOG.info("Validating when getting all fields");
    LOG.info("--------------------------------------------------------------");
    List<TestCase> testCases = uaa.getTestCases();
    long start = System.nanoTime();
    assertEquals(0, testCases.stream().filter(testCase -> !testCase.verify(uaa)).count());
    long stop = System.nanoTime();
    LOG.info("All %d tests passed in %dms (average %4.3fms per testcase).", testCases.size(), (stop - start) / 1_000_000, ((stop - start) / 1_000_000D / testCases.size()));
    LOG.info("--------------------------------------------------------------");
    LOG.info("Running all tests again which should return the cached values");
    assertEquals(0, testCases.stream().filter(testCase -> !testCase.verify(uaa)).count());
    // Only here for ensuring the code being tested with "all fields".
    uaa.destroy();
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) TestCase(nl.basjes.parse.useragent.config.TestCase) Test(org.junit.jupiter.api.Test)

Example 28 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.

the class DocumentationExample method runDocumentationExample.

@Test
void runDocumentationExample() {
    UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().dropDefaultResources().addResources("classpath*:DocumentationExample.yaml").build();
    assertTrue(uaa.runTests(false, true));
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) Test(org.junit.jupiter.api.Test)

Example 29 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.

the class TestErrorHandling method runTest.

private void runTest(String resourceString, Matcher<String> expectedMessage) {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> {
        UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().dropDefaultResources().keepTests().addResources(resourceString).build();
        assertTrue(uaa.runTests(false, false));
    });
    assertTrue(expectedMessage.matches(exception.getMessage()), "Bad message:" + exception.getMessage());
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester)

Example 30 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester in project yauaa by nielsbasjes.

the class TestPredefinedBrowsers method validateAllPredefinedBrowsers.

@Test
void validateAllPredefinedBrowsers() {
    UserAgentAnalyzerTester uaa;
    uaa = UserAgentAnalyzerTester.newBuilder().immediateInitialization().build();
    LOG.info("==============================================================");
    LOG.info("Validating when getting all fields");
    LOG.info("--------------------------------------------------------------");
    assertTrue(uaa.runTests(false, true, null, false, true));
    LOG.info("--------------------------------------------------------------");
    LOG.info("Running all tests again which should return the cached values");
    assertTrue(uaa.runTests(false, true, null, false, false));
    // Only here for ensuring the code being tested with "all fields".
    uaa.destroy();
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) Test(org.junit.jupiter.api.Test)

Aggregations

UserAgentAnalyzerTester (nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester)43 Test (org.junit.jupiter.api.Test)37 ArrayList (java.util.ArrayList)3 UserAgentAnalyzerTesterBuilder (nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester.UserAgentAnalyzerTesterBuilder)3 TestCase (nl.basjes.parse.useragent.config.TestCase)2 YamlUtils.getKeyAsString (nl.basjes.parse.useragent.utils.YamlUtils.getKeyAsString)2 Kryo (com.esotericsoftware.kryo.Kryo)1 ByteBufferInput (com.esotericsoftware.kryo.io.ByteBufferInput)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInput (java.io.ObjectInput)1 ObjectInputStream (java.io.ObjectInputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ImmutableUserAgent (nl.basjes.parse.useragent.UserAgent.ImmutableUserAgent)1 MutableUserAgent (nl.basjes.parse.useragent.UserAgent.MutableUserAgent)1 InvalidParserConfigurationException (nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException)1 Match (nl.basjes.parse.useragent.analyze.MatchesList.Match)1 AbstractUserAgentAnalyzerTester (nl.basjes.parse.useragent.debug.AbstractUserAgentAnalyzerTester)1 Disabled (org.junit.jupiter.api.Disabled)1