View Javadoc

1   /*
2    * Copyright 2012 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Implementation of the {@link UpdateProductCommand} for Bugzilla.
28   */
29  public final class BugzillaUpdateProductCommand extends
30      AbstractCommand<UpdateProductCommand> implements UpdateProductCommand
31  {
32    // ********************************* Fields *********************************
33  
34    // --- constants ------------------------------------------------------------
35  
36    /**
37     * The class version identifier.
38     * <p>
39     * The value of this constant is {@value}.
40     * </p>
41     */
42    private static final long serialVersionUID = 1L;
43  
44    /**
45     * The service on the command target to call.
46     * <p>
47     * The value of this constant is {@value}.
48     * </p>
49     */
50    private static final String SERVICE = "editproducts.cgi";
51  
52    /**
53     * The title of the expected page.
54     * <p>
55     * The value of this constant is {@value}.
56     * </p>
57     */
58    private static final String EXPECTED_PAGE_TITLE = "Updating Product";
59  
60    // --- members --------------------------------------------------------------
61  
62    // ****************************** Initializer *******************************
63  
64    // ****************************** Constructors ******************************
65  
66    // CHECKSTYLE:OFF
67  
68    /**
69     * Default constructor.
70     *
71     * @param oldProduct the current name of the product.
72     * @param product the product to add the version to.
73     * @param description the description to the product.
74     * @param defaultMilestone the initial default milestone of the product.
75     * @param token the token from the previous command to help the browser to
76     *          secure the request.
77     */
78    public BugzillaUpdateProductCommand( // NOPMD
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    // ****************************** Inner Classes *****************************
90  
91    // ********************************* Methods ********************************
92  
93    // --- init -----------------------------------------------------------------
94  
95    private static List<CommandArgument<UpdateProductCommand>> attachDefaulArguments( // NOPMD
96        final CommandArgument<UpdateProductCommand> oldProduct, // NOPMD
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   // CHECKSTYLE:ON
119 
120   // --- get&set --------------------------------------------------------------
121 
122   // --- business -------------------------------------------------------------
123 
124   /**
125    * {@inheritDoc}
126    *
127    * @see de.smartics.maven.issue.command.AbstractCommand#checkExpectation(de.smartics.maven.issue.command.CommandResult.Page)
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    * {@inheritDoc}
141    *
142    * @see de.smartics.maven.issue.command.AbstractCommand#getCommandResultDescription(Page,Expectation)
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   // --- object basics --------------------------------------------------------
162 
163 }