From e8b4c4e788dbca67e9461afcd008b631d08a9d04 Mon Sep 17 00:00:00 2001 From: Giri Dandu Date: Wed, 18 Mar 2015 10:25:16 -0400 Subject: [PATCH] Make whoas configuration optional - If configuration is not present, create InMemoryQueue and SequentialHookRunner - Add unit tests - Update docs with configuration section - Fixes #14 --- README.md | 2 + docs/html5/configuration.html | 536 ++++++++++++++++++ .../lookout/whoas/WhoasConfiguration.html | 216 +++++++ .../github/lookout/whoas/WhoasFactory.html | 381 +++++++++++++ src/asciidoc/configuration.ad | 14 + .../github/lookout/whoas/WhoasFactory.groovy | 14 +- .../lookout/whoas/WhoasFactorySec.groovy | 68 +++ whoas.iml | 42 -- 8 files changed, 1226 insertions(+), 47 deletions(-) create mode 100644 docs/html5/configuration.html create mode 100644 docs/html5/groovydoc/com/github/lookout/whoas/WhoasConfiguration.html create mode 100644 docs/html5/groovydoc/com/github/lookout/whoas/WhoasFactory.html create mode 100644 src/asciidoc/configuration.ad create mode 100644 src/test/groovy/com/github/lookout/whoas/WhoasFactorySec.groovy delete mode 100644 whoas.iml diff --git a/README.md b/README.md index c7de1ef..07cea49 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,6 @@ This project intends to be a library to help implement the service-side of [Webhooks](https://en.wikipedia.org/wiki/Webhook). Allowing services to implement reliable webhook-based notifications. +* [Configuration ](http://hackers.lookout.com/whoas/configuration.html) + ![whoa](http://www.reactiongifs.us/wp-content/uploads/2013/03/bill_ted_whoa.gif) diff --git a/docs/html5/configuration.html b/docs/html5/configuration.html new file mode 100644 index 0000000..16f11da --- /dev/null +++ b/docs/html5/configuration.html @@ -0,0 +1,536 @@ + + + + + + + + +Default behavior + + + + + + +
+

Library Configuration

+
+

The clients of whoas library can add "whoas" configuration to build queue and runner of their choice. +See the example below

+
+
+

whos: + queueType: "com.github.lookout.whoas.Queue" + runnerType: "com.github.lookout.whoas.SequentialHookRunner"

+
+
+ + + \ No newline at end of file diff --git a/docs/html5/groovydoc/com/github/lookout/whoas/WhoasConfiguration.html b/docs/html5/groovydoc/com/github/lookout/whoas/WhoasConfiguration.html new file mode 100644 index 0000000..e26b5be --- /dev/null +++ b/docs/html5/groovydoc/com/github/lookout/whoas/WhoasConfiguration.html @@ -0,0 +1,216 @@ + + + + + + + + + + WhoasConfiguration (whoas 0.1.2 API) + + + + + + + + + + +
+ + + + + +
+ + + + + +
+ +
Package: com.github.lookout.whoas
+ +

[Groovy] Interface WhoasConfiguration<T>

+
+
+ +
+
    +
  • + + +

    The interface to create the whoas factory based on configuration + The client of whoas will call with the configuration to create the whoas factory. +

    Parameters:
    < - T > Configuration class that extends dropwizard configuration

    + +
  • +
+
+ +
+
    +
  • + + + + + + + + + + + + + + + + + + +
      + +
    • +

      Methods Summary

      + +
    • + +
    + +
  • +
+
+ +
+
    +
  • + + + + + + + + + + + + + +
      +
    • + + +

      Method Detail

      + + + + +
    • +
    + +
  • +
+
+ + + +
+ + + + + +
+ + +
+ + + diff --git a/docs/html5/groovydoc/com/github/lookout/whoas/WhoasFactory.html b/docs/html5/groovydoc/com/github/lookout/whoas/WhoasFactory.html new file mode 100644 index 0000000..59120f7 --- /dev/null +++ b/docs/html5/groovydoc/com/github/lookout/whoas/WhoasFactory.html @@ -0,0 +1,381 @@ + + + + + + + + + + WhoasFactory (whoas 0.1.2 API) + + + + + + + + + + +
+ + + + + +
+ + + + + +
+ +
Package: com.github.lookout.whoas
+ +

[Groovy] Class WhoasFactory

+
+
+ +
+
    +
  • + + + +

    This factory will allow clients of whoas to build + different queues like in memory, persistent etc and runners + like sequential. +

    + +
  • +
+
+ +
+
    +
  • + + + + + + + + + + +
      +
    • +

      Properties Summary

      +
        + + + + + + + + + + + + + + + + + +
        Properties 
        TypeName and description
        java.lang.String queueType
        Type of queue to create in whoas
        java.lang.String runnerType
        Type of runner to create in whoas.
        +
      +
    • +
    + + + + + + + + + +
      + +
    • +

      Methods Summary

      +
        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        Methods 
        TypeName and description
        AbstractHookQueuebuildQueue()
        Allocate and return the queue based on stored queue type.
        AbstractHookRunnerbuildRunner(AbstractHookQueue hookQueue)
        Allocate and return runner based on stored runner type
        java.lang.StringgetQueueType()
        Get function for queue type in the factory
        java.lang.StringgetRunnerType()
        Get function for runner type in the factory
        voidsetQueueType(java.lang.String queueType)
        Set function for the queue type in the factory
        java.lang.ObjectsetRunnerType(java.lang.String runnerType)
        Set function for runner type in the factory
        +
      +
    • + +
    • +

      Inherited Methods Summary

      +
        + + + + + + + + + + + +
        Inherited Methods 
        Methods inherited from className
        class java.lang.Objectjava.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
        +
      +
    • + +
    + +
  • +
+
+ +
+
    +
  • + + + + + + +
      +
    • + + +

      Property Detail

      + + +
        +
      • +

        @com.fasterxml.jackson.annotation.JsonProperty +java.lang.String queueType

        +

        Type of queue to create in whoas + + Default queue in whoas is InMemoryQueue +

        +
      • +
      + + +
        +
      • +

        @com.fasterxml.jackson.annotation.JsonProperty +java.lang.String runnerType

        +

        Type of runner to create in whoas. + + Default runner in whoas is SequentialHookRunner +

        +
      • +
      + +
    • +
    + + + + + + + + + +
      +
    • + + +

      Method Detail

      + + +
        +
      • +

        AbstractHookQueue buildQueue()

        +

        Allocate and return the queue based on stored queue type. + + If the queue cannot be created, then this throws + ClassNotFoundException - if the class is not found + IllegalAccessException - if the class or its nullary constructor is not accessible. + InstantiationException - if this Class represents an abstract class, an interface, + an array class, a primitive type, or void; + or if the class has no nullary constructor; + or if the instantiation fails for some other reason. +

        Returns:
        allocated queue

        +
      • +
      + + +
        +
      • +

        AbstractHookRunner buildRunner(AbstractHookQueue hookQueue)

        +

        Allocate and return runner based on stored runner type + + If the runner cannot be created, then this throws + ClassNotFoundException - if the class is not found + IllegalAccessException - if the class or its nullary constructor is not accessible. + InstantiationException - if this Class represents an abstract class, an interface, + an array class, a primitive type, or void; + or if the class has no nullary constructor; + or if the instantiation fails for some other reason.

        Parameters:
        hookQueue - queue to associate with allocated runner
        Returns:

        +
      • +
      + + +
        +
      • +

        java.lang.String getQueueType()

        +

        Get function for queue type in the factory +

        Returns:
        queue type in the factory

        +
      • +
      + + +
        +
      • +

        java.lang.String getRunnerType()

        +

        Get function for runner type in the factory +

        Returns:
        runner type in the factory

        +
      • +
      + + +
        +
      • +

        void setQueueType(java.lang.String queueType)

        +

        Set function for the queue type in the factory +

        Parameters:
        queueType - type of queue to store

        +
      • +
      + + +
        +
      • +

        java.lang.Object setRunnerType(java.lang.String runnerType)

        +

        Set function for runner type in the factory

        Parameters:
        runnerType - type of the runner to store
        Returns:

        +
      • +
      + +
    • +
    + +
  • +
+
+ + + +
+ + + + + +
+ + +
+ + + diff --git a/src/asciidoc/configuration.ad b/src/asciidoc/configuration.ad new file mode 100644 index 0000000..692fd7d --- /dev/null +++ b/src/asciidoc/configuration.ad @@ -0,0 +1,14 @@ +Default behavior +================ +If clients of whoas library don't have any whoas configuration, the whoas factory will create +InMemoryQueue and SequentialHookRunner + +Library Configuration +===================== + +The clients of whoas library can add "whoas" configuration to build queue and runner of their choice. +See the example below + +whos: + queueType: "com.github.lookout.whoas.Queue" + runnerType: "com.github.lookout.whoas.SequentialHookRunner" diff --git a/src/main/groovy/com/github/lookout/whoas/WhoasFactory.groovy b/src/main/groovy/com/github/lookout/whoas/WhoasFactory.groovy index 80bf716..115ce76 100644 --- a/src/main/groovy/com/github/lookout/whoas/WhoasFactory.groovy +++ b/src/main/groovy/com/github/lookout/whoas/WhoasFactory.groovy @@ -12,10 +12,11 @@ public class WhoasFactory { /** * Type of queue to create in whoas + * + * Default queue in whoas is InMemoryQueue */ @JsonProperty - @NotEmpty - String queueType + String queueType = "com.github.lookout.whoas.InMemoryQueue" /** * Get function for queue type in the factory @@ -36,11 +37,12 @@ public class WhoasFactory { } /** - * Type of runner to create in whoas + * Type of runner to create in whoas. + * + * Default runner in whoas is SequentialHookRunner */ @JsonProperty - @NotEmpty - String runnerType + String runnerType = "com.github.lookout.whoas.SequentialHookRunner" /** * Get function for runner type in the factory @@ -65,6 +67,7 @@ public class WhoasFactory { * Allocate and return the queue based on stored queue type. * * If the queue cannot be created, then this throws + * ClassNotFoundException - if the class is not found * IllegalAccessException - if the class or its nullary constructor is not accessible. * InstantiationException - if this Class represents an abstract class, an interface, * an array class, a primitive type, or void; @@ -80,6 +83,7 @@ public class WhoasFactory { * Allocate and return runner based on stored runner type * * If the runner cannot be created, then this throws + * ClassNotFoundException - if the class is not found * IllegalAccessException - if the class or its nullary constructor is not accessible. * InstantiationException - if this Class represents an abstract class, an interface, * an array class, a primitive type, or void; diff --git a/src/test/groovy/com/github/lookout/whoas/WhoasFactorySec.groovy b/src/test/groovy/com/github/lookout/whoas/WhoasFactorySec.groovy new file mode 100644 index 0000000..9d7676f --- /dev/null +++ b/src/test/groovy/com/github/lookout/whoas/WhoasFactorySec.groovy @@ -0,0 +1,68 @@ +package com.github.lookout.whoas + +import spock.lang.* + +class WhoasFactorySpec extends Specification { + + def "by default buildQueue should create InMemoryQueue"() { + given: + WhoasFactory whoasFactory = new WhoasFactory() + InMemoryQueue inMemoryQueue = whoasFactory.buildQueue() + + expect: + inMemoryQueue instanceof InMemoryQueue + } + + def "by default buildRunner should create SequentialHookRunner"() { + given: + WhoasFactory whoasFactory = new WhoasFactory() + SequentialHookRunner sequentialHookRunner = whoasFactory.buildRunner( + whoasFactory.buildQueue()) + + expect: + sequentialHookRunner instanceof SequentialHookRunner + } + + def "given a queue class name, buildQueue should create specified queue"() { + given: + WhoasFactory whoasFactory = new WhoasFactory() + whoasFactory.setQueueType("com.github.lookout.whoas.InMemoryQueue") + InMemoryQueue inMemoryQueue = whoasFactory.buildQueue() + + expect: + inMemoryQueue instanceof InMemoryQueue + + } + + def "given a invalid class name, buildQueue should throw ClassNotFound exception"() { + when: + WhoasFactory whoasFactory = new WhoasFactory() + whoasFactory.setQueueType("com.github.lookout.InvalidQueue") + AbstractHookQueue abstractHookQueue = whoasFactory.buildQueue() + + then: + thrown(ClassNotFoundException) + + } + def "given a runner class name, buildQueue should create specified queue"() { + given: + WhoasFactory whoasFactory = new WhoasFactory() + whoasFactory.setRunnerType("com.github.lookout.whoas.SequentialHookRunner") + SequentialHookRunner sequentialHookRunner = whoasFactory.buildRunner(whoasFactory.buildQueue()) + + expect: + sequentialHookRunner instanceof SequentialHookRunner + + } + + def "given a invalid class name, buildRunner should throw ClassNotFound exception"() { + when: + WhoasFactory whoasFactory = new WhoasFactory() + whoasFactory.setRunnerType("com.github.lookout.whoas.Invalidunner") + AbstractHookRunner abstractHookRunner = whoasFactory.buildRunner(whoasFactory.buildQueue()) + + then: + thrown(ClassNotFoundException) + + } +} \ No newline at end of file diff --git a/whoas.iml b/whoas.iml deleted file mode 100644 index 54523a4..0000000 --- a/whoas.iml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file