generated from SpineEventEngine/template
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #138 from SpineEventEngine/set-once-protodata
Support `(set_once)` in validation codegen
- Loading branch information
Showing
26 changed files
with
3,152 additions
and
74 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
59 changes: 59 additions & 0 deletions
59
.../validation-gen/src/test/java/io/spine/test/tools/validate/setonce/SetOnceAssertions.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,59 @@ | ||
/* | ||
* Copyright 2024, TeamDev. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Redistribution and use in source and/or binary forms, with or without | ||
* modification, must retain the above copyright notice and the following | ||
* disclaimer. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package io.spine.test.tools.validate.setonce; | ||
|
||
import io.spine.validate.ValidationException; | ||
import org.junit.jupiter.api.function.Executable; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* Test assertions for {@code (set_once)} tests. | ||
*/ | ||
final class SetOnceAssertions { | ||
|
||
/** | ||
* Prohibit instantiation of this utility class. | ||
*/ | ||
private SetOnceAssertions() { | ||
} | ||
|
||
/** | ||
* Asserts that the given {@code executable} throws {@link ValidationException}. | ||
*/ | ||
static void assertValidationFails(Executable executable) { | ||
assertThrows(ValidationException.class, executable); | ||
} | ||
|
||
/** | ||
* Asserts that the given {@code executable} doesn't throw anything. | ||
*/ | ||
static void assertValidationPasses(Executable executable) { | ||
assertDoesNotThrow(executable); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
...idation-gen/src/test/java/io/spine/test/tools/validate/setonce/SetOnceConstraintTest.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,109 @@ | ||
/* | ||
* Copyright 2024, TeamDev. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Redistribution and use in source and/or binary forms, with or without | ||
* modification, must retain the above copyright notice and the following | ||
* disclaimer. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package io.spine.test.tools.validate.setonce; | ||
|
||
import io.spine.test.tools.validate.Name; | ||
import io.spine.test.tools.validate.SetOnceExplicitFalse; | ||
import io.spine.test.tools.validate.SetOnceImplicitFalse; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.spine.test.tools.validate.setonce.SetOnceAssertions.assertValidationPasses; | ||
|
||
@DisplayName("`(set_once)` constraint should") | ||
class SetOnceConstraintTest { | ||
|
||
@Test | ||
@DisplayName("not affect fields without the option") | ||
void notAffectFieldsWithoutOption() { | ||
assertValidationPasses(() -> SetOnceImplicitFalse.newBuilder() | ||
.setMessage(Name.newBuilder().setValue("MyName1").build()) | ||
.setMessage(Name.newBuilder().setValue("MyName2").build()) | ||
.setString("string-1") | ||
.setString("string-2") | ||
.setDouble(0.25) | ||
.setDouble(0.75) | ||
.setFloat(0.25f) | ||
.setFloat(0.75f) | ||
.setInt32(5) | ||
.setInt32(10) | ||
.setInt64(5) | ||
.setInt64(10) | ||
.setUint32(5) | ||
.setUint32(10) | ||
.setUint64(5) | ||
.setUint64(10) | ||
.setSint32(5) | ||
.setSint32(10) | ||
.setSint64(5) | ||
.setSint64(10) | ||
.setFixed32(5) | ||
.setFixed32(10) | ||
.setFixed64(5) | ||
.setFixed64(10) | ||
.setSfixed32(5) | ||
.setSfixed32(10) | ||
.setSfixed64(5) | ||
.setSfixed64(10) | ||
.build()); | ||
} | ||
|
||
@Test | ||
@DisplayName("not affect fields with the option set to `false`") | ||
void notAffectFieldsWithTheOptionSetToFalse() { | ||
assertValidationPasses(() -> SetOnceExplicitFalse.newBuilder() | ||
.setMessage(Name.newBuilder().setValue("MyName1").build()) | ||
.setMessage(Name.newBuilder().setValue("MyName2").build()) | ||
.setString("string-1") | ||
.setString("string-2") | ||
.setDouble(0.25) | ||
.setDouble(0.75) | ||
.setFloat(0.25f) | ||
.setFloat(0.75f) | ||
.setInt32(5) | ||
.setInt32(10) | ||
.setInt64(5) | ||
.setInt64(10) | ||
.setUint32(5) | ||
.setUint32(10) | ||
.setUint64(5) | ||
.setUint64(10) | ||
.setSint32(5) | ||
.setSint32(10) | ||
.setSint64(5) | ||
.setSint64(10) | ||
.setFixed32(5) | ||
.setFixed32(10) | ||
.setFixed64(5) | ||
.setFixed64(10) | ||
.setSfixed32(5) | ||
.setSfixed32(10) | ||
.setSfixed64(5) | ||
.setSfixed64(10) | ||
.build()); | ||
} | ||
} |
Oops, something went wrong.