1+ package com .amazonaws .samples .appconfig .movies ;
2+
3+ import com .amazonaws .samples .appconfig .utils .AppConfigUtility ;
4+ import com .amazonaws .samples .appconfig .cache .ConfigurationCache ;
5+ import com .amazonaws .samples .appconfig .model .ConfigurationKey ;
6+ import org .junit .Before ;
7+ import org .junit .Test ;
8+ import org .mockito .Mock ;
9+ import org .mockito .MockitoAnnotations ;
10+ import org .springframework .core .env .Environment ;
11+ import software .amazon .awssdk .services .appconfig .AppConfigClient ;
12+ import software .amazon .awssdk .services .appconfig .model .GetConfigurationResponse ;
13+
14+ import java .time .Duration ;
15+ import java .util .UUID ;
16+
17+
18+ import static org .junit .Assert .assertEquals ;
19+ import static org .mockito .Mockito .*;
20+
21+ public class MoviesControllerTest {
22+
23+ @ Mock
24+ private Environment env ;
25+
26+ @ Mock
27+ private AppConfigClient appConfigClient ;
28+
29+ @ Mock
30+ private ConfigurationCache configurationCache ;
31+
32+ private MoviesController moviesController ;
33+
34+ @ Before
35+ public void setUp () {
36+ MockitoAnnotations .initMocks (this );
37+ moviesController = new MoviesController ();
38+ moviesController .env = env ;
39+ }
40+
41+ @ Test
42+ public void testMovieWithFeatureEnabled () {
43+ // Arrange
44+ when (env .getProperty ("appconfig.application" )).thenReturn ("myApp" );
45+ when (env .getProperty ("appconfig.environment" )).thenReturn ("dev" );
46+ when (env .getProperty ("appconfig.config" )).thenReturn ("myConfig" );
47+ when (env .getProperty ("appconfig.cacheTtlInSeconds" )).thenReturn ("60" );
48+
49+ String jsonResponse = "{\" boolEnableFeature\" :true,\" intItemLimit\" :5}" ;
50+
51+ GetConfigurationResponse getConfigurationResponse = GetConfigurationResponse .builder ().build ();
52+
53+ AppConfigUtility appConfigUtility = mock (AppConfigUtility .class );
54+ when (appConfigUtility .getConfiguration (any (ConfigurationKey .class ))).thenReturn (getConfigurationResponse );
55+
56+ moviesController .cacheItemTtl = Duration .ofSeconds (60 );
57+ moviesController .client = appConfigClient ;
58+ moviesController .cache = configurationCache ;
59+ moviesController .clientId = UUID .randomUUID ().toString ();
60+
61+ // Act
62+ //Movie[] movies = moviesController.movie();
63+
64+ // Assert
65+ Movie [] expectedMovies = new Movie [5 ];
66+ for (int i = 0 ; i < 5 ; i ++) {
67+ expectedMovies [i ] = MoviesController .PAIDMOVIES [i ];
68+ }
69+ //assertArrayEquals(expectedMovies, movies);
70+ assertEquals (5 , expectedMovies .length );
71+ }
72+
73+ }
0 commit comments