-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and fix Kotlin source generation to work correctly
- Loading branch information
Showing
20 changed files
with
527 additions
and
228 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
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,2 @@ | ||
invoker.goals = clean package | ||
invoker.quiet = false |
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,113 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (C) 2023, 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.1</junit.version> | ||
<kotlin.version>1.9.21</kotlin.version> | ||
<protobuf.version>3.25.0</protobuf.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-kotlin</artifactId> | ||
<version>${protobuf.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${maven-surefire-plugin.version}</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
|
||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
|
||
<execution> | ||
<id>test-compile</id> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>${plugin-group-id}</groupId> | ||
<artifactId>${plugin-artifact-id}</artifactId> | ||
<version>${plugin-version}</version> | ||
|
||
<configuration> | ||
<generateKotlinWrappers>true</generateKotlinWrappers> | ||
<version>${protobuf.version}</version> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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, 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; | ||
} | ||
|
42 changes: 42 additions & 0 deletions
42
src/it/kotlin-simple/src/test/kotlin/org/example/helloworld/ProtobufTest.kt
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,42 @@ | ||
/* | ||
* Copyright (C) 2023, 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 org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertNotEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class ProtobufTest { | ||
|
||
@Test | ||
fun generatedProtobufSourcesAreValid() { | ||
// Given | ||
val expectedGreetingRequest = greetingRequest { | ||
name = "Ashley" | ||
} | ||
|
||
// When | ||
val baos = ByteArrayOutputStream() | ||
expectedGreetingRequest.writeTo(baos); | ||
val actualGreetingRequest = GreetingRequest.parseFrom(baos.toByteArray()) | ||
|
||
assertNotEquals(0, baos.toByteArray().size) | ||
|
||
// Then | ||
assertEquals(expectedGreetingRequest.name, actualGreetingRequest.name) | ||
} | ||
} |
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,51 @@ | ||
/* | ||
* Copyright (C) 2023, 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 expectedGeneratedJavaFiles = [ | ||
"org/example/helloworld/Helloworld", | ||
"org/example/helloworld/GreetingRequest", | ||
"org/example/helloworld/GreetingRequestOrBuilder", | ||
] | ||
def expectedGeneratedKotlinFiles = [ | ||
"org/example/helloworld/GreetingRequestKt", | ||
] | ||
|
||
assertThat(generatedSourcesDir).isDirectory() | ||
|
||
assertThat(classesDir).isDirectory() | ||
|
||
expectedGeneratedJavaFiles.forEach { | ||
assertThat(generatedSourcesDir.resolve("${it}.java")) | ||
.exists() | ||
.isNotEmptyFile() | ||
assertThat(classesDir.resolve("${it}.class")) | ||
.exists() | ||
.isNotEmptyFile() | ||
} | ||
|
||
expectedGeneratedKotlinFiles.forEach { | ||
assertThat(generatedSourcesDir.resolve("${it}.kt")) | ||
.exists() | ||
.isNotEmptyFile() | ||
assertThat(classesDir.resolve("${it}.class")) | ||
.exists() | ||
.isNotEmptyFile() | ||
} |
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,2 @@ | ||
invoker.goals = clean package | ||
invoker.quiet = false |
Oops, something went wrong.