Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Oct 9, 2018
1 parent b700f07 commit 3e95694
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.controller

import org.springframework.beans.factory.BeanInitializationException
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.client.TestRestTemplate
Expand All @@ -23,7 +24,6 @@ class MetadataSourcesUiDefinitionControllerIntegrationTests extends Specificatio

def "GET Metadata Sources UI definition schema"() {
when: 'GET request is made for metadata source UI definition schema'

def result = this.restTemplate.getForEntity(RESOURCE_URI, Object)

then: "Request completed successfully"
Expand All @@ -33,7 +33,7 @@ class MetadataSourcesUiDefinitionControllerIntegrationTests extends Specificatio

def "GET Malformed Metadata Sources UI definition schema"() {
when: 'GET request is made for malformed metadata source UI definition schema'
configureMalformedJsonInput()
configureMalformedJsonInput(simulateApplicationStartup { false })
def result = this.restTemplate.getForEntity(RESOURCE_URI, Object)

then: "Request results in HTTP 500"
Expand All @@ -42,8 +42,32 @@ class MetadataSourcesUiDefinitionControllerIntegrationTests extends Specificatio
result.body.sourceUiSchemaDefinitionFile
}

private configureMalformedJsonInput() {
def "Malformed Metadata Sources UI definition schema is detected during application start up"() {
when: 'Application is starting up and malformed JSON schema is detected'
configureMalformedJsonInput(simulateApplicationStartup { true })

then:
def ex = thrown(BeanInitializationException)
ex.message.contains('An error is detected during JSON parsing =>')
ex.message.contains('Offending resource =>')

}

private configureMalformedJsonInput(boolean simulateApplicationStartup) {
controllerUnderTest.metadataSourcesUiSchemaLocation = 'classpath:metadata-sources-ui-schema_MALFORMED.json'
controllerUnderTest.init()
try {
controllerUnderTest.init()
}
catch (Exception e) {
if (simulateApplicationStartup) {
throw e
}
}

}

//Just for the nicer, readable, DSL-like
private static boolean simulateApplicationStartup(Closure booleanFlagSupplier) {
booleanFlagSupplier()
}
}

0 comments on commit 3e95694

Please sign in to comment.