16
16
package org .labkey .test .tests ;
17
17
18
18
import org .apache .commons .lang3 .StringUtils ;
19
- import org .apache .commons .text .similarity .LevenshteinDistance ;
20
19
import org .apache .hc .core5 .http .HttpStatus ;
20
+ import org .assertj .core .api .Assertions ;
21
21
import org .intellij .lang .annotations .Language ;
22
22
import org .jetbrains .annotations .Nullable ;
23
23
import org .junit .Assert ;
62
62
import org .labkey .test .util .Maps ;
63
63
import org .labkey .test .util .PortalHelper ;
64
64
import org .labkey .test .util .RReportHelper ;
65
+ import org .labkey .test .util .SimpleHttpRequest ;
65
66
import org .labkey .test .util .TestLogger ;
66
67
import org .labkey .test .util .WikiHelper ;
67
68
import org .labkey .test .util .ext4cmp .Ext4FieldRef ;
@@ -1125,7 +1126,7 @@ private void doTestQueryViews()
1125
1126
}
1126
1127
1127
1128
@ LogMethod
1128
- private void doTestReports ()
1129
+ private void doTestReports () throws IOException
1129
1130
{
1130
1131
RReportHelper _rReportHelper = new RReportHelper (this );
1131
1132
WikiHelper wikiHelper = new WikiHelper (this );
@@ -1177,7 +1178,7 @@ private void doTestReports()
1177
1178
}
1178
1179
1179
1180
@ LogMethod
1180
- private void doTestReportThumbnails ()
1181
+ private void doTestReportThumbnails () throws IOException
1181
1182
{
1182
1183
goToProjectHome ();
1183
1184
log ("Verify custom module report thumbnail images" );
@@ -1187,14 +1188,13 @@ private void doTestReportThumbnails()
1187
1188
}
1188
1189
1189
1190
@ LogMethod
1190
- private void doTestReportIcon ()
1191
+ private void doTestReportIcon () throws IOException
1191
1192
{
1192
1193
log ("Verify custom module report icon image" );
1193
1194
setFormElement (Locator .xpath ("//table[contains(@class, 'dataset-search')]//input" ), KNITR_PEOPLE );
1194
1195
waitForElementToDisappear (Locator .tag ("tr" ).withClass ("x4-grid-row" ).containing (WANT_TO_BE_COOL ).notHidden ());
1195
1196
1196
1197
File expectedIconFile = TestFileUtils .getSampleData (THUMBNAIL_FOLDER + KNITR_PEOPLE + ICON_FILENAME );
1197
- String expectedIcon = TestFileUtils .getFileContents (expectedIconFile );
1198
1198
1199
1199
WebElement img = waitForElement (Locator .tag ("img" ).withClass ("dataview-icon" ).withoutClass ("x4-tree-icon-parent" ).notHidden ());
1200
1200
String backgroundImage = StringUtils .trimToEmpty (img .getCssValue ("background-image" ));
@@ -1204,12 +1204,10 @@ private void doTestReportIcon()
1204
1204
Assert .fail ("Module report icon style is not as expected: " + img .getDomAttribute ("style" ));
1205
1205
}
1206
1206
String iconUrl = matcher .group (1 );
1207
- String iconData = WebTestHelper . getHttpResponse (iconUrl ).getResponseBody ( );
1207
+ File downloadedIcon = new SimpleHttpRequest (iconUrl ).getResponseAsFile ( TestFileUtils . ensureTestTempFile ( KNITR_PEOPLE + ICON_FILENAME ) );
1208
1208
1209
- int lengthToCompare = 3000 ;
1210
- int diff = LevenshteinDistance .getDefaultInstance ().apply (expectedIcon .substring (0 , lengthToCompare ), iconData .substring (0 , lengthToCompare ));
1211
- assertTrue ("Module report icon is not as expected, diff is " + diff , expectedIcon .equals (iconData ) ||
1212
- diff <= lengthToCompare * 0.03 ); // Might be slightly different due to indentations, etc
1209
+ Assertions .assertThat (downloadedIcon ).as ("Module report icon is not as expected" )
1210
+ .hasSameBinaryContentAs (expectedIconFile );
1213
1211
}
1214
1212
1215
1213
@ LogMethod
@@ -1222,20 +1220,18 @@ private void doTestReportCreatedDate()
1222
1220
}
1223
1221
1224
1222
@ LogMethod
1225
- private void verifyReportThumbnail (@ LoggedParam String reportTitle )
1223
+ private void verifyReportThumbnail (@ LoggedParam String reportTitle ) throws IOException
1226
1224
{
1227
1225
File expectedThumbnailFile = TestFileUtils .getSampleData (THUMBNAIL_FOLDER + reportTitle + THUMBNAIL_FILENAME );
1228
- String expectedThumbnail = TestFileUtils .getFileContents (expectedThumbnailFile );
1229
1226
1230
1227
WebElement reportLink = waitForElement (Locator .xpath ("//a[text()='" + reportTitle + "']" ));
1231
1228
mouseOver (reportLink );
1232
1229
WebElement thumbnail = waitForElement (Locator .xpath ("//div[@class='thumbnail']/img" ).notHidden ());
1233
- String thumbnailData = WebTestHelper .getHttpResponse (thumbnail .getDomProperty ("src" )).getResponseBody ();
1230
+ File downloadedThumbnail = new SimpleHttpRequest (thumbnail .getDomProperty ("src" ))
1231
+ .getResponseAsFile (TestFileUtils .ensureTestTempFile (reportTitle + THUMBNAIL_FILENAME ));
1234
1232
1235
- int lengthToCompare = 5000 ;
1236
- int diff = LevenshteinDistance .getDefaultInstance ().apply (expectedThumbnail .substring (0 , lengthToCompare ), thumbnailData .substring (0 , lengthToCompare ));
1237
- assertTrue ("Module report thumbnail is not as expected, diff is " + diff , expectedThumbnail .equals (thumbnailData ) ||
1238
- diff <= lengthToCompare * 0.03 ); // Might be slightly different due to indentations, etc
1233
+ Assertions .assertThat (downloadedThumbnail ).as ("Module report thumbnail is not as expected" )
1234
+ .hasSameBinaryContentAs (expectedThumbnailFile );
1239
1235
}
1240
1236
1241
1237
@ LogMethod
0 commit comments