-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:framework-one/fw1 into develop
- Loading branch information
Showing
6 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
component { | ||
this.name = 'fw1-examples-rest'; | ||
this.mappings[ '/framework' ] = expandPath( '../framework' ); | ||
|
||
function _get_framework_one() { | ||
if ( !structKeyExists( request, '_framework_one' ) ) { | ||
request._framework_one = new framework.one( { | ||
decodeRequestBody = true, | ||
reloadApplicationOnEveryRequest = true | ||
} ); | ||
} | ||
return request._framework_one; | ||
} | ||
|
||
// delegation of lifecycle methods to FW/1: | ||
function onApplicationStart() { | ||
return _get_framework_one().onApplicationStart(); | ||
} | ||
function onError( exception, event ) { | ||
return _get_framework_one().onError( exception, event ); | ||
} | ||
function onRequest( targetPath ) { | ||
return _get_framework_one().onRequest( targetPath ); | ||
} | ||
function onRequestEnd() { | ||
return _get_framework_one().onRequestEnd(); | ||
} | ||
function onRequestStart( targetPath ) { | ||
return _get_framework_one().onRequestStart( targetPath ); | ||
} | ||
function onSessionStart() { | ||
return _get_framework_one().onSessionStart(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
component { | ||
|
||
function init( any fw ) { | ||
variables.fw = fw; | ||
return this; | ||
} | ||
|
||
function patch( struct rc, struct headers ) { | ||
var response = { | ||
"method": "PATCH", | ||
"multi": rc.multi, | ||
"single": rc.single | ||
}; | ||
variables.fw.renderData().type( 'json' ).data( response ); | ||
} | ||
|
||
function post( struct rc, struct headers ) { | ||
var response = { | ||
"method": "POST", | ||
"multi": rc.multi, | ||
"single": rc.single | ||
}; | ||
variables.fw.renderData().type( 'json' ).data( response ); | ||
} | ||
|
||
function put( struct rc, struct headers ) { | ||
var response = { | ||
"method": "PUT", | ||
"multi": rc.multi, | ||
"single": rc.single | ||
}; | ||
variables.fw.renderData().type( 'json' ).data( response ); | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!--- intentionally blank ---> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This rest example is used by the tests to assert that data is decoded as expected |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
component extends="mxunit.framework.TestCase" { | ||
|
||
function testPostFormEncodedRequestDecodesMultiField() { | ||
var actual = doFormEncodedHTTPRequest( "POST" ); | ||
assertEquals( "POST", actual.method ); | ||
assertEquals( "a,b,c", actual.single ); | ||
assertEquals( "1,2,3,40,50", actual.multi ); | ||
} | ||
|
||
function testPatchFormEncodedRequestDecodesMultiField() skip="engineNotSupported" { | ||
var actual = doFormEncodedHTTPRequest( "PATCH" ); | ||
assertEquals( "PATCH", actual.method ); | ||
assertEquals( "a,b,c", actual.single ); | ||
assertEquals( "1,2,3,40,50", actual.multi ); | ||
} | ||
|
||
function testPutFormEncodedRequestDecodesMultiField() { | ||
var actual = doFormEncodedHTTPRequest( "PUT" ); | ||
assertEquals( "PUT", actual.method ); | ||
assertEquals( "a,b,c", actual.single ); | ||
assertEquals( "1,2,3,40,50", actual.multi ); | ||
} | ||
|
||
function testPostJSONEncodedRequestDecodesMultiField() { | ||
var actual = doJSONEncodedHTTPRequest( "POST" ); | ||
assertEquals( "POST", actual.method ); | ||
assertEquals( "a,b,c", actual.single ); | ||
assertEquals( "1,2,3,40,50", actual.multi ); | ||
} | ||
|
||
function testPatchJSONRequestDecodesMultiField() skip="engineNotSupported" { | ||
var actual = doJSONEncodedHTTPRequest( "PATCH" ); | ||
assertEquals( "PATCH", actual.method ); | ||
assertEquals( "a,b,c", actual.single ); | ||
assertEquals( "1,2,3,40,50", actual.multi ); | ||
} | ||
|
||
function testPutJSONRequestDecodesMultiField() { | ||
var actual = doJSONEncodedHTTPRequest( "PUT" ); | ||
assertEquals( "PUT", actual.method ); | ||
assertEquals( "a,b,c", actual.single ); | ||
assertEquals( "1,2,3,40,50", actual.multi ); | ||
} | ||
|
||
|
||
|
||
private function doFormEncodedHTTPRequest( verb ) { | ||
return doHTTPRequest( verb, "application/x-www-form-urlencoded", "multi=1%2C2%2C3&multi=40&multi=50&single=a%2Cb%2Cc" ); | ||
} | ||
|
||
private function doJSONEncodedHTTPRequest( verb ) { | ||
return doHTTPRequest( verb, "application/json", '{"multi": "1,2,3,40,50","single": "a,b,c"}' ); | ||
} | ||
|
||
private function doHTTPRequest( verb, contentType, body ) { | ||
var httpService = new http(); | ||
httpService.setmethod( verb ); | ||
httpService.setCharset( "utf-8" ); | ||
httpService.setUrl( "http://#CGI.SERVER_NAME#:#CGI.SERVER_PORT#/examples/rest/?action=main.#verb#" ); | ||
httpService.addParam( type = "header", name = "content-type", value = contentType ); | ||
httpService.addParam( type = "body", value = body ); | ||
var response = httpService.send().getPrefix().filecontent; | ||
if ( isJson( response ) ) { | ||
return deserializeJSON( response ); | ||
} | ||
fail( "expected a JSON response for #verb# #contentType#" ); | ||
} | ||
|
||
function engineNotSupported() { | ||
return server.coldfusion.productname != "Lucee" && ListFirst( server.coldfusion.productversion ) == 10; | ||
} | ||
|
||
} |