Package org.apache.stanbol.entityhub.servicesapi.model

Examples of org.apache.stanbol.entityhub.servicesapi.model.ValueFactory


     * @param headers the http headers of the request
     * @return the response
     */
    private Response executeLDPathQuery(Entityhub entityhub,FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
        QueryResultList<Representation> result;
        ValueFactory vf = new RdfValueFactory(new IndexedMGraph());
        EntityhubBackend backend = new EntityhubBackend(entityhub);
        EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
        //copy the selected fields, because we might need to delete some during
        //the preparation phase
        Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
View Full Code Here


     * @param headers the http headers of the request
     * @return the response
     */
    private Response executeLDPathQuery(FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
        QueryResultList<Representation> result;
        ValueFactory vf = new RdfValueFactory(new IndexedMGraph());
        SiteBackend backend = new SiteBackend(site,vf);
        EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
        //copy the selected fields, because we might need to delete some during
        //the preparation phase
        Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
View Full Code Here

    }

    @Test
    public void testFieldRemoval() throws URISyntaxException {
        String field = "urn:the.field:used.for.this.Test";
        ValueFactory vf = getValueFactory();
        Representation rep = createRepresentation(null);
        // Test removal for References
        String strRef = "urn:testValue";
        rep.addReference(field, strRef);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.removeReference(field, strRef);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        Reference ref = vf.createReference("urn:testValue2");
        rep.add(field, ref);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.remove(field, ref);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        // test removal for texts (with and without language)
        String strText = "test text";
        String strTextLang = "en";
        rep.addNaturalText(field, strText, strTextLang);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.removeNaturalText(field, strText, strTextLang);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        String strTextNoLang = "test text without lang";
        rep.addNaturalText(field, strTextNoLang);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.removeNaturalText(field, strTextNoLang);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        // there is also the possibility to explicitly parse null as language
        // could internally case differences however externally this is the same
        rep.addNaturalText(field, strTextNoLang, (String) null);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.removeNaturalText(field, strTextNoLang, (String) null);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));

        Text text = vf.createText("Das ist ein Text zum testen des Text Objektes", "de");
        rep.add(field, text);
        assertTrue(asCollection(rep.getFieldNames()).contains(field));
        rep.remove(field, text);
        assertFalse(asCollection(rep.getFieldNames()).contains(field));
View Full Code Here

     */
    @Test
    public void testURIToReferenceConversion() throws URISyntaxException {
        String field = "urn:the.field:used.for.this.Test";
        URI uri = new URI("http://www.test.org/uriTest");
        ValueFactory vf = getValueFactory();
        Representation rep = createRepresentation(null);
        // test conversion
        rep.add(field, uri);
        Iterator<Reference> refs = rep.getReferences(field);
        assertTrue(refs.hasNext());
        assertEquals(refs.next().getReference(), uri.toString());
        assertFalse(refs.hasNext());
        // test multiple adds do not generate duplicate References
        rep.add(field, uri);
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test adding a equivalent reference
        rep.add(field, vf.createReference(uri.toString()));
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test removing
        rep.remove(field, uri);
        assertFalse(rep.get(field).hasNext());
    }
View Full Code Here

     */
    @Test
    public void testURLToReferenceConversion() throws MalformedURLException {
        String field = "urn:the.field:used.for.this.Test";
        URL url = new URL("http://www.test.org/urlTest");
        ValueFactory vf = getValueFactory();
        Representation rep = createRepresentation(null);
        // test empty reference
        Iterator<Reference> refs = rep.getReferences(field);
        assertFalse(refs.hasNext());
        // test conversion
        rep.add(field, url);
        refs = rep.getReferences(field);
        assertTrue(refs.hasNext());
        assertEquals(refs.next().getReference(), url.toString());
        assertFalse(refs.hasNext());
        // test multiple adds do not generate duplicate References
        rep.add(field, url);
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test adding a equivalent reference
        rep.add(field, vf.createReference(url.toString()));
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test removing
        rep.remove(field, url);
        assertFalse(rep.get(field).hasNext());

View Full Code Here

     * correct implementation of the {@link Text#equals(Object)} method
     */
    @Test
    public void testStringArrayToTextConversion() {
        String field = "urn:the.field:used.for.this.Test";
        ValueFactory vf = getValueFactory();
        Representation rep = createRepresentation(null);
        // test conversion of String[] with language as second element
        String[] textWithLang = new String[] {"Test text with language", "en"};
        rep.add(field, textWithLang);
        Iterator<Text> refs = rep.get(field, (String[]) null);
        assertTrue(refs.hasNext());
        Text test = refs.next();
        assertEquals(textWithLang[1], test.getLanguage());
        assertEquals(textWithLang[0], test.getText());
        assertFalse(refs.hasNext());
        // test multiple adds do not generate duplicate References
        rep.add(field, textWithLang);
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test adding a equivalent reference
        rep.add(field, vf.createText(textWithLang[0], textWithLang[1]));
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test removing
        rep.remove(field, textWithLang);
        assertFalse(rep.get(field).hasNext());

        // test conversion of String[] with only one element (default language)
        String[] textWithoutLang = new String[] {"Test text without language"};
        rep.add(field, textWithoutLang);
        refs = rep.get(field, (String[]) null);
        assertTrue(refs.hasNext());
        test = refs.next();
        assertNull(test.getLanguage());
        assertEquals(textWithoutLang[0], test.getText());
        assertFalse(refs.hasNext());
        // test multiple adds do not generate duplicate References
        rep.add(field, textWithoutLang);
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test adding a equivalent reference
        rep.add(field, vf.createText(textWithoutLang[0]));
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test removing
        rep.remove(field, textWithoutLang);
        assertFalse(rep.get(field).hasNext());

        // test conversion of String[] with null as second element (default language)
        String[] textWithDefaultLang = new String[] {"Test text with default language", null};
        rep.add(field, textWithDefaultLang);
        refs = rep.get(field, (String[]) null);
        assertTrue(refs.hasNext());
        test = refs.next();
        assertNull(test.getLanguage());
        assertEquals(textWithDefaultLang[0], test.getText());
        assertFalse(refs.hasNext());
        // test multiple adds do not generate duplicate References
        rep.add(field, textWithDefaultLang);
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test adding a equivalent reference
        rep.add(field, vf.createText(textWithDefaultLang[0], null));
        assertTrue(asCollection(rep.get(field)).size() == 1);
        // test removing
        rep.remove(field, textWithDefaultLang);
        assertFalse(rep.get(field).hasNext());

View Full Code Here

    }

    @Test
    public void testMultipleAddAndRemove() throws MalformedURLException, URISyntaxException {
        String field = "urn:the.field:used.for.this.Test";
        ValueFactory vf = getValueFactory();
        Representation rep = createRepresentation(null);
        Reference ref = vf.createReference("http://www.test.org/test");
        Text text = vf.createText("test", "en");
        Integer i = 42;
        Double d = Math.PI;
        URI uri = new URI("http://www.test.org/uriTest");
        URL url = new URL("http://www.test.org/urlTest");
        String[] textAsArray = new String[] {"Test text as Array", "en"};
View Full Code Here

        assertTrue(rep.equals(rep1));
        assertTrue(rep.hashCode() == rep1.hashCode()); // check the hash code
    }

    private Representation testRepresentation(String id) {
        ValueFactory vf = getValueFactory();
        Representation rep = vf.createRepresentation(id);
        assertNotNull(rep);
        assertNotNull(rep.getId());
        if (id != null) {
            assertEquals(rep.getId(), id);
        }
View Full Code Here

     * @param language
     *            the language
     * @return the created {@link Text} instance that can be used to perform further tests.
     */
    private Text testText(String textString, String language) {
        ValueFactory vf = getValueFactory();
        Text text = vf.createText(textString, language);
        assertNotNull(text.getText());
        assertNotNull(text.getText());
        assertEquals(text.getText(), textString);
        if (language == null) {
            assertTrue(text.getLanguage() == null);
View Full Code Here

     * @param refObject
     *            the object representing the reference
     * @return the created {@link Reference} that can be used to perform further tests.
     */
    private Reference testRef(Object refObject) {
        ValueFactory vf = getValueFactory();
        Reference ref = vf.createReference(refObject);
        // check not null
        assertNotNull(ref);
        // check reference is not null
        assertNotNull(ref.getReference());
        return ref;
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.model.ValueFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.