Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): refactor a test to consume retrofit2 interfaced FiatService #6313

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clouddriver-docker/clouddriver-docker.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
implementation "io.spinnaker.kork:kork-retrofit"
implementation "io.spinnaker.kork:kork-exceptions"

testImplementation "com.squareup.retrofit2:retrofit-mock"
testImplementation "cglib:cglib-nodep"
testImplementation "org.objenesis:objenesis"
testImplementation "org.assertj:assertj-core"
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
Loading