5
5
6
6
package io .opentelemetry .contrib .jmxscraper ;
7
7
8
+ import static org .assertj .core .api .Assertions .assertThat ;
8
9
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
9
10
import static org .mockito .Mockito .mock ;
10
11
12
+ import io .opentelemetry .contrib .jmxscraper .config .ConfigurationException ;
13
+ import io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig ;
11
14
import io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfigFactory ;
15
+ import java .io .IOException ;
16
+ import java .io .InputStream ;
12
17
import java .util .Arrays ;
13
18
import java .util .Collections ;
14
19
import java .util .List ;
@@ -18,7 +23,7 @@ class JmxScraperTest {
18
23
@ Test
19
24
void shouldThrowExceptionWhenInvalidCommandLineArgsProvided () {
20
25
// Given
21
- List <String > emptyArgs = Collections .singletonList ("-inexistingOption " );
26
+ List <String > emptyArgs = Collections .singletonList ("-nonExistentOption " );
22
27
JmxScraperConfigFactory configFactoryMock = mock (JmxScraperConfigFactory .class );
23
28
24
29
// When and Then
@@ -29,11 +34,46 @@ void shouldThrowExceptionWhenInvalidCommandLineArgsProvided() {
29
34
@ Test
30
35
void shouldThrowExceptionWhenTooManyCommandLineArgsProvided () {
31
36
// Given
32
- List <String > emptyArgs = Arrays .asList ("-config" , "path" , "-inexistingOption " );
37
+ List <String > args = Arrays .asList ("-config" , "path" , "-nonExistentOption " );
33
38
JmxScraperConfigFactory configFactoryMock = mock (JmxScraperConfigFactory .class );
34
39
35
40
// When and Then
36
- assertThatThrownBy (() -> JmxScraper .createConfigFromArgs (emptyArgs , configFactoryMock ))
41
+ assertThatThrownBy (() -> JmxScraper .createConfigFromArgs (args , configFactoryMock ))
37
42
.isInstanceOf (ArgumentsParsingException .class );
38
43
}
44
+
45
+ @ Test
46
+ void shouldCreateConfig_propertiesLoadedFromFile ()
47
+ throws ConfigurationException , ArgumentsParsingException {
48
+ // Given
49
+ String filePath = ClassLoader .getSystemClassLoader ().getResource ("validConfig.properties" ).getPath ();
50
+ List <String > args = Arrays .asList ("-config" , filePath );
51
+ JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory ();
52
+
53
+ // When
54
+ JmxScraperConfig config = JmxScraper .createConfigFromArgs (args , configFactory );
55
+
56
+ // Then
57
+ assertThat (config ).isNotNull ();
58
+ }
59
+
60
+ @ Test
61
+ void shouldCreateConfig_propertiesLoadedFromStdIn ()
62
+ throws ConfigurationException , ArgumentsParsingException , IOException {
63
+ InputStream originalIn = System .in ;
64
+ try (InputStream stream = ClassLoader .getSystemClassLoader ().getResourceAsStream ("validConfig.properties" )) {
65
+ // Given
66
+ System .setIn (stream );
67
+ List <String > args = Arrays .asList ("-config" , "-" );
68
+ JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory ();
69
+
70
+ // When
71
+ JmxScraperConfig config = JmxScraper .createConfigFromArgs (args , configFactory );
72
+
73
+ // Then
74
+ assertThat (config ).isNotNull ();
75
+ } finally {
76
+ System .setIn (originalIn );
77
+ }
78
+ }
39
79
}
0 commit comments