Skip to content

Commit

Permalink
WIP5
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Jun 12, 2019
1 parent 23a863d commit 15db654
Show file tree
Hide file tree
Showing 6 changed files with 972 additions and 1 deletion.
26 changes: 26 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ configurations {
integrationTestRuntime {
extendsFrom testRuntime
}
enversTestCompile {
extendsFrom testCompile

}
enversTestRuntime {
extendsFrom testRuntime
}
}

processResources.dependsOn(':ui:npm_run_buildProd')
Expand Down Expand Up @@ -197,6 +204,13 @@ sourceSets {
srcDir 'src/integration/resources'
}
}
enversTest {
groovy {
srcDirs = ['src/enversTest/groovy']
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
}

task integrationTest(type: Test) {
Expand All @@ -210,6 +224,18 @@ task integrationTest(type: Test) {
systemProperties['user.dir'] = workingDir
}

task enversTest(type: Test) {
group = 'verification'
description = 'Run tests pertaing to envers versioning engine'
testClassesDirs = sourceSets.enversTest.output.classesDirs
classpath = sourceSets.enversTest.runtimeClasspath
systemProperties = System.properties
systemProperties['user.dir'] = workingDir
}
test.finalizedBy enversTest



task generateSources {
inputs.dir('src/main/templates')
inputs.files fileTree('src/main/resources') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package edu.internet2.tier.shibboleth.admin.ui.controller

import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityDescriptorRepresentation
import edu.internet2.tier.shibboleth.admin.ui.repository.EntityDescriptorRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.test.context.ActiveProfiles
import spock.lang.Specification

/**
* @author Dmitriy Kopylenko
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles(['no-auth', 'dev'])
class EntityDescriptorControllerVersionEndpointsIntegrationTests extends Specification {

@Autowired
private TestRestTemplate restTemplate

@Autowired
EntityDescriptorRepository entityDescriptorRepository

static BASE_URI = '/api/EntityDescriptor'

static ALL_VERSIONS_URI = "$BASE_URI/%s/Versions"

static SPECIFIC_VERSION_URI = "$BASE_URI/%s/Versions/%s"

def "GET /api/EntityDescriptor/{resourceId}/Versions with non-existent entity descriptor"() {
when:
def result = getAllEntityDescriptorVersions('non-existent-ed-id', String)

then:
result.statusCodeValue == 404
}

def "GET /api/EntityDescriptor{resourceId}/Versions with 1 entity descriptor version"() {
given:
EntityDescriptor ed = new EntityDescriptor(entityID: 'http://test/controller', createdBy: 'anonymousUser')
entityDescriptorRepository.save(ed)

when:
def result = getAllEntityDescriptorVersions(ed.resourceId, List)

then:
result.statusCodeValue == 200
result.body.size == 1
result.body[0].id && result.body[0].creator && result.body[0].date
}

def "GET /api/EntityDescriptor{resourceId}/Versions with 2 entity descriptor versions"() {
given:
EntityDescriptor ed = new EntityDescriptor(entityID: 'http://test/controller', createdBy: 'anonymousUser')
ed = entityDescriptorRepository.save(ed)
//Will created a second version for UPDATE revision
ed.serviceEnabled = true
entityDescriptorRepository.save(ed)

when:
def result = getAllEntityDescriptorVersions(ed.resourceId, List)

then:
result.statusCodeValue == 200
result.body.size == 2
result.body[0].id < result.body[1].id
result.body[0].date < result.body[1].date
}

def "GET /api/EntityDescriptor{resourceId}/Versions/{version} for non existent version"() {
given:
EntityDescriptor ed = new EntityDescriptor(entityID: 'http://test/controller', createdBy: 'anonymousUser')
ed = entityDescriptorRepository.save(ed)

when:
def result = getEntityDescriptorForVersion(ed.resourceId, '1000', EntityDescriptorRepresentation)

then:
result.statusCodeValue == 404
}

def "GET /api/EntityDescriptor{resourceId}/Versions/{version} with 2 entity descriptor versions returns correct ED for specific versions"() {
given:
EntityDescriptor ed = new EntityDescriptor(entityID: 'http://test/controller', createdBy: 'anonymousUser', serviceProviderName: 'SP1')
ed = entityDescriptorRepository.save(ed)
//Will created a second version for UPDATE revision
ed.serviceProviderName = 'SP2'
entityDescriptorRepository.save(ed)

when:
def allVersions = getAllEntityDescriptorVersions(ed.resourceId, List)
def edv1 = getEntityDescriptorForVersion(ed.resourceId, allVersions.body[0].id, EntityDescriptorRepresentation)
def edv2 = getEntityDescriptorForVersion(ed.resourceId, allVersions.body[1].id, EntityDescriptorRepresentation)

then:
edv1.statusCodeValue == 200
edv1.body.serviceProviderName == 'SP1'
edv2.statusCodeValue == 200
edv2.body.serviceProviderName == 'SP2'
}

private getAllEntityDescriptorVersions(String resourceId, responseType) {
this.restTemplate.getForEntity(resourceUriFor(ALL_VERSIONS_URI, resourceId), responseType)
}

private getEntityDescriptorForVersion(String resourceId, String version, responseType) {
this.restTemplate.getForEntity(resourceUriFor(SPECIFIC_VERSION_URI, resourceId, version), responseType)
}

private static resourceUriFor(String uriTemplate, String resourceId, String version) {
String.format(uriTemplate, resourceId, version)
}

private static resourceUriFor(String uriTemplate, String resourceId) {
String.format(uriTemplate, resourceId)
}
}
Loading

0 comments on commit 15db654

Please sign in to comment.