-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Fix the example on how to use Slf4j 1.x and 2.x and test for it
- Loading branch information
1 parent
81060db
commit 4f54a01
Showing
12 changed files
with
257 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ public Demo() { | |
.withCache(1234) | ||
.withField("DeviceClass") | ||
.withAllFields() | ||
.preheat() | ||
.build(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Yet Another UserAgent Analyzer | ||
* Copyright (C) 2013-2023 Niels Basjes | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
File buildLog = new File( basedir, 'build.log' ) | ||
assert buildLog.exists() | ||
|
||
assert 1 <= buildLog.getText().count("YauaaVersion") | ||
assert 1 == buildLog.getText().count("For more information: https://yauaa.basjes.nl") | ||
assert 1 == buildLog.getText().count("using expression: classpath*:UserAgents/") | ||
assert 1 == buildLog.getText().count("Building all matchers for all possible fields.") | ||
assert 1 == buildLog.getText().count("Preheating JVM by running ") | ||
assert 1 == buildLog.getText().count("Initializing Analyzer data structures") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ public Demo() { | |
.withCache(1234) | ||
.withField("DeviceClass") | ||
.withAllFields() | ||
.preheat() | ||
.build(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Yet Another UserAgent Analyzer | ||
* Copyright (C) 2013-2023 Niels Basjes | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
File buildLog = new File( basedir, 'build.log' ) | ||
assert buildLog.exists() | ||
|
||
assert 1 <= buildLog.getText().count("YauaaVersion") | ||
assert 1 == buildLog.getText().count("For more information: https://yauaa.basjes.nl") | ||
assert 1 == buildLog.getText().count("using expression: classpath*:UserAgents/") | ||
assert 1 == buildLog.getText().count("Building all matchers for all possible fields.") | ||
assert 1 == buildLog.getText().count("Preheating JVM by running ") | ||
assert 1 == buildLog.getText().count("Initializing Analyzer data structures") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Yet Another UserAgent Analyzer | ||
~ Copyright (C) 2013-2023 Niels Basjes | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>nl.basjes.parse.useragent</groupId> | ||
<artifactId>yauaa-example-parent-it</artifactId> | ||
<version>0.0.1</version> | ||
</parent> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<artifactId>yauaa-example-java-slf4j</artifactId> | ||
<name>Yauaa : Examples : Java (SLF4J 2.x)</name> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.release>17</maven.compiler.release> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>nl.basjes.parse.useragent</groupId> | ||
<artifactId>yauaa</artifactId> | ||
<version>${yauaa.version}</version> | ||
</dependency> | ||
|
||
<!-- The default logging implementation for Yauaa --> | ||
<!-- Send all Log4j2 calls to SLF4J 2.x --> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-to-slf4j</artifactId> | ||
<version>${log4j2.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<!-- Make sure the Slf4j 1.x api is excluded because we want the 2.x version --> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<!-- Just the simplest of logger for this demo. --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>${slf4j2.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
41 changes: 41 additions & 0 deletions
41
...zer/src/it/Examples/java-slf4j2/src/main/java/nl/basjes/parse/useragent/example/Demo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Yet Another UserAgent Analyzer | ||
* Copyright (C) 2013-2023 Niels Basjes | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nl.basjes.parse.useragent.example; | ||
|
||
import nl.basjes.parse.useragent.UserAgent; | ||
import nl.basjes.parse.useragent.UserAgentAnalyzer; | ||
|
||
public class Demo { | ||
|
||
private final UserAgentAnalyzer uaa; | ||
|
||
public Demo() { | ||
uaa = UserAgentAnalyzer | ||
.newBuilder() | ||
.withCache(1234) | ||
.withField("DeviceClass") | ||
.withAllFields() | ||
.preheat() | ||
.build(); | ||
} | ||
|
||
public UserAgent parse(String userAgent) { | ||
return uaa.parse(userAgent); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...src/it/Examples/java-slf4j2/src/test/java/nl/basjes/parse/useragent/example/TestDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Yet Another UserAgent Analyzer | ||
* Copyright (C) 2013-2023 Niels Basjes | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nl.basjes.parse.useragent.example; | ||
|
||
import nl.basjes.parse.useragent.UserAgent; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class TestDemo { | ||
@Test | ||
void testParser() { | ||
Demo demo = new Demo(); | ||
|
||
String userAgent = "Mozilla/5.0 (Linux; Android 7.0; Nexus 6 Build/NBD90Z) " + | ||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.124 Mobile Safari/537.36"; | ||
|
||
UserAgent result = demo.parse(userAgent); | ||
|
||
assertTrue(result.toXML().contains("<DeviceName>Google Nexus 6</DeviceName>"), | ||
"The parser must extract the correct DeviceName"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Yet Another UserAgent Analyzer | ||
* Copyright (C) 2013-2023 Niels Basjes | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
File buildLog = new File( basedir, 'build.log' ) | ||
assert buildLog.exists() | ||
|
||
assert 1 <= buildLog.getText().count("YauaaVersion") | ||
assert 1 == buildLog.getText().count("For more information: https://yauaa.basjes.nl") | ||
assert 1 == buildLog.getText().count("using expression: classpath*:UserAgents/") | ||
assert 1 == buildLog.getText().count("Building all matchers for all possible fields.") | ||
assert 1 == buildLog.getText().count("Preheating JVM by running ") | ||
assert 1 == buildLog.getText().count("Initializing Analyzer data structures") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ public Demo() { | |
.withCache(1234) | ||
.withField("DeviceClass") | ||
.withAllFields() | ||
.preheat() | ||
.build(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Yet Another UserAgent Analyzer | ||
* Copyright (C) 2013-2023 Niels Basjes | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
File buildLog = new File( basedir, 'build.log' ) | ||
assert buildLog.exists() | ||
|
||
assert 1 <= buildLog.getText().count("YauaaVersion") | ||
assert 1 == buildLog.getText().count("For more information: https://yauaa.basjes.nl") | ||
assert 1 == buildLog.getText().count("using expression: classpath*:UserAgents/") | ||
assert 1 == buildLog.getText().count("Building all matchers for all possible fields.") | ||
assert 1 == buildLog.getText().count("Preheating JVM by running ") | ||
assert 1 == buildLog.getText().count("Initializing Analyzer data structures") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters