Java Code Examples for org.apache.axis2.addressing.EndpointReference#setAddress()

The following examples show how to use org.apache.axis2.addressing.EndpointReference#setAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityHandlerAdapterTest.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a handler configuration similar to the following with no resources defined.
 * <p>
 * <handler name="SampleInternalApiHandlerWithNoResources"
 *          class="internal.http.api.SampleInternalApiHandlerWithNoResources"/>
 */
@Test
public void testHandledWithNoResource() {

    //set message context
    MessageContext messageContext = new TestMessageContext();
    EndpointReference endpointReference = new EndpointReference();
    endpointReference.setAddress("/sectest/resource1");
    messageContext.setTo(endpointReference);

    TestSecurityHandler internalAPIHandler = new TestSecurityHandler("/sectest");

    //test with no resources
    internalAPIHandler.setResources(new ArrayList<>());
    internalAPIHandler.invoke(messageContext);
    Assert.assertTrue("Handler should be engaged when no resources are explictely defined, but it was not engaged.",
                      internalAPIHandler.isHandleTriggered());
}
 
Example 2
Source File: SecurityHandlerAdapterTest.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a handler configuration similar to the following.
 *
 * <handler name="SampleInternalApiHandlerWithAllResources"
 *          class="internal.http.api.SampleInternalApiHandlerWithAllResources">
 *  <resources>
 *      <resource>/</resource>
 *  </resources>
 *</handler>
 */
@Test
public void testHandledWithAllResources() {

    //Create test message context
    MessageContext messageContext = new TestMessageContext();
    EndpointReference endpointReference = new EndpointReference();
    messageContext.setTo(endpointReference);

    TestSecurityHandler internalAPIHandler = new TestSecurityHandler("/sectest");
    List<String> resources = new ArrayList<>();
    resources.add("/");
    internalAPIHandler.setResources(resources);

    //set message context with matching resource
    endpointReference.setAddress("/sectest/resource1");
    internalAPIHandler.invoke(messageContext);
    Assert.assertTrue("Handler should be engaged since all resources are defined, but it was not engaged.",
                      internalAPIHandler.isHandleTriggered());
}
 
Example 3
Source File: SecurityHandlerAdapterTest.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Tests a handler configuration similar to the following.
 * <p>
 * <handler name="SampleInternalApiHandlerWithCustomResources"
 *          class="internal.http.api.SampleInternalApiHandlerWithCustomResources">
 *  <resources>
 *      <resource>/resource1</resource>
 *      <resource>/resource2</resource>
 *  </resources>
 *</handler>
 */
@Test
public void testHandledWithCustomResources() {

    //Create test message context
    MessageContext messageContext = new TestMessageContext();
    EndpointReference endpointReference = new EndpointReference();
    messageContext.setTo(endpointReference);

    TestSecurityHandler internalAPIHandler = new TestSecurityHandler("/sectest");
    List<String> resources = new ArrayList<>();
    resources.add("/resource1");
    resources.add("/resource2");
    internalAPIHandler.setResources(resources);

    //set message context with matching resource
    endpointReference.setAddress("/sectest/resource1");
    internalAPIHandler.invoke(messageContext);
    Assert.assertTrue("Handler should be engaged since resource 1 was defined, but it was not engaged.",
                      internalAPIHandler.isHandleTriggered());

    //set message context with matching resource
    endpointReference.setAddress("/sectest/resource2");
    internalAPIHandler.invoke(messageContext);
    Assert.assertTrue("Handler should be engaged since resource 2 was defined, but it was not engaged.",
                      internalAPIHandler.isHandleTriggered());

    //set message context with matching resource but containing a sub resource
    endpointReference.setAddress("/sectest/resource2/resource22");
    internalAPIHandler.invoke(messageContext);
    Assert.assertTrue("Handler should be engaged since resource 2 was defined, but it was not engaged.",
                      internalAPIHandler.isHandleTriggered());

    //set message context with a resource that is not matching
    endpointReference.setAddress("/sectest/resource3");
    internalAPIHandler.invoke(messageContext);
    Assert.assertFalse("Handler should not be engaged since resource 3 was not defined, but it was engaged.",
                       internalAPIHandler.isHandleTriggered());

}