Created
February 10, 2012 10:26
-
-
Save talios/1788598 to your computer and use it in GitHub Desktop.
Xtend HAL test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Running TestSuite | |
| log4j:WARN No appenders could be found for logger (com.ning.http.client.providers.netty.NettyAsyncHttpProvider). | |
| log4j:WARN Please initialize the log4j system properly. | |
| 2012-02-10 23:05:30,251 DEBUG - RouteMatcherFactory - creates RouteMatcher | |
| 2012-02-10 23:05:30,255 DEBUG - SimpleRouteMatcher - Adds route: get, /, com.talios.routes.RootRoute@cbc5ae4 | |
| 2012-02-10 23:05:30,265 DEBUG - SimpleRouteMatcher - Adds route: get, /forums, com.talios.routes.ForumListingRoute@2f11b156 | |
| 2012-02-10 23:05:30,271 DEBUG - SimpleRouteMatcher - Adds route: post, /forums, com.talios.routes.ForumCreationRoute@18d1e874 | |
| 2012-02-10 23:05:30,280 DEBUG - SimpleRouteMatcher - Adds route: get, /forums/:id, com.talios.routes.ForumRoute@5f556d56 | |
| 2012-02-10 23:05:30,281 DEBUG - SimpleRouteMatcher - Adds route: get, /, com.talios.routes.RootRoute@46bc720e | |
| 2012-02-10 23:05:30,281 DEBUG - SimpleRouteMatcher - Adds route: get, /forums, com.talios.routes.ForumListingRoute@fd2ec59 | |
| 2012-02-10 23:05:30,282 DEBUG - SimpleRouteMatcher - Adds route: post, /forums, com.talios.routes.ForumCreationRoute@79f0a8b0 | |
| 2012-02-10 23:05:30,282 DEBUG - SimpleRouteMatcher - Adds route: get, /forums/:id, com.talios.routes.ForumRoute@26d2f95b | |
| == Spark has ignited ... | |
| >> Listening on 0.0.0.0:4567 | |
| 2012-02-10 23:05:30,461 DEBUG - MatcherFilter - httpMethod:get, uri: / | |
| 2012-02-10 23:05:30,462 DEBUG - Request - set params for requestUri: /, matchUri: / | |
| 2012-02-10 23:05:30,568 DEBUG - MatcherFilter - Time for request: 107 | |
| <resource href="http://localhost:4567/"> | |
| <link rel="forums" href="http://localhost:4567/forums" /> | |
| </resource> | |
| 2012-02-10 23:05:30,829 DEBUG - MatcherFilter - httpMethod:get, uri: /forums | |
| 2012-02-10 23:05:30,829 DEBUG - Request - set params for requestUri: /forums, matchUri: /forums | |
| 2012-02-10 23:05:30,840 DEBUG - MatcherFilter - Time for request: 11 | |
| <resource href="http://localhost:4567/forums"> | |
| <resource href="http://localhost:4567/forums/offtopic" rel="forum self"> | |
| <description>Anything goes baby!</description> | |
| <id>offtopic</id> | |
| </resource> | |
| <resource href="http://localhost:4567/forums/gadgets" rel="forum self"> | |
| <description>Gadgets and Toys</description> | |
| <id>gadgets</id> | |
| </resource> | |
| </resource> | |
| 2012-02-10 23:05:30,873 DEBUG - MatcherFilter - httpMethod:get, uri: /forums | |
| 2012-02-10 23:05:30,873 DEBUG - Request - set params for requestUri: /forums, matchUri: /forums | |
| 2012-02-10 23:05:30,875 DEBUG - MatcherFilter - Time for request: 2 | |
| <resource href="http://localhost:4567/forums/gadgets" rel="forum self"> | |
| <description>Gadgets and Toys</description> | |
| <id>gadgets</id> | |
| </resource> | |
| 2012-02-10 23:05:30,883 DEBUG - MatcherFilter - httpMethod:get, uri: /forums/gadgets | |
| 2012-02-10 23:05:30,883 DEBUG - Request - set params for requestUri: /forums/gadgets, matchUri: /forums/:id | |
| 2012-02-10 23:05:30,883 DEBUG - Request - matchedPart: :id = gadgets | |
| 2012-02-10 23:05:30,887 DEBUG - MatcherFilter - Time for request: 4 | |
| <resource href="http://localhost:4567/forums/gadgets"> | |
| <link rel="forums" href="http://localhost:4567/forums" /> | |
| <description>Gadgets and Toys</description> | |
| <id>gadgets</id> | |
| <name>Gadget Talk</name> | |
| <owner>example@example.com</owner> | |
| </resource> | |
| Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.906 sec | |
| Results : | |
| Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.talios; | |
| import com.google.common.base.Optional; | |
| import com.talios.App; | |
| import com.theoryinpractise.halbuilder.ResourceFactory; | |
| import com.theoryinpractise.halbuilder.spi.Link; | |
| import com.theoryinpractise.halbuilder.spi.ReadableResource; | |
| import com.theoryinpractise.halbuilder.spi.RenderableResource; | |
| import com.theoryinpractise.halbuilder.spi.Resource; | |
| import java.util.List; | |
| import java.util.Map; | |
| import java.util.concurrent.Future; | |
| import org.eclipse.xtext.xbase.lib.Exceptions; | |
| import org.eclipse.xtext.xbase.lib.Functions.Function0; | |
| import org.eclipse.xtext.xbase.lib.Functions.Function1; | |
| import org.eclipse.xtext.xbase.lib.InputOutput; | |
| import org.eclipse.xtext.xbase.lib.IterableExtensions; | |
| import org.eclipse.xtext.xbase.lib.ObjectExtensions; | |
| import org.testng.annotations.BeforeTest; | |
| import org.testng.annotations.Test; | |
| @SuppressWarnings("all") | |
| public class TestXtendApp { | |
| private ResourceFactory rf = new Function0<ResourceFactory>() { | |
| public ResourceFactory apply() { | |
| ResourceFactory _resourceFactory = new ResourceFactory(); | |
| return _resourceFactory; | |
| } | |
| }.apply(); | |
| @BeforeTest | |
| public void setup() { | |
| App.main(null); | |
| } | |
| @Test | |
| public void testResource() { | |
| Future<ReadableResource> _openResource = this.rf.openResource("http://localhost:4567/"); | |
| final Future<ReadableResource> root = _openResource; | |
| String _asXml = this.asXml(root); | |
| InputOutput.<String>println(_asXml); | |
| ReadableResource _follow = this.follow(root, "forums"); | |
| String _asXml_1 = this.asXml(_follow); | |
| InputOutput.<String>println(_asXml_1); | |
| ReadableResource _follow_1 = this.follow(root, "forums"); | |
| List<Resource> _resources = _follow_1.getResources(); | |
| final Function1<Resource,Boolean> _function = new Function1<Resource,Boolean>() { | |
| public Boolean apply(final Resource r) { | |
| Map<String,Object> _properties = r.getProperties(); | |
| Object _get = _properties.get("id"); | |
| boolean _operator_equals = ObjectExtensions.operator_equals(_get, "gadgets"); | |
| return Boolean.valueOf(_operator_equals); | |
| } | |
| }; | |
| Resource _findFirst = IterableExtensions.<Resource>findFirst(_resources, _function); | |
| final Resource gadgets = _findFirst; | |
| String _asXml_2 = this.asXml(gadgets); | |
| InputOutput.<String>println(_asXml_2); | |
| ReadableResource _follow_2 = this.follow(gadgets, "self"); | |
| String _asXml_3 = this.asXml(_follow_2); | |
| InputOutput.<String>println(_asXml_3); | |
| } | |
| public String asXml(final Future<ReadableResource> res) { | |
| try { | |
| ReadableResource _get = res.get(); | |
| String _asXml = this.asXml(_get); | |
| return _asXml; | |
| } catch (Exception _e) { | |
| throw Exceptions.sneakyThrow(_e); | |
| } | |
| } | |
| public String asXml(final ReadableResource res) { | |
| RenderableResource _asRenderableResource = res.asRenderableResource(); | |
| String _renderContent = _asRenderableResource.renderContent(ResourceFactory.HALXML); | |
| return _renderContent; | |
| } | |
| public ReadableResource follow(final Future<ReadableResource> res, final String rel) { | |
| try { | |
| ReadableResource _get = res.get(); | |
| ReadableResource _follow = this.follow(_get, rel); | |
| return _follow; | |
| } catch (Exception _e) { | |
| throw Exceptions.sneakyThrow(_e); | |
| } | |
| } | |
| public ReadableResource follow(final ReadableResource res, final String rel) { | |
| try { | |
| Optional<Link> _linkByRel = res.getLinkByRel(rel); | |
| Link _get = _linkByRel.get(); | |
| Future<ReadableResource> _openResource = _get.openResource(); | |
| ReadableResource _get_1 = _openResource.get(); | |
| return _get_1; | |
| } catch (Exception _e) { | |
| throw Exceptions.sneakyThrow(_e); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.talios | |
| import com.theoryinpractise.halbuilder.ResourceFactory | |
| import com.theoryinpractise.halbuilder.spi.ReadableResource | |
| import com.theoryinpractise.halbuilder.spi.Resource | |
| import org.testng.annotations.BeforeTest | |
| import org.testng.annotations.Test | |
| import java.util.concurrent.Future | |
| class TestXtendApp { | |
| ResourceFactory rf = new ResourceFactory() | |
| @BeforeTest | |
| def void setup() { | |
| App::main(null) | |
| } | |
| @Test | |
| def void testResource() { | |
| val root = rf.openResource("http://localhost:4567/"); | |
| println(root.asXml) | |
| println(root.follow("forums").asXml) | |
| val gadgets = root.follow("forums").resources.findFirst(r | r.properties.get("id") == "gadgets") | |
| println(gadgets.asXml) | |
| println(gadgets.follow("self").asXml) | |
| } | |
| // Some useful extension methods | |
| def asXml(Future<ReadableResource> res) { | |
| res.get.asXml | |
| } | |
| def asXml(ReadableResource res) { | |
| res.asRenderableResource().renderContent(ResourceFactory::HALXML) | |
| } | |
| def follow(Future<ReadableResource> res, String rel) { | |
| res.get.follow(rel) | |
| } | |
| def follow(ReadableResource res, String rel) { | |
| res.getLinkByRel(rel).get.openResource.get | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment