Skip to content

Commit

Permalink
MODUSERBL-180 Resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
pavankumar181 committed Oct 6, 2023
1 parent fcd90a5 commit 93b4aa5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

public class TokenNotFoundException extends RuntimeException {

public TokenNotFoundException() {
super();
}

public TokenNotFoundException(String message) {
super(message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/folio/rest/util/ExceptionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Response handleException(Throwable throwable) {
.type(MediaType.TEXT_PLAIN)
.entity(throwable.getMessage())
.build();
} else if(throwable.getClass() == TokenNotFoundException.class){
} else if (throwable.getClass() == TokenNotFoundException.class){
return Response.status(HttpStatus.SC_NOT_FOUND)
.type(MediaType.TEXT_PLAIN)
.entity(throwable.getMessage())
Expand Down
41 changes: 41 additions & 0 deletions src/test/java/org/folio/rest/GeneratePasswordRestLinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,37 @@ public void cannotGeneratePasswordWhenTokenSignLegacyEndPointReturns500(

}

public void shouldNotGenerateAndSendPasswordWhenLegacyTokenEndpointReturns404(
String expirationTime, String expirationTimeOfUnit, String expectedExpirationTime,
String expectedExpirationTimeOfUnit) {
Map<String, String> configToMock = new HashMap<>();
configToMock.put(FOLIO_HOST_CONFIG_KEY, MOCK_FOLIO_UI_HOST);
configToMock.put(RESET_PASSWORD_LINK_EXPIRATION_TIME, expirationTime);
configToMock.put(RESET_PASSWORD_LINK_EXPIRATION_UNIT_OF_TIME, expirationTimeOfUnit);
User mockUser = new User()
.withId(UUID.randomUUID().toString())
.withUsername(MOCK_USERNAME);
boolean passwordExists = true;

mockUserFound(mockUser.getId(), mockUser);
mockConfigModule(MODULE_NAME, configToMock);
mockSignAuthTokenNotFound();
mockSignAuthTokenLegacyNotFound();
mockPostPasswordResetAction(passwordExists);
mockNotificationModule();

JsonObject requestBody = new JsonObject()
.put("userId", mockUser.getId());
RestAssured.given()
.spec(spec)
.header(mockUrlHeader)
.body(requestBody.encode())
.when()
.post(GENERATE_PASSWORD_RESET_LINK_PATH)
.then()
.statusCode(HttpStatus.SC_NOT_FOUND);

}
@Test
public void shouldGenerateAndSendCreatePasswordNotificationWhenPasswordExists() {
Map<String, String> configToMock = new HashMap<>();
Expand Down Expand Up @@ -526,6 +557,11 @@ public void cannotGeneratePasswordWhenTokenSignLegacyEndPointReturns500() {
EXPIRATION_UNIT_OF_TIME_MINUTES, EXPIRATION_TIME_MINUTES, EXPIRATION_UNIT_OF_TIME_MINUTES);
}

@Test
public void shouldNotGenerateAndSendPasswordWhenLegacyTokenEndpointReturns404() {
shouldNotGenerateAndSendPasswordWhenLegacyTokenEndpointReturns404(EXPIRATION_TIME_DAYS,
EXPIRATION_UNIT_OF_TIME_DAYS, EXPIRATION_TIME_DAYS, EXPIRATION_UNIT_OF_TIME_DAYS);
}
private String toJson(Object object) {
return JsonObject.mapFrom(object).toString();
}
Expand Down Expand Up @@ -583,6 +619,11 @@ private void mockSignAuthTokenLegacyServerError() {
.willReturn(WireMock.serverError()));
}

private void mockSignAuthTokenLegacyNotFound() {
WireMock.stubFor(WireMock.post("/token")
.willReturn(WireMock.notFound()));
}

private void mockNotificationModule() {
WireMock.stubFor(WireMock.post(NOTIFY_PATH)
.willReturn(WireMock.created()));
Expand Down

0 comments on commit 93b4aa5

Please sign in to comment.