mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1499 Add Protobuf builder integration test
* Don't run the ProtobufBuilderTest with the processor_plugin_java8 and eclipse_jdt_java_8 (processor plugin runs before the proto java classes are created and the eclipse plugin has some bug) * Include *.proto for license checks
This commit is contained in:
parent
e29c25e5cb
commit
0fa964038c
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.itest.tests;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mapstruct.itest.testutil.runner.ProcessorSuite;
|
||||
import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner;
|
||||
|
||||
/**
|
||||
* ECLIPSE_JDT_JAVA_8 is not working with Protobuf. Use all other available processor types.
|
||||
*
|
||||
* @author Christian Bandowski
|
||||
*/
|
||||
@RunWith(ProcessorSuiteRunner.class)
|
||||
@ProcessorSuite(baseDir = "protobufBuilderTest",
|
||||
processorTypes = {
|
||||
ProcessorSuite.ProcessorType.ORACLE_JAVA_6,
|
||||
ProcessorSuite.ProcessorType.ORACLE_JAVA_7,
|
||||
ProcessorSuite.ProcessorType.ORACLE_JAVA_8,
|
||||
ProcessorSuite.ProcessorType.ORACLE_JAVA_9,
|
||||
ProcessorSuite.ProcessorType.ECLIPSE_JDT_JAVA_6,
|
||||
ProcessorSuite.ProcessorType.ECLIPSE_JDT_JAVA_7
|
||||
})
|
||||
public class ProtobufBuilderTest {
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Copyright MapStruct Authors.
|
||||
|
||||
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
-->
|
||||
<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>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-it-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>protobufIntegrationTest</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<os.mavenplugin.version>1.6.0</os.mavenplugin.version>
|
||||
<protobuf.mavenplugin.version>0.5.1</protobuf.mavenplugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>kr.motd.maven</groupId>
|
||||
<artifactId>os-maven-plugin</artifactId>
|
||||
<version>${os.mavenplugin.version}</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.xolstice.maven.plugins</groupId>
|
||||
<artifactId>protobuf-maven-plugin</artifactId>
|
||||
<version>${protobuf.mavenplugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>compile-custom</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}
|
||||
</protocArtifact>
|
||||
<pluginId>grpc-java</pluginId>
|
||||
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.2.0:exe:${os.detected.classifier}
|
||||
</pluginArtifact>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.itest.protobuf;
|
||||
|
||||
public class AddressDto {
|
||||
|
||||
private String addressLine;
|
||||
|
||||
public AddressDto() {
|
||||
|
||||
}
|
||||
|
||||
public AddressDto(String addressLine) {
|
||||
this.addressLine = addressLine;
|
||||
}
|
||||
|
||||
public String getAddressLine() {
|
||||
return addressLine;
|
||||
}
|
||||
|
||||
public void setAddressLine(String addressLine) {
|
||||
this.addressLine = addressLine;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.itest.protobuf;
|
||||
|
||||
public class PersonDto {
|
||||
private String name;
|
||||
private int age;
|
||||
private AddressDto address;
|
||||
|
||||
public PersonDto() {
|
||||
}
|
||||
|
||||
public PersonDto(String name, int age, AddressDto address) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public AddressDto getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(AddressDto address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.itest.protobuf;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) // protobuf has a lot of strange additional setters/getters
|
||||
public interface PersonMapper {
|
||||
|
||||
PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class );
|
||||
|
||||
PersonProtos.Person fromDto(PersonDto personDto);
|
||||
PersonDto toDto(PersonProtos.Person personDto);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
syntax = "proto3";
|
||||
|
||||
package itest.protobuf;
|
||||
|
||||
option java_package = "org.mapstruct.itest.protobuf";
|
||||
option java_outer_classname = "PersonProtos";
|
||||
|
||||
message Person {
|
||||
string name = 1;
|
||||
int32 age = 2;
|
||||
Address address = 3;
|
||||
|
||||
message Address {
|
||||
string addressLine = 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.itest.protobuf;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test for generation of Protobuf Builder Mapper implementations
|
||||
*
|
||||
* @author Christian Bandowski
|
||||
*/
|
||||
public class ProtobufMapperTest {
|
||||
|
||||
@Test
|
||||
public void testSimpleImmutableBuilderHappyPath() {
|
||||
PersonDto personDto = PersonMapper.INSTANCE.toDto( PersonProtos.Person.newBuilder()
|
||||
.setAge( 33 )
|
||||
.setName( "Bob" )
|
||||
.setAddress( PersonProtos.Person.Address.newBuilder()
|
||||
.setAddressLine( "Wild Drive" )
|
||||
.build() )
|
||||
.build() );
|
||||
|
||||
assertThat( personDto.getAge() ).isEqualTo( 33 );
|
||||
assertThat( personDto.getName() ).isEqualTo( "Bob" );
|
||||
assertThat( personDto.getAddress() ).isNotNull();
|
||||
assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLombokToImmutable() {
|
||||
PersonProtos.Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) );
|
||||
|
||||
assertThat( person.getAge() ).isEqualTo( 33 );
|
||||
assertThat( person.getName() ).isEqualTo( "Bob" );
|
||||
assertThat( person.getAddress() ).isNotNull();
|
||||
assertThat( person.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" );
|
||||
}
|
||||
}
|
@ -196,6 +196,11 @@
|
||||
<artifactId>auto-value</artifactId>
|
||||
<version>1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>3.6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.inferred</groupId>
|
||||
<artifactId>freebuilder</artifactId>
|
||||
@ -576,7 +581,7 @@
|
||||
<header>${basedir}/../etc/license.txt</header>
|
||||
<strictCheck>true</strictCheck>
|
||||
<excludes>
|
||||
<exclude>.idea/**</exclude>
|
||||
<exclude>**/.idea/**</exclude>
|
||||
<exclude>**/build-config/checkstyle.xml</exclude>
|
||||
<exclude>**/build-config/import-control.xml</exclude>
|
||||
<exclude>copyright.txt</exclude>
|
||||
@ -601,6 +606,7 @@
|
||||
</excludes>
|
||||
<mapping>
|
||||
<java>SLASHSTAR_STYLE</java>
|
||||
<proto>SLASHSTAR_STYLE</proto>
|
||||
</mapping>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
Loading…
x
Reference in New Issue
Block a user