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 public BugzillaAddProductCommand(
89 final CommandArgument<AddProductCommand> classification,
90 final CommandArgument<AddProductCommand> product,
91 final CommandArgument<AddProductCommand> description,
92 final CommandArgument<AddProductCommand> defaultMilestone,
93 final CommandArgument<AddProductCommand> version,
94 final CommandArgument<AddProductCommand> token)
95 {
96 super(SERVICE, attachDefaulArguments(classification, product, description,
97 defaultMilestone, version, token));
98 }
99
100
101
102
103
104
105
106 private static List<CommandArgument<AddProductCommand>> attachDefaulArguments(
107 final CommandArgument<AddProductCommand> classification,
108 final CommandArgument<AddProductCommand> product,
109 final CommandArgument<AddProductCommand> description,
110 final CommandArgument<AddProductCommand> defaultMilestone,
111 final CommandArgument<AddProductCommand> version,
112 final CommandArgument<AddProductCommand> token)
113 {
114 final List<CommandArgument<AddProductCommand>> allArguments =
115 new ArrayList<CommandArgument<AddProductCommand>>(8);
116 final CommandArgument<AddProductCommand> action =
117 CommandArgument.create(AddProductCommand.Parameter.ACTION, "new");
118 allArguments.add(action);
119 allArguments.add(classification);
120 allArguments.add(product);
121 allArguments.add(description);
122 allArguments.add(defaultMilestone);
123 allArguments.add(version);
124 final CommandArgument<AddProductCommand> active =
125 CommandArgument.create(AddProductCommand.Parameter.IS_ACTIVE, "1");
126 allArguments.add(active);
127 allArguments.add(token);
128 return allArguments;
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142 @Override
143 protected Expectation checkExpectation(final Page page)
144 {
145 final boolean expected = EXPECTED_PAGE_TITLE.equals(page.getTitle());
146 final Expectation expectation =
147 new Expectation(expected, EXPECTED_PAGE_TITLE, expected
148 ? EXPECTED_PAGE_TITLE : Expectation.UNKNOWN_FLAG);
149 return expectation;
150 }
151
152
153
154
155
156
157 @Override
158 protected String getCommandResultDescription(final Page page,
159 final Expectation expectation)
160 {
161 final CommandArgument<AddProductCommand> productArg =
162 getArgument(AddProductCommand.Parameter.PRODUCT);
163 final String expectationFlag = expectation.getFlag();
164 if (EXPECTED_PAGE_TITLE.equals(expectationFlag))
165 {
166 return "Successfully added product '" + productArg.getValue() + "'.";
167 }
168 else if (SUSPICIOUS_ACTION.equals(page.getTitle()))
169 {
170 return "Failed to add product '" + productArg.getValue()
171 + "'. Maybe the classification is unknown?"
172 + " Please check parameters below.";
173 }
174 else
175 {
176 return "Failed to add product '" + productArg.getValue() + "'.";
177 }
178 }
179
180
181
182 }