-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-26: Add tests for $PATH resolution of protoc
- Loading branch information
Showing
7 changed files
with
239 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
invoker.goals = clean package |
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,91 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (C) 2023 - 2024, Ashley Scopes. | ||
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 | ||
http://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> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>example</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<properties> | ||
<junit.version>5.10.2</junit.version> | ||
<protobuf.version>3.25.1</protobuf.version> | ||
|
||
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version> | ||
<maven-surefire-plugin.version>3.2.2</maven-surefire-plugin.version> | ||
|
||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.protobuf</groupId> | ||
<artifactId>protobuf-java</artifactId> | ||
<version>${protobuf.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven-compiler-plugin.version}</version> | ||
|
||
<configuration> | ||
<release>11</release> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${maven-surefire-plugin.version}</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>${plugin-group-id}</groupId> | ||
<artifactId>${plugin-artifact-id}</artifactId> | ||
<version>${plugin-version}</version> | ||
|
||
<configuration> | ||
<protocVersion>PATH</protocVersion> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
27 changes: 27 additions & 0 deletions
27
src/it/test-java-main-system-protoc/src/main/protobuf/helloworld.proto
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,27 @@ | ||
// | ||
// Copyright (C) 2023 - 2024, Ashley Scopes. | ||
// | ||
// 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 | ||
// | ||
// http://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. | ||
// | ||
|
||
syntax = "proto3"; | ||
|
||
option java_multiple_files = true; | ||
option java_package = "org.example.helloworld"; | ||
|
||
package org.example.helloworld; | ||
|
||
message GreetingRequest { | ||
string name = 1; | ||
} | ||
|
60 changes: 60 additions & 0 deletions
60
src/it/test-java-main-system-protoc/src/test/java/org/example/helloworld/ProtobufTest.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,60 @@ | ||
/* | ||
* Copyright (C) 2023 - 2024, Ashley Scopes. | ||
* | ||
* 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 | ||
* | ||
* http://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 org.example.helloworld; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.util.ArrayList; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class ProtobufTest { | ||
@Test | ||
void generatedProtobufSourcesAreFullMessages() throws Throwable { | ||
// When | ||
var superClasses = new ArrayList<String>(); | ||
Class<?> superClass = GreetingRequest.class; | ||
|
||
do { | ||
superClasses.add(superClass.getName()); | ||
superClass = superClass.getSuperclass(); | ||
} while (superClass != null); | ||
|
||
// Then | ||
assertTrue(superClasses.contains("com.google.protobuf.GeneratedMessageV3")); | ||
} | ||
|
||
@Test | ||
void generatedProtobufSourcesAreValid() throws Throwable { | ||
// Given | ||
var expectedGreetingRequest = GreetingRequest | ||
.newBuilder() | ||
.setName("Ashley") | ||
.build(); | ||
|
||
// When | ||
var baos = new ByteArrayOutputStream(); | ||
expectedGreetingRequest.writeTo(baos); | ||
var actualGreetingRequest = GreetingRequest.parseFrom(baos.toByteArray()); | ||
|
||
assertNotEquals(0, baos.toByteArray().length); | ||
|
||
// Then | ||
assertEquals(expectedGreetingRequest.getName(), actualGreetingRequest.getName()); | ||
} | ||
} |
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 @@ | ||
/* | ||
* Copyright (C) 2023 - 2024, Ashley Scopes. | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
import java.nio.file.Path | ||
|
||
import static org.assertj.core.api.Assertions.assertThat | ||
|
||
Path baseDirectory = basedir.toPath().toAbsolutePath() | ||
def generatedSourcesDir = baseDirectory.resolve("target/generated-sources/protobuf") | ||
def classesDir = baseDirectory.resolve("target/classes") | ||
def expectedGeneratedFiles = [ | ||
"org/example/helloworld/Helloworld", | ||
"org/example/helloworld/GreetingRequest", | ||
"org/example/helloworld/GreetingRequestOrBuilder", | ||
] | ||
|
||
assertThat(generatedSourcesDir).isDirectory() | ||
|
||
assertThat(classesDir).isDirectory() | ||
|
||
expectedGeneratedFiles.forEach { | ||
assertThat(generatedSourcesDir.resolve("${it}.java")) | ||
.exists() | ||
.isNotEmptyFile() | ||
assertThat(classesDir.resolve("${it}.class")) | ||
.exists() | ||
.isNotEmptyFile() | ||
|
||
} |