-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple example application to demonstrate testing launchpad paramter …
…conversion
- Loading branch information
Showing
4 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
source/Launchpad-Commands-Tests/LaunchpadZnHelloApplicationTest.class.st
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,76 @@ | ||
" | ||
A LaunchpadCommandLineHandlerTest is a test class for testing the behavior of LaunchpadCommandLineHandler | ||
" | ||
Class { | ||
#name : 'LaunchpadZnHelloApplicationTest', | ||
#superclass : 'LaunchpadTest', | ||
#category : 'Launchpad-Commands-Tests', | ||
#package : 'Launchpad-Commands-Tests' | ||
} | ||
|
||
{ #category : 'tests' } | ||
LaunchpadZnHelloApplicationTest >> testConfigParsingInValidLogLevel [ | ||
"Verify the launchpad handler properly handles non numeric input" | ||
|
||
| application mockContext config | | ||
|
||
"Test passing a non-numeric log level parameter" | ||
config := NullConfigurationProvider new | ||
atName: #'log-level' putValue: 'false'; | ||
yourself. | ||
|
||
application := LaunchpadZnHelloApplication | ||
runningIn: DebuggingApplicationMode new | ||
configuredBy: config | ||
controlledBy: NullCommandServer new. | ||
|
||
"Expect the Launchpad application to handle the error and substitute a loglevel of 0" | ||
mockContext := MockObject new | ||
on: #runZnHelloWithPort:debugLevel: | ||
with: 8181 | ||
with: 0; | ||
yourself. | ||
|
||
application basicStartWithin: mockContext. | ||
|
||
mockContext verifyIn: self | ||
] | ||
|
||
{ #category : 'tests' } | ||
LaunchpadZnHelloApplicationTest >> testConfigParsingValidLogLevel [ | ||
"Verify the launchpad handler correctly parses the paramter to an integer" | ||
|
||
| application mockContext config | | ||
|
||
config := NullConfigurationProvider new | ||
atName: #'log-level' putValue: '2'; | ||
yourself. | ||
|
||
application := LaunchpadZnHelloApplication | ||
runningIn: DebuggingApplicationMode new | ||
configuredBy: config | ||
controlledBy: NullCommandServer new. | ||
|
||
mockContext := MockObject new | ||
on: #runZnHelloWithPort:debugLevel: | ||
with: 8181 | ||
with: 2; | ||
yourself. | ||
|
||
application basicStartWithin: mockContext. | ||
|
||
mockContext verifyIn: self | ||
] | ||
|
||
{ #category : 'tests' } | ||
LaunchpadZnHelloApplicationTest >> testDryRunApplication [ | ||
|
||
self | ||
should: [ | ||
LaunchpadCommandLineHandler activateWithArguments: | ||
#( 'launchpad' 'start' '--dry-run' 'znHello' ) | ||
] | ||
raise: Exit | ||
withExceptionDo: [ :exit | self assert: exit isSuccess ] | ||
|
||
] |
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
8 changes: 8 additions & 0 deletions
8
source/Launchpad-Examples/LaunchpadApplicationContext.extension.st
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,8 @@ | ||
Extension { #name : 'LaunchpadApplicationContext' } | ||
|
||
{ #category : '*Launchpad-Examples' } | ||
LaunchpadApplicationContext >> runZnHelloWithPort: portNumber debugLevel: debugLevel [ | ||
"Context extension that allows easy launchpad parameter testing" | ||
|
||
LaunchpadZnHelloApplication startServerOn: portNumber debug: debugLevel | ||
] |
100 changes: 100 additions & 0 deletions
100
source/Launchpad-Examples/LaunchpadZnHelloApplication.class.st
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,100 @@ | ||
" | ||
Small example Zinc server application to demonstrate Launchpad with tiny web server example | ||
" | ||
Class { | ||
#name : 'LaunchpadZnHelloApplication', | ||
#superclass : 'LaunchpadApplication', | ||
#category : 'Launchpad-Examples', | ||
#package : 'Launchpad-Examples' | ||
} | ||
|
||
{ #category : 'accessing' } | ||
LaunchpadZnHelloApplication class >> commandName [ | ||
|
||
^ 'znHello' | ||
] | ||
|
||
{ #category : 'private - accessing' } | ||
LaunchpadZnHelloApplication class >> configurationParameters [ | ||
|
||
^ { | ||
(OptionalConfigurationParameter | ||
named: #'log-level' | ||
describedBy: 'Log http requests level' | ||
defaultingTo: 0). | ||
|
||
(OptionalConfigurationParameter | ||
named: #port | ||
describedBy: 'Server port' | ||
defaultingTo: 8181) } | ||
] | ||
|
||
{ #category : 'accessing' } | ||
LaunchpadZnHelloApplication class >> description [ | ||
|
||
^ 'Launchpad demo zinc http application' | ||
] | ||
|
||
{ #category : 'example' } | ||
LaunchpadZnHelloApplication class >> startServer [ | ||
<script> | ||
"This would really be in its own server class, but here to demonstrate a simple example of a running application to start via the command line. | ||
eg using: launchpad start ZnHello --log-level=2" | ||
|
||
self startServerOn: 8181 debug: true | ||
] | ||
|
||
{ #category : 'example' } | ||
LaunchpadZnHelloApplication class >> startServerOn: port debug: debug [ | ||
"This would really be in its own server class, but here to demonstrate a simple example" | ||
|
||
| server | | ||
server := (ZnServer defaultOn: port). | ||
debug ifTrue: [ server logToTranscript ]. | ||
server start. | ||
] | ||
|
||
{ #category : 'example' } | ||
LaunchpadZnHelloApplication class >> stopServer [ | ||
<script> | ||
"This would really be in its own server class, but here to demonstrate a simple example" | ||
|
||
ZnServer default stop | ||
] | ||
|
||
{ #category : 'accessing' } | ||
LaunchpadZnHelloApplication class >> version [ | ||
|
||
^ 'v1.0.0' | ||
] | ||
|
||
{ #category : 'private - activation' } | ||
LaunchpadZnHelloApplication >> basicStartWithin: context [ | ||
"This is an example of a launcher using a testable #run:withArguments: pattern. See the example test " | ||
|
||
| debugLevel serverPort | | ||
|
||
debugLevel := [(self configuration valueAt: #'log-level') asNumber] on: Error do: [ 0 ]. | ||
serverPort := (self configuration valueAt: #port) asInteger. | ||
|
||
"This would be something to call for your own application class to allow testing" | ||
context runZnHelloWithPort: serverPort debugLevel: debugLevel | ||
] | ||
|
||
{ #category : 'accessing' } | ||
LaunchpadZnHelloApplication >> name [ | ||
|
||
^ self configuration name | ||
] | ||
|
||
{ #category : 'error handling' } | ||
LaunchpadZnHelloApplication >> stackTraceDumper [ | ||
|
||
^ NullStackTraceDumper new | ||
] | ||
|
||
{ #category : 'accessing' } | ||
LaunchpadZnHelloApplication >> title [ | ||
|
||
^ self configuration title | ||
] | ||