mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
108207: Merged 5.0.N (5.0.3) to HEAD-BUG-FIX (5.1/Cloud) 108196: Merged DEV to 5.0.N (5.0.3) 108195: MNT-13706 : Admin console unusable after we set any busy port in Port Number Value for subsystem - New and improved fix. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@108223 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,11 +18,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.management.subsystems.test;
|
package org.alfresco.repo.management.subsystems.test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
|
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
|
||||||
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
|
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
|
||||||
|
import org.alfresco.repo.management.subsystems.InvalidPropertyValueException;
|
||||||
|
import org.alfresco.repo.management.subsystems.SubsystemEarlyPropertyChecker;
|
||||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||||
import org.alfresco.util.ApplicationContextHelper;
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
import org.alfresco.util.BaseSpringTest;
|
import org.alfresco.util.BaseSpringTest;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
@@ -43,6 +51,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||||||
@Category(OwnJVMTestsCategory.class)
|
@Category(OwnJVMTestsCategory.class)
|
||||||
public class SubsystemsTest extends BaseSpringTest
|
public class SubsystemsTest extends BaseSpringTest
|
||||||
{
|
{
|
||||||
|
volatile boolean shouldBlockPort;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
@@ -97,4 +106,148 @@ public class SubsystemsTest extends BaseSpringTest
|
|||||||
assertEquals("Global Instance Default", testBeans[2].getAnotherStringProperty());
|
assertEquals("Global Instance Default", testBeans[2].getAnotherStringProperty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void blockPort(final int portNumber)
|
||||||
|
{
|
||||||
|
shouldBlockPort = true;
|
||||||
|
|
||||||
|
new Thread()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
ServerSocket serverSocket = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
serverSocket = new ServerSocket(portNumber);
|
||||||
|
serverSocket.setSoTimeout(200);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
serverSocket.accept();
|
||||||
|
}
|
||||||
|
catch (SocketTimeoutException ste)
|
||||||
|
{
|
||||||
|
//We're expecting this.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (shouldBlockPort);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
LogFactory.getLog(SubsystemsTest.class).error(ex.getMessage());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (serverSocket != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
serverSocket.close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogFactory.getLog(SubsystemsTest.class).error(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unblockPort()
|
||||||
|
{
|
||||||
|
shouldBlockPort = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAbstractPropertyBackedBean_performEarlyPropertyChecks_PortEarlyPropertyChecker()
|
||||||
|
{
|
||||||
|
int testPortNumber = (Integer) getApplicationContext().getBean("testPortNumber");
|
||||||
|
|
||||||
|
ChildApplicationContextFactory testBean = (ChildApplicationContextFactory) getApplicationContext().getBean("testsubsystem");
|
||||||
|
|
||||||
|
Map<String, String> testProperties = new HashMap<String, String>();
|
||||||
|
|
||||||
|
// Check for empty port value error:
|
||||||
|
testProperties.put("test1.port", "");
|
||||||
|
|
||||||
|
// Check for "unable to parse" error:
|
||||||
|
testProperties.put("test2.port", "123xy");
|
||||||
|
|
||||||
|
// Check for "out-of-bounds" (less than) error:
|
||||||
|
testProperties.put("test3.port", "0");
|
||||||
|
|
||||||
|
// Check for "out of bounds" (greater than) error:
|
||||||
|
testProperties.put("test4.port", "65536");
|
||||||
|
|
||||||
|
// Check for "port in use" error:
|
||||||
|
testProperties.put("test5.port", "" + testPortNumber);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
blockPort(testPortNumber);
|
||||||
|
testBean.performEarlyPropertyChecks(testProperties);
|
||||||
|
fail("An InvalidPropertyValueException should have occured.");
|
||||||
|
}
|
||||||
|
catch (InvalidPropertyValueException ipve)
|
||||||
|
{
|
||||||
|
assertTrue(ipve.getMessage().contains("The value for TestSubsystem port property cannot be empty."));
|
||||||
|
assertTrue(ipve.getMessage().contains("Unable to parse value for TestSubsystem port property: 123xy."));
|
||||||
|
assertTrue(ipve.getMessage().contains("The port chosen for TestSubsystem is outside the required range (1, 65535): 0."));
|
||||||
|
assertTrue(ipve.getMessage().contains("The port chosen for TestSubsystem is outside the required range (1, 65535): 65536."));
|
||||||
|
assertTrue(ipve.getMessage().contains("The port chosen for TestSubsystem is already in use: " + testPortNumber + "."));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
unblockPort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAbstractPropertyBackedBean_performEarlyPropertyChecks_CustomEarlyPropertyChecker()
|
||||||
|
{
|
||||||
|
ChildApplicationContextFactory testBean = new ChildApplicationContextFactory();
|
||||||
|
|
||||||
|
SubsystemEarlyPropertyChecker testEarlyPropertyChecker = new SubsystemEarlyPropertyChecker()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void checkPropertyValue(String propertyName, String propertyValue) throws InvalidPropertyValueException
|
||||||
|
{
|
||||||
|
if (propertyValue == null || propertyValue.isEmpty())
|
||||||
|
{
|
||||||
|
throw new InvalidPropertyValueException("Property value cannot be empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propertyValue.equals("Bad value"))
|
||||||
|
{
|
||||||
|
throw new InvalidPropertyValueException("Property value cannot be a 'Bad value'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Map<String, SubsystemEarlyPropertyChecker> earlyPropertyCheckersMap = new HashMap<String, SubsystemEarlyPropertyChecker>();
|
||||||
|
earlyPropertyCheckersMap.put("test1.property", testEarlyPropertyChecker);
|
||||||
|
earlyPropertyCheckersMap.put("test2.property", testEarlyPropertyChecker);
|
||||||
|
|
||||||
|
testBean.setEarlyPropertyCheckers(earlyPropertyCheckersMap);
|
||||||
|
|
||||||
|
Map<String, String> testProperties = new HashMap<String, String>();
|
||||||
|
|
||||||
|
// Test empty value error:
|
||||||
|
testProperties.put("test1.property", "");
|
||||||
|
|
||||||
|
// Test "Bad value" error:
|
||||||
|
testProperties.put("test2.property", "Bad value");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
testBean.performEarlyPropertyChecks(testProperties);
|
||||||
|
fail("An InvalidPropertyValueException should have occured.");
|
||||||
|
}
|
||||||
|
catch (InvalidPropertyValueException ipve)
|
||||||
|
{
|
||||||
|
assertTrue(ipve.getMessage().contains("Property value cannot be empty."));
|
||||||
|
assertTrue(ipve.getMessage().contains("Property value cannot be a 'Bad value'."));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user