You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(13) |
Aug
(151) |
Sep
(21) |
Oct
(6) |
Nov
(70) |
Dec
(8) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(47) |
Feb
(66) |
Mar
(23) |
Apr
(115) |
May
(24) |
Jun
(53) |
Jul
(10) |
Aug
(279) |
Sep
(84) |
Oct
(149) |
Nov
(138) |
Dec
(52) |
2003 |
Jan
(22) |
Feb
(20) |
Mar
(29) |
Apr
(106) |
May
(170) |
Jun
(122) |
Jul
(70) |
Aug
(64) |
Sep
(27) |
Oct
(71) |
Nov
(49) |
Dec
(9) |
2004 |
Jan
(7) |
Feb
(38) |
Mar
(3) |
Apr
(9) |
May
(22) |
Jun
(4) |
Jul
(1) |
Aug
(2) |
Sep
(2) |
Oct
|
Nov
(15) |
Dec
(2) |
2005 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
(1) |
May
(28) |
Jun
(3) |
Jul
(11) |
Aug
(5) |
Sep
(1) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
2006 |
Jan
(8) |
Feb
(3) |
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Radirs <ra...@re...> - 2001-12-14 08:28:37
|
Hi All:=0D=0A Iam using MockObjects in our project. We have made a mock sy= stem=0D=0A(database) and are populating this MO by inputting data in to the= =0D=0AMockResultSet and stuff like that.And all these MO codes resides in t= he test=0D=0Amethod of the test class(written for the class under test) and= the test is=0D=0Aworking fine.=0D=0A=0D=0ARequirement : =0D=0A To get t= he data from the Mock system (remember the MO=0D=0Acoding[instantiation and= initialization] is done in the test class) and=0D=0Adisplay on to the brow= ser using jsp's.(similar to getting the values from=0D=0Athe database and d= isplaying on to the screen).=0D=0A=0D=0AMy Questions are : =0D=0A1) Is ther= e any way this(refer Requirement) can be done?if yes, How this can=0D=0Abe = accomplished?=0D=0A2) Are there any steps to be followed ,specific to MO,if= we need to=0D=0Aintegrate MO into any propreitary framework?=0D=0A=0D=0AIt= will be really helpful to me if anybody cud suggest a solution for the=0D= =0Aabove.=0D=0A=0D=0AThanks in advance,=0D=0A=0D=0ARad. =0A |
From: Steve F. <st...@m3...> - 2001-12-05 21:09:10
|
apologies to all and sundry for not responding to your patches/proposals/whatever. Been a bit busy recently _and_ had to rebuild because of a virus :-( Back real soon now, Steve |
From: Jeff M. <je...@mk...> - 2001-12-05 12:21:52
|
Just thought I'd mention that the link API Reference which points to http://www.mockobjects.com/javadoc/index.html is broken as the is no javadoc dir. |
From: <Aar...@vo...> - 2001-11-30 03:51:43
|
I have modified a few classes in the java.sql package to give better integration of the Statement and ResultSet implementations. To summarize the changes I have made: * MockPreparedStatement.execute() returns true if a ResultSet has been set via setupResultSet(), otherwise false. * MockStatement.getResultSet returns the ResultSet that was set via setupResultSet() and also sets the ResultSet to null (so the next call does not get the same ResultSet again). * MockPreparedStatement.setupResultSet() now calls MockResultSet.setupStatement(this) * PreparedStatement.setObject(int index, Object obj, int Type) now works. It also tests to see that the specified object can be mapped to the specified type without some kind of conversion (so no longs going into TINYINT fields, but bytes into INTEGER fields are OK). The Mapping could be done better (and may not be entirely correct) but it is a start. Here are the diffs for the changed files. The extra file is attached. Let me know the format you would prefer contributions in for next time. Cheers ADK (See attached file: SQLTypeMap.java) --- MockStatement.java Fri Nov 30 15:06:48 2001 +++ /d/temp/mockobjects-0.01-orig/src/com/mockobjects/sql/MockStatement.java Sun Aug 12 22:52:50 2001 @@ -30,7 +30,6 @@ } public void setupResultSet(MockResultSet aResultSet) { - aResultSet.setupStatement(this); myResultSet = aResultSet; } @@ -42,13 +41,11 @@ myUpdateCount = updateCount; } - protected boolean innerExecute() throws SQLException { + protected void innerExecute() throws SQLException { myExecuteCalls.inc(); if (null != myExecuteException) { throw myExecuteException; } - - return (myResultSet != null); } public void close() throws SQLException { @@ -116,9 +113,7 @@ } public ResultSet getResultSet() throws SQLException { - ResultSet result = myResultSet; - myResultSet = null; - return result; + throw new UnsupportedOperationException(); } public int getUpdateCount() throws SQLException { --- MockPreparedStatement.java Fri Nov 30 13:46:15 2001 +++ /d/temp/mockobjects-0.01-orig/src/com/mockobjects/sql/MockPreparedStatement.java Sun Aug 12 22:52:50 2001 @@ -9,8 +9,7 @@ public class MockPreparedStatement extends MockStatement implements PreparedStatement { private ExpectationSet mySetParameters = new ExpectationSet ("MockPreparedStatement.setParameters"); private ExpectationCounter myClearParametersCalls = new ExpectationCounter("MockPreparedStatement.clearParameters() calls"); - private SQLTypeMap mySQLTypeMap = new SQLTypeMap(); - + public MockPreparedStatement() { super(); } @@ -41,7 +40,8 @@ } public boolean execute() throws SQLException { - return innerExecute(); + innerExecute(); + return false; } public void setExpectedClearParametersCalls(int callCount) { @@ -105,12 +105,7 @@ } public void setObject(int param, Object obj, int targetSqlType) throws SQLException { - assertTrue("Invalid type mapping: " + obj.getClass().getName() + " to: " + targetSqlType, mySQLTypeMap.canMap(obj.getClass(), targetSqlType)); - mySetParameters.addActual(new MapEntry(new Integer(param), obj)); - } - - public void setObject(int param, Object obj) throws SQLException { - mySetParameters.addActual(new MapEntry(new Integer(param), obj)); + throw new UnsupportedOperationException(); } public void setRef(int param, Ref ref) throws SQLException { @@ -151,6 +146,10 @@ public void setBytes(int param, byte[] values) throws SQLException { setObject(param, values); + } + + public void setObject(int param, Object obj) throws SQLException { + mySetParameters.addActual(new MapEntry(new Integer(param), obj)); } public void setByte(int param, byte aByte) throws SQLException { CAUTION: This correspondence is confidential and intended for the named recipient(s) only. If you are not the named recipient and receive this correspondence in error, you must not copy, distribute or take any action in reliance on it and you should delete it from your system and notify the sender immediately. Thank you. Unless otherwise stated, any views or opinions expressed are solely those of the author and do not represent those of Vodafone New Zealand Limited. Vodafone New Zealand Limited 21 Pitt Street, Private Bag 92161, Auckland, 1020, New Zealand Telephone + 64 9 357 5100 Facsimile + 64 9 377 0962 |
From: King D. <Ki...@tc...> - 2001-11-29 15:04:47
|
I have started some work on creating a Mock Objects framework for C++ and was wondering if anyone was interested in assisting? Unfortunately Java is much nicer for this sort of thing (reflection is a god-send for this sort of stuff). You can email me directly with any thoughts at Ki...@TC... |
From: <rin...@me...> - 2001-11-26 10:09:29
|
Dear fellow mockers, My company is in the process of automating the build, test and deploy process for our Java products. There are a number of third party libraries we use in our products, and for testing purposes, the Mock Objects package is one of them. We have a system in place that checks out the required libraries (JARs only) if they are not available locally. However, the Mock Objects framework does not have a tagged JAR file in the CVS repository. Would it be possible to check in (one or more) JAR file(s) and also label it (them) when creating an official release? Ringo |
From: Steve F. <sm...@us...> - 2001-11-22 00:08:14
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/com/mockobjects/servlet In directory usw-pr-cvs1:/tmp/cvs-serv8160/servlet Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/j2ee/com/mockobjects/servlet added to the repository |
From: Steve F. <sm...@us...> - 2001-11-22 00:08:13
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/com/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv7715/mockobjects Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/j2ee/com/mockobjects added to the repository |
From: Steve F. <sm...@us...> - 2001-11-22 00:08:13
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/com/mockobjects/jms In directory usw-pr-cvs1:/tmp/cvs-serv7985/jms Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/j2ee/com/mockobjects/jms added to the repository |
From: Steve F. <sm...@us...> - 2001-11-22 00:08:11
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/com In directory usw-pr-cvs1:/tmp/cvs-serv7043/com Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/j2ee/com added to the repository |
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/com/mockobjects/jms In directory usw-pr-cvs1:/tmp/cvs-serv9080/com/mockobjects/jms Added Files: MockConnection.java MockMessage.java MockMessageConsumer.java MockMessageProducer.java MockQueue.java MockQueueConnection.java MockQueueConnectionFactory.java MockQueueReceiver.java MockQueueSender.java MockQueueSession.java MockSession.java MockTemporaryQueue.java MockTextMessage.java Log Message: started j2ee section --- NEW FILE: MockConnection.java --- package com.mockobjects.jms; import javax.jms.Connection; import javax.jms.ConnectionMetaData; import javax.jms.ExceptionListener; import javax.jms.JMSException; import com.mockobjects.ExpectationCounter; import com.mockobjects.MockObject; public class MockConnection extends MockObject implements Connection { protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockConnection.close"); protected ExpectationCounter myStartCalls = new ExpectationCounter("MockConnection.start"); protected ExpectationCounter myStopCalls = new ExpectationCounter("MockConnection.stop"); private JMSException myException; public MockConnection() { } public void close() throws JMSException { myCloseCalls.inc(); throwExceptionIfAny(); } public String getClientID() throws JMSException { notImplemented(); return null; } public ExceptionListener getExceptionListener() throws JMSException { notImplemented(); return null; } public ConnectionMetaData getMetaData() throws JMSException { notImplemented(); return null; } public void setClientID(String clientID) throws JMSException { notImplemented(); } public void setExceptionListener(ExceptionListener listener) throws JMSException { //does nothing } public void start() throws JMSException { myStartCalls.inc(); throwExceptionIfAny(); } public void stop() throws JMSException { myStopCalls.inc(); throwExceptionIfAny(); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setExpectedStartCalls(int callCount) { myStartCalls.setExpected(callCount); } public void setExpectedStopCalls(int callCount) { myStopCalls.setExpected(callCount); } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockMessage.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public abstract class MockMessage extends MockObject implements Message { protected ExpectationValue myJMSReplyTo = new ExpectationValue("MockMessage.setJMSReplyTo"); protected ExpectationCounter mySetJMSCorrelationIDCalls = new ExpectationCounter("MockMessage.setJMSCorrelationID"); private JMSException myException; /** * Used for both messageID and correlationID */ private String myJMSMessageID; public MockMessage() { } public void acknowledge() throws JMSException { notImplemented(); } public void clearBody() { notImplemented(); } public void clearProperties() { notImplemented(); } public boolean getBooleanProperty(String name) { notImplemented(); return false; } public byte getByteProperty(String name) { notImplemented(); return 0; } public double getDoubleProperty(String name) { notImplemented(); return 0; } public float getFloatProperty(String name) { notImplemented(); return 0; } public int getIntProperty(String name) { notImplemented(); return 0; } public String getJMSCorrelationID() { return myJMSMessageID; } public byte[] getJMSCorrelationIDAsBytes() { notImplemented(); return null; } public int getJMSDeliveryMode() { notImplemented(); return 0; } public Destination getJMSDestination() { notImplemented(); return null; } public long getJMSExpiration() { notImplemented(); return 0; } public String getJMSMessageID() { return myJMSMessageID; } public int getJMSPriority() { notImplemented(); return 0; } public boolean getJMSRedelivered() { notImplemented(); return false; } public Destination getJMSReplyTo() { notImplemented(); return null; } public long getJMSTimestamp() { notImplemented(); return 0; } public String getJMSType() { notImplemented(); return null; } public long getLongProperty(String name) { notImplemented(); return 0; } public Object getObjectProperty(String name) { notImplemented(); return null; } public java.util.Enumeration getPropertyNames() { notImplemented(); return null; } public short getShortProperty(String name) { notImplemented(); return 0; } public String getStringProperty(String name) { notImplemented(); return null; } public boolean propertyExists(String name) { notImplemented(); return false; } public void setBooleanProperty(String name, boolean value) { notImplemented(); } public void setByteProperty(String name, byte value) { notImplemented(); } public void setDoubleProperty(String name, double value) { notImplemented(); } public void setFloatProperty(String name, float value) { notImplemented(); } public void setIntProperty(String name, int value) { notImplemented(); } public void setJMSCorrelationID(String jmsCorrelationID) { mySetJMSCorrelationIDCalls.inc(); } public void setJMSCorrelationIDAsBytes(byte[] correlationID) { notImplemented(); } public void setJMSDeliveryMode(int deliveryMode) { notImplemented(); } public void setJMSDestination(Destination destination) { notImplemented(); } public void setJMSExpiration(long expiration) { notImplemented(); } public void setJMSMessageID(String id) { notImplemented(); } public void setJMSPriority(int priority) { notImplemented(); } public void setJMSRedelivered(boolean redelivered) { notImplemented(); } public void setJMSReplyTo(Destination replyTo) throws JMSException { throwExceptionIfAny(); myJMSReplyTo.setActual(replyTo); } public void setJMSTimestamp(long timestamp) { notImplemented(); } public void setJMSType(String type) { notImplemented(); } public void setLongProperty(String name, long value) { notImplemented(); } public void setObjectProperty(String name, Object value) { notImplemented(); } public void setShortProperty(String name, short value) { notImplemented(); } public void setStringProperty(String name, String value) { notImplemented(); } public void setExpectedJMSReplyTo(Destination expectedJMSReplyTo) { myJMSReplyTo.setExpected(expectedJMSReplyTo); } public void setExpectedSetJMSCorrelationIDCalls(int callCount) { mySetJMSCorrelationIDCalls.setExpected(callCount); } public void setupJMSMessageID(String jmsMessageID) { myJMSMessageID = jmsMessageID; } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockMessageConsumer.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public abstract class MockMessageConsumer extends MockObject implements MessageConsumer { protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockMessageConsumer.close"); protected ExpectationCounter myReceiveCalls = new ExpectationCounter("MockMessageConsumer.receive"); private Message myMessage; private boolean myExpiresOnTimeout = false; private JMSException myException; public MockMessageConsumer() { } public void close() throws JMSException { throwExceptionIfAny(); myCloseCalls.inc(); } public MessageListener getMessageListener() throws JMSException { notImplemented(); return null; } public String getMessageSelector() throws JMSException { notImplemented(); return null; } public Message receive() throws JMSException { throwExceptionIfAny(); myReceiveCalls.inc(); if (myExpiresOnTimeout) { synchronized(this) { try { wait(); } catch (InterruptedException e) { throw new junit.framework.AssertionFailedError("Thread interrupted"); } } } return myMessage; } public Message receive(long timeout) throws JMSException { throwExceptionIfAny(); myReceiveCalls.inc(); if (myExpiresOnTimeout) { return null; } else { return myMessage; } } public Message receiveNoWait() throws JMSException { throwExceptionIfAny(); myReceiveCalls.inc(); return myMessage; } public void setMessageListener(MessageListener listener) throws JMSException { notImplemented(); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setExpectedReceiveCalls(int callCount) { myReceiveCalls.setExpected(callCount); } public void setupReceivedMessage(Message message) { myMessage = message; } public void setupExpiresOnTimeout(boolean expiresOnTimeout) { myExpiresOnTimeout = expiresOnTimeout; } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockMessageProducer.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public abstract class MockMessageProducer extends MockObject implements MessageProducer { protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockMessageConsumer.close"); private JMSException myException; public MockMessageProducer() { } public void close() throws JMSException { myCloseCalls.inc(); } public int getDeliveryMode() throws JMSException { notImplemented(); return 0; } public boolean getDisableMessageID() throws JMSException { notImplemented(); return false; } public boolean getDisableMessageTimestamp() throws JMSException { notImplemented(); return false; } public int getPriority() throws JMSException { notImplemented(); return 0; } public long getTimeToLive() throws JMSException { notImplemented(); return 0l; } public void setDeliveryMode(int deliveryMode) throws JMSException { notImplemented(); } public void setDisableMessageID(boolean value) throws JMSException { notImplemented(); } public void setDisableMessageTimestamp(boolean value) throws JMSException { notImplemented(); } public void setPriority(int defaultPriority) throws JMSException { notImplemented(); } public void setTimeToLive(long timeToLive) throws JMSException { notImplemented(); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockQueue.java --- package com.mockobjects.jms; import javax.jms.JMSException; import javax.jms.Queue; import com.mockobjects.MockObject; public class MockQueue extends MockObject implements Queue { private JMSException myException; private String myName; public MockQueue(String name) { myName = name; } public String getQueueName() throws JMSException { throwExceptionIfAny(); return myName; } public boolean equals(Object object) { if (!(object instanceof Queue)) return false; try { return myName.equals(((Queue) object).getQueueName()); } catch (JMSException e) { throw new junit.framework.AssertionFailedError( "JMSException caught while getting actual queue name"); } } public int hashCode() { return myName.hashCode(); } public String toString() { return this.getClass().getName() + ", " + myName; } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockQueueConnection.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueConnection extends MockConnection implements QueueConnection { private QueueSession myQueueSession; public MockQueueConnection() { } public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int mexMessages) throws JMSException { notImplemented(); return null; } public QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException { throwExceptionIfAny(); return myQueueSession; } public void setupQueueSession(QueueSession queueSession) { myQueueSession = queueSession; } } --- NEW FILE: MockQueueConnectionFactory.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueConnectionFactory extends MockObject implements QueueConnectionFactory { protected ExpectationValue myUserName = new ExpectationValue("MockQueueConnectionFactory.createQueueConnection"); protected ExpectationValue myPassword = new ExpectationValue("MockQueueConnectionFactory.createQueueConnection"); private JMSException myException; private QueueConnection myQueueConnection; public MockQueueConnectionFactory() { } public QueueConnection createQueueConnection() throws JMSException { throwExceptionIfAny(); return myQueueConnection; } public QueueConnection createQueueConnection(String userName, String password) throws JMSException { throwExceptionIfAny(); myUserName.setActual(userName); myPassword.setActual(password); return myQueueConnection; } public void setExpectedUserName(String userName) { myUserName.setExpected(userName); } public void setExpectedPassword(String password) { myPassword.setExpected(password); } public void setupQueueConnection(QueueConnection queueConnection) { myQueueConnection = queueConnection; } public void setupThrowException(JMSException e) { myException = e; } private void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockQueueReceiver.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueReceiver extends MockMessageConsumer implements QueueReceiver { public MockQueueReceiver() { } public Queue getQueue() { notImplemented(); return null; } } --- NEW FILE: MockQueueSender.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueSender extends MockMessageProducer implements QueueSender { protected ExpectationCounter mySendCalls = new ExpectationCounter("MockQueueSender.send"); public MockQueueSender() { } public Queue getQueue() throws JMSException { notImplemented(); return null; } public void send(Message message) throws JMSException { mySendCalls.inc(); throwExceptionIfAny(); } public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { notImplemented(); } public void send(Queue queue, Message message) throws JMSException { notImplemented(); } public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { notImplemented(); } public void setExpectedSendCalls(int callCount) { mySendCalls.setExpected(callCount); } } --- NEW FILE: MockQueueSession.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueSession extends MockSession implements QueueSession { protected ExpectationValue mySendingQueue = new ExpectationValue("MockQueueSession.createSender"); protected ExpectationValue myReceivingQueue = new ExpectationValue("MockQueueSession.createReceiver"); private QueueReceiver myReceiver; private QueueSender mySender; private TemporaryQueue myTemporaryQueue; public MockQueueSession() { } public QueueBrowser createBrowser(Queue queue) throws JMSException { notImplemented(); return null; } public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException { notImplemented(); return null; } public Queue createQueue(String queueName) throws JMSException { throwExceptionIfAny(); return new MockQueue(queueName); } public QueueReceiver createReceiver(Queue queue) throws JMSException { throwExceptionIfAny(); myReceivingQueue.setActual(queue); return myReceiver; } public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException { myReceivingQueue.setActual(queue); throwExceptionIfAny(); return myReceiver; } public QueueSender createSender(Queue queue) throws JMSException { mySendingQueue.setActual(queue); throwExceptionIfAny(); return mySender; } public TemporaryQueue createTemporaryQueue() throws JMSException { throwExceptionIfAny(); return myTemporaryQueue; } public void setExpectedSendingQueue(Queue queue) { mySendingQueue.setExpected(queue); } public void setExpectedReceivingQueue(Queue queue) { myReceivingQueue.setExpected(queue); } public void setupReceiver(QueueReceiver receiver) { myReceiver = receiver; } public void setupSender(QueueSender sender) { mySender = sender; } public void setupTemporaryQueue(MockTemporaryQueue temporaryQueue) { myTemporaryQueue = temporaryQueue; } } --- NEW FILE: MockSession.java --- package com.mockobjects.jms; import com.mockobjects.*; import java.io.Serializable; import javax.jms.*; public class MockSession extends MockObject implements Session { protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockSession.close"); protected ExpectationCounter myCreateTextMessageCalls = new ExpectationCounter("MockSession.createTextMessage"); private TextMessage myTextMessage = new MockTextMessage(); private JMSException myException; public MockSession() { } public void close() throws JMSException { throwExceptionIfAny(); myCloseCalls.inc(); } public void commit() throws JMSException { notImplemented(); } public BytesMessage createBytesMessage() throws JMSException { notImplemented(); return null; } public MapMessage createMapMessage() throws JMSException { notImplemented(); return null; } public Message createMessage() throws JMSException { notImplemented(); return null; } public ObjectMessage createObjectMessage() throws JMSException { notImplemented(); return null; } public ObjectMessage createObjectMessage(Serializable object) throws JMSException { notImplemented(); return null; } public StreamMessage createStreamMessage() throws JMSException { notImplemented(); return null; } public TextMessage createTextMessage() throws JMSException { myCreateTextMessageCalls.inc(); return myTextMessage; } public TextMessage createTextMessage(String text) throws JMSException { myTextMessage.setText(text); return myTextMessage; } public MessageListener getMessageListener() throws JMSException { notImplemented(); return null; } public boolean getTransacted() throws JMSException { notImplemented(); return false; } public void recover() throws JMSException { notImplemented(); } public void rollback() throws JMSException { notImplemented(); } public void run() { notImplemented(); } public void setMessageListener(MessageListener listener) throws JMSException { notImplemented(); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setExpectedCreateTextMessageCalls(int callCount) { myCreateTextMessageCalls.setExpected(callCount); } public void setupTextMessage(TextMessage textMessage) { myTextMessage = textMessage; } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockTemporaryQueue.java --- package com.mockobjects.jms; import javax.jms.JMSException; import javax.jms.TemporaryQueue; import com.mockobjects.ExpectationCounter; public class MockTemporaryQueue extends MockQueue implements TemporaryQueue { protected ExpectationCounter myDeleteCalls = new ExpectationCounter("MockTemporaryQueue.delete"); public MockTemporaryQueue() { super("TemporaryQueue"); } public void delete() throws JMSException { myDeleteCalls.inc(); throwExceptionIfAny(); } public void setExpectedDeleteCalls(int callCount) { myDeleteCalls.setExpected(callCount); } } --- NEW FILE: MockTextMessage.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockTextMessage extends MockMessage implements TextMessage { protected ExpectationValue myExpectedText = new ExpectationValue("MockTextMessage.setText"); private String myText; public MockTextMessage() { } public MockTextMessage(String text) { myText = text; } public void setText(String text) { myExpectedText.setActual(text); } public String getText() { return myText; } public void setExpectedText(String text) { myExpectedText.setExpected(text); } } |
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/com/mockobjects/servlet In directory usw-pr-cvs1:/tmp/cvs-serv9080/com/mockobjects/servlet Added Files: MockHttpServletRequest.java MockHttpServletResponse.java MockHttpSession.java MockRequestDispatcher.java MockServletOutputStream.java Log Message: started j2ee section --- NEW FILE: MockHttpServletRequest.java --- package com.mockobjects.servlet; import java.util.*; import javax.servlet.http.*; import com.mockobjects.*; public class MockHttpServletRequest implements HttpServletRequest { private Dictionary myParameters = new Hashtable(); private String myPathInfo; public MockHttpServletRequest() { super(); } /** * @deprecated */ public void addActualParameter(String paramName, String[] values) { setupAddParameter(paramName, values); } /** * @deprecated */ public void addActualParameter(String paramName, String value) { setupAddParameter(paramName, value); } /** * getAttribute method comment. */ public Object getAttribute(String arg1) { return null; } /** * getAttributeNames method comment. */ public java.util.Enumeration getAttributeNames() { return null; } /** * getAuthType method comment. */ public String getAuthType() { return null; } /** * getCharacterEncoding method comment. */ public String getCharacterEncoding() { return null; } /** * getContentLength method comment. */ public int getContentLength() { return 0; } /** * getContentType method comment. */ public String getContentType() { return null; } /** * getContextPath method comment. */ public java.lang.String getContextPath() { return null; } /** * getCookies method comment. */ public javax.servlet.http.Cookie[] getCookies() { return null; } /** * getDateHeader method comment. */ public long getDateHeader(String arg1) { return 0; } /** * getHeader method comment. */ public String getHeader(String arg1) { return null; } /** * getHeaderNames method comment. */ public java.util.Enumeration getHeaderNames() { return null; } /** * getHeaders method comment. */ public java.util.Enumeration getHeaders(java.lang.String arg1) { return null; } /** * getInputStream method comment. */ public javax.servlet.ServletInputStream getInputStream() throws java.io.IOException { return null; } /** * getIntHeader method comment. */ public int getIntHeader(String arg1) { return 0; } /** * getLocale method comment. */ public java.util.Locale getLocale() { return null; } /** * getLocales method comment. */ public java.util.Enumeration getLocales() { return null; } /** * getMethod method comment. */ public String getMethod() { return null; } public String getParameter(String paramName) { String[] values = getParameterValues(paramName); return (values == null ? null : values[0]); } public java.util.Enumeration getParameterNames() { return myParameters.keys(); } public String[] getParameterValues(String key) { return (String[]) myParameters.get(key); } public String getPathInfo() { return myPathInfo; } /** * getPathTranslated method comment. */ public String getPathTranslated() { return null; } /** * getProtocol method comment. */ public String getProtocol() { return null; } /** * getQueryString method comment. */ public String getQueryString() { return null; } /** * getReader method comment. */ public java.io.BufferedReader getReader() throws java.io.IOException { return null; } /** * getRealPath method comment. */ public String getRealPath(String arg1) { return null; } /** * getRemoteAddr method comment. */ public String getRemoteAddr() { return null; } /** * getRemoteHost method comment. */ public String getRemoteHost() { return null; } /** * getRemoteUser method comment. */ public String getRemoteUser() { return null; } /** * getRequestDispatcher method comment. */ public javax.servlet.RequestDispatcher getRequestDispatcher( java.lang.String arg1) { return null; } /** * getRequestedSessionId method comment. */ public String getRequestedSessionId() { return null; } /** * getRequestURI method comment. */ public String getRequestURI() { return null; } /** * getScheme method comment. */ public String getScheme() { return null; } /** * getServerName method comment. */ public String getServerName() { return null; } /** * getServerPort method comment. */ public int getServerPort() { return 0; } /** * getServletPath method comment. */ public String getServletPath() { return null; } /** * getSession method comment. */ public javax.servlet.http.HttpSession getSession() { return null; } /** * getSession method comment. */ public javax.servlet.http.HttpSession getSession(boolean arg1) { return null; } /** * getUserPrincipal method comment. */ public java.security.Principal getUserPrincipal() { return null; } /** * isRequestedSessionIdFromCookie method comment. */ public boolean isRequestedSessionIdFromCookie() { return false; } /** * isRequestedSessionIdFromUrl method comment. */ public boolean isRequestedSessionIdFromUrl() { return false; } /** * isRequestedSessionIdFromURL method comment. */ public boolean isRequestedSessionIdFromURL() { return false; } /** * isRequestedSessionIdValid method comment. */ public boolean isRequestedSessionIdValid() { return false; } /** * isSecure method comment. */ public boolean isSecure() { return false; } /** * isUserInRole method comment. */ public boolean isUserInRole(java.lang.String arg1) { return false; } /** * removeAttribute method comment. */ public void removeAttribute(java.lang.String arg1) { } /** * setAttribute method comment. */ public void setAttribute(String arg1, Object arg2) { } /** * @deprecated */ public void setNoActualParameters() { setupNoParameters(); } public void setupAddParameter(String paramName, String[] values) { myParameters.put(paramName, values); } public void setupAddParameter(String paramName, String value) { setupAddParameter(paramName, new String[] { value }); } public void setupNoParameters() { myParameters = new Hashtable(); } public void setupPathInfo(String pathInfo) { myPathInfo = pathInfo; } } --- NEW FILE: MockHttpServletResponse.java --- package com.mockobjects.servlet; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import junit.framework.Assert; import com.mockobjects.*; public class MockHttpServletResponse extends MockObject implements HttpServletResponse, Verifiable { private ExpectationList myContentTypes = new ExpectationList("MockHttpServletResponse.setContentType"); private ExpectationList myHeaders = new ExpectationList("MockHttpServletResponse.setHeader"); private ExpectationCounter mySetStatusCalls = new ExpectationCounter("MockHttpServletResponse.setStatus"); private ExpectationList myRedirects = new ExpectationList("MockHttpServletResponse.sendRedirect"); private ServletOutputStream myOutputStream = new MockServletOutputStream(); /** * MockHttpServletResponse constructor comment. */ public MockHttpServletResponse() { super(); } public void addCookie(javax.servlet.http.Cookie arg1) { fail("Not implemented"); } /** * addDateHeader method comment. */ public void addDateHeader(java.lang.String arg1, long arg2) { } /** * addHeader method comment. */ public void addHeader(java.lang.String arg1, java.lang.String arg2) { } /** * addIntHeader method comment. */ public void addIntHeader(java.lang.String arg1, int arg2) { } public boolean containsHeader(String arg1) { fail("Not implemented"); return false; } public String encodeRedirectUrl(String arg1) { fail("Not implemented"); return null; } public String encodeRedirectURL(String arg1) { fail("Not implemented"); return null; } public String encodeUrl(String arg1) { fail("Not implemented"); return null; } public String encodeURL(String arg1) { fail("Not implemented"); return null; } /** * flushBuffer method comment. */ public void flushBuffer() throws java.io.IOException { } /** * getBufferSize method comment. */ public int getBufferSize() { return 0; } public String getCharacterEncoding() { fail("Not implemented"); return null; } /** * getLocale method comment. */ public java.util.Locale getLocale() { return null; } public javax.servlet.ServletOutputStream getOutputStream() throws java.io.IOException { return myOutputStream; } public String getOutputStreamContents() { return ((MockServletOutputStream) myOutputStream).getContents(); } public java.io.PrintWriter getWriter() throws java.io.IOException { return new PrintWriter(myOutputStream, true); } /** * isCommitted method comment. */ public boolean isCommitted() { return false; } /** * reset method comment. */ public void reset() { } public void sendError(int arg1) throws java.io.IOException { fail("Not implemented"); } public void sendError(int arg1, String arg2) throws java.io.IOException { fail("Not implemented"); } public void sendRedirect(String aURL) throws java.io.IOException { myRedirects.addActual(aURL); } /** * setBufferSize method comment. */ public void setBufferSize(int arg1) { } public void setContentLength(int arg1) { fail("Not implemented"); } public void setContentType(String contentType) { myContentTypes.addActual(contentType); } public void setDateHeader(String arg1, long arg2) { fail("Not implemented"); } public void setExpectedContentType(String contentType) { myContentTypes.addExpected(contentType); } public void setExpectedHeader(String key, String value) { myHeaders.addExpected(new MapEntry(key, value)); } public void setExpectedRedirect(String aURL) throws IOException { myRedirects.addExpected(aURL); } public void setExpectedSetStatusCalls(int callCount) { mySetStatusCalls.setExpected(callCount); } public void setHeader(String key, String value) { myHeaders.addActual(new MapEntry(key, value)); } public void setIntHeader(String arg1, int arg2) { Assert.fail("Not implemented"); } /** * setLocale method comment. */ public void setLocale(java.util.Locale arg1) { } public void setStatus(int status) { mySetStatusCalls.inc(); } public void setStatus(int arg1, String arg2) { Assert.fail("Not implemented"); } public void setupOutputStream(ServletOutputStream anOutputStream) { myOutputStream = anOutputStream; } } --- NEW FILE: MockHttpSession.java --- package com.mockobjects.servlet; import java.util.*; import javax.servlet.http.HttpSessionContext; import javax.servlet.http.HttpSession; import com.mockobjects.*; public class MockHttpSession extends MockObject implements HttpSession, Verifiable { public ExpectationSet myAttributes = new ExpectationSet("session attributes"); public MockHttpSession() { super(); } public Object getAttribute(String arg1) { notImplemented(); return null; } public Enumeration getAttributeNames() { return null; } public long getCreationTime() { notImplemented(); return 0; } public String getId() { notImplemented(); return null; } public long getLastAccessedTime() { notImplemented(); return 0; } public int getMaxInactiveInterval() { return 0; } public HttpSessionContext getSessionContext() { return null; } public Object getValue(String arg1) { notImplemented(); return null; } public java.lang.String[] getValueNames() { notImplemented(); return null; } public void invalidate() { } public boolean isNew() { return false; } public void putValue(String arg1, Object arg2) { } public void removeAttribute(String arg1) { } public void removeValue(String arg1) { } public void setAttribute(String aKey, Object aValue) { myAttributes.addActual(new MapEntry(aKey, aValue)); } public void setExpectedAttribute(String aKey, Object aValue) { myAttributes.addExpected(new MapEntry(aKey, aValue)); } public void setMaxInactiveInterval(int arg1) { } public void verify() { myAttributes.verify(); } } --- NEW FILE: MockRequestDispatcher.java --- package com.mockobjects.servlet; import java.io.IOException; import javax.servlet.*; public class MockRequestDispatcher implements RequestDispatcher { /** * MockRequestDispatcher constructor comment. */ public MockRequestDispatcher() { super(); } public void forward(ServletRequest arg1, ServletResponse arg2) throws ServletException, IOException { } public void include(ServletRequest arg1, ServletResponse arg2) throws ServletException, IOException { } } --- NEW FILE: MockServletOutputStream.java --- package com.mockobjects.servlet; import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.servlet.ServletOutputStream; import com.mockobjects.ExpectationCounter; import com.mockobjects.ExpectationValue; public class MockServletOutputStream extends ServletOutputStream { private ExpectationValue myWriteCalled = new ExpectationValue("MockServletOutputStream.write()"); private boolean myThrowException = false; private ExpectationCounter myCloseCallCount = new ExpectationCounter("MockServletOutputstream.close()"); private ByteArrayOutputStream myBuffer; public MockServletOutputStream() { super(); setupClearContents(); } public void setExpectedCloseCalls(int closeCall) { myCloseCallCount.setExpected(closeCall); } public void setExpectingWriteCalls(boolean expectingWriteCall) { myWriteCalled.setExpected(expectingWriteCall); } public void setThrowIOException(boolean throwException) { myThrowException = throwException; } public void close() throws IOException { myCloseCallCount.inc(); } public String toString() { return getContents(); } public void write(int b) throws IOException { myWriteCalled.setActual(true); if (myThrowException) throw new IOException("Test IOException generated by request"); myBuffer.write(b); } public void setupClearContents () { myBuffer = new ByteArrayOutputStream(); } public String getContents() { return myBuffer.toString(); } public void verify() { myWriteCalled.verify(); myCloseCallCount.verify(); } } |
From: Steve F. <sm...@us...> - 2001-11-21 23:59:02
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee In directory usw-pr-cvs1:/tmp/cvs-serv5851/j2ee Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/j2ee added to the repository |
From: Steve F. <sm...@us...> - 2001-11-21 23:43:22
|
Update of /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/atg In directory usw-pr-cvs1:/tmp/cvs-serv2850 Modified Files: MockDynamoHttpServletRequest.java Log Message: reformat removed unnecessary cast Index: MockDynamoHttpServletRequest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/atg/MockDynamoHttpServletRequest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockDynamoHttpServletRequest.java 2001/07/29 19:50:25 1.1 +++ MockDynamoHttpServletRequest.java 2001/11/21 23:43:18 1.2 @@ -1,31 +1,27 @@ package com.mockobjects.atg; -import atg.servlet.DynamoHttpServletRequest; -import com.mockobjects.ExpectationSet; -import atg.nucleus.naming.*; + import java.io.IOException; -import javax.servlet.*; -import java.util.*; +import java.util.HashMap; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import com.mockobjects.ExpectationSet; import com.mockobjects.MapEntry; -import com.mockobjects.util.Verifier;public class MockDynamoHttpServletRequest extends DynamoHttpServletRequest { +import com.mockobjects.util.Verifier; + +public class MockDynamoHttpServletRequest extends DynamoHttpServletRequest { private ExpectationSet myServicedLocalParameter = new ExpectationSet("Serviced Local Params"); - private ExpectationSet myExpectedOutputParameters = new ExpectationSet("Output Parameters"); + private ExpectationSet myOutputParameters = new ExpectationSet("Output Parameters"); private HashMap myInputParameters = new HashMap(); - private HashMap myOutputParameters = new HashMap(); private HashMap myNamedComponents = new HashMap(); private HashMap myCookieParameters = new HashMap(); private HashMap myHeaders = new HashMap(); public MockDynamoHttpServletRequest() { - } public void setParameter(String key, Object value) { - myExpectedOutputParameters.addActual(new MapEntry(key, value)); - myOutputParameters.put(key, value); - } - - public void verify() { - Verifier.verifyObject(this); + myOutputParameters.addActual(new MapEntry(key, value)); } public Object getObjectParameter(ParameterName name) { @@ -36,28 +32,21 @@ return myInputParameters.get(name); } + public Object getLocalParameter(String parameterName) { + return myInputParameters.get(parameterName); + } + public String getParameter(String param1) { return (String) myInputParameters.get(param1); } - public boolean serviceLocalParameter( - String name, - ServletRequest request, - ServletResponse response) - throws ServletException, IOException { - + public boolean serviceLocalParameter(String name, ServletRequest request, ServletResponse response) throws ServletException, IOException { myServicedLocalParameter.addActual(name); - return true; - - } - - public Object getLocalParameter(String parameterName) { - return (String) myInputParameters.get(parameterName); } public void setupExpectedOutputParameter(String name, Object value) { - myExpectedOutputParameters.addExpected(new MapEntry(name, value)); + myOutputParameters.addExpected(new MapEntry(name, value)); } public void setupExpectedServicedLocalParameter(String name) { @@ -85,24 +74,24 @@ } - public String encodeURL(String str) { return str + ";sessionId=123"; } - public String getHeader(String param1) { return (String) myHeaders.get(param1); } - public Object resolveName(String componentName, boolean param2) { return myNamedComponents.get(componentName); } + public void verify() { + Verifier.verifyObject(this); + } public String toString() { return "MockDynamoServletRequest"; |
From: Jeff M. <je...@cu...> - 2001-11-21 11:12:04
|
I've writen some very basic mocks for the new 2.3 servlet stuff I've put them here http://www.custommonkey.org/~jeff/mock/ there's also a couple of small changes to AbstractExpectationCollection and MockConnection. I apologise in advance is there a bit untidy but I've not had a chance to go back to them and tidy up yet. On Mon, 2001-11-12 at 22:18, Steve Freeman wrote: > I think the current implementation of servlets is a bit out of date. Anyone object to bringing it up to date? > > I think the new stuff is largely additive, so there shouldn't be a backwards compatibility issue. > > Steve > |
From: <pir...@ya...> - 2001-11-19 20:46:47
|
Hi fellow mockers, I've had earlier version of these changes pending in the sourceforge for sometime. Not having access to the CVS, I'm emailing these updates in. Here are differences for MockDynamoHttpServletRequest.java and a new file for MockDynamoServlet.java. First, com.mockobjects.atg.MockDynamoHttpServletRequest.java. The changes are to call MockDynamoServlet if possible, and to fix a bug in getLocalParameter() 1a2 > import atg.servlet.DynamoServlet; 2a4 > import atg.servlet.DynamoHttpServletResponse; 9c11,14 < import com.mockobjects.util.Verifier;public class MockDynamoHttpServletRequest extends DynamoHttpServletRequest { --- > import com.mockobjects.util.Verifier; > > public class MockDynamoHttpServletRequest extends DynamoHttpServletRequest { > 42a48,51 > public Object getOutputParameter(String key) { > return myOutputParameters.get(key); > } > 51c60,62 < return true; --- > DynamoServlet servlet = (DynamoServlet) this.getLocalParameter(name); > if (servlet != null) > servlet.service((DynamoHttpServletRequest)request, (DynamoHttpServ letResponse)response); 52a64 > return true; 56c68 < return (String) myInputParameters.get(parameterName); --- > return myInputParameters.get(parameterName); Second, com.mockobjects.atg.MockDynamoServlet is a new class which mocks oparams in calls. The current implementation is very simple, counting its calls or checking its parameters. However, you can override it to do more of your own checks. package com.mockobjects.atg; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import java.util.HashSet; import atg.servlet.DynamoServlet; import atg.servlet.DynamoHttpServletRequest; import atg.servlet.DynamoHttpServletResponse; import com.mockobjects.Verifiable; import com.mockobjects.util.Verifier; import com.mockobjects.ExpectationSet; import com.mockobjects.ExpectationCounter; import com.mockobjects.MapEntry; import com.mockobjects.atg.MockDynamoHttpServletRequest; public class MockDynamoServlet extends DynamoServlet implements Verifiable { private ExpectationCounter myServiceCalls = new ExpectationCounter("MockDynamoServlet.service"); private ExpectationSet myExpectedOutputParameters = new ExpectationSet("Output Parameters"); private Set myExpectedParamNames = new HashSet(); public void setExpectedServiceCalls(int callCount) { myServiceCalls.setExpected(callCount); } public void setExpectedParameter(String name, Object value) { myExpectedOutputParameters.addExpected(new MapEntry(name, value)); myExpectedParamNames.add(name); } public void service(DynamoHttpServletRequest request, DynamoHttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { myServiceCalls.inc(); if (request instanceof MockDynamoHttpServletRequest) { MockDynamoHttpServletRequest mockRequest = (MockDynamoHttpServletRequest) request; for ( Iterator i = myExpectedParamNames.iterator(); i.hasNext(); ) { String key = (String) i.next(); Object value = mockRequest.getOutputParameter(key); myExpectedOutputParameters.addActual(new MapEntry(key, value)); } } } public void verify() { Verifier.verifyObject(this); } } Below is a simple droplet Size that gets the size of something, and after that it's junit test case: package com.philips.utils;import java.io.IOException;import atg.servlet.*;import javax.servlet.*;import java.util.Collection;import java.util.Map;/** * Get the size of an array, collection, string or map. * * param <code>value</code>: the value to find the size of<br> * oparam <code>output</code>: passed the param <code>size</code> with the size of <code>value</code><br> * oparam <code>error</code>: passed the param <code>errorMsg</code> in case of an error * * For strings, the size is the length of the string * For collections, the size is the number of elements * For arrays, the size is the array length * For maps, the size is the number of elements * * @author Piran Montford * @version $Revision: 1.2 $ */public class Size extends DynamoServlet { private static final String PARAM_VALUE = "value"; private static final String PARAM_SIZE = "size"; private static final String PARAM_OUTPUT = "output"; private static final String PARAM_ERROR = "error"; private static final String PARAM_ERROR_MSG = "errorMsg"; /** Creates new Size */ public Size() {} /** * Find the size of the parameter. */ public void service(DynamoHttpServletRequest request, DynamoHttpServletResponse response) throws ServletException, IOException { int size; Object value = request.getLocalParameter(PARAM_VALUE); if (value instanceof Collection) { size = ((Collection) value).size(); } else if (value instanceof Object[]) { size = ((Object[]) value).length; } else if (value instanceof Map) { size = ((Map) value).size(); } else if (value instanceof String) { size = ((String) value).length(); } else { request.setParameter(PARAM_ERROR_MSG, "unknown type of value"); request.serviceLocalParameter(PARAM_ERROR, request, response); return; } request.setParameter(PARAM_SIZE, new Integer(size)); request.serviceLocalParameter(PARAM_OUTPUT, request, response); }}import java.io.IOException;import atg.servlet.*;import javax.servlet.*;import java.util.Collection;import java.util.Map;import java.util.HashMap;import java.util.List;import java.util.ArrayList;import java.util.Set;import java.util.HashSet;import junit.framework.TestCase;import junit.framework.TestSuite;import com.mockobjects.atg.MockDynamoServlet;import com.mockobjects.atg.MockDynamoHttpServletRequest;import com.mockobjects.atg.MockDynamoHttpServletResponse;/** * JUnit Test class for Size * * @author Piran Montford * @version $Revision: 1.1 $ */public class TestSize extends TestCase { public TestSize(String name) { super(name); } /** TestSuite of tests in this class */ public static TestSuite suite() { return new TestSuite(TestSize.class); } Size mTarget; MockDynamoHttpServletRequest mRequest; MockDynamoHttpServletResponse mResponse; MockDynamoServlet mOutput, mError; public void setUp() { mTarget = new Size(); mRequest = new MockDynamoHttpServletRequest(); mResponse = new MockDynamoHttpServletResponse(); mOutput = new MockDynamoServlet(); mError = new MockDynamoServlet(); mRequest.setupInputParameter("output", mOutput); mRequest.setupInputParameter("error", mError); } /** Verify all the default variables */ public void verify() { mRequest.verify(); mResponse.verify(); mOutput.verify(); mError.verify(); } /** Test we get the right length of a string */ public void testString() throws Throwable { doOutputCall( "Size5", 5 ); } /** Test we get the right length of a list */ public void testList() throws Throwable { List test = new ArrayList(); test.add( "one" ); test.add( "two" ); test.add( "three" ); doOutputCall(test, 3); } /** Test we get the right airity of a set */ public void testSet() throws Throwable { Set test = new HashSet(); test.add("ragtag"); test.add("bobtail"); doOutputCall(test, 2); } /** Test we get the right size of a map */ public void testMap() throws Throwable { Map test = new HashMap(); test.put("pupil", "teacher"); test.put("student", "lecturer"); test.put("ward", "nurse"); test.put("charge", "police"); doOutputCall(test, 4); } /** Test we get the right lenght of an array */ public void testStringArray() throws Throwable { String[] test = {"Enie", "Meenie", "Minie", "Moe"}; doOutputCall(test, 4); } /** Test we get an error for a non-collection type */ public void testBadType() throws Throwable { Integer test = new Integer(3); mError.setExpectedServiceCalls(1); mOutput.setExpectedServiceCalls(0); mRequest.setupInputParameter("value", test); mTarget.service(mRequest, mResponse); } /** Test we get an error for a null value */ public void testNullValue() throws Throwable { mError.setExpectedServiceCalls(1); mOutput.setExpectedServiceCalls(0); mRequest.setupInputParameter("value", null); mTarget.service(mRequest, mResponse); } /** Call the service() method expecting success with the test value, and the predicted size */ void doOutputCall(Object test, int size) throws Throwable { mError.setExpectedServiceCalls(0); mOutput.setExpectedServiceCalls(1); mOutput.setExpectedParameter("size", new Integer(size)); mRequest.setupInputParameter("value", test); mTarget.service(mRequest, mResponse); verify(); } } BCNU, Piran. I came here for a reason, and I don't intend to leave without one Piran Montford mailto:pi...@po... http://www.pobox.com/piran --------------------------------- Do You Yahoo!? Get personalised at My Yahoo!. |
From: Steve F. <st...@m3...> - 2001-11-18 22:26:39
|
VGhpcyBtYXkgYmUgdGhlIHJpZ2h0IHdheSB0byBnbywgYnV0IEkgZmluZCB0aGUgcHJvc3BlY3Qg b2YgbWFpbnRhaW5pbmcgYW5kIGJ1aWxkaW5nIGl0IHJhdGhlciBkYXVudGluZy4gDQoNCldlJ2Qg cHJvYmFibHkgaGF2ZSB0byBoYXZlIGRpZmZlcmVudCBwZW9wbGUgcmVzcG9uc2libGUgZm9yIGRp ZmZlcmVudCBqZGsgYnVpbGRzLCBhbmQgSSdtIG5vdCBzdXJlIGhvdyB3ZSdkIGtlZXAgdGhlIHZl cnNpb25zIGluIHN5bmMgd2l0aCBlbmhhbmNlbWVudHMuIA0KDQpJJ20gaW5jbGluZWQgdGhlc2Ug ZGF5cyB0byB0aGUgY29yZS9qcmUvajJlZSBkaXZpc2lvbiwgYWx0aG91Z2ggdGhlcmUgYXJlIGlz c3VlcyBhYm91dCB0aGUgdXNlIG9mIHJlZmxlY3Rpb24gaW4gZXZlbiB0aGUgY29yZSBsaWJyYXJ5 Lg0KDQpBbnkgdm9sdW50ZWVycyB0byB0YWtlIG92ZXIgd29ycnlpbmcgYWJvdXQgc29tZSBvZiB0 aGlzIHN0dWZmPw0KDQpTdGV2ZQ0KDQotLS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F. <st...@m3...> - 2001-11-18 21:53:48
|
V2UgY2FuIGFsd2F5cyBob3N0IGl0IHdoZW4geW91J3JlIHJlYWR5IGFuZCBzZWUgaWYgdGhlcmUn cyBhbnkgdGFrZSB1cC4NCg0KU3RldmUNCg0KRnJvbTogIkdyZWcgTWVycmlsbCIgPGdyZWdobWVy cmlsbEB5YWhvby5jb20+DQo+IFdoeSBkb24ndCBJIGZpbmlzaCB0aGUgcHJvdG90eXBlICYgcGFz cyBpdCBhbG9uZyB0bw0KPiB5b3UgZ3V5cy4gIFRoZW4geW91IGNhbiBkZWNpZGUgaWYgaXQncyB3 b3J0aCBpbmNsdXNpb24NCj4gaW4gdGhlIHByb2plY3QsIGFuZCBpZiBzbywgaW4gd2hhdCBjYXBh Y3RpeS4NCg0K |
From: Steve F. <sm...@us...> - 2001-11-18 21:06:27
|
Update of /cvsroot/mockobjects/doc In directory usw-pr-cvs1:/tmp/cvs-serv8984 Modified Files: another_route.html Log Message: Index: another_route.html =================================================================== RCS file: /cvsroot/mockobjects/doc/another_route.html,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- another_route.html 2001/08/28 22:58:19 1.3 +++ another_route.html 2001/11/18 21:06:24 1.4 @@ -7,7 +7,7 @@ .deemphasised { color: #666666} h1 { text-align: center; font-family: Arial, Helvetica, sans-serif; font-weight: bold} h3 { font-family: Arial, Helvetica, sans-serif; font-style: italic; font-weight: bold; font-size: small} -.inline_code { font-family: "Courier New", Courier, mono; font-style: normal; font-size: smaller; vertical-align: middle} +.inline_code { font-family: "Courier New", Courier, mono; font-style: normal; font-size: small; vertical-align: middle} p { font-family: Arial, Helvetica, sans-serif} li { font-family: Arial, Helvetica, sans-serif } h2 { font-family: Arial, Helvetica, sans-serif; margin-top: 3%} @@ -38,6 +38,7 @@ <pre> public void testReminderEmailSent() throws ServletException, IOException { mockRequest.setupAddParameter(ForgotPasswordServlet.EMAIL_PARAM, EMAIL); + mockReminder.setExpectedEmailAddress(EMAIL); mockResponse.setExpectedRedirect(SENT_URI + "?email=" + EMAIL); @@ -109,14 +110,21 @@ <h3>Differences</h3> <p>There are two obvious differences to the original so far. First, we start at the top level of the problem, from outside the servlet, rather than from an - internal object. Second, we perfer to pass our test infrastructure into the + internal object. Second, we prefer to pass our test infrastructure into the target code, as Mock Objects, rather than use techniques such as inner classes to give us access to private data. This means that we tend to define our assertions at the beginning of test, rather than at the end.</p> -<h2>More functionality</h2> +<h2>Handling failure</h2> +<h3>Cannot send an email</h3> +<p>Sending an email may fail, perhaps because a connection has failed or because + an address is not well-formed; we will handle this by redirecting the user to + a suitable error page. To </p> +<h3> </h3> <h3>No record for the email address</h3> <p>People are likely to request passwords for email addresses that are not in - the database, either by accident or maliciously. </p> + the database, either by accident or maliciously. Our response will be to redirect + users who specify an incorrect email address to </p> +<h3>Test Bad Email</h3> <hr> <p>© Steve Freeman, 2001</p> <p> </p> |
From: Steve F. <st...@m3...> - 2001-11-18 21:00:34
|
RnJvbTogPG1vY2tvYmplY3RzLWphdmEtZGV2LWFkbWluQGxpc3RzLnNvdXJjZWZvcmdlLm5ldD4N Cj4gQXMgd2UgYXJlIGFsbCBhYm91dCB0ZXN0aW5nIC0gSSB3b3VsZCBsaWtlIHRvIHNlZSBzb21l b25lIHB1dCBzb21lIHdvcmsgaW50bw0KPiB0ZXN0aW5nIFNRTCB0aGlzIHdheSAtIGl0IHNvdW5k cyBjb29sLiBBcyB5b3UgcG9pbnRlZCBvdXQgc3RldmUgLSB0aGVyZSBpcw0KPiBhbiBhcnQgdG8g dGVzdGluZyBqdXN0IHRoZSByaWdodCBhbW91bnQgc28gaXQgd291bGQgYmUgaW50ZXJlc3Rpbmcg dG8gc2VlDQo+IGhvdyB0aGlzIHdvcmtzIG91dCAtIGJ1dCBpbiB0aGVvcnkgd2h5IG5vdCB3b3Jr IG9uIGl0IGhlcmUgYW5kIHNlZSBob3cgaXQNCj4gcGFucyBvdXQ/DQo+IFRpbQ0KDQpBY3R1YWxs eSwgSSB0a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8vbW9ja29iamVjdHMt amF2YS1kZXYNCj4gDQo= |
From: Greg M. <gre...@ya...> - 2001-11-18 20:58:51
|
Why don't I finish the prototype & pass it along to you guys. Then you can decide if it's worth inclusion in the project, and if so, in what capactiy. --- moc...@li... wrote: > As we are all about testing - I would like to see > someone put some work into > testing SQL this way - it sounds cool. As you > pointed out steve - there is > an art to testing just the right amount so it would > be interesting to see > how this works out - but in theory why not work on > it here and see how it > pans out? > > Tim > > > the other thought that strikes me is that we know > that test-first > > changes the way we write our code (to make it > testable). I would > > expect that writing db access for testability > would change the > > way we write SQL. Has anyone noticed this? > > > > > I've created a prototype of such a feature, > using a > > > parser generated with JavaCC and a contributed > grammar > > > (http://www.cobase.cs.ucla.edu/pub/javacc/). It > seems > > > to work OK. (The grammar is a little > Oracle-specific, > > > but should handle standard SQL just fine.) > > > > > > Do you think this kind of feature would fit well > in > > > the mock objects core? Or does it seem more > like an > > > optional feature which should be > released/maintained > > > separately? > > > > It sounds like a separate feature to me. Do people > think it > > should be hosted on the Mock Objects project? > > > > Steve > > > > > 2$¡¸ÞrÛ#jözùX§X¬´ÊãyËl«ÚuëåËl²«qçè®§zØm¶?þX¬¶Ë(º·~à > > zwþX¬¶ÏåËbú?$¡¸ÞrÛ#jö > > > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev __________________________________________________ Do You Yahoo!? Find the one for you at Yahoo! Personals http://personals.yahoo.com |
From: Greg M. <gre...@ya...> - 2001-11-18 20:56:20
|
> > And the bottom line - does basic SQL validation > have a > > place in MockObject-style unit testing? Or should > > this type of responsibililty lie with functional > > testing, since the SQL validation which is > actually > > done at runtime is database-dependent? > > my (doubtless naive) take on this is that is that > most SQL is either simple (pop a couple of values in > a query) or dreadfully complicated. For the former, > all you really need to check _in the unit test_ is > that the right values get passed through, which you > can probably do with a simple substring match. > There's a bit of an art to specifiying the minimum > that is important in a unit test. For the latter, > you probably want a separate object to generate the > SQL which would be tested away from the JDBC -- in > which case your parser might be appropriate. This take is not naive, but is in fact quite consistent with my experience. I think queries typically do fall into the two categories you mention: trivially simple or flat-out ghastly. I also agree with the notion of "a separate object to generate the SQL" in complex cases; for example, I use a "Query" object with methods like addSelect(), addFrom(), and addWhere(). Using this object helps ensure that for complex queries, all the punctuation & conjunctions separating various parts of the query end up in the right places. Nevertheless, mistakes are still occasionally made in both the simple and complex types (particularly when making changes to pre-existing code), and SQL syntax errors just _feel_ to me like they should be detectable earlier in the testing process. I say this because what is and isn't valid SQL syntax is not going to change during the life of the project, as something such as the db schema will. > Of course, this kind of development also requires a > higher-level test to make sure you haven't drifted > away from the schema. For a small application, that > would probably be your acceptance tests (or whatever > we're calling them now). For a large application, > you might have some DB integration tests. > > the other thought that strikes me is that we know > that test-first changes the way we write our code > (to make it testable). I would expect that writing > db access for testability would change the way we > write SQL. Has anyone noticed this? Interesting notion. I think most folks currently test db access which falls outside of the JDBC API (e.g. the SQL itself) not with unit tests, but with "acceptance tests" and "DB integration tests", as you have mentioned. Until unit-like facilities are available in the db access domain, I don't imagine we'll know the answer to this question. > > I've created a prototype of such a feature, using > a > > parser generated with JavaCC and a contributed > grammar > > (http://www.cobase.cs.ucla.edu/pub/javacc/). It > seems > > to work OK. (The grammar is a little > Oracle-specific, > > but should handle standard SQL just fine.) > > > > Do you think this kind of feature would fit well > in > > the mock objects core? Or does it seem more like > an > > optional feature which should be > released/maintained > > separately? > > It sounds like a separate feature to me. Do people > think it should be hosted on the Mock Objects > project? The more I think about it, the more I agree with you on this point. The Oracle-specificness of the grammar alone suggests to me that this is not core functionality. -Greg __________________________________________________ Do You Yahoo!? Find the one for you at Yahoo! Personals http://personals.yahoo.com |
From: <moc...@li...> - 2001-11-18 14:04:04
|
As we are all about testing - I would like to see someone put some work into testing SQL this way - it sounds cool. As you pointed out steve - there is an art to testing just the right amount so it would be interesting to see how this works out - but in theory why not work on it here and see how it pans out? Tim > the other thought that strikes me is that we know that test-first > changes the way we write our code (to make it testable). I would > expect that writing db access for testability would change the > way we write SQL. Has anyone noticed this? > > > I've created a prototype of such a feature, using a > > parser generated with JavaCC and a contributed grammar > > (http://www.cobase.cs.ucla.edu/pub/javacc/). It seems > > to work OK. (The grammar is a little Oracle-specific, > > but should handle standard SQL just fine.) > > > > Do you think this kind of feature would fit well in > > the mock objects core? Or does it seem more like an > > optional feature which should be released/maintained > > separately? > > It sounds like a separate feature to me. Do people think it > should be hosted on the Mock Objects project? > > Steve > > 2$¡¸ÞrÛ#jözùX§X¬´ÊãyËl«ÚuëåËl²«qçè®§zØm¶?þX¬¶Ë(º·~à > zwþX¬¶ÏåËbú?$¡¸ÞrÛ#jö |
From: <moc...@li...> - 2001-11-18 12:52:23
|
Have you considered distributing the mock object classes in multiple jars, partitioned by API? In the current release package mockobjects-java there is one jar file (mockobjects.jar) in the lib directory that contains all the classes. Maybe mock classes corresponding to a particular API could be contained in a separate jar. Something like: mock-sql-jdk1-3-version-0-1.jar - version 0.1 of the mocks for java.sql.* in the 1.3 jdk mock-servlet-2-1-version-1-1.jar - version 1.1 of the mocks for javax.servlet.* in the 2.1 servlet spec. So if I was developing some servlet code (version 2.1) and wanted to use MOs, I'd have mock-servlet-2-1-version-1-1.jar in my unit test classpath. If you split up the classes into more jars then you could separately version the different jars and so possibly attain maturer status for parts of the mock library. This might encourage developers to use the maturer parts of the mockobject code, rather than being put off because a part that they weren't going to use anyway is not quite ready for prime time. Theres a slight problem I guess with shared mockobjects classes clashing if you use more than one MO library. Maybe a solution like versioning numbers in the shared classes package name might solve that. Graham |
From: <moc...@li...> - 2001-11-17 10:17:20
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/password In directory usw-pr-cvs1:/tmp/cvs-serv29276/examples/com/mockobjects/examples/password Modified Files: AllTests.java ForgotPasswordServlet.java NotFoundException.java TestForgotPasswordServlet.java Added Files: MailingException.java PasswordException.java Log Message: updated password example --- NEW FILE: MailingException.java --- package src.examples.com.mockobjects.examples.password; public class MailingException extends Exception { public MailingException() { super(); } public MailingException(String s) { super(s); } } --- NEW FILE: PasswordException.java --- package com.mockobjects.examples.password; public class PasswordException extends Exception { public PasswordException() { super(); } public PasswordException(String s) { super(s); } } Index: AllTests.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/password/AllTests.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AllTests.java 2001/08/21 00:16:27 1.1 +++ AllTests.java 2001/11/17 10:17:17 1.2 @@ -4,9 +4,6 @@ import junit.framework.TestSuite; import com.mockobjects.util.SuiteBuilder; import com.mockobjects.util.TestCaseMo; -import com.mockobjects.examples.calcserver.TestCalculator; -import com.mockobjects.examples.calcserver.TestCalculatorServlet; -import com.mockobjects.examples.calcserver.TestSavingCalculator; public class AllTests extends TestCaseMo { private static final Class THIS = AllTests.class; Index: ForgotPasswordServlet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/password/ForgotPasswordServlet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ForgotPasswordServlet.java 2001/08/27 11:20:23 1.2 +++ ForgotPasswordServlet.java 2001/11/17 10:17:17 1.3 @@ -25,15 +25,14 @@ try { passwordReminder.sendReminder(emailAddress); - redirectFor(SENT_PARAM_NAME, response, emailAddress); - - } catch (NotFoundException ex) { - redirectFor(EMAIL_NOT_FOUND_PARAM_NAME, response, emailAddress); + redirectFor(response, emailAddress); + } catch (NotFoundException e) { + throw new ServletException("Password not found", e); } } - private void redirectFor(String baseName, HttpServletResponse response, String emailAddress) throws IOException { - response.sendRedirect(getInitParameter(baseName) + "?" + EMAIL_PARAM + "=" + emailAddress); + private void redirectFor(HttpServletResponse response, String emailAddress) throws IOException { + response.sendRedirect("sent_uri?" + EMAIL_PARAM + "=" + emailAddress); } } Index: NotFoundException.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/password/NotFoundException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NotFoundException.java 2001/08/21 00:16:27 1.1 +++ NotFoundException.java 2001/11/17 10:17:17 1.2 @@ -1,6 +1,6 @@ package com.mockobjects.examples.password; -public class NotFoundException extends Exception { +public class NotFoundException extends PasswordException { public NotFoundException() { super(); } Index: TestForgotPasswordServlet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/password/TestForgotPasswordServlet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestForgotPasswordServlet.java 2001/08/28 22:57:23 1.3 +++ TestForgotPasswordServlet.java 2001/11/17 10:17:17 1.4 @@ -24,14 +24,14 @@ public void setUp() throws ServletException, IOException { passwordServlet = new ForgotPasswordServlet(mockReminder); - passwordServlet.init(createStubServletConfig()); mockRequest.setupAddParameter(ForgotPasswordServlet.EMAIL_PARAM, EMAIL); } public void testReminderEmailSent() throws ServletException, IOException { mockReminder.setExpectedEmailAddress(EMAIL); - mockResponse.setExpectedRedirect(SENT_URI + "?email=" + EMAIL); + mockResponse.setExpectedRedirect( + SENT_URI + "?" + ForgotPasswordServlet.EMAIL_PARAM + "=" + EMAIL); passwordServlet.doGet(mockRequest, mockResponse); @@ -39,6 +39,7 @@ mockReminder.verify(); } +/* public void testEmailNotFound() throws ServletException, IOException { mockReminder.setupEmailNotFound(); @@ -64,6 +65,6 @@ return super.getInitParameter(s); } }; - } + }*/ } |