all.js revision 0dd7db90ddc84e1fe5b102a52f8966faa923c124
/**
* Created by craig on 07/07/2014.
*/
// ============================================================================================================
// TDD framework
getTestDetails = function() {
function getErrorObject() {
}
var err = getErrorObject();
// e.g. at shouldCreateComparisonResultWithZeroPenaltyPoints (eval at <anonymous> (eval at <anonymous> (http://repl.it/jsrepl/sandbox.js:39:104)), <anonymous>:247:73)
var callee_function = caller_line.slice(caller_line.indexOf("at ")+2, caller_line.indexOf("(eval"));
var callee_line_number = caller_line.slice(caller_line.indexOf("<anonymous>:")+12, caller_line.indexOf(":", caller_line.indexOf("<anonymous>:")+12));
};
};
}
};
assertTrue = function(value) {
if (value !== true) {
logError("expected true");
}
};
assertFalse = function(value) {
if (value !== false) {
logError("expected false");
}
};
return;
}
return;
}
}
};
// ============================================================================================================
// Dummy Data
var ldapDevicePrintProfiles =[
{
"uuid":"uuid1",
"lastSelectedDate":"2014-07-03T08:10:46.154+0000",
"selectionCounter":1,
"devicePrint":{
"screen":{
"screenWidth":1920,
"screenHeight":1200,
"screenColourDepth":24
},
"timezone":{
"timezone":-60
},
"plugins":{
"installedPlugins":"QuickTime Plugin.plugin;Default Browser.plugin;googletalkbrowserplugin.plugin;o1dbrowserplugin.plugin;AdobePDFViewerNPAPI.plugin;JavaAppletPlugin.plugin;CitrixOnlineWebDeploymentPlugin.plugin"
},
"fonts":{
"installedFonts":"cursive;monospace;serif;sans-serif;fantasy;default;Arial;Arial Black;Arial Narrow;Arial Rounded MT Bold;Comic Sans MS;Courier;Courier New;Georgia;Impact;Papyrus;Tahoma;Times;Times New Roman;Trebuchet MS;Verdana;"
},
"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0",
"appName":"Netscape",
"appCodeName":"Mozilla",
"appVersion":"5.0 (Macintosh)",
"buildID":"20140605174243",
"platform":"MacIntel",
"oscpu":"Intel Mac OS X 10.9",
"product":"Gecko",
"productSub":"20100101",
"language":"en-GB",
"geolocation":{
"longitude":-2.5942761,
"latitude":51.451074999999996
}
}
},
{
"uuid":"uuid2",
"lastSelectedDate":"2014-06-30T00:02:46.154+0000",
"selectionCounter":1,
"devicePrint":{
"screen":{
"screenWidth":1920,
"screenHeight":1200,
"screenColourDepth":24
},
"timezone":{
"timezone":-60
},
"plugins":{
"installedPlugins":"QuickTime Plugin.plugin;Default Browser.plugin;googletalkbrowserplugin.plugin;o1dbrowserplugin.plugin;AdobePDFViewerNPAPI.plugin;JavaAppletPlugin.plugin;CitrixOnlineWebDeploymentPlugin.plugin"
},
"fonts":{
"installedFonts":"cursive;monospace;serif;sans-serif;fantasy;default;Arial;Arial Black;Arial Narrow;Arial Rounded MT Bold;Comic Sans MS;Courier;Courier New;Georgia;Impact;Papyrus;Tahoma;Times;Times New Roman;Trebuchet MS;Verdana;"
},
"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0",
"appName":"Netscape",
"appCodeName":"Mozilla",
"appVersion":"5.0 (Macintosh)",
"buildID":"20140605174243",
"platform":"MacIntel",
"oscpu":"Intel Mac OS X 10.9",
"product":"Gecko",
"productSub":"20100101",
"language":"en-GB",
"geolocation":{
"longitude":-2.5942761,
"latitude":51.451074999999996
}
}
},
{
"uuid":"uuid3",
"lastSelectedDate":"2014-06-30T23:59:46.154+0000",
"selectionCounter":1,
"devicePrint":{
"screen":{
"screenWidth":1920,
"screenHeight":1200,
"screenColourDepth":24
},
"timezone":{
"timezone":-60
},
"plugins":{
"installedPlugins":"QuickTime Plugin.plugin;Default Browser.plugin;googletalkbrowserplugin.plugin;o1dbrowserplugin.plugin;AdobePDFViewerNPAPI.plugin;JavaAppletPlugin.plugin;CitrixOnlineWebDeploymentPlugin.plugin"
},
"fonts":{
"installedFonts":"cursive;monospace;serif;sans-serif;fantasy;default;Arial;Arial Black;Arial Narrow;Arial Rounded MT Bold;Comic Sans MS;Courier;Courier New;Georgia;Impact;Papyrus;Tahoma;Times;Times New Roman;Trebuchet MS;Verdana;"
},
"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0",
"appName":"Netscape",
"appCodeName":"Mozilla",
"appVersion":"5.0 (Macintosh)",
"buildID":"20140605174243",
"platform":"MacIntel",
"oscpu":"Intel Mac OS X 10.9",
"product":"Gecko",
"productSub":"20100101",
"language":"en-GB",
"geolocation":{
"longitude":-2.5942761,
"latitude":51.451074999999996
}
}
}
];
"screen":{
"screenWidth":1920,
"screenHeight":1200,
"screenColourDepth":24
},
"timezone":{
"timezone":-60
},
"plugins":{
"installedPlugins":"QuickTime Plugin.plugin;Default Browser.plugin;googletalkbrowserplugin.plugin;o1dbrowserplugin.plugin;AdobePDFViewerNPAPI.plugin;JavaAppletPlugin.plugin;CitrixOnlineWebDeploymentPlugin.plugin"
},
"fonts":{
"installedFonts":"cursive;monospace;serif;sans-serif;fantasy;default;Arial;Arial Black;Arial Narrow;Arial Rounded MT Bold;Comic Sans MS;Courier;Courier New;Georgia;Impact;Papyrus;Tahoma;Times;Times New Roman;Trebuchet MS;Verdana;"
},
"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0",
"appName":"Netscape",
"appCodeName":"Mozilla",
"appVersion":"5.0 (Macintosh)",
"buildID":"20140605174243",
"platform":"MacIntel",
"oscpu":"Intel Mac OS X 10.9",
"product":"Gecko",
"productSub":"20100101",
"language":"en-GB",
"geolocation":{
"longitude":-2.5942761,
"latitude":51.451074999999996
}
};
/**
* Constructs an instance of a ComparisonResult with the given penalty points.
*
* @param penaltyPoints The penalty points for the comparison (defaults to 0).
* @param additionalInfoInCurrentValue Whether the current value contains more information than the stored value (defaults to false).
*/
function ComparisonResult() {
penaltyPoints = 0;
additionalInfoInCurrentValue = false;
// TODO: Simplfiy constructor overloading copied from Java
}
} else {
}
}
this.penaltyPoints = penaltyPoints;
}
/**
* Comparison function that can be provided as an argument to array.sort
*/
return 0;
} else if (first === null) {
return -1;
} else if (second === null) {
return 1;
} else {
} else {
return (first.additionalInfoInCurrentValue ? 1 : 0) - (second.additionalInfoInCurrentValue ? 1 : 0);
}
}
};
/**
* Amalgamates the given ComparisonResult into this ComparisonResult.
*
* @param comparisonResult The ComparisonResult to include.
*/
}
};
/**
* Returns true if no penalty points have been assigned for the comparison.
*
* @return If the comparison was successful.
*/
};
/**
* Constructs an instance of a ColocationComparator
*/
function ColocationComparator() {
}
/**
* Compares two locations, taking into account a degree of difference.
*
* @param currentLatitude (double) The current latitude.
* @param currentLongitude (double) The current longitude.
* @param storedLatitude (double) The stored latitude.
* @param storedLongitude (double) The current longitude.
* @param maxToleratedDistance (long) The max difference allowed in the two locations, before the penalty is assigned.
* @param differencePenaltyPoints(long) The number of penalty points.
* @return A ComparisonResult.
*/
ColocationComparator.prototype.compare = function(currentLatitude, currentLongitude, storedLatitude,
return ComparisonResult.ZERO_PENALTY_POINTS;
}
if (this.currentNullStoredNotNull(currentLatitude, currentLongitude, storedLatitude, storedLongitude)) {
return new ComparisonResult(differencePenaltyPoints);
}
if (this.storedNullCurrentNotNull(currentLatitude, currentLongitude, storedLatitude, storedLongitude)) {
return new ComparisonResult(differencePenaltyPoints, true);
}
distance = this.calculateDistance(currentLatitude, currentLongitude, storedLatitude, storedLongitude);
// if (DEBUG.messageEnabled()) {
// DEBUG.message("Distance between (" + currentLatitude + "," + currentLongitude + ") and (" + storedLatitude
// + "," + storedLongitude + ") is " + distance + " miles");
// }
// if (DEBUG.messageEnabled()) {
// DEBUG.message("Location is the same");
// }
return ComparisonResult.ZERO_PENALTY_POINTS;
}
if (inMaxToleratedRange) {
// if (DEBUG.messageEnabled()) {
// DEBUG.message("Tolerated because distance not more then "+maxToleratedDistance);
// }
return new ComparisonResult(true);
} else {
// if (DEBUG.messageEnabled()) {
// DEBUG.message("Would be ignored if distance not more then "+maxToleratedDistance);
// }
return new ComparisonResult(differencePenaltyPoints);
}
};
/**
* Checks if the stored location is null and the current location is null.
*
* @param currentLatitude (double) The current latitude.
* @param currentLongitude (double) The current longitude.
* @param storedLatitude (double) The stored latitude.
* @param storedLongitude (double) The current longitude.
* @return If the check passes true, otherwise false.
*/
ColocationComparator.prototype.bothNull = function(currentLatitude, currentLongitude, storedLatitude, storedLongitude) {
return this.atLeastOneNull(currentLatitude, currentLongitude) && this.atLeastOneNull(storedLatitude, storedLongitude);
};
/**
* Checks to see if the x or y co-ordinates is null.
*
* @param first (double) The x co-ordinates.
* @param second (double) The y co-ordinates.
* @return If either are null.
*/
};
/**
* Checks if the current location is null and the stored location is not null.
*
* @param currentLatitude (double) The current latitude.
* @param currentLongitude (double) The current longitude.
* @param storedLatitude (double) The stored latitude.
* @param storedLongitude (double) The current longitude.
* @return If the check passes true, otherwise false.
*/
ColocationComparator.prototype.currentNullStoredNotNull = function(currentLatitude, currentLongitude, storedLatitude, storedLongitude) {
return this.atLeastOneNull(currentLatitude, currentLongitude) && !this.atLeastOneNull(storedLatitude, storedLongitude);
};
/**
* Checks if the stored location is null and the current location is not null.
*
* @param currentLatitude (double) The current latitude.
* @param currentLongitude (double) The current longitude.
* @param storedLatitude (double) The stored latitude.
* @param storedLongitude (double) The current longitude.
* @return If the check passes true, otherwise false.
*/
ColocationComparator.prototype.storedNullCurrentNotNull = function(currentLatitude, currentLongitude, storedLatitude, storedLongitude) {
return !this.atLeastOneNull(currentLatitude, currentLongitude) && this.atLeastOneNull(storedLatitude, storedLongitude);
};
/**
* Calculates the distances between the two locations.
*
* @param currentLatitude The current latitude.
* @param currentLongitude The current longitude.
* @param storedLatitude The stored latitude.
* @param storedLongitude The stored longitude.
* @return The distance between the two locations.
*/
ColocationComparator.prototype.calculateDistance = function(currentLatitude, currentLongitude, storedLatitude, storedLongitude) {
function degreesToRadians(degrees) {
}
function radiansToDegrees(radians) {
}
return dist;
};
/**
* Whether the distance between the two locations is within the allowed difference.
*
* @param distance (double) The actual distance between the locations.
* @param maxToleratedDistance (long) The max difference allowed between the locations.
* @return True is the check passes, otherwise false.
*/
return distance <= maxToleratedDistance;
};
/**
* Compares two Strings of comma separated values.
*/
function MultiValueAttributeComparator() {
}
/**
* Splits both attributes using delimiter, trims every value and compares collections of values.
* Returns zero-result for same multi-value attributes.
*
* If collections are not same checks if number of differences is less or equal maxToleratedNumberOfDifferences or
* percentage of difference is less or equal maxToleratedPercentageToMarkAsDifferent.
*
* If yes then returns zero-result with additional info, else returns penaltyPoints-result.
*
* @param currentAttribute The current value.
* @param storedAttribute The stored value.
* @param maxToleratedNumberOfDifferences The max number of differences in the values, before the penalty points
* are assigned.
* @param maxToleratedPercentageToMarkAsDifferent The max difference percentage in the values, before the penalty
* is assigned.
* @param penaltyPoints The number of penalty points.
* @return A ComparisonResult.
*/
return new ComparisonResult(true);
}
var numberOfDifferences = this.getNumberOfDifferences(numberOfTheSameElements, maxNumberOfElements);
var percentageOfDifferences = this.getPercentageOfDifferences(numberOfDifferences, maxNumberOfElements);
// if (DEBUG.messageEnabled()) {
// DEBUG.message(numberOfTheSameElements + " of " + maxNumberOfElements + " are same");
// }
if (maxNumberOfElements === 0) {
// if (DEBUG.messageEnabled()) {
// DEBUG.message("Ignored because no attributes found in both profiles");
// }
return ComparisonResult.ZERO_PENALTY_POINTS;
}
if (numberOfTheSameElements === maxNumberOfElements) {
// if (DEBUG.messageEnabled()) {
// DEBUG.message("Ignored because all attributes are same");
// }
return ComparisonResult.ZERO_PENALTY_POINTS;
}
// if (DEBUG.messageEnabled()) {
// DEBUG.message("Would be ignored if not more than " + maxToleratedDifferences + " differences");
// }
return new ComparisonResult(penaltyPoints);
}
// if (DEBUG.messageEnabled()) {
// DEBUG.message(percentageOfDifferences + " percents are different");
// DEBUG.message("Would be ignored if not more than " + maxToleratedPercentage + " percent");
// }
return new ComparisonResult(penaltyPoints);
}
// if (DEBUG.messageEnabled()) {
// DEBUG.message("Ignored because number of differences(" + numberOfDifferences + ") not more than "
// + maxToleratedDifferences);
// DEBUG.message(percentageOfDifferences + " percents are different");
// DEBUG.message("Ignored because not more than " + maxToleratedPercentage + " percent");
// }
return new ComparisonResult(true);
};
/**
* Converts a comma separated String into a List.
*
* @param multiAttribute The comma separated String.
* @return A list of the comma separated values.
*/
results = [];
if (multiAttribute === null) {
return results;
}
var attribute = attributes[i];
}
}
return results;
};
/**
* Gets the percentage of the differences between the two values.
*
* @param numberOfDifferences The actual number of differences.
* @param maxNumberOfElements The number of values in the largest multi-value.
* @return The percentage of differences.
*/
MultiValueAttributeComparator.prototype.getPercentageOfDifferences = function(numberOfDifferences, maxNumberOfElements) {
if (maxNumberOfElements === 0) {
return 0;
}
// divide by 2, keeping result to 2 decimal places then multiply by 100
// return this.numberOfDifferences.divide(maxNumberOfElements, 2, RoundingMode.HALF_UP).multiply(HUNDRED);
};
/**
* Gets the number of differences between the two values.
*
* @param numberOfSameElements The number of elements that are equal.
* @param maxNumberOfElements The number of values in the largest multi-value.
* @return The number of differences.
*/
MultiValueAttributeComparator.prototype.getNumberOfDifferences = function(numberOfSameElements, maxNumberOfElements) {
return maxNumberOfElements - numberOfSameElements;
};
/**
* Gets the number of elements that are equal between the two lists of values.
*
* @param currentAttributes The current values.
* @param storedAttributes The stored values.
* @return The number of elements that are equal.
*/
MultiValueAttributeComparator.prototype.getNumberOfSameElements = function(currentAttributes, storedAttributes) {
});
};
/**
* Comparator for comparing two Device Print objects to determine how similar they are based
* from the penalty points assigned to each attribute on the Device Print object.
*
* @param multiValueAttributeComparator An instance of the MultiValueAttributeComparator.
* @param colocationComparator An instance of the ColocationComparator.
*/
}
/**
* Compares two Device Print objects to determine how similar they are based from the penalty points
* assigned to each attribute on the Device Print object.
*
* @param currentDevicePrint The latest Device Print object.
* @param storedDevicePrint A previously stored Device Print object.
* @param config An instance of the DevicePrintAuthenticationConfig.
* @return A ComparisonResult detailing the number of penalty points assigned to this comparison.
*/
var aggregatedComparisonResult = new ComparisonResult();
var userAgentComparisonResult = this.compareUserAgent(
var timezoneComparisonResult = this.compareStrings(
// if (DEBUG.messageEnabled()) {
// DEBUG.message("Compared device current print: " + currentDevicePrint);
// DEBUG.message("Compared stored device print: " + storedDevicePrint);
// DEBUG.message("Penalty points: " + aggregatedComparisonResult.getPenaltyPoints());
// DEBUG.message("UserAgent: " + userAgentComparisonResult + ", fonts: " + installedFontsComparisonResult
// + ", plugins: " + installedPluginsComparisonResult + ", colourDepth: " + colorDepthComparisonResult
// + ", timezone: " + timezoneComparisonResult + ", screenRes: " + screenResolutionComparisonResult
// + ", location: " + locationComparisonResult);
// }
return aggregatedComparisonResult;
};
/**
* Compares two Strings and if they are equal then returns a ComparisonResult with zero penalty points assigned,
* otherwise returns a ComparisonResult with the given number of penalty points assigned.
*
* @param currentValue The current value.
* @param storedValue The stored value.
* @param penaltyPoints The number of penalty points.
* @return A ComparisonResult.
*/
DevicePrintComparator.prototype.compareStrings = function(currentValue, storedValue, penaltyPoints) {
if (penaltyPoints === 0) {
return ComparisonResult.ZERO_PENALTY_POINTS;
}
if (storedValue !== null) {
return new ComparisonResult(penaltyPoints);
}
} else if (currentValue !== null) {
return new ComparisonResult(true);
}
return ComparisonResult.ZERO_PENALTY_POINTS;
};
/**
* Compares two User Agent Strings and if they are equal then returns a ComparisonResult with zero penalty
* points assigned, otherwise returns a ComparisonResult with the given number of penalty points assigned.
*
* @param currentValue The current value.
* @param storedValue The stored value.
* @param penaltyPoints The number of penalty points.
* @param ignoreVersion If the version numbers in the User Agent Strings should be ignore in the comparison.
* @return A ComparisonResult.
*/
DevicePrintComparator.prototype.compareUserAgent = function(currentValue, storedValue, penaltyPoints, ignoreVersion) {
if (ignoreVersion) {
// remove version number
}
};
/**
* Compares two Screen resolution Strings and if they are equal then returns a ComparisonResult with zero penalty
* points assigned, otherwise returns a ComparisonResult with the given number of penalty points assigned.
*
* @param currentWidth The current width.
* @param currentHeight The current height.
* @param storedWidth The stored width.
* @param storedHeight The stored height.
* @param penaltyPoints The number of penalty points.
* @return A ComparisonResult.
*/
DevicePrintComparator.prototype.compareScreenResolution = function(currentWidth, currentHeight, storedWidth, storedHeight, penaltyPoints) {
return new ComparisonResult(widthComparisonResult.additionalInfoInCurrentValue || heightComparisonResult.additionalInfoInCurrentValue);
} else {
return new ComparisonResult(penaltyPoints);
}
};
function UserProfilesDao() {
}
/**
* Gets the list of device print profiles that have been saved for the user.
*
* @returns a JavaScript array of JSON strings.
*/
};
/**
* Sets the list of device print profiles for the user.
* NOTE: will completely replace the current value.
*
* @param profiles expected to be a JavaScript array of JSON strings.
*/
};
/**
* This class exposes services to parse Device Print information from the client, find matches against stored user
* profiles, and update the user profiles in LDAP.
*
* @param config JSON object storing configuration attributes.
* @param userProfilesDao An instance of the UserProfilesDao.
* @param extractorFactory An instance of the DevicePrintExtractorFactory.
* @param devicePrintComparator An instance of the DevicePrintComparator.
*/
this.userProfilesDao = userProfilesDao;
this.extractorFactory = extractorFactory;
}
if (this.config.requiredAttributes[requiredAttribute] && devicePrint[requiredAttribute] === undefined) {
return false;
}
}
}
return true;
};
if (selectedProfile != null) {
selectedProfile.lastSelectedDate = new Date();
return true;
}
return false;
};
/**
* Uses the given Device Print information to find the best matching stored Device Print information from stored
* User Profiles. It uses the penalty points set in the authentication module settings to determine whether a stored
* Device print matches the given one.
*
* If no match is found null is returned.
*
* @param devicePrint The Device Print to find a match for.
* @return The matching User Profile or null.
*/
var results = [];
var notExpiredProfiles = this.getNotExpiredProfiles();
var userProfile = notExpiredProfiles[i];
var comparisonResult = this.devicePrintComparator.compare(devicePrint, storedDevicePrint, this.config);
});
}
return null;
}
});
var selectedProfile = null;
}
return selectedProfile;
}
/**
* Gets the list of valid, non-expired User's profiles.
*
* @return The valid User profiles.
*/
var results = [];
if (!this.isExpiredProfile(profiles[i])) {
}
}
return results;
};
/**
* Determines whether a User's profile has expired due to it not being accessed within the profile expiration
* authentication module setting.
*
* @param userProfile The User profile to check if has expired.
* @return If the user profile has expired or not.
*/
var expirationDate = new Date();
return lastSelectedDate < expirationDate;
};
// ============================================================================================================
// TESTS
// @BeforeMethod
// public void setUpMethod() {
// devicePrintAuthenticationConfig = mock(DevicePrintAuthenticationConfig.class);
// userProfilesDao = mock(UserProfilesDao.class);
// extractorFactory = mock(DevicePrintExtractorFactory.class);
// devicePrintComparator = mock(DevicePrintComparator.class);
// given(devicePrintAuthenticationConfig.getInt(
// DevicePrintAuthenticationConfig.PROFILE_EXPIRATION_DAYS)).willReturn(30);
// given(devicePrintAuthenticationConfig.getInt(
// DevicePrintAuthenticationConfig.MAX_STORED_PROFILES)).willReturn(2);
// devicePrintService = new DevicePrintService(devicePrintAuthenticationConfig, userProfilesDao, extractorFactory,
// devicePrintComparator);
// }
// @Test
// public void shouldCheckHasRequiredAttributes() {
// //Given
// DevicePrint devicePrint = mock(DevicePrint.class);
// //When
// devicePrintService.hasRequiredAttributes(devicePrint);
// //Then
// verify(devicePrintAuthenticationConfig).hasRequiredAttributes(devicePrint);
// }
// @Test
// public void shouldGetCurrentDevicePrint() {
// //Given
// HttpServletRequest request = mock(HttpServletRequest.class);
// Set<Extractor> extractors = new HashSet<Extractor>();
// Extractor extractorOne = mock(Extractor.class);
// Extractor extractorTwo = mock(Extractor.class);
// given(extractorFactory.getExtractors()).willReturn(extractors);
// extractors.add(extractorOne);
// extractors.add(extractorTwo);
// //When
// DevicePrint devicePrint = devicePrintService.getDevicePrint(request);
// //Then
// verify(extractorOne).extractData(Matchers.<DevicePrint>anyObject(), eq(request));
// verify(extractorTwo).extractData(Matchers.<DevicePrint>anyObject(), eq(request));
// assertNotNull(devicePrint);
// }
// XXX: Flaky test: replace hard-coded string with getDate()
function testIsExpired() {
// Given
var config = {
};
// When
// Then
}
// TODO: handle bad input? in Java?
// XXX: Flaky test
function testGetNotExpiredProfiles() {
// Given
var config = {
};
var mockUserProfilesDao = {
getProfiles: function() { return ldapDevicePrintProfiles; }
};
// When
// Then
}
function shouldGetBestMatchingUserProfileWithNoStoredProfiles() {
//Given
var config = {};
var devicePrint = {}; // mock(DevicePrint.class);
var mockUserProfilesDao = {
getProfiles: function() { return []; }
};
//When
//Then
assertEquals(null, selectedUserProfile);
}
function shouldGetBestMatchingUserProfile() {
var result = new Date();
return result;
}
//Given
var mockConfig = {
};
var devicePrint = {}; // mock(DevicePrint.class);
var userProfileOneDevicePrint = {};
var userProfileTwoDevicePrint = {};
var userProfileThreeDevicePrint = {};
var userProfileOne = {
};
var userProfileTwo = {
};
var userProfileThree = {
};
var mockUserProfilesDao = {
getProfiles: function() {
}
};
var mockDevicePrintComparator = {
if (storedDevicePrint === userProfileOneDevicePrint) {
return userProfileOneResult;
} else if (storedDevicePrint === userProfileThreeDevicePrint) {
return userProfileThreeResult;
}
}
};
var devicePrintService = new DevicePrintService(mockConfig, mockUserProfilesDao, null, mockDevicePrintComparator);
//When
//Then
}
// private Date getDate(int daysAgo) {
// Calendar calendar = Calendar.getInstance();
// calendar.add(Calendar.DAY_OF_YEAR, -daysAgo);
// return calendar.getTime();
// }
// @Test
// public void shouldCreateNewProfile() throws NotUniqueUserProfileException {
// //Given
// DevicePrint devicePrint = mock(DevicePrint.class);
// given(userProfilesDao.getProfiles()).willReturn(new ArrayList<UserProfile>());
// //When
// devicePrintService.createNewProfile(devicePrint);
// //Then
// verify(userProfilesDao).removeProfile(anyString());
// ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
// verify(userProfilesDao).addProfile(userProfileCaptor.capture());
// UserProfile userProfile = userProfileCaptor.getValue();
// assertEquals(userProfile.getDevicePrint(), devicePrint);
// verify(userProfilesDao).saveProfiles();
// }
// @Test
// public void shouldCreateNewProfileAndDeleteOlderOnes() throws NotUniqueUserProfileException {
// //Given
// DevicePrint devicePrint = mock(DevicePrint.class);
// List<UserProfile> userProfiles = spy(new ArrayList<UserProfile>());
// UserProfile userProfileOne = mock(UserProfile.class);
// UserProfile userProfileTwo = mock(UserProfile.class);
// UserProfile userProfileThree = mock(UserProfile.class);
// userProfiles.add(userProfileOne);
// userProfiles.add(userProfileTwo);
// userProfiles.add(userProfileThree);
// given(userProfilesDao.getProfiles()).willReturn(userProfiles);
// given(userProfileOne.getLastSelectedDate()).willReturn(getDate(10));
// given(userProfileTwo.getLastSelectedDate()).willReturn(getDate(31));
// given(userProfileThree.getLastSelectedDate()).willReturn(getDate(30));
// //When
// devicePrintService.createNewProfile(devicePrint);
// //Then
// verify(userProfilesDao).removeProfile(anyString());
// verify(userProfiles).remove(userProfileTwo);
// verify(userProfiles).remove(userProfileThree);
// ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
// verify(userProfilesDao).addProfile(userProfileCaptor.capture());
// UserProfile userProfile = userProfileCaptor.getValue();
// assertEquals(userProfile.getDevicePrint(), devicePrint);
// verify(userProfilesDao).saveProfiles();
// }
// @Test
// public void shouldUpdateProfile() throws NotUniqueUserProfileException {
// //Given
// UserProfile userProfile = mock(UserProfile.class);
// DevicePrint devicePrint = mock(DevicePrint.class);
// given(userProfile.getUuid()).willReturn("USER_PROFILE_UUID");
// given(userProfilesDao.getProfiles()).willReturn(new ArrayList<UserProfile>());
// //When
// devicePrintService.updateProfile(userProfile, devicePrint);
// //Then
// verify(userProfile).setSelectionCounter(anyLong());
// verify(userProfile).setLastSelectedDate(Matchers.<Date>anyObject());
// verify(userProfile).setDevicePrint(devicePrint);
// verify(userProfilesDao).removeProfile(anyString());
// verify(userProfilesDao).addProfile(userProfile);
// verify(userProfilesDao).saveProfiles();
// }
function shouldCompareDevicePrints() {
//Given
var currentDevicePrint = {
"screen":{
"screenWidth": "SCREEN_WIDTH", // XXX: integer?
"screenHeight": "SCREEN_HEIGHT", // XXX: integer?
"screenColourDepth": "SCREEN_COLOUR_DEPTH" // XXX: integer?
},
"timezone":{
"timezone": "TIMEZONE" // XXX: integer?
},
"plugins":{
"installedPlugins":"INSTALLED_PLUGINS"
},
"fonts":{
"installedFonts":"INSTALLED_FONTS"
},
"userAgent":"USER_AGENT",
"geolocation":{
"longitude": 2.0,
"latitude": 3.0
}
};
var storedDevicePrint = {
"screen":{
"screenWidth": "SCREEN_WIDTH",
"screenHeight": "SCREEN_HEIGHT",
"screenColourDepth": "SCREEN_COLOUR_DEPTH"
},
"timezone":{
"timezone": "TIMEZONE"
},
"plugins":{
"installedPlugins":"INSTALLED_PLUGINS"
},
"fonts":{
"installedFonts":"INSTALLED_FONTS"
},
"userAgent":"USER_AGENT",
"geolocation":{
"longitude": 2.0,
"latitude": 3.0
}
};
var config = {
fonts: true,
plugins: true,
screen: true,
geolocation: false,
timezone: true
},
userAgentPenaltyPoints: 100,
ignoreVersionInUserAgent: false,
timezonePenaltyPoints: 100,
locationAllowedRange: 100,
locationPenaltyPoints: 100,
};
return cr;
},
};
var mockColocationComparator = {
return cr;
},
};
var devicePrintComparator = new DevicePrintComparator(mockMultiValueAttributeComparator, mockColocationComparator);
//When
var comparisonResult = devicePrintComparator.compare(currentDevicePrint, storedDevicePrint, config);
//Then
}
function shouldCompareWithNoPenaltyPoints() {
//Given
var devicePrintComparator = new DevicePrintComparator(null, null);
//When
//Then
}
//Given
var devicePrintComparator = new DevicePrintComparator(null, null);
//When
//Then
}
//Given
var devicePrintComparator = new DevicePrintComparator(null, null);
//When
//Then
}
//Given
var devicePrintComparator = new DevicePrintComparator(null, null);
//When
//Then
}
function shouldCompareUserAgentsIgnoringVersionNumbers() {
//Given
var devicePrintComparator = new DevicePrintComparator(null, null);
//When
"1234USER_.567890AGENT_", 10, true);
//Then
}
function shouldCompareScreenResolutionWhenNotTheSame() {
//Given
var devicePrintComparator = new DevicePrintComparator(null, null);
//When
"CURRENT_HEIGHT", "STORED_WIDTH", "STORED_HEIGHT", 10);
//Then
}
//Given
var multiValueAttrComparator = new MultiValueAttributeComparator();
var currentValue = "";
var storedValue = null;
//When
//Then
}
function shouldCompareMultiValueStringsWhenBothAreEmpty() {
//Given
var multiValueAttrComparator = new MultiValueAttributeComparator();
var currentValue = "";
var storedValue = "";
//When
//Then
}
function shouldCompareMultiValueStringsWhenBothAreEqual() {
//Given
var multiValueAttrComparator = new MultiValueAttributeComparator();
var currentValue = "VALUE_A; VALUE_B; VALUE_C; VALUE_D; VALUE_E";
var storedValue = "VALUE_A; VALUE_B; VALUE_C; VALUE_D; VALUE_E";
//When
//Then
}
//Given
var multiValueAttrComparator = new MultiValueAttributeComparator();
var currentValue = "VALUE_AA; VALUE_B; VALUE_C; VALUE_D; VALUE_E";
var storedValue = "VALUE_B; VALUE_C; VALUE_D; VALUE_E";
//When
//Then
}
//Given
var multiValueAttrComparator = new MultiValueAttributeComparator();
var currentValue = "VALUE_AA; VALUE_BB; VALUE_C; VALUE_D; VALUE_E";
var storedValue = "VALUE_B; VALUE_C; VALUE_D; VALUE_E";
//When
//Then
}
//Given
var multiValueAttrComparator = new MultiValueAttributeComparator();
var currentValue = "VALUE_AA; VALUE_B; VALUE_C; VALUE_D; VALUE_E";
var storedValue = "VALUE_B; VALUE_C; VALUE_D; VALUE_E";
//When
//Then
}
//Given
var multiValueAttrComparator = new MultiValueAttributeComparator();
var currentValue = "VALUE_AA; VALUE_BB; VALUE_C; VALUE_D; VALUE_E";
var storedValue = "VALUE_B; VALUE_C; VALUE_D; VALUE_E";
//When
//Then
}
function shouldCompareLocationWhenBothXsAreNull() {
//Given
var colocationComparator = new ColocationComparator();
//When
//Then
}
function shouldCompareLocationWhenBothYsAreNull() {
//Given
var colocationComparator = new ColocationComparator();
//When
//Then
}
function shouldCompareLocationWhenCurrentXIsNull() {
//Given
//When
//Then
}
function shouldCompareLocationWhenCurrentYIsNull() {
//Given
var colocationComparator = new ColocationComparator();
//When
//Then
}
function shouldCompareLocationWhenStoredXIsNull() {
//Given
var colocationComparator = new ColocationComparator();
//When
//Then
}
function shouldCompareLocationWhenStoredYIsNull() {
//Given
var colocationComparator = new ColocationComparator();
//When
//Then
}
function shouldCompareLocationsThatAreEqual() {
//Given
var colocationComparator = new ColocationComparator();
//When
//Then
}
function shouldCompareLocationsThatAreWithinTolerableRange() {
//Given
var colocationComparator = new ColocationComparator();
//When
//Then
}
function shouldCompareLocationsThatAreOutsideTolerableRange() {
//Given
var colocationComparator = new ColocationComparator();
//When
//Then
}
function shouldCreateComparisonResultWithZeroPenaltyPoints() {
var comparisonResult = new ComparisonResult();
}
}
}
function shouldCreateComparisonResultWithPenaltyPoints() {
}
function shouldCreateComparisonResultWithAdditionalInfo() {
var comparisonResult = new ComparisonResult(true);
}
function shouldAddComparisonResult() {
// Given
//When
//Then
}
function shouldGetComparisonResultSuccessful() {
//Given
//When
//Then
}
function shouldGetComparisonResultUnsuccessful() {
//Given
//When
//Then
}
function shouldCompareComparisonResultsEqually() {
//Given
//When
//Then
}
function shouldCompareComparisonResultsEqually() {
//Given
//When
//Then
}
function shouldCompareComparisonResultsNotEqualPenaltyPoints() {
//Given
//When
//Then
}
//Given
//When
//Then
}
function shouldCompareComparisonResultsWithNull() {
//Given
anotherComparisonResult = null;
//When
//Then
}