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.AddComponentCommand;
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 BugzillaAddComponentCommand extends
30 AbstractCommand<AddComponentCommand> implements AddComponentCommand
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 = "editcomponents.cgi";
51
52
53
54
55
56
57
58 private static final String EXPECTED_PAGE_TITLE_CREATED = "Component Created";
59
60
61
62
63
64
65
66 private static final String EXPECTED_PAGE_TITLE_EXISTS =
67 "Component Already Exists";
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 public BugzillaAddComponentCommand(
87
88 final CommandArgument<AddComponentCommand> product,
89 final CommandArgument<AddComponentCommand> component,
90 final CommandArgument<AddComponentCommand> description,
91 final CommandArgument<AddComponentCommand> initialOwner,
92 final CommandArgument<AddComponentCommand> token)
93 {
94 super(SERVICE, attachDefaulArguments(product, component, description,
95 initialOwner, token));
96 }
97
98
99
100
101
102
103
104
105
106 private static List<CommandArgument<AddComponentCommand>> attachDefaulArguments(
107 final CommandArgument<AddComponentCommand> product,
108 final CommandArgument<AddComponentCommand> component,
109 final CommandArgument<AddComponentCommand> description,
110 final CommandArgument<AddComponentCommand> initialOwner,
111 final CommandArgument<AddComponentCommand> token)
112 {
113 final List<CommandArgument<AddComponentCommand>> allArguments =
114 new ArrayList<CommandArgument<AddComponentCommand>>(3);
115 final CommandArgument<AddComponentCommand> action =
116 CommandArgument.create(AddComponentCommand.Parameter.ACTION, "new");
117 allArguments.add(action);
118 allArguments.add(product);
119 allArguments.add(component);
120 allArguments.add(description);
121 allArguments.add(initialOwner);
122 allArguments.add(token);
123 return allArguments;
124 }
125
126
127
128
129
130
131
132
133
134
135 @Override
136 protected Expectation checkExpectation(final Page page)
137 {
138 final Expectation expectation =
139 BugzillaCommandUtils.createExpectation(page,
140 EXPECTED_PAGE_TITLE_CREATED, EXPECTED_PAGE_TITLE_EXISTS);
141 return expectation;
142 }
143
144
145
146
147
148
149 @Override
150 protected String getCommandResultDescription(final Page page,
151 final Expectation expectation)
152 {
153 final CommandArgument<AddComponentCommand> componentArg =
154 getArgument(AddComponentCommand.Parameter.COMPONENT);
155 final String expectationFlag = expectation.getFlag();
156
157 final String messageSuffix;
158 if (EXPECTED_PAGE_TITLE_CREATED.equals(expectationFlag))
159 {
160 messageSuffix = "has been created.";
161 }
162 else if (EXPECTED_PAGE_TITLE_EXISTS.equals(expectationFlag))
163 {
164 messageSuffix = "already existed.";
165 }
166 else
167 {
168 messageSuffix = "failed to be created.";
169 }
170
171 return "Component '" + componentArg.getValue() + "' " + messageSuffix;
172 }
173
174
175
176 }