Skip to content

Commit dd45d81

Browse files
authored
APIS-6913: Subprojects for integration and component tests (#496)
1 parent d81f454 commit dd45d81

26 files changed

+168
-328
lines changed

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version="3.5.3"
1+
version="3.7.17"
22
runner.dialect = "scala213"
33

44
maxColumn = 180

acceptance/uk/gov/hmrc/apidocumentation/BaseSpec.scala renamed to acceptance/test/uk/gov/hmrc/apidocumentation/BaseSpec.scala

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ package uk.gov.hmrc.apidocumentation
1919
import com.github.tomakehurst.wiremock.WireMockServer
2020
import com.github.tomakehurst.wiremock.client.WireMock
2121
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
22+
import org.scalatest.concurrent.Eventually
23+
import org.scalatest.featurespec.AnyFeatureSpec
24+
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
25+
import org.scalatestplus.play.guice.GuiceOneServerPerTest
2226

2327
import play.api.inject.guice.GuiceApplicationBuilder
28+
import play.api.test.TestServerFactory
2429
import play.api.{Application, Mode}
25-
import org.scalatest.BeforeAndAfterAll
26-
import org.scalatest.BeforeAndAfterEach
27-
import org.scalatest.featurespec.AnyFeatureSpec
28-
import uk.gov.hmrc.apidocumentation.common.MyTestServerFactory
29-
import org.scalatestplus.play.guice.GuiceOneServerPerTest
30-
import org.scalatest.concurrent.Eventually
3130
import uk.gov.hmrc.selenium.webdriver.{Browser, Driver, ScreenshotOnFailure}
32-
import play.api.test.TestServerFactory
31+
32+
import uk.gov.hmrc.apidocumentation.common.MyTestServerFactory
3333

3434
trait BaseSpec extends AnyFeatureSpec
35-
with BeforeAndAfterAll
36-
with BeforeAndAfterEach
37-
with GuiceOneServerPerTest
38-
with Eventually
39-
with Browser
40-
with ScreenshotOnFailure {
35+
with BeforeAndAfterAll
36+
with BeforeAndAfterEach
37+
with GuiceOneServerPerTest
38+
with Eventually
39+
with Browser
40+
with ScreenshotOnFailure {
4141

4242
val stubPort = 11111
4343
val stubHost = "localhost"
@@ -49,12 +49,12 @@ trait BaseSpec extends AnyFeatureSpec
4949
override def fakeApplication(): Application = {
5050
GuiceApplicationBuilder()
5151
.configure(
52-
"microservice.services.developer-frontend.host" -> stubHost,
53-
"microservice.services.developer-frontend.port" -> stubPort,
52+
"microservice.services.developer-frontend.host" -> stubHost,
53+
"microservice.services.developer-frontend.port" -> stubPort,
5454
"microservice.services.api-platform-microservice.host" -> stubHost,
5555
"microservice.services.api-platform-microservice.port" -> stubPort,
56-
"microservice.services.third-party-developer.host" -> stubHost,
57-
"microservice.services.third-party-developer.port" -> stubPort,
56+
"microservice.services.third-party-developer.host" -> stubHost,
57+
"microservice.services.third-party-developer.port" -> stubPort,
5858
"microservice.services.api-platform-xml-services.host" -> stubHost,
5959
"microservice.services.api-platform-xml-services.port" -> stubPort
6060
)

acceptance/uk/gov/hmrc/apidocumentation/DescriptiveMocks.scala renamed to acceptance/test/uk/gov/hmrc/apidocumentation/DescriptiveMocks.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ trait DescriptiveMocks extends Stubs {
3838
condition(s"$serviceName is deployed with version $version")
3939
developerIsSignedIn()
4040
fetchDefinition(serviceName)
41-
fetchApiSpec(serviceName,version)
41+
fetchApiSpec(serviceName, version)
4242
}
4343

4444
def apiDocumentationTestServiceVersionsIsDeployed(): Unit = {
45-
val versions = List("0.1", "0.2", "0.3", "0.4", "1.0", "1.1", "1.2","1.3", "1.5", "2.0")
45+
val versions = List("0.1", "0.2", "0.3", "0.4", "1.0", "1.1", "1.2", "1.3", "1.5", "2.0")
4646
versions.foreach { version =>
4747
apiDocumentationTestServiceIsDeployed("api-documentation-test-service", version)
4848
}
File renamed without changes.

acceptance/uk/gov/hmrc/apidocumentation/NavigationSugar.scala renamed to acceptance/test/uk/gov/hmrc/apidocumentation/NavigationSugar.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
package spec
17+
package uk.gov.hmrc.apidocumentation
1818

1919
import org.mockito.MockitoSugar
2020
import org.scalatest.concurrent.Eventually
2121
import org.scalatest.matchers.should.Matchers
2222
import org.scalatest.time.{Millis, Seconds, Span}
2323
import org.scalatest.{Assertion, Assertions}
2424

25-
import uk.gov.hmrc.apidocumentation.WebPage
2625
import uk.gov.hmrc.selenium.webdriver.Driver
2726

27+
import uk.gov.hmrc.apidocumentation.WebPage
28+
2829
trait NavigationSugar extends Assertions with Matchers with Eventually with MockitoSugar {
2930

3031
implicit override val patienceConfig: PatienceConfig = PatienceConfig(timeout = scaled(Span(5, Seconds)), interval = scaled(Span(100, Millis)))

acceptance/uk/gov/hmrc/apidocumentation/PageObject.scala renamed to acceptance/test/uk/gov/hmrc/apidocumentation/PageObject.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
package uk.gov.hmrc.apidocumentation
1818

19-
import org.openqa.selenium.{By, Keys, WebDriver, WebElement}
20-
import org.openqa.selenium.support.ui.{ExpectedConditions, FluentWait, Select, Wait}
21-
import uk.gov.hmrc.selenium.webdriver.Driver
2219
import java.time.Duration
2320
import scala.jdk.CollectionConverters._
2421

22+
import org.openqa.selenium.support.ui.{ExpectedConditions, FluentWait, Select, Wait}
23+
import org.openqa.selenium.{By, Keys, WebDriver, WebElement}
24+
25+
import uk.gov.hmrc.selenium.webdriver.Driver
26+
2527
trait PageObject {
2628

2729
protected def click(locator: By): Unit = {
@@ -59,7 +61,7 @@ trait PageObject {
5961

6062
protected def findElements(locator: By): List[WebElement] =
6163
Driver.instance.findElements(locator).asScala.toList
62-
64+
6365
protected def waitForElementToBePresent(locator: By): WebElement =
6466
fluentWait.until(ExpectedConditions.presenceOfElementLocated(locator))
6567

@@ -73,7 +75,7 @@ trait PageObject {
7375

7476
trait TextInput {
7577
self: PageObject =>
76-
78+
7779
private def clear(locator: By): Unit = {
7880
waitForElementToBePresent(locator)
7981
findElement(locator).get.clear()
@@ -92,7 +94,7 @@ trait TextInput {
9294
}
9395

9496
trait CheckBox {
95-
self : PageObject =>
97+
self: PageObject =>
9698

9799
protected def isSelected(locator: By): Boolean =
98100
findElement(locator).get.isSelected()
@@ -108,14 +110,14 @@ trait CheckBox {
108110
}
109111

110112
trait SelectChoice {
111-
self : PageObject =>
113+
self: PageObject =>
112114

113115
private def withSelect(locator: By)(action: Select => Unit): Unit = {
114116
waitForElementToBePresent(locator)
115117
val select = new Select(findElement(locator).get)
116118
action(select)
117-
}
118-
119+
}
120+
119121
protected def selectByValue(locator: By, value: String): Unit =
120122
withSelect(locator)(_.selectByValue(value))
121123

@@ -127,4 +129,4 @@ trait SelectChoice {
127129

128130
protected def deselectByVisibleText(locator: By, value: String): Unit =
129131
withSelect(locator)(_.deselectByVisibleText(value))
130-
}
132+
}

acceptance/uk/gov/hmrc/apidocumentation/Stubs.scala renamed to acceptance/test/uk/gov/hmrc/apidocumentation/Stubs.scala

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@
1616

1717
package uk.gov.hmrc.apidocumentation
1818

19-
import com.github.tomakehurst.wiremock.client.WireMock._
20-
import play.utils.UriEncoding
2119
import scala.io.Source
20+
21+
import com.github.tomakehurst.wiremock.client.WireMock._
22+
2223
import play.api.libs.json.Json
24+
import play.utils.UriEncoding
25+
2326
import uk.gov.hmrc.apidocumentation.models.apispecification.ApiSpecification
2427

2528
trait Stubs extends ApiMicroservice with DeveloperFrontend with ApiPlatformMicroservice with XmlServices
2629

2730
trait XmlServices {
31+
2832
def fetchAllXmlApis(): Unit = {
2933
val allXmlApisJson = Source.fromURL(getClass.getResource("/acceptance/api-platform-xml-services/xml_apis.json")).mkString
3034

@@ -38,7 +42,8 @@ trait XmlServices {
3842
}
3943
}
4044

41-
trait ApiPlatformMicroservice{
45+
trait ApiPlatformMicroservice {
46+
4247
def fetchAll(): Unit = {
4348
val allDefinitionJson = Source.fromURL(getClass.getResource(s"/acceptance/api-definition/all.json")).mkString
4449

@@ -63,19 +68,18 @@ trait ApiPlatformMicroservice{
6368
}
6469

6570
def fetchApiSpec(serviceName: String, version: String): Unit = {
66-
val url = getClass.getResource(s"/services/$serviceName/spec_${version}.json")
71+
val url = getClass.getResource(s"/services/$serviceName/spec_${version}.json")
6772
val file = Source.fromURL(url).mkString
6873
import uk.gov.hmrc.apidocumentation.models.apispecification.ApiSpecificationFormatters._
6974
Json.fromJson[ApiSpecification](Json.parse(file))
7075

7176
stubFor(get(urlPathEqualTo(s"/combined-api-definitions/$serviceName/$version/specification"))
7277
.willReturn(
7378
aResponse()
74-
.withStatus(200)
75-
.withHeader("Content-Type", "application/json")
76-
.withBody(file)
77-
)
78-
)
79+
.withStatus(200)
80+
.withHeader("Content-Type", "application/json")
81+
.withBody(file)
82+
))
7983
}
8084

8185
def failToFetch(serviceName: String): Unit = {
@@ -112,7 +116,8 @@ trait DeveloperFrontend {
112116
.willReturn(
113117
aResponse()
114118
.withStatus(200)
115-
.withBody("""[{"label": "John Doe", "href": "/developer/profile", "truncate" : false, "openInNewWindow": false, "isSensitive": false}, {"label":"Sign out", "href":"/developer/logout", "truncate" : false, "openInNewWindow": false, "isSensitive": false}]"""))
119+
.withBody("""[{"label": "John Doe", "href": "/developer/profile", "truncate" : false, "openInNewWindow": false, "isSensitive": false}, {"label":"Sign out", "href":"/developer/logout", "truncate" : false, "openInNewWindow": false, "isSensitive": false}]""")
120+
)
116121
)
117122
}
118123

@@ -122,17 +127,16 @@ trait DeveloperFrontend {
122127
.willReturn(
123128
aResponse()
124129
.withStatus(200)
125-
.withBody("""[{"label": "Sign in", "href": "/developer/login", "truncate" : false, "openInNewWindow": false, "isSensitive": false}, {"label":"Register", "href":"/developer/registration", "truncate" : false, "openInNewWindow": false, "isSensitive": false}]"""))
130+
.withBody("""[{"label": "Sign in", "href": "/developer/login", "truncate" : false, "openInNewWindow": false, "isSensitive": false}, {"label":"Register", "href":"/developer/registration", "truncate" : false, "openInNewWindow": false, "isSensitive": false}]""")
131+
)
126132
)
127133
}
128134
}
129135

130-
131-
132136
object ExternalServicesConfig {
133137

134-
val stubPort = sys.env.getOrElse("WIREMOCK_PORT", "11111").toInt
135-
val stubHost = "localhost"
138+
val stubPort = sys.env.getOrElse("WIREMOCK_PORT", "11111").toInt
139+
val stubHost = "localhost"
136140
val wireMockUrl = s"http://$stubHost:$stubPort"
137141

138142
}

acceptance/uk/gov/hmrc/apidocumentation/TableDrivenPropertyMocks.scala renamed to acceptance/test/uk/gov/hmrc/apidocumentation/TableDrivenPropertyMocks.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
package uk.gov.hmrc.apidocumentation
1818

19-
import uk.gov.hmrc.apidocumentation.specs.ComponentTestsSpec
2019
import org.scalatest.prop.{TableDrivenPropertyChecks, TableFor1}
2120

21+
import uk.gov.hmrc.apidocumentation.specs.ComponentTestsSpec
22+
2223
trait TableDrivenPropertyMocks extends TableDrivenPropertyChecks { cs: ComponentTestsSpec =>
23-
def helloWorldVersionsIsDeployed(versionTable:TableFor1[String]=Table("Versions", "1.0", "1.2")): Unit = {
24+
25+
def helloWorldVersionsIsDeployed(versionTable: TableFor1[String] = Table("Versions", "1.0", "1.2")): Unit = {
2426
forAll(versionTable) { version =>
2527
And.helloWorldIsDeployed("api-example-microservice", version)
2628
}

acceptance/uk/gov/hmrc/apidocumentation/Wait.scala renamed to acceptance/test/uk/gov/hmrc/apidocumentation/Wait.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
package uk.gov.hmrc.apidocumentation
1818

19+
import scala.concurrent.duration._
20+
1921
import org.openqa.selenium._
2022
import org.scalatest.concurrent.Eventually
2123

22-
import scala.concurrent.duration._
23-
2424
trait Wait extends Eventually {
2525

2626
override implicit val patienceConfig: PatienceConfig = PatienceConfig(timeout = 2 seconds)
@@ -30,8 +30,7 @@ trait Wait extends Eventually {
3030
try {
3131
oldPageElement.getText
3232
throw new RuntimeException("Old element still present")
33-
}
34-
catch {
33+
} catch {
3534
case _: StaleElementReferenceException => ()
3635
}
3736
}

acceptance/uk/gov/hmrc/apidocumentation/WebPage.scala renamed to acceptance/test/uk/gov/hmrc/apidocumentation/WebPage.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package uk.gov.hmrc.apidocumentation
1818

19-
2019
import org.openqa.selenium.By
2120

2221
trait WebPage extends PageObject {
@@ -26,10 +25,10 @@ trait WebPage extends PageObject {
2625
def goTo(): Unit = get(url())
2726

2827
def pageHeading(): String
29-
30-
def heading() = getText(By.tagName("h1"))
28+
29+
def heading() = getText(By.tagName("h1"))
3130
def bodyText() = getText(By.tagName("body"))
32-
31+
3332
def isCurrentPage(): Boolean = {
3433
this.heading() == this.pageHeading()
3534
}

0 commit comments

Comments
 (0)