001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.adapter.ls.client.test;
034:
035: import junit.framework.TestCase;
036:
037: import org.libresource.so6.adapter.ls.client.soap.ClientISoapImpl;
038: import org.libresource.so6.core.client.ClientI;
039: import org.libresource.so6.core.engine.util.FileUtils;
040:
041: import java.io.File;
042: import java.io.FileWriter;
043:
044: import java.util.Properties;
045:
046: /**
047: * @author molli
048: */
049: public class ClientTest extends TestCase {
050: private ClientI client;
051: private Properties props;
052:
053: public ClientTest(String arg0) {
054: super (arg0);
055: }
056:
057: public static void main(String[] args) {
058: junit.textui.TestRunner.run(ClientTest.class);
059: }
060:
061: protected void setUp() throws Exception {
062: props = new Properties();
063:
064: //
065: props.put(ClientISoapImpl.SERVICE_URL_ENDPOINT,
066: "http://localhost:80/ls-so6/services/so6");
067: props.put(ClientISoapImpl.SO6_QUEUE_ID,
068: "libresource:///projects/libresource/dev");
069: props.put(ClientISoapImpl.SO6_LOGIN, "root");
070: props.put(ClientISoapImpl.SO6_PASSWORD, "root");
071:
072: client = new ClientISoapImpl(props);
073:
074: //client = new DummyClient();
075: }
076:
077: public void testBinExt() throws Exception {
078: client.addBinExt("aaa");
079: client.addBinExt("bbb");
080: client.addBinExt("ccc");
081:
082: String binExt = client.getBinExt();
083:
084: assertTrue(binExt.indexOf("aaa") != -1);
085: assertTrue(binExt.indexOf("bbb") != -1);
086: assertTrue(binExt.indexOf("ccc") != -1);
087:
088: client.removeBinExt("bbb");
089: binExt = client.getBinExt();
090:
091: assertTrue(binExt.indexOf("aaa") != -1);
092: assertTrue(binExt.indexOf("bbb") == -1);
093: assertTrue(binExt.indexOf("ccc") != -1);
094: }
095:
096: public void testPatch() throws Exception {
097: long lastTicket = client.getLastTicket();
098: assertTrue("Shouldn't find ticket: " + lastTicket,
099: lastTicket == 0);
100:
101: String patch = "<?xml version=\"1.0\"?>"
102: + "<patch>"
103: + "<name>momo</name><begin>1</begin><end>1</end>"
104: + "<command><class>org.libresource.so6.command.fs.AddDir</class><ticket>1</ticket><from>momo</from><time>1077878457582</time><path>a</path>"
105: + "</command>" + "</patch>";
106: File f = createPatchFile(1, 1, patch);
107:
108: client.sendPatch(1, 1, f.getAbsolutePath());
109:
110: lastTicket = client.getLastTicket();
111: assertTrue("Shouldn't find 1 ticket: " + lastTicket,
112: lastTicket == 1);
113:
114: long[][] patchList = client.listPatch();
115:
116: assertTrue(
117: "Should find 1 pacth instead of " + patchList.length,
118: patchList.length == 1);
119:
120: String patchFileName = client.getPatch(1);
121: File fDownload = new File(patchFileName);
122:
123: assertTrue("The 2 pacth are different " + patchFileName + " / "
124: + f.getAbsolutePath(), FileUtils.compareBinFile(
125: fDownload, f));
126:
127: patch = "<?xml version=\"1.0\"?>"
128: + "<patch>"
129: + "<name>momo</name><begin>2</begin><end>3</end>"
130: + "<command><class>org.libresource.so6.command.fs.AddDir</class><ticket>2</ticket><from>momo</from><time>1077878457582</time><path>b</path></command>"
131: + "<command><class>org.libresource.so6.command.fs.AddDir</class><ticket>3</ticket><from>momo</from><time>1077878457582</time><path>c</path></command>"
132: + "</patch>";
133: f = createPatchFile(2, 3, patch);
134:
135: client.sendPatch(2, 3, f.getAbsolutePath());
136:
137: patchList = client.listPatch();
138: assertTrue(
139: "Should find 2 pacth instead of " + patchList.length,
140: patchList.length == 2);
141:
142: String patchListString = patchList[0][0] + "."
143: + patchList[0][1] + " " + patchList[1][0] + "."
144: + patchList[1][1];
145: assertTrue("Invalide patch list: " + patchListString,
146: patchListString.equals("2.3 1.1"));
147:
148: lastTicket = client.getLastTicket();
149: assertTrue("Shouldn't find 3 ticket: " + lastTicket,
150: lastTicket == 3);
151: }
152:
153: private File createPatchFile(int from, int to, String content)
154: throws Exception {
155: File d = new File(System.getProperty("java.io.tmpdir")
156: + java.io.File.separator + "patchList");
157: d.mkdirs();
158:
159: File f = new File(d, from + "." + to);
160: f.delete();
161:
162: FileWriter fw = new FileWriter(f);
163: fw.write(content);
164: fw.close();
165:
166: return f;
167: }
168: }
|