Skip to content

Commit

Permalink
fix(tests): refactor a test to consume retrofit2 interfaces FiatService
Browse files Browse the repository at this point in the history
  • Loading branch information
kirangodishala committed Dec 6, 2024
1 parent f017f16 commit 89f896c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions clouddriver-docker/clouddriver-docker.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation "com.netflix.spectator:spectator-api"
implementation "com.squareup.retrofit:converter-jackson"
implementation "com.squareup.retrofit:retrofit"
implementation "com.squareup.retrofit2:retrofit-mock"
implementation "org.apache.commons:commons-compress:1.21"
implementation "commons-io:commons-io"
implementation "io.spinnaker.fiat:fiat-api:$fiatVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.springframework.context.annotation.Import;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import retrofit2.mock.Calls;

@SpringBootTest(classes = TestConfig.class, properties = "services.fiat.cache.max-entries=0")
@AutoConfigureMockMvc
Expand Down Expand Up @@ -112,7 +113,7 @@ void setUp() {
@Test
void authorizedToReadTags() throws Exception {
var permissions = createAuthorizedUserPermission();
given(fiatService.getUserPermission(eq("user"))).willReturn(permissions);
given(fiatService.getUserPermission(eq("user"))).willReturn(Calls.response(permissions));

mockMvc
.perform(
Expand All @@ -125,7 +126,7 @@ void authorizedToReadTags() throws Exception {
@Test
void notAuthorizedToReadTags() throws Exception {
var permissions = createUnauthorizedUserPermission();
given(fiatService.getUserPermission("user")).willReturn(permissions);
given(fiatService.getUserPermission("user")).willReturn(Calls.response(permissions));

mockMvc
.perform(
Expand All @@ -138,7 +139,7 @@ void notAuthorizedToReadTags() throws Exception {
@Test
void canSearchForAuthorizedItems() throws Exception {
var permissions = createAuthorizedUserPermission();
given(fiatService.getUserPermission("user")).willReturn(permissions);
given(fiatService.getUserPermission("user")).willReturn(Calls.response(permissions));
cache.merge(Keys.Namespace.TAGGED_IMAGE.getNs(), createTestAccountTaggedImageCacheData());
var credentials = createTestAccountCredentials();
accountCredentialsRepository.save(credentials.getName(), credentials);
Expand All @@ -151,7 +152,7 @@ void canSearchForAuthorizedItems() throws Exception {
@Test
void filtersOutUnauthorizedItems() throws Exception {
var permissions = createUnauthorizedUserPermission();
given(fiatService.getUserPermission("user")).willReturn(permissions);
given(fiatService.getUserPermission("user")).willReturn(Calls.response(permissions));
cache.merge(Keys.Namespace.TAGGED_IMAGE.getNs(), createTestAccountTaggedImageCacheData());
var credentials = createTestAccountCredentials();
accountCredentialsRepository.save(credentials.getName(), credentials);
Expand Down

0 comments on commit 89f896c

Please sign in to comment.