Search in sources :

Example 46 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class HeadersTest method nullContentTypeTest.

@Test
public void nullContentTypeTest() {
    IMocksControl control = EasyMock.createNiceControl();
    Message message = new MessageImpl();
    // first check - content-type==null in message, nothing specified in request
    // expect that determineContentType will return the default value of text/xml
    message.put(Message.CONTENT_TYPE, null);
    Headers headers = new Headers(message);
    assertEquals("Unexpected content-type determined - expected text/xml", "text/xml", headers.determineContentType());
    // second check - null specified in request, valid content-type specified in message
    // expect that determineContentType returns the content-type specified in the message
    HttpServletRequest req = control.createMock(HttpServletRequest.class);
    EasyMock.expect(req.getHeaderNames()).andReturn(Collections.emptyEnumeration());
    EasyMock.expect(req.getContentType()).andReturn(null).anyTimes();
    control.replay();
    message = new MessageImpl();
    message.put(Message.CONTENT_TYPE, "application/json");
    headers = new Headers(message);
    headers.copyFromRequest(req);
    assertEquals("Unexpected content-type determined - expected application/json", "application/json", headers.determineContentType());
    control.verify();
    // third check - content-type==null in message, null in request
    // expect that determineContentType returns the default value of text/xml
    control = EasyMock.createNiceControl();
    req = control.createMock(HttpServletRequest.class);
    EasyMock.expect(req.getHeaderNames()).andReturn(Collections.emptyEnumeration());
    EasyMock.expect(req.getContentType()).andReturn(null).anyTimes();
    control.replay();
    message = new MessageImpl();
    message.put(Message.CONTENT_TYPE, null);
    headers = new Headers(message);
    headers.copyFromRequest(req);
    assertEquals("Unexpected content-type determined - expected text/xml", "text/xml", headers.determineContentType());
    control.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) HttpServletRequest(javax.servlet.http.HttpServletRequest) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 47 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class HeadersTest method setHeadersTest.

@Test
public void setHeadersTest() throws Exception {
    IMocksControl control = EasyMock.createNiceControl();
    String[] headerNames = { "Content-Type", "authorization", "soapAction" };
    String[] headerValues = { "text/xml", "Basic Zm9vOmJhcg==", "foo" };
    Map<String, List<String>> inmap = new HashMap<>();
    for (int i = 0; i < headerNames.length; i++) {
        inmap.put(headerNames[i], Arrays.asList(headerValues[i]));
    }
    HttpServletRequest req = control.createMock(HttpServletRequest.class);
    EasyMock.expect(req.getHeaderNames()).andReturn(Collections.enumeration(inmap.keySet()));
    for (int i = 0; i < headerNames.length; i++) {
        EasyMock.expect(req.getHeaders(headerNames[i])).andReturn(Collections.enumeration(inmap.get(headerNames[i])));
    }
    EasyMock.expect(req.getContentType()).andReturn(headerValues[0]).anyTimes();
    control.replay();
    Message message = new MessageImpl();
    message.put(AbstractHTTPDestination.HTTP_REQUEST, req);
    Headers headers = new Headers(message);
    headers.copyFromRequest(req);
    Map<String, List<String>> protocolHeaders = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
    assertTrue("unexpected size", protocolHeaders.size() == headerNames.length);
    assertEquals("unexpected header", protocolHeaders.get("Content-Type").get(0), headerValues[0]);
    assertEquals("unexpected header", protocolHeaders.get("content-type").get(0), headerValues[0]);
    assertEquals("unexpected header", protocolHeaders.get("CONTENT-TYPE").get(0), headerValues[0]);
    assertEquals("unexpected header", protocolHeaders.get("content-TYPE").get(0), headerValues[0]);
    assertEquals("unexpected header", protocolHeaders.get("Authorization").get(0), headerValues[1]);
    assertEquals("unexpected header", protocolHeaders.get("authorization").get(0), headerValues[1]);
    assertEquals("unexpected header", protocolHeaders.get("AUTHORIZATION").get(0), headerValues[1]);
    assertEquals("unexpected header", protocolHeaders.get("authoriZATION").get(0), headerValues[1]);
    assertEquals("unexpected header", protocolHeaders.get("SOAPAction").get(0), headerValues[2]);
    assertEquals("unexpected header", protocolHeaders.get("soapaction").get(0), headerValues[2]);
    assertEquals("unexpected header", protocolHeaders.get("SOAPACTION").get(0), headerValues[2]);
    assertEquals("unexpected header", protocolHeaders.get("soapAction").get(0), headerValues[2]);
    control.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) HttpServletRequest(javax.servlet.http.HttpServletRequest) Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 48 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class DigestAuthSupplierTest method testEncode.

@Test
public void testEncode() throws Exception {
    String origNonce = "MTI0ODg3OTc5NzE2OTplZGUyYTg0Yzk2NTFkY2YyNjc1Y2JjZjU2MTUzZmQyYw==";
    String fullHeader = "Digest realm=\"MyCompany realm.\", qop=\"auth\"," + "nonce=\"" + origNonce + "\"";
    /**
     * Initialize DigestAuthSupplier that always uses the same cnonce so we always
     * get the same response
     */
    DigestAuthSupplier authSupplier = new DigestAuthSupplier() {

        @Override
        public String createCnonce() throws UnsupportedEncodingException {
            return "27db039b76362f3d55da10652baee38c";
        }
    };
    IMocksControl control = EasyMock.createControl();
    AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
    authorizationPolicy.setUserName("testUser");
    authorizationPolicy.setPassword("testPassword");
    URI uri = new URI("http://myserver");
    Message message = new MessageImpl();
    control.replay();
    String authToken = authSupplier.getAuthorization(authorizationPolicy, uri, message, fullHeader);
    HttpAuthHeader authHeader = new HttpAuthHeader(authToken);
    assertEquals("Digest", authHeader.getAuthType());
    Map<String, String> params = authHeader.getParams();
    Map<String, String> expectedParams = new HashMap<>();
    expectedParams.put("response", "28e616b6868f60aaf9b19bb5b172f076");
    expectedParams.put("cnonce", "27db039b76362f3d55da10652baee38c");
    expectedParams.put("username", "testUser");
    expectedParams.put("nc", "00000001");
    expectedParams.put("nonce", "MTI0ODg3OTc5NzE2OTplZGUyYTg0Yzk2NTFkY2YyNjc1Y2JjZjU2MTUzZmQyYw==");
    expectedParams.put("realm", "MyCompany realm.");
    expectedParams.put("qop", "auth");
    expectedParams.put("uri", "");
    expectedParams.put("algorithm", "MD5");
    assertEquals(expectedParams, params);
    control.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) URI(java.net.URI) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 49 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class PolicyDataEngineImplTest method checkAssertWithMap.

/**
 * Simply check that it runs without any exceptions
 *
 * @param assertionInfoMap
 */
private void checkAssertWithMap(AssertionInfoMap assertionInfoMap) {
    PolicyDataEngineImpl pde = new PolicyDataEngineImpl(null);
    pde.setPolicyEngine(new PolicyEngineImpl());
    TestPolicy confPol = new TestPolicy();
    IMocksControl control = EasyMock.createControl();
    PolicyCalculator<TestPolicy> policyCalculator = new TestPolicyCalculator();
    Message message = control.createMock(Message.class);
    EasyMock.expect(message.get(TestPolicy.class)).andReturn(confPol);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(assertionInfoMap);
    control.replay();
    pde.assertMessage(message, confPol, policyCalculator);
    control.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) Message(org.apache.cxf.message.Message)

Example 50 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class ServiceInvokerInterceptorTest method createEndpoint.

Endpoint createEndpoint(Invoker i) throws Exception {
    IMocksControl control = EasyMock.createNiceControl();
    Endpoint endpoint = control.createMock(Endpoint.class);
    ServiceImpl service = new ServiceImpl((ServiceInfo) null);
    service.setInvoker(i);
    service.setExecutor(new SimpleExecutor());
    EasyMock.expect(endpoint.getService()).andReturn(service).anyTimes();
    control.replay();
    return endpoint;
}
Also used : IMocksControl(org.easymock.IMocksControl) Endpoint(org.apache.cxf.endpoint.Endpoint) ServiceImpl(org.apache.cxf.service.ServiceImpl)

Aggregations

IMocksControl (org.easymock.IMocksControl)57 Test (org.junit.Test)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Message (org.apache.cxf.message.Message)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 MessageImpl (org.apache.cxf.message.MessageImpl)9 QName (javax.xml.namespace.QName)7 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)7 Before (org.junit.Before)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Exchange (org.apache.cxf.message.Exchange)6 FakeHttpServletRequest (com.google.gerrit.util.http.testutil.FakeHttpServletRequest)5 FakeHttpServletResponse (com.google.gerrit.util.http.testutil.FakeHttpServletResponse)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Binding (javax.xml.ws.Binding)5 Handler (javax.xml.ws.handler.Handler)5 MessageContext (javax.xml.ws.handler.MessageContext)5