cdorn commented on issue #2868:
URL: https://github.com/apache/jena/issues/2868#issuecomment-2536361481

   Hi, sorry for the typo, its was not #deleteProperties() but 
#removeProperties() , below a full example:
   `package at.jku.isse.passiveprocessengine.rdf.trialcode;
   
   import java.util.ArrayList;
   import java.util.List;
   
   import org.apache.jena.graph.Graph;
   import org.apache.jena.ontapi.OntModelFactory;
   import org.apache.jena.ontapi.OntSpecification;
   import org.apache.jena.ontapi.UnionGraph;
   import org.apache.jena.rdf.listeners.StatementListener;
   import org.apache.jena.rdf.model.Statement;
   import org.apache.jena.rdf.model.impl.ModelCom;
   import org.apache.jena.reasoner.InfGraph;
   import org.junit.jupiter.api.Assertions;
   import org.junit.jupiter.api.Test;
   
   public class GraphListenerTest {
   
        @Test
        void testListenToDeleteEventsWithIncompleteRegistration() {
                var listener = new LoggingListener();
           var m = 
OntModelFactory.createModel(OntSpecification.OWL2_DL_MEM_RDFS_INF);
           m.register(listener);
           var type = m.createOntClass("http://x";);
           type.removeProperties();
           Assertions.assertEquals(1, listener.added.size());
        // here I dont receive the removed statement
           Assertions.assertEquals(1, listener.removed.size());
        }
        
        @Test
        void testListenToDeleteEventsWithCorrectRegistration() {
                var listener = new LoggingListener();
           var m = 
OntModelFactory.createModel(OntSpecification.OWL2_DL_MEM_RDFS_INF);
           m.register(listener);
           if (m.getGraph() instanceof InfGraph infG) {
                Graph raw = infG.getRawGraph();
               if (raw instanceof UnionGraph ugraph) {
                
ugraph.getEventManager().register(((ModelCom)m).adapt(listener));
               }   
           }
           var type = m.createOntClass("http://x";);
           type.removeProperties();
           // here I receive the same event twice, due to the two listener 
registrations
           Assertions.assertEquals(2, listener.added.size()); 
           Assertions.assertEquals(1, listener.removed.size());
        }
        
        public static class LoggingListener extends StatementListener {
   
                private final List<Statement> added = new ArrayList<>();
           private final List<Statement> removed = new ArrayList<>();
                
                @Override
                public void addedStatement(Statement s) {
                        System.out.println("ADDED "+s.toString());
                        added.add(s);
                }
   
                @Override
                public void removedStatement(Statement s) {
                        System.out.println("REMOVED "+s.toString());
                        removed.add(s);
                }
        }
   }
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to