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