Skip to content

Commit

Permalink
Added tests to check loading integers, booleans and Resource as a str…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
litvinovg committed Mar 12, 2024
1 parent 7f9f29d commit b776311
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import static edu.cornell.mannlib.vitro.testing.ModelUtilitiesTestHelper.objectProperty;
import static edu.cornell.mannlib.vitro.testing.ModelUtilitiesTestHelper.typeStatement;
import static edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoader.toJavaUri;
import static org.apache.jena.datatypes.xsd.XSDDatatype.XSDboolean;
import static org.apache.jena.datatypes.xsd.XSDDatatype.XSDfloat;
import static org.apache.jena.datatypes.xsd.XSDDatatype.XSDinteger;
import static org.apache.jena.datatypes.xsd.XSDDatatype.XSDstring;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
Expand Down Expand Up @@ -395,11 +397,29 @@ public Friend() {

}
Friend friend;
String uri;
Integer intNumber;
boolean booleanValue;

@Property(uri = "http://set.friend/property")
public void setFriend(Friend friend) {
this.friend = friend;
}

@Property(uri = "http://set.friend/asString", asString = true)
public void setUri(String uri) {
this.uri = uri;
}

@Property(uri = "http://set.friend/setInteger")
public void setIntNumber(int intNumber) {
this.intNumber = intNumber;
}

@Property(uri = "http://set.friend/setBoolean")
public void setBooleanValue(boolean booleanValue) {
this.booleanValue = booleanValue;
}
}

// --------------------------------------------
Expand Down Expand Up @@ -696,6 +716,37 @@ public void loop_test() throws ConfigurationBeanLoaderException {
assertEquals(friend, friend.friend.friend);
}

@Test
public void loadUriAsString() throws ConfigurationBeanLoaderException {
model.add(new Statement[] {
typeStatement("http://friend.instance/one", toJavaUri(Friend.class)),
typeStatement("http://friend.instance/two", toJavaUri(Friend.class)),
objectProperty("http://friend.instance/one", "http://set.friend/asString",
"http://friend.instance/two"), });

Friend friend = loader.loadInstance("http://friend.instance/one", Friend.class);
assertEquals(friend.uri, "http://friend.instance/two");
}

@Test
public void loadInteger() throws ConfigurationBeanLoaderException {
model.add(new Statement[] {
typeStatement("http://friend.instance/one", toJavaUri(Friend.class)),
dataProperty("http://friend.instance/one", "http://set.friend/setInteger", 42, XSDinteger), });

Friend friend = loader.loadInstance("http://friend.instance/one", Friend.class);
assertEquals(new Integer(42), friend.intNumber);
}

@Test
public void loadBoolean() throws ConfigurationBeanLoaderException {
model.add(new Statement[] {
typeStatement("http://friend.instance/one", toJavaUri(Friend.class)),
dataProperty("http://friend.instance/one", "http://set.friend/setBoolean", true, XSDboolean), });

Friend friend = loader.loadInstance("http://friend.instance/one", Friend.class);
assertEquals(Boolean.TRUE, friend.booleanValue);
}
// --------------------------------------------

@Test
Expand Down

0 comments on commit b776311

Please sign in to comment.