Search in sources :

Example 11 with Request

use of org.apache.tapestry5.http.services.Request in project tapestry-5 by apache.

the class BaseURLSourceImplTest method hostname_from_environment_variable.

@Test
public void hostname_from_environment_variable() {
    expect(request.getServerPort()).andReturn(80).once();
    expect(request.isSecure()).andReturn(false);
    replay();
    BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "$HOSTNAME", 0, 0);
    assertEquals(baseURLSource.getBaseURL(false), "http://" + System.getenv("HOSTNAME"));
    verify();
}
Also used : BaseURLSourceImpl(org.apache.tapestry5.http.internal.services.BaseURLSourceImpl) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Test(org.testng.annotations.Test)

Example 12 with Request

use of org.apache.tapestry5.http.services.Request in project tapestry-5 by apache.

the class BaseURLSourceImplTest method secure_url_using_default_port.

@Test
public void secure_url_using_default_port() {
    replay();
    BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "localhost", 80, 443);
    assertEquals(baseURLSource.getBaseURL(true), "https://localhost");
    verify();
}
Also used : BaseURLSourceImpl(org.apache.tapestry5.http.internal.services.BaseURLSourceImpl) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Test(org.testng.annotations.Test)

Example 13 with Request

use of org.apache.tapestry5.http.services.Request in project tapestry-5 by apache.

the class BaseURLSourceImplTest method insecure_url_using_default_port.

@Test
public void insecure_url_using_default_port() {
    replay();
    BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "localhost", 80, 443);
    assertEquals(baseURLSource.getBaseURL(false), "http://localhost");
    verify();
}
Also used : BaseURLSourceImpl(org.apache.tapestry5.http.internal.services.BaseURLSourceImpl) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Test(org.testng.annotations.Test)

Example 14 with Request

use of org.apache.tapestry5.http.services.Request in project tapestry-5 by apache.

the class ClientPersistentFieldStorageImplTest method null_value_is_a_remove.

@Test
public void null_value_is_a_remove() {
    Request request = mockRequest(null);
    Link link = mockLink();
    String pageName = "Foo";
    String componentId = "bar.baz";
    String fieldName = "woops";
    replay();
    ClientPersistentFieldStorage storage = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
    storage.postChange(pageName, componentId, fieldName, 99);
    storage.postChange(pageName, componentId, fieldName, null);
    storage.updateLink(link);
    assertTrue(storage.gatherFieldChanges(pageName).isEmpty());
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 15 with Request

use of org.apache.tapestry5.http.services.Request in project tapestry-5 by apache.

the class ClientPersistentFieldStorageImplTest method store_and_restore_a_change.

@SuppressWarnings("unchecked")
@Test
public void store_and_restore_a_change() {
    Request request = mockRequest(null);
    Link link = mockLink();
    String pageName = "Foo";
    String componentId = "bar.baz";
    String fieldName = "biff";
    Object value = 99;
    final Holder<String> holder = captureLinkModification(link);
    replay();
    ClientPersistentFieldStorage storage1 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
    storage1.postChange(pageName, componentId, fieldName, value);
    List<PersistentFieldChange> changes1 = newList(storage1.gatherFieldChanges(pageName));
    storage1.updateLink(link);
    verify();
    assertEquals(changes1.size(), 1);
    PersistentFieldChange change1 = changes1.get(0);
    assertEquals(change1.getComponentId(), componentId);
    assertEquals(change1.getFieldName(), fieldName);
    assertEquals(change1.getValue(), value);
    // Now more training ...
    train_getParameter(request, ClientPersistentFieldStorageImpl.PARAMETER_NAME, holder.get());
    replay();
    ClientPersistentFieldStorage storage2 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
    List<PersistentFieldChange> changes2 = newList(storage2.gatherFieldChanges(pageName));
    verify();
    assertEquals(changes2.size(), 1);
    PersistentFieldChange change2 = changes2.get(0);
    assertEquals(change2.getComponentId(), componentId);
    assertEquals(change2.getFieldName(), fieldName);
    assertEquals(change2.getValue(), value);
    assertNotSame(change1, change2);
}
Also used : Request(org.apache.tapestry5.http.services.Request) PersistentFieldChange(org.apache.tapestry5.services.PersistentFieldChange) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)86 Request (org.apache.tapestry5.http.services.Request)83 Response (org.apache.tapestry5.http.services.Response)25 HttpServletRequest (javax.servlet.http.HttpServletRequest)19 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)19 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)18 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)17 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)15 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 Session (org.apache.tapestry5.http.services.Session)14 Link (org.apache.tapestry5.http.Link)12 RequestImpl (org.apache.tapestry5.http.internal.services.RequestImpl)11 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)9 Context (org.apache.tapestry5.http.services.Context)8 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)8 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)8 IOException (java.io.IOException)7 BaseURLSourceImpl (org.apache.tapestry5.http.internal.services.BaseURLSourceImpl)7 BaseURLSource (org.apache.tapestry5.http.services.BaseURLSource)7 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)7