Skip to content

Commit

Permalink
[SHIBUI-1058]
Browse files Browse the repository at this point in the history
WIP
Added JsonAssert. Updated test to use it.
  • Loading branch information
Bill Smith committed Feb 14, 2019
1 parent 29b5a04 commit 9125590
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ dependencies {

// CSV file support
compile 'com.opencsv:opencsv:4.4'

testCompile 'org.skyscreamer:jsonassert:1.5.0'
}

def generatedSrcDir = new File(buildDir, 'generated/src/main/java')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService
import edu.internet2.tier.shibboleth.admin.ui.util.RandomGenerator
import edu.internet2.tier.shibboleth.admin.ui.util.TestObjectGenerator
import edu.internet2.tier.shibboleth.admin.util.AttributeUtility
import groovy.json.JsonOutput
import org.skyscreamer.jsonassert.JSONAssert
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.json.JacksonTester
Expand Down Expand Up @@ -56,6 +58,8 @@ class JPAEntityDescriptorServiceImplTests extends Specification {

JacksonTester<EntityDescriptorRepresentation> jacksonTester

ObjectMapper mapper

RandomGenerator generator

@Autowired
Expand All @@ -67,7 +71,8 @@ class JPAEntityDescriptorServiceImplTests extends Specification {
def setup() {
service = new JPAEntityDescriptorServiceImpl(openSamlObjects,
new JPAEntityServiceImpl(openSamlObjects, new AttributeUtility(openSamlObjects), customPropertiesConfiguration), new UserService(roleRepository, userRepository))
JacksonTester.initFields(this, new ObjectMapper())
mapper = new ObjectMapper()
JacksonTester.initFields(this, mapper)
generator = new RandomGenerator()
testObjectGenerator = new TestObjectGenerator()
}
Expand Down Expand Up @@ -765,16 +770,20 @@ class JPAEntityDescriptorServiceImplTests extends Specification {
testRunIndex << (1..5)
}

def "updateDescriptorFromRepresentation throws expected exception"() {
def "updateDescriptorFromRepresentation updates descriptor properly"() {
given:
def randomEntityDescriptor = generateRandomEntityDescriptor()
def entityDescriptorRepresentation = service.createRepresentationFromDescriptor(randomEntityDescriptor)
def updatedEntityDescriptor = generateRandomEntityDescriptor()
//TODO: copy values we don't care about asserting (id, entity id, ...)
def updatedEntityDescriptorRepresentation = service.createRepresentationFromDescriptor(updatedEntityDescriptor)

when:
service.updateDescriptorFromRepresentation(randomEntityDescriptor, entityDescriptorRepresentation)
service.updateDescriptorFromRepresentation(randomEntityDescriptor, updatedEntityDescriptorRepresentation)

then:
thrown UnsupportedOperationException
def expectedJson = mapper.writeValueAsString(updatedEntityDescriptorRepresentation)
def actualJson = mapper.writeValueAsString(service.createRepresentationFromDescriptor(randomEntityDescriptor))
JSONAssert.assertEquals(expectedJson, actualJson, false)
}

def "createRepresentationFromDescriptor creates a representation containing a version that is a hash of the original object"() {
Expand Down Expand Up @@ -850,6 +859,9 @@ class JPAEntityDescriptorServiceImplTests extends Specification {
ed.setServiceProviderName(generator.randomString(10))
ed.setServiceEnabled(generator.randomBoolean())
ed.setResourceId(generator.randomId())
ed.setElementLocalName(generator.randomString(10))

//TODO: Finish fleshing out this thing

return ed
}
Expand Down

0 comments on commit 9125590

Please sign in to comment.