|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service;
|
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
|
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResultItem;
|
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.UserModelStatusCodes;
|
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration;
|
|
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserDetectionDto;
|
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.ConfigRepository;
|
|
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.UserRepository;
|
|
10 |
import org.junit.jupiter.api.Test;
|
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
12 |
import org.springframework.boot.test.context.SpringBootTest;
|
|
13 |
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
14 |
|
|
15 |
import java.util.List;
|
|
16 |
|
|
17 |
import static org.junit.jupiter.api.Assertions.*;
|
|
18 |
import static org.mockito.ArgumentMatchers.any;
|
|
19 |
import static org.mockito.Mockito.when;
|
|
20 |
|
|
21 |
@SpringBootTest
|
|
22 |
public class DetectionServiceImplementationTest {
|
|
23 |
@Autowired
|
|
24 |
DetectionService detectionService;
|
|
25 |
@MockBean
|
|
26 |
private ConfigRepository configRepository;
|
|
27 |
|
|
28 |
private final Configuration mockConfiguration = new Configuration
|
|
29 |
("{ \"configuration\": [ { \"antiPattern\": \"TooLongSprint\", \"thresholds\": [ { \"thresholdName\": \"maxIterationLength\", \"value\": \"21\" }, { \"thresholdName\": \"maxNumberOfTooLongIterations\", \"value\": \"0\" } ] }, { \"antiPattern\": \"VaryingSprintLength\", \"thresholds\": [ { \"thresholdName\": \"maxDaysDifference\", \"value\": \"7\" }, { \"thresholdName\": \"maxIterationChanged\", \"value\": \"1\" } ] }, { \"antiPattern\": \"BusinessAsUsual\", \"thresholds\": [ { \"thresholdName\": \"divisionOfIterationsWithRetrospective\", \"value\": \"66.66f\" }, { \"thresholdName\": \"searchSubstringsWithRetrospective\", \"value\": \"%retr%||%revi%||%week%scrum%\" } ] }, { \"antiPattern\": \"SpecifyNothing\", \"thresholds\": [ { \"thresholdName\": \"minNumberOfWikiPagesWithSpecification\", \"value\": \"1\" }, { \"thresholdName\": \"minNumberOfActivitiesWithSpecification\", \"value\": \"1\" }, { \"thresholdName\": \"minAvgLengthOfActivityDescription\", \"value\": \"150\" }, { \"thresholdName\": \"searchSubstringsWithProjectSpecification\", \"value\": \"%dsp%||%specifikace%||%specification%||%vize%proj%||%vize%produ%\" } ] }, { \"antiPattern\": \"RoadToNowhere\", \"thresholds\": [ { \"thresholdName\": \"minNumberOfWikiPagesWithProjectPlan\", \"value\": \"1\" }, { \"thresholdName\": \"minNumberOfActivitiesWithProjectPlan\", \"value\": \"1\" }, { \"thresholdName\": \"searchSubstringsWithProjectPlan\", \"value\": \"%plán projektu%||%project plan%||%plan project%||%projektový plán%\" } ] }, { \"antiPattern\": \"LongOrNonExistentFeedbackLoops\", \"thresholds\": [ { \"thresholdName\": \"divisionOfIterationsWithFeedbackLoop\", \"value\": \"50.00f\" }, { \"thresholdName\": \"maxGapBetweenFeedbackLoopRate\", \"value\": \"2f\" }, { \"thresholdName\": \"searchSubstringsWithFeedbackLoop\", \"value\": \"%schůz%zákazník%||%předvedení%zákazník%||%zákazn%demo%||%schůz%zadavat%||%inform%schůz%||%zákazn%||%zadavatel%\" } ] }, { \"antiPattern\": \"NinetyNinetyRule\", \"thresholds\": [ { \"thresholdName\": \"maxDivisionRange\", \"value\": \"1.25f\" }, { \"thresholdName\": \"maxBadDivisionLimit\", \"value\": \"2\" } ] }, { \"antiPattern\": \"UnknownPoster\", \"thresholds\": [ { \"thresholdName\": \"searchSubstringsInvalidNames\", \"value\": \"%unknown%||%anonym%\" } ] }, { \"antiPattern\": \"BystanderApathy\", \"thresholds\": [ { \"thresholdName\": \"searchSubstringsInvalidContributors\", \"value\": \"%dependabot%\" }, { \"thresholdName\": \"maximumPercentageOfTasksWithoutTeamwork\", \"value\": \"30f\" } ] }, { \"antiPattern\": \"YetAnotherProgrammer\", \"thresholds\": [ { \"thresholdName\": \"maxNumberOfNewContributors\", \"value\": \"5\" }, { \"thresholdName\": \"numberOfFirstMonthsWithoutDetection\", \"value\": \"2\" } ] } ] }",
|
|
30 |
"N","mockName",null);
|
|
31 |
//[JT] test for detection which is a valid input and anti patterns should not be detected in the project
|
|
32 |
@Test
|
|
33 |
public void validDetectionTestNotDetected() {
|
|
34 |
final UserDetectionDto userDetectionDtoMockNotDetected = new UserDetectionDto("foo",1,new String[]{"2"},new String[]{"3"});
|
|
35 |
|
|
36 |
when(configRepository.findConfigurationById(1)).thenReturn(mockConfiguration);
|
|
37 |
List<QueryResult> results = detectionService.analyze(userDetectionDtoMockNotDetected);
|
|
38 |
//only 1 project is being analyzed in the test, therefore only index 0 contains a value
|
|
39 |
QueryResult queryResult = results.get(0);
|
|
40 |
List<QueryResultItem> queryResultItems = queryResult.getQueryResultItems();
|
|
41 |
//again only one is being used in the test - only the first index contains value
|
|
42 |
QueryResultItem queryItem = queryResultItems.get(0);
|
|
43 |
assertFalse(queryItem.isDetected());
|
|
44 |
}
|
|
45 |
//test for valid request - anti pattern should be detected
|
|
46 |
@Test
|
|
47 |
public void validDetectionTestDetected() {
|
|
48 |
final UserDetectionDto userDetectionDtoMockDetected = new UserDetectionDto("foo",1,new String[]{"1"},new String[]{"1"});
|
|
49 |
when(configRepository.findConfigurationById(1)).thenReturn(mockConfiguration);
|
|
50 |
List<QueryResult> results = detectionService.analyze(userDetectionDtoMockDetected);
|
|
51 |
//only 1 project is being analyzed in the test, therefore only index 0 contains a value
|
|
52 |
QueryResult queryResult = results.get(0);
|
|
53 |
List<QueryResultItem> queryResultItems = queryResult.getQueryResultItems();
|
|
54 |
//again only one is being used in the test - only the first index contains value
|
|
55 |
QueryResultItem queryItem = queryResultItems.get(0);
|
|
56 |
assertTrue(queryItem.isDetected());
|
|
57 |
}
|
|
58 |
//no projects provided in request - incorrect request
|
|
59 |
@Test
|
|
60 |
public void invalidProjectParameterDetection() {
|
|
61 |
final UserDetectionDto userDetectionDtoMockInvalid = new UserDetectionDto("foo",1,new String[]{},new String[]{"1"});
|
|
62 |
//request is invalid
|
|
63 |
when(configRepository.findConfigurationById(1)).thenReturn(mockConfiguration);
|
|
64 |
List<QueryResult> results = detectionService.analyze(userDetectionDtoMockInvalid);
|
|
65 |
assertEquals(0,results.size());
|
|
66 |
}
|
|
67 |
//no antipatterns provided in request - also incorrect
|
|
68 |
@Test
|
|
69 |
public void invalidAntipatternParameterDetection() {
|
|
70 |
final UserDetectionDto userDetectionDtoMockInvalid = new UserDetectionDto("foo",1,new String[]{"1"},new String[]{});
|
|
71 |
//request is invalid
|
|
72 |
when(configRepository.findConfigurationById(1)).thenReturn(mockConfiguration);
|
|
73 |
List<QueryResult> results = detectionService.analyze(userDetectionDtoMockInvalid);
|
|
74 |
assertEquals(0,results.size());
|
|
75 |
}
|
|
76 |
|
|
77 |
}
|
#10397 Dopsání testové sady pro detekci. Opravena chyba při detekci s nevalidním počtem antipatternů.