Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Oct 5, 2018
1 parent d578ed6 commit a9f5cf9
Show file tree
Hide file tree
Showing 4 changed files with 506 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
package edu.internet2.tier.shibboleth.admin.ui.controller

import groovy.json.JsonSlurper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.core.io.ResourceLoader
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

import javax.annotation.PostConstruct

/**
* Controller implementing REST resource responsible for exposing structure definition for metadata sources user
* interface in terms of JSON schema.
*
* @author Dmitriy Kopylenko
*/
@RestController('/api/ui/metadataSources')
@RestController('/api/ui/MetadataSources')
@ConfigurationProperties('shibui')
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'
String metadataSourcesUiSchemaLocation //= 'classpath:metadata-sources-ui-schema.json'

URL jsonSchemaUrl

MetadataSourcesUiDefinitionController(ResourceLoader resourceLoader) {
jsonSchemaUrl = resourceLoader.getResource(metadataSourcesUiSchemaLocation).getURL()
}
@Autowired
ResourceLoader resourceLoader

@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)
}

@PostConstruct
def init() {
jsonSchemaUrl = this.resourceLoader.getResource(this.metadataSourcesUiSchemaLocation).getURL()
}
}
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ spring.profiles.active=default

#shibui.default-password=

shibui.metadata-sources-ui-schema-location=classpath:metadata-sources-ui-schema-location.json
shibui.metadata-sources-ui-schema-location=classpath:metadata-sources-ui-schema.json

#Actuator endpoints (info)
# Un-comment to get full git details exposed like author, abbreviated SHA-1, commit message
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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

/**
* @author Dmitriy Kopylenko
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("no-auth")
class MetadataSourcesUiDefinitionControllerIntegrationTests extends Specification {

@Autowired
private TestRestTemplate restTemplate

@Autowired
ConfigurableEnvironment environment

@Autowired
MetadataSourcesUiDefinitionController controllerUnderTest

static RESOURCE_URI = '/api/ui/MetadataSources'

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"
result.statusCodeValue == 200
result.body.properties.entityId.title == 'label.entity-id'
}

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

then: "Request results in HTTP 400"
result.statusCodeValue == 200
}

private configureMalformedJsonInput() {
controllerUnderTest.metadataSourcesUiSchemaLocation = 'classpath:metadata-sources-ui-schema_BAD.json'
controllerUnderTest.init()
}
}
Loading

0 comments on commit a9f5cf9

Please sign in to comment.