gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] fenfire/org/fenfire/modules/pp PPActionsImpl.ja...


From: Matti Katila
Subject: [Gzz-commits] fenfire/org/fenfire/modules/pp PPActionsImpl.ja...
Date: Tue, 25 Mar 2003 18:27:15 -0500

CVSROOT:        /cvsroot/fenfire
Module name:    fenfire
Changes by:     Matti Katila <address@hidden>   03/03/25 18:27:15

Modified files:
        org/fenfire/modules/pp: PPActionsImpl.java PPActionsImpl.test 

Log message:
        all implemented things are tested

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/modules/pp/PPActionsImpl.java.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/modules/pp/PPActionsImpl.test.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: fenfire/org/fenfire/modules/pp/PPActionsImpl.java
diff -u fenfire/org/fenfire/modules/pp/PPActionsImpl.java:1.10 
fenfire/org/fenfire/modules/pp/PPActionsImpl.java:1.11
--- fenfire/org/fenfire/modules/pp/PPActionsImpl.java:1.10      Sun Mar  9 
06:30:05 2003
+++ fenfire/org/fenfire/modules/pp/PPActionsImpl.java   Tue Mar 25 18:27:15 2003
@@ -12,7 +12,7 @@
 /** The implementation of PPActions.
  */
 public class PPActionsImpl extends UnicastRemoteObject implements PPActions {
-public static final String rcsid = "$Id: PPActionsImpl.java,v 1.10 2003/03/09 
11:30:05 mudyc Exp $";
+public static final String rcsid = "$Id: PPActionsImpl.java,v 1.11 2003/03/25 
23:27:15 mudyc Exp $";
     public static final boolean dbg = true;
     protected static void p(String s) { if(dbg) pa(s); }
     protected static void pa(String s) { System.out.println(s); }
@@ -88,10 +88,10 @@
 
        // set coords
        note.addProperty(PP.CoordX, ""+x);
-       note.addProperty(PP.CoordX, ""+x);
+       note.addProperty(PP.CoordY, ""+y);
 
        // set depth...
-       note.addProperty(PP.Depth,  "5");
+       note.addProperty(PP.Depth,  "10");
 
        // scale etc..  XXX
 
@@ -217,17 +217,35 @@
     { synchronized(model) { try {
        Resource note = model.getResource(noteURI);
        Resource assoc = model.getResource(assocURI);
-           
-       // check if already associated
-       Selector slctr = new SelectorImpl(note, PP.Association, assoc);
-       StmtIterator iter = model.listStatements(slctr);
-       if (iter.hasNext()) {
-           pa("Already associated!");
+
+       if (note == assoc) {
+           pa("link to itself???");
            return;
        }
 
-       // assoc
-       note.addProperty(PP.Association, assoc);
+       if (side < 0) {
+           // check if already associated
+           Selector slctr = new SelectorImpl(assoc, PP.Association, note);
+           StmtIterator iter = model.listStatements(slctr);
+           if (iter.hasNext()) {
+               pa("Already associated!");
+               return;
+           }
+
+           // assoc
+           assoc.addProperty(PP.Association, note);
+       } else {
+           // check if already associated
+           Selector slctr = new SelectorImpl(note, PP.Association, assoc);
+           StmtIterator iter = model.listStatements(slctr);
+           if (iter.hasNext()) {
+               pa("Already associated!");
+               return;
+           }
+
+           // assoc
+           note.addProperty(PP.Association, assoc);
+       }
     } catch (RDFException e) {
        pa("Fault associationing notes: "+e);
     }}}
Index: fenfire/org/fenfire/modules/pp/PPActionsImpl.test
diff -u fenfire/org/fenfire/modules/pp/PPActionsImpl.test:1.1 
fenfire/org/fenfire/modules/pp/PPActionsImpl.test:1.2
--- fenfire/org/fenfire/modules/pp/PPActionsImpl.test:1.1       Tue Mar 25 
09:23:57 2003
+++ fenfire/org/fenfire/modules/pp/PPActionsImpl.test   Tue Mar 25 18:27:15 2003
@@ -1,19 +1,261 @@
 #(c): Matti Katila
 
 from org.fenfire.modules.pp import *
+from org.fenfire.util import URN5Namespace
 from com.hp.hpl.mesa.rdf import jena
+from com.hp.hpl.mesa.rdf.jena.vocabulary import RDF
 
 def setUp():
-    global model, ppact
+    global model, ppact, PP
     model = jena.mem.ModelMem()
     ppact = PPActionsImpl(model)
+    PP = PPVocab()
 
 def testNewPaper():
-    """
-    Create a new pp paper
-    """
-    text = ppact.newPaper()
-    assert text != ''
+    paper = ppact.newPaper()
+    assert paper != ''
+
+    slctr = jena.common.SelectorImpl(None, RDF.type, PP.PaperType)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getSubject().toString() == paper
+
+    # XXX does not check creation time
  
 def testNewNote():
-    assert 1 == 1
+    newNoteCheck()
+
+    paper = URN5Namespace.instance.generateId()
+    paperRes = jena.common.ResourceImpl(paper)
+    note = ppact.newNote(paper, 123, 456, 'This is a new note')
+    noteRes = jena.common.ResourceImpl(note)
+
+    # note1 -.
+    #         >-> lintoReal data -> data
+    # note2 -'
+    
+    # check link to real data 
+    slctr = jena.common.SelectorImpl(noteRes, PP.LinkToContentRef, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getSubject().toString() == note
+
+    datalink = stmt.getObject()
+
+    # check data
+    slctr = jena.common.SelectorImpl(datalink, PP.Data, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getObject().toString() == 'This is a new note'
+
+    # check type of data
+    slctr = jena.common.SelectorImpl(datalink, RDF.type, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getSubject() == datalink
+    assert stmt.getObject() == PP.DataType
+
+
+def testCloneNote():
+    newNoteCheck()
+
+    paper = URN5Namespace.instance.generateId()
+    orig = ppact.newNote(paper, 123, 456, 'This is the original note')
+    origRes = jena.common.ResourceImpl(orig)
+    clone = ppact.cloneNote(paper, orig, 123, 456, 'This is a new clone')
+    cloneRes = jena.common.ResourceImpl(clone)
+
+    # note  -.
+    #         >-> lintoReal data -> data
+    # clone -'
+    
+    # check link to real data 
+    slctr = jena.common.SelectorImpl(cloneRes, PP.LinkToContentRef, None)
+    iter = model.listStatements(slctr)
+
+    slctr2 = jena.common.SelectorImpl(origRes, PP.LinkToContentRef, None)
+    iter2 = model.listStatements(slctr2)
+
+    assert iter.hasNext() == 1
+    assert iter2.hasNext() == 1
+
+    stmt = iter.next()
+    stmt2 = iter2.next()
+
+    assert iter.hasNext() == 0
+    assert iter2.hasNext() == 0
+    
+    assert stmt.getObject() == stmt2.getObject()
+
+    slctr = jena.common.SelectorImpl(stmt.getObject(), PP.Data, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getObject().toString() == 'This is the original note'
+
+def newNoteCheck():
+    paper = URN5Namespace.instance.generateId()
+    paperRes = jena.common.ResourceImpl(paper)
+    note = ppact.newNote(paper, -123, 456, 'This is a new note')
+    noteRes = jena.common.ResourceImpl(note)
+
+    # type test - NoteType
+    slctr = jena.common.SelectorImpl(noteRes, RDF.type, PP.NoteType)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getSubject().toString() == note
+    
+    # is node on paper?
+    slctr = jena.common.SelectorImpl(paperRes, PP.Contains, noteRes)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getSubject().toString() == paper
+    assert stmt.getObject().toString() == note
+
+    # x coord ok?
+    slctr = jena.common.SelectorImpl(noteRes, PP.CoordX, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getObject().toString() == '-123'
+
+    # y coord ok?
+    slctr = jena.common.SelectorImpl(noteRes, PP.CoordY, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getObject().toString() == '456'
+
+    # deth ok?
+    slctr = jena.common.SelectorImpl(noteRes, PP.Depth, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getObject().toString() == '10'
+
+def testAssoc():
+    assocPos()
+    assocNeg()
+
+def assocPos():
+    paper = URN5Namespace.instance.generateId()
+    noteA = ppact.newNote(paper, 12, 45, 'This is A')
+    noteARes = jena.common.ResourceImpl(noteA)
+    noteB = ppact.newNote(paper, 23, 56, 'This is B')
+    noteBRes = jena.common.ResourceImpl(noteB)
+
+    ppact.assocNotes(noteA, 1, noteB)
+
+    # noteA -> ?
+    slctr = jena.common.SelectorImpl(None, PP.Association, noteARes)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 0
+    
+    slctr = jena.common.SelectorImpl(noteARes, PP.Association, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getObject().toString() == noteB
+    
+    # ? <- noteB
+    slctr = jena.common.SelectorImpl(noteBRes, PP.Association, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 0
+
+    slctr = jena.common.SelectorImpl(None, PP.Association, noteBRes)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getSubject().toString() == noteA
+
+
+def assocNeg():
+    paper = URN5Namespace.instance.generateId()
+    noteA = ppact.newNote(paper, 12, 45, 'This is A')
+    noteARes = jena.common.ResourceImpl(noteA)
+    noteB = ppact.newNote(paper, 23, 56, 'This is B')
+    noteBRes = jena.common.ResourceImpl(noteB)
+
+    ppact.assocNotes(noteA, -1, noteB)
+
+    # noteA -> ?
+    slctr = jena.common.SelectorImpl(noteARes, PP.Association, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 0
+    
+    slctr = jena.common.SelectorImpl(None, PP.Association, noteARes)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getSubject().toString() == noteB
+    
+    # ? <- noteB
+    slctr = jena.common.SelectorImpl(None, PP.Association, noteBRes)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 0
+
+    slctr = jena.common.SelectorImpl(noteBRes, PP.Association, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+    assert stmt.getObject().toString() == noteA
+
+
+def testInsertAndDeleteText():
+    paper = URN5Namespace.instance.generateId()
+    note = ppact.newNote(paper, -12, -45, 'This is a test')
+    noteRes = jena.common.ResourceImpl(note)
+    print note
+
+    ppact.insertText(note, 5, 'FOO! ')
+
+    # insert test
+    slctr = jena.common.SelectorImpl(noteRes, PP.LinkToContentRef, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+
+    slctr = jena.common.SelectorImpl(stmt.getObject(), PP.Data, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+
+    assert stmt.getObject().toString() == 'This FOO! is a test'
+
+    #delete test
+    ppact.deleteText(note, 5, 8)
+    slctr = jena.common.SelectorImpl(noteRes, PP.LinkToContentRef, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+
+    slctr = jena.common.SelectorImpl(stmt.getObject(), PP.Data, None)
+    iter = model.listStatements(slctr)
+    assert iter.hasNext() == 1
+    stmt = iter.next()
+    assert iter.hasNext() == 0
+
+    assert stmt.getObject().toString() == 'This ! is a test'




reply via email to

[Prev in Thread] Current Thread [Next in Thread]