diff --git a/source/Launchpad-Commands-Tests/LaunchpadZnHelloApplicationTest.class.st b/source/Launchpad-Commands-Tests/LaunchpadZnHelloApplicationTest.class.st new file mode 100644 index 0000000..7e2c476 --- /dev/null +++ b/source/Launchpad-Commands-Tests/LaunchpadZnHelloApplicationTest.class.st @@ -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 ] + +] diff --git a/source/Launchpad-Commands/LaunchpadCommandLineHandler.class.st b/source/Launchpad-Commands/LaunchpadCommandLineHandler.class.st index d15c168..36038b2 100644 --- a/source/Launchpad-Commands/LaunchpadCommandLineHandler.class.st +++ b/source/Launchpad-Commands/LaunchpadCommandLineHandler.class.st @@ -59,5 +59,7 @@ LaunchpadCommandLineHandler >> activateWithContext: context [ StandardStreamLogger onStandardError startFor: ( LogRecord where: [ :record | record isInformational not ] ). + LogRecord emitInfo: 'Launchpad processing command line parameters'. + ^ LaunchpadRootCommand new evaluateWithin: context ] diff --git a/source/Launchpad-Examples/LaunchpadApplicationContext.extension.st b/source/Launchpad-Examples/LaunchpadApplicationContext.extension.st new file mode 100644 index 0000000..f2c97a4 --- /dev/null +++ b/source/Launchpad-Examples/LaunchpadApplicationContext.extension.st @@ -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 +] diff --git a/source/Launchpad-Examples/LaunchpadZnHelloApplication.class.st b/source/Launchpad-Examples/LaunchpadZnHelloApplication.class.st new file mode 100644 index 0000000..9e3b85b --- /dev/null +++ b/source/Launchpad-Examples/LaunchpadZnHelloApplication.class.st @@ -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 [ +