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