You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Sachin <cs...@pisoftek.com> on 2003/08/04 12:19:22 UTC

About TestCases

Hello Kumar..

I am part of this forum for 3-4 days but i have as feeling that as compare
to other here activity is too slow and
I am not getting reponse for my question.

I have posted 3 Questions but got no reponse.well ia have just started
testCases with StrutsTestCase which has facility
to write TestCases with cactus but i am not able to test Struts Action with
cactus or with mockObject based approach

Well then i have tried to run Example with testCase but not successful..

So could you guide me where i can get proper feedback on testCases of Struts
with Catus Approach....


if Any body have Any suggestion then plz help me



So can Any body help me in this..


public class TestSampleAction extends MockStrutsTestCase {

    public TestLoginAction(String testName) { super(testName); }

    public void testSuccessfulLogin() {
       setRequestPathInfo("/login");
       addRequestParameter("username","deryl");
       addRequestParameter("password","radar");
       actionPerform();
    }
}


[main] INFO util.PropertyMessageResources  -
Initializing,config='org.apache.struts.util.LocalStrings', returnNull=true
[main] INFO util.PropertyMessageResources  -
Initializing,config='org.apache.struts.action.ActionResources',
returnNull=true

Time: 0.625
There was 1 failure:
1)testAction(logic.struts.actions.TestFirstAction)
junit.framework.AssertionFailedError: Error running action.perform():
classjava.lang.NullPointerException - null
	at
servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:
339)
	at logic.struts.actions.TestFirstAction.testAction(TestFirstAction.java:47)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
	at
com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12)
FAILURES!!!




Re: fileupload

Posted by Christopher Lenz <cm...@gmx.de>.
Stefan Groschupf wrote:

> Hi incites, ;)
> 
> I want to test file upload with strutsTestCase.
> I found this link.
> 
> http://jakarta.apache.org/cactus/faq.html#faq7
> 
> Since the link to the httpclient is dead and I can't find a other download
> location can someone provide me the hhtpclient package from Ronald Tschalär?

The link works here.

> Is this package related to the apache httpclient?

No (it is sometimes referred to as the "innovation.ch HTTPClient").

But AFAIK Apache Commons-HttpClient also supports file upload. You might 
prefer to use that because you should already have Commons-HttpClient on 
your classpath.

http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/methods/multipart/package-summary.html

-- 
Christopher Lenz
/=/ cmlenz at gmx.de


multi part

Posted by Stefan Groschupf <sg...@media-style.com>.
Hi there,
sorry i have still problems with testing uploading.
I steeled HttClient from an other project cvs. I take the code from the
cactus faq. I use an extension to catus: struststest 2.0.0.
I don't get an multi part request in my struts action, but can't see where
an mistake could be..
Someone can give an hint?

Thanks a lot!!!
Stefan

My code looks like:
	NVPair[] hdrs = new NVPair[1];

	public void beginCreateDocumente(org.apache.cactus.WebRequest theRequest) {

		WetaSecurityManager.getInstance().setPrincipal(getSession(), new
Principal(ITestDatabaseEntries.CONTENT_ADMIN, "pw"));
		LoginContext loginContext;
		try {

// ... create some test data ...
File file1 = new File(System.getProperty("java.io.tmpdir") +
"/HttpUploadUtilsTest.dat");
			//	  setup the file(s) name value pair object.
			NVPair[] file = { new NVPair("binaryTypeAttribute",
file1.getAbsolutePath())};

			form_data[0] = new NVPair(IParameterKeys.LOCALE, "en");
			form_data[1] = new NVPair(IParameterKeys.NAME, "a test name");
			form_data[2] = new NVPair(IParameterKeys.FOLDER_PK, "" + folderPK);
			form_data[3] = new NVPair(IParameterKeys.XSLT, xslts[0]);
			form_data[4] = new NVPair(IParameterKeys.TYPE_PK, "" + typePK);

			byte[] data = Codecs.mpFormDataEncode(form_data, file, hdrs);
			InputStream i = new ByteArrayInputStream(data);
			theRequest.setUserData(i);
			theRequest.setContentType(hdrs[0].getValue());


			i.close();
			loginContext.logout();
		} catch (IOException e) {
			System.out.println("Error Building Multipart");
		} catch (LoginException e) {
			System.err.println("error: " + e.toString());
		} catch (CreateException e) {
			System.err.println("error: " + e.toString());
		} catch (NamingException e) {
			System.err.println("error: " + e.toString());
		} catch (FinderException e) {
			System.err.println("error: " + e.toString());
		} catch (RemoveException e) {
			System.err.println("error: " + e.toString());
		} catch (WetaDocumentException e) {
			System.err.println("error: " + e.toString());
		}

	}



	public void testCreateDocument() throws LoginException, FinderException,
RemoveException, CreateException, NamingException, WetaDocumentException {

		setRequestPathInfo("/" + IActionKeys.CREATE_DOCUMENT);

		verifyForward("Xslt");
		assertEquals(getRequest().getAttribute("xslt"), "message");
		assertTrue(getRequest().getAttribute("xml") instanceof Document);

	}





RE: fileupload

Posted by Vincent Massol <vm...@pivolis.com>.
Hi Stefan,

You can also try http://www.freeroller.net/page/tradem/20030722. It
seems Tobias has succeeded in using Commons-httpclient to perform file
uploads with Cactus.

Thanks
-Vincent

> -----Original Message-----
> From: Stefan Groschupf [mailto:sg@media-style.com]
> Sent: 04 August 2003 15:38
> To: Cactus Users List
> Subject: fileupload
> 
> Hi incites, ;)
> 
> I want to test file upload with strutsTestCase.
> I found this link.
> 
> http://jakarta.apache.org/cactus/faq.html#faq7
> 
> Since the link to the httpclient is dead and I can't find a other
download
> location can someone provide me the hhtpclient package from Ronald
> Tschalär?
> Is this package related to the apache httpclient?
> 
> Thanks
> Stefan
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org



fileupload

Posted by Stefan Groschupf <sg...@media-style.com>.
Hi incites, ;)

I want to test file upload with strutsTestCase.
I found this link.

http://jakarta.apache.org/cactus/faq.html#faq7

Since the link to the httpclient is dead and I can't find a other download
location can someone provide me the hhtpclient package from Ronald Tschal�r?
Is this package related to the apache httpclient?

Thanks
Stefan





AW: About TestCases

Posted by Stefan Groschupf <sg...@media-style.com>.
Looks like your test failed since you have an nullpointer exception in your
struts action.
So your test runs but your code not.

May be it make sense to use container tests for your struts class?

Greetings
Stefan

-----Urspr�ngliche Nachricht-----
Von: Sachin [mailto:csachin@pisoftek.com]
Gesendet: 04 August 2003 12:19
An: Kumar_maniranjan@infosys.com
Betreff: About TestCases

Hello Kumar..

I am part of this forum for 3-4 days but i have as feeling that as compare
to other here activity is too slow and
I am not getting reponse for my question.

I have posted 3 Questions but got no reponse.well ia have just started
testCases with StrutsTestCase which has facility
to write TestCases with cactus but i am not able to test Struts Action with
cactus or with mockObject based approach

Well then i have tried to run Example with testCase but not successful..

So could you guide me where i can get proper feedback on testCases of Struts
with Catus Approach....


if Any body have Any suggestion then plz help me



So can Any body help me in this..


public class TestSampleAction extends MockStrutsTestCase {

    public TestLoginAction(String testName) { super(testName); }

    public void testSuccessfulLogin() {
       setRequestPathInfo("/login");
       addRequestParameter("username","deryl");
       addRequestParameter("password","radar");
       actionPerform();
    }
}


[main] INFO util.PropertyMessageResources  -
Initializing,config='org.apache.struts.util.LocalStrings', returnNull=true
[main] INFO util.PropertyMessageResources  -
Initializing,config='org.apache.struts.action.ActionResources',
returnNull=true

Time: 0.625
There was 1 failure:
1)testAction(logic.struts.actions.TestFirstAction)
junit.framework.AssertionFailedError: Error running action.perform():
classjava.lang.NullPointerException - null
        at
servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:
339)
        at
logic.struts.actions.TestFirstAction.testAction(TestFirstAction.java:47)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
        at
com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12)
FAILURES!!!




---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-user-help@jakarta.apache.org