mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Check for duplicate tags in SemanticTags.csv (#4702)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
+24
@@ -15,7 +15,12 @@ package org.openhab.core.semantics;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -83,6 +88,25 @@ public class SemanticTagsTest {
|
||||
temperatureTagClass = SemanticTags.getById("Property_Temperature");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureTagsAreUnique() {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader("model/SemanticTags.csv"))) {
|
||||
Set<String> tags = new HashSet<>();
|
||||
String line;
|
||||
reader.readLine(); // Skip the header line
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// We're only interested in the second column,
|
||||
// so quoted fields in synonyms/description are not a problem
|
||||
String[] columns = line.split(",");
|
||||
String tag = columns[1].trim(); // Tag is in the second column
|
||||
assertTrue(tags.add(tag), "Duplicate tag found: " + tag);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
fail("Failed to read SemanticTags.csv. Current dir: " + System.getProperty("user.dir") + " Error: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTagClasses() {
|
||||
assertNotNull(roomTagClass);
|
||||
|
||||
Reference in New Issue
Block a user