Skip to content

Commit

Permalink
Fix UserStepDefs cocumber test
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 21, 2022
1 parent 402a7cb commit 86f21b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
-%>
package <%= packageName %>.cucumber.stepdefs;

<%_ if (reactive) { _%>
import org.springframework.test.web.reactive.server.WebTestClient;
<%_ } else { _%>
import org.springframework.test.web.servlet.ResultActions;
<%_ } _%>

public abstract class StepDefs {

<%_ if (reactive) { _%>
protected WebTestClient.ResponseSpec actions;
<%_ } else { _%>
protected ResultActions actions;
<%_ } _%>

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,42 @@ public class UserStepDefs extends StepDefs {
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(authentication);
SecurityContextHolder.setContext(context);
<%_ if (reactive) { _%>
this.userResourceMock = WebTestClient.bindToController(userResource).build();
<%_ } else { _%>
this.userResourceMock = MockMvcBuilders.standaloneSetup(userResource).build();
<%_ } _%>
}

@When("I search user {string}")
public void i_search_user(String userId) throws Throwable {
<%_ if (reactive) { _%>
actions = userResourceMock.get().uri("/api/admin/users/" + userId)
actions = userResourceMock.get().uri("/api/admin/users/" + userId).accept(MediaType.APPLICATION_JSON).exchange();
<%_ } else { _%>
actions = userResourceMock.perform(get("/api/admin/users/" + userId)
actions = userResourceMock.perform(get("/api/admin/users/" + userId).accept(MediaType.APPLICATION_JSON));
<%_ } _%>
.accept(MediaType.APPLICATION_JSON)<% if (!reactive) { %>)<%_ } _%>;
}

@Then("the user is found")
public void the_user_is_found() throws Throwable {
<%_ if (reactive) { _%>
actions
.expectStatus().isOk()
.expectHeader().contentTypeCompatibleWith(MediaType.APPLICATION_JSON_VALUE);
<%_ } else { _%>
actions
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
<%_ } _%>
}

@Then("his last name is {string}")
public void his_last_name_is(String lastName) throws Throwable {
<%_ if (reactive) { _%>
actions.expectBody().jsonPath("$.lastName").value(lastName);
<%_ } else { _%>
actions.andExpect(jsonPath("$.lastName").value(lastName));
<%_ } _%>
}

}

0 comments on commit 86f21b4

Please sign in to comment.