This is the method where I do the request and which I effectively want to test:

  private Model queryResourceModel(Resource o) {
    URL url;
    URLConnection conn;
    Model result = ModelFactory.createDefaultModel();   
    try {
      url = new URL(o.getURI());
    } catch (MalformedURLException e) {
      e.printStackTrace();
      return result;
    }
    try {
      conn = url.openConnection();
      conn.setRequestProperty("Accept", "application/rdf+xml");
      conn.setRequestProperty("Accept-Language", "en");
      return ModelFactory.createDefaultModel()
        .read(conn.getInputStream(), null);
    } catch (ConnectException e) {
      if (e.getMessage().contains("refused")) {
        throw new RuntimeException(e);
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return result;
  }


> On 14. Jan 2019, at 15:09, ajs6f <[email protected]> wrote:
> 
> Please show the code you are actually using to make requests.
> 
> ajs6f
> 
>> On Jan 14, 2019, at 9:06 AM, Kevin Dreßler <[email protected]> wrote:
>> 
>> Hello, 
>> 
>> for unit testing I need to mock up a HTTP server delivering RDF/XML per 
>> content negotiation (Accept: application/rdf+xml). For a HTTP request on 
>> http://myEndpoint:myPort/test with the "Accept" header set as above it 
>> should output DESCRIBE(http://myEndpoint:myPort/test) as RDF/XML, so 
>> basically I want to mimic DBpedia. Is there a way to do this with a minimal 
>> amount of configuration inside my tests using FUSEKI 2?
>> Right now I am using the following code but I get the output only as TURTLE.
>> 
>>   String EX = "http://localhost:32537/";;
>> 
>>   Model lookup = ModelFactory.createDefaultModel();
>>   lookup.add(lookup.createResource(EX + "birch"),
>>     lookup.createProperty(EX + "brinellHardness"),
>>     lookup.createTypedLiteral(27));
>> 
>>   FusekiServer server = FusekiServer.create()
>>     .add("/birch", DatasetFactory.create(lookup))
>>     .port(32537)
>>     .build();
>>   server.start();
>> 
>> Thanks in advance,
>> Kevin
> 

Reply via email to