Skip to content

Commit

Permalink
[SHIBUI-479]
Browse files Browse the repository at this point in the history
Added a small unit test for checking EntityDescriptor version.
Added getters for the version onto the representation for a filter and entity descriptor.
  • Loading branch information
Bill Smith committed May 10, 2018
1 parent 00dbd9c commit 097fa15
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public void setAttributeRelease(List<String> attributeRelease) {
this.attributeRelease = attributeRelease;
}

public int getVersion() {
return version;
}

public void setVersion(int version) {
this.version = version;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public void setModifiedDate(LocalDateTime modifiedDate) {
this.modifiedDate = modifiedDate;
}

public int getVersion() {
return version;
}

public void setVersion(int version) {
this.version = version;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package edu.internet2.tier.shibboleth.admin.ui.service
import com.fasterxml.jackson.databind.ObjectMapper
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.*
import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects
import edu.internet2.tier.shibboleth.admin.ui.util.TestObjectGenerator
import org.springframework.boot.test.json.JacksonTester
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.builder.Input
Expand All @@ -11,6 +12,9 @@ import org.xmlunit.diff.ElementSelectors
import spock.lang.Specification

class JPAEntityDescriptorServiceImplTests extends Specification {

def testObjectGenerator

OpenSamlObjects openSamlObjects = new OpenSamlObjects().with {
init()
it
Expand All @@ -22,6 +26,7 @@ class JPAEntityDescriptorServiceImplTests extends Specification {

def setup() {
JacksonTester.initFields(this, new ObjectMapper())
testObjectGenerator = new TestObjectGenerator()
}


Expand Down Expand Up @@ -589,4 +594,17 @@ class JPAEntityDescriptorServiceImplTests extends Specification {
assert descriptor.getSPSSODescriptor('').getKeyDescriptors().size() == 1
assert descriptor.getSPSSODescriptor('').getKeyDescriptors()[0].getUse() == null
}

def "createRepresentationFromDescriptor creates a representation containing a version that is a hash of the original object"() {
given:
def entityDescriptor = testObjectGenerator.buildEntityDescriptor()
def expectedVersion = entityDescriptor.hashCode()

when:
def representation = service.createRepresentationFromDescriptor(entityDescriptor)

then:
def actualVersion = representation.version
expectedVersion == actualVersion
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package edu.internet2.tier.shibboleth.admin.ui.util

import edu.internet2.tier.shibboleth.admin.ui.domain.AdditionalMetadataLocation
import edu.internet2.tier.shibboleth.admin.ui.domain.Attribute
import edu.internet2.tier.shibboleth.admin.ui.domain.ContactPerson
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityAttributesFilter
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityAttributesFilterTarget
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor
import edu.internet2.tier.shibboleth.admin.ui.domain.LocalizedName
import edu.internet2.tier.shibboleth.admin.ui.domain.OrganizationDisplayName
import edu.internet2.tier.shibboleth.admin.ui.domain.OrganizationName
import edu.internet2.tier.shibboleth.admin.ui.domain.OrganizationURL
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.FilterRepresentation
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.FilterTargetRepresentation
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.RelyingPartyOverridesRepresentation
import edu.internet2.tier.shibboleth.admin.util.AttributeUtility
import edu.internet2.tier.shibboleth.admin.util.MDDCConstants
import org.opensaml.saml.saml2.metadata.Organization
import org.w3c.dom.Element

import java.time.LocalDateTime

/**
* @author Bill Smith (wsmith@unicon.net)
Expand Down Expand Up @@ -146,7 +147,7 @@ class TestObjectGenerator {
entityDescriptor.setServiceEnabled(generator.randomBoolean())
entityDescriptor.setResourceId(generator.randomId())
entityDescriptor.setOrganization(buildOrganization())
//TODO Finish adding the rest of the setters here.
entityDescriptor.addContactPerson(buildContactPerson())

//TODO: Implement these if we ever start setting them elsewhere
//entityDescriptor.setRoleDescriptors(buildRoleDescriptors())
Expand All @@ -165,8 +166,50 @@ class TestObjectGenerator {
Organization buildOrganization() {
Organization organization = new edu.internet2.tier.shibboleth.admin.ui.domain.Organization()

//TODO Fill this out based on what gets used in the Organization domain object
organization.setNamespaceURI(generator.randomString(20))
organization.setElementLocalName(generator.randomString(20))
organization.setNamespacePrefix(generator.randomString(5))

organization.setOrganizationNames(buildListOfTypeWithValues(OrganizationName.class, generator.randomInt(1, 10)))
organization.setOrganizationDisplayNames(buildListOfTypeWithValues(OrganizationDisplayName.class, generator.randomInt(1, 10)))
organization.setOrganizationURLs(buildListOfTypeWithValues(OrganizationURL.class, generator.randomInt(1, 10)))

//TODO: Implement these if we ever start setting them elsewhere
//organization.setExtensions(buildExtensions())

return organization
}

ContactPerson buildContactPerson() {
ContactPerson contactPerson = new ContactPerson();

contactPerson.setNamespaceURI(generator.randomString(20))
contactPerson.setElementLocalName(generator.randomString(20))
contactPerson.setNamespacePrefix(generator.randomString(5))

return contactPerson
}

/**
* This method takes a type and a size and builds a List of that size containing objects of that type. This is
* intended to be used with things that extend LocalizedName such as {@link OrganizationName}, {@link OrganizationDisplayName},
* or with {@link OrganizationURL}s (really, a class that has a setValue() method).
*
* @param type the type of list to generate
* @param listSize the number of instances of that type to generate and add to the list
* @return a list of the specified size containing objects of the specified type
*/
private <T> List<T> buildListOfTypeWithValues(Class<T> type, int listSize) {
List<T> list = []
listSize.times {
T newItemOfType = type.newInstance()
if (newItemOfType instanceof LocalizedName) {
newItemOfType.value = generator.randomString(10)
} else if (newItemOfType instanceof OrganizationURL) {
newItemOfType.value = generator.randomString(10)
}
list.add(newItemOfType)
}
return list
}
}

0 comments on commit 097fa15

Please sign in to comment.