Ejemplo n.º 1
0
  /**
   * Check that a predicate for which no shortnames are defined in name map still gets a term
   * binding in the metadata.
   */
  @Test
  public void testTermBindingsCoverAllPredicates() throws URISyntaxException {
    Resource thisPage = ResourceFactory.createResource("elda:thisPage");
    String pageNumber = "1";
    Bindings cc = new Bindings();
    URI reqURI = new URI("");
    //
    EndpointDetails spec =
        new EndpointDetails() {

          @Override
          public boolean isListEndpoint() {
            return true;
          }

          @Override
          public boolean hasParameterBasedContentNegotiation() {
            return false;
          }
        };
    EndpointMetadata em = new EndpointMetadata(spec, thisPage, pageNumber, cc, reqURI);
    //
    PrefixMapping pm =
        PrefixMapping.Factory.create().setNsPrefix("this", "http://example.com/root#");
    Model toScan = ModelIOUtils.modelFromTurtle(":a <http://example.com/root#predicate> :b.");
    toScan.setNsPrefixes(pm);
    Resource predicate = toScan.createProperty("http://example.com/root#predicate");
    Model meta = ModelFactory.createDefaultModel();
    Resource exec = meta.createResource("fake:exec");
    ShortnameService sns = new StandardShortnameService();
    //		APIEndpoint.Request r = new APIEndpoint.Request( new Controls(), reqURI, cc );

    CompleteContext c =
        new CompleteContext(CompleteContext.Mode.PreferPrefixes, sns.asContext(), pm)
            .include(toScan);

    em.addTermBindings(toScan, meta, exec, c);

    @SuppressWarnings("unused")
    Map<String, String> termBindings = c.Do();
    Resource tb = meta.listStatements(null, API.termBinding, Any).nextStatement().getResource();
    assertTrue(meta.contains(tb, API.label, "this_predicate"));
    assertTrue(meta.contains(tb, API.property, predicate));
  }
Ejemplo n.º 2
0
  private Resource createMetadata(final boolean isListEndpoint, Integer totalResults)
      throws URISyntaxException {
    Model objectModel = ModelFactory.createDefaultModel();
    MergedModels mergedModels = new MergedModels(objectModel);
    //
    Model meta = mergedModels.getMetaModel();
    //
    Resource thisMetaPage = meta.createResource("eh:/thisMetaPage");
    Resource SEP = meta.createResource("eh:/sparqlEndpoint");
    thisMetaPage.addProperty(API.sparqlEndpoint, SEP);

    Bindings bindings = new Bindings();
    URI ru = new URI(thisMetaPage.getURI());
    Resource uriForDefinition = objectModel.createResource(thisMetaPage.getURI());
    boolean suppressIPTO = true;
    int page = 1, perPage = 10;
    boolean hasMorePages = true;
    Context context = new Context();
    CompleteContext cc = new CompleteContext(Mode.PreferLocalnames, context, objectModel);
    //
    SetsMetadata setsMeta =
        new SetsMetadata() {

          @Override
          public void setMetadata(String type, Model meta) {}
        };
    WantsMetadata wantsMeta =
        new WantsMetadata() {

          @Override
          public boolean wantsMetadata(String name) {
            return true;
          }
        };
    //
    Map<String, View> views = new HashMap<String, View>();
    Set<FormatNameAndType> formats = new HashSet<FormatNameAndType>();
    //
    EndpointDetails details =
        new EndpointDetails() {

          @Override
          public boolean isListEndpoint() {
            return isListEndpoint;
          }

          @Override
          public boolean hasParameterBasedContentNegotiation() {
            return false;
          }
        };
    //
    EndpointMetadata.addAllMetadata(
        mergedModels,
        ru,
        uriForDefinition,
        bindings,
        cc,
        suppressIPTO,
        thisMetaPage,
        page,
        perPage,
        totalResults,
        hasMorePages,
        CollectionUtils.list(objectModel.createResource("eh:/item/_1")),
        setsMeta,
        wantsMeta,
        "SELECT",
        "VIEW",
        new TestCaches.FakeSource("Nemos"),
        views,
        formats,
        details);
    return thisMetaPage;
  }