Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d88250ff

Přidáno uživatelem Jiri Trefil před téměř 2 roky(ů)

#10397 Opraveny testy na detekci

Zobrazit rozdíly:

src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/DetectionServiceImplementationTest.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service;
2 2

  
3
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
4
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
3 5
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
4 6
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResultItem;
7
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository;
8
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.ProjectRepository;
5 9
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.UserModelStatusCodes;
6 10
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration;
11
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User;
7 12
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserDetectionDto;
8 13
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.ConfigRepository;
9 14
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.UserRepository;
......
13 18
import org.springframework.boot.test.mock.mockito.MockBean;
14 19

  
15 20
import java.util.List;
21
import java.util.Optional;
16 22

  
17 23
import static org.junit.jupiter.api.Assertions.*;
18 24
import static org.mockito.ArgumentMatchers.any;
......
24 30
    DetectionService detectionService;
25 31
    @MockBean
26 32
    private ConfigRepository configRepository;
27

  
28 33
    private final Configuration mockConfiguration = new Configuration
29 34
            ("{      \"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 35
                    "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

  
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 37
    //no projects provided in request - incorrect request
59 38
    @Test
60 39
    public void invalidProjectParameterDetection() {
61 40
        final UserDetectionDto userDetectionDtoMockInvalid = new UserDetectionDto("foo",1,new String[]{},new String[]{"1"});
62 41
        //request is invalid
42

  
63 43
        when(configRepository.findConfigurationById(1)).thenReturn(mockConfiguration);
64 44
        List<QueryResult> results = detectionService.analyze(userDetectionDtoMockInvalid);
65 45
        assertEquals(0,results.size());

Také k dispozici: Unified diff