Skip to content

Commit

Permalink
WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Oct 8, 2018
1 parent 12a91ed commit 4758298
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.controller

import groovy.json.JsonSlurper
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.core.io.ResourceLoader
Expand All @@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RestController

import javax.annotation.PostConstruct

import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR

/**
* Controller implementing REST resource responsible for exposing structure definition for metadata sources user
* interface in terms of JSON schema.
Expand All @@ -21,19 +23,28 @@ import javax.annotation.PostConstruct
class MetadataSourcesUiDefinitionController {

//Configured via @ConfigurationProperties with 'shibui.metadata-sources-ui-schema-location' property and default
//value set here if that property is not set
String metadataSourcesUiSchemaLocation //= 'classpath:metadata-sources-ui-schema.json'
//value set here if that property is not explicitly set in application.properties
String metadataSourcesUiSchemaLocation = 'classpath:metadata-sources-ui-schema.json'

URL jsonSchemaUrl

@Autowired
ResourceLoader resourceLoader

@Autowired
ObjectMapper jacksonObjectMapper

@GetMapping
ResponseEntity<?> getUiDefinitionJsonSchema() {
//JsonSlurper is not threadsafe, but cheap to init. New instance per-thread is the canonical usage
def json = new JsonSlurper().parse(this.jsonSchemaUrl)
ResponseEntity.ok(json)
try {
def parsedJson = jacksonObjectMapper.readValue(this.jsonSchemaUrl, Map)
return ResponseEntity.ok(parsedJson)
}
catch (Exception e) {
return ResponseEntity.status(INTERNAL_SERVER_ERROR)
.body([jsonParseError : e.getMessage(),
sourceUiSchemaDefinitionFile: this.jsonSchemaUrl])
}
}

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package edu.internet2.tier.shibboleth.admin.ui.controller
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.core.env.ConfigurableEnvironment
import org.springframework.test.context.ActiveProfiles
import spock.lang.Specification

Expand Down Expand Up @@ -37,12 +36,14 @@ class MetadataSourcesUiDefinitionControllerIntegrationTests extends Specificatio
configureMalformedJsonInput()
def result = this.restTemplate.getForEntity(RESOURCE_URI, Object)

then: "Request results in HTTP 400"
result.statusCodeValue == 200
then: "Request results in HTTP 500"
result.statusCodeValue == 500
result.body.jsonParseError
result.body.sourceUiSchemaDefinitionFile
}

private configureMalformedJsonInput() {
controllerUnderTest.metadataSourcesUiSchemaLocation = 'classpath:metadata-sources-ui-schema_BAD.json'
controllerUnderTest.metadataSourcesUiSchemaLocation = 'classpath:metadata-sources-ui-schema_MALFORMED.json'
controllerUnderTest.init()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

"type": "object",
{
"type": "object"
"properties": {
"entityId": {
"title": "label.entity-id",
Expand Down

0 comments on commit 4758298

Please sign in to comment.