codemodels-java 0.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +198 -0
- data/README.md +6 -0
- data/Rakefile +13 -0
- data/codemodels-java.gemspec +24 -0
- data/lib/codemodels/java/info_extraction.rb +110 -0
- data/lib/codemodels/java/java_models_builder.rb +17 -0
- data/lib/codemodels/java/language.rb +17 -0
- data/lib/codemodels/java/metamodel.rb +234 -0
- data/lib/codemodels/java/model_building.rb +42 -0
- data/lib/codemodels/java/parser.rb +83 -0
- data/lib/codemodels/java.rb +10 -0
- data/lib/jars/javaparser-1.0.8.jar +0 -0
- data/test/data/ActionButtonsColumnTag.java +100 -0
- data/test/data/AuthConstraint.java +17 -0
- data/test/data/CsvExporter.java +58 -0
- data/test/data/ReorderStoriesForm.java +100 -0
- data/test/data/TestIteration.java +192 -0
- data/test/data/example_accessors.java +24 -0
- data/test/data/example_basic.java +5 -0
- data/test/test_correspondences.rb +31 -0
- data/test/test_helper.rb +57 -0
- data/test/test_info_extraction.rb +258 -0
- data/test/test_metamodel.rb +133 -0
- data/test/test_parsing.rb +174 -0
- data/test/test_values.rb +361 -0
- metadata +188 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'codemodels'
|
2
|
+
require 'codemodels/java/parser'
|
3
|
+
|
4
|
+
module CodeModels
|
5
|
+
|
6
|
+
module Java
|
7
|
+
|
8
|
+
SRC_EXTENSION = 'java'
|
9
|
+
|
10
|
+
MODEL_EXTENSION = "#{SRC_EXTENSION}.lm"
|
11
|
+
|
12
|
+
MODEL_PRODUCER = Proc.new do |src|
|
13
|
+
root = CodeModels::Java.parse_file(src)
|
14
|
+
end
|
15
|
+
|
16
|
+
SERIALIZED_MODEL_PRODUCER = Proc.new do |src|
|
17
|
+
root = CodeModels::Java.parse_file(src)
|
18
|
+
CodeModels::Serialization.rgenobject_to_model(root)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.generate_models_in_dir(src,dest,model_ext=MODEL_EXTENSION,max_nesting=500)
|
22
|
+
CodeModels::ModelBuilding.generate_models_in_dir(src,dest,SRC_EXTENSION,model_ext,max_nesting) do |src|
|
23
|
+
SERIALIZED_MODEL_PRODUCER.call(src)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.generate_model_per_file(src,dest,model_ext=MODEL_EXTENSION,max_nesting=500)
|
28
|
+
CodeModels::ModelBuilding.generate_model_per_file(src,dest) do |src|
|
29
|
+
SERIALIZED_MODEL_PRODUCER.call(src)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.handle_models_in_dir(src,error_handler=nil,model_handler)
|
34
|
+
raise "Unexisting dir given: #{src}" unless File.exist?(src)
|
35
|
+
CodeModels::ModelBuilding.handle_models_in_dir(src,SRC_EXTENSION,error_handler,model_handler) do |src|
|
36
|
+
MODEL_PRODUCER.call(src)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'codemodels'
|
2
|
+
|
3
|
+
module CodeModels
|
4
|
+
module Java
|
5
|
+
|
6
|
+
class << self
|
7
|
+
include ParserWrapper
|
8
|
+
end
|
9
|
+
|
10
|
+
java_import 'japa.parser.JavaParser'
|
11
|
+
java_import 'java.io.FileInputStream'
|
12
|
+
java_import 'java.io.ByteArrayInputStream'
|
13
|
+
|
14
|
+
def self.containment_pos(node)
|
15
|
+
container = node.eContainer
|
16
|
+
children = node.eContainer.send(node.eContainingFeature)
|
17
|
+
if children.respond_to?(:each)
|
18
|
+
children.each_with_index do |c,i|
|
19
|
+
return i if c==node
|
20
|
+
end
|
21
|
+
raise "Not found"
|
22
|
+
else
|
23
|
+
raise "Not found" unless children==node
|
24
|
+
0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# node tree contains the original
|
29
|
+
def self.corresponding_node(model_element,node_tree)
|
30
|
+
return node_tree unless model_element.eContainer
|
31
|
+
corresponding_parent_node = corresponding_node(model_element.eContainer,node_tree)
|
32
|
+
containment_pos = containment_pos(model_element)
|
33
|
+
containing_feat = model_element.eContainingFeature
|
34
|
+
|
35
|
+
children = corresponding_parent_node.send(containing_feat)
|
36
|
+
if children.respond_to?(:each)
|
37
|
+
children[containment_pos]
|
38
|
+
else
|
39
|
+
children
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.node_tree_from_code(code)
|
44
|
+
sis = ByteArrayInputStream.new(code.to_java_bytes)
|
45
|
+
node_tree = JavaParser.parse(sis)
|
46
|
+
sis.close
|
47
|
+
node_tree
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.corresponding_node_from_code(model_element,code)
|
51
|
+
sis = ByteArrayInputStream.new(code.to_java_bytes)
|
52
|
+
node_tree = JavaParser.parse(sis)
|
53
|
+
sis.close
|
54
|
+
corresponding_node(model_element,node_tree)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.parse_code(code)
|
58
|
+
node_to_model(node_tree_from_code(code))
|
59
|
+
end
|
60
|
+
|
61
|
+
class Parser < CodeModels::Parser
|
62
|
+
|
63
|
+
def parse_code(code)
|
64
|
+
CodeModels::Java.parse_code(code)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
DefaultParser = Parser.new
|
70
|
+
|
71
|
+
def self.parse_file(path)
|
72
|
+
DefaultParser.parse_file(path)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def self.adapter_specific_class(model_class,ref)
|
78
|
+
return nil unless CodeModels::Java::PROP_ADAPTERS[model_class]
|
79
|
+
CodeModels::Java::PROP_ADAPTERS[model_class][ref.name]
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
curr_dir = File.dirname(__FILE__)
|
2
|
+
Dir[curr_dir+"/../jars/*.jar"].each do |jar|
|
3
|
+
require jar
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'codemodels/java/metamodel'
|
7
|
+
require 'codemodels/java/parser'
|
8
|
+
require 'codemodels/java/model_building'
|
9
|
+
require 'codemodels/java/info_extraction'
|
10
|
+
require 'codemodels/java/language'
|
Binary file
|
@@ -0,0 +1,100 @@
|
|
1
|
+
package com.technoetic.xplanner.tags.displaytag;
|
2
|
+
|
3
|
+
import javax.servlet.jsp.JspException;
|
4
|
+
import javax.servlet.jsp.PageContext;
|
5
|
+
|
6
|
+
import org.apache.commons.logging.Log;
|
7
|
+
import org.apache.commons.logging.LogFactory;
|
8
|
+
import org.displaytag.properties.MediaTypeEnum;
|
9
|
+
import org.displaytag.util.TagConstants;
|
10
|
+
|
11
|
+
import com.technoetic.xplanner.tags.WritableTag;
|
12
|
+
|
13
|
+
|
14
|
+
public class ActionButtonsColumnTag extends org.displaytag.tags.ColumnTag {
|
15
|
+
// TODO: why not use our ColumnTag instead for consistency?
|
16
|
+
//public class ActionButtonsColumnTag extends com.technoetic.xplanner.tags.displaytag.ColumnTag
|
17
|
+
private static Log log = LogFactory.getLog(ActionButtonsColumnTag.class);
|
18
|
+
ActionButtonsTag actionButtonsTag;
|
19
|
+
|
20
|
+
public void setActionButtonsTag(ActionButtonsTag actionButtonsTag)
|
21
|
+
{
|
22
|
+
this.actionButtonsTag = actionButtonsTag;
|
23
|
+
}
|
24
|
+
|
25
|
+
public ActionButtonsColumnTag() {
|
26
|
+
setMedia(MediaTypeEnum.HTML.getName());
|
27
|
+
actionButtonsTag = new ActionButtonsTag();
|
28
|
+
actionButtonsTag.showOnlyActionWithIcon();
|
29
|
+
}
|
30
|
+
|
31
|
+
public void setPageContext(PageContext context)
|
32
|
+
{
|
33
|
+
super.setPageContext(context);
|
34
|
+
actionButtonsTag.setPageContext(context);
|
35
|
+
}
|
36
|
+
|
37
|
+
public void setId(String s)
|
38
|
+
{
|
39
|
+
this.id = s;
|
40
|
+
actionButtonsTag.setId(s);
|
41
|
+
}
|
42
|
+
|
43
|
+
public String getName() {
|
44
|
+
return actionButtonsTag.getName();
|
45
|
+
}
|
46
|
+
|
47
|
+
public void setName(String name) {
|
48
|
+
actionButtonsTag.setName(name);
|
49
|
+
}
|
50
|
+
|
51
|
+
public String getScope() {
|
52
|
+
return actionButtonsTag.getScope();
|
53
|
+
}
|
54
|
+
|
55
|
+
public void setScope(String scope) {
|
56
|
+
actionButtonsTag.setScope(scope);
|
57
|
+
}
|
58
|
+
|
59
|
+
public int doStartTag() throws JspException {
|
60
|
+
try {
|
61
|
+
WritableTag parentTable = (WritableTag) this.getParent();
|
62
|
+
if (!parentTable.isWritable()) {
|
63
|
+
return SKIP_BODY;
|
64
|
+
}
|
65
|
+
if (!getAttributeMap().containsKey(TagConstants.ATTRIBUTE_NOWRAP))
|
66
|
+
getAttributeMap().put(TagConstants.ATTRIBUTE_NOWRAP, "true");
|
67
|
+
|
68
|
+
int status = super.doStartTag();
|
69
|
+
if (status != SKIP_BODY) {
|
70
|
+
return actionButtonsTag.doStartTag();
|
71
|
+
}
|
72
|
+
return status;
|
73
|
+
} catch (Exception e) {
|
74
|
+
throw new JspException(e);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
public int doAfterBody() throws JspException {
|
80
|
+
return actionButtonsTag.doAfterBody();
|
81
|
+
}
|
82
|
+
|
83
|
+
public int doEndTag() throws JspException {
|
84
|
+
actionButtonsTag.doEndTag();
|
85
|
+
try {
|
86
|
+
WritableTag parentTable = (WritableTag) this.getParent();
|
87
|
+
if (!parentTable.isWritable()) {
|
88
|
+
return SKIP_BODY;
|
89
|
+
} else {
|
90
|
+
return super.doEndTag();
|
91
|
+
}
|
92
|
+
} catch (Exception e) {
|
93
|
+
throw new JspException(e);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
public void release() {
|
98
|
+
actionButtonsTag.release();
|
99
|
+
}
|
100
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
package com.technoetic.xplanner.security.config;
|
2
|
+
|
3
|
+
import java.util.ArrayList;
|
4
|
+
import java.util.Collection;
|
5
|
+
import java.util.List;
|
6
|
+
|
7
|
+
public class AuthConstraint {
|
8
|
+
private List<String> roleNames = new ArrayList<String>();
|
9
|
+
|
10
|
+
public void addRoleName(String roleName) {
|
11
|
+
roleNames.add(roleName);
|
12
|
+
}
|
13
|
+
|
14
|
+
public Collection<String> getRoleNames() {
|
15
|
+
return roleNames;
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
package com.technoetic.xplanner.export;
|
2
|
+
|
3
|
+
|
4
|
+
import java.io.ByteArrayOutputStream;
|
5
|
+
|
6
|
+
import javax.servlet.ServletResponseWrapper;
|
7
|
+
import javax.servlet.http.HttpServletResponse;
|
8
|
+
|
9
|
+
import org.hibernate.classic.Session;
|
10
|
+
|
11
|
+
public class CsvExporter implements Exporter {
|
12
|
+
|
13
|
+
private String encoding = "UTF-8";
|
14
|
+
|
15
|
+
private String delimiter = ";";
|
16
|
+
|
17
|
+
public void setEncoding(String encoding) {
|
18
|
+
this.encoding = encoding;
|
19
|
+
}
|
20
|
+
|
21
|
+
public void setDelimiter(String delimiter) {
|
22
|
+
this.delimiter = delimiter;
|
23
|
+
}
|
24
|
+
|
25
|
+
public String getFileExtension() {
|
26
|
+
return "csv";
|
27
|
+
}
|
28
|
+
|
29
|
+
@Override
|
30
|
+
public byte[] export(Session session, Object object) throws ExportException {
|
31
|
+
ByteArrayOutputStream data = new ByteArrayOutputStream();
|
32
|
+
return data.toByteArray();
|
33
|
+
// for (Object item : items) {
|
34
|
+
// BeanWrapperImpl wrapper = new BeanWrapperImpl(item);
|
35
|
+
// String[] properties = {"", ""};
|
36
|
+
// for (String property : properties ) {
|
37
|
+
// Object value = wrapper.getPropertyValue(property);
|
38
|
+
// if (value instanceof Collection) {
|
39
|
+
// Iterator<?> it = ((Collection<?>) value).iterator();
|
40
|
+
// while (it.hasNext()) {
|
41
|
+
// out.print(it.next());
|
42
|
+
// out.print(' ');
|
43
|
+
// }
|
44
|
+
// }
|
45
|
+
// else if (value != null) {
|
46
|
+
// out.print(value);
|
47
|
+
// }
|
48
|
+
// out.print(delimiter);
|
49
|
+
// }
|
50
|
+
// out.println();
|
51
|
+
}
|
52
|
+
|
53
|
+
@Override
|
54
|
+
public void initializeHeaders(HttpServletResponse response) {
|
55
|
+
response.setContentType("text/csv; charset=" + encoding);
|
56
|
+
// response.setCharacterEncoding(encoding);
|
57
|
+
}
|
58
|
+
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006 Your Corporation. All Rights Reserved.
|
3
|
+
*/
|
4
|
+
|
5
|
+
package com.technoetic.xplanner.forms;
|
6
|
+
|
7
|
+
import java.util.ArrayList;
|
8
|
+
import java.util.Iterator;
|
9
|
+
import java.util.List;
|
10
|
+
|
11
|
+
import javax.servlet.http.HttpServletRequest;
|
12
|
+
|
13
|
+
import org.apache.struts.action.ActionErrors;
|
14
|
+
import org.apache.struts.action.ActionMapping;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Created by IntelliJ IDEA.
|
18
|
+
* User: SG0897500
|
19
|
+
* Date: Mar 6, 2006
|
20
|
+
* Time: 11:58:37 AM
|
21
|
+
* To change this template use File | Settings | File Templates.
|
22
|
+
*/
|
23
|
+
public class ReorderStoriesForm extends AbstractEditorForm {
|
24
|
+
|
25
|
+
public static final String INVALID_ORDER_NUMBER = "story.editor.invalid.order.number";
|
26
|
+
private List<String> storyIds = new ArrayList<String>();
|
27
|
+
private List<String> orderNos = new ArrayList<String>();
|
28
|
+
private String iterationId;
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
|
32
|
+
ActionErrors errors = new ActionErrors();
|
33
|
+
if (orderNos != null) {
|
34
|
+
for (Iterator<String> iterator = orderNos.iterator(); iterator.hasNext();) {
|
35
|
+
String orderValue = iterator.next();
|
36
|
+
try {
|
37
|
+
Double.parseDouble(orderValue);
|
38
|
+
} catch (NumberFormatException e) {
|
39
|
+
error(errors, INVALID_ORDER_NUMBER, new Object[] {orderValue});
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return errors;
|
44
|
+
}
|
45
|
+
|
46
|
+
public List<String> getStoryIds() {
|
47
|
+
return storyIds;
|
48
|
+
}
|
49
|
+
|
50
|
+
public void setStoryIds(List<String> storyIds) {
|
51
|
+
this.storyIds = storyIds;
|
52
|
+
}
|
53
|
+
|
54
|
+
public void setStoryId(int index, String storyId) {
|
55
|
+
ensureSize(storyIds, index + 1);
|
56
|
+
storyIds.set(index, storyId);
|
57
|
+
}
|
58
|
+
|
59
|
+
public String getStoryId(int index) {
|
60
|
+
return storyIds.get(index);
|
61
|
+
}
|
62
|
+
|
63
|
+
public int getStoryIdAsInt(int index) {
|
64
|
+
return Integer.parseInt(getStoryId(index));
|
65
|
+
}
|
66
|
+
|
67
|
+
public int getStoryCount() {
|
68
|
+
return storyIds.size();
|
69
|
+
}
|
70
|
+
|
71
|
+
public List<String> getOrderNos() {
|
72
|
+
return orderNos;
|
73
|
+
}
|
74
|
+
|
75
|
+
public void setOrderNos(List<String> orderNos) {
|
76
|
+
this.orderNos = orderNos;
|
77
|
+
}
|
78
|
+
|
79
|
+
public void setOrderNo(int index, String orderNo) {
|
80
|
+
ensureSize(orderNos, index + 1);
|
81
|
+
orderNos.set(index, orderNo);
|
82
|
+
}
|
83
|
+
|
84
|
+
public String getOrderNo(int index) {
|
85
|
+
return orderNos.get(index);
|
86
|
+
}
|
87
|
+
|
88
|
+
public int getOrderNoAsInt(int index) {
|
89
|
+
return (int) Double.parseDouble(getOrderNo(index));
|
90
|
+
}
|
91
|
+
|
92
|
+
public String getIterationId() {
|
93
|
+
return iterationId;
|
94
|
+
}
|
95
|
+
|
96
|
+
public void setIterationId(String iterationId) {
|
97
|
+
this.iterationId = iterationId;
|
98
|
+
}
|
99
|
+
|
100
|
+
}
|
@@ -0,0 +1,192 @@
|
|
1
|
+
package com.technoetic.xplanner.domain;
|
2
|
+
|
3
|
+
import java.util.ArrayList;
|
4
|
+
import java.util.Date;
|
5
|
+
import java.util.List;
|
6
|
+
|
7
|
+
import junit.framework.TestCase;
|
8
|
+
import net.sf.xplanner.domain.Iteration;
|
9
|
+
import net.sf.xplanner.domain.Task;
|
10
|
+
import net.sf.xplanner.domain.TimeEntry;
|
11
|
+
import net.sf.xplanner.domain.UserStory;
|
12
|
+
|
13
|
+
public class TestIteration extends TestCase {
|
14
|
+
Iteration iteration = new Iteration();
|
15
|
+
|
16
|
+
public void testGetActualHoursWithNoStories() throws Exception {
|
17
|
+
assertEquals(0.0d, iteration.getCachedActualHours(),0.0);
|
18
|
+
}
|
19
|
+
|
20
|
+
public void testGetEstimatedHoursWithNoStories() throws Exception {
|
21
|
+
assertEquals(0.0d, iteration.getEstimatedHours(),0.0);
|
22
|
+
}
|
23
|
+
|
24
|
+
public void testGetAdjustedEstimatedHoursWithNoStories() throws Exception {
|
25
|
+
assertEquals(0.0d, iteration.getAdjustedEstimatedHours(),0.0);
|
26
|
+
}
|
27
|
+
|
28
|
+
public void testGetRemainingHours() throws Exception {
|
29
|
+
assertEquals(0.0d, iteration.getTaskRemainingHours(),0.0);
|
30
|
+
}
|
31
|
+
|
32
|
+
public void testGetEstimatedOriginalHours() throws Exception {
|
33
|
+
assertEquals(0.0d, iteration.getTaskEstimatedOriginalHours(),0.0);
|
34
|
+
List<UserStory> stories = new ArrayList<UserStory>();
|
35
|
+
UserStory story = new UserStory();
|
36
|
+
//start iteration
|
37
|
+
story.setEstimatedOriginalHours(new Double(10.0));
|
38
|
+
stories.add(story);
|
39
|
+
List<Task> tasks = new ArrayList();
|
40
|
+
Task task = new Task();
|
41
|
+
task.setUserStory(story);
|
42
|
+
task.setEstimatedOriginalHours(3);
|
43
|
+
tasks.add(task);
|
44
|
+
story.setTasks(tasks);
|
45
|
+
iteration.setUserStories(stories);
|
46
|
+
assertEquals(3.0d, iteration.getTaskEstimatedOriginalHours(),0.0);
|
47
|
+
task.setDisposition(TaskDisposition.ADDED);
|
48
|
+
assertEquals(0.0d, iteration.getTaskEstimatedOriginalHours(),0.0);
|
49
|
+
}
|
50
|
+
|
51
|
+
public void testGetOverestimatedHours() throws Exception {
|
52
|
+
Iteration iteration = setUpTestIteration();
|
53
|
+
assertEquals(7.0d, iteration.getTaskOverestimatedHours(),0.0);
|
54
|
+
}
|
55
|
+
|
56
|
+
public void testGetOverestimatedOriginalHours() throws Exception {
|
57
|
+
Iteration iteration = setUpTestIteration();
|
58
|
+
assertEquals(4.0d, iteration.getOverestimatedOriginalHours(),0.0);
|
59
|
+
}
|
60
|
+
|
61
|
+
public void testGetUnderestimatedHours() throws Exception {
|
62
|
+
Iteration iteration = setUpTestIteration();
|
63
|
+
assertEquals(1.0d, iteration.getTaskUnderestimatedOriginalHours(),0.0);
|
64
|
+
}
|
65
|
+
|
66
|
+
public void testGetUnderestimatedOriginalHours() throws Exception {
|
67
|
+
Iteration iteration = setUpTestIteration();
|
68
|
+
assertEquals(1.0d, iteration.getUnderestimatedOriginalHours(),0.0);
|
69
|
+
}
|
70
|
+
|
71
|
+
public void testGetAddedHours() throws Exception {
|
72
|
+
Iteration iteration = setUpTestIteration();
|
73
|
+
assertEquals(5.0d, iteration.getEstimatedHoursOfAddedTasks(),0.0);
|
74
|
+
}
|
75
|
+
|
76
|
+
public void testGetAddedOrDiscoveredOriginalHours() throws Exception {
|
77
|
+
Iteration iteration = setUpTestIteration();
|
78
|
+
assertEquals(5.0d, iteration.getAddedOriginalHours(),0.0);
|
79
|
+
}
|
80
|
+
|
81
|
+
public void testGetPostponedHours() throws Exception {
|
82
|
+
Iteration iteration = setUpTestIteration();
|
83
|
+
assertEquals(2.0d, iteration.getPostponedHours(),0.0);
|
84
|
+
}
|
85
|
+
|
86
|
+
public void testIsFuture() throws Exception
|
87
|
+
{
|
88
|
+
Iteration iteration = new Iteration();
|
89
|
+
iteration.setStartDate(new Date(System.currentTimeMillis() - 7200000));
|
90
|
+
assertFalse(iteration.isFuture());
|
91
|
+
iteration.setStartDate(new Date(System.currentTimeMillis() + 7200000));
|
92
|
+
assertTrue(iteration.isFuture());
|
93
|
+
}
|
94
|
+
|
95
|
+
public void testIsActive() throws Exception
|
96
|
+
{
|
97
|
+
Iteration iteration = new Iteration();
|
98
|
+
iteration.setIterationStatus(IterationStatus.INACTIVE);
|
99
|
+
assertFalse(iteration.isActive());
|
100
|
+
}
|
101
|
+
|
102
|
+
public void testIsCurrent() throws Exception
|
103
|
+
{
|
104
|
+
Iteration iteration = new Iteration();
|
105
|
+
iteration.setStartDate(new Date(System.currentTimeMillis() - 2000));
|
106
|
+
iteration.setEndDate(new Date(System.currentTimeMillis() - 1000));
|
107
|
+
assertFalse("Past iteration", iteration.isCurrent());
|
108
|
+
iteration.setStartDate(new Date(System.currentTimeMillis() - 1000));
|
109
|
+
iteration.setEndDate(new Date(System.currentTimeMillis() + 1000));
|
110
|
+
assertTrue("Current iteration", iteration.isCurrent());
|
111
|
+
iteration.setStartDate(new Date(System.currentTimeMillis() + 1000));
|
112
|
+
iteration.setEndDate(new Date(System.currentTimeMillis() + 2000));
|
113
|
+
assertFalse("Future iteration", iteration.isCurrent());
|
114
|
+
}
|
115
|
+
|
116
|
+
public void testGetCompletedOriginalHours() throws Exception {
|
117
|
+
Iteration iteration = setUpTestIteration();
|
118
|
+
assertEquals(9.0, iteration.getCompletedOriginalHours(), 0.0);
|
119
|
+
}
|
120
|
+
|
121
|
+
public void testGetCompletedHours() throws Exception {
|
122
|
+
Iteration iteration = setUpTestIteration();
|
123
|
+
assertEquals(6.0, iteration.getTaskActualCompletedHours(), 0.0);
|
124
|
+
}
|
125
|
+
|
126
|
+
private Iteration setUpTestIteration() throws Exception {
|
127
|
+
Iteration iteration = new Iteration();
|
128
|
+
iteration.setIterationStatus(IterationStatus.INACTIVE);
|
129
|
+
|
130
|
+
List tasks1 = new ArrayList();
|
131
|
+
List tasks2 = new ArrayList();
|
132
|
+
ArrayList twoHourTimeEntry = getTimeEntriesForDurationInHours(2);
|
133
|
+
|
134
|
+
UserStory story1 = new UserStory();
|
135
|
+
story1.setDisposition(StoryDisposition.ADDED);
|
136
|
+
story1.setEstimatedOriginalHours(new Double(10.0));
|
137
|
+
|
138
|
+
UserStory story2 = new UserStory();
|
139
|
+
story2.setDisposition(StoryDisposition.CARRIED_OVER);
|
140
|
+
story2.setPostponedHours(2.0d);
|
141
|
+
story2.setEstimatedOriginalHours(new Double(10.0));
|
142
|
+
|
143
|
+
Task task1 = new Task();
|
144
|
+
task1.setEstimatedHours(1.0);
|
145
|
+
task1.setTimeEntries(twoHourTimeEntry);
|
146
|
+
task1.setUserStory(story1);
|
147
|
+
tasks1.add(task1);
|
148
|
+
|
149
|
+
tasks2.add(createTask(4.0d, twoHourTimeEntry, TaskDisposition.PLANNED, story2));
|
150
|
+
tasks2.add(createTask(4.0d, twoHourTimeEntry, TaskDisposition.DISCOVERED, story2));
|
151
|
+
|
152
|
+
story1.setTasks(tasks1);
|
153
|
+
|
154
|
+
story2.setTasks(tasks2);
|
155
|
+
|
156
|
+
List userStories = new ArrayList();
|
157
|
+
userStories.add(story1);
|
158
|
+
userStories.add(story2);
|
159
|
+
iteration.setUserStories(userStories);
|
160
|
+
iteration.start();
|
161
|
+
task1.setEstimatedHours(5.0);
|
162
|
+
task1.setCompleted(true);
|
163
|
+
task1.setDisposition(TaskDisposition.ADDED);
|
164
|
+
return iteration;
|
165
|
+
}
|
166
|
+
|
167
|
+
private Task createTask(double estimatedHours, ArrayList twoHourTimeEntry, TaskDisposition disposition) {
|
168
|
+
Task task2 = new Task();
|
169
|
+
task2.setEstimatedHours(estimatedHours);
|
170
|
+
task2.setTimeEntries(twoHourTimeEntry);
|
171
|
+
task2.setCompleted(true);
|
172
|
+
task2.setDisposition(disposition);
|
173
|
+
return task2;
|
174
|
+
}
|
175
|
+
|
176
|
+
private Task createTask(double estimatedHours, ArrayList twoHourTimeEntry, TaskDisposition disposition, UserStory story) {
|
177
|
+
Task task2 = createTask(estimatedHours, twoHourTimeEntry, disposition);
|
178
|
+
task2.setUserStory(story);
|
179
|
+
return task2;
|
180
|
+
}
|
181
|
+
|
182
|
+
private ArrayList getTimeEntriesForDurationInHours(int duration) {
|
183
|
+
long now = new Date().getTime();
|
184
|
+
TimeEntry timeEntry = new TimeEntry();
|
185
|
+
timeEntry.setStartTime(new Date(now - 7200000));
|
186
|
+
timeEntry.setEndTime(new Date(now));
|
187
|
+
timeEntry.setDuration(duration);
|
188
|
+
ArrayList timeEntries = new ArrayList();
|
189
|
+
timeEntries.add(timeEntry);
|
190
|
+
return timeEntries;
|
191
|
+
}
|
192
|
+
}
|