10
10
import org .mockito .Mock ;
11
11
import org .mockito .runners .MockitoJUnitRunner ;
12
12
13
+ import com .amazonaws .ResponseMetadata ;
14
+ import com .amazonaws .http .SdkHttpMetadata ;
13
15
import com .amazonaws .services .simplesystemsmanagement .AWSSimpleSystemsManagement ;
14
16
import com .amazonaws .services .simplesystemsmanagement .model .GetParameterRequest ;
15
17
import com .amazonaws .services .simplesystemsmanagement .model .GetParameterResult ;
@@ -28,19 +30,25 @@ public class ParameterStoreSourceTest
28
30
29
31
@ Mock
30
32
private AWSSimpleSystemsManagement ssmClientMock ;
33
+ @ Mock
34
+ private SdkHttpMetadata sdkHttpMetadataMock ;
35
+ @ Mock
36
+ private ResponseMetadata responseMetadataMock ;
31
37
32
38
private ParameterStoreSource parameterStoreSource ;
33
39
34
40
@ Before
35
41
public void setUp ()
36
42
{
43
+ when (sdkHttpMetadataMock .getHttpStatusCode ()).thenReturn (200 );
44
+
37
45
parameterStoreSource = new ParameterStoreSource (ssmClientMock , false );
38
46
}
39
47
40
48
@ Test
41
49
public void testGetProperty ()
42
50
{
43
- when (ssmClientMock .getParameter (getParameterRequest (VALID_PROPERTY_NAME ))).thenReturn (new GetParameterResult ().withParameter (new Parameter ().withValue (VALID_PROPERTY_VALUE )));
51
+ when (ssmClientMock .getParameter (getParameterRequest (VALID_PROPERTY_NAME ))).thenReturn (getGetParameterResult ().withParameter (new Parameter ().withValue (VALID_PROPERTY_VALUE )));
44
52
45
53
Object value = parameterStoreSource .getProperty (VALID_PROPERTY_NAME );
46
54
@@ -74,6 +82,42 @@ public void shouldThrowOnGetPropertyWhenNotFoundAndHaltBootIsTrue()
74
82
parameterStoreSourceHaltingBoot .getProperty (INVALID_PROPERTY_NAME );
75
83
}
76
84
85
+ @ Test (expected = ParameterStoreError .class )
86
+ public void shouldThrowWhenStatusCodeIsNot200 ()
87
+ {
88
+ when (sdkHttpMetadataMock .getHttpStatusCode ()).thenReturn (503 );
89
+ when (ssmClientMock .getParameter (getParameterRequest (VALID_PROPERTY_NAME ))).thenReturn (getGetParameterResult ());
90
+ ParameterStoreSource parameterStoreSourceHaltingBoot = new ParameterStoreSource (ssmClientMock , true );
91
+
92
+ parameterStoreSourceHaltingBoot .getProperty (VALID_PROPERTY_NAME );
93
+ }
94
+
95
+ @ Test (expected = ParameterStoreError .class )
96
+ public void shouldThrowWhenParameterIsNull ()
97
+ {
98
+ when (ssmClientMock .getParameter (getParameterRequest (VALID_PROPERTY_NAME ))).thenReturn (getGetParameterResult ());
99
+ ParameterStoreSource parameterStoreSourceHaltingBoot = new ParameterStoreSource (ssmClientMock , true );
100
+
101
+ parameterStoreSourceHaltingBoot .getProperty (VALID_PROPERTY_NAME );
102
+ }
103
+
104
+ @ Test (expected = ParameterStoreError .class )
105
+ public void shouldThrowWhenParameterValueIsNull ()
106
+ {
107
+ when (ssmClientMock .getParameter (getParameterRequest (VALID_PROPERTY_NAME ))).thenReturn (getGetParameterResult ().withParameter (new Parameter ()));
108
+ ParameterStoreSource parameterStoreSourceHaltingBoot = new ParameterStoreSource (ssmClientMock , true );
109
+
110
+ parameterStoreSourceHaltingBoot .getProperty (VALID_PROPERTY_NAME );
111
+ }
112
+
113
+ private GetParameterResult getGetParameterResult ()
114
+ {
115
+ GetParameterResult getParameterResult = new GetParameterResult ();
116
+ getParameterResult .setSdkHttpMetadata (sdkHttpMetadataMock );
117
+ getParameterResult .setSdkResponseMetadata (responseMetadataMock );
118
+ return getParameterResult ;
119
+ }
120
+
77
121
private GetParameterRequest getParameterRequest (String parameterName )
78
122
{
79
123
return new GetParameterRequest ().withName (parameterName ).withWithDecryption (true );
0 commit comments