Skip to content

Commit

Permalink
Merge pull request #8 from hmrc/refactor-tests
Browse files Browse the repository at this point in the history
refactor-tests: Refactored test structure, added unit test for defini…
  • Loading branch information
MJCallahanPage authored Nov 28, 2016
2 parents 2877987 + 4e5a702 commit 8214b8c
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 167 deletions.
11 changes: 6 additions & 5 deletions app/controllers/DocumentationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@

package controllers

import play.api.mvc.{Action, AnyContent}
import uk.gov.hmrc.play.microservice.controller.BaseController

trait Documentation extends AssetsBuilder with BaseController {
trait DocumentationController extends AssetsBuilder with BaseController {

val definition = super.at(s"/public/api", "definition.json")

def documentation(version: String, endpointName: String) =
super.at(s"/public/api/documentation/$version", s"${endpointName.replaceAll(" ", "-")}.xml")
val documentation: (String, String) => Action[AnyContent] = (version, endPointName) =>
super.at(s"/public/api/documentation/$version", s"${endPointName.replaceAll(" ", "-")}.xml")

def raml(version: String, file: String) =
val raml: (String, String) => Action[AnyContent] = (version, file) =>
super.at(s"/public/api/conf/$version", file)
}

object Documentation extends Documentation
object DocumentationController extends DocumentationController
2 changes: 1 addition & 1 deletion app/controllers/HelloWorldController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package controllers

import common.validation.HeaderValidator
import models.ErrorInternalServerError
import play.api.libs.json.Json
import services.{HelloWorldService, LiveHelloWorldService, SandboxHelloWorldService}
import uk.gov.hmrc.play.http.HeaderCarrier
import uk.gov.hmrc.play.microservice.controller.BaseController
import common.validation.HeaderValidator
import scala.concurrent.ExecutionContext.Implicits.global

trait HelloWorldController extends BaseController with HeaderValidator {
Expand Down
2 changes: 1 addition & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ controllers {
needsAuditing = false
}

controllers.Documentation = {
controllers.DocumentationController = {
needsAuth = false
needsLogging = false
needsAuditing = false
Expand Down
6 changes: 3 additions & 3 deletions conf/definition.routes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GET /api/definition controllers.Documentation.definition()
GET /api/documentation/:version/:endpointName controllers.Documentation.documentation(version,endpointName)
GET /api/conf/:version/*file controllers.Documentation.raml(version, file)
GET /api/definition controllers.DocumentationController.definition()
GET /api/documentation/:version/:endpointName controllers.DocumentationController.documentation(version,endpointName)
GET /api/conf/:version/*file controllers.DocumentationController.raml(version, file)
3 changes: 3 additions & 0 deletions project/MicroService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ trait MicroService {
retrieveManaged := true,
evictionWarningOptions in update := EvictionWarningOptions.default.withWarnScalaVersionEviction(false)
)
.settings(
unmanagedResourceDirectories in Compile += baseDirectory.value / "resources"
)
.configs(IntegrationTest)
.settings(inConfig(IntegrationTest)(Defaults.itSettings): _*)
.settings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

package unit.common.validation
package common.validation

import common.validation.HeaderValidator
import org.scalatest.Matchers
import uk.gov.hmrc.play.test.UnitSpec

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

package unit.config
package config

import config.ServiceLocatorRegistration
import connectors.ServiceLocatorConnector
import org.mockito.Matchers._
import org.mockito.Mockito._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

package unit.connectors
package connectors

import connectors.ServiceLocatorConnector
import domain.Registration
import org.mockito.Mockito._
import org.scalatest.concurrent.ScalaFutures
Expand Down
41 changes: 41 additions & 0 deletions test/controllers/DocumentationControllerSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2016 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package controllers

import play.api.libs.json.{JsValue, Json}
import play.api.test.FakeRequest
import uk.gov.hmrc.play.test.{UnitSpec, WithFakeApplication}

import scala.io.Source

class DocumentationControllerSpec extends UnitSpec with WithFakeApplication {

val definitionSource: String = Source.fromFile("resources/public/api/definition.json").getLines.mkString
val expectedJsonDefinition: JsValue = Json.parse(definitionSource)

"Calling the .definition method" should {
lazy val result = DocumentationController.definition(FakeRequest())

"return Status OK (200)" in {
status(result) shouldBe 200
}

"return the Json Definition response" in {
jsonBodyOf(await(result)) shouldBe expectedJsonDefinition
}
}
}
72 changes: 0 additions & 72 deletions test/it/PlatformIntegrationSpec.scala

This file was deleted.

33 changes: 0 additions & 33 deletions test/it/utils/MicroserviceLocalRunSugar.scala

This file was deleted.

46 changes: 0 additions & 46 deletions test/it/utils/WiremockServiceLocatorSugar.scala

This file was deleted.

File renamed without changes.

0 comments on commit 8214b8c

Please sign in to comment.