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.AddProductCommand;
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 BugzillaAddProductCommand extends
30 AbstractCommand<AddProductCommand> implements AddProductCommand
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 = "editproducts.cgi";
51
52
53
54
55
56
57
58 private static final String EXPECTED_PAGE_TITLE = "Product Created";
59
60
61
62
63
64
65
66
67 private static final String SUSPICIOUS_ACTION = "Suspicious Action";
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 public BugzillaAddProductCommand(
92
93 final CommandArgument<AddProductCommand> classification,
94 final CommandArgument<AddProductCommand> product,
95 final CommandArgument<AddProductCommand> description,
96 final CommandArgument<AddProductCommand> defaultMilestone,
97 final CommandArgument<AddProductCommand> version,
98 final CommandArgument<AddProductCommand> token,
99 final CommandArgument<AddProductCommand> component,
100 final CommandArgument<AddProductCommand> componentDescription,
101 final CommandArgument<AddProductCommand> componentInitialOwner)
102 {
103 super(SERVICE, attachDefaulArguments(classification, product, description,
104 defaultMilestone, version, token, component, componentDescription,
105 componentInitialOwner));
106 }
107
108
109
110
111
112
113
114 private static List<CommandArgument<AddProductCommand>> attachDefaulArguments(
115
116 final CommandArgument<AddProductCommand> classification,
117 final CommandArgument<AddProductCommand> product,
118 final CommandArgument<AddProductCommand> description,
119 final CommandArgument<AddProductCommand> defaultMilestone,
120 final CommandArgument<AddProductCommand> version,
121 final CommandArgument<AddProductCommand> token,
122 final CommandArgument<AddProductCommand> component,
123 final CommandArgument<AddProductCommand> componentDescription,
124 final CommandArgument<AddProductCommand> componentInitialOwner)
125 {
126 final List<CommandArgument<AddProductCommand>> allArguments =
127 new ArrayList<CommandArgument<AddProductCommand>>(8);
128 final CommandArgument<AddProductCommand> action =
129 CommandArgument.create(AddProductCommand.Parameter.ACTION, "new");
130 allArguments.add(action);
131 allArguments.add(classification);
132 allArguments.add(product);
133 allArguments.add(description);
134 allArguments.add(defaultMilestone);
135 allArguments.add(version);
136 final CommandArgument<AddProductCommand> active =
137 CommandArgument.create(AddProductCommand.Parameter.IS_ACTIVE, "1");
138 allArguments.add(active);
139 allArguments.add(token);
140 if (component != null)
141 {
142 allArguments.add(component);
143 }
144 if (componentDescription != null)
145 {
146 allArguments.add(componentDescription);
147 }
148 if (componentInitialOwner != null)
149 {
150 allArguments.add(componentInitialOwner);
151 }
152 return allArguments;
153 }
154
155
156
157
158
159
160
161
162
163
164
165
166 @Override
167 protected Expectation checkExpectation(final Page page)
168 {
169 final boolean expected = EXPECTED_PAGE_TITLE.equals(page.getTitle());
170 final Expectation expectation =
171 new Expectation(expected, EXPECTED_PAGE_TITLE, expected
172 ? EXPECTED_PAGE_TITLE : Expectation.UNKNOWN_FLAG);
173 return expectation;
174 }
175
176
177
178
179
180
181 @Override
182 protected String getCommandResultDescription(final Page page,
183 final Expectation expectation)
184 {
185 final CommandArgument<AddProductCommand> productArg =
186 getArgument(AddProductCommand.Parameter.PRODUCT);
187 final String expectationFlag = expectation.getFlag();
188 if (EXPECTED_PAGE_TITLE.equals(expectationFlag))
189 {
190 return "Successfully added product '" + productArg.getValue() + "'.";
191 }
192 else if (SUSPICIOUS_ACTION.equals(page.getTitle()))
193 {
194 return "Failed to add product '" + productArg.getValue()
195 + "'. Maybe the classification is unknown?"
196 + " Please check parameters below.";
197 }
198 else
199 {
200 return "Failed to add product '" + productArg.getValue() + "'.";
201 }
202 }
203
204
205
206 }