|
| 1 | +// Copyright (c) 2022, Oracle and/or its affiliates. |
| 2 | +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 3 | + |
| 4 | +package oracle.kubernetes.operator.logging; |
| 5 | + |
| 6 | +import java.io.IOException; |
| 7 | +import java.lang.reflect.Field; |
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Properties; |
| 11 | + |
| 12 | +import org.junit.jupiter.api.BeforeAll; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | + |
| 15 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 16 | +import static org.hamcrest.Matchers.empty; |
| 17 | + |
| 18 | +class MessageIntegrityTest { |
| 19 | + |
| 20 | + private static final DuplicateFindingProperties properties = new DuplicateFindingProperties(); |
| 21 | + |
| 22 | + @BeforeAll |
| 23 | + static void setUpClass() throws IOException { |
| 24 | + properties.load(MessageIntegrityTest.class.getClassLoader().getResourceAsStream("Operator.properties")); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + void operatorPropertiesHasNoDuplications() throws IOException { |
| 29 | + assertThat(properties.duplicateProperties, empty()); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + void messageKeysAllHaveProperties() throws IllegalAccessException { |
| 34 | + List<String> missingProperties = new ArrayList<>(); |
| 35 | + for (Field field : MessageKeys.class.getDeclaredFields()) { |
| 36 | + if (field.getType().equals(String.class) && !(properties.containsKey(field.get(null)))) { |
| 37 | + missingProperties.add(field.getName()); |
| 38 | + } |
| 39 | + } |
| 40 | + assertThat("MessageKey entries with no properties", missingProperties, empty()); |
| 41 | + } |
| 42 | + |
| 43 | + static class DuplicateFindingProperties extends Properties { |
| 44 | + private final List<Object> duplicateProperties = new ArrayList<>(); |
| 45 | + |
| 46 | + @Override |
| 47 | + public synchronized Object put(Object key, Object value) { |
| 48 | + if (containsKey(key)) { |
| 49 | + return duplicateProperties.add(key); |
| 50 | + } else { |
| 51 | + return super.put(key, value); |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments