Skip to content

Commit

Permalink
#2490: fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-may committed Jun 19, 2024
1 parent ef8c0b5 commit 9d942f0
Showing 1 changed file with 13 additions and 70 deletions.
83 changes: 13 additions & 70 deletions service/src/test/java/skills/intTests/CachingSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package skills.intTests

import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.io.ResourceLoader
import org.springframework.core.io.support.ResourcePatternUtils
import org.springframework.http.ResponseEntity
import skills.intTests.utils.DefaultIntSpec

@Slf4j
class CachingSpec extends DefaultIntSpec {

@Autowired
Expand Down Expand Up @@ -83,81 +85,22 @@ class CachingSpec extends DefaultIntSpec {
def "assets should be cached"() {
when:
int count = 0
getFileNamesFromClasspath("/public/assets/**").each {
println it
ResponseEntity<String> responseEntity = skillsService.wsHelper.rawGet("/assets/${it}", [:])
assert responseEntity.statusCode.is2xxSuccessful()
assert responseEntity.headers.getCacheControl() == "max-age=${defaultCacheAge}, must-revalidate, private"
count++
}
List<String> ignore = ["dashboard-prime"]
getFileNamesFromClasspath("/public/assets/**")
.findAll { !ignore.contains(it) }
.each {
String endpoint = "/assets/${it}".toString()
log.info("Checking endpoint: [${endpoint}]")
ResponseEntity<String> responseEntity = skillsService.wsHelper.rawGet(endpoint, [:])
assert responseEntity.statusCode.is2xxSuccessful(), "Failed for [${endpoint}] endpoint"
assert responseEntity.headers.getCacheControl() == "max-age=${defaultCacheAge}, must-revalidate, private", "Failed for [${endpoint}] endpoint"
count++
}

then:
count > 0
}

// TODO: add back
// def "clientPortal index page should not be cached"() {
// when:
// ResponseEntity<String> responseEntity = skillsService.wsHelper.rawGet("assets/clientPortal/index.html", [:])
//
// then:
// responseEntity.statusCode.is2xxSuccessful()
// responseEntity.headers.getCacheControl() == "no-store"
// }
//
// def "clientPortal js resources should be cached"() {
// when:
//
// getFileNamesFromClasspath("/public/assets/clientPortal/js/**").each {
// ResponseEntity<String> responseEntity = skillsService.wsHelper.rawGet("/assets/clientPortal/js/${it}", [:])
// assert responseEntity.statusCode.is2xxSuccessful()
// assert responseEntity.headers.getCacheControl() == "max-age=7776000, must-revalidate, private"
// }
//
// then:
// true
// }
//
// def "clientPortal img resources should be cached"() {
// when:
//
// getFileNamesFromClasspath("/public/assets/clientPortal/img/**").each {
// ResponseEntity<String> responseEntity = skillsService.wsHelper.rawGet("/assets/clientPortal/img/${it}", [:])
// assert responseEntity.statusCode.is2xxSuccessful()
// assert responseEntity.headers.getCacheControl() == "max-age=1209600, must-revalidate, private"
// }
//
// then:
// true
// }
//
// def "clientPortal fonts resources should be cached"() {
// when:
//
// getFileNamesFromClasspath("/public/assets/clientPortal/fonts/**").each {
// ResponseEntity<String> responseEntity = skillsService.wsHelper.rawGet("/assets/clientPortal/fonts/${it}", [:])
// assert responseEntity.statusCode.is2xxSuccessful()
// assert responseEntity.headers.getCacheControl() == "max-age=1209600, must-revalidate, private"
// }
//
// then:
// true
// }
//
// def "clientPortal css resources should be cached"() {
// when:
//
// getFileNamesFromClasspath("/public/assets/clientPortal/css/**").each {
// ResponseEntity<String> responseEntity = skillsService.wsHelper.rawGet("/assets/clientPortal/css/${it}", [:])
// assert responseEntity.statusCode.is2xxSuccessful()
// assert responseEntity.headers.getCacheControl() == "max-age=7776000, must-revalidate, private"
// }
//
// then:
// true
// }


private getFileNamesFromClasspath(String classpathPath) {
return ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:${classpathPath}").collect {
it.filename
Expand Down

0 comments on commit 9d942f0

Please sign in to comment.