Skip to content

Commit

Permalink
Increase test code coverage. (#377)
Browse files Browse the repository at this point in the history
* Increase test code coverage.

* Increase test code coverage, pt.2.

* avoid running functional tests twice in nightly build

* Add missing assertions in a test.

Co-authored-by: Shravan Mechineni <shravan.mechineni@ladbrokescoral.com>
  • Loading branch information
Radoslaw Orlowski and Shravan Mechineni authored Jun 9, 2020
1 parent e44e3bc commit 792d59d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
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

0 comments on commit 792d59d

Please sign in to comment.