Skip to content

Commit 83331b5

Browse files
committed
add tests
1 parent ee6096d commit 83331b5

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/concurrent/synch/TestJoinPoint.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import net.lecousin.framework.concurrent.CancelException;
77
import net.lecousin.framework.concurrent.Task;
8+
import net.lecousin.framework.concurrent.Threading;
89
import net.lecousin.framework.concurrent.synch.JoinPoint;
910
import net.lecousin.framework.concurrent.synch.SynchronizationPoint;
1011
import net.lecousin.framework.core.test.LCCoreAbstractTest;
@@ -17,6 +18,7 @@ public class TestJoinPoint extends LCCoreAbstractTest {
1718

1819
@Test(timeout=30000)
1920
public void test() {
21+
Threading.debugSynchronization = true;
2022
JoinPoint<Exception> jp = new JoinPoint<>();
2123
Assert.assertEquals(0, jp.getToJoin());
2224
jp.addToJoin(1);
@@ -30,6 +32,7 @@ public void test() {
3032
SynchronizationPoint<Exception> spCancel = new SynchronizationPoint<>();
3133
jp.addToJoin(spCancel);
3234
Assert.assertEquals(4, jp.getToJoin());
35+
jp.start();
3336

3437
spOk.unblock();
3538
Assert.assertEquals(3, jp.getToJoin());
@@ -72,8 +75,13 @@ public Integer run() {
7275
JoinPoint<NoException> jp2 = JoinPoint.onAllDone(Collections.singletonList(task));
7376
Assert.assertEquals(1, jp2.getToJoin());
7477
Assert.assertFalse(jp2.isUnblocked());
78+
79+
task.cancel(new CancelException("test"));
80+
Assert.assertTrue(jp.isUnblocked());
81+
Assert.assertTrue(jp.isUnblocked());
7582

7683
JoinPoint.listenInlineOnAllDone(() -> {}, spOk, spError, spCancel);
84+
Threading.debugSynchronization = false;
7785
}
7886

7987
}

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/concurrent/synch/TestSynchronizationPoint.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,30 @@ public void test() throws Exception {
194194

195195
sp = new SynchronizationPoint<>();
196196
sp.onSuccess(onOk);
197+
sp.onError(onError);
198+
sp.onException(onError);
199+
sp.onCancel(onCancel);
197200
sp.unblock();
198201
Assert.assertEquals(9, ok.get());
199202

200203
sp = new SynchronizationPoint<>();
204+
sp.onSuccess(onOk);
201205
sp.onError(onError);
206+
sp.onCancel(onCancel);
202207
sp.error(new Exception());
203208
Assert.assertEquals(6, error.get());
204209

205210
sp = new SynchronizationPoint<>();
211+
sp.onSuccess(onOk);
206212
sp.onException(onError);
213+
sp.onCancel(onCancel);
207214
sp.error(new Exception());
208215
Assert.assertEquals(7, error.get());
209216

210217
sp = new SynchronizationPoint<>();
218+
sp.onSuccess(onOk);
219+
sp.onError(onError);
220+
sp.onException(onError);
211221
sp.onCancel(onCancel);
212222
sp.cancel(new CancelException("test"));
213223
Assert.assertEquals(6, cancel.get());

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/exception/TestExceptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.lecousin.framework.core.test.LCCoreAbstractTest;
44
import net.lecousin.framework.exception.AlreadyExistsException;
55
import net.lecousin.framework.exception.InvalidException;
6+
import net.lecousin.framework.exception.LocalizableException;
67

78
import org.junit.Assert;
89
import org.junit.Test;
@@ -13,6 +14,9 @@ public class TestExceptions extends LCCoreAbstractTest {
1314
public void test() throws Exception {
1415
Assert.assertEquals("Fichier 'test' existe déjà", new AlreadyExistsException("b", "File", "test").getLocalizable().localize("fr").blockResult(0));
1516
Assert.assertEquals("Fichier invalide: test", new InvalidException("b", "File", "test").getLocalizable().localize("fr").blockResult(0));
17+
new LocalizableException("b", "file").getMessage();
18+
new LocalizableException("message", new Exception()).getMessage();
19+
new LocalizableException((String)null).getMessage();
1620
}
1721

1822
}

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/xml/TestDOMModifications.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import javax.xml.parsers.DocumentBuilderFactory;
44
import javax.xml.soap.Node;
55

6+
import net.lecousin.framework.xml.dom.XMLCData;
7+
import net.lecousin.framework.xml.dom.XMLComment;
8+
import net.lecousin.framework.xml.dom.XMLDocument;
9+
import net.lecousin.framework.xml.dom.XMLElement;
10+
import net.lecousin.framework.xml.dom.XMLText;
11+
612
import org.junit.Assert;
713
import org.junit.Test;
814
import org.w3c.dom.Attr;
@@ -12,12 +18,6 @@
1218
import org.w3c.dom.Element;
1319
import org.w3c.dom.Text;
1420

15-
import net.lecousin.framework.xml.dom.XMLCData;
16-
import net.lecousin.framework.xml.dom.XMLComment;
17-
import net.lecousin.framework.xml.dom.XMLDocument;
18-
import net.lecousin.framework.xml.dom.XMLElement;
19-
import net.lecousin.framework.xml.dom.XMLText;
20-
2121
public class TestDOMModifications extends TestDOM {
2222

2323
@Test(timeout=120000)
@@ -50,6 +50,15 @@ public void test() throws Exception {
5050
Assert.assertEquals(Node.DOCUMENT_TYPE_NODE, d.getDoctype().getNodeType());
5151
doc2.getImplementation().hasFeature("test", "1");
5252
doc2.getImplementation().getFeature("test", "1");
53+
Assert.assertTrue(d.getDoctype().isEqualNode(doc2.getImplementation().createDocumentType("toto:tata", "hello", "world")));
54+
Assert.assertTrue(d.getDoctype().isEqualNode(d.getDoctype().cloneNode(true)));
55+
d.getDoctype().getEntities();
56+
d.getDoctype().getNotations();
57+
d.getDoctype().getInternalSubset();
58+
d.getDoctype().getTextContent();
59+
d.getDoctype().setTextContent("");
60+
d = doc2.getImplementation().createDocument(null, "test", null);
61+
Assert.assertEquals("test", d.getDocumentElement().getNodeName());
5362
// create root
5463
Element root1 = doc1.createElement("root");
5564
doc1.appendChild(root1);
@@ -100,6 +109,9 @@ public void test() throws Exception {
100109
root1.setAttributeNS("http://test3", "test3:b", "bb");
101110
root2.setAttributeNS("http://test3", "test3:b", "bb");
102111
checkDocument(doc1, doc2);
112+
Assert.assertTrue(root1.hasAttributeNS("http://test3", "b"));
113+
Assert.assertTrue(root2.hasAttributeNS("http://test3", "b"));
114+
Assert.assertNotNull(root2.getAttributeNS("http://test3", "b"));
103115
// change prefix
104116
root1.getAttributeNodeNS("http://test3", "b").setPrefix("tutu");
105117
root2.getAttributeNodeNS("http://test3", "b").setPrefix("tutu");
@@ -111,6 +123,13 @@ public void test() throws Exception {
111123
// get owner
112124
Assert.assertTrue(root2.getAttributeNodeNS("http://test3", "b").getOwnerElement() == root2);
113125
Assert.assertTrue(root2.getAttributeNodeNS("http://test3", "b").getOwnerDocument() == doc2);
126+
// change value
127+
// TODO root2.setAttributeNodeNS(root2.getAttributeNodeNS("http://test3", "b").cloneNode(true));
128+
// TODO checkDocument(doc1, doc2);
129+
// remove attribute
130+
root1.removeAttributeNode(root1.getAttributeNodeNS("http://test3", "b"));
131+
root2.removeAttributeNode(root2.getAttributeNodeNS("http://test3", "b"));
132+
checkDocument(doc1, doc2);
114133
// add text
115134
Text text1 = doc1.createTextNode("My Text");
116135
XMLText text2 = doc2.createTextNode("My Text");

0 commit comments

Comments
 (0)