xlawrence 2005/05/19 12:54:06 CEST
Added files:
src/test/java/org/jahia/suite/calendar/framework/jms
JMSTransportReceiverTest.java
JMSTransportSenderTest.java
src/test/java/org/jahia/suite/calendar/framework/message
GetCalendarRequestResponseTest.java
GetGUIDRequestResponseTest.java
UpdateCalendarRequestResponseTest.java
src/test/java/org/jahia/suite/calendar/framework/model
CalendarTest.java
src/test/java/org/jahia/suite/calendar/framework/rmi
RMITransportReceiverTest.java
RMITransportSenderTest.java
Log:
Added tests
Revision Changes Path
1.1 +162 -0
uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/jms/JMSTransportReceiverTest.java
(new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/jms/JMSTransportReceiverTest.java?rev=1.1&content-type=text/plain
1.1 +158 -0
uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/jms/JMSTransportSenderTest.java
(new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/jms/JMSTransportSenderTest.java?rev=1.1&content-type=text/plain
1.1 +133 -0
uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/message/GetCalendarRequestResponseTest.java
(new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/message/GetCalendarRequestResponseTest.java?rev=1.1&content-type=text/plain
1.1 +111 -0
uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/message/GetGUIDRequestResponseTest.java
(new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/message/GetGUIDRequestResponseTest.java?rev=1.1&content-type=text/plain
1.1 +135 -0
uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/message/UpdateCalendarRequestResponseTest.java
(new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/message/UpdateCalendarRequestResponseTest.java?rev=1.1&content-type=text/plain
1.1 +166 -0
uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/model/CalendarTest.java
(new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/model/CalendarTest.java?rev=1.1&content-type=text/plain
1.1 +100 -0
uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/rmi/RMITransportReceiverTest.java
(new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/rmi/RMITransportReceiverTest.java?rev=1.1&content-type=text/plain
1.1 +110 -0
uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/rmi/RMITransportSenderTest.java
(new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/test/java/org/jahia/suite/calendar/framework/rmi/RMITransportSenderTest.java?rev=1.1&content-type=text/plain
Index: JMSTransportReceiverTest.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.framework.jms;
import junit.framework.*;
import org.jahia.suite.calendar.framework.TransportReceiver;
import org.jahia.suite.calendar.framework.TransportException;
import org.jahia.suite.calendar.framework.message.Response;
import org.jahia.suite.calendar.framework.message.Request;
import org.jahia.suite.calendar.util.Props;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.Context;
import org.apache.log4j.Logger;
/**
* JUnit based test
*
* @author Xavier Lawrence
*/
public class JMSTransportReceiverTest extends TestCase{
// JMS variables
protected javax.jms.QueueConnectionFactory connFactory;
protected javax.jms.QueueConnection conn;
protected javax.jms.QueueSession qSession;
protected javax.jms.QueueReceiver receiver;
protected javax.jms.Queue receiverQueue;
static int threshold = 3;
int received = 0;
private static Logger log =
Logger.getLogger(JMSTransportReceiverTest.class);
public JMSTransportReceiverTest(String testName) {
super(testName);
}
protected void setUp() throws java.lang.Exception {
try {
Props props = Props.getInstance();
String host = props.getValue(Props.JMS_HOST);
String port = props.getValue(Props.JMS_HOST_JNDI_PORT);
// Create the JNDI context
Hashtable context = new Hashtable(0);
context.put(Context.INITIAL_CONTEXT_FACTORY,
"fr.dyade.aaa.jndi2.client.NamingContextFactory");
context.put("java.naming.factory.host", host);
context.put("java.naming.factory.port", port);
Context jndiCtx = new InitialContext(context);
connFactory = (javax.jms.QueueConnectionFactory)
jndiCtx.lookup(Props.getInstance().getValue(Props.JMS_CONN_NAME));
receiverQueue = (javax.jms.Queue) jndiCtx.lookup(
props.getValue(props.JMS_QUEUE_NAME));
jndiCtx.close();
log.debug("receiverQueue: "+receiverQueue.getQueueName());
// Connect to the JMS Server ...
conn = connFactory.createQueueConnection(
props.getValue(props.JMS_HOST_USERNAME_CAL),
props.getValue(props.JMS_HOST_PASSWORD_CAL));
log.info("Connection started");
// ...and create needed ressources
qSession = conn.createQueueSession(false,
javax.jms.Session.AUTO_ACKNOWLEDGE);
receiver = qSession.createReceiver(receiverQueue);
} catch (Exception e) {
e.printStackTrace();
}
}
protected void tearDown() throws java.lang.Exception {
try {
conn.stop();
receiver.close();
qSession.close();
} catch (Exception e) {
log.debug(e.getMessage());
} finally {
try {
conn.close();
conn = null;
qSession = null;
receiver = null;
} catch (Exception e) {}
}
}
public static junit.framework.Test suite() {
junit.framework.TestSuite suite = new junit.framework.TestSuite(
JMSTransportReceiverTest.class);
return suite;
}
/**
* tests all the features
*/
public void testAll() throws java.lang.Exception {
log.info("testAll");
TransportReceiver tReceiver = new JMSTransportReceiver(conn, qSession,
receiver, receiverQueue);
conn.start();
log.info("TransportReceiver ready, starting tests...");
Request req = tReceiver.receive(5000L);
if (req != null) {
log.info(req);
Response resp = req.makeResponse(2);
tReceiver.sendResponse(resp, req);
assertEquals(resp.getRequestID(), req.getID());
}
}
}
Index: JMSTransportSenderTest.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.framework.jms;
import junit.framework.*;
import org.jahia.suite.calendar.framework.TransportSender;
import org.jahia.suite.calendar.framework.TransportException;
import org.jahia.suite.calendar.framework.message.Response;
import org.jahia.suite.calendar.framework.message.Request;
import org.jahia.suite.calendar.framework.message.GetGUIDRequest;
import org.jahia.suite.calendar.framework.message.Message;
import org.jahia.suite.calendar.framework.message.MessageListener;
import org.jahia.suite.calendar.util.Props;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.Context;
import org.apache.log4j.Logger;
/**
* JUnit based test
*
* @author Xavier Lawrence
*/
public class JMSTransportSenderTest extends TestCase implements
MessageListener {
// JMS variables
protected javax.jms.QueueConnectionFactory connFactory;
protected javax.jms.QueueConnection conn;
protected javax.jms.QueueSession qSession;
protected javax.jms.QueueSender sender;
protected javax.jms.Queue senderQueue;
private static Logger log =
Logger.getLogger(JMSTransportSenderTest.class);
public JMSTransportSenderTest(String testName) {
super(testName);
}
protected void setUp() {
try {
Props props = Props.getInstance();
String host = props.getValue(Props.JMS_HOST);
String port = props.getValue(Props.JMS_HOST_JNDI_PORT);
// Create the JNDI context
Hashtable context = new Hashtable(0);
context.put(Context.INITIAL_CONTEXT_FACTORY,
"fr.dyade.aaa.jndi2.client.NamingContextFactory");
context.put("java.naming.factory.host", host);
context.put("java.naming.factory.port", port);
Context jndiCtx = new InitialContext(context);
connFactory = (javax.jms.QueueConnectionFactory)
jndiCtx.lookup(Props.getInstance().getValue(Props.JMS_CONN_NAME));
senderQueue = (javax.jms.Queue) jndiCtx.lookup(
props.getValue(props.JMS_QUEUE_NAME));
jndiCtx.close();
log.debug("senderQueue: "+senderQueue.getQueueName());
// Connect to the JMS Server ...
conn = connFactory.createQueueConnection(
props.getValue(props.JMS_HOST_USERNAME_CAL),
props.getValue(props.JMS_HOST_PASSWORD_CAL));
log.info("Connection started");
// ...and create needed ressources
qSession = conn.createQueueSession(false,
javax.jms.Session.AUTO_ACKNOWLEDGE);
sender = qSession.createSender(senderQueue);
} catch (Exception e) {
e.printStackTrace();
}
}
protected void tearDown() throws java.lang.Exception {
try {
conn.stop();
sender.close();
} catch (Exception e) {
log.debug(e.getMessage());
} finally {
try {
conn.close();
} catch (Exception e) {}
}
}
public static junit.framework.Test suite() {
junit.framework.TestSuite suite = new junit.framework.TestSuite(
JMSTransportSenderTest.class);
return suite;
}
/**
* tests all the features
*/
public void testAll() throws java.lang.Exception {
log.info("testAll");
TransportSender transportSender = new JMSTransportSender(conn,
qSession, sender,
senderQueue);
conn.start();
log.info("TransportSender ready, starting tests...");
Request req = new GetGUIDRequest(1);
transportSender.sendRequest(req);
Thread.currentThread().sleep(5000);
}
public void messageReceived(Message msg) {
log.info("Message Received:");
log.info(msg);
}
}
Index: GetCalendarRequestResponseTest.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.framework.message;
import junit.framework.*;
import org.jahia.suite.calendar.framework.model.Calendar;
import org.jahia.suite.calendar.framework.model.SyncEvent;
import org.jahia.suite.calendar.framework.model.GUID;
import org.jahia.suite.calendar.framework.message.GetCalendarRequest;
import org.jahia.suite.calendar.framework.message.GetCalendarRequestResponse;
import java.sql.Timestamp;
import org.apache.log4j.Logger;
/**
* JUnit based test
*
* @author Xavier Lawrence
*/
public class GetCalendarRequestResponseTest extends TestCase {
private static Logger log =
Logger.getLogger(GetCalendarRequestResponseTest.class);
private GetCalendarRequest request;
private GetCalendarRequestResponse response;
private Calendar calendar;
private SyncEvent[] events;
public GetCalendarRequestResponseTest(String testName) {
super(testName);
}
protected void setUp() throws java.lang.Exception {
request = new GetCalendarRequest(1, "aUserName", "aDeviceID",
new Timestamp(System.currentTimeMillis()));
SyncEvent[] tmp = {new SyncEvent(new GUID("guid1"),
"aFirstContent".getBytes(), SyncEvent.UNKNOWN),
new SyncEvent(new GUID("guid2"),
"aSecondContent".getBytes(), SyncEvent.NEW),
new SyncEvent(new GUID("guid3"),
"aThirdContent".getBytes(), SyncEvent.MODIFIED)
};
events = tmp;
calendar = new Calendar(events);
response = (GetCalendarRequestResponse)request.makeResponse(2,
"aResponse", calendar);
}
protected void tearDown() throws java.lang.Exception {
request = null;
response = null;
}
public static junit.framework.Test suite() {
junit.framework.TestSuite suite = new junit.framework.TestSuite(
GetCalendarRequestResponseTest.class);
return suite;
}
/**
* Test of getCalendar method, of class
org.jahia.suite.calendar.framework.message.GetCalendarRequestResponse.
*/
public void testGetCalendar() {
log.info("testGetCalendar");
Calendar cal = response.getCalendar();
assertEquals(cal, calendar);
}
/**
* Test of getType method, of class
org.jahia.suite.calendar.framework.message.GetCalendarRequestResponse.
*/
public void testGetType() {
log.info("testGetType");
String type = response.getType();
assertEquals(type, GetCalendarRequestResponse.TYPE);
}
/**
*
*/
public void testMakeResponse() {
log.info("testMakeResponse");
String reqId = response.getRequestID();
assertEquals(reqId, request.getID());
}
}
Index: GetGUIDRequestResponseTest.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.framework.message;
import junit.framework.*;
import org.jahia.suite.calendar.framework.model.GUID;
import org.jahia.suite.calendar.framework.message.GetGUIDRequest;
import org.jahia.suite.calendar.framework.message.GetGUIDRequestResponse;
import org.apache.log4j.Logger;
/**
* JUnit based test
*
* @author Xavier Lawrence
*/
public class GetGUIDRequestResponseTest extends TestCase {
private static Logger log =
Logger.getLogger(GetGUIDRequestResponseTest.class);
private GetGUIDRequest request;
private GetGUIDRequestResponse response;
private GUID guid;
public GetGUIDRequestResponseTest(String testName) {
super(testName);
}
protected void setUp() throws java.lang.Exception {
request = new GetGUIDRequest(1);
guid = new GUID("GUID1");
response = (GetGUIDRequestResponse)request.makeResponse(2, guid);
}
protected void tearDown() throws java.lang.Exception {
}
public static junit.framework.Test suite() {
junit.framework.TestSuite suite = new
junit.framework.TestSuite(GetGUIDRequestResponseTest.class);
return suite;
}
/**
* Test of getType method, of class
org.jahia.suite.calendar.framework.message.GetGUIDRequestResponse.
*/
public void testGetType() {
log.info("testGetType");
String type = response.getType();
assertEquals(type, GetGUIDRequestResponse.TYPE);
}
/**
* Test of getGUID method, of class
org.jahia.suite.calendar.framework.message.GetGUIDRequestResponse.
*/
public void testGetGUID() {
log.info("testGetGUID");
GUID key = response.getGUID();
assertEquals(guid, key);
}
/**
*
*/
public void testMakeResponse() {
log.info("testMakeResponse");
String reqId = response.getRequestID();
assertEquals(reqId, request.getID());
}
}
Index: UpdateCalendarRequestResponseTest.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.framework.message;
import junit.framework.*;
import org.jahia.suite.calendar.framework.model.SyncOperation;
import org.jahia.suite.calendar.framework.model.SyncEvent;
import org.jahia.suite.calendar.framework.model.GUID;
import org.jahia.suite.calendar.framework.message.UpdateCalendarRequest;
import
org.jahia.suite.calendar.framework.message.UpdateCalendarRequestResponse;
import org.apache.log4j.Logger;
/**
* JUnit based test
*
* @author Xavier Lawrence
*/
public class UpdateCalendarRequestResponseTest extends TestCase {
private static Logger log = Logger.getLogger(
UpdateCalendarRequestResponseTest.class);
private UpdateCalendarRequest request;
private UpdateCalendarRequestResponse response;
private SyncOperation[] ops;
public UpdateCalendarRequestResponseTest(String testName) {
super(testName);
}
protected void setUp() throws java.lang.Exception {
SyncOperation[] tmp = {new SyncOperation(SyncOperation.ADD,
new SyncEvent(new GUID("guid1"), "event1".getBytes(),
SyncEvent.SYNCHRONIZED)),
new SyncOperation(SyncOperation.MODIFY,
new SyncEvent(new GUID("guid2"), "event2".getBytes(),
SyncEvent.SYNCHRONIZED))
};
ops = tmp;
request = new UpdateCalendarRequest(1, "cal1", ops);
response = (UpdateCalendarRequestResponse)request.makeResponse(2,
UpdateCalendarRequestResponse.OK);
}
protected void tearDown() throws java.lang.Exception {
}
public static junit.framework.Test suite() {
junit.framework.TestSuite suite = new junit.framework.TestSuite(
UpdateCalendarRequestResponseTest.class);
return suite;
}
/**
* Test of getType method, of class
org.jahia.suite.calendar.framework.message.UpdateCalendarRequestResponse.
*/
public void testGetType() {
log.info("testGetType");
String type = response.getType();
assertEquals(type, UpdateCalendarRequestResponse.TYPE);
}
/**
* Test of getStatus method, of class
org.jahia.suite.calendar.framework.message.UpdateCalendarRequestResponse.
*/
public void testGetStatus() {
log.info("testGetStatus");
int status = response.getStatus();
assertEquals(UpdateCalendarRequestResponse.OK, status);
}
/**
*
*/
public void testGetOperations() {
log.info("testGetOperations");
assertEquals(2, request.getOperations().length);
}
/**
*
*/
public void testMakeResponse() {
log.info("testMakeResponse");
String reqId = response.getRequestID();
assertEquals(reqId, request.getID());
}
}
Index: CalendarTest.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.framework.model;
import junit.framework.*;
import java.io.Serializable;
import java.util.Vector;
import org.jahia.suite.calendar.framework.model.Calendar;
import org.jahia.suite.calendar.framework.model.SyncEvent;
import org.jahia.suite.calendar.framework.model.GUID;
import org.apache.log4j.Logger;
/**
* JUnit based test
*
* @author Xavier Lawrence
*/
public class CalendarTest extends TestCase {
private static Logger log = Logger.getLogger(CalendarTest.class);
private Calendar calendar;
private SyncEvent newEvent;
private SyncEvent modEvent;
private SyncEvent event;
private SyncEvent[] events;
public CalendarTest(String testName) {
super(testName);
}
protected void setUp() throws java.lang.Exception {
event = new SyncEvent(new GUID("guid1"),
"aFirstContent".getBytes(), SyncEvent.UNKNOWN);
newEvent = new SyncEvent(new GUID("guid2"),
"aSecondContent".getBytes(), SyncEvent.NEW);
modEvent = new SyncEvent(new GUID("guid3"),
"aThirdContent".getBytes(), SyncEvent.MODIFIED);
SyncEvent[] tmp = {event, newEvent, modEvent};
calendar = new Calendar(tmp);
events = tmp;
}
public static junit.framework.Test suite() {
junit.framework.TestSuite suite = new
junit.framework.TestSuite(CalendarTest.class);
return suite;
}
/**
* Test of getEvents method, of class
org.jahia.suite.calendar.framework.model.Calendar.
*/
public void testGetEvents() {
log.info("testGetEvents");
SyncEvent[] evs = calendar.getEvents();
assertEquals(event, evs[0]);
assertEquals(newEvent, evs[1]);
assertEquals(modEvent, evs[2]);
}
/**
* Test of getEvent method, of class
org.jahia.suite.calendar.framework.model.Calendar.
*/
public void testGetEvent() {
log.info("testGetEvent");
SyncEvent ev = calendar.getEvent(event.getKey().getKey());
assertEquals(event, ev);
}
/**
* Test of addEvent method, of class
org.jahia.suite.calendar.framework.model.Calendar.
*/
public void testAddEvent() {
log.info("testAddEvent");
SyncEvent addedEvent = new SyncEvent(new GUID("guid4"), "4th
event".getBytes(),
SyncEvent.NEW);
calendar.addEvent(addedEvent);
assertEquals(calendar.getEvent(addedEvent.getKey().getKey()),
addedEvent);
}
/**
* Test of replaceEvent method, of class
org.jahia.suite.calendar.framework.model.Calendar.
*/
public void testReplaceEvent() {
log.info("testReplaceEvent");
SyncEvent modEvent = new SyncEvent(new GUID(event.getKey().getKey()),
"MODIFIED EVENT".getBytes(), SyncEvent.MODIFIED);
calendar.replaceEvent(modEvent);
assertEquals(modEvent, calendar.getEvent(event.getKey().getKey()));
}
/**
* Test of removeEvent method, of class
org.jahia.suite.calendar.framework.model.Calendar.
*/
public void testRemoveEvent() {
log.info("testRemoveEvent");
calendar.removeEvent(event);
assertEquals(2, calendar.getEvents().length);
assertNull(calendar.getEvent(event.getKey().getKey()));
}
/**
* Test of equals method, of class
org.jahia.suite.calendar.framework.model.Calendar.
*/
public void testEquals() {
log.info("testEquals");
Calendar calendar2 = new Calendar(events);
assertTrue(calendar.equals(calendar) && calendar.equals(calendar2));
}
}
Index: RMITransportReceiverTest.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.framework.rmi;
import org.jahia.suite.calendar.framework.TransportReceiver;
import org.jahia.suite.calendar.framework.TransportException;
import org.jahia.suite.calendar.framework.message.Response;
import org.jahia.suite.calendar.framework.message.Request;
import org.jahia.suite.calendar.framework.message.GetGUIDRequestResponse;
import org.jahia.suite.calendar.framework.message.GetGUIDRequest;
import org.jahia.suite.calendar.framework.message.MessageListener;
import org.apache.log4j.Logger;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
/**
*
* @author Xavier Lawrence
*/
public class RMITransportReceiverTest {
private static Logger log =
Logger.getLogger(RMITransportReceiverTest.class);
private TransportReceiver transportReceiver;
private long timeout = 10000L;
private int number = 3;
/**
* tests all the features
*/
public void start() throws Exception {
log.info("Starting RMITransportReceiverTest...");
transportReceiver = new RMITransportReceiver(1100);
log.info("Waiting for "+number+" request(s) with a timeout of "+
timeout +" ms and then will stop");
for (int i = 0; i<number; i++) {
Request req = transportReceiver.receive(timeout);
if (req != null) {
log.info("Received Request !");
log.info(req);
Response resp = req.makeResponse((i+1));
transportReceiver.sendResponse(resp, req);
} else {
log.info("Didn't receive request after: "+ timeout +" ms !");
log.info("Still waiting for "+ (number-i-1) +" request(s)");
}
}
log.info("Good bye !");
}
public static void main(String[] args) throws Exception {
RMITransportReceiverTest test = new RMITransportReceiverTest();
test.start();
System.exit(0);
}
}
Index: RMITransportSenderTest.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.framework.rmi;
import org.jahia.suite.calendar.framework.message.Request;
import org.jahia.suite.calendar.framework.message.GetGUIDRequest;
import org.jahia.suite.calendar.framework.message.MessageListener;
import org.jahia.suite.calendar.framework.message.Message;
import org.jahia.suite.calendar.framework.TransportSender;
import org.apache.log4j.Logger;
/**
*
* @author Xavier Lawrence
*/
public class RMITransportSenderTest implements MessageListener {
private static Logger log =
Logger.getLogger(RMITransportSenderTest.class);
private TransportSender transportSender;
private long timeout = 10000L;
/**
* tests all the features
*/
public void start(boolean sync) throws Exception {
log.info("Starting RMITransportSenderTest...");
transportSender = new RMITransportSender("localhost", 1100);
if (!sync) transportSender.setMessageListener(this);
Request req = new GetGUIDRequest(1);
if (sync) {
log.info("Testing the Synchronous call...");
log.info("Sending Request...");
Message resp = transportSender.sendAndGetResponse(req);
log.info("Response Received !");
log.info(resp);
} else {
log.info("Testing the Asynchronous call...");
transportSender.sendRequest(req);
log.info("Request sent !");
log.info("Waiting for "+ timeout +" ms to get a Response");
Thread.currentThread().sleep(timeout);
}
log.info("good bye !");
System.exit(0);
}
public void messageReceived(Message msg) {
log.info("Response Received !");
log.info(msg);
}
public static void main (String[] args) throws Exception {
boolean sync = false;
if (args != null && args.length > 0) {
if (args[0].toLowerCase().equals("true")) {
sync = true;
}
}
RMITransportSenderTest test = new RMITransportSenderTest();
test.start(sync);
}
}