ConverterUtil { public static List<Header> getRequestHeaders(Set<RequestData> headers, Set<RequestData> cookies) { List<Header> dataList = new ArrayList<Header>(); Header testData = new Header(); testData.setKey("TEST"); testData.setValue("LoadTest"); dataList.add(testData); for (RequestData data : headers) { if (includedHeader(data.getKey())) { String key = data.getKey(); if (key.toLowerCase().startsWith("x-include-")) { key = key.substring(10); } Header td = new Header(); td.setKey(key); td.setValue(data.getValue()); dataList.add(td); } } if (null != cookies) { String cookieStr = ""; for (RequestData c : cookies) { if (c.getValue().startsWith("@")) { cookieStr += "." + c.getKey().replace(".", "-dot-") + "=." + c.getValue() + ".;"; } } if (!cookieStr.isEmpty()) { String cookieValue = "#function.string.concat" + cookieStr; Header cookieData = new Header(); cookieData.setKey("Cookie"); cookieData.setValue(cookieValue); dataList.add(cookieData); } } return dataList; }  static HDWorkload convertScriptToHdWorkload(Script script); static HDWorkload convertWorkload(Workload workload, BaseJob job); static String getWorkloadXML(HDWorkload hdWorkload); static boolean isAssignment(RequestData data); static List<Header> getPostData(Set<RequestData> postData); static List<ResponseData> getResponseData(Set<RequestData> responseData); static List<Header> getResponseHeaders(Set<RequestData> responseHeaders, Set<RequestData> responseCookies); static List<Header> getRequestHeaders(Set<RequestData> headers, Set<RequestData> cookies); static boolean includedHeader(String header);  }
@Test public void testGetRequestHeaders_1() throws Exception { Set<RequestData> headers = new HashSet(); headers.add(new RequestData("X-Include-Connection", "myValue", RequestDataType.requestHeader.name())); headers.add(new RequestData("Connection", "myValueNotIncluded", RequestDataType.requestHeader.name())); Set<RequestData> cookies = new HashSet(); List<Header> result = ConverterUtil.getRequestHeaders(headers, cookies); assertNotNull(result); assertEquals(2, result.size()); for (Header h : result) { if (h.getKey().equalsIgnoreCase("Connection")) { assertEquals("myValue", h.getValue()); return; } } fail("X-Include header not included"); }
@Test public void testGetRequestHeaders_2() throws Exception { Set<RequestData> headers = new HashSet(); Set<RequestData> cookies = new HashSet(); List<Header> result = ConverterUtil.getRequestHeaders(headers, cookies); assertNotNull(result); assertEquals(1, result.size()); }
@Test public void testGetRequestHeaders_3() throws Exception { Set<RequestData> headers = new HashSet(); Set<RequestData> cookies = new HashSet(); List<Header> result = ConverterUtil.getRequestHeaders(headers, cookies); assertNotNull(result); assertEquals(1, result.size()); }
@Test public void testGetRequestHeaders_4() throws Exception { Set<RequestData> headers = new HashSet(); Set<RequestData> cookies = null; List<Header> result = ConverterUtil.getRequestHeaders(headers, cookies); assertNotNull(result); assertEquals(1, result.size()); }