Skip to content

Instantly share code, notes, and snippets.

@zednis
Created June 29, 2015 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zednis/21640b7bb31536511a87 to your computer and use it in GitHub Desktop.
Save zednis/21640b7bb31536511a87 to your computer and use it in GitHub Desktop.
TestCase for Jena Spring-powered CountryService class
package edu.rpi.tw.dco.usermgmt.service;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.rpi.tw.dco.usermgmt.DcoUserManagementApplication;
import edu.rpi.tw.dco.usermgmt.model.mongo.Country;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author szednik
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = DcoUserManagementApplication.class)
@WebAppConfiguration
public class CountryServiceTest {
@Autowired
private CountryService countryService;
final Resource VIVO_Country = ResourceFactory.createResource("http://vivoweb.org/ontology/core#Country");
@Test
public void testService() {
assertNotNull(countryService);
}
@Test
public void testListCountries() {
Model m = countryService.getSparqlTemplate().getModel();
m.createResource("http://example.com/test/US")
.addProperty(RDF.type, VIVO_Country)
.addProperty(RDFS.label, m.createLiteral("United States of America"));
m.createResource("http://example.com/test/UK")
.addProperty(RDF.type, VIVO_Country)
.addProperty(RDFS.label, m.createLiteral("United Kingdom"));
List<Country> countries = countryService.getCountries();
assertNotNull(countries);
assertEquals(2, countries.size());
}
@Test
public void testGetCountry() {
Model m = countryService.getSparqlTemplate().getModel();
m.createResource("http://example.com/test/US")
.addProperty(RDF.type, VIVO_Country)
.addProperty(RDFS.label, m.createLiteral("United States of America"));
Country country = countryService.getCountry("http://example.com/test/US");
assertNotNull(country);
assertEquals("United States of America", country.getLabel());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment