1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.bugzilla.command;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import de.smartics.maven.issue.command.AbstractCommand;
22 import de.smartics.maven.issue.command.AddMilestoneCommand;
23 import de.smartics.maven.issue.command.CommandArgument;
24 import de.smartics.maven.issue.command.CommandResult.Page;
25
26
27
28
29 public final class BugzillaAddMilestoneCommand extends
30 AbstractCommand<AddMilestoneCommand> implements AddMilestoneCommand
31 {
32
33
34
35
36
37
38
39
40
41
42 private static final long serialVersionUID = 1L;
43
44
45
46
47
48
49
50 private static final String SERVICE = "editmilestones.cgi";
51
52
53
54
55
56
57
58 private static final String EXPECTED_PAGE_TITLE_CREATED = "Milestone Created";
59
60
61
62
63
64
65
66 private static final String EXPECTED_PAGE_TITLE_EXISTS =
67 "Milestone Already Exists";
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 public BugzillaAddMilestoneCommand(
85
86 final CommandArgument<AddMilestoneCommand> product,
87 final CommandArgument<AddMilestoneCommand> milestone,
88 final CommandArgument<AddMilestoneCommand> sortkey,
89 final CommandArgument<AddMilestoneCommand> token)
90 {
91 super(SERVICE, attachDefaulArguments(product, milestone, sortkey, token));
92 }
93
94
95
96
97
98
99
100 private static List<CommandArgument<AddMilestoneCommand>> attachDefaulArguments(
101 final CommandArgument<AddMilestoneCommand> product,
102 final CommandArgument<AddMilestoneCommand> milestone,
103 final CommandArgument<AddMilestoneCommand> sortkey,
104 final CommandArgument<AddMilestoneCommand> token)
105 {
106 final List<CommandArgument<AddMilestoneCommand>> allArguments =
107 new ArrayList<CommandArgument<AddMilestoneCommand>>(3);
108 final CommandArgument<AddMilestoneCommand> action =
109 CommandArgument.create(AddMilestoneCommand.Parameter.ACTION, "new");
110 allArguments.add(action);
111 allArguments.add(product);
112 allArguments.add(milestone);
113 if (sortkey.hasValue())
114 {
115 allArguments.add(sortkey);
116 }
117 allArguments.add(token);
118 return allArguments;
119 }
120
121
122
123
124
125
126
127
128
129
130 @Override
131 protected Expectation checkExpectation(final Page page)
132 {
133 final Expectation expectation =
134 BugzillaCommandUtils.createExpectation(page,
135 EXPECTED_PAGE_TITLE_CREATED, EXPECTED_PAGE_TITLE_EXISTS);
136 return expectation;
137 }
138
139
140
141
142
143
144 @Override
145 protected String getCommandResultDescription(final Page page,
146 final Expectation expectation)
147 {
148 final CommandArgument<AddMilestoneCommand> milestoneArg =
149 getArgument(AddMilestoneCommand.Parameter.MILESTONE);
150 final String expectationFlag = expectation.getFlag();
151
152 final String messageSuffix;
153 if (EXPECTED_PAGE_TITLE_CREATED.equals(expectationFlag))
154 {
155 messageSuffix = "has been created.";
156 }
157 else if (EXPECTED_PAGE_TITLE_EXISTS.equals(expectationFlag))
158 {
159 messageSuffix = "already existed.";
160 }
161 else
162 {
163 messageSuffix = "failed to be created.";
164 }
165
166 return "Milestone '" + milestoneArg.getValue() + "' " + messageSuffix;
167 }
168
169
170
171 }