KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > isac > plugins > httpinjector10 > actions > HttpInjectorTests


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.isac.plugins.httpinjector10.actions;
24
25 import org.apache.commons.httpclient.Header;
26 import org.objectweb.clif.isac.plugins.httpinjector10.SessionObject;
27 import org.objectweb.clif.scenario.util.isac.engine.IsacScenarioEngine;
28 import org.objectweb.util.monolog.api.Logger;
29
30 /**
31  * This class implements the matrix test methods
32  *
33  * @author JC Meillaud
34  * @author A Peyrard
35  */

36 public class HttpInjectorTests {
37
38     // logger
39
static protected Logger log = IsacScenarioEngine.logger
40             .getLogger(HttpInjectorTests.class.getName());
41     /**
42      * Simple test to know if the last response was a not found Http Status Code
43      *
44      * @param sessionObject
45      * The SessionObject where we get information about the last
46      * statuscode
47      * @return true if it was a 404 error
48      */

49
50     public static boolean is404Response(SessionObject sessionObject) {
51         return (sessionObject.getLastStatusCode() == 404);
52     }
53
54     /**
55      * General test to know if the last response Status code is equal to
56      * statusCode
57      *
58      * @param sessionObject
59      * The SessionObject where we get information about the last
60      * statuscode
61      * @param statusCode
62      * the code
63      * @return true if it was an error equal to statusCode
64      */

65     public static boolean isStatusCodeResponse(SessionObject sessionObject,
66             int statusCode) {
67
68         return (sessionObject.getLastStatusCode() == statusCode);
69     }
70
71     /**
72      * Test to know if a header value of the last executed method is equal to
73      * the one given
74      *
75      * @param sessionObject
76      * The SessionObject where we get information about the last
77      * headers
78      * @param headerParameterType
79      * the name of the header value to compare
80      * @param headerParameterValue
81      * the value of the header value to compare
82      * @return
83      */

84     public static boolean isHeaderValue(SessionObject sessionObject,
85             String JavaDoc headerParameterType, String JavaDoc headerParameterValue) {
86         Header[] headers = sessionObject.getLastHeader();
87         for (int i = 0; i < headers.length; i++) {
88             if (headers[i].getName().equals(headerParameterType)) {
89                 return (headers[i].getValue().equals(headerParameterValue));
90             }
91         }
92         return false;
93     }
94 }
Popular Tags