-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
506 additions
and
6 deletions.
There are no files selected for viewing
17 changes: 12 additions & 5 deletions
17
...nternet2/tier/shibboleth/admin/ui/controller/MetadataSourcesUiDefinitionController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ibboleth/admin/ui/controller/MetadataSourcesUiDefinitionControllerIntegrationTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
Oops, something went wrong.