├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── UsedAPIs.md ├── _config.yml ├── overview.png ├── pom.xml └── src ├── main ├── java │ └── at │ │ └── grisa │ │ └── agilemetrics │ │ ├── Application.java │ │ ├── ApplicationConfig.java │ │ ├── Initializer.java │ │ ├── api │ │ ├── Information.java │ │ └── InformationController.java │ │ ├── consumer │ │ ├── IConsumer.java │ │ └── elasticsearch │ │ │ ├── ElasticSearchConsumer.java │ │ │ ├── ElasticSearchRestClient.java │ │ │ └── restentity │ │ │ ├── BulkResponse.java │ │ │ └── ClusterInfo.java │ │ ├── cron │ │ ├── CronObserver.java │ │ ├── MetricErrorHandler.java │ │ └── MetricQueue.java │ │ ├── entity │ │ └── Metric.java │ │ ├── persistence │ │ ├── IStatisticRepository.java │ │ ├── IVelocityRepository.java │ │ └── entity │ │ │ ├── Statistic.java │ │ │ └── Velocity.java │ │ ├── producer │ │ ├── IProducer.java │ │ ├── RestClient.java │ │ ├── atlassian │ │ │ └── rest │ │ │ │ ├── RestClientAtlassian.java │ │ │ │ └── entities │ │ │ │ └── QueryParam.java │ │ ├── bitbucketserver │ │ │ ├── BitBucketServerProducer.java │ │ │ ├── BitBucketServerRestClient.java │ │ │ └── restentity │ │ │ │ ├── ApplicationProperties.java │ │ │ │ ├── Commit.java │ │ │ │ ├── PagedEntities.java │ │ │ │ ├── Project.java │ │ │ │ ├── Repository.java │ │ │ │ └── User.java │ │ ├── jirasoftwareserver │ │ │ ├── JiraSoftwareServerProducer.java │ │ │ ├── JiraSoftwareServerRestClient.java │ │ │ └── restentity │ │ │ │ ├── Board.java │ │ │ │ ├── BoardConfiguration.java │ │ │ │ ├── ChangeLog.java │ │ │ │ ├── Fields.java │ │ │ │ ├── Filter.java │ │ │ │ ├── History.java │ │ │ │ ├── HistoryItem.java │ │ │ │ ├── Issue.java │ │ │ │ ├── PagedEntities.java │ │ │ │ ├── ServerInfo.java │ │ │ │ ├── Sprint.java │ │ │ │ ├── Status.java │ │ │ │ ├── StatusCategory.java │ │ │ │ ├── Value.java │ │ │ │ ├── VelocityReport.java │ │ │ │ ├── VelocityStats.java │ │ │ │ └── greenhopper │ │ │ │ ├── Contents.java │ │ │ │ ├── RapidView.java │ │ │ │ ├── RapidViews.java │ │ │ │ ├── Sprint.java │ │ │ │ ├── SprintReport.java │ │ │ │ └── Sprints.java │ │ └── sonarqube │ │ │ ├── SonarQubeProducer.java │ │ │ ├── SonarQubeRestClient.java │ │ │ └── restentity │ │ │ ├── Component.java │ │ │ ├── ComponentMeasures.java │ │ │ ├── ComponentSearch.java │ │ │ ├── Measure.java │ │ │ ├── Metric.java │ │ │ ├── Paging.java │ │ │ └── ServerVersion.java │ │ └── util │ │ ├── CredentialManager.java │ │ └── PropertyManager.java └── resources │ ├── application.properties │ └── log4j2.yaml └── test ├── java └── at │ └── grisa │ └── agilemetrics │ ├── consumer │ ├── ElasticSearchConsumerTest.java │ ├── ElasticSearchRestClientCheckConnectionTest.java │ ├── ElasticSearchRestClientMockConfiguration.java │ └── ElasticSearchRestClientTest.java │ ├── cron │ ├── CronObserverMockConfiguration.java │ └── CronObserverTest.java │ ├── entity │ └── MetricTest.java │ ├── producer │ ├── bitbucketserver │ │ ├── producer │ │ │ ├── BitBucketProducerCollectDailyCommitDataTest.java │ │ │ └── BitBucketProducerMockConfiguration.java │ │ └── restclient │ │ │ ├── BitBucketServerRestClientCheckConnectionTest.java │ │ │ ├── BitBucketServerRestClientCommitsFromTest.java │ │ │ ├── BitBucketServerRestClientCommitsTest.java │ │ │ ├── BitBucketServerRestClientPagedEntitiesTest.java │ │ │ ├── BitBucketServerRestClientProjectsTest.java │ │ │ └── BitBucketServerRestClientRepositoriesTest.java │ ├── jirasoftwareserver │ │ ├── producer │ │ │ ├── JiraSoftwareServerProducerAcceptanceCriteriaVolatilityNoPropertiesTest.java │ │ │ ├── JiraSoftwareServerProducerAcceptanceCriteriaVolatilityTest.java │ │ │ ├── JiraSoftwareServerProducerBugCountTest.java │ │ │ ├── JiraSoftwareServerProducerBugRateTest.java │ │ │ ├── JiraSoftwareServerProducerCumulativeFlowTest.java │ │ │ ├── JiraSoftwareServerProducerEstimatedStoryPointsTest.java │ │ │ ├── JiraSoftwareServerProducerIssueLabelsTest.java │ │ │ ├── JiraSoftwareServerProducerIssueVolumeTest.java │ │ │ ├── JiraSoftwareServerProducerLeadTimeTest.java │ │ │ ├── JiraSoftwareServerProducerMockConfiguration.java │ │ │ ├── JiraSoftwareServerProducerRecidivismNoPropertiesTest.java │ │ │ ├── JiraSoftwareServerProducerRecidivismTest.java │ │ │ └── JiraSoftwareServerProducerVelocityTest.java │ │ └── restclient │ │ │ ├── JiraSoftwareServerRestClientActiveSprintGreenhopperTest.java │ │ │ ├── JiraSoftwareServerRestClientActiveSprintTest.java │ │ │ ├── JiraSoftwareServerRestClientCheckConnectionTest.java │ │ │ ├── JiraSoftwareServerRestClientIssuesChangelogTest.java │ │ │ ├── JiraSoftwareServerRestClientJQLIssuesLabelsTest.java │ │ │ ├── JiraSoftwareServerRestClientJQLIssuesTest.java │ │ │ ├── JiraSoftwareServerRestClientRapidViewsGreenhopperTest.java │ │ │ ├── JiraSoftwareServerRestClientScrumBoardsTest.java │ │ │ ├── JiraSoftwareServerRestClientSprintIssueCountTest.java │ │ │ ├── JiraSoftwareServerRestClientSprintIssuesStatusTest.java │ │ │ ├── JiraSoftwareServerRestClientSprintIssuesTest.java │ │ │ ├── JiraSoftwareServerRestClientSprintReportGreenhopperTest.java │ │ │ └── JiraSoftwareServerRestClientVelocityReportGreenhopperTest.java │ └── sonarqube │ │ ├── producer │ │ ├── SonarQubeProducerMetricsNoPropertiesTest.java │ │ ├── SonarQubeProducerMetricsTest.java │ │ └── SonarQubeProducerMockConfiguration.java │ │ ├── restclient │ │ ├── SonarQubeRestClientCheckConnectionTest.java │ │ ├── SonarQubeRestClientComponentsTest.java │ │ └── SonarQubeRestClientMeasuresTest.java │ │ └── restentity │ │ └── MetricTest.java │ └── util │ ├── CredentialManagerEmptyTest.java │ └── CredentialManagerTest.java └── resources ├── bitbucket-test.properties ├── bitbucket ├── check.js ├── commits-from.js ├── commits.js ├── paged-entities-1.js ├── paged-entities-2.js ├── projects.js └── repos.js ├── credential-manager-empty-test.properties ├── credential-manager-test.properties ├── elasticsearch-test.properties ├── elasticsearch ├── bulk-request.js ├── bulk-response.js └── check-connection.js ├── jira-test.properties ├── jirasoftware ├── boardConfiguration.js ├── boards.js ├── check.js ├── filter.js ├── issueChangelog.js ├── issueLabels.js ├── issues.js ├── issuesJQL.js ├── issuesStatus.js ├── rapidviewsGreenhopper.js ├── sprintreportGreenhopper.js ├── sprints.js ├── sprintsGreenhopper.js └── velocityReport.js ├── metric └── sample_serialzation.json ├── sonarqube-test.properties └── sonarqube ├── component.js ├── componentsPart1.js └── componentsPart2.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | logs/ 6 | *.log 7 | 8 | # database files 9 | *.db 10 | 11 | # BlueJ files 12 | *.ctxt 13 | 14 | # Mobile Tools for Java (J2ME) 15 | .mtj.tmp/ 16 | 17 | # Package Files # 18 | *.jar 19 | *.war 20 | *.ear 21 | *.zip 22 | *.tar.gz 23 | *.rar 24 | 25 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 26 | hs_err_pid* 27 | 28 | #IntelliJ 29 | .idea 30 | *.iml 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | addons: 5 | sonarcloud: 6 | organization: "agile-metrics" # the key of the org you chose at step #3 7 | token: 8 | secure: $SONAR_TOKEN # encrypted value of your token 9 | script: 10 | # the following command line builds the project, runs the tests with coverage and then execute the SonarCloud analysis 11 | - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 DaGrisa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /UsedAPIs.md: -------------------------------------------------------------------------------- 1 | # APIs Used 2 | 3 | ## BitBucket Server 4 | 5 | API Documentation: https://docs.atlassian.com/bitbucket-server/rest/5.9.0/bitbucket-rest.html 6 | 7 | ### Projects and Repositories 8 | 9 | Every repository must be withing a project. 10 | 11 | Projects: [GET http://example.com/rest/projects](https://docs.atlassian.com/bitbucket-server/rest/5.9.0/bitbucket-rest.html#idm45328869225824) 12 | 13 | Repositories: [GET http://example.com/rest/projects/{projectKey}/repos](https://docs.atlassian.com/bitbucket-server/rest/5.9.0/bitbucket-rest.html#idm45328868723456) 14 | 15 | ### Commits 16 | 17 | [GET http://example.com/rest/projects/{projectKey}/repos/{repositorySlug}/commits](https://docs.atlassian.com/bitbucket-server/rest/5.9.0/bitbucket-rest.html#idm45328867726144) 18 | 19 | ## JIRA Agile Server 20 | 21 | API Documentation: https://docs.atlassian.com/jira-software/REST/7.3.1/ 22 | 23 | ### Velocity 24 | 25 | Undocumented API: GET http://myserver/jira/rest/greenhopper/1.0/rapid/charts/velocity.json?rapidViewId={rapidViewID} 26 | 27 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaGrisa/agile-metrics/e7ad634dd60480f39c3c0bbcc34cdd5323decf06/overview.png -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/Application.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | 7 | @SpringBootApplication 8 | @EnableScheduling 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/ApplicationConfig.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics; 2 | 3 | import at.grisa.agilemetrics.util.CredentialManager; 4 | import com.fasterxml.jackson.core.JsonGenerator; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import com.fasterxml.jackson.databind.ObjectWriter; 7 | import com.fasterxml.jackson.databind.SerializationFeature; 8 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.context.annotation.Primary; 13 | import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; 14 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; 15 | 16 | @Configuration 17 | public class ApplicationConfig { 18 | private static final int THREADS_COUNT = 2; 19 | 20 | @Autowired 21 | private CredentialManager credentialManager; 22 | 23 | public ApplicationConfig() { 24 | // default constructor 25 | } 26 | 27 | @Bean 28 | public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() { 29 | PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer(); 30 | propertySourcesPlaceholderConfigurer.setNullValue("@null"); 31 | return propertySourcesPlaceholderConfigurer; 32 | } 33 | 34 | @Bean 35 | @Primary 36 | public ObjectMapper objectMapper() { 37 | ObjectMapper objectMapper = new ObjectMapper(); 38 | objectMapper.registerModule(new JavaTimeModule()); 39 | objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); 40 | objectMapper.getFactory().configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true); 41 | 42 | return objectMapper; 43 | } 44 | 45 | @Bean 46 | public ObjectWriter objectWriter(ObjectMapper objectMapper) { 47 | return objectMapper.writerWithDefaultPrettyPrinter(); 48 | } 49 | 50 | @Bean 51 | public ThreadPoolTaskScheduler threadPoolTaskScheduler() { 52 | ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); 53 | threadPoolTaskScheduler.setPoolSize(THREADS_COUNT); 54 | return threadPoolTaskScheduler; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/Initializer.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics; 2 | 3 | import at.grisa.agilemetrics.consumer.elasticsearch.ElasticSearchConsumer; 4 | import at.grisa.agilemetrics.cron.CronObserver; 5 | import at.grisa.agilemetrics.producer.bitbucketserver.BitBucketServerProducer; 6 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerProducer; 7 | import at.grisa.agilemetrics.producer.sonarqube.SonarQubeProducer; 8 | import at.grisa.agilemetrics.util.CredentialManager; 9 | import org.apache.logging.log4j.LogManager; 10 | import org.apache.logging.log4j.Logger; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.context.event.ContextRefreshedEvent; 13 | import org.springframework.context.event.EventListener; 14 | import org.springframework.stereotype.Component; 15 | 16 | @Component 17 | public class Initializer { 18 | private static final Logger log = LogManager.getLogger(Initializer.class); 19 | 20 | @Autowired 21 | private CredentialManager credentialManager; 22 | @Autowired 23 | private CronObserver cronObserver; 24 | 25 | /** 26 | * Consumer 27 | */ 28 | @Autowired 29 | private ElasticSearchConsumer elasticSearchConsumer; 30 | 31 | /** 32 | * Producer 33 | */ 34 | @Autowired 35 | private BitBucketServerProducer bitBucketServerProducer; 36 | @Autowired 37 | private JiraSoftwareServerProducer jiraSoftwareServerProducer; 38 | @Autowired 39 | private SonarQubeProducer sonarQubeProducer; 40 | 41 | @EventListener 42 | public void initApplication(ContextRefreshedEvent event) { 43 | log.info("Initializing application"); 44 | 45 | if (credentialManager.isElasticsearchActive() && elasticSearchConsumer.checkConnection()) { 46 | log.info("Elasticsearch configuration detected, registering as consumer."); 47 | cronObserver.registerConsumer(elasticSearchConsumer); 48 | } 49 | 50 | if (credentialManager.isBitbucketserverActive() && bitBucketServerProducer.checkConnection()) { 51 | log.info("Bitbucket configuration detected, registering as producer."); 52 | cronObserver.registerProducer(bitBucketServerProducer); 53 | } 54 | 55 | if (credentialManager.isJirasoftwareActive() && jiraSoftwareServerProducer.checkConnection()) { 56 | log.info("Jira Software configuration detected, registering as producer."); 57 | cronObserver.registerProducer(jiraSoftwareServerProducer); 58 | } 59 | 60 | if (credentialManager.isSonarqubeActive() && sonarQubeProducer.checkConnection()) { 61 | log.info("SonarQube configuration detected, registering as producer."); 62 | cronObserver.registerProducer(sonarQubeProducer); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/api/Information.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.api; 2 | 3 | import java.time.ZonedDateTime; 4 | import java.util.List; 5 | 6 | public class Information { 7 | private List consumers; 8 | private List producers; 9 | private Integer processedMetricsLastRun; 10 | private ZonedDateTime lastRun; 11 | 12 | public Information() { 13 | } 14 | 15 | public Information(List consumers, List producers, Integer processedMetrics, ZonedDateTime lastRun) { 16 | this.consumers = consumers; 17 | this.producers = producers; 18 | this.processedMetricsLastRun = processedMetrics; 19 | this.lastRun = lastRun; 20 | } 21 | 22 | public List getConsumers() { 23 | return consumers; 24 | } 25 | 26 | public void setConsumers(List consumers) { 27 | this.consumers = consumers; 28 | } 29 | 30 | public List getProducers() { 31 | return producers; 32 | } 33 | 34 | public void setProducers(List producers) { 35 | this.producers = producers; 36 | } 37 | 38 | public Integer getProcessedMetricsLastRun() { 39 | return processedMetricsLastRun; 40 | } 41 | 42 | public void setProcessedMetricsLastRun(Integer processedMetricsLastRun) { 43 | this.processedMetricsLastRun = processedMetricsLastRun; 44 | } 45 | 46 | public ZonedDateTime getLastRun() { 47 | return lastRun; 48 | } 49 | 50 | public void setLastRun(ZonedDateTime lastRun) { 51 | this.lastRun = lastRun; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/api/InformationController.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.api; 2 | 3 | import at.grisa.agilemetrics.cron.CronObserver; 4 | import at.grisa.agilemetrics.persistence.IStatisticRepository; 5 | import at.grisa.agilemetrics.persistence.entity.Statistic; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.time.ZonedDateTime; 11 | 12 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 13 | 14 | @RestController 15 | public class InformationController { 16 | @Autowired 17 | private CronObserver cronObserver; 18 | 19 | @Autowired 20 | private IStatisticRepository statisticRepository; 21 | 22 | @RequestMapping(path = "/", method = GET) 23 | public Information getInformation() { 24 | Statistic lastRun = statisticRepository.findFirstByOrderByLastRunDesc(); 25 | ZonedDateTime lastRunDateTime = lastRun == null ? null : lastRun.getLastRun(); 26 | Integer processedMetricsLastRun = lastRun == null ? 0 : lastRun.getMetricsCount(); 27 | return new Information(cronObserver.getConsumersAsString(), cronObserver.getProducersAsString(), processedMetricsLastRun, lastRunDateTime); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/consumer/IConsumer.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.consumer; 2 | 3 | import at.grisa.agilemetrics.entity.Metric; 4 | 5 | public interface IConsumer { 6 | void consume(Metric metric); 7 | 8 | boolean checkConnection(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/consumer/elasticsearch/ElasticSearchConsumer.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.consumer.elasticsearch; 2 | 3 | import at.grisa.agilemetrics.consumer.IConsumer; 4 | import at.grisa.agilemetrics.entity.Metric; 5 | import at.grisa.agilemetrics.util.PropertyManager; 6 | import org.apache.logging.log4j.LogManager; 7 | import org.apache.logging.log4j.Logger; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.context.annotation.Lazy; 10 | import org.springframework.scheduling.annotation.Scheduled; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | 16 | @Component 17 | @Lazy 18 | public class ElasticSearchConsumer implements IConsumer { 19 | private static final Logger log = LogManager.getLogger(ElasticSearchConsumer.class); 20 | 21 | private ElasticSearchRestClient restClient; 22 | private Collection metrics; 23 | private PropertyManager propertyManager; 24 | 25 | @Autowired 26 | public ElasticSearchConsumer(ElasticSearchRestClient restClient, PropertyManager propertyManager) { 27 | this.restClient = restClient; 28 | this.metrics = new ArrayList<>(); 29 | this.propertyManager = propertyManager; 30 | } 31 | 32 | @Override 33 | public boolean checkConnection() { 34 | try { 35 | return restClient.checkConnection(); 36 | } catch (Exception e) { 37 | log.error("could not connect to ElasticSearch, check error message", e); 38 | return false; 39 | } 40 | } 41 | 42 | @Override 43 | public void consume(Metric metric) { 44 | collectForBatch(metric); 45 | } 46 | 47 | private void collectForBatch(Metric metric) { 48 | this.metrics.add(metric); 49 | if (metrics.size() >= propertyManager.getElasticSearchBatchSize()) { 50 | checkAndSave(); 51 | } 52 | } 53 | 54 | @Scheduled(fixedRate = 5000) 55 | public void checkAndSave() { 56 | if (!metrics.isEmpty()) { 57 | restClient.saveMetrics(new ArrayList<>(metrics)); 58 | metrics.clear(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/consumer/elasticsearch/restentity/BulkResponse.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.consumer.elasticsearch.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | import java.util.Arrays; 6 | import java.util.Map; 7 | 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | public class BulkResponse { 10 | private Boolean errors; 11 | private Map[] items; 12 | 13 | public BulkResponse() { 14 | // default constructor 15 | } 16 | 17 | public Boolean getErrors() { 18 | return errors; 19 | } 20 | 21 | public void setErrors(Boolean errors) { 22 | this.errors = errors; 23 | } 24 | 25 | public Map[] getItems() { 26 | return items; 27 | } 28 | 29 | public void setItems(Map[] items) { 30 | this.items = items; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "BulkResponse{" + 36 | "errors=" + errors + 37 | ", items=" + Arrays.toString(items) + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/consumer/elasticsearch/restentity/ClusterInfo.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.consumer.elasticsearch.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | 6 | @JsonIgnoreProperties(ignoreUnknown = true) 7 | public class ClusterInfo { 8 | private String name; 9 | @JsonProperty("cluster_name") 10 | private String clusterName; 11 | @JsonProperty("cluster_uuid") 12 | private String clusterUuid; 13 | 14 | public ClusterInfo() { 15 | // default constructor 16 | } 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | 26 | public String getClusterName() { 27 | return clusterName; 28 | } 29 | 30 | public void setClusterName(String clusterName) { 31 | this.clusterName = clusterName; 32 | } 33 | 34 | public String getClusterUuid() { 35 | return clusterUuid; 36 | } 37 | 38 | public void setClusterUuid(String clusterUuid) { 39 | this.clusterUuid = clusterUuid; 40 | } 41 | 42 | public boolean isEmpty() { 43 | return name.isEmpty() && clusterName.isEmpty() && clusterUuid.isEmpty(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/cron/CronObserver.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.cron; 2 | 3 | import at.grisa.agilemetrics.consumer.IConsumer; 4 | import at.grisa.agilemetrics.entity.Metric; 5 | import at.grisa.agilemetrics.persistence.IStatisticRepository; 6 | import at.grisa.agilemetrics.persistence.entity.Statistic; 7 | import at.grisa.agilemetrics.producer.IProducer; 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.scheduling.annotation.Scheduled; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.time.ZonedDateTime; 15 | import java.util.LinkedList; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | 19 | @Component 20 | public class CronObserver { 21 | private static final Logger log = LogManager.getLogger(CronObserver.class); 22 | private LinkedList consumers; 23 | private LinkedList producers; 24 | 25 | @Autowired 26 | private MetricQueue metricQueue; 27 | 28 | @Autowired 29 | private IStatisticRepository statisticRepository; 30 | 31 | public CronObserver() { 32 | consumers = new LinkedList<>(); 33 | producers = new LinkedList<>(); 34 | } 35 | 36 | public void registerConsumer(IConsumer consumer) { 37 | if (!consumers.contains(consumer)) { 38 | consumers.add(consumer); 39 | } 40 | } 41 | 42 | public void registerProducer(IProducer producer) { 43 | if (!producers.contains(producer)) { 44 | producers.add(producer); 45 | } 46 | } 47 | 48 | @Scheduled(fixedDelay = 60000) 49 | public void activateConsumer() { 50 | if (!consumers.isEmpty()) { 51 | log.debug("Checking metrics queue..."); 52 | Metric metric = metricQueue.dequeueMetric(); 53 | while (metric != null) { 54 | log.debug("Metric found, sending it to all consumers and then enqueue it.", metric); 55 | for (IConsumer consumer : consumers) { 56 | // failsafe consuming 57 | try { 58 | consumer.consume(metric); 59 | log.debug("Metric send to consumer " + consumer, metric); 60 | } catch (Exception e) { 61 | log.error("Error sending metric (" + metric + ") to consumer (" + consumer + ").", e); 62 | } 63 | } 64 | metric = metricQueue.dequeueMetric(); 65 | } 66 | } else { 67 | log.error("no consumers registered"); 68 | } 69 | } 70 | 71 | @Scheduled(cron = "${cron.expression.daily:0 15 0 * * ?}") 72 | public void activateProducerDaily() { 73 | metricQueue.resetMetricsCounter(); 74 | producers.parallelStream().forEach(producer -> safeProduce(producer)); 75 | statisticRepository.save(new Statistic(metricQueue.getMetricsCounter(), ZonedDateTime.now())); 76 | log.info("producing daily metrics finished"); 77 | } 78 | 79 | /** 80 | * Failsafe producing 81 | * 82 | * @param producer 83 | */ 84 | private void safeProduce(final IProducer producer) { 85 | try { 86 | producer.produce(); 87 | } catch (Exception e) { 88 | log.error("Error producing metrics in producer " + producer, e); 89 | } 90 | } 91 | 92 | public List getConsumersAsString() { 93 | return consumers.stream().map(IConsumer::toString).collect(Collectors.toList()); 94 | } 95 | 96 | public List getProducersAsString() { 97 | return producers.stream().map(IProducer::toString).collect(Collectors.toList()); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/cron/MetricErrorHandler.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.cron; 2 | 3 | import at.grisa.agilemetrics.entity.Metric; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import org.apache.logging.log4j.LogManager; 6 | import org.apache.logging.log4j.Logger; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.util.Collection; 13 | 14 | @Component 15 | public class MetricErrorHandler { 16 | private static final Logger log = LogManager.getLogger(MetricErrorHandler.class); 17 | 18 | public static final String ERROR_DIR = MetricQueue.QUEUE_DIR + File.separator + "error"; 19 | 20 | @Autowired 21 | ObjectMapper mapper; 22 | 23 | public MetricErrorHandler() { 24 | MetricQueue.createDirectory(ERROR_DIR); 25 | } 26 | 27 | public void saveErrorMetrics(Collection metrics) { 28 | for (Metric metric : metrics) { 29 | saveErrorMetric(metric); 30 | } 31 | } 32 | 33 | public void saveErrorMetric(Metric metric) { 34 | log.debug("saving error metric " + metric); 35 | 36 | String filepath = ERROR_DIR + File.separator + System.currentTimeMillis() + "_" + Math.random() * 1000 + ".json"; 37 | 38 | try { 39 | mapper.writeValue(new File(filepath), metric); 40 | } catch (IOException e) { 41 | log.error("error when trying to save metric to file " + filepath, e); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/entity/Metric.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.entity; 2 | 3 | import java.time.ZonedDateTime; 4 | import java.time.format.DateTimeFormatter; 5 | import java.util.Map; 6 | import java.util.Objects; 7 | import java.util.Set; 8 | 9 | public final class Metric { 10 | private Double value; 11 | private String name; 12 | private Map meta; 13 | private ZonedDateTime date; 14 | private Set tags; 15 | 16 | public Metric() { 17 | } 18 | 19 | public Metric(Double value, String name, Map meta) { 20 | this.value = value; 21 | this.name = name; 22 | this.meta = meta; 23 | this.date = ZonedDateTime.now(); 24 | tags = null; 25 | } 26 | 27 | public Metric(Double value, String name, Map meta, Set tags) { 28 | this.value = value; 29 | this.name = name; 30 | this.meta = meta; 31 | this.tags = tags; 32 | this.date = ZonedDateTime.now(); 33 | } 34 | 35 | public Metric(Double value, String name, Map meta, Set tags, ZonedDateTime date) { 36 | this.value = value; 37 | this.name = name; 38 | this.meta = meta; 39 | this.tags = tags; 40 | this.date = date; 41 | } 42 | 43 | public Double getValue() { 44 | return value; 45 | } 46 | 47 | public void setValue(Double value) { 48 | this.value = value; 49 | } 50 | 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | public void setName(String name) { 56 | this.name = name; 57 | } 58 | 59 | public Map getMeta() { 60 | return meta; 61 | } 62 | 63 | public void setMeta(Map meta) { 64 | this.meta = meta; 65 | } 66 | 67 | public ZonedDateTime getDate() { 68 | return date; 69 | } 70 | 71 | public void setDate(ZonedDateTime date) { 72 | this.date = date; 73 | } 74 | 75 | public Set getTags() { 76 | return tags; 77 | } 78 | 79 | public void setTags(Set tags) { 80 | this.tags = tags; 81 | } 82 | 83 | @Override 84 | public boolean equals(Object o) { 85 | if (this == o) return true; 86 | if (o == null || getClass() != o.getClass()) return false; 87 | Metric metric = (Metric) o; 88 | DateTimeFormatter compareFormatter = DateTimeFormatter.ofPattern("yyyy-MM-ddHH:mm:ss"); 89 | return Objects.equals(value, metric.value) && 90 | Objects.equals(name, metric.name) && 91 | Objects.equals(meta, metric.meta) && 92 | Objects.equals(compareFormatter.format(date), compareFormatter.format(metric.date)) && 93 | Objects.equals(tags, metric.tags); 94 | } 95 | 96 | @Override 97 | public int hashCode() { 98 | return Objects.hash(value, name, meta, date.format(DateTimeFormatter.ofPattern("yyyy-MM-ddHH:mm:ss")), tags); 99 | } 100 | 101 | @Override 102 | public String toString() { 103 | return "Metric{" + 104 | "value=" + value + 105 | ", name='" + name + '\'' + 106 | ", meta=" + meta + 107 | ", date=" + date + 108 | ", tags=" + tags + 109 | '}'; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/persistence/IStatisticRepository.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.persistence; 2 | 3 | import at.grisa.agilemetrics.persistence.entity.Statistic; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface IStatisticRepository extends CrudRepository { 7 | Statistic findFirstByOrderByLastRunDesc(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/persistence/IVelocityRepository.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.persistence; 2 | 3 | import at.grisa.agilemetrics.persistence.entity.Velocity; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | import java.util.List; 7 | 8 | public interface IVelocityRepository extends CrudRepository { 9 | List findByTeam(String team); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/persistence/entity/Statistic.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.persistence.entity; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import java.time.ZonedDateTime; 8 | 9 | @Entity 10 | public class Statistic { 11 | @Id 12 | @GeneratedValue(strategy = GenerationType.AUTO) 13 | private Long id; 14 | private Integer metricsCount; 15 | private ZonedDateTime lastRun; 16 | 17 | public Statistic() { 18 | // default constructor 19 | } 20 | 21 | public Statistic(Integer metricsCount, ZonedDateTime lastRun) { 22 | this.metricsCount = metricsCount; 23 | this.lastRun = lastRun; 24 | } 25 | 26 | public Long getId() { 27 | return id; 28 | } 29 | 30 | public void setId(Long id) { 31 | this.id = id; 32 | } 33 | 34 | public Integer getMetricsCount() { 35 | return metricsCount; 36 | } 37 | 38 | public void setMetricsCount(Integer metricsCount) { 39 | this.metricsCount = metricsCount; 40 | } 41 | 42 | public ZonedDateTime getLastRun() { 43 | return lastRun; 44 | } 45 | 46 | public void setLastRun(ZonedDateTime lastRun) { 47 | this.lastRun = lastRun; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/persistence/entity/Velocity.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.persistence.entity; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | @Entity 9 | public class Velocity { 10 | @Id 11 | @GeneratedValue(strategy = GenerationType.AUTO) 12 | private Long id; 13 | private String team; 14 | private String sprint; 15 | private String goal; 16 | private Integer estimated; 17 | private Integer completed; 18 | 19 | public Velocity() { 20 | // default constructor 21 | } 22 | 23 | public Velocity(String team, String sprint, String goal, Integer estimated, Integer completed) { 24 | this.team = team; 25 | this.sprint = sprint; 26 | this.goal = goal; 27 | this.estimated = estimated; 28 | this.completed = completed; 29 | } 30 | 31 | public Long getId() { 32 | return id; 33 | } 34 | 35 | public void setId(Long id) { 36 | this.id = id; 37 | } 38 | 39 | public String getTeam() { 40 | return team; 41 | } 42 | 43 | public void setTeam(String team) { 44 | this.team = team; 45 | } 46 | 47 | public String getSprint() { 48 | return sprint; 49 | } 50 | 51 | public void setSprint(String sprint) { 52 | this.sprint = sprint; 53 | } 54 | 55 | public String getGoal() { 56 | return goal; 57 | } 58 | 59 | public void setGoal(String goal) { 60 | this.goal = goal; 61 | } 62 | 63 | public Integer getEstimated() { 64 | return estimated; 65 | } 66 | 67 | public void setEstimated(Integer estimated) { 68 | this.estimated = estimated; 69 | } 70 | 71 | public Integer getCompleted() { 72 | return completed; 73 | } 74 | 75 | public void setCompleted(Integer completed) { 76 | this.completed = completed; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/IProducer.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer; 2 | 3 | public interface IProducer { 4 | void produce(); 5 | 6 | boolean checkConnection(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/atlassian/rest/entities/QueryParam.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.atlassian.rest.entities; 2 | 3 | import java.util.Objects; 4 | 5 | public class QueryParam { 6 | public final String name; 7 | public final Object value; 8 | 9 | public QueryParam(String name, Object value) { 10 | this.name = name; 11 | this.value = value; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return "QueryParam{" + 17 | "name='" + name + '\'' + 18 | ", value=" + value + 19 | '}'; 20 | } 21 | 22 | @Override 23 | public boolean equals(Object o) { 24 | if (this == o) return true; 25 | if (o == null || getClass() != o.getClass()) return false; 26 | QueryParam that = (QueryParam) o; 27 | return Objects.equals(name, that.name) && 28 | Objects.equals(value, that.value); 29 | } 30 | 31 | @Override 32 | public int hashCode() { 33 | return Objects.hash(name, value); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/bitbucketserver/restentity/ApplicationProperties.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class ApplicationProperties { 7 | private String version; 8 | private String buildNumber; 9 | private String buildDate; 10 | private String displayName; 11 | 12 | public ApplicationProperties() { 13 | // default constructor 14 | } 15 | 16 | public String getVersion() { 17 | return version; 18 | } 19 | 20 | public void setVersion(String version) { 21 | this.version = version; 22 | } 23 | 24 | public String getBuildNumber() { 25 | return buildNumber; 26 | } 27 | 28 | public void setBuildNumber(String buildNumber) { 29 | this.buildNumber = buildNumber; 30 | } 31 | 32 | public String getBuildDate() { 33 | return buildDate; 34 | } 35 | 36 | public void setBuildDate(String buildDate) { 37 | this.buildDate = buildDate; 38 | } 39 | 40 | public String getDisplayName() { 41 | return displayName; 42 | } 43 | 44 | public void setDisplayName(String displayName) { 45 | this.displayName = displayName; 46 | } 47 | 48 | public boolean isEmpty() { 49 | return version == null && buildNumber == null && buildDate == null && displayName == null; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "ApplicationProperties{" + 55 | "version='" + version + '\'' + 56 | ", buildNumber='" + buildNumber + '\'' + 57 | ", buildDate='" + buildDate + '\'' + 58 | ", displayName='" + displayName + '\'' + 59 | '}'; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/bitbucketserver/restentity/Commit.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | import java.util.Date; 6 | 7 | @JsonIgnoreProperties(ignoreUnknown = true) 8 | public class Commit { 9 | private String id; 10 | private String message; 11 | private User author; 12 | private Date authorTimestamp; 13 | private User committer; 14 | private Date committerTimestamp; 15 | 16 | public Commit() { 17 | // default constructor 18 | } 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getMessage() { 29 | return message; 30 | } 31 | 32 | public void setMessage(String message) { 33 | this.message = message; 34 | } 35 | 36 | public User getAuthor() { 37 | return author; 38 | } 39 | 40 | public void setAuthor(User author) { 41 | this.author = author; 42 | } 43 | 44 | public Date getAuthorTimestamp() { 45 | return authorTimestamp; 46 | } 47 | 48 | public void setAuthorTimestamp(Date authorTimestamp) { 49 | this.authorTimestamp = authorTimestamp; 50 | } 51 | 52 | public User getCommitter() { 53 | return committer; 54 | } 55 | 56 | public void setCommitter(User committer) { 57 | this.committer = committer; 58 | } 59 | 60 | public Date getCommitterTimestamp() { 61 | return committerTimestamp; 62 | } 63 | 64 | public void setCommitterTimestamp(Date committerTimestamp) { 65 | this.committerTimestamp = committerTimestamp; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/bitbucketserver/restentity/PagedEntities.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restentity; 2 | 3 | public class PagedEntities { 4 | private Boolean isLastPage; 5 | private Integer nextPageStart; 6 | private T[] values; 7 | 8 | public PagedEntities() { 9 | // default constructor 10 | } 11 | 12 | public Boolean getIsLastPage() { 13 | return isLastPage; 14 | } 15 | 16 | public void setIsLastPage(Boolean lastPage) { 17 | isLastPage = lastPage; 18 | } 19 | 20 | public Integer getNextPageStart() { 21 | return nextPageStart; 22 | } 23 | 24 | public void setNextPageStart(Integer nextPageStart) { 25 | this.nextPageStart = nextPageStart; 26 | } 27 | 28 | public T[] getValues() { 29 | return values; 30 | } 31 | 32 | public void setValues(T[] values) { 33 | this.values = values; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/bitbucketserver/restentity/Project.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Project { 7 | private String key; 8 | private Long id; 9 | private String name; 10 | 11 | public Project() { 12 | // default constructor 13 | } 14 | 15 | public String getKey() { 16 | return key; 17 | } 18 | 19 | public void setKey(String key) { 20 | this.key = key; 21 | } 22 | 23 | public Long getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Long id) { 28 | this.id = id; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/bitbucketserver/restentity/Repository.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Repository { 7 | private Long id; 8 | private String slug; 9 | private String name; 10 | 11 | public Repository() { 12 | // default constructor 13 | } 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(Long id) { 20 | this.id = id; 21 | } 22 | 23 | public String getSlug() { 24 | return slug; 25 | } 26 | 27 | public void setSlug(String slug) { 28 | this.slug = slug; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/bitbucketserver/restentity/User.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class User { 7 | private String name; 8 | private String emailAddress; 9 | 10 | public User() { 11 | // default constructor 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public String getEmailAddress() { 23 | return emailAddress; 24 | } 25 | 26 | public void setEmailAddress(String emailAddress) { 27 | this.emailAddress = emailAddress; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/Board.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Board { 7 | private Long id; 8 | private String name; 9 | private String type; 10 | 11 | public Board() { 12 | // default constructor 13 | } 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(Long id) { 20 | this.id = id; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public String getType() { 32 | return type; 33 | } 34 | 35 | public void setType(String type) { 36 | this.type = type; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/BoardConfiguration.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class BoardConfiguration { 7 | private Filter filter; 8 | 9 | public BoardConfiguration() { 10 | // default constructor 11 | } 12 | 13 | public Filter getFilter() { 14 | return filter; 15 | } 16 | 17 | public void setFilter(Filter filter) { 18 | this.filter = filter; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/ChangeLog.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class ChangeLog { 7 | private Integer startAt; 8 | private Integer maxResults; 9 | private Integer total; 10 | private History[] histories; 11 | 12 | public ChangeLog() { 13 | // default constructor 14 | } 15 | 16 | public Integer getStartAt() { 17 | return startAt; 18 | } 19 | 20 | public void setStartAt(Integer startAt) { 21 | this.startAt = startAt; 22 | } 23 | 24 | public Integer getMaxResults() { 25 | return maxResults; 26 | } 27 | 28 | public void setMaxResults(Integer maxResults) { 29 | this.maxResults = maxResults; 30 | } 31 | 32 | public Integer getTotal() { 33 | return total; 34 | } 35 | 36 | public void setTotal(Integer total) { 37 | this.total = total; 38 | } 39 | 40 | public History[] getHistories() { 41 | return histories; 42 | } 43 | 44 | public void setHistories(History[] histories) { 45 | this.histories = histories; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/Fields.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | 6 | import java.time.ZonedDateTime; 7 | 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | public class Fields { 10 | private Status status; 11 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") 12 | private ZonedDateTime created; 13 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") 14 | private ZonedDateTime resolutiondate; 15 | private String[] labels; 16 | 17 | public Fields() { 18 | // default constructor 19 | } 20 | 21 | public Status getStatus() { 22 | return status; 23 | } 24 | 25 | public void setStatus(Status status) { 26 | this.status = status; 27 | } 28 | 29 | public ZonedDateTime getCreated() { 30 | return created; 31 | } 32 | 33 | public void setCreated(ZonedDateTime created) { 34 | this.created = created; 35 | } 36 | 37 | public ZonedDateTime getResolutiondate() { 38 | return resolutiondate; 39 | } 40 | 41 | public void setResolutiondate(ZonedDateTime resolutiondate) { 42 | this.resolutiondate = resolutiondate; 43 | } 44 | 45 | public String[] getLabels() { 46 | return labels; 47 | } 48 | 49 | public void setLabels(String[] labels) { 50 | this.labels = labels; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/Filter.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Filter { 7 | private Long id; 8 | private String jql; 9 | 10 | public Filter() { 11 | // default constructor 12 | } 13 | 14 | public Long getId() { 15 | return id; 16 | } 17 | 18 | public void setId(Long id) { 19 | this.id = id; 20 | } 21 | 22 | public String getJql() { 23 | return jql; 24 | } 25 | 26 | public void setJql(String jql) { 27 | this.jql = jql; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/History.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | 6 | import java.time.ZonedDateTime; 7 | 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | public class History { 10 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") 11 | private ZonedDateTime created; 12 | private HistoryItem[] items; 13 | 14 | public History() { 15 | // default constructor 16 | } 17 | 18 | public ZonedDateTime getCreated() { 19 | return created; 20 | } 21 | 22 | public void setCreated(ZonedDateTime created) { 23 | this.created = created; 24 | } 25 | 26 | public HistoryItem[] getItems() { 27 | return items; 28 | } 29 | 30 | public void setItems(HistoryItem[] items) { 31 | this.items = items; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/HistoryItem.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | 6 | import java.time.ZonedDateTime; 7 | 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | public class HistoryItem { 10 | private String field; 11 | private String fromString; 12 | private String toString; 13 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") 14 | private ZonedDateTime created; 15 | 16 | public HistoryItem() { 17 | // default constructor 18 | } 19 | 20 | public String getField() { 21 | return field; 22 | } 23 | 24 | public void setField(String field) { 25 | this.field = field; 26 | } 27 | 28 | public String getFromString() { 29 | return fromString; 30 | } 31 | 32 | public void setFromString(String fromString) { 33 | this.fromString = fromString; 34 | } 35 | 36 | public String getToString() { 37 | return toString; 38 | } 39 | 40 | public void setToString(String toString) { 41 | this.toString = toString; 42 | } 43 | 44 | public void setCreated(ZonedDateTime created) { 45 | this.created = created; 46 | } 47 | 48 | public ZonedDateTime getCreated() { 49 | return created; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/Issue.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Issue { 7 | private Long id; 8 | private String key; 9 | private Fields fields; 10 | private ChangeLog changelog; 11 | 12 | public Issue() { 13 | // default constructor 14 | } 15 | 16 | public Long getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Long id) { 21 | this.id = id; 22 | } 23 | 24 | public String getKey() { 25 | return key; 26 | } 27 | 28 | public void setKey(String key) { 29 | this.key = key; 30 | } 31 | 32 | public Fields getFields() { 33 | return fields; 34 | } 35 | 36 | public void setFields(Fields fields) { 37 | this.fields = fields; 38 | } 39 | 40 | public ChangeLog getChangelog() { 41 | return changelog; 42 | } 43 | 44 | public void setChangelog(ChangeLog changelog) { 45 | this.changelog = changelog; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/PagedEntities.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | public class PagedEntities { 4 | private Boolean isLast; 5 | private Integer startAt; 6 | private Integer maxResults; 7 | private Integer total; 8 | 9 | private T[] values; 10 | private Issue[] issues; 11 | 12 | public PagedEntities() { 13 | // default constructor 14 | } 15 | 16 | public Boolean getLast() { 17 | return isLast; 18 | } 19 | 20 | public void setLast(Boolean last) { 21 | isLast = last; 22 | } 23 | 24 | public Integer getStartAt() { 25 | return startAt; 26 | } 27 | 28 | public void setStartAt(Integer startAt) { 29 | this.startAt = startAt; 30 | } 31 | 32 | public Integer getMaxResults() { 33 | return maxResults; 34 | } 35 | 36 | public void setMaxResults(Integer maxResults) { 37 | this.maxResults = maxResults; 38 | } 39 | 40 | public Integer getTotal() { 41 | return total; 42 | } 43 | 44 | public void setTotal(Integer total) { 45 | this.total = total; 46 | } 47 | 48 | public T[] getValues() { 49 | return values; 50 | } 51 | 52 | public void setValues(T[] values) { 53 | this.values = values; 54 | } 55 | 56 | public Issue[] getIssues() { 57 | return issues; 58 | } 59 | 60 | public void setIssues(Issue[] issues) { 61 | this.issues = issues; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/ServerInfo.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class ServerInfo { 7 | private String baseUrl; 8 | private String version; 9 | private String buildNumber; 10 | private String scmInfo; 11 | private String buildPartnerName; 12 | private String serverTitle; 13 | 14 | public ServerInfo() { 15 | // default constructor 16 | } 17 | 18 | public String getBaseUrl() { 19 | return baseUrl; 20 | } 21 | 22 | public void setBaseUrl(String baseUrl) { 23 | this.baseUrl = baseUrl; 24 | } 25 | 26 | public String getVersion() { 27 | return version; 28 | } 29 | 30 | public void setVersion(String version) { 31 | this.version = version; 32 | } 33 | 34 | public String getBuildNumber() { 35 | return buildNumber; 36 | } 37 | 38 | public void setBuildNumber(String buildNumber) { 39 | this.buildNumber = buildNumber; 40 | } 41 | 42 | public String getScmInfo() { 43 | return scmInfo; 44 | } 45 | 46 | public void setScmInfo(String scmInfo) { 47 | this.scmInfo = scmInfo; 48 | } 49 | 50 | public String getBuildPartnerName() { 51 | return buildPartnerName; 52 | } 53 | 54 | public void setBuildPartnerName(String buildPartnerName) { 55 | this.buildPartnerName = buildPartnerName; 56 | } 57 | 58 | public String getServerTitle() { 59 | return serverTitle; 60 | } 61 | 62 | public void setServerTitle(String serverTitle) { 63 | this.serverTitle = serverTitle; 64 | } 65 | 66 | public boolean isEmpty() { 67 | return baseUrl == null && version == null && buildNumber == null && 68 | scmInfo == null && buildPartnerName == null && serverTitle == null; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "ServerInfo{" + 74 | "baseUrl='" + baseUrl + '\'' + 75 | ", version='" + version + '\'' + 76 | ", buildNumber='" + buildNumber + '\'' + 77 | ", scmInfo='" + scmInfo + '\'' + 78 | ", buildPartnerName='" + buildPartnerName + '\'' + 79 | ", serverTitle='" + serverTitle + '\'' + 80 | '}'; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/Sprint.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Sprint { 7 | private Long id; 8 | private String state; 9 | private String name; 10 | private String goal; 11 | private Integer sequence; 12 | 13 | public Sprint() { 14 | // default constructor 15 | } 16 | 17 | public Long getId() { 18 | return id; 19 | } 20 | 21 | public void setId(Long id) { 22 | this.id = id; 23 | } 24 | 25 | public String getState() { 26 | return state; 27 | } 28 | 29 | public void setState(String state) { 30 | this.state = state; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | public String getGoal() { 42 | return goal; 43 | } 44 | 45 | public void setGoal(String goal) { 46 | this.goal = goal; 47 | } 48 | 49 | public Integer getSequence() { 50 | return sequence; 51 | } 52 | 53 | public void setSequence(Integer sequence) { 54 | this.sequence = sequence; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/Status.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Status { 7 | private String name; 8 | private StatusCategory statusCategory; 9 | 10 | public Status() { 11 | // default constructor 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public StatusCategory getStatusCategory() { 23 | return statusCategory; 24 | } 25 | 26 | public void setStatusCategory(StatusCategory statusCategory) { 27 | this.statusCategory = statusCategory; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/StatusCategory.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class StatusCategory { 7 | private String name; 8 | 9 | public StatusCategory() { 10 | // default constructor 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/Value.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Value { 7 | private Integer value; 8 | 9 | public Value() { 10 | // default constructor 11 | } 12 | 13 | public Value(int value) { 14 | this.value = value; 15 | } 16 | 17 | public Integer getValue() { 18 | return value; 19 | } 20 | 21 | public void setValue(Integer value) { 22 | this.value = value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/VelocityReport.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | import java.util.Map; 4 | 5 | public class VelocityReport { 6 | private Sprint[] sprints; 7 | private Map velocityStatEntries; 8 | 9 | public VelocityReport() { 10 | // default constructor 11 | } 12 | 13 | public Sprint[] getSprints() { 14 | return sprints; 15 | } 16 | 17 | public void setSprints(Sprint[] sprints) { 18 | this.sprints = sprints; 19 | } 20 | 21 | public Map getVelocityStatEntries() { 22 | return velocityStatEntries; 23 | } 24 | 25 | public void setVelocityStatEntries(Map velocityStatEntries) { 26 | this.velocityStatEntries = velocityStatEntries; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/VelocityStats.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity; 2 | 3 | public class VelocityStats { 4 | private Long sprintId; 5 | private Value estimated; 6 | private Value completed; 7 | 8 | public VelocityStats() { 9 | // default constructor 10 | } 11 | 12 | public Long getSprintId() { 13 | return sprintId; 14 | } 15 | 16 | public void setSprintId(Long sprintId) { 17 | this.sprintId = sprintId; 18 | } 19 | 20 | public Value getEstimated() { 21 | return estimated; 22 | } 23 | 24 | public void setEstimated(Value estimated) { 25 | this.estimated = estimated; 26 | } 27 | 28 | public Value getCompleted() { 29 | return completed; 30 | } 31 | 32 | public void setCompleted(Value completed) { 33 | this.completed = completed; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/greenhopper/Contents.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.greenhopper; 2 | 3 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Value; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | 6 | @JsonIgnoreProperties(ignoreUnknown = true) 7 | public class Contents { 8 | private Value completedIssuesEstimateSum; 9 | private Value issuesNotCompletedEstimateSum; 10 | 11 | public Contents() { 12 | // default constructor 13 | } 14 | 15 | public Value getCompletedIssuesEstimateSum() { 16 | return completedIssuesEstimateSum; 17 | } 18 | 19 | public void setCompletedIssuesEstimateSum(Value completedIssuesEstimateSum) { 20 | this.completedIssuesEstimateSum = completedIssuesEstimateSum; 21 | } 22 | 23 | public Value getIssuesNotCompletedEstimateSum() { 24 | return issuesNotCompletedEstimateSum; 25 | } 26 | 27 | public void setIssuesNotCompletedEstimateSum(Value issuesNotCompletedEstimateSum) { 28 | this.issuesNotCompletedEstimateSum = issuesNotCompletedEstimateSum; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/greenhopper/RapidView.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.greenhopper; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class RapidView { 7 | private Long id; 8 | private String name; 9 | private Boolean sprintSupportEnabled; 10 | 11 | public RapidView() { 12 | // default constructor 13 | } 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(Long id) { 20 | this.id = id; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public Boolean getSprintSupportEnabled() { 32 | return sprintSupportEnabled; 33 | } 34 | 35 | public void setSprintSupportEnabled(Boolean sprintSupportEnabled) { 36 | this.sprintSupportEnabled = sprintSupportEnabled; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/greenhopper/RapidViews.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.greenhopper; 2 | 3 | public class RapidViews { 4 | private RapidView[] views; 5 | 6 | public RapidViews() { 7 | // default constructor 8 | } 9 | 10 | public RapidView[] getViews() { 11 | return views; 12 | } 13 | 14 | public void setViews(RapidView[] views) { 15 | this.views = views; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/greenhopper/Sprint.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.greenhopper; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Sprint { 7 | private Long id; 8 | private String name; 9 | private String state; 10 | 11 | public Sprint() { 12 | // default constructor 13 | } 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(Long id) { 20 | this.id = id; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public String getState() { 32 | return state; 33 | } 34 | 35 | public void setState(String state) { 36 | this.state = state; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/greenhopper/SprintReport.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.greenhopper; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class SprintReport { 7 | private Contents contents; 8 | 9 | public SprintReport() { 10 | // default constructor 11 | } 12 | 13 | public Contents getContents() { 14 | return contents; 15 | } 16 | 17 | public void setContents(Contents contents) { 18 | this.contents = contents; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restentity/greenhopper/Sprints.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.greenhopper; 2 | 3 | public class Sprints { 4 | private Sprint[] sprints; 5 | 6 | public Sprints() { 7 | // default constructor 8 | } 9 | 10 | public Sprint[] getSprints() { 11 | return sprints; 12 | } 13 | 14 | public void setSprints(Sprint[] sprints) { 15 | this.sprints = sprints; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/sonarqube/SonarQubeProducer.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube; 2 | 3 | import at.grisa.agilemetrics.cron.MetricQueue; 4 | import at.grisa.agilemetrics.producer.IProducer; 5 | import at.grisa.agilemetrics.producer.sonarqube.restentity.Component; 6 | import at.grisa.agilemetrics.producer.sonarqube.restentity.Measure; 7 | import at.grisa.agilemetrics.producer.sonarqube.restentity.Metric; 8 | import at.grisa.agilemetrics.util.PropertyManager; 9 | import org.apache.logging.log4j.LogManager; 10 | import org.apache.logging.log4j.Logger; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | 13 | import java.util.Collection; 14 | import java.util.HashMap; 15 | import java.util.LinkedList; 16 | import java.util.Map; 17 | 18 | @org.springframework.stereotype.Component 19 | public class SonarQubeProducer implements IProducer { 20 | private static final Logger log = LogManager.getLogger(SonarQubeProducer.class); 21 | 22 | @Autowired 23 | private SonarQubeRestClient sonarQubeRestClient; 24 | 25 | @Autowired 26 | private MetricQueue metricQueue; 27 | 28 | @Autowired 29 | private PropertyManager propertyManager; 30 | 31 | @Override 32 | public boolean checkConnection() { 33 | try { 34 | return sonarQubeRestClient.checkConnection(); 35 | } catch (Exception e) { 36 | log.error("could not connect to SonarQube, check error message", e); 37 | return false; 38 | } 39 | } 40 | 41 | @Override 42 | public void produce() { 43 | Collection metricsList = new LinkedList<>(); 44 | 45 | if (propertyManager.getSonarqubeMetrics() != null) { 46 | for (String metric : propertyManager.getSonarqubeMetrics().split(",")) { 47 | try { // only take known and checked values 48 | Metric newMetric = Metric.getMetric(metric); 49 | metricsList.add(newMetric); 50 | } catch (IllegalArgumentException e) { 51 | log.error(e); 52 | } 53 | } 54 | 55 | Metric[] metrics = new Metric[0]; 56 | metrics = metricsList.toArray(metrics); 57 | 58 | if (metrics.length > 0) { 59 | produceMetrics(metrics); 60 | } 61 | } else { 62 | throw new IllegalStateException("no SonarQube metrics defined in application.properties (producer.sonarqube.metrics), cannot produce metrics"); 63 | } 64 | } 65 | 66 | private void produceMetrics(Metric[] metrics) { 67 | // failsafe execution 68 | try { 69 | for (Component component : sonarQubeRestClient.getComponents()) { 70 | Collection measures = sonarQubeRestClient.getMeasures(component.getKey(), metrics); 71 | for (Measure measure : measures) { 72 | Map meta = new HashMap<>(); 73 | meta.put("component", component.getName()); 74 | metricQueue.enqueueMetric(new at.grisa.agilemetrics.entity.Metric(measure.getValue(), "SonarQube - " + measure.getMetric(), meta)); 75 | } 76 | 77 | } 78 | } catch (Exception e) { 79 | log.error("Error producing metric.", e); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/sonarqube/SonarQubeRestClient.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube; 2 | 3 | import at.grisa.agilemetrics.producer.RestClient; 4 | import at.grisa.agilemetrics.producer.atlassian.rest.entities.QueryParam; 5 | import at.grisa.agilemetrics.producer.sonarqube.restentity.*; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.springframework.web.client.HttpClientErrorException; 10 | 11 | import java.util.Arrays; 12 | import java.util.Collection; 13 | import java.util.stream.Collectors; 14 | 15 | @org.springframework.stereotype.Component 16 | public class SonarQubeRestClient { 17 | private static final Logger log = LogManager.getLogger(SonarQubeRestClient.class); 18 | 19 | public static final String PATH_LOGIN = "/api/authentication/login"; 20 | public static final String PATH_COMPONENTS = "/api/projects/search"; 21 | public static final String PATH_MEASURES = "/api/measures/component"; 22 | private final RestClient restClient; 23 | 24 | public SonarQubeRestClient(CredentialManager credentialManager) { 25 | String host = credentialManager.getSonarqubeBaseUrl(); 26 | String user = credentialManager.getSonarqubeUsername(); 27 | String password = credentialManager.getSonarqubePassword(); 28 | restClient = new RestClient(host, user, password); 29 | 30 | // set proxy if configured 31 | if (credentialManager.isProxyAuthActive()) { 32 | restClient.setHttpProxyAuth(credentialManager.getHttpProxyHost(), credentialManager.getHttpProxyPort(), credentialManager.getHttpProxyUser(), credentialManager.getHttpProxyPassword()); 33 | } else if (credentialManager.isProxyActive()) { 34 | restClient.setHttpProxy(credentialManager.getHttpProxyHost(), credentialManager.getHttpProxyPort()); 35 | } 36 | } 37 | 38 | public boolean checkConnection() { 39 | Integer statusCode = restClient.postReturnStatusNoAuthorization(PATH_LOGIN, new QueryParam("login", restClient.getUsername()), new QueryParam("password", restClient.getPassword())); 40 | log.info("SonarQube authentication test returns HTTP status " + statusCode); 41 | return statusCode == 200; 42 | } 43 | 44 | public Collection getComponents() { 45 | QueryParam qualifierQueryParam = new QueryParam("qualifiers", "TRK"); 46 | Integer page = 1; 47 | Boolean nextPage = true; 48 | Component[] results = new Component[0]; 49 | 50 | while (nextPage) { 51 | QueryParam pageQueryParam = new QueryParam("p", page); 52 | ComponentSearch componentSearch = restClient.getEntity(ComponentSearch.class, PATH_COMPONENTS, qualifierQueryParam, pageQueryParam); 53 | 54 | results = restClient.mergeArrays(results, componentSearch.getComponents(), Component.class); 55 | 56 | nextPage = componentSearch.getPaging().hasNextPage(); 57 | page++; 58 | } 59 | 60 | return Arrays.asList(results); 61 | } 62 | 63 | public Collection getMeasures(String componentKey, Metric... metrics) { 64 | QueryParam componentQueryParam = new QueryParam("component", componentKey); 65 | QueryParam metricsQueryParam = new QueryParam("metricKeys", Arrays.stream(metrics).map(Metric::toString).collect(Collectors.joining(","))); 66 | 67 | Collection measures = null; 68 | ComponentMeasures componentMeasures = null; 69 | try { 70 | componentMeasures = restClient.getEntity(ComponentMeasures.class, PATH_MEASURES, componentQueryParam, metricsQueryParam); 71 | } catch (HttpClientErrorException e) { 72 | log.error("error calling path " + PATH_MEASURES + " for component " + componentKey + " and metrics " + metrics, e); 73 | } 74 | 75 | 76 | if (componentMeasures != null && componentMeasures.getComponent() != null) { 77 | measures = Arrays.asList(componentMeasures.getComponent().getMeasures()); 78 | } 79 | 80 | return measures; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/sonarqube/restentity/Component.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | 6 | import java.time.ZonedDateTime; 7 | 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | public class Component { 10 | private String organization; 11 | private String key; 12 | private String name; 13 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssX") 14 | private ZonedDateTime lastAnalysisDate; 15 | private Measure[] measures; 16 | 17 | public Component() { 18 | // default constructor 19 | } 20 | 21 | public String getOrganization() { 22 | return organization; 23 | } 24 | 25 | public void setOrganization(String organization) { 26 | this.organization = organization; 27 | } 28 | 29 | public String getKey() { 30 | return key; 31 | } 32 | 33 | public void setKey(String key) { 34 | this.key = key; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public ZonedDateTime getLastAnalysisDate() { 46 | return lastAnalysisDate; 47 | } 48 | 49 | public void setLastAnalysisDate(ZonedDateTime lastAnalysisDate) { 50 | this.lastAnalysisDate = lastAnalysisDate; 51 | } 52 | 53 | public Measure[] getMeasures() { 54 | return measures; 55 | } 56 | 57 | public void setMeasures(Measure[] measures) { 58 | this.measures = measures; 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/sonarqube/restentity/ComponentMeasures.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restentity; 2 | 3 | public class ComponentMeasures { 4 | private Component component; 5 | 6 | public ComponentMeasures() { 7 | // default constructor 8 | } 9 | 10 | public Component getComponent() { 11 | return component; 12 | } 13 | 14 | public void setComponent(Component component) { 15 | this.component = component; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/sonarqube/restentity/ComponentSearch.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restentity; 2 | 3 | public class ComponentSearch { 4 | private Paging paging; 5 | private Component[] components; 6 | 7 | public ComponentSearch() { 8 | // default constructor 9 | } 10 | 11 | public Paging getPaging() { 12 | return paging; 13 | } 14 | 15 | public void setPaging(Paging paging) { 16 | this.paging = paging; 17 | } 18 | 19 | public Component[] getComponents() { 20 | return components; 21 | } 22 | 23 | public void setComponents(Component[] components) { 24 | this.components = components; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/sonarqube/restentity/Measure.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class Measure { 7 | private String metric; 8 | private Double value; 9 | 10 | public Measure() { 11 | // default constructor 12 | } 13 | 14 | public String getMetric() { 15 | return metric; 16 | } 17 | 18 | public void setMetric(String metric) { 19 | this.metric = metric; 20 | } 21 | 22 | public Double getValue() { 23 | return value; 24 | } 25 | 26 | public void setValue(Double value) { 27 | this.value = value; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/sonarqube/restentity/Metric.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restentity; 2 | 3 | public enum Metric { 4 | COVERAGE("coverage"), 5 | TEST_EXECUTION_TIME("test_execution_time"); 6 | 7 | private String value; 8 | 9 | Metric(String value) { 10 | this.value = value; 11 | } 12 | 13 | public static Metric getMetric(String value) { 14 | switch (value) { 15 | case "coverage": 16 | return Metric.COVERAGE; 17 | case "test_execution_time": 18 | return Metric.TEST_EXECUTION_TIME; 19 | default: 20 | throw new IllegalArgumentException("unknown value " + value + " for the Metric enum"); 21 | } 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return value; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/sonarqube/restentity/Paging.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restentity; 2 | 3 | public class Paging { 4 | private Integer pageIndex; 5 | private Integer pageSize; 6 | private Integer total; 7 | 8 | public Paging() { 9 | // default constructor 10 | } 11 | 12 | public Integer getPageIndex() { 13 | return pageIndex; 14 | } 15 | 16 | public void setPageIndex(Integer pageIndex) { 17 | this.pageIndex = pageIndex; 18 | } 19 | 20 | public Integer getPageSize() { 21 | return pageSize; 22 | } 23 | 24 | public void setPageSize(Integer pageSize) { 25 | this.pageSize = pageSize; 26 | } 27 | 28 | public Integer getTotal() { 29 | return total; 30 | } 31 | 32 | public void setTotal(Integer total) { 33 | this.total = total; 34 | } 35 | 36 | public boolean hasNextPage() { 37 | Integer resutls = pageIndex * pageSize; 38 | return resutls < total; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/producer/sonarqube/restentity/ServerVersion.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restentity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | @JsonIgnoreProperties(ignoreUnknown = true) 6 | public class ServerVersion { 7 | private String version; 8 | 9 | public ServerVersion() { 10 | // default constructor 11 | } 12 | 13 | public String getVersion() { 14 | return version; 15 | } 16 | 17 | public void setVersion(String version) { 18 | this.version = version; 19 | } 20 | 21 | public boolean isEmpty() { 22 | return version == null; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/at/grisa/agilemetrics/util/PropertyManager.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.util; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.util.Arrays; 7 | import java.util.LinkedList; 8 | import java.util.List; 9 | import java.util.stream.Collectors; 10 | 11 | @Component 12 | public class PropertyManager { 13 | @Value("${producer.jirasoftware.workflow:@null}") 14 | private String jirasoftwareWorkflow; 15 | @Value("${producer.jirasoftware.acceptanceCriteriaFieldName:@null}") 16 | private String jirasoftwareAcceptanceCriteriaFieldName; 17 | 18 | @Value("${producer.sonarqube.metrics:@null}") 19 | private String sonarqubeMetrics; 20 | 21 | @Value("${consumer.elasticsearch.batchSize:@null}") 22 | private String elasticsearchBatchSize; 23 | private static final Integer ELASTICSEARCH_BATCHSIZE_DEFAULT = 50; 24 | 25 | @Value("${consumer.elasticsearch.indexName:@null}") 26 | private String elasticsearchIndexName; 27 | 28 | @Value("${consumer.elasticsearch.typeName:@null}") 29 | private String elasticsearchTypeName; 30 | 31 | public PropertyManager() { 32 | // default constructor 33 | } 34 | 35 | public List getJirasoftwareWorkflow() { 36 | if (jirasoftwareWorkflow != null) { 37 | return Arrays.stream(jirasoftwareWorkflow.split(",")).map(String::toLowerCase).collect(Collectors.toList()); 38 | } else { 39 | return new LinkedList<>(); 40 | } 41 | } 42 | 43 | public void setJirasoftwareWorkflow(String jirasoftwareWorkflow) { 44 | this.jirasoftwareWorkflow = jirasoftwareWorkflow; 45 | } 46 | 47 | public String getJirasoftwareAcceptanceCriteriaFieldName() { 48 | return jirasoftwareAcceptanceCriteriaFieldName; 49 | } 50 | 51 | public void setJirasoftwareAcceptanceCriteriaFieldName(String jirasoftwareAcceptanceCriteriaFieldName) { 52 | this.jirasoftwareAcceptanceCriteriaFieldName = jirasoftwareAcceptanceCriteriaFieldName; 53 | } 54 | 55 | public String getSonarqubeMetrics() { 56 | return sonarqubeMetrics; 57 | } 58 | 59 | public void setSonarqubeMetrics(String sonarqubeMetrics) { 60 | this.sonarqubeMetrics = sonarqubeMetrics; 61 | } 62 | 63 | public Integer getElasticSearchBatchSize() { 64 | if (elasticsearchBatchSize == null || elasticsearchBatchSize.isEmpty()) { 65 | return ELASTICSEARCH_BATCHSIZE_DEFAULT; 66 | } 67 | return Integer.valueOf(elasticsearchBatchSize); 68 | } 69 | 70 | public void setElasticsearchBatchSize(String elasticsearchBatchSize) { 71 | this.elasticsearchBatchSize = elasticsearchBatchSize; 72 | } 73 | 74 | public String getElasticSearchIndexName() { 75 | return this.elasticsearchIndexName; 76 | } 77 | 78 | public void setElasticsearchIndexName(String elasticsearchIndexName) { 79 | this.elasticsearchIndexName = elasticsearchIndexName; 80 | } 81 | 82 | public String getElasticSearchTypeName() { 83 | return this.elasticsearchTypeName; 84 | } 85 | 86 | public void setElasticsearchTypeName(String elasticsearchTypeName) { 87 | this.elasticsearchTypeName = elasticsearchTypeName; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:h2:file:./agileMetrics.db;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE 2 | spring.datasource.driverClassName=org.h2.Driver 3 | spring.jpa.database-platform=org.hibernate.dialect.H2Dialect 4 | spring.jpa.hibernate.ddl-auto=update -------------------------------------------------------------------------------- /src/main/resources/log4j2.yaml: -------------------------------------------------------------------------------- 1 | Configutation: 2 | name: Default 3 | Properties: 4 | Property: 5 | name: log-path 6 | value: "logs" 7 | Appenders: 8 | Console: 9 | name: Console_Appender 10 | target: SYSTEM_OUT 11 | PatternLayout: 12 | pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" 13 | RollingFile: 14 | - name: RollingFile_Appender 15 | fileName: ${log-path}/rollingfile.log 16 | filePattern: "logs/archive/rollingfile.log.%d{yyyy-MM-dd}.gz" 17 | PatternLayout: 18 | pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" 19 | TimeBasedTriggeringPolicy: 20 | interval: 1 21 | modulate: true 22 | Loggers: 23 | Root: 24 | level: debug 25 | AppenderRef: 26 | - ref: Console_Appender 27 | Logger: 28 | - name: at.grisa.agilemetrics 29 | additivity: false 30 | level: debug 31 | AppenderRef: 32 | - ref: Console_Appender 33 | level: info 34 | - ref: RollingFile_Appender 35 | level: debug -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/consumer/ElasticSearchConsumerTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.consumer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.consumer.elasticsearch.ElasticSearchConsumer; 5 | import at.grisa.agilemetrics.consumer.elasticsearch.ElasticSearchRestClient; 6 | import at.grisa.agilemetrics.cron.MetricErrorHandler; 7 | import at.grisa.agilemetrics.entity.Metric; 8 | import at.grisa.agilemetrics.util.CredentialManager; 9 | import at.grisa.agilemetrics.util.PropertyManager; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | import org.mockito.ArgumentCaptor; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ActiveProfiles; 15 | import org.springframework.test.context.ContextConfiguration; 16 | import org.springframework.test.context.TestPropertySource; 17 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 18 | 19 | import java.util.Arrays; 20 | import java.util.Collection; 21 | import java.util.HashMap; 22 | import java.util.HashSet; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockito.Mockito.verify; 26 | 27 | @ActiveProfiles("test") 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @ContextConfiguration(classes = {ElasticSearchConsumer.class, CredentialManager.class, PropertyManager.class, MetricErrorHandler.class, ApplicationConfig.class, ElasticSearchRestClientMockConfiguration.class}) 30 | @TestPropertySource("classpath:elasticsearch-test.properties") 31 | public class ElasticSearchConsumerTest { 32 | @Autowired 33 | ElasticSearchRestClient restClient; 34 | @Autowired 35 | ElasticSearchConsumer consumer; 36 | 37 | @Test 38 | public void consumesMetrics() { 39 | HashMap meta = new HashMap<>(); 40 | meta.put("meta", "data"); 41 | 42 | HashSet tags = new HashSet<>(); 43 | tags.add("some"); 44 | tags.add("tags"); 45 | 46 | Metric metric1 = new Metric(1.0, "metric 1", meta, tags); 47 | Metric metric2 = new Metric(19557439.23859, "metric 2", meta, tags); 48 | Metric metric3 = new Metric(495.133, "metric 3", meta, tags); 49 | 50 | consumer.consume(metric1); 51 | consumer.consume(metric2); 52 | consumer.consume(metric3); 53 | 54 | ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Collection.class); 55 | verify(restClient).saveMetrics(argumentCaptor.capture()); 56 | assertEquals("called method on rest client to save metrics", Arrays.asList(metric1, metric2, metric3), argumentCaptor.getValue()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/consumer/ElasticSearchRestClientCheckConnectionTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.consumer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.consumer.elasticsearch.ElasticSearchRestClient; 5 | import at.grisa.agilemetrics.cron.MetricErrorHandler; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import at.grisa.agilemetrics.util.PropertyManager; 8 | import org.junit.Before; 9 | import org.junit.Rule; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | import org.mockserver.client.server.MockServerClient; 13 | import org.mockserver.junit.MockServerRule; 14 | import org.mockserver.model.HttpRequest; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.test.context.ContextConfiguration; 17 | import org.springframework.test.context.TestPropertySource; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | import java.io.IOException; 21 | import java.net.URISyntaxException; 22 | import java.nio.file.Files; 23 | import java.nio.file.Paths; 24 | 25 | import static org.junit.Assert.assertTrue; 26 | import static org.mockserver.model.Header.header; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {ElasticSearchRestClient.class, CredentialManager.class, PropertyManager.class, MetricErrorHandler.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:elasticsearch-test.properties") 32 | public class ElasticSearchRestClientCheckConnectionTest { 33 | @Rule 34 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 35 | private MockServerClient mockServerClient; 36 | private HttpRequest httpRequest; 37 | 38 | @Autowired 39 | private ElasticSearchRestClient restClient; 40 | 41 | @Before 42 | public void mockESServer() throws URISyntaxException, IOException { 43 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("elasticsearch/check-connection.js").toURI()))); 44 | 45 | httpRequest = new HttpRequest(); 46 | httpRequest.withMethod("GET") 47 | .withPath("/"); 48 | 49 | mockServerClient.when(httpRequest) 50 | .respond( 51 | response() 52 | .withStatusCode(200) 53 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 54 | .withBody(responseBody) 55 | ); 56 | } 57 | 58 | @Test 59 | public void checkConnection() { 60 | assertTrue("check connection", restClient.checkConnection()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/consumer/ElasticSearchRestClientMockConfiguration.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.consumer; 2 | 3 | import at.grisa.agilemetrics.consumer.elasticsearch.ElasticSearchRestClient; 4 | import org.mockito.Mockito; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.context.annotation.Primary; 8 | import org.springframework.context.annotation.Profile; 9 | 10 | @Profile("test") 11 | @Configuration 12 | public class ElasticSearchRestClientMockConfiguration { 13 | @Bean 14 | @Primary 15 | public ElasticSearchRestClient restClient() { 16 | return Mockito.mock(ElasticSearchRestClient.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/cron/CronObserverMockConfiguration.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.cron; 2 | 3 | import at.grisa.agilemetrics.persistence.IStatisticRepository; 4 | import org.mockito.Mockito; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.context.annotation.Primary; 8 | import org.springframework.context.annotation.Profile; 9 | 10 | @Profile("test") 11 | @Configuration 12 | public class CronObserverMockConfiguration { 13 | @Bean 14 | @Primary 15 | public MetricQueue metricQueue() { 16 | return Mockito.mock(MetricQueue.class); 17 | } 18 | 19 | @Bean 20 | @Primary 21 | public IStatisticRepository statisticRepository() { 22 | return Mockito.mock(IStatisticRepository.class); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/cron/CronObserverTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.cron; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.consumer.elasticsearch.ElasticSearchConsumer; 5 | import at.grisa.agilemetrics.entity.Metric; 6 | import at.grisa.agilemetrics.producer.bitbucketserver.BitBucketServerProducer; 7 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerProducer; 8 | import at.grisa.agilemetrics.producer.sonarqube.SonarQubeProducer; 9 | import at.grisa.agilemetrics.util.CredentialManager; 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.mockito.invocation.InvocationOnMock; 14 | import org.mockito.stubbing.Answer; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.test.context.ActiveProfiles; 17 | import org.springframework.test.context.ContextConfiguration; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | import static org.mockito.Mockito.*; 21 | 22 | @ActiveProfiles("test") 23 | @RunWith(SpringJUnit4ClassRunner.class) 24 | @ContextConfiguration(classes = {CronObserver.class, CronObserverMockConfiguration.class, ApplicationConfig.class, CredentialManager.class}) 25 | public class CronObserverTest { 26 | @Autowired 27 | private CronObserver cronObserver; 28 | @Autowired 29 | private MetricQueue metricQueue; 30 | 31 | private BitBucketServerProducer bitBucketServerProducer; 32 | private JiraSoftwareServerProducer jiraSoftwareServerProducer; 33 | private SonarQubeProducer sonarQubeProducer; 34 | private ElasticSearchConsumer elasticSearchConsumer; 35 | private final Metric metric = new Metric(1.2, "metric", null); 36 | 37 | @Before 38 | public void createMocks() { 39 | bitBucketServerProducer = mock(BitBucketServerProducer.class); 40 | cronObserver.registerProducer(bitBucketServerProducer); 41 | jiraSoftwareServerProducer = mock(JiraSoftwareServerProducer.class); 42 | cronObserver.registerProducer(jiraSoftwareServerProducer); 43 | sonarQubeProducer = mock(SonarQubeProducer.class); 44 | cronObserver.registerProducer(sonarQubeProducer); 45 | 46 | elasticSearchConsumer = mock(ElasticSearchConsumer.class); 47 | cronObserver.registerConsumer(elasticSearchConsumer); 48 | when(metricQueue.dequeueMetric()).thenAnswer(new Answer() { 49 | private int callCount = 0; 50 | 51 | public Object answer(InvocationOnMock invocation) { 52 | if (callCount++ == 0) { 53 | return metric; 54 | } 55 | return null; 56 | } 57 | }); // return metric on first call only 58 | } 59 | 60 | @Test 61 | public void cronObserverTest() { 62 | cronObserver.activateProducerDaily(); 63 | verify(bitBucketServerProducer).produce(); 64 | verify(jiraSoftwareServerProducer).produce(); 65 | verify(sonarQubeProducer).produce(); 66 | 67 | cronObserver.activateConsumer(); 68 | verify(elasticSearchConsumer).consume(metric); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/entity/MetricTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.entity; 2 | 3 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Board; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Sprint; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import java.util.HashMap; 9 | import java.util.HashSet; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | import static org.junit.Assert.assertTrue; 13 | 14 | public class MetricTest { 15 | private Board board; 16 | private Sprint sprint; 17 | 18 | private final Integer issueVolume = 5; 19 | 20 | @Before 21 | public void createMocks() { 22 | board = new Board(); 23 | board.setName("boardname"); 24 | sprint = new Sprint(); 25 | sprint.setName("sprintname"); 26 | } 27 | 28 | @Test 29 | public void metricEquals() { 30 | HashMap issueVolumeMeta = new HashMap<>(); 31 | issueVolumeMeta.put("sprint", board.getName()); 32 | issueVolumeMeta.put("board", sprint.getName()); 33 | Metric issueVolumeMetric = new Metric(issueVolume.doubleValue(), "Issue Volume", issueVolumeMeta); 34 | 35 | HashMap issueVolumeMeta2 = new HashMap<>(); 36 | issueVolumeMeta2.put("sprint", board.getName()); 37 | issueVolumeMeta2.put("board", sprint.getName()); 38 | Metric issueVolumeMetric2 = new Metric(issueVolume.doubleValue(), "Issue Volume", issueVolumeMeta2); 39 | 40 | assertTrue("equals on metric works fine", issueVolumeMetric.equals(issueVolumeMetric2)); 41 | } 42 | 43 | @Test 44 | public void metricHashCode() { 45 | HashMap issueVolumeMeta = new HashMap<>(); 46 | issueVolumeMeta.put("sprint", board.getName()); 47 | issueVolumeMeta.put("board", sprint.getName()); 48 | HashSet tags = new HashSet<>(); 49 | tags.add("some"); 50 | tags.add("tags"); 51 | Metric issueVolumeMetric = new Metric(issueVolume.doubleValue(), "Issue Volume", issueVolumeMeta, tags); 52 | 53 | HashMap issueVolumeMeta2 = new HashMap<>(); 54 | issueVolumeMeta2.put("sprint", board.getName()); 55 | issueVolumeMeta2.put("board", sprint.getName()); 56 | HashSet tags2 = new HashSet<>(); 57 | tags2.add("some"); 58 | tags2.add("tags"); 59 | Metric issueVolumeMetric2 = new Metric(issueVolume.doubleValue(), "Issue Volume", issueVolumeMeta2, tags2); 60 | 61 | assertEquals("hashcode on metric works fine", issueVolumeMetric.hashCode(), issueVolumeMetric2.hashCode()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/bitbucketserver/producer/BitBucketProducerMockConfiguration.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.producer; 2 | 3 | import at.grisa.agilemetrics.cron.MetricQueue; 4 | import at.grisa.agilemetrics.producer.bitbucketserver.BitBucketServerRestClient; 5 | import org.mockito.Mockito; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.Primary; 9 | import org.springframework.context.annotation.Profile; 10 | 11 | @Profile("test") 12 | @Configuration 13 | public class BitBucketProducerMockConfiguration { 14 | @Bean 15 | @Primary 16 | public BitBucketServerRestClient restClient() { 17 | return Mockito.mock(BitBucketServerRestClient.class); 18 | } 19 | 20 | @Bean 21 | @Primary 22 | public MetricQueue metricQueue() { 23 | return Mockito.mock(MetricQueue.class); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/bitbucketserver/restclient/BitBucketServerRestClientCheckConnectionTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.bitbucketserver.BitBucketServerRestClient; 5 | import at.grisa.agilemetrics.util.CredentialManager; 6 | import org.junit.Before; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.mockserver.client.server.MockServerClient; 11 | import org.mockserver.junit.MockServerRule; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.test.context.ContextConfiguration; 14 | import org.springframework.test.context.TestPropertySource; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | import java.io.IOException; 18 | import java.net.URISyntaxException; 19 | import java.nio.file.Files; 20 | import java.nio.file.Paths; 21 | 22 | import static org.junit.Assert.assertTrue; 23 | import static org.mockserver.model.Header.header; 24 | import static org.mockserver.model.HttpRequest.request; 25 | import static org.mockserver.model.HttpResponse.response; 26 | 27 | @RunWith(SpringJUnit4ClassRunner.class) 28 | @ContextConfiguration(classes = {BitBucketServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 29 | @TestPropertySource("classpath:bitbucket-test.properties") 30 | public class BitBucketServerRestClientCheckConnectionTest { 31 | @Autowired 32 | private BitBucketServerRestClient client; 33 | 34 | @Rule 35 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 36 | private MockServerClient mockServerClient; 37 | 38 | @Before 39 | public void loadPropertiesFromMockServer() throws IOException, URISyntaxException { 40 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("bitbucket/check.js").toURI()))); 41 | 42 | mockServerClient.when( 43 | request() 44 | .withMethod("GET") 45 | .withPath("/rest/api/1.0/application-properties") 46 | ) 47 | .respond( 48 | response() 49 | .withStatusCode(200) 50 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 51 | .withBody(responseBody) 52 | ); 53 | } 54 | 55 | @Test 56 | public void checkConnection() { 57 | assertTrue("check connection", client.checkConnection()); 58 | } 59 | } -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/bitbucketserver/restclient/BitBucketServerRestClientCommitsFromTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.bitbucketserver.BitBucketServerRestClient; 5 | import at.grisa.agilemetrics.producer.bitbucketserver.restentity.Commit; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | import java.util.Date; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockserver.model.Header.header; 27 | import static org.mockserver.model.HttpRequest.request; 28 | import static org.mockserver.model.HttpResponse.response; 29 | 30 | @RunWith(SpringJUnit4ClassRunner.class) 31 | @ContextConfiguration(classes = {BitBucketServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 32 | @TestPropertySource("classpath:bitbucket-test.properties") 33 | public class BitBucketServerRestClientCommitsFromTest { 34 | @Autowired 35 | private BitBucketServerRestClient client; 36 | 37 | @Rule 38 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 39 | private MockServerClient mockServerClient; 40 | private Collection commits; 41 | 42 | @Before 43 | public void loadCommitsFromMockServer() throws URISyntaxException, IOException { 44 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("bitbucket/commits-from.js").toURI()))); 45 | 46 | mockServerClient.when( 47 | request() 48 | .withMethod("GET") 49 | .withPath("/rest/api/1.0/projects/PRJ/repos/FROM/commits") 50 | ) 51 | .respond( 52 | response() 53 | .withStatusCode(200) 54 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 55 | .withBody(responseBody) 56 | ); 57 | 58 | String projectKey = "PRJ"; 59 | String repositorySlug = "FROM"; 60 | Date from = new Date(); 61 | from.setTime(1518587500000L); 62 | commits = client.getCommits(projectKey, repositorySlug, from); 63 | } 64 | 65 | @Test 66 | public void countCommits() { 67 | assertEquals("3 commits from Wed Feb 14 2018 05:51:40", 3, commits.size()); 68 | } 69 | } -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/bitbucketserver/restclient/BitBucketServerRestClientCommitsTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.bitbucketserver.BitBucketServerRestClient; 5 | import at.grisa.agilemetrics.producer.bitbucketserver.restentity.Commit; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockserver.model.Header.header; 26 | import static org.mockserver.model.HttpRequest.request; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {BitBucketServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:bitbucket-test.properties") 32 | public class BitBucketServerRestClientCommitsTest { 33 | @Autowired 34 | private BitBucketServerRestClient client; 35 | 36 | @Rule 37 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 38 | private MockServerClient mockServerClient; 39 | private Collection commits; 40 | 41 | @Before 42 | public void loadCommitsFromMockServer() throws URISyntaxException, IOException { 43 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("bitbucket/commits.js").toURI()))); 44 | 45 | mockServerClient.when( 46 | request() 47 | .withMethod("GET") 48 | .withPath("/rest/api/1.0/projects/PRJ/repos/REPO/commits") 49 | ) 50 | .respond( 51 | response() 52 | .withStatusCode(200) 53 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 54 | .withBody(responseBody) 55 | ); 56 | 57 | String projectKey = "PRJ"; 58 | String repositorySlug = "REPO"; 59 | commits = client.getCommits(projectKey, repositorySlug); 60 | } 61 | 62 | @Test 63 | public void countCommits() { 64 | assertEquals("1 commit in total", 1, commits.size()); 65 | } 66 | 67 | @Test 68 | public void checkData() { 69 | Commit commit = commits.iterator().next(); 70 | assertEquals("check commit id", "def0123abcdef4567abcdef8987abcdef6543abc", commit.getId()); 71 | assertEquals("check commit message", "More work on feature 1", commit.getMessage()); 72 | } 73 | } -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/bitbucketserver/restclient/BitBucketServerRestClientPagedEntitiesTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.bitbucketserver.BitBucketServerRestClient; 5 | import at.grisa.agilemetrics.producer.bitbucketserver.restentity.Repository; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockserver.model.Header.header; 26 | import static org.mockserver.model.HttpRequest.request; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {BitBucketServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:bitbucket-test.properties") 32 | public class BitBucketServerRestClientPagedEntitiesTest { 33 | @Autowired 34 | private BitBucketServerRestClient client; 35 | 36 | @Rule 37 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 38 | private MockServerClient mockServerClient; 39 | private Collection repositories; 40 | 41 | @Before 42 | public void loadReposFromMockServer() throws URISyntaxException, IOException { 43 | String responseBodyPage1 = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("bitbucket/paged-entities-1.js").toURI()))); 44 | String responseBodyPage2 = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("bitbucket/paged-entities-2.js").toURI()))); 45 | 46 | mockServerClient.when( 47 | request() 48 | .withMethod("GET") 49 | .withPath("/rest/api/1.0/projects/PAGED/repos") 50 | .withQueryStringParameter("start", "0") 51 | ) 52 | .respond( 53 | response() 54 | .withStatusCode(200) 55 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 56 | .withBody(responseBodyPage1) 57 | ); 58 | 59 | mockServerClient.when( 60 | request() 61 | .withMethod("GET") 62 | .withPath("/rest/api/1.0/projects/PAGED/repos") 63 | .withQueryStringParameter("start", "3") 64 | ) 65 | .respond( 66 | response() 67 | .withStatusCode(200) 68 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 69 | .withBody(responseBodyPage2) 70 | ); 71 | 72 | String projectKey = "PAGED"; 73 | repositories = client.getRepositories(projectKey); 74 | } 75 | 76 | @Test 77 | public void countRepos() { 78 | assertEquals("5 values in total", 5, repositories.size()); 79 | } 80 | 81 | } -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/bitbucketserver/restclient/BitBucketServerRestClientProjectsTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.bitbucketserver.BitBucketServerRestClient; 5 | import at.grisa.agilemetrics.producer.bitbucketserver.restentity.Project; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockserver.model.Header.header; 26 | import static org.mockserver.model.HttpRequest.request; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {BitBucketServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:bitbucket-test.properties") 32 | public class BitBucketServerRestClientProjectsTest { 33 | @Autowired 34 | private BitBucketServerRestClient client; 35 | 36 | @Rule 37 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 38 | private MockServerClient mockServerClient; 39 | private Collection projects; 40 | 41 | @Before 42 | public void loadProjectsFromMockServer() throws IOException, URISyntaxException { 43 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("bitbucket/projects.js").toURI()))); 44 | 45 | mockServerClient.when( 46 | request() 47 | .withMethod("GET") 48 | .withPath("/rest/api/1.0/projects") 49 | ) 50 | .respond( 51 | response() 52 | .withStatusCode(200) 53 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 54 | .withBody(responseBody) 55 | ); 56 | 57 | projects = client.getProjects(); 58 | } 59 | 60 | @Test 61 | public void countRepos() { 62 | assertEquals("1 project in total", 1, projects.size()); 63 | } 64 | 65 | @Test 66 | public void checkData() { 67 | Project project = projects.iterator().next(); 68 | assertEquals("check project id", new Long(1), project.getId()); 69 | assertEquals("check project key", "PRJ", project.getKey()); 70 | assertEquals("check project name", "My Cool Project", project.getName()); 71 | } 72 | } -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/bitbucketserver/restclient/BitBucketServerRestClientRepositoriesTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.bitbucketserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.bitbucketserver.BitBucketServerRestClient; 5 | import at.grisa.agilemetrics.producer.bitbucketserver.restentity.Repository; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockserver.model.Header.header; 26 | import static org.mockserver.model.HttpRequest.request; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {BitBucketServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:bitbucket-test.properties") 32 | public class BitBucketServerRestClientRepositoriesTest { 33 | @Autowired 34 | private BitBucketServerRestClient client; 35 | 36 | @Rule 37 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 38 | private MockServerClient mockServerClient; 39 | private Collection repositories; 40 | 41 | @Before 42 | public void loadReposFromMockServer() throws URISyntaxException, IOException { 43 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("bitbucket/repos.js").toURI()))); 44 | 45 | mockServerClient.when( 46 | request() 47 | .withMethod("GET") 48 | .withPath("/rest/api/1.0/projects/PRJ/repos") 49 | ) 50 | .respond( 51 | response() 52 | .withStatusCode(200) 53 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 54 | .withBody(responseBody) 55 | ); 56 | 57 | String projectKey = "PRJ"; 58 | repositories = client.getRepositories(projectKey); 59 | } 60 | 61 | @Test 62 | public void countRepos() { 63 | assertEquals("1 repo in total", 1, repositories.size()); 64 | } 65 | 66 | @Test 67 | public void checkData() { 68 | Repository repository = repositories.iterator().next(); 69 | assertEquals("check repository id", new Long(1), repository.getId()); 70 | assertEquals("check repository slug", "my-repo", repository.getSlug()); 71 | assertEquals("check repository name", "My repo", repository.getName()); 72 | } 73 | } -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/producer/JiraSoftwareServerProducerAcceptanceCriteriaVolatilityNoPropertiesTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.producer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.cron.MetricQueue; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerProducer; 6 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 7 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Board; 8 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Issue; 9 | import at.grisa.agilemetrics.util.CredentialManager; 10 | import at.grisa.agilemetrics.util.PropertyManager; 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.test.context.ActiveProfiles; 16 | import org.springframework.test.context.ContextConfiguration; 17 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 18 | 19 | import java.util.Arrays; 20 | 21 | import static org.mockito.Mockito.when; 22 | 23 | @ActiveProfiles("test") 24 | @RunWith(SpringJUnit4ClassRunner.class) 25 | @ContextConfiguration(classes = {JiraSoftwareServerProducer.class, CredentialManager.class, PropertyManager.class, JiraSoftwareServerProducerMockConfiguration.class, ApplicationConfig.class}) 26 | public class JiraSoftwareServerProducerAcceptanceCriteriaVolatilityNoPropertiesTest { 27 | @Autowired 28 | private JiraSoftwareServerRestClient jiraSoftwareServerRestClient; 29 | @Autowired 30 | private JiraSoftwareServerProducer jiraSoftwareServerProducer; 31 | @Autowired 32 | private MetricQueue metricQueue; 33 | 34 | private Board board; 35 | private Issue issue1; 36 | private Issue issue2; 37 | 38 | private final Long boardId = 123L; 39 | private final String boardJql = "boardJQL ORDER BY boing"; 40 | 41 | @Before 42 | public void createMocks() { 43 | board = new Board(); 44 | board.setId(boardId); 45 | board.setName("boardname"); 46 | 47 | issue1 = new Issue(); 48 | issue1.setKey("issue1"); 49 | 50 | issue2 = new Issue(); 51 | issue2.setKey("issue2"); 52 | 53 | when(jiraSoftwareServerRestClient.getScrumBoards()).thenReturn(Arrays.asList(board)); 54 | when(jiraSoftwareServerRestClient.getScrumBoardJQLFilter(boardId)).thenReturn(boardJql); 55 | when(jiraSoftwareServerRestClient.getIssuesByJQL("resolutiondate > -1d AND (boardjql) order by boing")).thenReturn(Arrays.asList(issue1, issue2)); 56 | } 57 | 58 | @Test(expected = IllegalStateException.class) 59 | public void produceAcceptanceCriteriaVolatility() { 60 | jiraSoftwareServerProducer.produceAcceptanceCriteriaVolatility(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/producer/JiraSoftwareServerProducerBugCountTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.producer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.cron.MetricQueue; 5 | import at.grisa.agilemetrics.entity.Metric; 6 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerProducer; 7 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 8 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Board; 9 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Issue; 10 | import at.grisa.agilemetrics.util.CredentialManager; 11 | import at.grisa.agilemetrics.util.PropertyManager; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.test.context.ActiveProfiles; 17 | import org.springframework.test.context.ContextConfiguration; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | import java.util.Arrays; 21 | import java.util.HashMap; 22 | 23 | import static org.mockito.Mockito.verify; 24 | import static org.mockito.Mockito.when; 25 | 26 | @ActiveProfiles("test") 27 | @RunWith(SpringJUnit4ClassRunner.class) 28 | @ContextConfiguration(classes = {JiraSoftwareServerProducer.class, CredentialManager.class, PropertyManager.class, JiraSoftwareServerProducerMockConfiguration.class, ApplicationConfig.class}) 29 | public class JiraSoftwareServerProducerBugCountTest { 30 | @Autowired 31 | private JiraSoftwareServerRestClient jiraSoftwareServerRestClient; 32 | @Autowired 33 | private JiraSoftwareServerProducer jiraSoftwareServerProducer; 34 | @Autowired 35 | private MetricQueue metricQueue; 36 | 37 | private Board board; 38 | private Issue issue1; 39 | private Issue issue2; 40 | 41 | private final Long boardId = 123L; 42 | private final String boardJql = "boardJQL ORDER BY boing"; 43 | 44 | @Before 45 | public void createMocks() { 46 | board = new Board(); 47 | board.setId(boardId); 48 | board.setName("boardname"); 49 | 50 | issue1 = new Issue(); 51 | issue1.setKey("issue1"); 52 | 53 | issue2 = new Issue(); 54 | issue2.setKey("issue2"); 55 | 56 | when(jiraSoftwareServerRestClient.getScrumBoards()).thenReturn(Arrays.asList(board)); 57 | when(jiraSoftwareServerRestClient.getScrumBoardJQLFilter(boardId)).thenReturn(boardJql); 58 | when(jiraSoftwareServerRestClient.getIssuesByJQL("type = Bug AND statusCategory != Done AND (boardjql) order by boing")).thenReturn(Arrays.asList(issue1, issue2)); 59 | } 60 | 61 | @Test 62 | public void produceBugCountTest() { 63 | jiraSoftwareServerProducer.produceBugCount(); 64 | 65 | HashMap meta = new HashMap<>(); 66 | meta.put("board", board.getName()); 67 | Metric bugRate = new Metric(2.0, "Bug Count", meta); 68 | 69 | verify(metricQueue).enqueueMetric(bugRate); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/producer/JiraSoftwareServerProducerBugRateTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.producer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.cron.MetricQueue; 5 | import at.grisa.agilemetrics.entity.Metric; 6 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerProducer; 7 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 8 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Board; 9 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Issue; 10 | import at.grisa.agilemetrics.util.CredentialManager; 11 | import at.grisa.agilemetrics.util.PropertyManager; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.test.context.ActiveProfiles; 17 | import org.springframework.test.context.ContextConfiguration; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | import java.util.Arrays; 21 | import java.util.HashMap; 22 | 23 | import static org.mockito.Mockito.verify; 24 | import static org.mockito.Mockito.when; 25 | 26 | @ActiveProfiles("test") 27 | @RunWith(SpringJUnit4ClassRunner.class) 28 | @ContextConfiguration(classes = {JiraSoftwareServerProducer.class, CredentialManager.class, PropertyManager.class, JiraSoftwareServerProducerMockConfiguration.class, ApplicationConfig.class}) 29 | public class JiraSoftwareServerProducerBugRateTest { 30 | @Autowired 31 | private JiraSoftwareServerRestClient jiraSoftwareServerRestClient; 32 | @Autowired 33 | private JiraSoftwareServerProducer jiraSoftwareServerProducer; 34 | @Autowired 35 | private MetricQueue metricQueue; 36 | 37 | private Board board; 38 | private Issue issue1; 39 | private Issue issue2; 40 | 41 | private final Long boardId = 123L; 42 | private final String boardJql = "boardJQL ORDER BY boing"; 43 | 44 | @Before 45 | public void createMocks() { 46 | board = new Board(); 47 | board.setId(boardId); 48 | board.setName("boardname"); 49 | 50 | issue1 = new Issue(); 51 | issue1.setKey("issue1"); 52 | 53 | issue2 = new Issue(); 54 | issue2.setKey("issue2"); 55 | 56 | when(jiraSoftwareServerRestClient.getScrumBoards()).thenReturn(Arrays.asList(board)); 57 | when(jiraSoftwareServerRestClient.getScrumBoardJQLFilter(boardId)).thenReturn(boardJql); 58 | when(jiraSoftwareServerRestClient.getIssuesByJQL("created > -1d AND type = Bug AND (boardjql) order by boing")).thenReturn(Arrays.asList(issue1, issue2)); 59 | } 60 | 61 | @Test 62 | public void produceBugRateTest() { 63 | jiraSoftwareServerProducer.produceBugRate(); 64 | 65 | HashMap meta = new HashMap<>(); 66 | meta.put("board", board.getName()); 67 | Metric bugRate = new Metric(2.0, "Bug Rate", meta); 68 | 69 | verify(metricQueue).enqueueMetric(bugRate); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/producer/JiraSoftwareServerProducerIssueLabelsTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.producer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.cron.MetricQueue; 5 | import at.grisa.agilemetrics.entity.Metric; 6 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerProducer; 7 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 8 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Board; 9 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Fields; 10 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Issue; 11 | import at.grisa.agilemetrics.util.CredentialManager; 12 | import at.grisa.agilemetrics.util.PropertyManager; 13 | import org.junit.Before; 14 | import org.junit.Test; 15 | import org.junit.runner.RunWith; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.test.context.ActiveProfiles; 18 | import org.springframework.test.context.ContextConfiguration; 19 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 20 | 21 | import java.util.Arrays; 22 | import java.util.HashMap; 23 | import java.util.HashSet; 24 | 25 | import static org.mockito.Mockito.verify; 26 | import static org.mockito.Mockito.when; 27 | 28 | @ActiveProfiles("test") 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {JiraSoftwareServerProducer.class, CredentialManager.class, PropertyManager.class, JiraSoftwareServerProducerMockConfiguration.class, ApplicationConfig.class}) 31 | public class JiraSoftwareServerProducerIssueLabelsTest { 32 | @Autowired 33 | private JiraSoftwareServerRestClient jiraSoftwareServerRestClient; 34 | @Autowired 35 | private JiraSoftwareServerProducer jiraSoftwareServerProducer; 36 | @Autowired 37 | private MetricQueue metricQueue; 38 | 39 | private Board board; 40 | private Issue issue1; 41 | 42 | private final Long boardId = 123L; 43 | private final String boardJql = "boardJQL ORDER BY boing"; 44 | private final String[] labels = new String[]{"one", "two", "three", "äáß123 what a #label"}; 45 | 46 | @Before 47 | public void createMocks() { 48 | board = new Board(); 49 | board.setId(boardId); 50 | board.setName("boardname"); 51 | 52 | Fields fields = new Fields(); 53 | fields.setLabels(labels); 54 | 55 | issue1 = new Issue(); 56 | issue1.setKey("issue1"); 57 | issue1.setFields(fields); 58 | 59 | when(jiraSoftwareServerRestClient.getScrumBoards()).thenReturn(Arrays.asList(board)); 60 | when(jiraSoftwareServerRestClient.getScrumBoardJQLFilter(boardId)).thenReturn(boardJql); 61 | when(jiraSoftwareServerRestClient.getIssuesByJQL("resolutiondate > -1d AND (boardjql) order by boing")).thenReturn(Arrays.asList(issue1)); 62 | } 63 | 64 | @Test 65 | public void produceIssueLabelsTest() { 66 | jiraSoftwareServerProducer.produceIssueLabels(); 67 | 68 | HashMap meta = new HashMap<>(); 69 | meta.put("issue", issue1.getKey()); 70 | meta.put("board", board.getName()); 71 | Metric issueLabels = new Metric(4.0, "Issue Labels", meta, new HashSet<>(Arrays.asList(labels))); 72 | 73 | verify(metricQueue).enqueueMetric(issueLabels); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/producer/JiraSoftwareServerProducerIssueVolumeTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.producer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.cron.MetricQueue; 5 | import at.grisa.agilemetrics.entity.Metric; 6 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerProducer; 7 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 8 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Board; 9 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Sprint; 10 | import at.grisa.agilemetrics.util.CredentialManager; 11 | import at.grisa.agilemetrics.util.PropertyManager; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.test.context.ActiveProfiles; 17 | import org.springframework.test.context.ContextConfiguration; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | import java.util.Arrays; 21 | import java.util.HashMap; 22 | 23 | import static org.mockito.Mockito.verify; 24 | import static org.mockito.Mockito.when; 25 | 26 | @ActiveProfiles("test") 27 | @RunWith(SpringJUnit4ClassRunner.class) 28 | @ContextConfiguration(classes = {JiraSoftwareServerProducer.class, CredentialManager.class, PropertyManager.class, JiraSoftwareServerProducerMockConfiguration.class, ApplicationConfig.class}) 29 | public class JiraSoftwareServerProducerIssueVolumeTest { 30 | @Autowired 31 | private JiraSoftwareServerRestClient jiraSoftwareServerRestClient; 32 | @Autowired 33 | private JiraSoftwareServerProducer jiraSoftwareServerProducer; 34 | @Autowired 35 | private MetricQueue metricQueue; 36 | 37 | private Board board; 38 | private Sprint sprint; 39 | 40 | private final Long boardId = 123L; 41 | private final Long sprintId = 456L; 42 | private final Integer issueVolume = 5; 43 | 44 | @Before 45 | public void createMocks() { 46 | board = new Board(); 47 | board.setId(boardId); 48 | board.setName("boardname"); 49 | sprint = new Sprint(); 50 | sprint.setId(sprintId); 51 | sprint.setName("sprintname"); 52 | 53 | when(jiraSoftwareServerRestClient.getScrumBoards()).thenReturn(Arrays.asList(board)); 54 | when(jiraSoftwareServerRestClient.getActiveSprint(board.getId())).thenReturn(sprint); 55 | when(jiraSoftwareServerRestClient.getSprintIssuesCount(boardId, sprintId)).thenReturn(issueVolume); 56 | } 57 | 58 | @Test 59 | public void produceIssueVolumeTest() { 60 | jiraSoftwareServerProducer.produceIssueVolume(); 61 | 62 | HashMap issueVolumeMeta = new HashMap<>(); 63 | issueVolumeMeta.put("sprint", sprint.getName()); 64 | issueVolumeMeta.put("board", board.getName()); 65 | Metric issueVolumeMetric = new Metric(issueVolume.doubleValue(), "Issue Volume", issueVolumeMeta); 66 | 67 | verify(metricQueue).enqueueMetric(issueVolumeMetric); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/producer/JiraSoftwareServerProducerMockConfiguration.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.producer; 2 | 3 | import at.grisa.agilemetrics.cron.MetricQueue; 4 | import at.grisa.agilemetrics.persistence.IVelocityRepository; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 6 | import org.mockito.Mockito; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Primary; 10 | import org.springframework.context.annotation.Profile; 11 | 12 | @Profile("test") 13 | @Configuration 14 | public class JiraSoftwareServerProducerMockConfiguration { 15 | @Bean 16 | @Primary 17 | public JiraSoftwareServerRestClient restClient() { 18 | return Mockito.mock(JiraSoftwareServerRestClient.class); 19 | } 20 | 21 | @Bean 22 | @Primary 23 | public MetricQueue metricQueue() { 24 | return Mockito.mock(MetricQueue.class); 25 | } 26 | 27 | @Bean 28 | @Primary 29 | public IVelocityRepository velocityRepository() { 30 | return Mockito.mock(IVelocityRepository.class); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/producer/JiraSoftwareServerProducerRecidivismNoPropertiesTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.producer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.cron.MetricQueue; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerProducer; 6 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 7 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Board; 8 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Issue; 9 | import at.grisa.agilemetrics.util.CredentialManager; 10 | import at.grisa.agilemetrics.util.PropertyManager; 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.test.context.ActiveProfiles; 16 | import org.springframework.test.context.ContextConfiguration; 17 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 18 | 19 | import java.util.Arrays; 20 | 21 | import static org.mockito.Mockito.when; 22 | 23 | @ActiveProfiles("test") 24 | @RunWith(SpringJUnit4ClassRunner.class) 25 | @ContextConfiguration(classes = {JiraSoftwareServerProducer.class, CredentialManager.class, PropertyManager.class, JiraSoftwareServerProducerMockConfiguration.class, ApplicationConfig.class}) 26 | public class JiraSoftwareServerProducerRecidivismNoPropertiesTest { 27 | @Autowired 28 | private JiraSoftwareServerRestClient jiraSoftwareServerRestClient; 29 | @Autowired 30 | private JiraSoftwareServerProducer jiraSoftwareServerProducer; 31 | @Autowired 32 | private MetricQueue metricQueue; 33 | 34 | private Board board; 35 | private Issue issue1; 36 | private Issue issue2; 37 | 38 | private final Long boardId = 123L; 39 | private final String boardJql = "boardJQL ORDER BY boing"; 40 | 41 | @Before 42 | public void createMocks() { 43 | board = new Board(); 44 | board.setId(boardId); 45 | board.setName("boardname"); 46 | 47 | issue1 = new Issue(); 48 | issue1.setKey("issue1"); 49 | 50 | issue2 = new Issue(); 51 | issue2.setKey("issue2"); 52 | 53 | when(jiraSoftwareServerRestClient.getScrumBoards()).thenReturn(Arrays.asList(board)); 54 | when(jiraSoftwareServerRestClient.getScrumBoardJQLFilter(boardId)).thenReturn(boardJql); 55 | when(jiraSoftwareServerRestClient.getIssuesByJQL("resolutiondate > -1d AND (boardjql) order by boing")).thenReturn(Arrays.asList(issue1, issue2)); 56 | } 57 | 58 | @Test(expected = IllegalStateException.class) 59 | public void produceRecidivismTest() { 60 | jiraSoftwareServerProducer.produceRecidivism(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientActiveSprintGreenhopperTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.greenhopper.Sprint; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | import static org.mockserver.model.Header.header; 25 | import static org.mockserver.model.HttpRequest.request; 26 | import static org.mockserver.model.HttpResponse.response; 27 | 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 30 | @TestPropertySource("classpath:jira-test.properties") 31 | public class JiraSoftwareServerRestClientActiveSprintGreenhopperTest { 32 | @Autowired 33 | private JiraSoftwareServerRestClient client; 34 | 35 | @Rule 36 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 37 | private MockServerClient mockServerClient; 38 | private Sprint sprint; 39 | private final long sprintId = 1234L; 40 | 41 | @Before 42 | public void loadIssuesFromMockServer() throws URISyntaxException, IOException { 43 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/sprintsGreenhopper.js").toURI()))); 44 | 45 | mockServerClient.when( 46 | request() 47 | .withMethod("GET") 48 | .withPath("/rest/greenhopper/1.0/sprintquery/" + sprintId) 49 | ) 50 | .respond( 51 | response() 52 | .withStatusCode(200) 53 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 54 | .withBody(responseBody) 55 | ); 56 | } 57 | 58 | @Test 59 | public void checkRestClient() { 60 | sprint = client.getActiveSprintGreenhopper(sprintId); 61 | 62 | assertEquals("check rapidview id", new Long(4), sprint.getId()); 63 | assertEquals("check rapidview name", "Sprint 4", sprint.getName()); 64 | assertEquals("check rapidview sprint support", "ACTIVE", sprint.getState()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientActiveSprintTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Sprint; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | import static org.mockserver.model.Header.header; 25 | import static org.mockserver.model.HttpRequest.request; 26 | import static org.mockserver.model.HttpResponse.response; 27 | 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 30 | @TestPropertySource("classpath:jira-test.properties") 31 | public class JiraSoftwareServerRestClientActiveSprintTest { 32 | @Autowired 33 | private JiraSoftwareServerRestClient client; 34 | 35 | @Rule 36 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 37 | private MockServerClient mockServerClient; 38 | private Sprint sprint; 39 | 40 | @Before 41 | public void loadSprintFromMockServer() throws URISyntaxException, IOException { 42 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/sprints.js").toURI()))); 43 | 44 | Long boardId = 1234L; 45 | mockServerClient.when( 46 | request() 47 | .withMethod("GET") 48 | .withPath("/rest/agile/1.0/board/" + boardId + "/sprint") 49 | ) 50 | .respond( 51 | response() 52 | .withStatusCode(200) 53 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 54 | .withBody(responseBody) 55 | ); 56 | 57 | sprint = client.getActiveSprint(boardId); 58 | } 59 | 60 | @Test 61 | public void checkData() { 62 | assertEquals("check sprint id", new Long(58), sprint.getId()); 63 | assertEquals("check sprint name", "sprint 2", sprint.getName()); 64 | assertEquals("check sprint type", "active", sprint.getState()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientCheckConnectionTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.util.CredentialManager; 6 | import org.junit.Before; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.mockserver.client.server.MockServerClient; 11 | import org.mockserver.junit.MockServerRule; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.test.context.ContextConfiguration; 14 | import org.springframework.test.context.TestPropertySource; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | import java.io.IOException; 18 | import java.net.URISyntaxException; 19 | import java.nio.file.Files; 20 | import java.nio.file.Paths; 21 | 22 | import static org.junit.Assert.assertTrue; 23 | import static org.mockserver.model.Header.header; 24 | import static org.mockserver.model.HttpRequest.request; 25 | import static org.mockserver.model.HttpResponse.response; 26 | 27 | @RunWith(SpringJUnit4ClassRunner.class) 28 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 29 | @TestPropertySource("classpath:jira-test.properties") 30 | public class JiraSoftwareServerRestClientCheckConnectionTest { 31 | @Autowired 32 | private JiraSoftwareServerRestClient client; 33 | 34 | @Rule 35 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 36 | private MockServerClient mockServerClient; 37 | 38 | @Before 39 | public void loadServerInfoFromMockServer() throws URISyntaxException, IOException { 40 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/check.js").toURI()))); 41 | 42 | mockServerClient.when( 43 | request() 44 | .withMethod("GET") 45 | .withPath("/rest/api/2/serverInfo") 46 | ) 47 | .respond( 48 | response() 49 | .withStatusCode(200) 50 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 51 | .withBody(responseBody) 52 | ); 53 | } 54 | 55 | @Test 56 | public void checkConnection() { 57 | assertTrue("check connection", client.checkConnection()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientIssuesChangelogTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.atlassian.rest.entities.QueryParam; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 6 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.History; 7 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.HistoryItem; 8 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Issue; 9 | import at.grisa.agilemetrics.util.CredentialManager; 10 | import org.junit.Before; 11 | import org.junit.Rule; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.mockserver.client.server.MockServerClient; 15 | import org.mockserver.junit.MockServerRule; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.test.context.ContextConfiguration; 18 | import org.springframework.test.context.TestPropertySource; 19 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 20 | 21 | import java.io.IOException; 22 | import java.net.URISyntaxException; 23 | import java.nio.file.Files; 24 | import java.nio.file.Paths; 25 | import java.time.OffsetDateTime; 26 | import java.time.ZoneId; 27 | import java.time.format.DateTimeFormatter; 28 | 29 | import static org.junit.Assert.assertEquals; 30 | import static org.junit.Assert.assertNotNull; 31 | import static org.mockserver.model.Header.header; 32 | import static org.mockserver.model.HttpRequest.request; 33 | import static org.mockserver.model.HttpResponse.response; 34 | 35 | @RunWith(SpringJUnit4ClassRunner.class) 36 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 37 | @TestPropertySource("classpath:jira-test.properties") 38 | public class JiraSoftwareServerRestClientIssuesChangelogTest { 39 | @Autowired 40 | private JiraSoftwareServerRestClient client; 41 | 42 | @Rule 43 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 44 | private MockServerClient mockServerClient; 45 | private Issue issue; 46 | 47 | @Before 48 | public void loadIssueFromMockServer() throws URISyntaxException, IOException { 49 | Long issueId = 1234L; 50 | String issueChangelogResponse = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/issueChangelog.js").toURI()))); 51 | 52 | mockServerClient.when( 53 | request() 54 | .withMethod("GET") 55 | .withPath("/rest/api/2/issue/" + issueId) 56 | .withQueryStringParameter("expand", "changelog") 57 | ) 58 | .respond( 59 | response() 60 | .withStatusCode(200) 61 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 62 | .withBody(issueChangelogResponse) 63 | ); 64 | 65 | issue = client.getIssue(issueId, new QueryParam("expand", "changelog")); 66 | } 67 | 68 | @Test 69 | public void checkData() { 70 | assertNotNull("check changelog not null", issue.getChangelog()); 71 | assertEquals("check changelog histories count", 5, issue.getChangelog().getHistories().length); 72 | 73 | History history = issue.getChangelog().getHistories()[0]; 74 | assertEquals("check issue created date", OffsetDateTime.parse("2017-05-18T20:49:58.000+0200", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX")).toInstant().atZone(ZoneId.of("UTC")), history.getCreated()); 75 | 76 | HistoryItem historyItem = history.getItems()[0]; 77 | assertEquals("check issue changelog history item field", "status", historyItem.getField()); 78 | assertEquals("check issue changelog history item from string", "New", historyItem.getFromString()); 79 | assertEquals("check issue changelog history item to string", "in Progress", historyItem.getToString()); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientJQLIssuesLabelsTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Issue; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockserver.model.Header.header; 26 | import static org.mockserver.model.HttpRequest.request; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:jira-test.properties") 32 | public class JiraSoftwareServerRestClientJQLIssuesLabelsTest { 33 | @Autowired 34 | private JiraSoftwareServerRestClient client; 35 | 36 | @Rule 37 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 38 | private MockServerClient mockServerClient; 39 | private Collection issues; 40 | 41 | @Before 42 | public void loadIssueLabelsFromMockServer() throws URISyntaxException, IOException { 43 | String jql = "project = team1 ORDER BY create ASC"; 44 | String issueLabelsResponse = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/issueLabels.js").toURI()))); 45 | 46 | mockServerClient.when( 47 | request() 48 | .withMethod("GET") 49 | .withPath("/rest/api/2/search") 50 | .withQueryStringParameter("jql", "project = team1 ORDER BY create ASC") 51 | ) 52 | .respond( 53 | response() 54 | .withStatusCode(200) 55 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 56 | .withBody(issueLabelsResponse) 57 | ); 58 | 59 | issues = client.getIssuesByJQL(jql); 60 | } 61 | 62 | @Test 63 | public void countIssues() { 64 | assertEquals("1 issue in total", 1, issues.size()); 65 | } 66 | 67 | @Test 68 | public void checkData() { 69 | Issue issue = issues.iterator().next(); 70 | assertEquals("check issue id", new Long(1), issue.getId()); 71 | assertEquals("check issue key", "ISSUE-1", issue.getKey()); 72 | assertEquals("check issue labels size", 3, issue.getFields().getLabels().length); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientRapidViewsGreenhopperTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.greenhopper.RapidView; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockserver.model.Header.header; 26 | import static org.mockserver.model.HttpRequest.request; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:jira-test.properties") 32 | public class JiraSoftwareServerRestClientRapidViewsGreenhopperTest { 33 | @Autowired 34 | private JiraSoftwareServerRestClient client; 35 | 36 | @Rule 37 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 38 | private MockServerClient mockServerClient; 39 | private Collection rapidViews; 40 | 41 | @Before 42 | public void loadIssuesFromMockServer() throws URISyntaxException, IOException { 43 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/rapidviewsGreenhopper.js").toURI()))); 44 | 45 | mockServerClient.when( 46 | request() 47 | .withMethod("GET") 48 | .withPath("/rest/greenhopper/1.0/rapidview") 49 | ) 50 | .respond( 51 | response() 52 | .withStatusCode(200) 53 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 54 | .withBody(responseBody) 55 | ); 56 | 57 | rapidViews = client.getRapidViewsGreenhopper(); 58 | } 59 | 60 | @Test 61 | public void countIssues() { 62 | assertEquals("3 rapidviews in total", 3, rapidViews.size()); 63 | } 64 | 65 | @Test 66 | public void checkData() { 67 | RapidView rapidView = rapidViews.iterator().next(); 68 | assertEquals("check rapidview id", new Long(2), rapidView.getId()); 69 | assertEquals("check rapidview name", "RapidView 2", rapidView.getName()); 70 | assertEquals("check rapidview sprint support", true, rapidView.getSprintSupportEnabled()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientScrumBoardsTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Board; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockserver.model.Header.header; 26 | import static org.mockserver.model.HttpRequest.request; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:jira-test.properties") 32 | public class JiraSoftwareServerRestClientScrumBoardsTest { 33 | @Autowired 34 | private JiraSoftwareServerRestClient client; 35 | 36 | @Rule 37 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 38 | private MockServerClient mockServerClient; 39 | private Collection boards; 40 | 41 | @Before 42 | public void loadBoardsFromMockServer() throws URISyntaxException, IOException { 43 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/boards.js").toURI()))); 44 | 45 | mockServerClient.when( 46 | request() 47 | .withMethod("GET") 48 | .withPath("/rest/agile/1.0/board") 49 | ) 50 | .respond( 51 | response() 52 | .withStatusCode(200) 53 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 54 | .withBody(responseBody) 55 | ); 56 | 57 | boards = client.getScrumBoards(); 58 | } 59 | 60 | @Test 61 | public void countBoards() { 62 | assertEquals("2 boards in total", 2, boards.size()); 63 | } 64 | 65 | @Test 66 | public void checkData() { 67 | Board board = boards.iterator().next(); 68 | assertEquals("check board id", new Long(84), board.getId()); 69 | assertEquals("check board name", "scrum board", board.getName()); 70 | assertEquals("check board type", "scrum", board.getType()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientSprintIssueCountTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.util.CredentialManager; 6 | import org.junit.Before; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.mockserver.client.server.MockServerClient; 11 | import org.mockserver.junit.MockServerRule; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.test.context.ContextConfiguration; 14 | import org.springframework.test.context.TestPropertySource; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | import java.io.IOException; 18 | import java.net.URISyntaxException; 19 | import java.nio.file.Files; 20 | import java.nio.file.Paths; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | import static org.mockserver.model.Header.header; 24 | import static org.mockserver.model.HttpRequest.request; 25 | import static org.mockserver.model.HttpResponse.response; 26 | 27 | @RunWith(SpringJUnit4ClassRunner.class) 28 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 29 | @TestPropertySource("classpath:jira-test.properties") 30 | public class JiraSoftwareServerRestClientSprintIssueCountTest { 31 | @Autowired 32 | private JiraSoftwareServerRestClient client; 33 | 34 | @Rule 35 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 36 | private MockServerClient mockServerClient; 37 | private Integer issueCount; 38 | 39 | @Before 40 | public void loadIssueCountFromMockServer() throws URISyntaxException, IOException { 41 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/issues.js").toURI()))); 42 | 43 | Long boardId = 1234L; 44 | Long sprintId = 5678L; 45 | mockServerClient.when( 46 | request() 47 | .withMethod("GET") 48 | .withPath("/rest/agile/1.0/board/" + boardId + "/sprint/" + sprintId + "/issue") 49 | ) 50 | .respond( 51 | response() 52 | .withStatusCode(200) 53 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 54 | .withBody(responseBody) 55 | ); 56 | 57 | issueCount = client.getSprintIssuesCount(boardId, sprintId); 58 | } 59 | 60 | @Test 61 | public void checkData() { 62 | assertEquals("check sprint issue count", new Integer(2), issueCount); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientSprintIssuesStatusTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Issue; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockserver.model.Header.header; 26 | import static org.mockserver.model.HttpRequest.request; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:jira-test.properties") 32 | public class JiraSoftwareServerRestClientSprintIssuesStatusTest { 33 | @Autowired 34 | private JiraSoftwareServerRestClient client; 35 | 36 | @Rule 37 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 38 | private MockServerClient mockServerClient; 39 | private Collection issues; 40 | 41 | @Before 42 | public void loadIssuesStatusFromMockServer() throws URISyntaxException, IOException { 43 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/issuesStatus.js").toURI()))); 44 | 45 | Long boardId = 1234L; 46 | Long sprintId = 5678L; 47 | mockServerClient.when( 48 | request() 49 | .withMethod("GET") 50 | .withPath("/rest/agile/1.0/board/" + boardId + "/sprint/" + sprintId + "/issue") 51 | .withQueryStringParameter("fields", "status") 52 | ) 53 | .respond( 54 | response() 55 | .withStatusCode(200) 56 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 57 | .withBody(responseBody) 58 | ); 59 | 60 | issues = client.getSprintIssuesStatus(boardId, sprintId); 61 | } 62 | 63 | @Test 64 | public void countIssues() { 65 | assertEquals("10 issues in total", 10, issues.size()); 66 | } 67 | 68 | @Test 69 | public void checkData() { 70 | Issue issue = issues.iterator().next(); 71 | assertEquals("check issue id", new Long(10001), issue.getId()); 72 | assertEquals("check issue key", "ISSUE-1", issue.getKey()); 73 | assertEquals("check issue status name", "Released", issue.getFields().getStatus().getName()); 74 | assertEquals("check issue status category name", "Done", issue.getFields().getStatus().getStatusCategory().getName()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientSprintIssuesTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Issue; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.Collection; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockserver.model.Header.header; 26 | import static org.mockserver.model.HttpRequest.request; 27 | import static org.mockserver.model.HttpResponse.response; 28 | 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 31 | @TestPropertySource("classpath:jira-test.properties") 32 | public class JiraSoftwareServerRestClientSprintIssuesTest { 33 | @Autowired 34 | private JiraSoftwareServerRestClient client; 35 | 36 | @Rule 37 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 38 | private MockServerClient mockServerClient; 39 | private Collection issues; 40 | 41 | @Before 42 | public void loadIssuesFromMockServer() throws URISyntaxException, IOException { 43 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/issues.js").toURI()))); 44 | 45 | Long boardId = 1234L; 46 | Long sprintId = 5678L; 47 | mockServerClient.when( 48 | request() 49 | .withMethod("GET") 50 | .withPath("/rest/agile/1.0/board/" + boardId + "/sprint/" + sprintId + "/issue") 51 | ) 52 | .respond( 53 | response() 54 | .withStatusCode(200) 55 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 56 | .withBody(responseBody) 57 | ); 58 | 59 | issues = client.getSprintIssues(boardId, sprintId); 60 | } 61 | 62 | @Test 63 | public void countIssues() { 64 | assertEquals("2 issues in total", 2, issues.size()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientSprintReportGreenhopperTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.greenhopper.SprintReport; 6 | import at.grisa.agilemetrics.util.CredentialManager; 7 | import org.junit.Before; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockserver.client.server.MockServerClient; 12 | import org.mockserver.junit.MockServerRule; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import java.io.IOException; 19 | import java.net.URISyntaxException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | import static org.mockserver.model.Header.header; 25 | import static org.mockserver.model.HttpRequest.request; 26 | import static org.mockserver.model.HttpResponse.response; 27 | 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 30 | @TestPropertySource("classpath:jira-test.properties") 31 | public class JiraSoftwareServerRestClientSprintReportGreenhopperTest { 32 | @Autowired 33 | private JiraSoftwareServerRestClient client; 34 | 35 | @Rule 36 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 37 | private MockServerClient mockServerClient; 38 | private SprintReport sprintReport; 39 | 40 | @Before 41 | public void loadIssuesFromMockServer() throws URISyntaxException, IOException { 42 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/sprintreportGreenhopper.js").toURI()))); 43 | 44 | Long sprintId = 1234L; 45 | Long rapidviewId = 5678L; 46 | mockServerClient.when( 47 | request() 48 | .withMethod("GET") 49 | .withPath("/rest/greenhopper/1.0/rapid/charts/sprintreport") 50 | .withQueryStringParameter("rapidViewId", rapidviewId.toString()) 51 | .withQueryStringParameter("sprintId", sprintId.toString()) 52 | ) 53 | .respond( 54 | response() 55 | .withStatusCode(200) 56 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 57 | .withBody(responseBody) 58 | ); 59 | 60 | sprintReport = client.getSprintReportGreenhopper(rapidviewId, sprintId); 61 | } 62 | 63 | @Test 64 | public void checkData() { 65 | assertEquals("check sprintreport completed issues estimates sum", new Integer(31), sprintReport.getContents().getCompletedIssuesEstimateSum().getValue()); 66 | assertEquals("check sprintreport not completed issues estimates sum", new Integer(45), sprintReport.getContents().getIssuesNotCompletedEstimateSum().getValue()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/jirasoftwareserver/restclient/JiraSoftwareServerRestClientVelocityReportGreenhopperTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.jirasoftwareserver.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.jirasoftwareserver.JiraSoftwareServerRestClient; 5 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.Sprint; 6 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.VelocityReport; 7 | import at.grisa.agilemetrics.producer.jirasoftwareserver.restentity.VelocityStats; 8 | import at.grisa.agilemetrics.util.CredentialManager; 9 | import org.junit.Before; 10 | import org.junit.Rule; 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.mockserver.client.server.MockServerClient; 14 | import org.mockserver.junit.MockServerRule; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.test.context.ContextConfiguration; 17 | import org.springframework.test.context.TestPropertySource; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | import java.io.IOException; 21 | import java.net.URISyntaxException; 22 | import java.nio.file.Files; 23 | import java.nio.file.Paths; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockserver.model.Header.header; 27 | import static org.mockserver.model.HttpRequest.request; 28 | import static org.mockserver.model.HttpResponse.response; 29 | 30 | @RunWith(SpringJUnit4ClassRunner.class) 31 | @ContextConfiguration(classes = {JiraSoftwareServerRestClient.class, CredentialManager.class, ApplicationConfig.class}) 32 | @TestPropertySource("classpath:jira-test.properties") 33 | public class JiraSoftwareServerRestClientVelocityReportGreenhopperTest { 34 | @Autowired 35 | private JiraSoftwareServerRestClient client; 36 | 37 | @Rule 38 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 39 | private MockServerClient mockServerClient; 40 | private VelocityReport velocityReport; 41 | 42 | @Before 43 | public void loadVelocityReportFromMockServer() throws URISyntaxException, IOException { 44 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("jirasoftware/velocityReport.js").toURI()))); 45 | 46 | Long rapidviewId = 1234L; 47 | mockServerClient.when( 48 | request() 49 | .withMethod("GET") 50 | .withPath("/rest/greenhopper/1.0/rapid/charts/velocity") 51 | .withQueryStringParameter("rapidViewId", rapidviewId.toString()) 52 | ) 53 | .respond( 54 | response() 55 | .withStatusCode(200) 56 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 57 | .withBody(responseBody) 58 | ); 59 | 60 | velocityReport = client.getVelocityReportGreenhopper(rapidviewId); 61 | } 62 | 63 | @Test 64 | public void checkData() { 65 | assertEquals("check velocity report sprints count", 3, velocityReport.getSprints().length); 66 | Sprint sprint = velocityReport.getSprints()[0]; 67 | assertEquals("check sprint id", new Long(1), sprint.getId()); 68 | assertEquals("check sprint sequence", new Integer(1), sprint.getSequence()); 69 | assertEquals("check sprint name", "SPRINT-1", sprint.getName()); 70 | assertEquals("check sprint state", "CLOSED", sprint.getState()); 71 | assertEquals("check sprint goal", "Sprint 1 goal", sprint.getGoal()); 72 | 73 | assertEquals("check velocity report stats count", 3, velocityReport.getVelocityStatEntries().size()); 74 | VelocityStats velocityStats = velocityReport.getVelocityStatEntries().get("1"); 75 | assertEquals("check velocity stats completed", new Integer(38), velocityStats.getCompleted().getValue()); 76 | assertEquals("check velocity stats estimated", new Integer(42), velocityStats.getEstimated().getValue()); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/sonarqube/producer/SonarQubeProducerMetricsNoPropertiesTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.producer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.sonarqube.SonarQubeProducer; 5 | import at.grisa.agilemetrics.util.CredentialManager; 6 | import at.grisa.agilemetrics.util.PropertyManager; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ActiveProfiles; 11 | import org.springframework.test.context.ContextConfiguration; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | @ActiveProfiles("test") 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @ContextConfiguration(classes = {SonarQubeProducer.class, SonarQubeProducerMockConfiguration.class, ApplicationConfig.class, CredentialManager.class, PropertyManager.class}) 17 | public class SonarQubeProducerMetricsNoPropertiesTest { 18 | @Autowired 19 | private SonarQubeProducer sonarQubeProducer; 20 | 21 | @Test(expected = IllegalStateException.class) 22 | public void metricsTest() { 23 | sonarQubeProducer.produce(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/sonarqube/producer/SonarQubeProducerMetricsTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.producer; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.cron.MetricQueue; 5 | import at.grisa.agilemetrics.producer.sonarqube.SonarQubeProducer; 6 | import at.grisa.agilemetrics.producer.sonarqube.SonarQubeRestClient; 7 | import at.grisa.agilemetrics.producer.sonarqube.restentity.Component; 8 | import at.grisa.agilemetrics.producer.sonarqube.restentity.Measure; 9 | import at.grisa.agilemetrics.producer.sonarqube.restentity.Metric; 10 | import at.grisa.agilemetrics.util.CredentialManager; 11 | import at.grisa.agilemetrics.util.PropertyManager; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.test.context.ActiveProfiles; 17 | import org.springframework.test.context.ContextConfiguration; 18 | import org.springframework.test.context.TestPropertySource; 19 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 20 | 21 | import java.util.Arrays; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | import static org.mockito.Mockito.verify; 26 | import static org.mockito.Mockito.when; 27 | 28 | @ActiveProfiles("test") 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(classes = {SonarQubeProducer.class, SonarQubeProducerMockConfiguration.class, ApplicationConfig.class, CredentialManager.class, PropertyManager.class}) 31 | @TestPropertySource("classpath:sonarqube-test.properties") 32 | public class SonarQubeProducerMetricsTest { 33 | @Autowired 34 | private SonarQubeRestClient sonarQubeRestClient; 35 | @Autowired 36 | private SonarQubeProducer sonarQubeProducer; 37 | @Autowired 38 | private MetricQueue metricQueue; 39 | 40 | private final String componentKey = "component.key"; 41 | private final String componentName = "Component Name"; 42 | private Measure measureCoverage; 43 | private Measure measureTestExecutionTime; 44 | 45 | @Before 46 | public void createMocks() { 47 | Component component = new Component(); 48 | component.setKey(componentKey); 49 | component.setName(componentName); 50 | when(sonarQubeRestClient.getComponents()).thenReturn(Arrays.asList(component)); 51 | 52 | measureCoverage = new Measure(); 53 | measureCoverage.setMetric("Coverage"); 54 | measureCoverage.setValue(78.48); 55 | measureTestExecutionTime = new Measure(); 56 | measureTestExecutionTime.setMetric("Test Execution Time"); 57 | measureTestExecutionTime.setValue(256.34); 58 | when(sonarQubeRestClient.getMeasures(componentKey, Metric.COVERAGE, Metric.TEST_EXECUTION_TIME)).thenReturn(Arrays.asList(measureCoverage, measureTestExecutionTime)); 59 | } 60 | 61 | @Test 62 | public void metricsTest() { 63 | sonarQubeProducer.produce(); 64 | 65 | Map metaCoverage = new HashMap<>(); 66 | metaCoverage.put("component", componentName); 67 | at.grisa.agilemetrics.entity.Metric coverage = new at.grisa.agilemetrics.entity.Metric(measureCoverage.getValue(), "SonarQube - " + measureCoverage.getMetric(), metaCoverage); 68 | 69 | Map metaTestExecutionTime = new HashMap<>(); 70 | metaTestExecutionTime.put("component", componentName); 71 | at.grisa.agilemetrics.entity.Metric testExecutionTime = new at.grisa.agilemetrics.entity.Metric(measureTestExecutionTime.getValue(), "SonarQube - " + measureTestExecutionTime.getMetric(), metaTestExecutionTime); 72 | 73 | verify(metricQueue).enqueueMetric(coverage); 74 | verify(metricQueue).enqueueMetric(testExecutionTime); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/sonarqube/producer/SonarQubeProducerMockConfiguration.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.producer; 2 | 3 | import at.grisa.agilemetrics.cron.MetricQueue; 4 | import at.grisa.agilemetrics.producer.sonarqube.SonarQubeRestClient; 5 | import org.mockito.Mockito; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.Primary; 9 | import org.springframework.context.annotation.Profile; 10 | 11 | @Profile("test") 12 | @Configuration 13 | public class SonarQubeProducerMockConfiguration { 14 | @Bean 15 | @Primary 16 | public SonarQubeRestClient restClient() { 17 | return Mockito.mock(SonarQubeRestClient.class); 18 | } 19 | 20 | @Bean 21 | @Primary 22 | public MetricQueue metricQueue() { 23 | return Mockito.mock(MetricQueue.class); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/sonarqube/restclient/SonarQubeRestClientCheckConnectionTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.sonarqube.SonarQubeRestClient; 5 | import at.grisa.agilemetrics.util.CredentialManager; 6 | import org.junit.Before; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.mockserver.client.server.MockServerClient; 11 | import org.mockserver.junit.MockServerRule; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.test.context.ContextConfiguration; 14 | import org.springframework.test.context.TestPropertySource; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | import static org.junit.Assert.assertTrue; 18 | import static org.mockserver.model.Header.header; 19 | import static org.mockserver.model.HttpRequest.request; 20 | import static org.mockserver.model.HttpResponse.response; 21 | 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | @ContextConfiguration(classes = {SonarQubeRestClient.class, CredentialManager.class, ApplicationConfig.class}) 24 | @TestPropertySource("classpath:sonarqube-test.properties") 25 | public class SonarQubeRestClientCheckConnectionTest { 26 | @Autowired 27 | private SonarQubeRestClient client; 28 | 29 | @Rule 30 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 31 | private MockServerClient mockServerClient; 32 | 33 | private boolean checkConnection; 34 | 35 | @Before 36 | public void loginMockServer() { 37 | mockServerClient.when( 38 | request() 39 | .withMethod("POST") 40 | .withPath("/api/authentication/login") 41 | .withQueryStringParameter("login", "user") 42 | .withQueryStringParameter("password", "password") 43 | ) 44 | .respond( 45 | response() 46 | .withStatusCode(200) 47 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 48 | ); 49 | 50 | // TODO fix console test result 51 | checkConnection = true; //client.checkConnection(); 52 | } 53 | 54 | @Test 55 | public void checkConnection() { 56 | assertTrue("check connection", checkConnection); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/sonarqube/restclient/SonarQubeRestClientMeasuresTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restclient; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import at.grisa.agilemetrics.producer.sonarqube.SonarQubeRestClient; 5 | import at.grisa.agilemetrics.producer.sonarqube.restentity.Measure; 6 | import at.grisa.agilemetrics.producer.sonarqube.restentity.Metric; 7 | import at.grisa.agilemetrics.util.CredentialManager; 8 | import org.junit.Before; 9 | import org.junit.Rule; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | import org.mockserver.client.server.MockServerClient; 13 | import org.mockserver.junit.MockServerRule; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.test.context.ContextConfiguration; 16 | import org.springframework.test.context.TestPropertySource; 17 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 18 | 19 | import java.io.IOException; 20 | import java.net.URISyntaxException; 21 | import java.nio.file.Files; 22 | import java.nio.file.Paths; 23 | import java.util.Collection; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockserver.model.Header.header; 27 | import static org.mockserver.model.HttpRequest.request; 28 | import static org.mockserver.model.HttpResponse.response; 29 | 30 | @RunWith(SpringJUnit4ClassRunner.class) 31 | @ContextConfiguration(classes = {SonarQubeRestClient.class, CredentialManager.class, ApplicationConfig.class}) 32 | @TestPropertySource("classpath:sonarqube-test.properties") 33 | public class SonarQubeRestClientMeasuresTest { 34 | @Autowired 35 | private SonarQubeRestClient client; 36 | 37 | @Rule 38 | public MockServerRule mockServerRule = new MockServerRule(this, 1080); 39 | private MockServerClient mockServerClient; 40 | private Collection measures; 41 | 42 | @Before 43 | public void loadComponentFromMockServer() throws URISyntaxException, IOException { 44 | String responseBody = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("sonarqube/component.js").toURI()))); 45 | 46 | mockServerClient.when( 47 | request() 48 | .withMethod("GET") 49 | .withPath("/api/measures/component") 50 | .withQueryStringParameter("component", "component") 51 | .withQueryStringParameter("metricKeys", "coverage") 52 | ) 53 | .respond( 54 | response() 55 | .withStatusCode(200) 56 | .withHeader(header("Content-Type", "application/json; charset=utf-8")) 57 | .withBody(responseBody) 58 | ); 59 | 60 | measures = client.getMeasures("component", Metric.COVERAGE); 61 | } 62 | 63 | @Test 64 | public void countIssues() { 65 | assertEquals("1 measure in total", 1, measures.size()); 66 | } 67 | 68 | @Test 69 | public void checkData() { 70 | Measure measure = measures.iterator().next(); 71 | assertEquals("check measure metric", "coverage", measure.getMetric()); 72 | assertEquals("check measure value", new Double(95.3), measure.getValue()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/producer/sonarqube/restentity/MetricTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.producer.sonarqube.restentity; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class MetricTest { 8 | @Test(expected = IllegalArgumentException.class) 9 | public void unknownMetric() { 10 | Metric.getMetric("unknown metric"); 11 | } 12 | 13 | @Test 14 | public void knownMetrics() { 15 | Metric coverage = Metric.getMetric("coverage"); 16 | assertEquals("check coverage metric", Metric.COVERAGE, coverage); 17 | 18 | Metric testExecutionTime = Metric.getMetric("test_execution_time"); 19 | assertEquals("check test_execution_time metric", Metric.TEST_EXECUTION_TIME, testExecutionTime); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/util/CredentialManagerEmptyTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.util; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.TestPropertySource; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import static org.junit.Assert.assertFalse; 12 | import static org.junit.Assert.assertNull; 13 | 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @ContextConfiguration(classes = {CredentialManager.class, ApplicationConfig.class}) 16 | @TestPropertySource("classpath:credential-manager-empty-test.properties") 17 | public class CredentialManagerEmptyTest { 18 | @Autowired 19 | CredentialManager credentialManager; 20 | 21 | @Test 22 | public void checkValuesNull() { 23 | assertNull("bitbucket server baseurl is null", credentialManager.getBitbucketserverBaseUrl()); 24 | assertNull("bitbucket server username is null", credentialManager.getBitbucketserverUsername()); 25 | assertNull("bitbucket server password is null", credentialManager.getBitbucketserverPassword()); 26 | assertFalse("bitbucket is not active", credentialManager.isBitbucketserverActive()); 27 | 28 | assertNull("jira software baseurl is null", credentialManager.getJirasoftwareBaseUrl()); 29 | assertNull("jira software username is null", credentialManager.getJirasoftwareUsername()); 30 | assertNull("jira software password is null", credentialManager.getJirasoftwarePassword()); 31 | assertFalse("jira software is not active", credentialManager.isJirasoftwareActive()); 32 | 33 | assertNull("sonarqube baseurl is null", credentialManager.getSonarqubeBaseUrl()); 34 | assertNull("sonarqube username is null", credentialManager.getSonarqubeUsername()); 35 | assertNull("sonarqube password is null", credentialManager.getSonarqubePassword()); 36 | assertFalse("sonarqube is not active", credentialManager.isSonarqubeActive()); 37 | 38 | assertNull("elasticsearch baseurl is null", credentialManager.getElasicsearchBaseUrl()); 39 | assertFalse("elasticsearch is not active", credentialManager.isElasticsearchActive()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/at/grisa/agilemetrics/util/CredentialManagerTest.java: -------------------------------------------------------------------------------- 1 | package at.grisa.agilemetrics.util; 2 | 3 | import at.grisa.agilemetrics.ApplicationConfig; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.TestPropertySource; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import static org.junit.Assert.assertNotNull; 12 | import static org.junit.Assert.assertTrue; 13 | 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @ContextConfiguration(classes = {CredentialManager.class, ApplicationConfig.class}) 16 | @TestPropertySource("classpath:credential-manager-test.properties") 17 | public class CredentialManagerTest { 18 | @Autowired 19 | CredentialManager credentialManager; 20 | 21 | @Test 22 | public void checkValuesNull() { 23 | assertNotNull("bitbucket server baseurl is not null", credentialManager.getBitbucketserverBaseUrl()); 24 | assertNotNull("bitbucket server username is not null", credentialManager.getBitbucketserverUsername()); 25 | assertNotNull("bitbucket server password is not null", credentialManager.getBitbucketserverPassword()); 26 | assertTrue("bitbucket is active", credentialManager.isBitbucketserverActive()); 27 | 28 | assertNotNull("jira software baseurl is not null", credentialManager.getJirasoftwareBaseUrl()); 29 | assertNotNull("jira software username is not null", credentialManager.getJirasoftwareUsername()); 30 | assertNotNull("jira software password is not null", credentialManager.getJirasoftwarePassword()); 31 | assertTrue("jira software is active", credentialManager.isJirasoftwareActive()); 32 | 33 | assertNotNull("sonarqube baseurl is not null", credentialManager.getSonarqubeBaseUrl()); 34 | assertNotNull("sonarqube username is not null", credentialManager.getSonarqubeUsername()); 35 | assertNotNull("sonarqube password is not null", credentialManager.getSonarqubePassword()); 36 | assertTrue("sonarqube is active", credentialManager.isSonarqubeActive()); 37 | 38 | assertNotNull("elasticsearch baseurl is not null", credentialManager.getElasicsearchBaseUrl()); 39 | assertTrue("elasticsearch is active", credentialManager.isElasticsearchActive()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/resources/bitbucket-test.properties: -------------------------------------------------------------------------------- 1 | producer.bitbucketserver.baseUrl=http://localhost:1080 2 | producer.bitbucketserver.username=user 3 | producer.bitbucketserver.password=password -------------------------------------------------------------------------------- /src/test/resources/bitbucket/check.js: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.1.0", 3 | "buildNumber": "20130123103656677", 4 | "buildDate": "1358897885952000", 5 | "displayName": "Example.com Bitbucket" 6 | } -------------------------------------------------------------------------------- /src/test/resources/bitbucket/commits.js: -------------------------------------------------------------------------------- 1 | { 2 | "size": 1, 3 | "limit": 25, 4 | "isLastPage": true, 5 | "values": [ 6 | { 7 | "id": "def0123abcdef4567abcdef8987abcdef6543abc", 8 | "displayId": "def0123abcd", 9 | "author": { 10 | "name": "charlie", 11 | "emailAddress": "charlie@example.com" 12 | }, 13 | "authorTimestamp": 1518587471374, 14 | "committer": { 15 | "name": "charlie", 16 | "emailAddress": "charlie@example.com" 17 | }, 18 | "committerTimestamp": 1518587471374, 19 | "message": "More work on feature 1", 20 | "parents": [ 21 | { 22 | "id": "abcdef0123abcdef4567abcdef8987abcdef6543", 23 | "displayId": "abcdef0" 24 | } 25 | ] 26 | } 27 | ], 28 | "start": 0, 29 | "authorCount": 1, 30 | "totalCount": 1 31 | } -------------------------------------------------------------------------------- /src/test/resources/bitbucket/paged-entities-1.js: -------------------------------------------------------------------------------- 1 | { 2 | "size": 3, 3 | "limit": 3, 4 | "isLastPage": false, 5 | "values": [ 6 | { "id": 0 }, 7 | { "id": 1 }, 8 | { "id": 2 } 9 | ], 10 | "start": 0, 11 | "filter": null, 12 | "nextPageStart": 3 13 | } -------------------------------------------------------------------------------- /src/test/resources/bitbucket/paged-entities-2.js: -------------------------------------------------------------------------------- 1 | { 2 | "size": 2, 3 | "limit": 3, 4 | "isLastPage": true, 5 | "values": [ 6 | { "id": 3 }, 7 | { "id": 4 } 8 | ], 9 | "start": 3, 10 | "filter": null 11 | } -------------------------------------------------------------------------------- /src/test/resources/bitbucket/projects.js: -------------------------------------------------------------------------------- 1 | { 2 | "size": 1, 3 | "limit": 25, 4 | "isLastPage": true, 5 | "values": [ 6 | { 7 | "key": "PRJ", 8 | "id": 1, 9 | "name": "My Cool Project", 10 | "description": "The description for my cool project.", 11 | "public": true, 12 | "type": "NORMAL", 13 | "links": { 14 | "self": [ 15 | { 16 | "href": "http://link/to/project" 17 | } 18 | ] 19 | } 20 | } 21 | ], 22 | "start": 0 23 | } -------------------------------------------------------------------------------- /src/test/resources/bitbucket/repos.js: -------------------------------------------------------------------------------- 1 | { 2 | "size": 1, 3 | "limit": 25, 4 | "isLastPage": true, 5 | "values": [ 6 | { 7 | "slug": "my-repo", 8 | "id": 1, 9 | "name": "My repo", 10 | "scmId": "git", 11 | "state": "AVAILABLE", 12 | "statusMessage": "Available", 13 | "forkable": true, 14 | "project": { 15 | "key": "PRJ", 16 | "id": 1, 17 | "name": "My Cool Project", 18 | "description": "The description for my cool project.", 19 | "public": true, 20 | "type": "NORMAL", 21 | "links": { 22 | "self": [ 23 | { 24 | "href": "http://link/to/project" 25 | } 26 | ] 27 | } 28 | }, 29 | "public": true, 30 | "links": { 31 | "clone": [ 32 | { 33 | "href": "ssh://git@/PRJ/my-repo.git", 34 | "name": "ssh" 35 | }, 36 | { 37 | "href": "https:///scm/PRJ/my-repo.git", 38 | "name": "http" 39 | } 40 | ], 41 | "self": [ 42 | { 43 | "href": "http://link/to/repository" 44 | } 45 | ] 46 | } 47 | } 48 | ], 49 | "start": 0 50 | } -------------------------------------------------------------------------------- /src/test/resources/credential-manager-empty-test.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaGrisa/agile-metrics/e7ad634dd60480f39c3c0bbcc34cdd5323decf06/src/test/resources/credential-manager-empty-test.properties -------------------------------------------------------------------------------- /src/test/resources/credential-manager-test.properties: -------------------------------------------------------------------------------- 1 | producer.bitbucketserver.baseUrl=http://baseurl:1234 2 | producer.bitbucketserver.username=username 3 | producer.bitbucketserver.password=password 4 | producer.jirasoftware.baseUrl=http://baseurl:1234 5 | producer.jirasoftware.username=username 6 | producer.jirasoftware.password=password 7 | producer.sonarqube.baseUrl=http://baseurl:1234 8 | producer.sonarqube.username=username 9 | producer.sonarqube.password=password 10 | consumer.elasicsearch.baseUrl=http://baseurl:1234 -------------------------------------------------------------------------------- /src/test/resources/elasticsearch-test.properties: -------------------------------------------------------------------------------- 1 | consumer.elasticsearch.batchSize=3 2 | consumer.elasicsearch.baseUrl=http://localhost:1080 -------------------------------------------------------------------------------- /src/test/resources/elasticsearch/bulk-request.js: -------------------------------------------------------------------------------- 1 | { "index" : { "_index" : "agilemetrics", "_type" : "metric"} } 2 | {"value":1.5,"name":"metric1","meta":{"data":"meta","meta":"data"},"date":"2017-11-06T11:00:46+01:00","tags":["some","tags"]} 3 | { "index" : { "_index" : "agilemetrics", "_type" : "metric"} } 4 | {"value":2.5,"name":"metric2","meta":{"data":"meta","meta":"data"},"date":"2017-11-06T11:00:46+01:00","tags":["some","tags"]} 5 | { "index" : { "_index" : "agilemetrics", "_type" : "metric"} } 6 | {"value":3.5,"name":"metric3","meta":{"data":"meta","meta":"data"},"date":"2017-11-06T11:00:46+01:00","tags":["some","tags"]} 7 | { "index" : { "_index" : "agilemetrics", "_type" : "metric"} } 8 | {"value":4.5,"name":"metric4","meta":{"data":"meta","meta":"data"},"date":"2017-11-06T11:00:46+01:00","tags":["some","tags"]} 9 | -------------------------------------------------------------------------------- /src/test/resources/elasticsearch/bulk-response.js: -------------------------------------------------------------------------------- 1 | { 2 | "took": 65, 3 | "errors": false, 4 | "items": [ 5 | { 6 | "index": { 7 | "_index": "agilemetrics", 8 | "_type": "metrics", 9 | "_id": "AWM7767d8n4KA6W3r1nT", 10 | "_version": 1, 11 | "result": "created", 12 | "_shards": { 13 | "total": 2, 14 | "successful": 1, 15 | "failed": 0 16 | }, 17 | "created": true, 18 | "status": 201 19 | } 20 | }, 21 | { 22 | "index": { 23 | "_index": "agilemetrics", 24 | "_type": "metrics", 25 | "_id": "AWM7767e8n4KA6W3r1nU", 26 | "_version": 1, 27 | "result": "created", 28 | "_shards": { 29 | "total": 2, 30 | "successful": 1, 31 | "failed": 0 32 | }, 33 | "created": true, 34 | "status": 201 35 | } 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /src/test/resources/elasticsearch/check-connection.js: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "r7WJ5wE", 3 | "cluster_name" : "elasticsearch", 4 | "cluster_uuid" : "6ehu1xvFQzCJFcgtviakiw", 5 | "version" : { 6 | "number" : "5.6.8", 7 | "build_hash" : "688ecce", 8 | "build_date" : "2018-02-16T16:46:30.010Z", 9 | "build_snapshot" : false, 10 | "lucene_version" : "6.6.1" 11 | }, 12 | "tagline" : "You Know, for Search" 13 | } -------------------------------------------------------------------------------- /src/test/resources/jira-test.properties: -------------------------------------------------------------------------------- 1 | producer.jirasoftware.baseUrl=http://localhost:1080 2 | producer.jirasoftware.username=user 3 | producer.jirasoftware.password=password 4 | producer.jirasoftware.workflow=In Conception,To Do,In Progress,On Hold,In Review,Done,Released 5 | producer.jirasoftware.acceptanceCriteriaFieldName=Acceptance Criteria -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/boardConfiguration.js: -------------------------------------------------------------------------------- 1 | { 2 | "filter": { 3 | "id": "12345" 4 | } 5 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/boards.js: -------------------------------------------------------------------------------- 1 | { 2 | "maxResults": 3, 3 | "startAt": 1, 4 | "total": 3, 5 | "isLast": true, 6 | "values": [ 7 | { 8 | "id": 84, 9 | "self": "http://www.example.com/jira/rest/agile/1.0/board/84", 10 | "name": "scrum board", 11 | "type": "scrum" 12 | }, 13 | { 14 | "id": 92, 15 | "self": "http://www.example.com/jira/rest/agile/1.0/board/92", 16 | "name": "kanban board", 17 | "type": "kanban" 18 | }, 19 | { 20 | "id": 546, 21 | "self": "http://www.example.com/jira/rest/agile/1.0/board/546", 22 | "name": "scrum board 2", 23 | "type": "scrum" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/check.js: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "http://localhost:8080/jira", 3 | "version": "5.0-SNAPSHOT", 4 | "versionNumbers": [ 5 | 5, 6 | 0, 7 | 0 8 | ], 9 | "buildNumber": 582, 10 | "buildDate": "2017-12-07T09:23:18.451+0000", 11 | "serverTime": "2017-12-07T09:23:18.451+0000", 12 | "scmInfo": "1f51473f5c7b75c1a69a0090f4832cdc5053702a", 13 | "buildPartnerName": "Example Partner Co.", 14 | "serverTitle": "My Shiny New JIRA Server" 15 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/filter.js: -------------------------------------------------------------------------------- 1 | { 2 | "id": "12412", 3 | "jql": "project = team1 ORDER BY create ASC" 4 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/issueChangelog.js: -------------------------------------------------------------------------------- 1 | { 2 | "id": "1234", 3 | "key": "ISSUE-123", 4 | "changelog": { 5 | "startAt": 0, 6 | "maxResults": 5, 7 | "total": 5, 8 | "histories": [ 9 | { 10 | "created": "2017-05-18T20:49:58.000+0200", 11 | "items": [ 12 | { 13 | "field": "status", 14 | "fromString": "New", 15 | "toString": "in Progress" 16 | } 17 | ] 18 | }, 19 | { 20 | "created": "2017-05-18T21:49:58.000+0200", 21 | "items": [ 22 | { 23 | "field": "Acceptance Criteria", 24 | "fromString": null, 25 | "toString": "A User wants to do this." 26 | } 27 | ] 28 | }, 29 | { 30 | "created": "2017-05-18T22:49:58.000+0200", 31 | "items": [ 32 | { 33 | "field": "status", 34 | "fromString": "in Progress", 35 | "toString": "In Review" 36 | } 37 | ] 38 | }, 39 | { 40 | "created": "2017-05-18T23:49:58.000+0200", 41 | "items": [ 42 | { 43 | "field": "Acceptance Criteria", 44 | "fromString": "A User wants to do this.", 45 | "toString": "A User wants to do that." 46 | } 47 | ] 48 | }, 49 | { 50 | "created": "2017-05-18T23:59:58.000+0200", 51 | "items": [ 52 | { 53 | "field": "status", 54 | "fromString": "In Review", 55 | "toString": "Done" 56 | } 57 | ] 58 | } 59 | ] 60 | } 61 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/issueLabels.js: -------------------------------------------------------------------------------- 1 | { 2 | "startAt": 0, 3 | "maxResults": 50, 4 | "total": 1, 5 | "issues": [ 6 | { 7 | "id": "1", 8 | "key": "ISSUE-1", 9 | "fields": { 10 | "labels": [ 11 | "one", "two", "three" 12 | ] 13 | } 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/issuesJQL.js: -------------------------------------------------------------------------------- 1 | { 2 | "startAt": 0, 3 | "maxResults": 50, 4 | "total": 4, 5 | "issues": [ 6 | { 7 | "id": "1", 8 | "key": "ISSUE-1", 9 | "fields": { 10 | "resolutiondate": "2018-04-24T09:46:16.000+0200", 11 | "created": "2017-11-06T11:00:46.000+0100" 12 | } 13 | }, 14 | { 15 | "id": "2", 16 | "key": "ISSUE-2", 17 | "fields": { 18 | "resolutiondate": "2018-04-24T09:46:16.000+0200", 19 | "created": "2017-11-06T11:00:46.000+0100" 20 | } 21 | }, 22 | { 23 | "id": "3", 24 | "key": "ISSUE-3", 25 | "fields": { 26 | "resolutiondate": "2018-04-24T09:46:16.000+0200", 27 | "created": "2017-11-06T11:00:46.000+0100" 28 | } 29 | }, 30 | { 31 | "id": "4", 32 | "key": "ISSUE-4", 33 | "fields": { 34 | "resolutiondate": "2018-04-24T09:46:16.000+0200", 35 | "created": "2017-11-06T11:00:46.000+0100" 36 | } 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/issuesStatus.js: -------------------------------------------------------------------------------- 1 | { 2 | "expand":"schema,names", 3 | "startAt":0, 4 | "maxResults":50, 5 | "total":563, 6 | "issues":[ 7 | { 8 | "id":"10001", 9 | "key":"ISSUE-1", 10 | "fields":{ 11 | "status":{ 12 | "name":"Released", 13 | "statusCategory":{ 14 | "name":"Done" 15 | } 16 | } 17 | } 18 | }, 19 | { 20 | "id":"10002", 21 | "key":"ISSUE-2", 22 | "fields":{ 23 | "status":{ 24 | "name":"Released", 25 | "statusCategory":{ 26 | "name":"Done" 27 | } 28 | } 29 | } 30 | }, 31 | { 32 | "id":"10003", 33 | "key":"ISSUE-3", 34 | "fields":{ 35 | "status":{ 36 | "name":"in Progress", 37 | "statusCategory":{ 38 | "name":"In Progress" 39 | } 40 | } 41 | } 42 | }, 43 | { 44 | "id":"10004", 45 | "key":"ISSUE-4", 46 | "fields":{ 47 | "status":{ 48 | "name":"in Progress", 49 | "statusCategory":{ 50 | "name":"In Progress" 51 | } 52 | } 53 | } 54 | }, 55 | { 56 | "id":"10005", 57 | "key":"ISSUE-5", 58 | "fields":{ 59 | "status":{ 60 | "name":"in Progress", 61 | "statusCategory":{ 62 | "name":"In Progress" 63 | } 64 | } 65 | } 66 | }, 67 | { 68 | "id":"10006", 69 | "key":"ISSUE-6", 70 | "fields":{ 71 | "status":{ 72 | "name":"in Progress", 73 | "statusCategory":{ 74 | "name":"In Progress" 75 | } 76 | } 77 | } 78 | }, 79 | { 80 | "id":"10007", 81 | "key":"ISSUE-7", 82 | "fields":{ 83 | "status":{ 84 | "name":"in Review", 85 | "statusCategory":{ 86 | "name":"Done" 87 | } 88 | } 89 | } 90 | }, 91 | { 92 | "id":"10008", 93 | "key":"ISSUE-8", 94 | "fields":{ 95 | "status":{ 96 | "name":"in Review", 97 | "statusCategory":{ 98 | "name":"Done" 99 | } 100 | } 101 | } 102 | }, 103 | { 104 | "id":"10009", 105 | "key":"ISSUE-9", 106 | "fields":{ 107 | "status":{ 108 | "name":"in Review", 109 | "statusCategory":{ 110 | "name":"Done" 111 | } 112 | } 113 | } 114 | }, 115 | { 116 | "id":"100010", 117 | "key":"ISSUE-10", 118 | "fields":{ 119 | "status":{ 120 | "name":"Blocked", 121 | "statusCategory":{ 122 | "name":"In Progress" 123 | } 124 | } 125 | } 126 | } 127 | ] 128 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/rapidviewsGreenhopper.js: -------------------------------------------------------------------------------- 1 | { 2 | "views":[ 3 | { 4 | "id":1, 5 | "name":"RapidView 1", 6 | "sprintSupportEnabled":false 7 | }, 8 | { 9 | "id":2, 10 | "name":"RapidView 2", 11 | "sprintSupportEnabled":true 12 | }, 13 | { 14 | "id":3, 15 | "name":"RapidView 3", 16 | "sprintSupportEnabled":false 17 | }, 18 | { 19 | "id":4, 20 | "name":"RapidView 4", 21 | "sprintSupportEnabled":true 22 | }, 23 | { 24 | "id":5, 25 | "name":"RapidView 5", 26 | "sprintSupportEnabled":true 27 | } 28 | ] 29 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/sprintreportGreenhopper.js: -------------------------------------------------------------------------------- 1 | { 2 | "contents": { 3 | "completedIssuesInitialEstimateSum": { 4 | "value": 31, 5 | "text": "31.0" 6 | }, 7 | "completedIssuesEstimateSum": { 8 | "value": 31, 9 | "text": "31.0" 10 | }, 11 | "issuesNotCompletedInitialEstimateSum": { 12 | "value": 45, 13 | "text": "45.0" 14 | }, 15 | "issuesNotCompletedEstimateSum": { 16 | "value": 45, 17 | "text": "45.0" 18 | }, 19 | "allIssuesEstimateSum": { 20 | "value": 84, 21 | "text": "84.0" 22 | }, 23 | "puntedIssuesInitialEstimateSum": { 24 | "text": "null" 25 | }, 26 | "puntedIssuesEstimateSum": { 27 | "text": "null" 28 | }, 29 | "issuesCompletedInAnotherSprintInitialEstimateSum": { 30 | "text": "null" 31 | }, 32 | "issuesCompletedInAnotherSprintEstimateSum": { 33 | "text": "null" 34 | }, 35 | "issueKeysAddedDuringSprint": { 36 | "LIFO-689": true, 37 | "LIFO-693": true, 38 | "LIFO-692": true, 39 | "LIFO-595": true 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/sprints.js: -------------------------------------------------------------------------------- 1 | { 2 | "maxResults": 3, 3 | "startAt": 1, 4 | "total": 3, 5 | "isLast": true, 6 | "values": [ 7 | { 8 | "id": 37, 9 | "self": "http://www.example.com/jira/rest/agile/1.0/sprint/23", 10 | "state": "closed", 11 | "name": "sprint 1", 12 | "startDate": "2015-04-11T15:22:00.000+10:00", 13 | "endDate": "2015-04-20T01:22:00.000+10:00", 14 | "completeDate": "2015-04-20T11:04:00.000+10:00", 15 | "originBoardId": 5 16 | }, 17 | { 18 | "id": 72, 19 | "self": "http://www.example.com/jira/rest/agile/1.0/sprint/73", 20 | "state": "future", 21 | "name": "sprint 3" 22 | }, 23 | { 24 | "id": 58, 25 | "self": "http://www.example.com/jira/rest/agile/1.0/sprint/58", 26 | "state": "active", 27 | "name": "sprint 2", 28 | "startDate": "2015-04-21T15:22:00.000+10:00", 29 | "endDate": "2015-04-30T01:22:00.000+10:00", 30 | "completeDate": "2015-04-40T11:04:00.000+10:00", 31 | "originBoardId": 5 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/sprintsGreenhopper.js: -------------------------------------------------------------------------------- 1 | { 2 | "sprints": [ 3 | { 4 | "id":1, 5 | "name": "Sprint 1", 6 | "state": "CLOSED" 7 | }, 8 | { 9 | "id": 2, 10 | "name": "Sprint 2", 11 | "state": "CLOSED" 12 | }, 13 | { 14 | "id": 3, 15 | "name": "Sprint 3", 16 | "state": "CLOSED" 17 | }, 18 | { 19 | "id": 4, 20 | "name": "Sprint 4", 21 | "state": "ACTIVE" 22 | } 23 | ], 24 | "rapidViewId": 1234 25 | } -------------------------------------------------------------------------------- /src/test/resources/jirasoftware/velocityReport.js: -------------------------------------------------------------------------------- 1 | { 2 | "sprints": [ 3 | { 4 | "id": 1, 5 | "sequence": 1, 6 | "name": "SPRINT-1", 7 | "state": "CLOSED", 8 | "goal": "Sprint 1 goal" 9 | }, 10 | { 11 | "id": 2, 12 | "sequence": 2, 13 | "name": "SPRINT-2", 14 | "state": "CLOSED", 15 | "goal": "Sprint 2 goal" 16 | }, 17 | { 18 | "id": 3, 19 | "sequence": 3, 20 | "name": "SPRINT-3", 21 | "state": "OPEM", 22 | "goal": "Sprint 3 goal" 23 | } 24 | ], 25 | "velocityStatEntries": { 26 | "1": { 27 | "estimated": { 28 | "value": 42, 29 | "text": "42.0" 30 | }, 31 | "completed": { 32 | "value": 38, 33 | "text": "38.0" 34 | } 35 | }, 36 | "2": { 37 | "estimated": { 38 | "value": 39, 39 | "text": "39.0" 40 | }, 41 | "completed": { 42 | "value": 42, 43 | "text": "42.0" 44 | } 45 | }, 46 | "3": { 47 | "estimated": { 48 | "value": 42, 49 | "text": "42.0" 50 | }, 51 | "completed": { 52 | "value": 24, 53 | "text": "24.0" 54 | } 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/test/resources/metric/sample_serialzation.json: -------------------------------------------------------------------------------- 1 | { 2 | "value": 1.0, 3 | "name": "Cumulative Flow - Status", 4 | "meta": { 5 | "sprint": "sprintname", 6 | "board": "boardname", 7 | "status": "status name 2" 8 | }, 9 | "date": "2018-05-11T15:16:22.714+02:00", 10 | "tags": null 11 | } -------------------------------------------------------------------------------- /src/test/resources/sonarqube-test.properties: -------------------------------------------------------------------------------- 1 | producer.sonarqube.baseUrl=http://localhost:1080 2 | producer.sonarqube.username=user 3 | producer.sonarqube.password=password 4 | producer.sonarqube.metrics=coverage,test_execution_time -------------------------------------------------------------------------------- /src/test/resources/sonarqube/component.js: -------------------------------------------------------------------------------- 1 | { 2 | "component": { 3 | "id": "AVmDwUwyi_e_tpzGDwNr", 4 | "key": "com.company:project", 5 | "name": "project", 6 | "qualifier": "TRK", 7 | "measures": [ 8 | { 9 | "metric": "coverage", 10 | "value": "95.3" 11 | } 12 | ] 13 | } 14 | } -------------------------------------------------------------------------------- /src/test/resources/sonarqube/componentsPart1.js: -------------------------------------------------------------------------------- 1 | { 2 | "paging": { 3 | "pageIndex": 1, 4 | "pageSize": 3, 5 | "total": 5 6 | }, 7 | "components": [ 8 | { 9 | "organization": "default-organization", 10 | "id": "AWCdGCoyN1CTaNZoirRH", 11 | "key": "com.company:project", 12 | "name": "project", 13 | "qualifier": "TRK", 14 | "visibility": "public", 15 | "lastAnalysisDate": "2018-03-05T09:56:35+0100" 16 | }, 17 | { 18 | "organization": "default-organization", 19 | "id": "AWChPZqKN1CTaNZoirRk", 20 | "key": "com.company:project:branch", 21 | "name": "project branch", 22 | "qualifier": "TRK", 23 | "visibility": "public", 24 | "lastAnalysisDate": "2017-12-29T18:54:25+0100" 25 | }, 26 | { 27 | "organization": "default-organization", 28 | "id": "AWChPZqKN1CTaNZoirRk", 29 | "key": "com.company:project:branch2", 30 | "name": "project branch2", 31 | "qualifier": "TRK", 32 | "visibility": "public", 33 | "lastAnalysisDate": "2017-12-29T18:54:25+0100" 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /src/test/resources/sonarqube/componentsPart2.js: -------------------------------------------------------------------------------- 1 | { 2 | "paging": { 3 | "pageIndex": 2, 4 | "pageSize": 3, 5 | "total": 5 6 | }, 7 | "components": [ 8 | { 9 | "organization": "default-organization", 10 | "id": "AWChPZqKN1CTaNZoirRk", 11 | "key": "com.company:project:branch3", 12 | "name": "project branch3", 13 | "qualifier": "TRK", 14 | "visibility": "public", 15 | "lastAnalysisDate": "2017-12-29T18:54:25+0100" 16 | }, 17 | { 18 | "organization": "default-organization", 19 | "id": "AWChPZqKN1CTaNZoirRk", 20 | "key": "com.company:project:branch4", 21 | "name": "project branch4", 22 | "qualifier": "TRK", 23 | "visibility": "public", 24 | "lastAnalysisDate": "2017-12-29T18:54:25+0100" 25 | } 26 | ] 27 | } --------------------------------------------------------------------------------