Search in sources :

Example 1 with AuthorizationRequiredException

use of com.meterware.httpunit.AuthorizationRequiredException in project javaee7-samples by javaee-samples.

the class MyResourceTest method testGetWithCorrectCredentials.

@Test
public void testGetWithCorrectCredentials() throws IOException, SAXException {
    WebConversation conv = new WebConversation();
    conv.setAuthentication("file", "u1", "p1");
    GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource");
    WebResponse response = null;
    try {
        response = conv.getResponse(getRequest);
    } catch (AuthorizationRequiredException e) {
        fail(e.getMessage());
    }
    assertNotNull(response);
    assertTrue(response.getText().contains("get"));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) AuthorizationRequiredException(com.meterware.httpunit.AuthorizationRequiredException) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 2 with AuthorizationRequiredException

use of com.meterware.httpunit.AuthorizationRequiredException in project javaee7-samples by javaee-samples.

the class MyResourceTest method testGetSubResourceWithCorrectCredentials.

@Test
public void testGetSubResourceWithCorrectCredentials() throws IOException, SAXException {
    WebConversation conv = new WebConversation();
    conv.setAuthentication("file", "u1", "p1");
    GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource/1");
    WebResponse response = null;
    try {
        response = conv.getResponse(getRequest);
    } catch (AuthorizationRequiredException e) {
        fail(e.getMessage());
    }
    assertNotNull(response);
    assertTrue(response.getText().contains("get1"));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) AuthorizationRequiredException(com.meterware.httpunit.AuthorizationRequiredException) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 3 with AuthorizationRequiredException

use of com.meterware.httpunit.AuthorizationRequiredException in project javaee7-samples by javaee-samples.

the class MyResourceTest method testGetWithIncorrectCredentials.

@Test
public void testGetWithIncorrectCredentials() throws IOException, SAXException {
    WebConversation conv = new WebConversation();
    conv.setAuthentication("file", "random", "random");
    GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource");
    try {
        WebResponse response = conv.getResponse(getRequest);
    } catch (AuthorizationRequiredException e) {
        assertNotNull(e);
        return;
    }
    fail("GET can be called with incorrect credentials");
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) AuthorizationRequiredException(com.meterware.httpunit.AuthorizationRequiredException) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Aggregations

AuthorizationRequiredException (com.meterware.httpunit.AuthorizationRequiredException)3 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)3 WebConversation (com.meterware.httpunit.WebConversation)3 WebResponse (com.meterware.httpunit.WebResponse)3 Test (org.junit.Test)3