modify helper tests

This commit is contained in:
Keiichi Watanabe 2015-12-21 17:25:24 +09:00
parent a1a6ad6ee5
commit 078d5f55db
3 changed files with 58 additions and 60 deletions

View file

@ -29,7 +29,7 @@ public class DuplicateHostHelper implements Serializable {
private static final long serialVersionUID = 1L;
private List<DuplicateHost> duplicateHostList;
protected List<DuplicateHost> duplicateHostList;
@PostConstruct
public void init() {

View file

@ -15,6 +15,9 @@
*/
package org.codelibs.fess.helper;
import java.util.ArrayList;
import org.codelibs.fess.es.config.exentity.DuplicateHost;
import org.codelibs.fess.unit.UnitFessTestCase;
public class DuplicateHostHelperTest extends UnitFessTestCase {
@ -24,13 +27,18 @@ public class DuplicateHostHelperTest extends UnitFessTestCase {
public void setUp() throws Exception {
super.setUp();
duplicateHostHelper = new DuplicateHostHelper();
// duplicateHostHelper.init(); // TODO cause error
duplicateHostHelper.duplicateHostList = new ArrayList<DuplicateHost>();
DuplicateHost foo = new DuplicateHost();
foo.setRegularName("www.foo.com");
foo.setDuplicateHostName("foo.com");
duplicateHostHelper.duplicateHostList.add(foo);
DuplicateHost bar = new DuplicateHost();
bar.setRegularName("www.bar.com");
bar.setDuplicateHostName("mail.bar.com");
duplicateHostHelper.duplicateHostList.add(bar);
}
public void test_dummy() {
}
/*
public void test_convert() {
String url;
String result;
@ -77,5 +85,5 @@ public class DuplicateHostHelperTest extends UnitFessTestCase {
result = "http://www.bar.com:8080/";
assertEquals(result, duplicateHostHelper.convert(url));
}
*/
}

View file

@ -15,11 +15,13 @@
*/
package org.codelibs.fess.helper.impl;
import java.util.Set;
import javax.servlet.http.Cookie;
import org.codelibs.core.crypto.CachedCipher;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.core.exception.IllegalBlockSizeRuntimeException;
import org.codelibs.fess.unit.UnitFessTestCase;
import org.codelibs.fess.util.ComponentUtil;
public class RoleQueryHelperImplTest extends UnitFessTestCase {
public RoleQueryHelperImpl roleQueryHelperImpl;
@ -30,35 +32,26 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
super.setUp();
roleQueryHelperImpl = new RoleQueryHelperImpl();
cipher = new CachedCipher();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
registerMockInstance(fessConfig);
registerMockInstance(new SystemHelper());
inject(roleQueryHelperImpl);
cipher.setKey("1234567890123456");
}
public void test_dummy() {
// TODO
}
/*
*
public void test_buildByParameter() {
final RoleQueryHelperImpl roleQueryHelperImpl = new RoleQueryHelperImpl();
Set<String> roleSet;
roleSet = roleQueryHelperImpl.buildByParameter(getRequest());
roleSet = roleQueryHelperImpl.buildByParameter(getMockRequest());
assertEquals(0, roleSet.size());
roleQueryHelperImpl.parameterKey = "fess1";
getRequest().setParameter("aaa", "bbb");
roleSet = roleQueryHelperImpl.buildByParameter(getRequest());
getMockRequest().setParameter("aaa", "bbb");
roleSet = roleQueryHelperImpl.buildByParameter(getMockRequest());
assertEquals(0, roleSet.size());
roleQueryHelperImpl.encryptedParameterValue = false;
getRequest().setParameter("fess1", "xxx\nrole1,role2,role3");
roleSet = roleQueryHelperImpl.buildByParameter(getRequest());
getMockRequest().setParameter("fess1", "xxx\nrole1,role2,role3");
roleSet = roleQueryHelperImpl.buildByParameter(getMockRequest());
assertEquals(3, roleSet.size());
assertTrue(roleSet.contains("role1"));
assertTrue(roleSet.contains("role2"));
@ -68,17 +61,16 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
roleQueryHelperImpl.cipher = cipher;
roleQueryHelperImpl.encryptedParameterValue = true;
getRequest().setParameter("fess2",
cipher.encryptoText("xxx\nrole1,role2,role3"));
roleSet = roleQueryHelperImpl.buildByParameter(getRequest());
getMockRequest().setParameter("fess2", cipher.encryptoText("xxx\nrole1,role2,role3"));
roleSet = roleQueryHelperImpl.buildByParameter(getMockRequest());
assertEquals(3, roleSet.size());
assertTrue(roleSet.contains("role1"));
assertTrue(roleSet.contains("role2"));
assertTrue(roleSet.contains("role3"));
getRequest().setParameter("fess2", "fail");
getMockRequest().setParameter("fess2", "fail");
try {
roleSet = roleQueryHelperImpl.buildByParameter(getRequest());
roleSet = roleQueryHelperImpl.buildByParameter(getMockRequest());
fail();
} catch (final IllegalBlockSizeRuntimeException e) {
// ok
@ -87,14 +79,14 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
roleQueryHelperImpl.parameterKey = "fess3";
roleQueryHelperImpl.encryptedParameterValue = false;
roleSet = roleQueryHelperImpl.buildByParameter(getRequest());
roleSet = roleQueryHelperImpl.buildByParameter(getMockRequest());
assertEquals(0, roleSet.size());
roleQueryHelperImpl.parameterKey = "fess4";
roleQueryHelperImpl.cipher = cipher;
roleQueryHelperImpl.encryptedParameterValue = true;
roleSet = roleQueryHelperImpl.buildByParameter(getRequest());
roleSet = roleQueryHelperImpl.buildByParameter(getMockRequest());
assertEquals(0, roleSet.size());
}
@ -105,7 +97,7 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
Set<String> roleSet;
try {
roleSet = roleQueryHelperImpl.buildByHeader(getRequest());
roleSet = roleQueryHelperImpl.buildByHeader(getMockRequest());
fail();
} catch (final NullPointerException e) {
//ok
@ -113,13 +105,13 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
roleQueryHelperImpl.headerKey = "fess1";
getRequest().addHeader("aaa", "bbb");
roleSet = roleQueryHelperImpl.buildByHeader(getRequest());
getMockRequest().addHeader("aaa", "bbb");
roleSet = roleQueryHelperImpl.buildByHeader(getMockRequest());
assertEquals(0, roleSet.size());
roleQueryHelperImpl.encryptedHeaderValue = false;
getRequest().addHeader("fess1", "xxx\nrole1,role2,role3");
roleSet = roleQueryHelperImpl.buildByHeader(getRequest());
getMockRequest().addHeader("fess1", "xxx\nrole1,role2,role3");
roleSet = roleQueryHelperImpl.buildByHeader(getMockRequest());
assertEquals(3, roleSet.size());
assertTrue(roleSet.contains("role1"));
assertTrue(roleSet.contains("role2"));
@ -129,18 +121,17 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
roleQueryHelperImpl.cipher = cipher;
roleQueryHelperImpl.encryptedHeaderValue = true;
getRequest().addHeader("fess2",
cipher.encryptoText("xxx\nrole1,role2,role3"));
roleSet = roleQueryHelperImpl.buildByHeader(getRequest());
getMockRequest().addHeader("fess2", cipher.encryptoText("xxx\nrole1,role2,role3"));
roleSet = roleQueryHelperImpl.buildByHeader(getMockRequest());
assertEquals(3, roleSet.size());
assertTrue(roleSet.contains("role1"));
assertTrue(roleSet.contains("role2"));
assertTrue(roleSet.contains("role3"));
roleQueryHelperImpl.headerKey = "fess2x";
getRequest().addHeader("fess2x", "fail");
getMockRequest().addHeader("fess2x", "fail");
try {
roleSet = roleQueryHelperImpl.buildByHeader(getRequest());
roleSet = roleQueryHelperImpl.buildByHeader(getMockRequest());
fail();
} catch (final IllegalBlockSizeRuntimeException e) {
// ok
@ -149,14 +140,14 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
roleQueryHelperImpl.headerKey = "fess3";
roleQueryHelperImpl.encryptedHeaderValue = false;
roleSet = roleQueryHelperImpl.buildByHeader(getRequest());
roleSet = roleQueryHelperImpl.buildByHeader(getMockRequest());
assertEquals(0, roleSet.size());
roleQueryHelperImpl.headerKey = "fess4";
roleQueryHelperImpl.cipher = cipher;
roleQueryHelperImpl.encryptedHeaderValue = true;
roleSet = roleQueryHelperImpl.buildByHeader(getRequest());
roleSet = roleQueryHelperImpl.buildByHeader(getMockRequest());
assertEquals(0, roleSet.size());
}
@ -166,13 +157,13 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
Set<String> roleSet;
Cookie cookie;
roleSet = roleQueryHelperImpl.buildByCookie(getRequest());
roleSet = roleQueryHelperImpl.buildByCookie(getMockRequest());
assertEquals(0, roleSet.size());
cookie = new Cookie("aaa", "bbb");
getRequest().addCookie(cookie);
getMockRequest().addCookie(cookie);
try {
roleSet = roleQueryHelperImpl.buildByCookie(getRequest());
roleSet = roleQueryHelperImpl.buildByCookie(getMockRequest());
fail();
} catch (final NullPointerException e) {
// ok
@ -180,13 +171,13 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
roleQueryHelperImpl.cookieKey = "fess1";
roleSet = roleQueryHelperImpl.buildByCookie(getRequest());
roleSet = roleQueryHelperImpl.buildByCookie(getMockRequest());
assertEquals(0, roleSet.size());
roleQueryHelperImpl.encryptedCookieValue = false;
cookie = new Cookie("fess1", "xxx\nrole1,role2,role3");
getRequest().addCookie(cookie);
roleSet = roleQueryHelperImpl.buildByCookie(getRequest());
getMockRequest().addCookie(cookie);
roleSet = roleQueryHelperImpl.buildByCookie(getMockRequest());
assertEquals(3, roleSet.size());
assertTrue(roleSet.contains("role1"));
assertTrue(roleSet.contains("role2"));
@ -196,10 +187,9 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
roleQueryHelperImpl.cipher = cipher;
roleQueryHelperImpl.encryptedCookieValue = true;
cookie = new Cookie("fess2",
cipher.encryptoText("xxx\nrole1,role2,role3"));
getRequest().addCookie(cookie);
roleSet = roleQueryHelperImpl.buildByCookie(getRequest());
cookie = new Cookie("fess2", cipher.encryptoText("xxx\nrole1,role2,role3"));
getMockRequest().addCookie(cookie);
roleSet = roleQueryHelperImpl.buildByCookie(getMockRequest());
assertEquals(3, roleSet.size());
assertTrue(roleSet.contains("role1"));
assertTrue(roleSet.contains("role2"));
@ -210,9 +200,9 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
roleQueryHelperImpl.cipher = cipher;
roleQueryHelperImpl.encryptedCookieValue = true;
cookie = new Cookie("fess2x", "fail");
getRequest().addCookie(cookie);
getMockRequest().addCookie(cookie);
try {
roleSet = roleQueryHelperImpl.buildByCookie(getRequest());
roleSet = roleQueryHelperImpl.buildByCookie(getMockRequest());
fail();
} catch (final Exception e) {
// ok
@ -221,14 +211,14 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
roleQueryHelperImpl.cookieKey = "fess3";
roleQueryHelperImpl.encryptedCookieValue = false;
roleSet = roleQueryHelperImpl.buildByCookie(getRequest());
roleSet = roleQueryHelperImpl.buildByCookie(getMockRequest());
assertEquals(0, roleSet.size());
roleQueryHelperImpl.cookieKey = "fess4";
roleQueryHelperImpl.cipher = cipher;
roleQueryHelperImpl.encryptedCookieValue = true;
roleSet = roleQueryHelperImpl.buildByCookie(getRequest());
roleSet = roleQueryHelperImpl.buildByCookie(getMockRequest());
assertEquals(0, roleSet.size());
}
@ -361,6 +351,6 @@ public class RoleQueryHelperImplTest extends UnitFessTestCase {
assertTrue(roleSet.contains("role1"));
assertTrue(roleSet.contains("role2"));
assertTrue(roleSet.contains("role3"));
}
*/
}
}