diff --git a/all/entrypoint.sh b/all/entrypoint.sh index 9358ee71..2c40d5d2 100755 --- a/all/entrypoint.sh +++ b/all/entrypoint.sh @@ -396,6 +396,10 @@ if [[ $GEN_VALIDATOR == true && $GEN_LANG == "gogo" ]]; then GEN_STRING="$GEN_STRING --validate_out=lang=gogo${VALIDATOR_SOURCE_RELATIVE}:$OUT_DIR" fi +if [[ $GEN_VALIDATOR == true && $GEN_LANG == "java" ]]; then + GEN_STRING="$GEN_STRING --validate_out=lang=java:$OUT_DIR" +fi + if [[ $GEN_DOCS == true ]]; then mkdir -p $OUT_DIR/doc GEN_STRING="$GEN_STRING --doc_opt=$DOCS_FORMAT --doc_out=$OUT_DIR/doc" diff --git a/all/test.sh b/all/test.sh index b6b93d5d..f959732f 100755 --- a/all/test.sh +++ b/all/test.sh @@ -187,9 +187,8 @@ testGeneration() { fi fi - # Test that we have generated the test.pb.go file. - expected_file_name="/all/test.pb.go" - if [[ "$extra_args" == *"--with-validator"* ]]; then + # Test that we have generated the test.pb.go file. + if [[ "$extra_args" == *"--with-validator"* ]] && [[ "$lang" == "go" ]]; then expected_file_name1="/all/test.pb.go" expected_file_name2="/all/test.pb.validate.go" if [[ "$extra_args" == *"--validator-source-relative"* ]]; then @@ -207,6 +206,22 @@ testGeneration() { fi fi + if [[ "$extra_args" == *"--with-validator"* ]] && [[ "$lang" == "java" ]]; then + # Test that we have generated the Test.java and TestValidator.java files + java_file_count=$(find $expected_output_dir -type f -name "Test.java" | wc -l) + if [ $java_file_count -ne 1 ]; then + echo >&2 "[Fail] $name" + echo >&2 "Test.java file was not generated in $expected_output_dir" + exit 1 + fi + java_validator_file_count=$(find $expected_output_dir -type f -name "TestValidator.java" | wc -l) + if [ $java_validator_file_count -ne 1 ]; then + echo >&2 "[Fail] $name" + echo >&2 "TestValidator.java file was not generated in $expected_output_dir" + exit 1 + fi + fi + if [[ "$extra_args" == *"--with-go-proto-validator"* ]]; then expected_file_name1="/all/test.pb.go" expected_file_name2="/all/test.pb.validate.go" @@ -347,6 +362,9 @@ testGeneration "web_with_commonjs_imports" web "gen/pb-web" 0 --grpc-web-out imp # Test java output testGeneration "java_test_jar" java "gen" 0 -o gen/test.jar +# Test java output +testGeneration "java_with_validator" java "gen/pb-java" 0 --with-validator + # Generate proto files for lang in ${LANGS[@]}; do expected_output_dir="" diff --git a/all/test/test.proto b/all/test/test.proto index a41d8584..da854802 100644 --- a/all/test/test.proto +++ b/all/test/test.proto @@ -5,6 +5,7 @@ package Messages; import "all/test/include.proto"; import "google/api/annotations.proto"; import "google/protobuf/field_mask.proto"; +import "validate/validate.proto"; option go_package = "all/;all"; @@ -29,7 +30,7 @@ message ListMessageRequest { } message UpdateMessageRequest { - string name = 1; + string name = 1 [(validate.rules).string.len = 1]; google.protobuf.FieldMask update_mask = 2; }