Package org.glassfish.jersey.examples.shortener.webapp.domain

Examples of org.glassfish.jersey.examples.shortener.webapp.domain.ShortenedLink


        final Form form = new Form("link", "https://java.net/");
        final Response created = target().request("text/html").post(Entity.form(form));

        assertThat(created.getStatus(), equalTo(200));

        final ShortenedLink shortenedLink = ShortenerService.shortenLink(getBaseUri(), "https://java.net/");
        final Response resolved = client().target(shortenedLink.getShortened()).request().get();

        assertThat(resolved.getStatus(), equalTo(301));
        assertThat(resolved.getHeaderString(HttpHeaders.LOCATION), equalTo(shortenedLink.getOriginal().toString()));
    }
View Full Code Here


    @Test
    public void testShortenLinksSame() throws Exception {
        final String url = "http://localhost:8080/shortener-webapp";
        URI baseUri = URI.create("");

        ShortenedLink link = ShortenerService.shortenLink(baseUri, url);

        assertThat(link.getOriginal(), equalTo(URI.create(url)));
        assertThat(link.getShortened(), notNullValue());

        link = ShortenerService.shortenLink(baseUri, url);

        assertThat(link.getOriginal(), equalTo(URI.create(url)));
        assertThat(link.getShortened(), notNullValue());

        final URI shortened = link.getShortened();
        assertThat(shortened, equalTo(link.getShortened()));
    }
View Full Code Here

    @Ignore
    public void testShortenLinksDifferent() throws Exception {
        final String url = "http://localhost:8080/shortener-webapp";
        URI baseUri = URI.create("");

        ShortenedLink link = ShortenerService.shortenLink(baseUri, url);

        assertThat(link.getOriginal(), equalTo(URI.create(url)));
        assertThat(link.getShortened(), notNullValue());

        link = ShortenerService.shortenLink(baseUri, url);

        assertThat(link.getOriginal(), equalTo(URI.create(url)));
        assertThat(link.getShortened(), notNullValue());

        final URI shortened = link.getShortened();
        assertThat(shortened, not(equalTo(link.getShortened())));
    }
View Full Code Here

        if (store.containsKey(encode(link))) {
            return store.get(encode(link));
        }

        String path = link;
        ShortenedLink shortenedLink;

        do {
            path = encode(path);
            shortenedLink = new ShortenedLink(URI.create(link),
                    UriBuilder.fromUri(baseUri).path("i").path(path).build(),
                    UriBuilder.fromUri(baseUri).path("r").path(path).build());
        } while (store.putIfAbsent(path, shortenedLink) != null);

        return store.get(path);
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.examples.shortener.webapp.domain.ShortenedLink

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.