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

Increase test code coverage. #377

Merged
5 commits merged into from
Jun 9, 2020
Merged
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
17 changes: 0 additions & 17 deletions Jenkinsfile_nightly
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,6 @@ withNightlyPipeline(type, product, component) {

after('fullFunctionalTest') {

sh "./gradlew smoke"

archiveArtifacts '**/build/test-results/**/*'

publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "output",
reportFiles : "idam-web-public-e2e-result.html",
reportName : "IDAM Web Public E2E smoke tests result"
]

sh "./gradlew functional"

archiveArtifacts '**/build/test-results/**/*'

publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/uk/gov/hmcts/reform/idam/web/helper/JSPHelper.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package uk.gov.hmcts.reform.idam.web.helper;

import lombok.NonNull;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.net.URLCodec;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.context.request.RequestContextHolder;
Expand All @@ -14,15 +15,14 @@

import javax.annotation.Nonnull;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Locale;
import java.util.Optional;

@UtilityClass
public class JSPHelper {

private static final UrlPathHelper PATH_HELPER = new UrlPathHelper();
private static final URLCodec URL_CODEC = new URLCodec();
private static MessageSource messageSource;

/**
Expand All @@ -31,16 +31,17 @@ public class JSPHelper {
* @should throw if there is no request in context
*/
@Nonnull
@SneakyThrows(UnsupportedEncodingException.class)
public String getOtherLocaleUrl() {
public String getOtherLocaleUrl() throws DecoderException {
final ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
final HttpServletRequest request = servletRequestAttributes != null ? servletRequestAttributes.getRequest() : null;
final String targetLocale = getTargetLocale();


if (request != null) {
final String requestUri = PATH_HELPER.getOriginatingRequestUri(request);
final String originatingQueryString = PATH_HELPER.getOriginatingQueryString(request);
final String requestQueryString = originatingQueryString == null ? null : URLDecoder.decode(originatingQueryString, "UTF-8"); //NOSONAR
final String requestQueryString; //NOSONAR
requestQueryString = originatingQueryString == null ? null : URL_CODEC.decode(originatingQueryString);
final UriComponentsBuilder initialUrl = UriComponentsBuilder.fromPath(requestUri).replaceQuery(requestQueryString);

return overrideLocaleParameter(initialUrl, targetLocale);
Expand All @@ -54,9 +55,9 @@ public String getOtherLocaleUrl() {
*
* @should override existing parameter
* @should add nonexisting parameter
* @should throw on any of the parameters being null
*/
public static String overrideLocaleParameter(@NonNull final UriComponentsBuilder builder, @NonNull final String targetLocale) {

return builder.replaceQueryParam(MessagesConfiguration.UI_LOCALES_PARAM_NAME, new Locale(targetLocale)).toUriString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ public void overrideLocaleParameter_shouldAddNonexistingParameter() {
Assert.assertEquals(CORRECT_BASE_TEST_URI + targetLocale, rewrittenUrl);
}

/**
* @verifies throw on any of the parameters being null
* @see JSPHelper#overrideLocaleParameter(org.springframework.web.util.UriComponentsBuilder, String)
*/
@Test
public void overrideLocaleParameter_shouldThrowOnAnyOfTheParametersBeingNull() {
try {
JSPHelper.overrideLocaleParameter(UriComponentsBuilder.newInstance(), null);
Assert.fail();
} catch (NullPointerException e) {
// do nothing, expected
}

try {
JSPHelper.overrideLocaleParameter(null, "en");
Assert.fail();
} catch (NullPointerException e) {
// do nothing, expected
}
}

/**
* @verifies return en if current locale is welsh
* @see JSPHelper#getTargetLocale()
Expand Down