martinzink commented on code in PR #1926:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1926#discussion_r2000462572
##########
libminifi/test/unit/PropertyValidationTests.cpp:
##########
@@ -17,77 +17,57 @@
#include "unit/TestBase.h"
#include "unit/Catch.h"
-#include "core/ConfigurableComponent.h"
#include "core/PropertyDefinitionBuilder.h"
-#include "utils/PropertyErrors.h"
#include "core/PropertyType.h"
-#include "core/PropertyValue.h"
+#include "utils/PropertyErrors.h"
namespace org::apache::nifi::minifi::core {
-/**
- * This Tests checks a deprecated behavior that should be removed
- * in the next major release.
- */
-TEST_CASE("Some default values get coerced to typed variants") {
- auto prop = Property("prop", "d", "true");
- REQUIRE_THROWS_AS(prop.setValue("banana"),
utils::internal::ConversionException);
-
- const std::string SPACE = " ";
- auto prop2 = Property("prop", "d", SPACE + "true");
- prop2.setValue("banana");
-}
TEST_CASE("Converting invalid PropertyValue") {
static constexpr auto property_definition =
PropertyDefinitionBuilder<>::createProperty("prop")
- .withPropertyType(core::StandardPropertyTypes::INTEGER_TYPE)
+ .withValidator(core::StandardPropertyTypes::INTEGER_VALIDATOR)
.withDefaultValue("0")
.build();
Property property{property_definition};
- REQUIRE_THROWS_AS(property.setValue("not int"),
utils::internal::ParseException);
- auto cast_check = [&]{ return static_cast<int>(property.getValue()) == 0; };
// To avoid unused-value warning
- REQUIRE_THROWS_AS(cast_check(), utils::internal::InvalidValueException);
+ CHECK_FALSE(property.setValue("not int").has_value());
+ CHECK(property.getValue() == "0");
}
TEST_CASE("Parsing int has baggage after") {
static constexpr auto property_definition =
PropertyDefinitionBuilder<>::createProperty("prop")
- .withPropertyType(core::StandardPropertyTypes::INTEGER_TYPE)
+ .withValidator(core::StandardPropertyTypes::INTEGER_VALIDATOR)
.withDefaultValue("0")
.build();
Property property{property_definition};
- REQUIRE_THROWS_AS(property.setValue("55almost int"),
utils::internal::ParseException);
+ CHECK_FALSE(property.setValue("not int").has_value());
+ CHECK(property.getValue() == "0");
}
TEST_CASE("Parsing int has spaces") {
static constexpr auto property_definition =
PropertyDefinitionBuilder<>::createProperty("prop")
- .withPropertyType(core::StandardPropertyTypes::INTEGER_TYPE)
- .withDefaultValue("0")
- .build();
- Property property{property_definition};
- property.setValue(" 55 ");
- REQUIRE(static_cast<int>(property.getValue()) == 55);
-}
-
-TEST_CASE("Parsing int out of range") {
- static constexpr auto property_definition =
PropertyDefinitionBuilder<>::createProperty("prop")
- .withPropertyType(core::StandardPropertyTypes::INTEGER_TYPE)
+ .withValidator(core::StandardPropertyTypes::INTEGER_VALIDATOR)
.withDefaultValue("0")
.build();
Property property{property_definition};
- REQUIRE_THROWS_AS(property.setValue(" 5000000000 "),
utils::internal::ParseException);
Review Comment:
Makes sense,
https://github.com/apache/nifi-minifi-cpp/pull/1926/commits/82054cb696d7a67f637781402cadb8496010ec0b
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]