Skip to content

Commit

Permalink
Jira Features Widget creation via remote API (hygieia#2580)
Browse files Browse the repository at this point in the history
* Updated the logback.xml for score collector to roll-off log files correctly

* Updated the log file name and file path as per the existing pattern

* Fix to create feature widget via remoteCreate api

* Added additional check to match one of the fields from the collector

* Adding unit tests for the changes made

* Cleaned up the dependency on FeatureCollector coming from jira-collector module

* Removed the toCollectorItem overridden method from FeatureEntry, and restored the original score collector logback.xml, will create a separate PR for it
  • Loading branch information
subodhsbattina authored and subodhbattina committed Nov 29, 2018
1 parent c099156 commit d04c648
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
import com.capitalone.dashboard.model.CollectorType;
import com.capitalone.dashboard.model.Owner;
import com.capitalone.dashboard.util.GitHubParsedUrl;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -248,7 +245,12 @@ public String getWidgetName() {

@Override
public Map<String, Object> toWidgetOptions() {
return null;
Map<String, Object> opts = new HashMap<>();
opts.put("id", getWidgetId());
options.keySet().forEach(key -> {
opts.put(key, options.get(key));
});
return opts;
}
}

Expand Down Expand Up @@ -553,6 +555,7 @@ public List<Entry> getAllEntries() {
all.addAll(securityScanEntries);
all.addAll(functionalTestEntries);
all.addAll(deploymentEntries);
all.addAll(featureEntries);
return all;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public Widget widget() {
if("build".equalsIgnoreCase(name)){
widget.getOptions().put("buildDurationThreshold",3);
widget.getOptions().put("consecutiveFailureThreshold",5);
} else if ("feature".equalsIgnoreCase(name)) {
widget.getOptions().putAll(options);
}
}
return widget;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.capitalone.dashboard.request;

import com.capitalone.dashboard.misc.HygieiaException;
import com.capitalone.dashboard.model.Collector;
import com.capitalone.dashboard.model.CollectorItem;
import com.capitalone.dashboard.model.CollectorType;
import com.capitalone.dashboard.util.FeatureCollectorConstants;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.HashMap;
import java.util.Map;

@RunWith(MockitoJUnitRunner.class)
public class FeatureEntryTest {
@Test
public void FeatureEntry_toWidgetOptions_Test() throws HygieiaException {
DashboardRemoteRequest.Entry entry = new DashboardRemoteRequest.FeatureEntry();

Map<String, Object> allOptions = new HashMap<>();
allOptions.put("featureTool", "Jira");
allOptions.put("projectName", "TestProject");
allOptions.put("projectId", "123");
allOptions.put("teamName", "TestTeam");
allOptions.put("teamId", "321");
allOptions.put("estimateMetricType", "storypoints");
allOptions.put("sprintType", "kanban");
allOptions.put("listType", "epics");
allOptions.put("showStatus", "showStatus");

entry.setOptions(allOptions);
Map<String, Object> options = entry.toWidgetOptions();

Assert.assertEquals(10, options.size());

Assert.assertEquals("feature0", options.get("id"));
Assert.assertEquals("Jira", options.get("featureTool"));
Assert.assertEquals("TestProject", options.get("projectName"));
Assert.assertEquals("123", options.get("projectId"));
Assert.assertEquals("TestTeam", options.get("teamName"));
Assert.assertEquals("321", options.get("teamId"));
Assert.assertEquals("storypoints", options.get("estimateMetricType"));
Assert.assertEquals("kanban", options.get("sprintType"));
Assert.assertEquals("epics", options.get("listType"));
Assert.assertEquals("showStatus", options.get("showStatus"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.capitalone.dashboard.request;

import com.capitalone.dashboard.model.Widget;
import com.capitalone.dashboard.util.FeatureCollectorConstants;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.HashMap;
import java.util.Map;

@RunWith(MockitoJUnitRunner.class)
public class WidgetRequestTest {
@Test
public void widgetTest() {
Map<String, Object> allOptions = new HashMap<>();
allOptions.put("id", "feature0");
allOptions.put("featureTool", "Jira");
allOptions.put("projectName", "TestProject");
allOptions.put("projectId", "123");
allOptions.put("teamName", "TestTeam");
allOptions.put("teamId", "321");

WidgetRequest widgetRequest = new WidgetRequest();
widgetRequest.setName("feature");
widgetRequest.setOptions(allOptions);
Widget widget = widgetRequest.widget();

Map<String, Object> options = widget.getOptions();
Assert.assertEquals(6, options.size());
Assert.assertEquals("feature0", options.get("id"));
Assert.assertEquals("Jira", options.get("featureTool"));
Assert.assertEquals("TestProject", options.get("projectName"));
Assert.assertEquals("123", options.get("projectId"));
Assert.assertEquals("TestTeam", options.get("teamName"));
Assert.assertEquals("321", options.get("teamId"));
}
}
2 changes: 1 addition & 1 deletion collectors/feature/jira/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<dependency>
<groupId>com.capitalone.dashboard</groupId>
<artifactId>core</artifactId>
<version>3.0.4</version>
<version>[3.1.0-SNAPSHOT,)</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.capitalone.dashboard.util.FeatureCollectorConstants;

import java.util.HashMap;
import java.util.Map;

/**
* Collector implementation for Feature that stores system configuration
* settings required for source system data connection (e.g., API tokens, etc.)
Expand All @@ -24,6 +27,27 @@ public static FeatureCollector prototype() {
protoType.setCollectorType(CollectorType.AgileTool);
protoType.setLastExecuted(System.currentTimeMillis());

Map<String, Object> allOptions = new HashMap<>();
allOptions.put(FeatureCollectorConstants.TOOL_TYPE, "");
allOptions.put(FeatureCollectorConstants.PROJECT_NAME, "");
allOptions.put(FeatureCollectorConstants.PROJECT_ID, "");
allOptions.put(FeatureCollectorConstants.TEAM_NAME, "");
allOptions.put(FeatureCollectorConstants.TEAM_ID, "");
allOptions.put(FeatureCollectorConstants.ESTIMATE_METRIC_TYPE, "");
allOptions.put(FeatureCollectorConstants.SPRINT_TYPE, "");
allOptions.put(FeatureCollectorConstants.LIST_TYPE, "");
allOptions.put(FeatureCollectorConstants.SHOW_STATUS, "");
protoType.setAllFields(allOptions);

Map<String, Object> uniqueOptions = new HashMap<>();
uniqueOptions.put(FeatureCollectorConstants.TOOL_TYPE, "");
uniqueOptions.put(FeatureCollectorConstants.PROJECT_NAME, "");
uniqueOptions.put(FeatureCollectorConstants.PROJECT_ID, "");
uniqueOptions.put(FeatureCollectorConstants.TEAM_NAME, "");
uniqueOptions.put(FeatureCollectorConstants.TEAM_ID, "");

protoType.setUniqueFields(uniqueOptions);

return protoType;
}
}
2 changes: 1 addition & 1 deletion collectors/misc/score/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- rollover daily -->
<fileNamePattern>logs/scorecollector-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 20MB -->
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
Expand Down

0 comments on commit d04c648

Please # to comment.