-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14281 from aibaars/aibaars/java-standalone-test
Java: standalone: add basic integration tests
- Loading branch information
Showing
17 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
java/ql/integration-tests/all-platforms/java/buildless-maven/pom.xml
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,114 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<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> | ||
|
||
<groupId>com.example</groupId> | ||
<artifactId>maven-sample</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>maven-sample</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<version>1.1.1</version> | ||
<executions> | ||
<execution> | ||
<id>check-maven-version</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>com.example.App</mainClass> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.diffplug.spotless</groupId> | ||
<artifactId>spotless-maven-plugin</artifactId> | ||
<version>2.19.1</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
<phase>compile</phase> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<java> | ||
<licenseHeader> | ||
<content>/* FAIL ME */</content> | ||
</licenseHeader> | ||
</java> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
<pluginManagement> | ||
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>3.7.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
30 changes: 30 additions & 0 deletions
30
...l/integration-tests/all-platforms/java/buildless-maven/src/main/java/com/example/App.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,30 @@ | ||
package com.example; | ||
|
||
import java.util.regex.Pattern; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Hello world! | ||
* | ||
*/ | ||
public class App | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
System.out.println( "Hello World!" ); | ||
String expectedVersion = System.getenv("EXPECT_MAVEN"); | ||
Path mavenHome = Paths.get(System.getProperty("maven.home")).normalize(); | ||
String observedVersion = mavenHome.getFileName().toString(); | ||
if (expectedVersion != null && !expectedVersion.equals(observedVersion)) { | ||
System.err.println("Wrong maven version, expected '" + expectedVersion + "' but got '" + observedVersion + "'" + mavenHome); | ||
System.exit(1); | ||
} | ||
String commandMatcher = System.getenv("EXPECT_COMMAND_REGEX"); | ||
String command = System.getProperty("sun.java.command"); | ||
if (commandMatcher != null && !Pattern.matches(commandMatcher, command)) { | ||
System.err.println("Wrong command line, '" + command + "' does not match '" + commandMatcher + "'"); | ||
System.exit(1); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...integration-tests/all-platforms/java/buildless-maven/src/main/resources/my-app.properties
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 @@ | ||
version=1.0 |
8 changes: 8 additions & 0 deletions
8
java/ql/integration-tests/all-platforms/java/buildless-maven/src/main/resources/page.xml
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,8 @@ | ||
<html> | ||
<head> | ||
<title>A sample</title> | ||
</head> | ||
<body> | ||
<p>Hello world!</p> | ||
</body> | ||
</html> |
4 changes: 4 additions & 0 deletions
4
java/ql/integration-tests/all-platforms/java/buildless-maven/src/main/resources/struts.xml
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<struts> | ||
This is a sample file | ||
</struts> |
20 changes: 20 additions & 0 deletions
20
...tegration-tests/all-platforms/java/buildless-maven/src/test/java/com/example/AppTest.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,20 @@ | ||
package com.example; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
{ | ||
/** | ||
* Rigorous Test :-) | ||
*/ | ||
@Test | ||
public void shouldAnswerWithTrue() | ||
{ | ||
assertTrue( true ); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
java/ql/integration-tests/all-platforms/java/buildless-maven/test.expected
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,8 @@ | ||
xmlFiles | ||
| pom.xml:0:0:0:0 | pom.xml | | ||
| src/main/resources/page.xml:0:0:0:0 | src/main/resources/page.xml | | ||
| src/main/resources/struts.xml:0:0:0:0 | src/main/resources/struts.xml | | ||
propertiesFiles | ||
#select | ||
| src/main/java/com/example/App.java:0:0:0:0 | App | | ||
| src/test/java/com/example/AppTest.java:0:0:0:0 | AppTest | |
5 changes: 5 additions & 0 deletions
5
java/ql/integration-tests/all-platforms/java/buildless-maven/test.py
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,5 @@ | ||
import sys | ||
|
||
from create_database_utils import * | ||
|
||
run_codeql_database_create([], lang="java", extra_env={"CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS": "true", "CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_CLASSPATH_FROM_BUILD_FILES": "true"}) |
9 changes: 9 additions & 0 deletions
9
java/ql/integration-tests/all-platforms/java/buildless-maven/test.ql
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,9 @@ | ||
import java | ||
|
||
from File f | ||
where f.isSourceFile() | ||
select f | ||
|
||
query predicate xmlFiles(XmlFile x) { any() } | ||
|
||
query predicate propertiesFiles(File f) { f.getExtension() = "properties" } |
30 changes: 30 additions & 0 deletions
30
java/ql/integration-tests/all-platforms/java/buildless/src/main/java/com/example/App.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,30 @@ | ||
package com.example; | ||
|
||
import java.util.regex.Pattern; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Hello world! | ||
* | ||
*/ | ||
public class App | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
System.out.println( "Hello World!" ); | ||
String expectedVersion = System.getenv("EXPECT_MAVEN"); | ||
Path mavenHome = Paths.get(System.getProperty("maven.home")).normalize(); | ||
String observedVersion = mavenHome.getFileName().toString(); | ||
if (expectedVersion != null && !expectedVersion.equals(observedVersion)) { | ||
System.err.println("Wrong maven version, expected '" + expectedVersion + "' but got '" + observedVersion + "'" + mavenHome); | ||
System.exit(1); | ||
} | ||
String commandMatcher = System.getenv("EXPECT_COMMAND_REGEX"); | ||
String command = System.getProperty("sun.java.command"); | ||
if (commandMatcher != null && !Pattern.matches(commandMatcher, command)) { | ||
System.err.println("Wrong command line, '" + command + "' does not match '" + commandMatcher + "'"); | ||
System.exit(1); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
java/ql/integration-tests/all-platforms/java/buildless/src/main/resources/my-app.properties
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 @@ | ||
version=1.0 |
8 changes: 8 additions & 0 deletions
8
java/ql/integration-tests/all-platforms/java/buildless/src/main/resources/page.xml
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,8 @@ | ||
<html> | ||
<head> | ||
<title>A sample</title> | ||
</head> | ||
<body> | ||
<p>Hello world!</p> | ||
</body> | ||
</html> |
4 changes: 4 additions & 0 deletions
4
java/ql/integration-tests/all-platforms/java/buildless/src/main/resources/struts.xml
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<struts> | ||
This is a sample file | ||
</struts> |
20 changes: 20 additions & 0 deletions
20
.../ql/integration-tests/all-platforms/java/buildless/src/test/java/com/example/AppTest.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,20 @@ | ||
package com.example; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
{ | ||
/** | ||
* Rigorous Test :-) | ||
*/ | ||
@Test | ||
public void shouldAnswerWithTrue() | ||
{ | ||
assertTrue( true ); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
java/ql/integration-tests/all-platforms/java/buildless/test.expected
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,7 @@ | ||
xmlFiles | ||
| src/main/resources/page.xml:0:0:0:0 | src/main/resources/page.xml | | ||
| src/main/resources/struts.xml:0:0:0:0 | src/main/resources/struts.xml | | ||
propertiesFiles | ||
#select | ||
| src/main/java/com/example/App.java:0:0:0:0 | App | | ||
| src/test/java/com/example/AppTest.java:0:0:0:0 | AppTest | |
5 changes: 5 additions & 0 deletions
5
java/ql/integration-tests/all-platforms/java/buildless/test.py
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,5 @@ | ||
import sys | ||
|
||
from create_database_utils import * | ||
|
||
run_codeql_database_create([], lang="java", extra_env={"CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS": "true"}) |
9 changes: 9 additions & 0 deletions
9
java/ql/integration-tests/all-platforms/java/buildless/test.ql
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,9 @@ | ||
import java | ||
|
||
from File f | ||
where f.isSourceFile() | ||
select f | ||
|
||
query predicate xmlFiles(XmlFile x) { any() } | ||
|
||
query predicate propertiesFiles(File f) { f.getExtension() = "properties" } |