Search in sources :

Example 6 with UserAgentAnalyzerTester

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

the class TestPerformance method validateAllPredefinedBrowsersPerformance.

@Disabled
@Test
void validateAllPredefinedBrowsersPerformance() {
    // NOSONAR: Do not complain about ignored performance test
    UserAgentAnalyzerTester uaa = UserAgentAnalyzerTester.newBuilder().showMatcherLoadStats().immediateInitialization().build();
    assertTrue(uaa.runTests(false, false, null, true, true));
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 7 with UserAgentAnalyzerTester

use of nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester 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 8 with UserAgentAnalyzerTester

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

the class TestJavaSerialization method deserialize.

UserAgentAnalyzerTester deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    try (ObjectInput in = new ObjectInputStream(bis)) {
        Object o = in.readObject();
        assertTrue(o instanceof UserAgentAnalyzerTester);
        return (UserAgentAnalyzerTester) o;
    }
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(java.io.ObjectInput) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with UserAgentAnalyzerTester

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

the class TestYamlBasedExpressions method runSubstringTests.

@Test
void runSubstringTests() {
    UserAgentAnalyzerTester uaa = createTester("SubString-tests.yaml");
    assertTrue(uaa.runTests(false, false));
}
Also used : UserAgentAnalyzerTester(nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester) Test(org.junit.jupiter.api.Test)

Example 10 with UserAgentAnalyzerTester

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

the class TestYamlBasedExpressions method runSubstringVersionTests.

@Test
void runSubstringVersionTests() {
    UserAgentAnalyzerTester uaa = createTester("SubStringVersion-tests.yaml");
    assertTrue(uaa.runTests(false, false));
}
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