Commit 85f022b8 authored by Julien Topçu's avatar Julien Topçu

renaming domain features

changing domain object factories strategy
parent e334c9f1
......@@ -31,7 +31,7 @@ Back to the basics, since the aim of a functional test is "testing the business
![Functional Tests in the Hexagonal Architecture](images/hexagon-implementation.png)
In TalkAdvisor, [Cucumber](https://docs.cucumber.io/) is used to define the features and the scenarios of our business logic. As you can see the feature files are located in [the tests packages of the domain](https://gitlab.com/crafts-records/talkadvisor/talkadvisor-back/tree/master/talkadvisor-domain/src/test/resources/features) beside the [step definitions](https://gitlab.com/crafts-records/talkadvisor/talkadvisor-back/tree/master/talkadvisor-domain/src/test/kotlin/org/craftsrecords/talkadvisor/recommendation/stepdefs).
Using the [Gherkin language](https://docs.cucumber.io/gherkin/reference/), we express the scenarios of a feature [profiles.feature](https://gitlab.com/crafts-records/talkadvisor/talkadvisor-back/blob/master/talkadvisor-domain/src/test/resources/features/profiles.feature):
Using the [Gherkin language](https://docs.cucumber.io/gherkin/reference/), we express the scenarios of a feature [creating-a-profile.feature](https://gitlab.com/crafts-records/talkadvisor/talkadvisor-back/blob/master/talkadvisor-domain/src/test/resources/features/creating-a-profile.feature):
```gherkin
Feature: As a frequent user,
In order not repeat my preferences at each request,
......
......@@ -5,5 +5,5 @@ import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith
@RunWith(Cucumber::class)
@CucumberOptions(strict = true, plugin = ["pretty", "json:target/cucumber/recommendation.json"], features = ["classpath:features/recommendations.feature"])
@CucumberOptions(strict = true, plugin = ["pretty", "json:target/cucumber/recommendation.json"], features = ["classpath:features/recommending-talks.feature"])
class RecommendationFunctionalTests
\ No newline at end of file
......@@ -7,6 +7,6 @@ import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat
fun createPreferences() =
Preferences(
setOf(Topic("DDD"), Topic("Hexagonal Architecture")),
setOf(TalkFormat.CONFERENCE, TalkFormat.QUICKIE))
setOf(TalkFormat.values().random(), TalkFormat.QUICKIE, TalkFormat.IGNITE))
fun createCriteria(): Criteria = createPreferences()
......@@ -6,7 +6,7 @@ import java.time.Duration.ZERO
import java.time.Duration.ofMinutes
internal class DurationExtensionTest {
internal class DurationTest {
@Test
fun `should be positive when greater than zero`() {
assertThat(ofMinutes(5).isPositive()).isTrue()
......
......@@ -8,6 +8,6 @@ import org.junit.runner.RunWith
@CucumberOptions(
strict = true,
plugin = ["pretty", "json:target/cucumber/profile.json"],
features = ["classpath:features/profiles.feature"],
features = ["classpath:features/creating-a-profile.feature"],
glue = ["classpath:org.craftsrecords.talkadvisor.recommendation.stepdefs"])
class ProfileFunctionalTests
\ No newline at end of file
package org.craftsrecords.talkadvisor.recommendation.talk
import org.craftsrecords.talkadvisor.recommendation.criteria.Criteria
import java.time.Duration
import java.time.Duration.ofMinutes
import java.util.*
import kotlin.random.Random
......@@ -19,10 +20,14 @@ fun createTalk(): Talk {
return prepareBuilder().apply { duration = ofMinutes(Random.nextLong(2, 120)) }.build()
}
private fun durationFrom(criteria: Criteria) = criteria.talksFormats.random().durationRange.start
private fun durationFrom(criteria: Criteria) = criteria.talksFormats.random().randomDuration()
private fun prepareBuilder(): Talk.Builder {
return Talk.with {
id = UUID.randomUUID().toString()
title = "title ${Random.nextInt()}"
}
}
private fun TalkFormat.randomDuration(): Duration {
return durationRange.start.plusSeconds(Random.nextLong(1, 59))
}
package org.craftsrecords.talkadvisor.infra.controller
import org.craftsrecords.talkadvisor.infra.configurations.DomainConfiguration
import org.craftsrecords.talkadvisor.recommendation.profile.createProfileFor
import org.craftsrecords.talkadvisor.recommendation.preferences.Preferences
import org.craftsrecords.talkadvisor.recommendation.preferences.Topic
import org.craftsrecords.talkadvisor.recommendation.profile.Profile
import org.craftsrecords.talkadvisor.recommendation.spi.Profiles
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat.*
import org.hamcrest.Matchers.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
......@@ -96,7 +98,7 @@ internal class RecommendationControllerTest {
.attributes(key("constraints").value("formatted in the ISO-8601 standard")))
.and(fieldWithPath("talks[].format")
.description("the format of the talk")
.attributes(key("constraints").value("Possible values: ${TalkFormat.values().contentToString()}"))))
.attributes(key("constraints").value("Possible values: ${values().contentToString()}"))))
}
private fun MvcResult.extractIdFromLocationHeader(): String {
......@@ -104,7 +106,12 @@ internal class RecommendationControllerTest {
}
private fun bootstrapProfileFor(userId: String) {
profiles.save(createProfileFor(userId))
profiles.save(createProfile(userId))
}
private fun createProfile(userId: String): Profile {
return Profile(id = userId,
preferences = Preferences(setOf(Topic("DDD"), Topic("Hexagonal Architecture")), setOf(CONFERENCE, QUICKIE)))
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment