1 /* 2 * Copyright 2012-2013 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.LoginCommand; 25 26 /** 27 * Implementation of the {@link LoginCommand} for Bugzilla. 28 */ 29 public final class BugzillaLoginCommand extends AbstractCommand<LoginCommand> 30 implements LoginCommand 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 = "index.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 = "Bugzilla Main Page"; 59 60 // --- members -------------------------------------------------------------- 61 62 // ****************************** Initializer ******************************* 63 64 // ****************************** Constructors ****************************** 65 66 /** 67 * Default constructor. 68 * 69 * @param login the login name for authentication. 70 * @param password the password for authentication. 71 */ 72 public BugzillaLoginCommand(final CommandArgument<LoginCommand> login, 73 final CommandArgument<LoginCommand> password) 74 { 75 super(SERVICE, attachDefaulArguments(login, password)); 76 } 77 78 // ****************************** Inner Classes ***************************** 79 80 // ********************************* Methods ******************************** 81 82 // --- init ----------------------------------------------------------------- 83 84 private static List<CommandArgument<LoginCommand>> attachDefaulArguments( 85 final CommandArgument<LoginCommand> login, 86 final CommandArgument<LoginCommand> password) 87 { 88 final List<CommandArgument<LoginCommand>> allArguments = 89 new ArrayList<CommandArgument<LoginCommand>>(2); 90 allArguments.add(login); 91 allArguments.add(password); 92 return allArguments; 93 } 94 95 // --- get&set -------------------------------------------------------------- 96 97 // --- business ------------------------------------------------------------- 98 99 /** 100 * {@inheritDoc} 101 * 102 * @see de.smartics.maven.issue.command.AbstractCommand#checkExpectation(de.smartics.maven.issue.command.CommandResult.Page) 103 */ 104 @Override 105 protected Expectation checkExpectation(final Page page) 106 { 107 final boolean expected = EXPECTED_PAGE_TITLE.equals(page.getTitle()); 108 final Expectation expectation = 109 new Expectation(expected, EXPECTED_PAGE_TITLE, expected 110 ? EXPECTED_PAGE_TITLE : Expectation.UNKNOWN_FLAG); 111 return expectation; 112 } 113 114 /** 115 * {@inheritDoc} 116 * 117 * @see de.smartics.maven.issue.command.AbstractCommand#getCommandResultDescription(Page,Expectation) 118 */ 119 @Override 120 protected String getCommandResultDescription(final Page page, 121 final Expectation expectation) 122 { 123 final String expectationFlag = expectation.getFlag(); 124 if (EXPECTED_PAGE_TITLE.equals(expectationFlag)) 125 { 126 return "Successful login to Bugzilla."; 127 } 128 else 129 { 130 return "Failed to login to Bugzilla."; 131 } 132 } 133 134 // --- object basics -------------------------------------------------------- 135 136 }