This repository has been archived by the owner on Mar 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inherit/merge parameters from prototype #646
- Loading branch information
Showing
4 changed files
with
152 additions
and
5 deletions.
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
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
54 changes: 54 additions & 0 deletions
54
src/test/resources/com/atomist/rug/runtime/js/HandlerWithInherritedParameters.ts
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,54 @@ | ||
import {HandleCommand, Instruction, Response, HandlerContext, CommandPlan, DirectedMessage, UserAddress} from '@atomist/rug/operations/Handlers' | ||
import {CommandHandler, MappedParameter, declareMappedParameter, Parameter, declareParameter, Tags, Intent} from '@atomist/rug/operations/Decorators' | ||
import {Build} from "@atomist/rug/cortex/stub/Build" | ||
|
||
let config = {description: "desc", pattern: "@any"} | ||
|
||
@CommandHandler("Uses same config object") | ||
class ParentHandler implements HandleCommand{ | ||
|
||
@Parameter(config) | ||
foo: number | ||
|
||
@Parameter(config) | ||
bar: number | ||
|
||
@MappedParameter("blah-parent") | ||
blah: string | ||
|
||
@MappedParameter("quz-parent") | ||
quz: string | ||
|
||
handle(ctx: HandlerContext) { | ||
return new CommandPlan(); | ||
} | ||
} | ||
|
||
export let parent = new ParentHandler(); | ||
|
||
|
||
@CommandHandler("Child with overrides") | ||
class ChildHandler extends ParentHandler { | ||
|
||
@Parameter({description: "child", pattern: "@any"}) | ||
foo: number | ||
|
||
@Parameter(config) | ||
baz: number | ||
|
||
@MappedParameter("blah-child") | ||
blah: string | ||
|
||
@MappedParameter("really-child") | ||
really: string | ||
|
||
handle(ctx: HandlerContext) { | ||
return new CommandPlan(); | ||
} | ||
} | ||
const child = new ChildHandler(); | ||
declareParameter(child, "baz", {description: "dup", pattern: "@any"}) | ||
declareMappedParameter(child, "really", "manual") | ||
|
||
export { child }; | ||
|
45 changes: 45 additions & 0 deletions
45
src/test/scala/com/atomist/rug/runtime/js/JavaScriptUtilsTest.scala
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,45 @@ | ||
package com.atomist.rug.runtime.js | ||
|
||
import com.atomist.project.archive.{AtomistConfig, DefaultAtomistConfig} | ||
import com.atomist.rug.RugArchiveReader | ||
import com.atomist.rug.TestUtils.contentOf | ||
import com.atomist.rug.ts.TypeScriptBuilder | ||
import com.atomist.source.{SimpleFileBasedArtifactSource, StringFileArtifact} | ||
import org.scalatest.{FunSpec, Matchers} | ||
|
||
class JavaScriptUtilsTest extends FunSpec with Matchers { | ||
|
||
val atomistConfig: AtomistConfig = DefaultAtomistConfig | ||
|
||
val parameterInherritance = StringFileArtifact(atomistConfig.handlersRoot + "/Handler.ts", | ||
contentOf(this, "HandlerWithInherritedParameters.ts")) | ||
|
||
it("should inherit parameters from the prototype") { | ||
val rugArchive = TypeScriptBuilder.compileWithExtendedModel( | ||
SimpleFileBasedArtifactSource(parameterInherritance)) | ||
val rugs = RugArchiveReader(rugArchive) | ||
val handler = rugs.commandHandlers.head | ||
val params = handler.parameters | ||
assert(params.size === 3) | ||
assert(params(1).name === "foo") | ||
assert(params(1).description === "child") | ||
assert(params(2).name === "bar") | ||
assert(params.head.name === "baz") | ||
assert(params.head.description === "dup") | ||
} | ||
|
||
it("should inherit mapped parameters from the prototype") { | ||
val rugArchive = TypeScriptBuilder.compileWithExtendedModel( | ||
SimpleFileBasedArtifactSource(parameterInherritance)) | ||
val rugs = RugArchiveReader(rugArchive) | ||
val handler = rugs.commandHandlers.head | ||
val params = handler.mappedParameters | ||
assert(params.size === 3) | ||
assert(params.head.localKey === "really") | ||
assert(params.head.foreignKey === "manual") | ||
assert(params(1).localKey === "blah") | ||
assert(params(1).foreignKey === "blah-child") | ||
assert(params(2).localKey === "quz") | ||
assert(params(2).foreignKey === "quz-parent") | ||
} | ||
} |