Search in sources :

Example 36 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class SesameDateTimeOrderingTest method sesameBetterOrderDateTimesCorrectly.

@Test
public void sesameBetterOrderDateTimesCorrectly() throws Exception {
    Graph tempGraph = new InMemoryTempGraphFactory().createTempGraph();
    tempGraph.addTriplesFromTurtle("" + "@prefix xsd:<http://www.w3.org/2001/XMLSchema#>  . " + "<http://foo1> <http://bar> \"2005-02-28T00:00:00Z\"^^xsd:dateTime . " + "<http://foo2> <http://bar> \"2005-02-28T00:00:01Z\"^^xsd:dateTime . " + "<http://foo3> <http://bar> \"2005-02-28T00:00:00-05:00\"^^xsd:dateTime . " + "");
    List<BoundVariables> bvs = tempGraph.select("PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" + "SELECT ?subject WHERE { " + "  ?subject ?p ?o . " + "} ORDER BY (?o)");
    assertEquals("http://foo1", bvs.get(0).getAsString("subject"));
    assertEquals("http://foo2", bvs.get(1).getAsString("subject"));
    assertEquals("http://foo3", bvs.get(2).getAsString("subject"));
    bvs = tempGraph.select("PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" + "SELECT ?subject WHERE { " + "  ?subject ?p ?o . " + "} ORDER BY DESC (?o)");
    assertEquals("http://foo3", bvs.get(0).getAsString("subject"));
    assertEquals("http://foo2", bvs.get(1).getAsString("subject"));
    assertEquals("http://foo1", bvs.get(2).getAsString("subject"));
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) BoundVariables(com.thoughtworks.studios.shine.semweb.BoundVariables) InMemoryTempGraphFactory(com.thoughtworks.studios.shine.semweb.sesame.InMemoryTempGraphFactory) Test(org.junit.Test)

Example 37 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class JobResourceImporterTest method testLoadingFileThatDoesNotExist.

@Test
public void testLoadingFileThatDoesNotExist() throws GoIntegrationException, IOException, DocumentException {
    Clock.fakeNowUTC(2008, 1, 20, 0, 0, 1);
    when(xmlApiService.write(any(JobXmlViewModel.class), eq(baseUri))).thenReturn(docFor(jobWithArtifactsMissing));
    JobResourceImporter rdfImporter = new JobResourceImporter("src/test-shared/resources/cruise/artifacts", new InMemoryTempGraphFactory(), transformerRegistry, xmlApiService, systemEnvironment);
    Graph jobGraph = rdfImporter.importJob(JobInstanceMother.passed("foo"), "https://localhost:8154/go");
    String ask = "PREFIX xunit: <" + XUnitOntology.URI + "> ASK WHERE { [] a xunit:TestCase }";
    assertAskIsFalse(jobGraph, ask);
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) JobXmlViewModel(com.thoughtworks.go.server.domain.xml.JobXmlViewModel) InMemoryTempGraphFactory(com.thoughtworks.studios.shine.semweb.sesame.InMemoryTempGraphFactory) Test(org.junit.Test)

Example 38 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class JobResourceImporterTest method testArtifactsAreImported.

@Test
public void testArtifactsAreImported() throws Exception {
    Clock.fakeNowUTC(2008, 1, 20, 0, 0, 1);
    JobInstance failedJob = JobInstanceMother.failed("test");
    Document document = docFor(happyJobResourceXML);
    document.selectSingleNode("//link[@rel='self']/@href").setText(new JobXmlViewModel(failedJob).httpUrl(baseUri));
    when(xmlApiService.write(any(JobXmlViewModel.class), eq(baseUri))).thenReturn(document);
    JobResourceImporter rdfImporter = new JobResourceImporter("src/test-shared/resources/cruise/artifacts", new InMemoryTempGraphFactory(), transformerRegistry, xmlApiService, systemEnvironment);
    Graph graph = rdfImporter.importJob(failedJob, baseUri);
    String testCountSelect = "PREFIX xunit: <" + XUnitOntology.URI + "> SELECT ?testcase WHERE { ?testCase a xunit:TestCase }";
    assertEquals(5, graph.select(testCountSelect).size());
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) JobInstance(com.thoughtworks.go.domain.JobInstance) JobXmlViewModel(com.thoughtworks.go.server.domain.xml.JobXmlViewModel) Document(org.dom4j.Document) InMemoryTempGraphFactory(com.thoughtworks.studios.shine.semweb.sesame.InMemoryTempGraphFactory) Test(org.junit.Test)

Example 39 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class LazyStageGraphLoaderTest method realGraph.

private Graph realGraph() {
    final Graph realStageGraph = graphFactory.createTempGraph();
    realStageGraph.addTriplesFromTurtle("" + "@prefix cruise: <" + GoOntology.URI + "> . " + "@prefix xunit: <" + XUnitOntology.URI + "> . " + "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . " + "" + " <http://pipeline/1> a cruise:Pipeline . " + " <http://pipeline/1> cruise:pipelineName \"pipeline-foo\"^^xsd:string ." + " <http://pipeline/1> cruise:pipelineCounter \"23\"^^xsd:integer . " + " <http://pipeline/1> cruise:hasStage <http://stage/1> . " + " <http://stage/1> a cruise:Stage . " + " <http://stage/1> cruise:stageName \"stage-1\"^^xsd:string . " + " <http://stage/1> cruise:stageCounter \"1\"^^xsd:integer . " + // only job in the stage graph
    " <http://stage/1> cruise:hasJob <http://job/1> . " + "");
    return realStageGraph;
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph)

Example 40 with Graph

use of com.thoughtworks.studios.shine.semweb.Graph in project gocd by gocd.

the class StageStorageTest method saveStageGraphAndLoadOutSameGraph.

@Test
public void saveStageGraphAndLoadOutSameGraph() throws Exception {
    Graph graph = graphWithRDF("" + "@prefix cruise: <" + GoOntology.URI + "> . " + "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . " + "" + "<http://pipeline/1> a cruise:Pipeline ." + "<http://pipeline/1> cruise:pipelineName \"p\"^^xsd:string ." + "<http://pipeline/1> cruise:pipelineCounter 1 ." + "<http://pipeline/1> cruise:hasStage <http://stage/1> ." + "<http://stage/1> rdf:type cruise:Stage . " + "<http://stage/1> cruise:stageName \"s\"^^xsd:string . " + "<http://stage/1> cruise:stageCounter 2 . " + "<http://stage/1> cruise:hasJob <http://job/1> . " + "<http://job/1> a cruise:Job . " + "");
    stageStorage.save(graph);
    Graph loadedGraph = stageStorage.load(new StageIdentifier("p", 1, "s", "2"));
    assertAskIsTrue(loadedGraph, "" + "PREFIX cruise: <" + GoOntology.URI + "> " + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + "ASK WHERE {" + "  <http://pipeline/1> a cruise:Pipeline ." + "  <http://pipeline/1> cruise:pipelineName \"p\"^^xsd:string ." + "  <http://pipeline/1> cruise:pipelineCounter 1 ." + "  <http://pipeline/1> cruise:hasStage <http://stage/1> ." + "  <http://stage/1> rdf:type cruise:Stage . " + "  <http://stage/1> cruise:stageName \"s\"^^xsd:string . " + "  <http://stage/1> cruise:stageCounter 2 . " + "  <http://stage/1> cruise:hasJob <http://job/1> . " + "  <http://job/1> a cruise:Job . " + "}");
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) Graph(com.thoughtworks.studios.shine.semweb.Graph) Test(org.junit.Test)

Aggregations

Graph (com.thoughtworks.studios.shine.semweb.Graph)41 Test (org.junit.Test)26 InMemoryTempGraphFactory (com.thoughtworks.studios.shine.semweb.sesame.InMemoryTempGraphFactory)18 File (java.io.File)7 JobXmlViewModel (com.thoughtworks.go.server.domain.xml.JobXmlViewModel)5 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)5 InputStream (java.io.InputStream)5 TestFailureSetup (com.thoughtworks.go.server.dao.sparql.TestFailureSetup)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Date (java.util.Date)4 Pipeline (com.thoughtworks.go.domain.Pipeline)3 Stage (com.thoughtworks.go.domain.Stage)3 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 StageXmlViewModel (com.thoughtworks.go.server.domain.xml.StageXmlViewModel)3 XSLTTransformerRegistry (com.thoughtworks.studios.shine.semweb.grddl.XSLTTransformerRegistry)3 Modification (com.thoughtworks.go.domain.materials.Modification)2 GoGRDDLResourceRDFizer (com.thoughtworks.studios.shine.cruise.GoGRDDLResourceRDFizer)2 BoundVariables (com.thoughtworks.studios.shine.semweb.BoundVariables)2 IOException (java.io.IOException)2 Transformer (javax.xml.transform.Transformer)2