Revize b543e564
Přidáno uživatelem Václav Hrabík před téměř 2 roky(ů)
src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/BaseTest.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller; |
2 | 2 |
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.AntiPatternService; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration; |
|
3 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User; |
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.ConfigRepository; |
|
4 | 8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.UserRepository; |
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.DetectionService; |
|
5 | 10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.JSONBuilder; |
6 | 11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.RequestBuilder; |
7 | 12 |
import io.restassured.module.mockmvc.RestAssuredMockMvc; |
... | ... | |
12 | 17 |
import org.springframework.http.ResponseEntity; |
13 | 18 |
import org.springframework.web.context.WebApplicationContext; |
14 | 19 |
|
20 |
import java.util.ArrayList; |
|
15 | 21 |
import java.util.HashMap; |
22 |
import java.util.List; |
|
16 | 23 |
import java.util.Map; |
17 | 24 |
|
18 | 25 |
import static org.mockito.ArgumentMatchers.*; |
... | ... | |
30 | 37 |
@MockBean |
31 | 38 |
private RequestBuilder requestBuilder; |
32 | 39 |
|
40 |
@MockBean |
|
41 |
private AntiPatternRepository antiPatternRepository; |
|
42 |
|
|
43 |
@MockBean |
|
44 |
private ConfigRepository configurationRepository; |
|
45 |
|
|
33 | 46 |
@BeforeEach |
34 | 47 |
public void init() { |
35 | 48 |
User user = new User("foo", "foo@foo.foo", "76D3BC41C9F588F7FCD0D5BF4718F8F84B1C41B20882703100B9EB9413807C01"); |
... | ... | |
68 | 81 |
ResponseEntity<String> logoutResponse = ResponseEntity.ok(logoutBody); |
69 | 82 |
when(requestBuilder.sendRequestResponse(eq("http://localhost:8081/logout"), anyMap())).thenReturn(logoutResponse); |
70 | 83 |
|
84 |
/* Configuration */ |
|
85 |
/* /configuration_name */ |
|
86 |
User config_user = new User("config_user"); |
|
87 |
config_user.setId(1); |
|
88 |
when(userRepository.findByName("config_user")).thenReturn(config_user); |
|
89 |
List<Object[]> configs = new ArrayList<>(); |
|
90 |
Object[] pom_pole = new Object[2]; |
|
91 |
pom_pole[0] = "default config"; |
|
92 |
pom_pole[1] = 1; |
|
93 |
configs.add(pom_pole); |
|
94 |
when(configurationRepository.getAllUserConfigurationNames(config_user.getId())).thenReturn(configs); |
|
95 |
|
|
96 |
/* configuration */ |
|
97 |
List<Configuration> configuration = new ArrayList<>(); |
|
98 |
Configuration con = new Configuration("{\r\n \"configuration\": [\r\n {\r\n \"antiPattern\": \"TooLongSprint\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"maxIterationLength\",\r\n \"value\": \"21\"\r\n },\r\n {\r\n \"thresholdName\": \"maxNumberOfTooLongIterations\",\r\n \"value\": \"0\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"VaryingSprintLength\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"maxDaysDifference\",\r\n \"value\": \"7\"\r\n },\r\n {\r\n \"thresholdName\": \"maxIterationChanged\",\r\n \"value\": \"1\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"BusinessAsUsual\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"divisionOfIterationsWithRetrospective\",\r\n \"value\": \"66.66f\"\r\n },\r\n {\r\n \"thresholdName\": \"searchSubstringsWithRetrospective\",\r\n \"value\": \"%retr%||%revi%||%week%scrum%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"SpecifyNothing\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"minNumberOfWikiPagesWithSpecification\",\r\n \"value\": \"1\"\r\n },\r\n {\r\n \"thresholdName\": \"minNumberOfActivitiesWithSpecification\",\r\n \"value\": \"1\"\r\n },\r\n {\r\n \"thresholdName\": \"minAvgLengthOfActivityDescription\",\r\n \"value\": \"150\"\r\n },\r\n {\r\n \"thresholdName\": \"searchSubstringsWithProjectSpecification\",\r\n \"value\": \"%dsp%||%specifikace%||%specification%||%vize%proj%||%vize%produ%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"RoadToNowhere\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"minNumberOfWikiPagesWithProjectPlan\",\r\n \"value\": \"1\"\r\n },\r\n {\r\n \"thresholdName\": \"minNumberOfActivitiesWithProjectPlan\",\r\n \"value\": \"1\"\r\n },\r\n {\r\n \"thresholdName\": \"searchSubstringsWithProjectPlan\",\r\n \"value\": \"%pl?n projektu%||%project plan%||%plan project%||%projektov? pl?n%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"LongOrNonExistentFeedbackLoops\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"divisionOfIterationsWithFeedbackLoop\",\r\n \"value\": \"50.00f\"\r\n },\r\n {\r\n \"thresholdName\": \"maxGapBetweenFeedbackLoopRate\",\r\n \"value\": \"2f\"\r\n },\r\n {\r\n \"thresholdName\": \"searchSubstringsWithFeedbackLoop\",\r\n \"value\": \"%sch?z%z?kazn?k%||%p?edveden?%z?kazn?k%||%z?kazn%demo%||%sch?z%zadavat%||%inform%sch?z%||%z?kazn%||%zadavatel%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"NinetyNinetyRule\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"maxDivisionRange\",\r\n \"value\": \"1.25f\"\r\n },\r\n {\r\n \"thresholdName\": \"maxBadDivisionLimit\",\r\n \"value\": \"2\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"UnknownPoster\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"searchSubstringsInvalidNames\",\r\n \"value\": \"%unknown%||%anonym%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"BystanderApathy\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"searchSubstringsInvalidContributors\",\r\n \"value\": \"%dependabot%\"\r\n },\r\n {\r\n \"thresholdName\": \"maximumPercentageOfTasksWithoutTeamwork\",\r\n \"value\": \"30f\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"YetAnotherProgrammer\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"maxNumberOfNewContributors\",\r\n \"value\": \"5\"\r\n },\r\n {\r\n \"thresholdName\": \"numberOfFirstMonthsWithoutDetection\",\r\n \"value\": \"2\"\r\n }\r\n ]\r\n }\r\n ]\r\n}" |
|
99 |
, "Y", "default_config"); |
|
100 |
configuration.add(con); |
|
101 |
when(configurationRepository.getAllUserConfigurations(config_user.getId())).thenReturn(configuration); |
|
102 |
|
|
71 | 103 |
RestAssuredMockMvc.webAppContextSetup(webApplicationContext); |
72 | 104 |
} |
73 | 105 |
|
src/test/resources/contracts/configurationNames200.groovy | ||
---|---|---|
1 |
package contracts |
|
2 |
|
|
3 |
import org.springframework.cloud.contract.spec.Contract |
|
4 |
|
|
5 |
Contract.make { |
|
6 |
description "Fetch all configurations of user." |
|
7 |
request { |
|
8 |
method POST() |
|
9 |
url("/v2/configuration/configuration_name") |
|
10 |
headers { |
|
11 |
header("Authorization": "Bearer token") |
|
12 |
contentType applicationJson() |
|
13 |
} |
|
14 |
body( |
|
15 |
"name": "config_user" |
|
16 |
) |
|
17 |
} |
|
18 |
response { |
|
19 |
body( |
|
20 |
"message": "ok", |
|
21 |
"configuration_ids": ["1"], |
|
22 |
"configuration_names": ["default config"] |
|
23 |
) |
|
24 |
status 200 |
|
25 |
} |
|
26 |
} |
src/test/resources/contracts/configurations_200.groovy | ||
---|---|---|
1 |
package contracts |
|
2 |
|
|
3 |
import org.springframework.cloud.contract.spec.Contract |
|
4 |
|
|
5 |
Contract.make { |
|
6 |
description "Fetch all configurations of user." |
|
7 |
request { |
|
8 |
method POST() |
|
9 |
url("/v2/configuration/configuration") |
|
10 |
headers { |
|
11 |
header("Authorization": "Bearer token") |
|
12 |
contentType applicationJson() |
|
13 |
} |
|
14 |
body( |
|
15 |
"name": "config_user" |
|
16 |
) |
|
17 |
} |
|
18 |
response { |
|
19 |
body( |
|
20 |
"message": "configuration retrived", |
|
21 |
"configurations": ["{\r\n \"configuration\": [\r\n {\r\n \"antiPattern\": \"TooLongSprint\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"maxIterationLength\",\r\n \"value\": \"21\"\r\n },\r\n {\r\n \"thresholdName\": \"maxNumberOfTooLongIterations\",\r\n \"value\": \"0\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"VaryingSprintLength\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"maxDaysDifference\",\r\n \"value\": \"7\"\r\n },\r\n {\r\n \"thresholdName\": \"maxIterationChanged\",\r\n \"value\": \"1\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"BusinessAsUsual\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"divisionOfIterationsWithRetrospective\",\r\n \"value\": \"66.66f\"\r\n },\r\n {\r\n \"thresholdName\": \"searchSubstringsWithRetrospective\",\r\n \"value\": \"%retr%||%revi%||%week%scrum%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"SpecifyNothing\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"minNumberOfWikiPagesWithSpecification\",\r\n \"value\": \"1\"\r\n },\r\n {\r\n \"thresholdName\": \"minNumberOfActivitiesWithSpecification\",\r\n \"value\": \"1\"\r\n },\r\n {\r\n \"thresholdName\": \"minAvgLengthOfActivityDescription\",\r\n \"value\": \"150\"\r\n },\r\n {\r\n \"thresholdName\": \"searchSubstringsWithProjectSpecification\",\r\n \"value\": \"%dsp%||%specifikace%||%specification%||%vize%proj%||%vize%produ%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"RoadToNowhere\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"minNumberOfWikiPagesWithProjectPlan\",\r\n \"value\": \"1\"\r\n },\r\n {\r\n \"thresholdName\": \"minNumberOfActivitiesWithProjectPlan\",\r\n \"value\": \"1\"\r\n },\r\n {\r\n \"thresholdName\": \"searchSubstringsWithProjectPlan\",\r\n \"value\": \"%pl?n projektu%||%project plan%||%plan project%||%projektov? pl?n%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"LongOrNonExistentFeedbackLoops\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"divisionOfIterationsWithFeedbackLoop\",\r\n \"value\": \"50.00f\"\r\n },\r\n {\r\n \"thresholdName\": \"maxGapBetweenFeedbackLoopRate\",\r\n \"value\": \"2f\"\r\n },\r\n {\r\n \"thresholdName\": \"searchSubstringsWithFeedbackLoop\",\r\n \"value\": \"%sch?z%z?kazn?k%||%p?edveden?%z?kazn?k%||%z?kazn%demo%||%sch?z%zadavat%||%inform%sch?z%||%z?kazn%||%zadavatel%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"NinetyNinetyRule\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"maxDivisionRange\",\r\n \"value\": \"1.25f\"\r\n },\r\n {\r\n \"thresholdName\": \"maxBadDivisionLimit\",\r\n \"value\": \"2\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"UnknownPoster\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"searchSubstringsInvalidNames\",\r\n \"value\": \"%unknown%||%anonym%\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"BystanderApathy\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"searchSubstringsInvalidContributors\",\r\n \"value\": \"%dependabot%\"\r\n },\r\n {\r\n \"thresholdName\": \"maximumPercentageOfTasksWithoutTeamwork\",\r\n \"value\": \"30f\"\r\n }\r\n ]\r\n },\r\n {\r\n \"antiPattern\": \"YetAnotherProgrammer\",\r\n \"thresholds\": [\r\n {\r\n \"thresholdName\": \"maxNumberOfNewContributors\",\r\n \"value\": \"5\"\r\n },\r\n {\r\n \"thresholdName\": \"numberOfFirstMonthsWithoutDetection\",\r\n \"value\": \"2\"\r\n }\r\n ]\r\n }\r\n ]\r\n}" |
|
22 |
] |
|
23 |
) |
|
24 |
status 200 |
|
25 |
} |
|
26 |
} |
|
27 |
|
Také k dispozici: Unified diff
#10645 vytvoření groovy sriptů a namockování pro configurace