View Javadoc
1   package de.dlr.shepard.data.timeseries.utilities;
2   
3   import de.dlr.shepard.common.exceptions.InvalidBodyException;
4   import de.dlr.shepard.data.timeseries.model.Timeseries;
5   import org.junit.jupiter.api.Assertions;
6   import org.junit.jupiter.api.Test;
7   
8   public class TimeseriesValidatorTest {
9   
10    @Test
11    public void assertTimeseriesPropertiesAreValid_everythingIsCorrect_noException() {
12      Timeseries timeseries = new Timeseries("measurement", "field", "device", "location", "symbolicName");
13  
14      Assertions.assertDoesNotThrow(() -> {
15        TimeseriesValidator.assertTimeseriesPropertiesAreValid(timeseries);
16      });
17    }
18  
19    @Test
20    public void assertTimeseriesPropertiesAreValid_everythingIsNull_throwsException() {
21      Timeseries timeseries = new Timeseries(null, null, null, null, null);
22  
23      InvalidBodyException thrown = Assertions.assertThrowsExactly(InvalidBodyException.class, () -> {
24        TimeseriesValidator.assertTimeseriesPropertiesAreValid(timeseries);
25      });
26      Assertions.assertTrue(thrown.getMessage().contains("not allowed to be empty"));
27    }
28  
29    @Test
30    public void assertTimeseriesPropertiesAreValid_containsSpace_throwsException() {
31      Timeseries timeseries = new Timeseries("my measurement", "a", "b", "c", "d");
32  
33      Assertions.assertThrowsExactly(InvalidBodyException.class, () -> {
34        TimeseriesValidator.assertTimeseriesPropertiesAreValid(timeseries);
35      });
36    }
37  
38    @Test
39    public void assertTimeseriesPropertiesAreValid_containsPoint_throwsException() {
40      Timeseries timeseries = new Timeseries("my.measurement", "a", "b", "c", "d");
41  
42      Assertions.assertThrowsExactly(InvalidBodyException.class, () -> {
43        TimeseriesValidator.assertTimeseriesPropertiesAreValid(timeseries);
44      });
45    }
46  
47    @Test
48    public void assertTimeseriesPropertiesAreValid_containsComma_throwsException() {
49      Timeseries timeseries = new Timeseries("my,measurement", "a", "b", "c", "d");
50  
51      Assertions.assertThrowsExactly(InvalidBodyException.class, () -> {
52        TimeseriesValidator.assertTimeseriesPropertiesAreValid(timeseries);
53      });
54    }
55  
56    @Test
57    public void assertTimeseriesPropertiesAreValid_containsSlash_throwsException() {
58      Timeseries timeseries = new Timeseries("my/measurement", "a", "b", "c", "d");
59  
60      Assertions.assertThrowsExactly(InvalidBodyException.class, () -> {
61        TimeseriesValidator.assertTimeseriesPropertiesAreValid(timeseries);
62      });
63    }
64  
65    @Test
66    public void assertTimeseriesPropertiesAreValid_emptyString_throwsException() {
67      Timeseries timeseries = new Timeseries("", "a", "b", "c", "d");
68  
69      Assertions.assertThrowsExactly(InvalidBodyException.class, () -> {
70        TimeseriesValidator.assertTimeseriesPropertiesAreValid(timeseries);
71      });
72    }
73  }