From bcdadac88805d8ffe75c4872f9ebc1271bff7eaa Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sat, 15 Jun 2024 11:30:47 +0200 Subject: [PATCH] Fix broken build (#465) * Use valid item type to fix the test * Add new test to for testing an invalid item type Caused by https://github.com/openhab/website/pull/461 Signed-off-by: Wouter Born --- .../test/OhInfXmlValidationCheckTest.java | 23 ++++++++++++++++++- .../resources/OH-INF/thing/thing-types.xml | 20 ++++++++++++++++ .../resources/OH-INF/thing/thing-types.xml | 2 +- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 custom-checks/checkstyle/src/test/resources/checkstyle/ohInfXmlValidationCheckTest/invalidItemType/src/main/resources/OH-INF/thing/thing-types.xml diff --git a/custom-checks/checkstyle/src/test/java/org/openhab/tools/analysis/checkstyle/test/OhInfXmlValidationCheckTest.java b/custom-checks/checkstyle/src/test/java/org/openhab/tools/analysis/checkstyle/test/OhInfXmlValidationCheckTest.java index 5ca6b448..5bce87c7 100644 --- a/custom-checks/checkstyle/src/test/java/org/openhab/tools/analysis/checkstyle/test/OhInfXmlValidationCheckTest.java +++ b/custom-checks/checkstyle/src/test/java/org/openhab/tools/analysis/checkstyle/test/OhInfXmlValidationCheckTest.java @@ -20,6 +20,7 @@ import java.net.URL; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.List; import java.util.Locale; import org.junit.jupiter.api.BeforeAll; @@ -176,6 +177,26 @@ public void testInvalidConfig() throws Exception { verifyWithPath("invalidConfig", RELATIVE_PATH_TO_CONFIG, expectedMessages); } + @Test + public void testInvalidItemType() throws Exception { + assumeTrue(isResourceAvailable); + + int lineNumber = 15; + String[] expectedMessages = generateExpectedMessages(lineNumber, + "Value Invalid is not facet-valid with respect to enumeration " + + "[Call, Color, Contact, DateTime, Dimmer, Group, Image, Location, Number, Number:Acceleration, Number:AmountOfSubstance, " + + "Number:Angle, Number:Area, Number:ArealDensity, Number:CatalyticActivity, Number:Currency, Number:DataAmount, " + + "Number:DataTransferRate, Number:Density, Number:Dimensionless, Number:ElectricCapacitance, Number:ElectricCharge, " + + "Number:ElectricConductance, Number:ElectricConductivity, Number:ElectricCurrent, Number:ElectricInductance, " + + "Number:ElectricPotential, Number:ElectricResistance, Number:EmissionIntensity, Number:Energy, Number:EnergyPrice, " + + "Number:Force, Number:Frequency, Number:Illuminance, Number:Intensity, Number:Length, Number:LuminousFlux, " + + "Number:LuminousIntensity, Number:MagneticFlux, Number:MagneticFluxDensity, Number:Mass, Number:Power, Number:Pressure, " + + "Number:RadiationDoseAbsorbed, Number:RadiationDoseEffective, Number:RadiationSpecificActivity, Number:RadioactiveActivity, " + + "Number:SolidAngle, Number:Speed, Number:Temperature, Number:Time, Number:Volume, Number:VolumetricFlowRate, Player, " + + "Rollershutter, String, Switch]. It must be a value from the enumeration."); + verifyWithPath("invalidItemType", RELATIVE_PATH_TO_THING, expectedMessages); + } + @Test public void testMissingThingDescriptionsContent() throws Exception { assumeTrue(isResourceAvailable); @@ -203,7 +224,7 @@ private void verifyWithPath(String testSubDirectory, String testFilePath, String verify(createChecker(CONFIGURATION), testFiles, directoryPath + testFilePath, expectedMessages); } - private File[] listFilesForFolder(File folder, ArrayList files) { + private File[] listFilesForFolder(File folder, List files) { for (File fileEntry : folder.listFiles()) { if (fileEntry.isDirectory()) { listFilesForFolder(fileEntry, files); diff --git a/custom-checks/checkstyle/src/test/resources/checkstyle/ohInfXmlValidationCheckTest/invalidItemType/src/main/resources/OH-INF/thing/thing-types.xml b/custom-checks/checkstyle/src/test/resources/checkstyle/ohInfXmlValidationCheckTest/invalidItemType/src/main/resources/OH-INF/thing/thing-types.xml new file mode 100644 index 00000000..8f08f81c --- /dev/null +++ b/custom-checks/checkstyle/src/test/resources/checkstyle/ohInfXmlValidationCheckTest/invalidItemType/src/main/resources/OH-INF/thing/thing-types.xml @@ -0,0 +1,20 @@ + + + + + + Some sample description + + + + + + + Invalid + + Test + + + diff --git a/custom-checks/checkstyle/src/test/resources/checkstyle/ohInfXmlValidationCheckTest/validThingTypeXml/src/main/resources/OH-INF/thing/thing-types.xml b/custom-checks/checkstyle/src/test/resources/checkstyle/ohInfXmlValidationCheckTest/validThingTypeXml/src/main/resources/OH-INF/thing/thing-types.xml index 4cfdf302..71f5c743 100644 --- a/custom-checks/checkstyle/src/test/resources/checkstyle/ohInfXmlValidationCheckTest/validThingTypeXml/src/main/resources/OH-INF/thing/thing-types.xml +++ b/custom-checks/checkstyle/src/test/resources/checkstyle/ohInfXmlValidationCheckTest/validThingTypeXml/src/main/resources/OH-INF/thing/thing-types.xml @@ -12,7 +12,7 @@ - Text + Number:Energy Test