Search in sources :

Example 1 with UserAgentAnalyzerTesterBuilder

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

the class TestResourceLoading method checkIfLoadingAllFilesSeparatelyAsOptionalWorks.

@Test
void checkIfLoadingAllFilesSeparatelyAsOptionalWorks() {
    UserAgentAnalyzerTesterBuilder uaaB = UserAgentAnalyzerTester.newBuilder().hideMatcherLoadStats().dropDefaultResources();
    PackagedRules.getRuleFileNames().forEach(uaaB::addOptionalResources);
    UserAgentAnalyzerTester uaa = uaaB.withCache(10000).build();
    assertTrue(uaa.runTests(false, false));
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) UserAgentAnalyzerTesterBuilder(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester.UserAgentAnalyzerTesterBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with UserAgentAnalyzerTesterBuilder

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

the class AbstractSerializationTest method serializeAndDeserializeUAA.

private void serializeAndDeserializeUAA(boolean immediate, boolean runTestsBefore, boolean useTestRules) throws IOException, ClassNotFoundException {
    LOG.info("==============================================================");
    LOG.info("Create");
    LOG.info("--------------------------------------------------------------");
    UserAgentAnalyzerTesterBuilder uaab = UserAgentAnalyzerTester.newBuilder().keepTests().withCacheInstantiator(new TestingCacheInstantiator()).withCache(1234).hideMatcherLoadStats();
    if (useTestRules) {
        uaab.dropDefaultResources().addResources("classpath*:AllSteps.yaml").addResources("classpath*:AllFields-tests.yaml").addResources("classpath*:AllPossibleSteps.yaml").addResources("classpath*:IsNullLookup.yaml");
    }
    if (immediate) {
        uaab.immediateInitialization();
    }
    UserAgentAnalyzerTester uaaBefore = uaab.build();
    String uaaBeforeString = uaaBefore.toString();
    if (runTestsBefore) {
        LOG.info("--------------------------------------------------------------");
        assertTrue(uaaBefore.runTests(false, false, null, false, false), "Tests BEFORE serialization failed");
        // Get rid of the data of the last tested useragent
        uaaBefore.reset();
        String uaaBeforeAfterTestsString = uaaBefore.toString();
        assertEquals(uaaBeforeString, uaaBeforeAfterTestsString);
    }
    LOG.info("--------------------------------------------------------------");
    LOG.info("Serialize");
    long serializeStartNs = System.nanoTime();
    byte[] bytes = serialize(uaaBefore);
    long serializeStopNs = System.nanoTime();
    LOG.info("Serialize took {} ns ({} ms)", serializeStopNs - serializeStartNs, (serializeStopNs - serializeStartNs) / 1_000_000);
    LOG.info("The UserAgentAnalyzer was serialized into {} bytes", bytes.length);
    LOG.info("--------------------------------------------------------------");
    LOG.info("Deserialize");
    long deserializeStartNs = System.nanoTime();
    UserAgentAnalyzerTester uaaAfter = deserialize(bytes);
    long deserializeStopNs = System.nanoTime();
    LOG.info("Done");
    LOG.info("Deserialize took {} ns ({} ms)", deserializeStopNs - deserializeStartNs, (deserializeStopNs - deserializeStartNs) / 1_000_000);
    String uaaAfterString = uaaAfter.toString();
    assertEquals(uaaBeforeString, uaaAfterString);
    assertEquals(1234, uaaAfter.getCacheSize());
    LOG.info("==============================================================");
    LOG.info("Validating when getting all fields");
    LOG.info("--------------------------------------------------------------");
    assertTrue(uaaAfter.runTests(false, false, null, false, false), "Tests AFTER serialization failed");
    LOG.info("==============================================================");
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) UserAgentAnalyzerTesterBuilder(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester.UserAgentAnalyzerTesterBuilder)

Example 3 with UserAgentAnalyzerTesterBuilder

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

the class TestResourceLoading method checkIfLoadingAllFilesSeparatelyWorks.

@Test
void checkIfLoadingAllFilesSeparatelyWorks() {
    UserAgentAnalyzerTesterBuilder uaaB = UserAgentAnalyzerTester.newBuilder().hideMatcherLoadStats().dropDefaultResources();
    PackagedRules.getRuleFileNames().forEach(uaaB::addResources);
    UserAgentAnalyzerTester uaa = uaaB.withCache(10000).build();
    assertTrue(uaa.runTests(false, false));
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) UserAgentAnalyzerTesterBuilder(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester.UserAgentAnalyzerTesterBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

UserAgentAnalyzerTester (nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester)3 UserAgentAnalyzerTesterBuilder (nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester.UserAgentAnalyzerTesterBuilder)3 Test (org.junit.jupiter.api.Test)2