Skip to content

Commit

Permalink
Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
natechadwick committed Feb 23, 2023
1 parent 999f9e6 commit 4fd884b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,49 @@
package com.percussion.search.objectstore;

import com.percussion.xml.PSXmlDocumentBuilder;
import org.junit.Test;
import org.w3c.dom.Element;

import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Element;

import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
* Unit test for <code>PSWSSearchRequest</code> class
*/
public class PSWSSearchRequestTest extends TestCase
public class PSWSSearchRequestTest
{

/**
* Default constructor.
*
* @param name the name of the test
*/
public PSWSSearchRequestTest(String name)
{
super(name);
}

public PSWSSearchRequestTest(){}

/**
* Test constructing with invalid values
*
* @throws Exception If there are any erros.
*
*/
public void testCtors() throws Exception
{
@Test
public void testCtors() {
// valid
PSWSSearchRequest req = null;

// suppress eclipse warning
if (req == null);
PSWSSearchRequest req;


req = new PSWSSearchRequest("test", null);
req = new PSWSSearchRequest("test", new HashMap());
assertNotNull(req);
req = new PSWSSearchRequest("test", new HashMap<>());
assertNotNull(req);
req = new PSWSSearchRequest(new PSWSSearchParams());
assertNotNull(req);

// invalid
boolean didThrow;
didThrow = false;
try
{
req = new PSWSSearchRequest(null, null);
req = new PSWSSearchRequest(null, null);
assertNotNull(req);
}
catch (Exception e)
{
Expand All @@ -74,7 +70,8 @@ public void testCtors() throws Exception
didThrow = false;
try
{
req = new PSWSSearchRequest("", null);
req = new PSWSSearchRequest("", null);
assertNotNull(req);
}
catch (Exception e)
{
Expand All @@ -85,7 +82,8 @@ public void testCtors() throws Exception
didThrow = false;
try
{
req = new PSWSSearchRequest((PSWSSearchParams)null);
req = new PSWSSearchRequest((PSWSSearchParams)null);
assertNotNull(req);
}
catch (Exception e)
{
Expand All @@ -96,7 +94,8 @@ public void testCtors() throws Exception
didThrow = false;
try
{
req = new PSWSSearchRequest((Element)null);
req = new PSWSSearchRequest((Element)null);
assertNotNull(req);
}
catch (Exception e)
{
Expand All @@ -110,27 +109,28 @@ public void testCtors() throws Exception
*
* @throws Exception if there are any errors.
*/
@Test
public void testEquals() throws Exception
{
PSWSSearchRequest req1 = new PSWSSearchRequest("test", null);
PSWSSearchRequest req2 = new PSWSSearchRequest("test", null);
assertEquals(req1, req2);
assertEquals(req1.hashCode(), req2.hashCode());
req2 = new PSWSSearchRequest("test2", null);
assertTrue(!req1.equals(req2));
assertNotEquals(req1, req2);

Map params = new HashMap();
Map<String,String> params = new HashMap<>();
params.put("foo", "bar");
params.put("a", "b");
req1 = new PSWSSearchRequest("test", params);
req2 = new PSWSSearchRequest("test", params);
assertEquals(req1, req2);
assertEquals(req1.hashCode(), req2.hashCode());
req2 = new PSWSSearchRequest("test", null);
assertTrue(!req1.equals(req2));
assertNotEquals(req1, req2);
params.clear();
req2 = new PSWSSearchRequest("test", params);
assertTrue(!req1.equals(req2));
assertNotEquals(req1, req2);


PSWSSearchParams searchParams1 = new PSWSSearchParams();
Expand All @@ -145,21 +145,22 @@ public void testEquals() throws Exception
assertEquals(req1, req2);
assertEquals(req1.hashCode(), req2.hashCode());
req2 = new PSWSSearchRequest(searchParams2);
assertTrue(!req1.equals(req2));
assertNotEquals(req1, req2);
}

/**
* Test xml serialization
*
* @throws Exception if there are any errors.
*/
@Test
public void testXml() throws Exception
{
PSWSSearchRequest req1 = new PSWSSearchRequest("test", null);
assertEquals(req1, new PSWSSearchRequest(req1.toXml(
PSXmlDocumentBuilder.createXmlDocument())));

Map params = new HashMap();
Map<String,String> params = new HashMap<>();
params.put("foo", "bar");
params.put("a", "b");
req1 = new PSWSSearchRequest("test", params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public PSWSSearchRequest(PSWSSearchParams searchParams)
* value is the parameter value, both as <code>String</code> objects. A
* shallow copy of the map is stored in this object.
*/
public PSWSSearchRequest(String searchName, Map params)
public PSWSSearchRequest(String searchName, Map<String,String> params)
{
if (searchName == null || searchName.trim().length() == 0)
throw new IllegalArgumentException(
Expand All @@ -73,19 +73,8 @@ public PSWSSearchRequest(String searchName, Map params)
m_internalSearchName = searchName;
if (params != null)
{
m_internalSearchParams = new HashMap();
Iterator entries = params.entrySet().iterator();
while (entries.hasNext())
{
Map.Entry entry = (Map.Entry)entries.next();
if (!(entry.getKey() instanceof String &&
entry.getValue() instanceof String))
{
throw new IllegalArgumentException("params must have" +
"only String objects for keys and values");
}
m_internalSearchParams.put(entry.getKey(), entry.getValue());
}
m_internalSearchParams = new HashMap<>();
m_internalSearchParams.putAll(params);
}
else
m_internalSearchParams = null;
Expand Down Expand Up @@ -295,8 +284,8 @@ private void fromXml(Element src) throws PSUnknownNodeTypeException
if (internalSearch)
{
// get params
m_internalSearchParams = new HashMap();
NodeList params = src.getElementsByTagNameNS("*", EL_REQ_PARAM);
m_internalSearchParams = new HashMap<>();
NodeList params = src.getElementsByTagName( EL_REQ_PARAM);
int tot = params.getLength();
for (int i = 0; i < tot; i++)
{
Expand Down Expand Up @@ -412,7 +401,7 @@ else if (m_searchParams != null && !m_searchParams.equals(
* may be <code>null</code>, possibly supplied by ctor only if
* {@link #m_internalSearchName} was supplied, never modified after that.
*/
private Map m_internalSearchParams;
private Map<String,String> m_internalSearchParams;

/**
* Determines if search is to be case-insentive or if dbms defaults will be
Expand Down

0 comments on commit 4fd884b

Please sign in to comment.