Search in sources :

Example 1 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class AbstractInjectorTest method before.

@Before
public void before() {
    app.setServletContext(new MockServletContext(app, null));
    ThreadContext.setApplication(app);
    app.setName(getClass().getName());
    app.initApplication();
    Session session = new WebSession(new MockWebRequest(Url.parse("/")));
    app.getSessionStore().bind(null, session);
    ThreadContext.setSession(session);
    GuiceComponentInjector injector = new GuiceComponentInjector(app, new Module() {

        @Override
        public void configure(final Binder binder) {
            binder.bind(ITestService.class).to(TestService.class);
            binder.bind(ITestService.class).annotatedWith(Red.class).to(TestServiceRed.class);
            binder.bind(ITestService.class).annotatedWith(Blue.class).to(TestServiceBlue.class);
            binder.bind(new TypeLiteral<Map<String, String>>() {
            }).toProvider(new Provider<Map<String, String>>() {

                @Override
                public Map<String, String> get() {
                    Map<String, String> strings = new HashMap<>();
                    strings.put(ITestService.RESULT, ITestService.RESULT);
                    return strings;
                }
            });
            binder.bind(String.class).annotatedWith(Names.named("named1")).toInstance("NAMED_1");
            binder.bind(String.class).annotatedWith(Names.named("named2")).toInstance("NAMED_2");
            binder.bind(String.class).annotatedWith(new Jsr330Named("named1")).toInstance("NAMED_1");
            binder.bind(String.class).annotatedWith(new Jsr330Named("named2")).toInstance("NAMED_2");
            binder.bind(EvilTestService.class).toInstance(new EvilTestService("evil123", 5));
        }
    });
    app.getComponentInstantiationListeners().add(injector);
}
Also used : HashMap(java.util.HashMap) MockServletContext(org.apache.wicket.protocol.http.mock.MockServletContext) Provider(com.google.inject.Provider) Binder(com.google.inject.Binder) WebSession(org.apache.wicket.protocol.http.WebSession) MockWebRequest(org.apache.wicket.mock.MockWebRequest) Module(com.google.inject.Module) HashMap(java.util.HashMap) Map(java.util.Map) WebSession(org.apache.wicket.protocol.http.WebSession) Session(org.apache.wicket.Session) Before(org.junit.Before)

Example 2 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class PackageMapperTest method testGetCompatibilityScore.

/**
 * https://issues.apache.org/jira/browse/WICKET-5565
 */
@Test
public void testGetCompatibilityScore() {
    Url url = Url.parse(MOUNT_PATH + '/' + "MyPage");
    MockWebRequest request = new MockWebRequest(url);
    int score = encoder.getCompatibilityScore(request);
    assertEquals(4, score);
    url = Url.parse(MOUNT_PATH + "/foo/bar/" + "MyPage");
    request = new MockWebRequest(url);
    score = namedParametersEncoder.getCompatibilityScore(request);
    assertEquals(6, score);
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 3 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method test6.

/**
 */
@Test
public void test6() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("url/")));
    assertEquals("./x?1", r1.renderUrl(Url.parse("url/x?1")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 4 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method renderUrlWithManyDotsAtTheBeginning2.

/**
 * https://issues.apache.org/jira/browse/WICKET-6230
 */
@Test
public void renderUrlWithManyDotsAtTheBeginning2() {
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(Url.parse("a/b")));
    String renderedUrl = renderer.renderUrl(Url.parse("...abc"));
    assertEquals("../...abc", renderedUrl);
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 5 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method test11.

/**
 * <a href="https://issues.apache.org/jira/browse/WICKET-3337">WICKET-3337</a>
 */
@Test
public void test11() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("a")));
    assertEquals(".", r1.renderUrl(Url.parse("")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Aggregations

MockWebRequest (org.apache.wicket.mock.MockWebRequest)54 Test (org.junit.Test)52 UrlRenderer (org.apache.wicket.request.UrlRenderer)47 Url (org.apache.wicket.request.Url)29 Locale (java.util.Locale)2 MockServletContext (org.apache.wicket.protocol.http.mock.MockServletContext)2 IRequestHandler (org.apache.wicket.request.IRequestHandler)2 Binder (com.google.inject.Binder)1 Module (com.google.inject.Module)1 Provider (com.google.inject.Provider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Session (org.apache.wicket.Session)1 MockApplication (org.apache.wicket.mock.MockApplication)1 WebSession (org.apache.wicket.protocol.http.WebSession)1 IExceptionMapper (org.apache.wicket.request.IExceptionMapper)1 IRequestCycle (org.apache.wicket.request.IRequestCycle)1