Package org.apache.stanbol.entityhub.servicesapi.yard

Examples of org.apache.stanbol.entityhub.servicesapi.yard.Yard


     */
    @Test
    public void testUpdateRepresentationsWithNonPresent() throws YardException {
        // NOTE: this does not test if the updated view of the representation is
        // stored, but only that the update method works correctly
        Yard yard = getYard();
        String id1 = "urn:yard.test.testUpdateRepresentationsWithNonPresent:representation.id1";
        String id2 = "urn:yard.test.testUpdateRepresentationsWithNonPresent:representation.id2";
        String field = "urn:the.field:used.for.this.Test";
        Representation test1 = create(id1, true);
        // change the representations to be sure to force an update even if the
        // implementation checks for changes before updating a representation
        test1.add(field, "test value 1");
        // create a 2nd Representation by using the ValueFactory (will not add it
        // to the yard!)
        Representation test2 = create(id2, false);
        // now test1 is present and test2 is not.
        Iterable<Representation> updated = yard.update(Arrays.asList(test1, test2));
        // We expect that only test1 is updated and test2 is ignored
        assertNotNull(updated);
        Iterator<Representation> updatedIt = updated.iterator();
        assertTrue(updatedIt.hasNext());
        assertEquals(test1, updatedIt.next());
View Full Code Here


        // remove the created representation form the store anyway as part of the
        // test
        String id = "urn:yard.test.tesrRemoveRepresentation:representation.id";
        String field = "urn:the.field:used.for.this.Test";
        String testValue = "This is a test";
        Yard yard = getYard();
        Representation test = yard.getValueFactory().createRepresentation(id);
        test.add(field, testValue);
        yard.store(test); // store the representation
        assertTrue(yard.isRepresentation(test.getId())); // test if stored
        test = null; // free the initial
        // create the instance form the store to test (2)
        test = yard.getRepresentation(id);
        assertEquals(id, test.getId()); // only to be sure ...
        yard.remove(test.getId()); // test (1) - the remove
        assertFalse(yard.isRepresentation(test.getId()));// test if removed
        // test if the test object is not destroyed by removing the representation
        // it represents form the store (2)
        assertEquals(testValue, test.getFirst(field));
    }
View Full Code Here

        // test
        String id = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.id1";
        String id2 = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.id2";
        String field = "urn:the.field:used.for.this.Test";
        String testValue = "This is a test";
        Yard yard = getYard();
        // use both ways to add the two Representations (should make no differences,
        // but one never can know ...
        Representation test1 = yard.create(id); // create and add
        Representation test2 = yard.getValueFactory().createRepresentation(id2); // create
        test2.add(field, testValue); // add value
        yard.store(test2);// store
        assertTrue(yard.isRepresentation(test1.getId())); // test if stored
        assertTrue(yard.isRepresentation(test2.getId()));
        yard.remove(Arrays.asList(test1.getId(), test2.getId())); // remove
        assertFalse(yard.isRepresentation(test1.getId())); // test if removed
        assertFalse(yard.isRepresentation(test2.getId()));
    }
View Full Code Here

        // test
        String id = "urn:yard.test.testRemoveAll:representation.id1";
        String id2 = "urn:yard.test.testRemoveAll:representation.id2";
        String field = "urn:the.field:used.for.this.Test";
        String testValue = "This is a test";
        Yard yard = getYard();
        // use both ways to add the two Representations (should make no differences,
        // but one never can know ...
        Representation test1 = yard.create(id); // create and add
        test1.add(field, testValue); // add value
        yard.store(test1);// store
        Representation test2 = yard.getValueFactory().createRepresentation(id2); // create
        test2.add(field, testValue); // add value
        yard.store(test2);// store
        assertTrue(yard.isRepresentation(test1.getId())); // test if stored
        assertTrue(yard.isRepresentation(test2.getId()));
        yard.removeAll(); // remove
        assertFalse(yard.isRepresentation(test1.getId())); // test if removed
        assertFalse(yard.isRepresentation(test2.getId()));
        //test that Yard is still useable after removeAll
        yard.store(test1);// store
        assertTrue(yard.isRepresentation(test1.getId())); // test if stored
        yard.removeAll(); // remove
        assertFalse(yard.isRepresentation(test1.getId()));
    }
View Full Code Here

    public void testRemoveRepresentationsWithNullValue() throws YardException {
        // NOTE: This test needs not to use the create(..) method, because we
        // remove the created representation form the store anyway as part of the
        // test
        String id = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.id";
        Yard yard = getYard();
        Representation test = yard.create(id); // create and add
        assertTrue(yard.isRepresentation(test.getId()));
        yard.remove(Arrays.asList(test.getId(), null));
        assertFalse(yard.isRepresentation(test.getId()));
    }
View Full Code Here

        // NOTE: This test needs not to use the create(..) method, because we
        // remove the created representation form the store anyway as part of the
        // test
        String id = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.stored";
        String id2 = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.notStored";
        Yard yard = getYard();
        Representation test = yard.create(id); // create and add
        assertTrue(yard.isRepresentation(test.getId()));
        yard.remove(Arrays.asList(test.getId(), id2));
        assertFalse(yard.isRepresentation(test.getId()));
        assertFalse(yard.isRepresentation(id2));
    }
View Full Code Here

    @Test
    public void testChangeRepresentation() throws YardException {
        String id = "urn:yard.test.testChangeRepresentation:representation.id";
        String field = "urn:the.field:used.for.this.Test";
        String testValue = "This is a test";
        Yard yard = getYard();
        // use the ValueFactory to create the representation to ensure that this
        // instance has nothing to do with the store
        Representation test = create(id, false);
        // now store the empty Representation
        yard.store(test);
        // now add a values
        test.add(field, testValue);
        // now get the representation from the yard
        Representation stored = yard.getRepresentation(id);
        // test if the stored version does not contain the value
        assertFalse(stored.get(field).hasNext());
        stored = null;
        // now store the updated version
        yard.store(test);
        // now check that the updated value is stored
        stored = yard.getRepresentation(id);
        assertEquals(testValue, stored.getFirst(field));

        // now we need to test if modifications of an Representation returned
        test = stored;
        stored = null;
        String testValue2 = "This is an ohter test value";
        test.add(field, testValue2);

        // now get the representation from the yard and check that it still has
        // only one value
        stored = yard.getRepresentation(id);
        Collection<Object> values = asCollection(stored.get(field));
        assertTrue(values.remove(testValue)); // test that it contains the value
        assertTrue(values.isEmpty()); // and that there is only this value
        values = null;
        // now update the stored version with the new state
        stored = null;
        stored = yard.update(test);
        values = asCollection(stored.get(field));
        assertTrue(values.remove(testValue)); // test that it contains the original
        assertTrue(values.remove(testValue2)); // test that it contains the 2nd value
        assertTrue(values.isEmpty()); // and that there are only these two values
        values = null;
View Full Code Here

                public void modifiedService(ServiceReference reference, Object service) {
                }
               
                @Override
                public Object addingService(ServiceReference reference) {
                    Yard yard = (Yard)bundleContext.getService(reference);
                    synchronized (yardReferenceLock) {
                        if(yardReference == null){
                            if(yard != null){
                                activateManagedSite(yard);
                                yardReference = reference;
View Full Code Here

     * @param The representation to store
     */
    @Override
    public void store(Representation representation) throws ManagedSiteException {
        try {
            Yard yard = getYard();
            fieldMapper.applyMappings(representation, representation, yard.getValueFactory());
            yard.store(representation);
        catch (YardException e) {
            throw new ManagedSiteException(e.getMessage(), e);
        }
       
    }
View Full Code Here

     * @param The representations to store
     */
    @Override
    public void store(final Iterable<Representation> representations) throws ManagedSiteException {
        try {
            Yard yard = getYard();
            final ValueFactory vf = yard.getValueFactory();
            yard.store(new Iterable<Representation>() {               
                @Override
                public Iterator<Representation> iterator() {
                    return new Iterator<Representation>() {
                        Iterator<Representation> it = representations.iterator();
                        @Override
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.yard.Yard

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.