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.CommandArgument;
23 import de.smartics.maven.issue.command.CommandResult.Page;
24 import de.smartics.maven.issue.command.UpdateProductCommand;
25
26
27
28
29 public final class BugzillaUpdateProductCommand extends
30 AbstractCommand<UpdateProductCommand> implements UpdateProductCommand
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 = "Updating Product";
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 public BugzillaUpdateProductCommand(
79 final CommandArgument<UpdateProductCommand> oldProduct,
80 final CommandArgument<UpdateProductCommand> product,
81 final CommandArgument<UpdateProductCommand> description,
82 final CommandArgument<UpdateProductCommand> defaultMilestone,
83 final CommandArgument<UpdateProductCommand> token)
84 {
85 super(SERVICE, attachDefaulArguments(oldProduct, product, description,
86 defaultMilestone, token));
87 }
88
89
90
91
92
93
94
95 private static List<CommandArgument<UpdateProductCommand>> attachDefaulArguments(
96 final CommandArgument<UpdateProductCommand> oldProduct,
97 final CommandArgument<UpdateProductCommand> product,
98 final CommandArgument<UpdateProductCommand> description,
99 final CommandArgument<UpdateProductCommand> defaultMilestone,
100 final CommandArgument<UpdateProductCommand> token)
101 {
102 final List<CommandArgument<UpdateProductCommand>> allArguments =
103 new ArrayList<CommandArgument<UpdateProductCommand>>(8);
104 final CommandArgument<UpdateProductCommand> action =
105 CommandArgument.create(UpdateProductCommand.Parameter.ACTION, "update");
106 allArguments.add(action);
107 allArguments.add(oldProduct);
108 allArguments.add(product);
109 allArguments.add(description);
110 allArguments.add(defaultMilestone);
111 final CommandArgument<UpdateProductCommand> active =
112 CommandArgument.create(UpdateProductCommand.Parameter.IS_ACTIVE, "1");
113 allArguments.add(active);
114 allArguments.add(token);
115 return allArguments;
116 }
117
118
119
120
121
122
123
124
125
126
127
128
129 @Override
130 protected Expectation checkExpectation(final Page page)
131 {
132 final boolean expected = (page.getTitle().startsWith(EXPECTED_PAGE_TITLE));
133 final Expectation expectation =
134 new Expectation(expected, EXPECTED_PAGE_TITLE, expected
135 ? EXPECTED_PAGE_TITLE : Expectation.UNKNOWN_FLAG);
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<UpdateProductCommand> productArg =
149 getArgument(UpdateProductCommand.Parameter.PRODUCT);
150 final String expectationFlag = expectation.getFlag();
151 if (EXPECTED_PAGE_TITLE.equals(expectationFlag))
152 {
153 return "Successfully updated product '" + productArg.getValue() + "'.";
154 }
155 else
156 {
157 return "Failed to update product '" + productArg.getValue() + "'.";
158 }
159 }
160
161
162
163 }