<commit_before><!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="style.css"/>
    <link rel="stylesheet" type="text/css" href="themes.css"/>
    <link rel="stylesheet" href="http://lab.hakim.se/reveal-js/lib/css/zenburn.css"><!-- For syntax highlighting -->
  </head>

  <body class="coverflow">
    <article>

      <section>
        <h1>pact-jvm</h1>
        <h2>Pact All the Things</h2>
        <h3><a href="http://markdalgleish.com/projects/bespoke.js">bespoke.js</a></h3>
      </section>

      <section>
        <h2>What we intended to do</h2>
        <ul>
          <li>Something</li>
          <li>Something else awesome</li>
          <li>Some other stuff</li>
        </ul>
      </section>

      <section>
        <h2>What we actually did</h2>
        <ul>
          <li>Something</li>
          <li>Something else awesome</li>
          <li>Some other stuff</li>
        </ul>
      </section>

      <section>
        <h2>JSON Conversion</h2>
        <pre><code data-trim class="scala">
class JSONThingy extends DefaultWrites {
  def convert(obj: Map[String,List[String]]): String =
    Json.toJson(obj).toString()
}

...

class TestSomethingSpec extends mutable.Specification {
  "JSON Thingy" should {
    "output valid JSON" in {
      val jsonResult = new JSONThingy().convert(Map("cat" -> List()))
      jsonResult must beEqualTo("{\"cat\":[]}")
    }
  }

...
        </code></pre>
      </section>
      <section>
        <h2>Pact Builder Test</h2>
        <pre><code data-trim class="scala">
...

  "pact" should {
    "be constructed" in {
      val pact:Pact = MakePact()
        .withProvider("p")
        .withConsumer("c")
        .withInteractions(
          given("something")
          .uponReceiving("lol")
        )

      pact.provider.name must beEqualTo("p")
      pact.consumer.name must beEqualTo("c")
      pact.interactions.size must beEqualTo(1)
      pact.interactionFor("something", "lol") must not be None
    }
  }
}
        </code></pre>
      </section>
      <section>
        <h2>Builder: Interaction</h2>
        <pre><code data-trim class="scala">
case class MakeInteraction(
                            description:   Option[String] = None,
                            providerState: Option[String] = None) {
  def uponReceiving(desc:String) = copy(description = Some(desc))
}

object MakeInteraction {

  def given(state:String) = MakeInteraction(providerState = Some(state))

  implicit def build(mi: MakeInteraction):Interaction = {
    Interaction(mi.description.get, mi.providerState.get, null, null) //FIXME
  }

  implicit def build(mis: Seq[MakeInteraction]) : Seq[Interaction] = {
    mis.map(mi => build(mi))
  }
}
        </code></pre>
      </section>
      <section>
        <h2>Builder: Pact</h2>
        <pre><code data-trim class="scala">
case class MakePact(
                     provider:Option[Provider] = None,
                     consumer:Option[Consumer] = None,
                     interactions:Seq[MakeInteraction] = Seq()) {
  def withProvider(name:String) = copy(provider = Some(Provider(name)))
  def withConsumer(name:String) = copy(consumer = Some(Consumer(name)))
  def withInteractions(list:MakeInteraction*) = copy(interactions = list)
}

object MakePact {
  implicit def build(mp:MakePact):Pact = {
    Pact(mp.provider.get, mp.consumer.get, mp.interactions)
  }
}
        </code></pre>
      </section>
      <section>
        <h2>Model</h2>
        <pre><code data-trim class="scala">
case class Pact( provider:Provider,
                 consumer:Consumer,
                 interactions:Seq[Interaction]) {
  def interactionFor(providerState:String, description:String) =
    interactions.find { i =>
      i.description == description &&
      i.providerState == providerState
    }
}

case class Interaction( description:   String,
                        providerState: String,
                        request:       Request,
                        response:      Response)

case class Provider(name:String)
case class Consumer(name:String)
case class Request(path:String)
case class Response(body:String)
        </code></pre>
      </section>

    </article>

    <script src="bespoke.min.js"></script>
    <script src="demo.js"></script>
    <script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
    <script type="text/javascript">
      hljs.initHighlightingOnLoad();
      bespoke.horizontal.from('article');
    </script>
  </body>
</html><commit_msg>add some details to presentation<commit_after><!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="style.css"/>
    <link rel="stylesheet" type="text/css" href="themes.css"/>
    <link rel="stylesheet" href="http://lab.hakim.se/reveal-js/lib/css/zenburn.css"><!-- For syntax highlighting -->
  </head>

  <body class="coverflow">
    <article>

      <section>
        <h1>pact-jvm</h1>
        <h2>Pact All the Things</h2>
        <h3><a href="http://markdalgleish.com/projects/bespoke.js">bespoke.js</a></h3>
      </section>

      <section>
        <h2>What we intended to do</h2>
        <ul>
          <li>Split Pacts into an Author, a Consumer Runner, and a Provider Runner</li>
          <li>implement the Author and the provider runner</li>
          <li>learn scala</li>
        </ul>
      </section>

      <section>
        <h2>What we actually did</h2>
        <ul>
          <li>Argued with Beth about splitting the Author form the Consumer Runner (lost)</li>
          <li>Implemented the Author (mostly)</li>
          <li>Learned that spray-can is a good http server</li>
        </ul>
      </section>

      <section>
        <h2>JSON Conversion</h2>
        <pre><code data-trim class="scala">
class JSONThingy extends DefaultWrites {
  def convert(obj: Map[String,List[String]]): String =
    Json.toJson(obj).toString()
}

...

class TestSomethingSpec extends mutable.Specification {
  "JSON Thingy" should {
    "output valid JSON" in {
      val jsonResult = new JSONThingy().convert(Map("cat" -> List()))
      jsonResult must beEqualTo("{\"cat\":[]}")
    }
  }

...
        </code></pre>
      </section>
      <section>
        <h2>Pact Builder Test</h2>
        <pre><code data-trim class="scala">
...

  "pact" should {
    "be constructed" in {
      val pact:Pact = MakePact()
        .withProvider("p")
        .withConsumer("c")
        .withInteractions(
          given("something")
          .uponReceiving("lol")
        )

      pact.provider.name must beEqualTo("p")
      pact.consumer.name must beEqualTo("c")
      pact.interactions.size must beEqualTo(1)
      pact.interactionFor("something", "lol") must not be None
    }
  }
}
        </code></pre>
      </section>
      <section>
        <h2>Builder: Interaction</h2>
        <pre><code data-trim class="scala">
case class MakeInteraction(
                            description:   Option[String] = None,
                            providerState: Option[String] = None) {
  def uponReceiving(desc:String) = copy(description = Some(desc))
}

object MakeInteraction {

  def given(state:String) = MakeInteraction(providerState = Some(state))

  implicit def build(mi: MakeInteraction):Interaction = {
    Interaction(mi.description.get, mi.providerState.get, null, null) //FIXME
  }

  implicit def build(mis: Seq[MakeInteraction]) : Seq[Interaction] = {
    mis.map(mi => build(mi))
  }
}
        </code></pre>
      </section>
      <section>
        <h2>Builder: Pact</h2>
        <pre><code data-trim class="scala">
case class MakePact(
                     provider:Option[Provider] = None,
                     consumer:Option[Consumer] = None,
                     interactions:Seq[MakeInteraction] = Seq()) {
  def withProvider(name:String) = copy(provider = Some(Provider(name)))
  def withConsumer(name:String) = copy(consumer = Some(Consumer(name)))
  def withInteractions(list:MakeInteraction*) = copy(interactions = list)
}

object MakePact {
  implicit def build(mp:MakePact):Pact = {
    Pact(mp.provider.get, mp.consumer.get, mp.interactions)
  }
}
        </code></pre>
      </section>
      <section>
        <h2>Model</h2>
        <pre><code data-trim class="scala">
case class Pact( provider:Provider,
                 consumer:Consumer,
                 interactions:Seq[Interaction]) {
  def interactionFor(providerState:String, description:String) =
    interactions.find { i =>
      i.description == description &&
      i.providerState == providerState
    }
}

case class Interaction( description:   String,
                        providerState: String,
                        request:       Request,
                        response:      Response)

case class Provider(name:String)
case class Consumer(name:String)
case class Request(path:String)
case class Response(body:String)
        </code></pre>
      </section>

      <section>
          <h2>spray-can server</h2>
          <h3>main</h3>
          <pre><code data-trim class="scala">
implicit val system = ActorSystem()
val handler = system.actorOf(Props[Service], name = "handler")
io.IO(Http) ! Http.Bind(handler, interface = "localhost", port = 8888)
          </code></pre>
      </section>
        <section>
            <h2>spray-can server</h2>
            <h3>handler</h3>
          <pre><code data-trim class="scala">
class Service extends Actor with ActorLogging {
  implicit val system = ActorSystem()

  def receive = {
    case _: Http.Connected => sender ! Http.Register(self)

    case HttpRequest(method, uri, headers, body, _) => {
      // Do Work
      sender ! HttpResponse(status = 200, entity = "hello world", headers = List())
    }
  }
}
          </code></pre>
        </section>
    </article>

    <script src="bespoke.min.js"></script>
    <script src="demo.js"></script>
    <script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
    <script type="text/javascript">
      hljs.initHighlightingOnLoad();
      bespoke.horizontal.from('article');
    </script>
  </body>
</html>
{'fraction_non_alphanumeric': 0.14635364635364637, 'fraction_numerical': 0.006093906093906094, 'mean_word_length': 2.4213943950786057, 'pattern_counts': {'":': 2, '<': 213, '<?xml version=': 0, '>': 221, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6468959', 'n_tokens_mistral': 3169, 'n_tokens_neox': 3077, 'n_words': 644}