diff --git a/SDK/build.xml b/SDK/build.xml index baaac4b..025fe0b 100644 --- a/SDK/build.xml +++ b/SDK/build.xml @@ -51,7 +51,8 @@ -init-macrodef-junit: defines macro for junit execution -init-macrodef-debug: defines macro for class debugging -init-macrodef-java: defines macro for class execution - -do-jar: JAR building + -do-jar-with-manifest: JAR building (if you are using a manifest) + -do-jar-without-manifest: JAR building (if you are not using a manifest) run: execution of project -javadoc-build: Javadoc generation test-report: JUnit report generation diff --git a/SDK/libs/hamcrest-core-1.3.jar b/SDK/libs/hamcrest-core-1.3.jar new file mode 100644 index 0000000..9d5fe16 Binary files /dev/null and b/SDK/libs/hamcrest-core-1.3.jar differ diff --git a/SDK/libs/javax.servlet-api.jar b/SDK/libs/javax.servlet-api.jar new file mode 100644 index 0000000..8161e88 Binary files /dev/null and b/SDK/libs/javax.servlet-api.jar differ diff --git a/SDK/libs/servlet-api.jar b/SDK/libs/servlet-api.jar deleted file mode 100644 index 9ed1b94..0000000 Binary files a/SDK/libs/servlet-api.jar and /dev/null differ diff --git a/SDK/nbproject/build-impl.xml b/SDK/nbproject/build-impl.xml index eeb4748..a14899c 100644 --- a/SDK/nbproject/build-impl.xml +++ b/SDK/nbproject/build-impl.xml @@ -12,18 +12,18 @@ is divided into following sections: - execution - debugging - javadoc - - test compilation - - test execution - - test debugging + - junit compilation + - junit execution + - junit debugging - applet - cleanup --> - + - + @@ -46,15 +46,14 @@ is divided into following sections: - - + + - @@ -72,20 +71,16 @@ is divided into following sections: - + - - - + + - - - - - - + + + @@ -96,6 +91,12 @@ is divided into following sections: + + + + + + @@ -114,12 +115,24 @@ is divided into following sections: - + - + + + + + + + + + + + + + @@ -143,7 +156,6 @@ is divided into following sections: - @@ -156,7 +168,6 @@ is divided into following sections: - @@ -174,15 +185,7 @@ is divided into following sections: - - - - - - - - - + @@ -192,38 +195,10 @@ is divided into following sections: - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - @@ -277,7 +252,6 @@ is divided into following sections: - @@ -317,7 +291,6 @@ is divided into following sections: - @@ -358,57 +331,11 @@ is divided into following sections: - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - @@ -416,277 +343,33 @@ is divided into following sections: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No tests executed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - + @@ -700,8 +383,7 @@ is divided into following sections: - - + @@ -718,13 +400,10 @@ is divided into following sections: - + Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - @@ -775,14 +454,13 @@ is divided into following sections: - + - @@ -799,15 +477,13 @@ is divided into following sections: - - + - @@ -834,15 +510,12 @@ is divided into following sections: - - - - - + + @@ -853,8 +526,8 @@ is divided into following sections: - - + + @@ -882,7 +555,7 @@ is divided into following sections: - + - + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + - + - + - - + + - - - - - - + - + - + To run this application from the command line without Ant, try: java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - + - - + - - + - - - This target only works when run from inside the NetBeans IDE. + @@ -1112,9 +779,8 @@ is divided into following sections: - + Must select one file in the IDE or set profile.class - This target only works when run from inside the NetBeans IDE. @@ -1122,8 +788,12 @@ is divided into following sections: - - This target only works when run from inside the NetBeans IDE. + + @@ -1135,8 +805,12 @@ is divided into following sections: - - This target only works when run from inside the NetBeans IDE. + + @@ -1158,42 +832,6 @@ is divided into following sections: - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - - - Must select some files in the IDE or set test.includes - - - - - Must select one file in the IDE or set run.class - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - + - + - @@ -1240,7 +866,7 @@ is divided into following sections: @@ -1283,14 +909,14 @@ is divided into following sections: - + Some tests failed; see details above. @@ -1303,40 +929,39 @@ is divided into following sections: Must select some files in the IDE or set test.includes - + Some tests failed; see details above. - - Must select some files in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - Some tests failed; see details above. - - - + Must select one file in the IDE or set test.class - - - - Must select one file in the IDE or set test.class - Must select some method in the IDE or set test.method - + + + + + + + + + + + + + + + - @@ -1401,12 +1026,9 @@ is divided into following sections: - - - - - - + + + diff --git a/SDK/nbproject/genfiles.properties b/SDK/nbproject/genfiles.properties index 952020f..efac672 100644 --- a/SDK/nbproject/genfiles.properties +++ b/SDK/nbproject/genfiles.properties @@ -1,8 +1,8 @@ build.xml.data.CRC32=4f4bbae4 -build.xml.script.CRC32=cd16bf81 -build.xml.stylesheet.CRC32=8064a381@1.80.1.48 +build.xml.script.CRC32=edafd639 +build.xml.stylesheet.CRC32=28e38971@1.44.1.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=4f4bbae4 -nbproject/build-impl.xml.script.CRC32=573072ea -nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 +nbproject/build-impl.xml.script.CRC32=6eb04d1d +nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45 diff --git a/SDK/nbproject/project.properties b/SDK/nbproject/project.properties index e813f1a..f7f5cf8 100644 --- a/SDK/nbproject/project.properties +++ b/SDK/nbproject/project.properties @@ -1,9 +1,9 @@ annotation.processing.enabled=true annotation.processing.enabled.in.editor=false -annotation.processing.processor.options= -annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=SDK +application.vendor=queueit build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: @@ -20,26 +20,24 @@ debug.classpath=\ ${run.classpath} debug.test.classpath=\ ${run.test.classpath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/SDK.jar dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= excludes= -file.reference.servlet-api.jar=libs\\servlet-api.jar +file.reference.javax.servlet-api.jar=libs/javax.servlet-api.jar includes=** jar.compress=false javac.classpath=\ - ${file.reference.servlet-api.jar} + ${file.reference.javax.servlet-api.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false -javac.external.vm=true javac.processorpath=\ ${javac.classpath} -javac.source=1.8 -javac.target=1.8 +javac.source=1.6 +javac.target=1.6 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir}:\ @@ -64,9 +62,9 @@ platform.active=default_platform run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): run.jvmargs= run.test.classpath=\ ${javac.test.classpath}:\ diff --git a/SDK/src/queueit/knownuserv3/sdk/KnownUser.java b/SDK/src/queueit/knownuserv3/sdk/KnownUser.java index e82d1df..3ced801 100644 --- a/SDK/src/queueit/knownuserv3/sdk/KnownUser.java +++ b/SDK/src/queueit/knownuserv3/sdk/KnownUser.java @@ -3,9 +3,12 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; -import java.time.Instant; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.TimeZone; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -38,7 +41,7 @@ public static RequestValidationResult validateRequestByIntegrationConfig(String String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey) throws Exception { - Map debugEntries = new HashMap<>(); + Map debugEntries = new HashMap(); try { boolean isDebug = getIsDebug(queueitToken, secretKey); @@ -92,7 +95,7 @@ public static RequestValidationResult cancelRequestByLocalConfig( String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey) throws Exception { - Map debugEntries = new HashMap<>(); + Map debugEntries = new HashMap(); try { targetUrl = generateTargetUrl(targetUrl, request); @@ -148,7 +151,7 @@ public static RequestValidationResult resolveQueueRequestByLocalConfig( String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey) throws Exception { - Map debugEntries = new HashMap<>(); + Map debugEntries = new HashMap(); try { targetUrl = generateTargetUrl(targetUrl, request); @@ -240,7 +243,12 @@ private static void setDebugCookie(Map debugEntries, HttpServlet } private static void logMoreRequestDetails(Map debugEntries, HttpServletRequest request) { - debugEntries.put("ServerUtcTime", Instant.now().toString()); + TimeZone tz = TimeZone.getTimeZone("UTC"); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Quoted "Z" to indicate UTC, no timezone offset + df.setTimeZone(tz); + String nowAsISO = df.format(new Date()); + + debugEntries.put("ServerUtcTime", nowAsISO); debugEntries.put("RequestIP", request.getRemoteAddr()); debugEntries.put("RequestHttpHeader_Via", request.getHeader("via") != null ? request.getHeader("via") : ""); debugEntries.put("RequestHttpHeader_Forwarded", request.getHeader("forwarded") != null ? request.getHeader("forwarded") : ""); @@ -260,23 +268,20 @@ private static boolean getIsDebug(String queueitToken, String secretKey) throws private static String getOriginalUrl(HttpServletRequest request) { return (request.getQueryString() != null) - ? String.join("", request.getRequestURL(), "?", request.getQueryString()) + ? request.getRequestURL().toString() + "?" + request.getQueryString() : request.getRequestURL().toString(); } private static RequestValidationResult handleQueueAction(IntegrationConfigModel matchedConfig, String currentUrlWithoutQueueITToken, CustomerIntegration customerIntegrationInfo, String queueitToken, String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey, Map debugEntries) throws Exception { String targetUrl; - switch (matchedConfig.RedirectLogic) { - case "ForecedTargetUrl": // suuport for typo (fall through) - case "ForcedTargetUrl": - targetUrl = matchedConfig.ForcedTargetUrl; - break; - case "EventTargetUrl": - targetUrl = ""; - break; - default: - targetUrl = generateTargetUrl(currentUrlWithoutQueueITToken, request); - break; + + if ("ForecedTargetUrl".equals(matchedConfig.RedirectLogic) || // support for typo + "ForcedTargetUrl".equals(matchedConfig.RedirectLogic)) { + targetUrl = matchedConfig.ForcedTargetUrl; + } else if ("EventTargetUrl".equals(matchedConfig.RedirectLogic)) { + targetUrl = ""; + } else { + targetUrl = generateTargetUrl(currentUrlWithoutQueueITToken, request); } QueueEventConfig queueConfig = new QueueEventConfig(); @@ -315,8 +320,8 @@ private static String generateTargetUrl(String originalTargetUrl, HttpServletReq return !isQueueAjaxCall(request) ? originalTargetUrl : URLDecoder.decode(request.getHeader(QueueITAjaxHeaderKey), "UTF-8"); - } catch (UnsupportedEncodingException e) { - } + } catch (UnsupportedEncodingException e) { + } return ""; } diff --git a/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java b/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java index 4150d4c..6cd17ab 100644 --- a/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java +++ b/SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java @@ -1,5 +1,7 @@ package queueit.knownuserv3.sdk; +import java.util.AbstractCollection; +import java.util.Iterator; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; @@ -26,6 +28,18 @@ public static boolean isLong(String value) { return false; } } + + public static String join(String delimiter, AbstractCollection s) { + if (s == null || s.isEmpty()) { + return ""; + } + Iterator iter = s.iterator(); + StringBuilder builder = new StringBuilder(iter.next()); + while (iter.hasNext()) { + builder.append(delimiter).append(iter.next()); + } + return builder.toString(); + } } class QueueParameterHelper { @@ -53,38 +67,28 @@ public static QueueUrlParams extractQueueParams(String queueitToken) { for (String paramKeyValue : paramList) { String[] keyValueArr = paramKeyValue.split(KeyValueSeparatorChar); - switch (keyValueArr[0]) { - case TimeStampKey: - if (Utils.isLong(keyValueArr[1])) { - result.setTimeStamp(Long.parseLong(keyValueArr[1])); - } else { - result.setTimeStamp(0); - } - break; - case CookieValidityMinutesKey: { - if (Utils.isInteger(keyValueArr[1])) { - result.setCookieValidityMinutes(Integer.parseInt(keyValueArr[1])); - } else { - result.setCookieValidityMinutes(null); - } - break; + if (TimeStampKey.equals(keyValueArr[0])) { + if (Utils.isLong(keyValueArr[1])) { + result.setTimeStamp(Long.parseLong(keyValueArr[1])); + } else { + result.setTimeStamp(0); } - - case EventIdKey: - result.setEventId(keyValueArr[1]); - break; - case QueueIdKey: - result.setQueueId(keyValueArr[1]); - break; - case ExtendableCookieKey: - result.setExtendableCookie(Boolean.parseBoolean(keyValueArr[1])); - break; - case HashKey: - result.setHashCode(keyValueArr[1]); - break; - case RedirectTypeKey: - result.setRedirectType(keyValueArr[1]); - break; + } else if (CookieValidityMinutesKey.equals(keyValueArr[0])) { + if (Utils.isInteger(keyValueArr[1])) { + result.setCookieValidityMinutes(Integer.parseInt(keyValueArr[1])); + } else { + result.setCookieValidityMinutes(null); + } + } else if (EventIdKey.equals(keyValueArr[0])) { + result.setEventId(keyValueArr[1]); + } else if (QueueIdKey.equals(keyValueArr[0])) { + result.setQueueId(keyValueArr[1]); + } else if (ExtendableCookieKey.equals(keyValueArr[0])) { + result.setExtendableCookie(Boolean.parseBoolean(keyValueArr[1])); + } else if (HashKey.equals(keyValueArr[0])) { + result.setHashCode(keyValueArr[1]); + } else if (RedirectTypeKey.equals(keyValueArr[0])) { + result.setRedirectType(keyValueArr[1]); } } String queueITTokenWithoutHash = result.getQueueITToken().replace(KeyValueSeparatorGroupChar + HashKey + KeyValueSeparatorChar + result.getHashCode(), ""); diff --git a/SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java b/SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java index 843a6ee..4fdba52 100644 --- a/SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java +++ b/SDK/src/queueit/knownuserv3/sdk/RequestValidationResult.java @@ -53,7 +53,7 @@ public String getAjaxRedirectUrl() { if (!Utils.isNullOrWhiteSpace(redirectUrl)) { return URLEncoder.encode(redirectUrl, "UTF-8"); } - } catch (UnsupportedEncodingException e) { + } catch (UnsupportedEncodingException e) { } return ""; } diff --git a/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java b/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java index 374c640..8609bfc 100644 --- a/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java +++ b/SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java @@ -2,7 +2,6 @@ import java.net.URLEncoder; import java.util.ArrayList; -import java.util.Objects; interface IUserInQueueService { @@ -23,15 +22,14 @@ void extendQueueCookie( String eventId, int cookieValidityMinutes, String cookieDomain, - String secretKey - ); + String secretKey); RequestValidationResult getIgnoreActionResult(); } class UserInQueueService implements IUserInQueueService { - public static final String SDK_VERSION = "3.5.1"; + public static final String SDK_VERSION = "3.5.2"; private final IUserInQueueStateRepository _userInQueueStateRepository; public UserInQueueService(IUserInQueueStateRepository queueStateRepository) { @@ -44,8 +42,7 @@ public RequestValidationResult validateQueueRequest( String queueitToken, QueueEventConfig config, String customerId, - String secretKey - ) throws Exception { + String secretKey) throws Exception { StateInfo stateInfo = this._userInQueueStateRepository.getState(config.getEventId(), config.getCookieValidityMinute(), secretKey, true); if (stateInfo.isValid()) { if (stateInfo.isStateExtendable() && config.getExtendCookieValidity()) { @@ -77,11 +74,11 @@ private RequestValidationResult getQueueITTokenValidationResult( String customerId, String secretKey) throws Exception { String calculatedHash = HashHelper.generateSHA256Hash(secretKey, queueParams.getQueueITTokenWithoutHash()); - if (!Objects.equals(calculatedHash.toUpperCase(), queueParams.getHashCode().toUpperCase())) { + if (!calculatedHash.toUpperCase().equals(queueParams.getHashCode().toUpperCase())) { return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "hash"); } - if (!Objects.equals(queueParams.getEventId().toUpperCase(), eventId.toUpperCase())) { + if (!eventId.toUpperCase().equals(queueParams.getEventId().toUpperCase())) { return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "eventid"); } @@ -141,7 +138,7 @@ private String getQueryString( int configVersion, String culture, String layoutName) throws Exception { - ArrayList queryStringList = new ArrayList<>(); + ArrayList queryStringList = new ArrayList(); queryStringList.add("c=" + URLEncoder.encode(customerId, "UTF-8")); queryStringList.add("e=" + URLEncoder.encode(eventId, "UTF-8")); queryStringList.add("ver=v3-java-" + URLEncoder.encode(SDK_VERSION, "UTF-8")); @@ -155,7 +152,7 @@ private String getQueryString( queryStringList.add("l=" + URLEncoder.encode(layoutName, "UTF-8")); } - return String.join("&", queryStringList); + return Utils.join("&", queryStringList); } @Override diff --git a/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java b/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java index f186897..759b513 100644 --- a/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java +++ b/SDK/src/queueit/knownuserv3/sdk/UserInQueueStateCookieRepository.java @@ -1,7 +1,6 @@ package queueit.knownuserv3.sdk; import java.util.HashMap; -import java.util.Objects; interface IUserInQueueStateRepository { @@ -20,15 +19,13 @@ StateInfo getState(String eventId, void cancelQueueCookie( String eventId, - String cookieDomain - ); + String cookieDomain); void reissueQueueCookie( String eventId, int cookieValidityMinutes, String cookieDomain, - String secretKey - ); + String secretKey); } class UserInQueueStateCookieRepository implements IUserInQueueStateRepository { @@ -40,7 +37,6 @@ class UserInQueueStateCookieRepository implements IUserInQueueStateRepository { private static final String REDIRECT_TYPE_KEY = "RedirectType"; private static final String EVENT_ID_KEY = "EventId"; private static final String FIXED_COOKIE_VALIDITY_MINUTES_KEY = "FixedValidityMins"; - private final ICookieManager cookieManager; public static String getCookieKey(String eventId) { @@ -117,7 +113,7 @@ private Boolean isCookieValid( + cookieNameValueMap.get(REDIRECT_TYPE_KEY) + cookieNameValueMap.get(ISSUETIME_KEY)); - if (!Objects.equals(hashValue, cookieNameValueMap.get(HASH_KEY))) { + if (!hashValue.equals(cookieNameValueMap.get(HASH_KEY))) { return false; } if (!eventId.toLowerCase().equals(cookieNameValueMap.get(EVENT_ID_KEY).toLowerCase())) { @@ -143,7 +139,7 @@ private Boolean isCookieValid( } public static HashMap getCookieNameValueMap(String cookieValue) { - HashMap result = new HashMap<>(); + HashMap result = new HashMap(); String[] cookieNameValues = cookieValue.split("&"); for (int i = 0; i < cookieNameValues.length; ++i) { @@ -172,7 +168,6 @@ public StateInfo getState(String eventId, int cookieValidityMinutes, String secr cookieNameValueMap.get(FIXED_COOKIE_VALIDITY_MINUTES_KEY), cookieNameValueMap.get(REDIRECT_TYPE_KEY)); } catch (NumberFormatException ex) { - } return new StateInfo(false, null, null, null); } @@ -190,8 +185,7 @@ public void reissueQueueCookie( String eventId, int cookieValidityMinutes, String cookieDomain, - String secretKey - ) { + String secretKey) { try { String cookieKey = getCookieKey(eventId); String cookieValueOld = this.cookieManager.getCookie(cookieKey); @@ -226,8 +220,7 @@ class StateInfo { private final String fixedCookieValidityMinutes; public StateInfo(boolean isValid, String queueid, String fixedCookieValidityMinutes, - String redirectType - ) { + String redirectType) { this.isValid = isValid; this.queueId = queueid; this.fixedCookieValidityMinutes = fixedCookieValidityMinutes; @@ -249,5 +242,4 @@ public String getRedirectType() { public boolean isStateExtendable() { return this.isValid && Utils.isNullOrWhiteSpace(this.fixedCookieValidityMinutes); } - } diff --git a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java b/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java index 5246cab..93c0509 100644 --- a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java +++ b/SDK/src/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluator.java @@ -1,7 +1,8 @@ package queueit.knownuserv3.sdk.integrationconfig; +import java.net.MalformedURLException; +import java.net.URL; import javax.servlet.http.Cookie; -import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; @@ -20,10 +21,11 @@ public IntegrationConfigModel getMatchedIntegrationConfig( CustomerIntegration customerIntegration, String currentPageUrl, HttpServletRequest request) throws Exception { - - if(request == null) - throw new Exception("request is null"); - + + if (request == null) { + throw new Exception("request is null"); + } + for (IntegrationConfigModel integration : customerIntegration.Integrations) { for (TriggerModel trigger : integration.Triggers) { if (evaluateTrigger(trigger, currentPageUrl, request)) { @@ -56,17 +58,16 @@ private boolean evaluateTrigger( } private boolean evaluateTriggerPart(TriggerPart triggerPart, String currentPageUrl, HttpServletRequest request) { - switch (triggerPart.ValidatorType) { - case ValidatorType.URL_VALIDATOR: - return UrlValidatorHelper.evaluate(triggerPart, currentPageUrl); - case ValidatorType.COOKIE_VALIDATOR: - return CookieValidatorHelper.evaluate(triggerPart, request.getCookies()); - case ValidatorType.USERAGENT_VALIDATOR: - return UserAgentValidatorHelper.evaluate(triggerPart, request.getHeader("User-Agent")); - case ValidatorType.HTTPHEADER_VALIDATOR: - return HttpHeaderValidatorHelper.evaluate(triggerPart, request); - default: - return false; + if (ValidatorType.URL_VALIDATOR.equals(triggerPart.ValidatorType)) { + return UrlValidatorHelper.evaluate(triggerPart, currentPageUrl); + } else if (ValidatorType.COOKIE_VALIDATOR.equals(triggerPart.ValidatorType)) { + return CookieValidatorHelper.evaluate(triggerPart, request.getCookies()); + } else if (ValidatorType.USERAGENT_VALIDATOR.equals(triggerPart.ValidatorType)) { + return UserAgentValidatorHelper.evaluate(triggerPart, request.getHeader("User-Agent")); + } else if (ValidatorType.HTTPHEADER_VALIDATOR.equals(triggerPart.ValidatorType)) { + return HttpHeaderValidatorHelper.evaluate(triggerPart, request); + } else { + return false; } } } @@ -84,38 +85,23 @@ public static boolean evaluate(TriggerPart triggerPart, String url) { } private static String getUrlPart(TriggerPart triggerPart, String url) { - switch (triggerPart.UrlPart) { - case UrlPartType.PAGE_PATH: - return getPathFromUrl(url); - case UrlPartType.PAGE_URL: - return url; - case UrlPartType.HOST_NAME: - return getHostNameFromUrl(url); - default: - return ""; + if (UrlPartType.PAGE_URL.equals(triggerPart.UrlPart)) { + return url; } - } - private static String getHostNameFromUrl(String url) { - return getMatchFromUrl(url, - "^(([^:/\\?#]+):)?(//(?[^/\\?#]*))?([^\\?#]*)(\\?([^#]*))?(#(.*))?", - "hostname"); - } - - private static String getPathFromUrl(String url) { - return getMatchFromUrl(url, - "^(([^:/\\?#]+):)?(//([^/\\?#]*))?(?[^\\?#]*)(\\?([^#]*))?(#(.*))?", - "path"); - } + try { + URL oUrl = new URL(url); - private static String getMatchFromUrl(String url, String urlMatcher, String matchName) { - Pattern pattern = Pattern.compile(urlMatcher); - Matcher matcher = pattern.matcher(url); - if (!matcher.matches()) { + if (UrlPartType.PAGE_PATH.equals(triggerPart.UrlPart)) { + return oUrl.getPath(); + } else if (UrlPartType.HOST_NAME.equals(triggerPart.UrlPart)) { + return oUrl.getHost(); + } else { + return ""; + } + } catch (MalformedURLException ex) { return ""; } - - return matcher.group(matchName); } } @@ -131,9 +117,10 @@ public static boolean evaluate(TriggerPart triggerPart, Cookie[] cookieCollectio } private static String getCookie(String cookieName, Cookie[] cookieCollection) { - if(cookieCollection == null) + if (cookieCollection == null) { return ""; - + } + for (Cookie cookie : cookieCollection) { if (cookie.getName().equals(cookieName)) { return cookie.getValue(); @@ -156,49 +143,47 @@ public static boolean evaluate(TriggerPart triggerPart, String userAgent) { } final class HttpHeaderValidatorHelper { - - public static boolean evaluate(TriggerPart triggerPart, HttpServletRequest request) - { + + public static boolean evaluate(TriggerPart triggerPart, HttpServletRequest request) { return ComparisonOperatorHelper.evaluate(triggerPart.Operator, - triggerPart.IsNegative, - triggerPart.IsIgnoreCase, - request.getHeader(triggerPart.HttpHeaderName), - triggerPart.ValueToCompare, - triggerPart.ValuesToCompare); + triggerPart.IsNegative, + triggerPart.IsIgnoreCase, + request.getHeader(triggerPart.HttpHeaderName), + triggerPart.ValueToCompare, + triggerPart.ValuesToCompare); } } final class ComparisonOperatorHelper { public static boolean evaluate( - String opt, - boolean isNegative, - boolean isIgnoreCase, - String value, - String valueToCompare, + String opt, + boolean isNegative, + boolean isIgnoreCase, + String value, + String valueToCompare, String[] valuesToCompare) { - + value = (value != null) ? value : ""; valueToCompare = (valueToCompare != null) ? valueToCompare : ""; valuesToCompare = (valuesToCompare != null) ? valuesToCompare : new String[0]; - - switch (opt) { - case ComparisonOperatorType.EQUALS: - return equals(value, valueToCompare, isNegative, isIgnoreCase); - case ComparisonOperatorType.CONTAINS: - return contains(value, valueToCompare, isNegative, isIgnoreCase); - case ComparisonOperatorType.STARTS_WITH: - return startsWith(value, valueToCompare, isNegative, isIgnoreCase); - case ComparisonOperatorType.ENDS_WITH: - return endsWith(value, valueToCompare, isNegative, isIgnoreCase); - case ComparisonOperatorType.MATCHES_WITH: - return matchesWith(value, valueToCompare, isNegative, isIgnoreCase); - case ComparisonOperatorType.EQUALS_ANY: - return equalsAny(value, valuesToCompare, isNegative, isIgnoreCase); - case ComparisonOperatorType.CONTAINS_ANY: - return containsAny(value, valuesToCompare, isNegative, isIgnoreCase); - default: - return false; + + if (ComparisonOperatorType.EQUALS.equals(opt)) { + return equals(value, valueToCompare, isNegative, isIgnoreCase); + } else if (ComparisonOperatorType.CONTAINS.equals(opt)) { + return contains(value, valueToCompare, isNegative, isIgnoreCase); + } else if (ComparisonOperatorType.STARTS_WITH.equals(opt)) { + return startsWith(value, valueToCompare, isNegative, isIgnoreCase); + } else if (ComparisonOperatorType.ENDS_WITH.equals(opt)) { + return endsWith(value, valueToCompare, isNegative, isIgnoreCase); + } else if (ComparisonOperatorType.MATCHES_WITH.equals(opt)) { + return matchesWith(value, valueToCompare, isNegative, isIgnoreCase); + } else if (ComparisonOperatorType.EQUALS_ANY.equals(opt)) { + return equalsAny(value, valuesToCompare, isNegative, isIgnoreCase); + } else if (ComparisonOperatorType.CONTAINS_ANY.equals(opt)) { + return containsAny(value, valuesToCompare, isNegative, isIgnoreCase); + } else { + return false; } } @@ -282,19 +267,21 @@ private static boolean matchesWith(String value, String valueToCompare, boolean return evaluation; } } - + private static boolean equalsAny(String value, String[] valuesToCompare, boolean isNegative, boolean isIgnoreCase) { for (String valueToCompare : valuesToCompare) { - if(equals(value, valueToCompare, false, isIgnoreCase)) + if (equals(value, valueToCompare, false, isIgnoreCase)) { return !isNegative; + } } return isNegative; } - + private static boolean containsAny(String value, String[] valuesToCompare, boolean isNegative, boolean isIgnoreCase) { for (String valueToCompare : valuesToCompare) { - if(contains(value, valueToCompare, false, isIgnoreCase)) + if (contains(value, valueToCompare, false, isIgnoreCase)) { return !isNegative; + } } return isNegative; } diff --git a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/TriggerPart.java b/SDK/src/queueit/knownuserv3/sdk/integrationconfig/TriggerPart.java index 2dfe5af..d5c13d5 100644 --- a/SDK/src/queueit/knownuserv3/sdk/integrationconfig/TriggerPart.java +++ b/SDK/src/queueit/knownuserv3/sdk/integrationconfig/TriggerPart.java @@ -12,6 +12,6 @@ public class TriggerPart { public String UrlPart; //CookieValidator public String CookieName; - //HttpHeaderValidator + //HttpHeaderValidator public String HttpHeaderName; } \ No newline at end of file diff --git a/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java b/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java index bb54156..afbd31e 100644 --- a/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/KnownUserTest.java @@ -25,7 +25,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpUpgradeHandler; import javax.servlet.http.Part; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -39,14 +38,14 @@ public class KnownUserTest { class UserInQueueServiceMock implements IUserInQueueService { - public ArrayList> validateQueueRequestCalls = new ArrayList<>(); - public ArrayList> validateCancelRequestCalls = new ArrayList<>(); - public ArrayList> extendQueueCookieCalls = new ArrayList<>(); - public ArrayList> getIgnoreActionResultCalls = new ArrayList<>(); + public ArrayList> validateQueueRequestCalls = new ArrayList(); + public ArrayList> validateCancelRequestCalls = new ArrayList(); + public ArrayList> extendQueueCookieCalls = new ArrayList(); + public ArrayList> getIgnoreActionResultCalls = new ArrayList(); @Override public RequestValidationResult validateQueueRequest(String targetUrl, String queueitToken, QueueEventConfig config, String customerId, String secretKey) throws Exception { - ArrayList args = new ArrayList<>(); + ArrayList args = new ArrayList(); args.add(targetUrl); args.add(queueitToken); args.add(config.getCookieDomain() + ":" @@ -71,7 +70,7 @@ public RequestValidationResult validateCancelRequest( String customerId, String secretKey) throws Exception { - ArrayList args = new ArrayList<>(); + ArrayList args = new ArrayList(); args.add(targetUrl); args.add(config.getCookieDomain() + ":" + config.getEventId() + ":" @@ -86,7 +85,7 @@ public RequestValidationResult validateCancelRequest( @Override public void extendQueueCookie(String eventId, int cookieValidityMinute, String cookieDomain, String secretKey) { - ArrayList args = new ArrayList<>(); + ArrayList args = new ArrayList(); args.add(eventId); args.add(Integer.toString(cookieValidityMinute)); args.add(cookieDomain); @@ -96,7 +95,7 @@ public void extendQueueCookie(String eventId, int cookieValidityMinute, String c @Override public RequestValidationResult getIgnoreActionResult() { - getIgnoreActionResultCalls.add(new ArrayList<>()); + getIgnoreActionResultCalls.add(new ArrayList()); return new RequestValidationResult("Ignore", "", "", "", ""); } } @@ -184,18 +183,18 @@ public void cancelRequestByLocalConfigDebugCookieLoggingTest() throws Exception assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey)); String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8"); assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl")); - assertTrue(decodedCookieValue.contains("|CancelConfig=EventId:eventid")); + assertTrue(decodedCookieValue.contains("CancelConfig=EventId:eventid")); assertTrue(decodedCookieValue.contains("&Version:1")); assertTrue(decodedCookieValue.contains("&QueueDomain:queuedomain")); assertTrue(decodedCookieValue.contains("&CookieDomain:cookiedomain")); - assertTrue(decodedCookieValue.contains("|QueueitToken=" + queueittoken)); - assertTrue(decodedCookieValue.contains("|TargetUrl=url")); - assertTrue(decodedCookieValue.contains("|RequestIP=80.35.35.34")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_Via=1.1 example.com")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_XForwardedProto=https")); + assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken)); + assertTrue(decodedCookieValue.contains("TargetUrl=url")); + assertTrue(decodedCookieValue.contains("RequestIP=80.35.35.34")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_Via=1.1 example.com")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedProto=https")); } @Test @@ -633,7 +632,7 @@ public void resolveQueueRequestByLocalConfigDebugCookieLoggingTest() throws Exce assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey)); String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8"); assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl")); - assertTrue(decodedCookieValue.contains("|QueueConfig=EventId:eventId")); + assertTrue(decodedCookieValue.contains("QueueConfig=EventId:eventId")); assertTrue(decodedCookieValue.contains("&Version:12")); assertTrue(decodedCookieValue.contains("&QueueDomain:queueDomain")); assertTrue(decodedCookieValue.contains("&CookieDomain:cookieDomain")); @@ -641,14 +640,14 @@ public void resolveQueueRequestByLocalConfigDebugCookieLoggingTest() throws Exce assertTrue(decodedCookieValue.contains("&CookieValidityMinute:10")); assertTrue(decodedCookieValue.contains("&LayoutName:layoutName")); assertTrue(decodedCookieValue.contains("&Culture:culture")); - assertTrue(decodedCookieValue.contains("|QueueitToken=" + queueittoken)); - assertTrue(decodedCookieValue.contains("|TargetUrl=targetUrl")); - assertTrue(decodedCookieValue.contains("|RequestIP=80.35.35.34")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_Via=1.1 example.com")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_XForwardedProto=https")); + assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken)); + assertTrue(decodedCookieValue.contains("TargetUrl=targetUrl")); + assertTrue(decodedCookieValue.contains("RequestIP=80.35.35.34")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_Via=1.1 example.com")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedProto=https")); } @Test @@ -867,9 +866,9 @@ public void validateRequestByIntegrationConfigDebugCookieLoggingTest() throws Ex assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey)); String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8"); assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl")); - assertTrue(decodedCookieValue.contains("|PureUrl=http://test.com?event1=true")); - assertTrue(decodedCookieValue.contains("|ConfigVersion=3")); - assertTrue(decodedCookieValue.contains("|QueueConfig=EventId:event1")); + assertTrue(decodedCookieValue.contains("PureUrl=http://test.com?event1=true")); + assertTrue(decodedCookieValue.contains("ConfigVersion=3")); + assertTrue(decodedCookieValue.contains("QueueConfig=EventId:event1")); assertTrue(decodedCookieValue.contains("&Version:3")); assertTrue(decodedCookieValue.contains("&QueueDomain:knownusertest.queue-it.net")); assertTrue(decodedCookieValue.contains("&CookieDomain:.test.com")); @@ -877,9 +876,9 @@ public void validateRequestByIntegrationConfigDebugCookieLoggingTest() throws Ex assertTrue(decodedCookieValue.contains("&CookieValidityMinute:20")); assertTrue(decodedCookieValue.contains("&LayoutName:Christmas Layout by Queue-it")); assertTrue(decodedCookieValue.contains("&Culture:da-DK")); - assertTrue(decodedCookieValue.contains("|QueueitToken=" + queueittoken)); - assertTrue(decodedCookieValue.contains("|TargetUrl=http://test.com?event1=true")); - assertTrue(decodedCookieValue.contains("|MatchedConfig=event1action")); + assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken)); + assertTrue(decodedCookieValue.contains("TargetUrl=http://test.com?event1=true")); + assertTrue(decodedCookieValue.contains("MatchedConfig=event1action")); } @Test @@ -932,15 +931,15 @@ public void validateRequestByIntegrationConfigNotMatchDebugCookieLoggingTest() t assertTrue(responseMock.addedCookies.get(0).getName().equals(KnownUser.QueueITDebugKey)); String decodedCookieValue = URLDecoder.decode(responseMock.addedCookies.get(0).getValue(), "UTF-8"); assertTrue(decodedCookieValue.contains("OriginalUrl=requestUrl")); - assertTrue(decodedCookieValue.contains("|PureUrl=http://test.com?event1=true")); + assertTrue(decodedCookieValue.contains("PureUrl=http://test.com?event1=true")); assertTrue(decodedCookieValue.contains("ConfigVersion=3")); - assertTrue(decodedCookieValue.contains("|QueueitToken=" + queueittoken)); - assertTrue(decodedCookieValue.contains("|RequestIP=80.35.35.34")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_Via=1.1 example.com")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080")); - assertTrue(decodedCookieValue.contains("|RequestHttpHeader_XForwardedProto=https")); + assertTrue(decodedCookieValue.contains("QueueitToken=" + queueittoken)); + assertTrue(decodedCookieValue.contains("RequestIP=80.35.35.34")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_Via=1.1 example.com")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080")); + assertTrue(decodedCookieValue.contains("RequestHttpHeader_XForwardedProto=https")); } @Test @@ -1366,11 +1365,6 @@ public HttpSession getSession() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - @Override - public String changeSessionId() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - @Override public boolean isRequestedSessionIdValid() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -1416,11 +1410,6 @@ public Part getPart(String string) throws IOException, ServletException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - @Override - public T upgrade(Class type) throws IOException, ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - @Override public Object getAttribute(String string) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -1446,11 +1435,6 @@ public int getContentLength() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - @Override - public long getContentLengthLong() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - @Override public String getContentType() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -1609,7 +1593,7 @@ public DispatcherType getDispatcherType() { class HttpServletResponseMock implements HttpServletResponse { - ArrayList addedCookies = new ArrayList<>(); + ArrayList addedCookies = new ArrayList(); @Override public void addCookie(Cookie cookie) { @@ -1746,11 +1730,6 @@ public void setContentLength(int i) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - @Override - public void setContentLengthLong(long l) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - @Override public void setContentType(String string) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -1803,11 +1782,11 @@ public static String generateToken( String eventId, String secretKey) throws Exception { - ArrayList paramList = new ArrayList<>(); + ArrayList paramList = new ArrayList(); paramList.add(QueueParameterHelper.EventIdKey + QueueParameterHelper.KeyValueSeparatorChar + eventId); paramList.add(QueueParameterHelper.RedirectTypeKey + QueueParameterHelper.KeyValueSeparatorChar + "debug"); - String tokenWithoutHash = String.join(QueueParameterHelper.KeyValueSeparatorGroupChar, paramList); + String tokenWithoutHash = Utils.join(QueueParameterHelper.KeyValueSeparatorGroupChar, paramList); String hash = HashHelper.generateSHA256Hash(secretKey, tokenWithoutHash); String token = tokenWithoutHash + QueueParameterHelper.KeyValueSeparatorGroupChar + QueueParameterHelper.HashKey + QueueParameterHelper.KeyValueSeparatorChar + hash; return token; diff --git a/SDK/test/queueit/knownuserv3/sdk/UrlParameterProviderTest.java b/SDK/test/queueit/knownuserv3/sdk/UrlParameterProviderTest.java index f5eec79..f27b4ee 100644 --- a/SDK/test/queueit/knownuserv3/sdk/UrlParameterProviderTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/UrlParameterProviderTest.java @@ -1,6 +1,5 @@ package queueit.knownuserv3.sdk; -import java.util.Objects; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -16,7 +15,7 @@ public void TryExtractQueueParams_Test() { assertTrue(queueParameter.getCookieValidityMinutes() == 10); assertTrue(queueParameter.getExtendableCookie() == false); assertTrue("218b734e-d5be-4b60-ad66-9b1b326266e2".equals(queueParameter.getHashCode())); - assertTrue(Objects.equals(queueParameter.getQueueITToken(), queueitToken)); + assertTrue(queueitToken.equals(queueParameter.getQueueITToken())); assertTrue("ts_1480593661~cv_10~ce_false~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895~c_customerid~e_eventid~rt_disabled".equals(queueParameter.getQueueITTokenWithoutHash())); } @@ -30,6 +29,6 @@ public void TryExtractQueueParams_NotValidFormat_Test() { assertTrue(queueParameter.getCookieValidityMinutes() == null); assertTrue(queueParameter.getExtendableCookie() == false); assertTrue("".equals(queueParameter.getHashCode())); - assertTrue(Objects.equals(queueParameter.getQueueITToken(), queueitToken)); + assertTrue(queueitToken.equals(queueParameter.getQueueITToken())); } } diff --git a/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java b/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java index 11e165c..1d1c6ac 100644 --- a/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/UserInQueueServiceTest.java @@ -24,7 +24,7 @@ public void validateQueueRequest_ValidState_ExtendableCookie_NoCookieExtensionFr config.setCookieValidityMinute(10); config.setExtendCookieValidity(false); - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); conditions.put("isStoreWasCalled", false); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { @@ -35,9 +35,9 @@ public void cancelQueueCookie(String eventId, String cookieDomain) { } @Override - public void store(String eventId, String queueId,Integer fixedCookieValidityMinutes, String cookieDomainString, - String redirectType, String customerSecretKey) throws Exception { - conditions.replace("isStoreWasCalled", true); + public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomainString, + String redirectType, String customerSecretKey) throws Exception { + conditions.put("isStoreWasCalled", true); } @Override @@ -69,12 +69,13 @@ public void validateQueueRequest_ValidState_ExtendableCookie_CookieExtensionFrom config.setCookieValidityMinute(10); config.setExtendCookieValidity(true); config.setCookieDomain(".testdomain.com"); - HashMap> callInfo = new HashMap<>(); - callInfo.put("firstCall", new HashMap<>()); + final HashMap> callInfo = new HashMap(); + callInfo.put("firstCall", new HashMap()); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - HashMap info = new HashMap<>(); + HashMap info = new HashMap(); info.put("eventId", eventId); info.put("fixedCookieValidityMinutes", fixedCookieValidityMinutes); info.put("redirectType", redirectType); @@ -122,14 +123,15 @@ public void validateQueueRequest_ValidState_NoExtendableCookie_DoNotRedirect_DoN config.setCookieValidityMinute(10); config.setExtendCookieValidity(true); - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); conditions.put("isStoreWasCalled", false); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - HashMap info = new HashMap<>(); - conditions.replace("isStoreWasCalled", true); + HashMap info = new HashMap(); + conditions.put("isStoreWasCalled", true); } @Override @@ -165,10 +167,11 @@ public void ValidateQueueRequest_NoCookie_TampredToken_RedirectToErrorPageWithHa config.setExtendCookieValidity(false); config.setVersion(100); - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); conditions.put("isStoreWasCalled", false); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void cancelQueueCookie(String eventId, String cookieDomain) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -176,7 +179,7 @@ public void cancelQueueCookie(String eventId, String cookieDomain) { @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - conditions.replace("isStoreWasCalled", true); + conditions.put("isStoreWasCalled", true); } @Override @@ -229,10 +232,11 @@ public void ValidateQueueRequest_NoCookie_ExpiredTimeStampInToken_RedirectToErro config.setVersion(100); String customerKey = "4e1db821-a825-49da-acd0-5d376f2068db"; - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); conditions.put("isStoreWasCalled", false); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void cancelQueueCookie(String eventId, String cookieDomain) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -240,7 +244,7 @@ public void cancelQueueCookie(String eventId, String cookieDomain) { @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - conditions.replace("isStoreWasCalled", true); + conditions.put("isStoreWasCalled", true); } @Override @@ -293,10 +297,11 @@ public void ValidateQueueRequest_NoCookie_EventIdMismatch_RedirectToErrorPageWit config.setVersion(10); String customerKey = "4e1db821-a825-49da-acd0-5d376f2068db"; - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); conditions.put("isStoreWasCalled", false); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void cancelQueueCookie(String eventId, String cookieDomain) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -304,7 +309,7 @@ public void cancelQueueCookie(String eventId, String cookieDomain) { @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - conditions.replace("isStoreWasCalled", true); + conditions.put("isStoreWasCalled", true); } @Override @@ -356,13 +361,14 @@ public void ValidateQueueRequest_NoCookie_ValidToken_ExtendableCookie_DoNotRedir config.setExtendCookieValidity(false); String customerKey = "4e1db821-a825-49da-acd0-5d376f2068db"; - HashMap> callInfo = new HashMap<>(); - callInfo.put("firstCall", new HashMap<>()); + final HashMap> callInfo = new HashMap(); + callInfo.put("firstCall", new HashMap()); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - HashMap info = new HashMap<>(); + HashMap info = new HashMap(); info.put("eventId", eventId); info.put("fixedCookieValidityMinutes", fixedCookieValidityMinutes); info.put("cookieDomain", cookieDomain); @@ -412,13 +418,14 @@ public void ValidateQueueRequest_NoCookie_ValidToken_CookieValidityMinuteFromTok config.setExtendCookieValidity(true); String customerKey = "secretekeyofuser"; - HashMap> callInfo = new HashMap<>(); - callInfo.put("firstCall", new HashMap<>()); + final HashMap> callInfo = new HashMap(); + callInfo.put("firstCall", new HashMap()); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - HashMap info = new HashMap<>(); + HashMap info = new HashMap(); info.put("eventId", eventId); info.put("fixedCookieValidityMinutes", fixedCookieValidityMinutes); info.put("cookieDomain", cookieDomain); @@ -467,10 +474,11 @@ public void ValidateQueueRequest_NoCookie_WithoutToken_RedirectToQueue() throws config.setLayoutName("testlayout"); config.setVersion(10); - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); conditions.put("isStoreWasCalled", false); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void cancelQueueCookie(String eventId, String cookieDomain) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -478,7 +486,7 @@ public void cancelQueueCookie(String eventId, String cookieDomain) { @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - conditions.replace("isStoreWasCalled", true); + conditions.put("isStoreWasCalled", true); } @Override @@ -518,10 +526,11 @@ public void ValidateQueueRequest_NoCookie_WithoutToken_RedirectToQueue_NoTargetU config.setLayoutName("testlayout"); config.setVersion(10); - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); conditions.put("isStoreWasCalled", false); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void cancelQueueCookie(String eventId, String cookieDomain) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -529,7 +538,7 @@ public void cancelQueueCookie(String eventId, String cookieDomain) { @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - conditions.replace("isStoreWasCalled", true); + conditions.put("isStoreWasCalled", true); } @Override @@ -567,10 +576,11 @@ public void ValidateQueueRequest_NoCookie_InValidToken() throws Exception { config.setLayoutName("testlayout"); config.setVersion(10); - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); conditions.put("isStoreWasCalled", false); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { + @Override public void cancelQueueCookie(String eventId, String cookieDomain) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -578,7 +588,7 @@ public void cancelQueueCookie(String eventId, String cookieDomain) { @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - conditions.replace("isStoreWasCalled", true); + conditions.put("isStoreWasCalled", true); } @Override @@ -616,13 +626,12 @@ public void validateCancelRequest() throws Exception { config.setCookieDomain("testdomain"); config.setVersion(10); - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); IUserInQueueStateRepository cookieProviderMock = new IUserInQueueStateRepository() { @Override public void store(String eventId, String queueId, Integer fixedCookieValidityMinutes, String cookieDomain, String redirectType, String customerSecretKey) throws Exception { - } @Override @@ -643,7 +652,6 @@ public void reissueQueueCookie(String eventId, int cookieValidityMinutes, String public void cancelQueueCookie(String eventId, String cookieDomain) { conditions.put("cancelQueueCookieWasCalled", "eventId:" + eventId + ",cookieDomain:" + cookieDomain); } - }; String knownUserVersion = UserInQueueService.SDK_VERSION; String expectedUrl = "https://testDomain.com/cancel/testCustomer/e1/?c=testCustomer&e=e1" @@ -680,9 +688,8 @@ public static String generateToken( boolean extendableCookie, Integer cookieValidityMinute, String secretKey, - String redirectType - ) throws Exception { - ArrayList paramList = new ArrayList<>(); + String redirectType) throws Exception { + ArrayList paramList = new ArrayList(); paramList.add(QueueParameterHelper.TimeStampKey + QueueParameterHelper.KeyValueSeparatorChar + GetUnixTimestamp(timeStamp)); if (cookieValidityMinute != null) { paramList.add(QueueParameterHelper.CookieValidityMinutesKey + QueueParameterHelper.KeyValueSeparatorChar + cookieValidityMinute); @@ -691,7 +698,7 @@ public static String generateToken( paramList.add(QueueParameterHelper.ExtendableCookieKey + QueueParameterHelper.KeyValueSeparatorChar + extendableCookie); paramList.add(QueueParameterHelper.RedirectTypeKey + QueueParameterHelper.KeyValueSeparatorChar + redirectType); - String tokenWithoutHash = String.join(QueueParameterHelper.KeyValueSeparatorGroupChar, paramList); + String tokenWithoutHash = Utils.join(QueueParameterHelper.KeyValueSeparatorGroupChar, paramList); String hash = HashHelper.generateSHA256Hash(secretKey, tokenWithoutHash); String token = tokenWithoutHash + QueueParameterHelper.KeyValueSeparatorGroupChar + QueueParameterHelper.HashKey + QueueParameterHelper.KeyValueSeparatorChar + hash; return token; diff --git a/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java b/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java index d1aecba..37b8a4d 100644 --- a/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/UserInQueueStateCookieRepositoryTest.java @@ -15,10 +15,11 @@ public void store_getState_ExtendableCookie_CookieIsSaved() throws Exception { String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc"; String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); int cookieValidity = 10; - HashMap> cookies = new HashMap<>(); - cookies.put(cookieKey, new HashMap<>()); + final HashMap> cookies = new HashMap(); + cookies.put(cookieKey, new HashMap()); ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { HashMap cookie = cookies.get(cookieName); @@ -44,7 +45,7 @@ public String getCookie(String cookieName) { assertTrue(state.getRedirectType().equals("Queue")); Long issueTime = Long.valueOf(UserInQueueStateCookieRepository.getCookieNameValueMap(String.valueOf(cookies.get(cookieKey).get("cookieValue"))).get("IssueTime")); assertTrue(Math.abs(System.currentTimeMillis() / 1000L - issueTime) < 2); - assertTrue((int) cookies.get(cookieKey).get("expiration") == 24 * 60 * 60); + assertTrue(Integer.parseInt(cookies.get(cookieKey).get("expiration").toString()) == 24 * 60 * 60); assertTrue(cookies.get(cookieKey).get("cookieDomain").equals(cookieDomain)); } @@ -56,9 +57,10 @@ public void store_getState_TamperedCookie_StateIsNotValid() throws Exception { String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc"; String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); int cookieValidity = 10; - HashMap cookies = new HashMap<>(); + final HashMap cookies = new HashMap(); ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { cookies.put(cookieName, cookieValue); @@ -78,7 +80,7 @@ public String getCookie(String cookieName) { String cookieString = cookies.get(cookieKey); cookieString = cookieString.replace("FixedValidityMins=10&", ""); - cookies.replace(cookieKey, cookieString); + cookies.put(cookieKey, cookieString); state = testObject.getState(eventId, 10, secretKey, true); assertFalse(state.isValid()); } @@ -89,9 +91,10 @@ public void store_getState_ExpiredCookie_StateIsNotValid_Queue() throws Exceptio String secretKey = "4e1db821-a825-49da-acd0-5d376f2068db"; String cookieDomain = ".test.com"; String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc"; - HashMap cookies = new HashMap<>(); + final HashMap cookies = new HashMap(); ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { cookies.put(cookieName, cookieValue); @@ -115,9 +118,10 @@ public void store_getState_ExpiredCookie_StateIsNotValid_Idle() throws Exception String secretKey = "4e1db821-a825-49da-acd0-5d376f2068db"; String cookieDomain = ".test.com"; String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc"; - HashMap cookies = new HashMap<>(); + final HashMap cookies = new HashMap(); ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { cookies.put(cookieName, cookieValue); @@ -143,9 +147,10 @@ public void store_getState_DifferentEventId_StateIsNotValid() throws Exception { String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc"; String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); - HashMap cookies = new HashMap<>(); + final HashMap cookies = new HashMap(); ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { cookies.put(cookieName, cookieValue); @@ -173,9 +178,9 @@ public void store_getState_InvalidCookie_StateIsNotValid() throws Exception { String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc"; ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { - } @Override @@ -198,11 +203,12 @@ public void cancelQueueCookie_Test() throws Exception { String cookieDomain = "testDomain"; String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); - HashMap> cookies = new HashMap<>(); - cookies.put(cookieKey + "1", new HashMap<>()); - cookies.put(cookieKey + "2", new HashMap<>()); + final HashMap> cookies = new HashMap(); + cookies.put(cookieKey + "1", new HashMap()); + cookies.put(cookieKey + "2", new HashMap()); ICookieManager cookieManager = new ICookieManager() { + public int setCookieCallNumber = 0; @Override @@ -228,7 +234,7 @@ public String getCookie(String cookieName) { testObject.cancelQueueCookie(eventId, cookieDomain); - assertTrue((int) cookies.get(cookieKey + "2").get("expiration") == 0); + assertTrue(Integer.parseInt(cookies.get(cookieKey + "2").get("expiration").toString()) == 0); assertTrue(cookies.get(cookieKey + "2").get("cookieValue") == null); assertTrue(cookies.get(cookieKey + "2").get("cookieDomain").equals(cookieDomain)); } @@ -240,12 +246,13 @@ public void extendQueueCookie_CookietExist_Test() throws Exception { String secretKey = "secretKey"; String queueId = "528f01d4-30f9-4753-95b3-2c8c33966abc"; String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); - HashMap cookie = new HashMap<>(); + final HashMap cookie = new HashMap(); Long issueTime = (System.currentTimeMillis() / 1000L - 120); String hash = HashHelper.generateSHA256Hash(secretKey, eventId + queueId + "3" + "idle" + String.valueOf(issueTime)); - String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&FixedValidityMins=3&RedirectType=idle&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; + final String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&FixedValidityMins=3&RedirectType=idle&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; ICookieManager cookieManager = new ICookieManager() { + public int setCookieCallNumber = 0; boolean isSetCookieCalled = false; @@ -281,7 +288,7 @@ public String getCookie(String cookieName) { assertTrue(state.getRedirectType().equals("idle")); Long newIssueTime = Long.valueOf(UserInQueueStateCookieRepository.getCookieNameValueMap(String.valueOf(cookie.get("cookieValue"))).get("IssueTime")); assertTrue(Math.abs(System.currentTimeMillis() / 1000L - newIssueTime) < 2); - assertTrue((int) cookie.get("expiration") == 24 * 60 * 60); + assertTrue(Integer.parseInt(cookie.get("expiration").toString()) == 24 * 60 * 60); assertTrue(cookie.get("cookieDomain").equals("cookieDomain")); } @@ -290,13 +297,14 @@ public void extendQueueCookie_CookieDoesNotExist_Test() { String eventId = "event1"; String secretKey = "secretKey"; - HashMap conditions = new HashMap<>(); + final HashMap conditions = new HashMap(); conditions.put("isSetCookieCalled", false); ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { - conditions.replace("isSetCookieCalled", true); + conditions.put("isSetCookieCalled", true); } @Override @@ -315,14 +323,14 @@ public void getState_ValidCookieFormat_Extendable_Test() throws Exception { String eventId = "event1"; String secretKey = "secretKey"; String queueId = "f8757c2d-34c2-4639-bef2-1736cdd30bbb"; - String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); + final String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); Long issueTime = (System.currentTimeMillis() / 1000L - 120); String hash = HashHelper.generateSHA256Hash(secretKey, eventId + queueId + "queue" + String.valueOf(issueTime)); - String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&RedirectType=queue&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; + final String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&RedirectType=queue&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { - } @Override @@ -347,14 +355,14 @@ public void getState_ValidCookieFormat_NonExtendable_Test() throws Exception { String eventId = "event1"; String secretKey = "secretKey"; String queueId = "f8757c2d-34c2-4639-bef2-1736cdd30bbb"; - String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); + final String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); Long issueTime = (System.currentTimeMillis() / 1000L - 120); String hash = HashHelper.generateSHA256Hash(secretKey, eventId + queueId + "3" + "idle" + String.valueOf(issueTime)); - String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&FixedValidityMins=3&RedirectType=idle&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; + final String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&FixedValidityMins=3&RedirectType=idle&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { - } @Override @@ -379,14 +387,14 @@ public void getState_OldCookie_InValid_ExpiredCookie_Extendable_Test() throws Ex String eventId = "event1"; String secretKey = "secretKey"; String queueId = "f8757c2d-34c2-4639-bef2-1736cdd30bbb"; - String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); + final String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); Long issueTime = (System.currentTimeMillis() / 1000L - (11 * 60)); String hash = HashHelper.generateSHA256Hash(secretKey, eventId + queueId + "queue" + String.valueOf(issueTime)); - String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&RedirectType=queue&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; + final String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&RedirectType=queue&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { - } @Override @@ -407,14 +415,14 @@ public void getState_OldCookie_InValid_ExpiredCookie_NonExtendable_Test() throws String eventId = "event1"; String secretKey = "secretKey"; String queueId = "f8757c2d-34c2-4639-bef2-1736cdd30bbb"; - String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); + final String cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId); Long issueTime = (System.currentTimeMillis() / 1000L - (4 * 60)); String hash = HashHelper.generateSHA256Hash(secretKey, eventId + queueId + "3" + "idle" + String.valueOf(issueTime)); - String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&FixedValidityMins=3&RedirectType=idle&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; + final String cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + "&FixedValidityMins=3&RedirectType=idle&IssueTime=" + String.valueOf(issueTime) + "&Hash=" + hash; ICookieManager cookieManager = new ICookieManager() { + @Override public void setCookie(String cookieName, String cookieValue, Integer expiration, String cookieDomain) { - } @Override diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java b/SDK/test/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java index de9ed71..4d53e5c 100644 --- a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/integrationconfig/ComparisonOperatorHelperTest.java @@ -49,7 +49,7 @@ public void Evaluate_MatchesWith() { assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.MATCHES_WITH, false, true, "test1_test1_testshop", ".*Shop.*", null)); assertFalse(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.MATCHES_WITH, true, true, "test1_test1_testshop", ".*Shop.*", null)); } - + @Test public void Evaluate_EqualsAny() { assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EQUALS_ANY, false, false, "test1", null, new String[]{"test1"})); @@ -59,7 +59,7 @@ public void Evaluate_EqualsAny() { assertFalse(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EQUALS_ANY, true, false, "test1", null, new String[]{"test1"})); assertFalse(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EQUALS_ANY, true, true, "test1", null, new String[]{"Test1"})); } - + @Test public void Evaluate_ContainsAny() { assertTrue(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.CONTAINS_ANY, false, false, "test_test1_test", null, new String[]{"test1"})); diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/HttpHeaderHelperTest.java b/SDK/test/queueit/knownuserv3/sdk/integrationconfig/HttpHeaderHelperTest.java index 2e0e485..13484e1 100644 --- a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/HttpHeaderHelperTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/integrationconfig/HttpHeaderHelperTest.java @@ -5,32 +5,33 @@ import org.junit.Test; public class HttpHeaderHelperTest { + @Test - public void Evaluate_Test() { + public void Evaluate_Test() { HttpServletRequestMock httpContextMock = new HttpServletRequestMock(); httpContextMock.Headers.put("MyHeaderName", "MyHeaderValue"); TriggerPart triggerPart = new TriggerPart(); - triggerPart.HttpHeaderName = "MyHeaderName"; - - triggerPart.ValueToCompare = "MyHeaderValue"; + triggerPart.HttpHeaderName = "MyHeaderName"; + + triggerPart.ValueToCompare = "MyHeaderValue"; triggerPart.Operator = ComparisonOperatorType.EQUALS; triggerPart.IsNegative = false; triggerPart.IsIgnoreCase = false; assertTrue(HttpHeaderValidatorHelper.evaluate(triggerPart, httpContextMock)); - + triggerPart.ValueToCompare = "Value"; triggerPart.Operator = ComparisonOperatorType.CONTAINS; triggerPart.IsNegative = false; triggerPart.IsIgnoreCase = false; assertTrue(HttpHeaderValidatorHelper.evaluate(triggerPart, httpContextMock)); - + triggerPart.ValueToCompare = "MyHeaderValue"; - triggerPart.Operator = ComparisonOperatorType.EQUALS; + triggerPart.Operator = ComparisonOperatorType.EQUALS; triggerPart.IsNegative = true; triggerPart.IsIgnoreCase = false; assertFalse(HttpHeaderValidatorHelper.evaluate(triggerPart, httpContextMock)); - - triggerPart.ValueToCompare = "myheadervalue"; + + triggerPart.ValueToCompare = "myheadervalue"; triggerPart.Operator = ComparisonOperatorType.EQUALS; triggerPart.IsNegative = false; triggerPart.IsIgnoreCase = true; diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluatorTest.java b/SDK/test/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluatorTest.java index bb8dc96..579ba0c 100644 --- a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluatorTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/integrationconfig/IntegrationEvaluatorTest.java @@ -23,367 +23,353 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpUpgradeHandler; import javax.servlet.http.Part; - class HttpServletRequestMock implements HttpServletRequest { - public Cookie[] CookiesValue; - public String UserAgent = ""; - public String RequestURL; - public String QueryString; - public HashMap Headers = new HashMap(); +class HttpServletRequestMock implements HttpServletRequest { - @Override - public String getAuthType() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public Cookie[] getCookies() { - return this.CookiesValue; - } + public Cookie[] CookiesValue; + public String UserAgent = ""; + public String RequestURL; + public String QueryString; + public HashMap Headers = new HashMap(); - @Override - public long getDateHeader(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public String getHeader(String key) { - if("User-Agent".equals(key)) - return this.UserAgent; - - if(this.Headers.containsKey(key)) - return this.Headers.get(key); - return ""; - } + @Override + public String getAuthType() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Enumeration getHeaders(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Cookie[] getCookies() { + return this.CookiesValue; + } - @Override - public Enumeration getHeaderNames() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public long getDateHeader(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public int getIntHeader(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + @Override + public String getHeader(String key) { + if ("User-Agent".equals(key)) { + return this.UserAgent; } - @Override - public String getMethod() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (this.Headers.containsKey(key)) { + return this.Headers.get(key); } + return ""; + } - @Override - public String getPathInfo() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getHeaders(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getPathTranslated() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getHeaderNames() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getContextPath() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public int getIntHeader(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getQueryString() { - return this.QueryString; - } + @Override + public String getMethod() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRemoteUser() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getPathInfo() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isUserInRole(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getPathTranslated() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Principal getUserPrincipal() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getContextPath() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRequestedSessionId() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getQueryString() { + return this.QueryString; + } - @Override - public String getRequestURI() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRemoteUser() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public StringBuffer getRequestURL() { - return new StringBuffer(this.RequestURL); - } + @Override + public boolean isUserInRole(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getServletPath() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Principal getUserPrincipal() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public HttpSession getSession(boolean bln) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRequestedSessionId() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public HttpSession getSession() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRequestURI() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String changeSessionId() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public StringBuffer getRequestURL() { + return new StringBuffer(this.RequestURL); + } - @Override - public boolean isRequestedSessionIdValid() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getServletPath() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isRequestedSessionIdFromCookie() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public HttpSession getSession(boolean bln) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isRequestedSessionIdFromURL() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public HttpSession getSession() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isRequestedSessionIdFromUrl() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isRequestedSessionIdValid() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean authenticate(HttpServletResponse hsr) throws IOException, ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isRequestedSessionIdFromCookie() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void login(String string, String string1) throws ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isRequestedSessionIdFromURL() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void logout() throws ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isRequestedSessionIdFromUrl() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Collection getParts() throws IOException, ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean authenticate(HttpServletResponse hsr) throws IOException, ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Part getPart(String string) throws IOException, ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void login(String string, String string1) throws ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public T upgrade(Class type) throws IOException, ServletException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void logout() throws ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Object getAttribute(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Collection getParts() throws IOException, ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Enumeration getAttributeNames() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Part getPart(String string) throws IOException, ServletException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getCharacterEncoding() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Object getAttribute(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void setCharacterEncoding(String string) throws UnsupportedEncodingException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getAttributeNames() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public int getContentLength() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getCharacterEncoding() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public long getContentLengthLong() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void setCharacterEncoding(String string) throws UnsupportedEncodingException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getContentType() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public int getContentLength() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public ServletInputStream getInputStream() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getContentType() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getParameter(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public ServletInputStream getInputStream() throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Enumeration getParameterNames() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getParameter(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String[] getParameterValues(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getParameterNames() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Map getParameterMap() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String[] getParameterValues(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getProtocol() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Map getParameterMap() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getScheme() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getProtocol() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getServerName() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getScheme() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public int getServerPort() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getServerName() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public BufferedReader getReader() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public int getServerPort() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRemoteAddr() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public BufferedReader getReader() throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRemoteHost() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRemoteAddr() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void setAttribute(String string, Object o) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRemoteHost() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void removeAttribute(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void setAttribute(String string, Object o) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Locale getLocale() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public void removeAttribute(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public Enumeration getLocales() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Locale getLocale() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isSecure() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public Enumeration getLocales() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public RequestDispatcher getRequestDispatcher(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isSecure() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getRealPath(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public RequestDispatcher getRequestDispatcher(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public int getRemotePort() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getRealPath(String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getLocalName() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public int getRemotePort() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public String getLocalAddr() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getLocalName() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public int getLocalPort() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public String getLocalAddr() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public ServletContext getServletContext() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public int getLocalPort() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public AsyncContext startAsync() throws IllegalStateException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public ServletContext getServletContext() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public AsyncContext startAsync(ServletRequest sr, ServletResponse sr1) throws IllegalStateException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public AsyncContext startAsync() throws IllegalStateException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isAsyncStarted() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public AsyncContext startAsync(ServletRequest sr, ServletResponse sr1) throws IllegalStateException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public boolean isAsyncSupported() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isAsyncStarted() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public AsyncContext getAsyncContext() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public boolean isAsyncSupported() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public DispatcherType getDispatcherType() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + @Override + public AsyncContext getAsyncContext() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override + public DispatcherType getDispatcherType() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } +} public class IntegrationEvaluatorTest { @@ -424,9 +410,9 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched() throws Excep customerIntegration.Integrations = integrationConfigModels; String url = "http://test.tesdomain.com:8080/test?q=2"; - + HttpServletRequestMock httpContextMock = new HttpServletRequestMock(); - httpContextMock.CookiesValue = new Cookie [0]; + httpContextMock.CookiesValue = new Cookie[0]; IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); assertTrue(result == null); @@ -471,9 +457,9 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_Matched() throws Exceptio customerIntegration.Integrations = integrationConfigModels; String url = "http://test.tesdomain.com:8080/test?q=2"; - + HttpServletRequestMock httpContextMock = new HttpServletRequestMock(); - httpContextMock.CookiesValue = new Cookie [1]; + httpContextMock.CookiesValue = new Cookie[1]; httpContextMock.CookiesValue[0] = new Cookie("c1", "value1"); IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); @@ -522,10 +508,10 @@ public void GetMatchedIntegrationConfig_OneTrigger_Or_NotMatched() throws Except String url = "http://test.tesdomain.com:8080/test?q=2"; HttpServletRequestMock httpContextMock = new HttpServletRequestMock(); - httpContextMock.CookiesValue = new Cookie [1]; + httpContextMock.CookiesValue = new Cookie[1]; httpContextMock.CookiesValue[0] = new Cookie("c2", "value1"); - IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); + IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); assertTrue(result == null); } @@ -567,12 +553,12 @@ public void GetMatchedIntegrationConfig_OneTrigger_Or_Matched() throws Exception customerIntegration.Integrations = integrationConfigModels; String url = "http://test.tesdomain.com:8080/test?q=2"; - + HttpServletRequestMock httpContextMock = new HttpServletRequestMock(); - httpContextMock.CookiesValue = new Cookie [1]; + httpContextMock.CookiesValue = new Cookie[1]; httpContextMock.CookiesValue[0] = new Cookie("c1", "value1"); - IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); + IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); assertTrue(result.Name.equals("integration1")); } @@ -588,7 +574,7 @@ public void GetMatchedIntegrationConfig_TwoTriggers_Matched() throws Exception { TriggerPart[] triggerParts1 = new TriggerPart[1]; triggerParts1[0] = triggerPart1; - + TriggerModel triggerModel1 = new TriggerModel(); triggerModel1.LogicalOperator = LogicalOperatorType.AND; triggerModel1.TriggerParts = triggerParts1; @@ -601,7 +587,7 @@ public void GetMatchedIntegrationConfig_TwoTriggers_Matched() throws Exception { TriggerPart[] triggerParts2 = new TriggerPart[1]; triggerParts2[0] = triggerPart2; - + TriggerModel triggerModel2 = new TriggerModel(); triggerModel2.LogicalOperator = LogicalOperatorType.AND; triggerModel2.TriggerParts = triggerParts2; @@ -609,7 +595,7 @@ public void GetMatchedIntegrationConfig_TwoTriggers_Matched() throws Exception { TriggerModel[] triggerModels = new TriggerModel[2]; triggerModels[0] = triggerModel1; triggerModels[1] = triggerModel2; - + IntegrationConfigModel integrationConfigModel = new IntegrationConfigModel(); integrationConfigModel.Name = "integration1"; integrationConfigModel.Triggers = triggerModels; @@ -621,11 +607,11 @@ public void GetMatchedIntegrationConfig_TwoTriggers_Matched() throws Exception { customerIntegration.Integrations = integrationConfigModels; String url = "http://test.tesdomain.com:8080/test?q=2"; - + HttpServletRequestMock httpContextMock = new HttpServletRequestMock(); - httpContextMock.CookiesValue = new Cookie [0]; + httpContextMock.CookiesValue = new Cookie[0]; - IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); + IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); assertTrue(result.Name.equals("integration1")); } @@ -654,7 +640,7 @@ public void GetMatchedIntegrationConfig_TwoTriggers_NotMatched() throws Exceptio TriggerPart[] triggerParts2 = new TriggerPart[1]; triggerParts2[0] = triggerPart2; - + TriggerModel triggerModel2 = new TriggerModel(); triggerModel2.LogicalOperator = LogicalOperatorType.AND; triggerModel2.TriggerParts = triggerParts2; @@ -662,7 +648,7 @@ public void GetMatchedIntegrationConfig_TwoTriggers_NotMatched() throws Exceptio TriggerModel[] triggerModels = new TriggerModel[2]; triggerModels[0] = triggerModel1; triggerModels[1] = triggerModel2; - + IntegrationConfigModel integrationConfigModel = new IntegrationConfigModel(); integrationConfigModel.Name = "integration1"; integrationConfigModel.Triggers = triggerModels; @@ -674,11 +660,11 @@ public void GetMatchedIntegrationConfig_TwoTriggers_NotMatched() throws Exceptio customerIntegration.Integrations = integrationConfigModels; String url = "http://test.tesdomain.com:8080/test?q=2"; - + HttpServletRequestMock httpContextMock = new HttpServletRequestMock(); - httpContextMock.CookiesValue = new Cookie [0]; + httpContextMock.CookiesValue = new Cookie[0]; - IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); + IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); assertTrue(result == null); } @@ -706,13 +692,13 @@ public void GetMatchedIntegrationConfig_ThreeIntegrationsInOrder_SecondMatched() TriggerPart[] triggerParts0 = new TriggerPart[1]; triggerParts0[0] = triggerPart0; - + TriggerPart[] triggerParts1 = new TriggerPart[1]; triggerParts1[0] = triggerPart1; - + TriggerPart[] triggerParts2 = new TriggerPart[1]; triggerParts2[0] = triggerPart2; - + TriggerModel triggerModel0 = new TriggerModel(); triggerModel0.LogicalOperator = LogicalOperatorType.AND; triggerModel0.TriggerParts = triggerParts0; @@ -727,13 +713,13 @@ public void GetMatchedIntegrationConfig_ThreeIntegrationsInOrder_SecondMatched() TriggerModel[] triggerModels0 = new TriggerModel[1]; triggerModels0[0] = triggerModel0; - + TriggerModel[] triggerModels1 = new TriggerModel[1]; triggerModels1[0] = triggerModel1; - + TriggerModel[] triggerModels2 = new TriggerModel[1]; triggerModels2[0] = triggerModel2; - + IntegrationConfigModel integrationConfigModel0 = new IntegrationConfigModel(); integrationConfigModel0.Name = "integration0"; integrationConfigModel0.Triggers = triggerModels0; @@ -753,19 +739,19 @@ public void GetMatchedIntegrationConfig_ThreeIntegrationsInOrder_SecondMatched() CustomerIntegration customerIntegration = new CustomerIntegration(); customerIntegration.Integrations = integrationConfigModels; - + String url = "http://test.tesdomain.com:8080/test?q=2"; - + HttpServletRequestMock httpContextMock = new HttpServletRequestMock(); - httpContextMock.CookiesValue = new Cookie [1]; + httpContextMock.CookiesValue = new Cookie[1]; httpContextMock.CookiesValue[0] = new Cookie("c1", "Value1"); - - IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); + + IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); assertTrue(result.Name.equals("integration1")); } - - @Test - public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_UserAgent() throws Exception { + + @Test + public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_UserAgent() throws Exception { IntegrationEvaluator testObject = new IntegrationEvaluator(); TriggerPart triggerPart1 = new TriggerPart(); @@ -780,12 +766,12 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_UserAgent() th triggerPart2.Operator = ComparisonOperatorType.CONTAINS; triggerPart2.UrlPart = UrlPartType.PAGE_URL; triggerPart2.ValueToCompare = "test"; - + TriggerPart triggerPart3 = new TriggerPart(); triggerPart3.ValidatorType = ValidatorType.USERAGENT_VALIDATOR; triggerPart3.Operator = ComparisonOperatorType.CONTAINS; triggerPart3.ValueToCompare = "googlebot"; - triggerPart3.IsNegative= true; + triggerPart3.IsNegative = true; triggerPart3.IsIgnoreCase = true; TriggerPart[] triggerParts = new TriggerPart[3]; @@ -811,13 +797,13 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_UserAgent() th customerIntegration.Integrations = integrationConfigModels; String url = "http://test.tesdomain.com:8080/test?q=2"; - + HttpServletRequestMock httpContextMock = new HttpServletRequestMock(); - httpContextMock.CookiesValue = new Cookie [1]; - httpContextMock.CookiesValue[0]=new Cookie("c1", "value1"); + httpContextMock.CookiesValue = new Cookie[1]; + httpContextMock.CookiesValue[0] = new Cookie("c1", "value1"); httpContextMock.UserAgent = "Googlebot"; - - IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); + + IntegrationConfigModel result = testObject.getMatchedIntegrationConfig(customerIntegration, url, httpContextMock); assertTrue(result == null); - } + } } \ No newline at end of file diff --git a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/UserAgentValidatorHelperTest.java b/SDK/test/queueit/knownuserv3/sdk/integrationconfig/UserAgentValidatorHelperTest.java index 5700cf7..6b3be6d 100644 --- a/SDK/test/queueit/knownuserv3/sdk/integrationconfig/UserAgentValidatorHelperTest.java +++ b/SDK/test/queueit/knownuserv3/sdk/integrationconfig/UserAgentValidatorHelperTest.java @@ -1,37 +1,33 @@ - package queueit.knownuserv3.sdk.integrationconfig; import static org.junit.Assert.assertFalse; import org.junit.Test; - public class UserAgentValidatorHelperTest { - @Test - public void Evaluate_Test() { - - TriggerPart triggerPart = new TriggerPart(); - triggerPart.Operator = ComparisonOperatorType.CONTAINS; - triggerPart.ValueToCompare = "googlebot"; - assertFalse(UserAgentValidatorHelper.evaluate(triggerPart, "Googlebot sample useraagent")); - - triggerPart.ValueToCompare = "googlebot"; - triggerPart.Operator = ComparisonOperatorType.EQUALS; - triggerPart.IsIgnoreCase = true; - triggerPart.IsNegative = true; - assert(UserAgentValidatorHelper.evaluate(triggerPart, "oglebot sample useraagent")); - - triggerPart.ValueToCompare = "googlebot"; - triggerPart.Operator = ComparisonOperatorType.CONTAINS; - triggerPart.IsIgnoreCase = false; - triggerPart.IsNegative = true; - assertFalse(UserAgentValidatorHelper.evaluate(triggerPart, "googlebot")); - - - triggerPart.ValueToCompare = "googlebot"; - triggerPart.IsIgnoreCase = true; - triggerPart.IsNegative = false; - triggerPart.Operator = ComparisonOperatorType.CONTAINS; - assert (UserAgentValidatorHelper.evaluate(triggerPart, "Googlebot")); + @Test + public void Evaluate_Test() { + TriggerPart triggerPart = new TriggerPart(); + triggerPart.Operator = ComparisonOperatorType.CONTAINS; + triggerPart.ValueToCompare = "googlebot"; + assertFalse(UserAgentValidatorHelper.evaluate(triggerPart, "Googlebot sample useraagent")); + + triggerPart.ValueToCompare = "googlebot"; + triggerPart.Operator = ComparisonOperatorType.EQUALS; + triggerPart.IsIgnoreCase = true; + triggerPart.IsNegative = true; + assert (UserAgentValidatorHelper.evaluate(triggerPart, "oglebot sample useraagent")); + + triggerPart.ValueToCompare = "googlebot"; + triggerPart.Operator = ComparisonOperatorType.CONTAINS; + triggerPart.IsIgnoreCase = false; + triggerPart.IsNegative = true; + assertFalse(UserAgentValidatorHelper.evaluate(triggerPart, "googlebot")); + + triggerPart.ValueToCompare = "googlebot"; + triggerPart.IsIgnoreCase = true; + triggerPart.IsNegative = false; + triggerPart.Operator = ComparisonOperatorType.CONTAINS; + assert (UserAgentValidatorHelper.evaluate(triggerPart, "Googlebot")); } }