From 7f1f50d8b9fabc17b5334fed3c1d0105c34fae46 Mon Sep 17 00:00:00 2001 From: Dustin Johnson Date: Wed, 15 May 2013 16:54:40 -0500 Subject: [PATCH] Issue #2000 Fix broken stuff after Spring 3 upgrade Change-Id: I9d063c5807f00a4af161d4f0dc47008c79f94e3c Former-commit-id: 38714c154732b26c386d8b85ebd5b7cbdf50c5a7 [formerly 695c64a9f487534152dc70116d4e033a7766b3b3] [formerly 8a9e1f643ab25e9debee0b79c6dab84115f22d2f] [formerly ef1e80b61fe28661bea14abead6fa337d6939b3a [formerly 8a9e1f643ab25e9debee0b79c6dab84115f22d2f [formerly 0f0d3c53b3644d977560b3067535c012c9ac5228]]] Former-commit-id: ef1e80b61fe28661bea14abead6fa337d6939b3a Former-commit-id: c86021e68028c259d0aabec26dbd9c639da89626 [formerly b8d6f54206917065a00d4781229781028391cd73] Former-commit-id: 31fbf71aa2a3df14a80284457dd717c18b7660ae --- .../uf/edex/event/EdexEventBusHandler.java | 11 ++++- .../LifecycleManagerSubmitObjectsTest.java | 16 +++++-- .../services/validator/ValidatorImplTest.java | 7 +-- .../archive/ArchiveManagerFactoryTest.java | 7 ++- .../EclipseTestLocalizationAdapter.java | 18 +++++++- .../common/localization/TestPathManager.java | 44 +++++++++++++++++-- .../raytheon/uf/common/util/JettyServer.java | 4 +- .../uf/edex/event/TestEventBusHandler.java | 10 +++++ 8 files changed, 98 insertions(+), 19 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.edex.event/src/com/raytheon/uf/edex/event/EdexEventBusHandler.java b/edexOsgi/com.raytheon.uf.edex.event/src/com/raytheon/uf/edex/event/EdexEventBusHandler.java index db2e593500..f27c1c9c0c 100644 --- a/edexOsgi/com.raytheon.uf.edex.event/src/com/raytheon/uf/edex/event/EdexEventBusHandler.java +++ b/edexOsgi/com.raytheon.uf.edex.event/src/com/raytheon/uf/edex/event/EdexEventBusHandler.java @@ -88,7 +88,7 @@ public class EdexEventBusHandler implements IEventBusHandler, */ @Override public void publish(Event event) { - if (TransactionSynchronizationManager.isActualTransactionActive()) { + if (isTransactionActive()) { if (TransactionSynchronizationManager.isSynchronizationActive()) { if (!TransactionSynchronizationManager.getSynchronizations() @@ -107,6 +107,15 @@ public class EdexEventBusHandler implements IEventBusHandler, } } + /** + * Check to see if a transaction is active. + * + * @return true if a transaction is active + */ + protected boolean isTransactionActive() { + return TransactionSynchronizationManager.isActualTransactionActive(); + } + /** * {@inheritDoc} */ diff --git a/tests/integration/com/raytheon/uf/edex/registry/ebxml/dao/LifecycleManagerSubmitObjectsTest.java b/tests/integration/com/raytheon/uf/edex/registry/ebxml/dao/LifecycleManagerSubmitObjectsTest.java index 0f1ebe8932..c5dc567759 100644 --- a/tests/integration/com/raytheon/uf/edex/registry/ebxml/dao/LifecycleManagerSubmitObjectsTest.java +++ b/tests/integration/com/raytheon/uf/edex/registry/ebxml/dao/LifecycleManagerSubmitObjectsTest.java @@ -48,10 +48,10 @@ import oasis.names.tc.ebxml.regrep.xsd.rs.v4.UnresolvedReferenceExceptionType; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.transaction.TransactionConfiguration; +import org.springframework.transaction.annotation.Transactional; import com.google.common.collect.Sets; import com.raytheon.uf.common.util.SpringFiles; @@ -85,7 +85,8 @@ import com.raytheon.uf.edex.database.dao.DatabaseUtil; SpringFiles.EBXML_SUBSCRIPTION_XML, SpringFiles.UNIT_TEST_EBXML_BEANS_XML, SpringFiles.UNIT_TEST_LOCALIZATION_BEANS_XML }) -@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +@TransactionConfiguration(transactionManager = "metadataTxManager", defaultRollback = true) +@Transactional public class LifecycleManagerSubmitObjectsTest extends AbstractRegistryTest { /** @@ -254,7 +255,9 @@ public class LifecycleManagerSubmitObjectsTest extends AbstractRegistryTest { Mode.CREATE_OR_VERSION); lifecycleManager.submitObjects(submitObjectsRequest); - lifecycleManager.submitObjects(submitObjectsRequest); + lifecycleManager.submitObjects(createSubmitObjectsRequest( + MY_REGISTRY_OBJECT_ID, REGISTRY_OBJECT_TYPE, + Mode.CREATE_OR_VERSION)); QueryRequest partQueryRequest = createQueryForRegistryObjectByLid(MY_REGISTRY_OBJECT_ID); @@ -493,7 +496,12 @@ public class LifecycleManagerSubmitObjectsTest extends AbstractRegistryTest { lifecycleManager.submitObjects(submitObjectsRequest); + submitObjectsRequest = createSubmitObjectsRequest( + MY_REGISTRY_OBJECT_ID, REGISTRY_OBJECT_TYPE, Mode.CREATE_ONLY); submitObjectsRequest.getRegistryObjects().iterator().next().setId(null); + submitObjectsRequest.getRegistryObjects().iterator().next() + .setLid("goingToSubmitTheSameLidTwice"); + expectFaultException(submitObjectsRequest, ObjectExistsExceptionType.class); } diff --git a/tests/integration/com/raytheon/uf/edex/registry/ebxml/services/validator/ValidatorImplTest.java b/tests/integration/com/raytheon/uf/edex/registry/ebxml/services/validator/ValidatorImplTest.java index fd237c40ee..0fcd8b1fcd 100644 --- a/tests/integration/com/raytheon/uf/edex/registry/ebxml/services/validator/ValidatorImplTest.java +++ b/tests/integration/com/raytheon/uf/edex/registry/ebxml/services/validator/ValidatorImplTest.java @@ -44,10 +44,10 @@ import oasis.names.tc.ebxml.regrep.xsd.spi.v4.ValidateObjectsResponse; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.transaction.TransactionConfiguration; +import org.springframework.transaction.annotation.Transactional; import com.raytheon.uf.common.util.SpringFiles; import com.raytheon.uf.edex.database.dao.DatabaseUtil; @@ -81,7 +81,8 @@ import com.raytheon.uf.edex.registry.ebxml.util.EbxmlObjectUtil; SpringFiles.EBXML_QUERYTYPES_XML, SpringFiles.EBXML_REGISTRY_DAO_XML, SpringFiles.UNIT_TEST_EBXML_BEANS_XML, SpringFiles.UNIT_TEST_LOCALIZATION_BEANS_XML }) -@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +@TransactionConfiguration(transactionManager = "metadataTxManager", defaultRollback = true) +@Transactional public class ValidatorImplTest extends AbstractRegistryTest { private static final String LOCAL_STATIC_REFERENCE = "urn:acme:person:Danyal"; diff --git a/tests/unit/com/raytheon/uf/common/archive/ArchiveManagerFactoryTest.java b/tests/unit/com/raytheon/uf/common/archive/ArchiveManagerFactoryTest.java index 34f1bf9d64..cb0acd0911 100644 --- a/tests/unit/com/raytheon/uf/common/archive/ArchiveManagerFactoryTest.java +++ b/tests/unit/com/raytheon/uf/common/archive/ArchiveManagerFactoryTest.java @@ -21,7 +21,6 @@ package com.raytheon.uf.common.archive; import org.junit.After; import org.junit.AfterClass; -import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; @@ -80,9 +79,9 @@ public class ArchiveManagerFactoryTest { @Ignore @Test public void testGetManagerNotNull() { - IArchiveManager manager = ArchiveManagerFactory.getManager(); - Assert.assertNotNull("ArchiveManagerFactory returned a null manager", - manager); + // IArchiveManager manager = ArchiveManagerFactory.getManager(); + // Assert.assertNotNull("ArchiveManagerFactory returned a null manager", + // manager); } } diff --git a/tests/unit/com/raytheon/uf/common/localization/EclipseTestLocalizationAdapter.java b/tests/unit/com/raytheon/uf/common/localization/EclipseTestLocalizationAdapter.java index c7ee7223b1..54af0cf415 100644 --- a/tests/unit/com/raytheon/uf/common/localization/EclipseTestLocalizationAdapter.java +++ b/tests/unit/com/raytheon/uf/common/localization/EclipseTestLocalizationAdapter.java @@ -20,9 +20,9 @@ package com.raytheon.uf.common.localization; import java.io.File; -import java.util.Arrays; import java.util.List; +import com.google.common.collect.Lists; import com.raytheon.uf.common.localization.TestPathManager.TestLocalizationAdapter; /** @@ -71,7 +71,21 @@ public class EclipseTestLocalizationAdapter extends TestLocalizationAdapter { */ @Override List getDirectoriesWithPlugins() { - return Arrays.asList(EDEX_OSGI_DIR, new File("..", "edexOsgi")); + + List retVal = Lists.newArrayList(); + retVal.add(EDEX_OSGI_DIR); + + File commonBaseline = TestPathManager + .getCommonBaselineEnvironmentPath(); + + if (commonBaseline != null) { + File commonEdexOsgiDir = new File(commonBaseline, EDEX_OSGI); + if (!retVal.contains(commonEdexOsgiDir)) { + retVal.add(commonEdexOsgiDir); + } + } + + return retVal; } /** diff --git a/tests/unit/com/raytheon/uf/common/localization/TestPathManager.java b/tests/unit/com/raytheon/uf/common/localization/TestPathManager.java index dbd105ca8e..f652dc7e5e 100644 --- a/tests/unit/com/raytheon/uf/common/localization/TestPathManager.java +++ b/tests/unit/com/raytheon/uf/common/localization/TestPathManager.java @@ -156,7 +156,8 @@ public class TestPathManager extends PathManager { * @return */ private File createTestIsolatedVersionOfLocalizationFile( - LocalizationContext context, String fileName, File baselinedVersion) { + LocalizationContext context, String fileName, + File baselinedVersion) { File savedFileBaseDir = new File(savedLocalizationFileDir, context.toPath()); File savedFile = new File(savedFileBaseDir, fileName); @@ -204,13 +205,30 @@ public class TestPathManager extends PathManager { } } + File esbDataUtility = new File(buildEdexDir, "esb/data/utility"); + if (buildEdexDir != null && buildEdexDir.isDirectory()) { + utilityDirs.add(esbDataUtility); + } + + // Add common baseline path if the test is in a work assignment + // folder + File commonBaselinePath = getCommonBaselineEnvironmentPath(); + if (commonBaselinePath != null) { + buildEdexDir = new File(commonBaselinePath, FileUtil.join( + "edexOsgi", "build.edex")); + esbDataUtility = new File(buildEdexDir, "esb/data/utility"); + + if (buildEdexDir.isDirectory() + && !utilityDirs.contains(esbDataUtility)) { + utilityDirs.add(esbDataUtility); + } + } + if (buildEdexDir == null) { throw new RuntimeException( "Unable to find the build.edex directory!"); } - utilityDirs.add(new File(buildEdexDir, "esb/data/utility")); - // Plugin utility directories for (File pluginDir : pluginDirectories) { File[] plugins = pluginDir.listFiles(new FileFilter() { @@ -240,4 +258,24 @@ public class TestPathManager extends PathManager { */ abstract List getDirectoriesWithPlugins(); } + + /** + * Get the common baseline repo path from the environment variable. + * + * @return the file reference, or null if none was provided + */ + public static File getCommonBaselineEnvironmentPath() { + // work assignment workaround to for tests since we don't + // find files if we don't know the baseline repo's location + // THIS MEANS THAT FOR WORK ASSIGNMENTS WE MUST HAVE + // BASELINE_DIR SET + final String commonBaselineVersion = System.getenv("baseline_dir"); + if (commonBaselineVersion != null) { + File dir = new File(commonBaselineVersion.replace("\n", "")); + if (dir.isDirectory()) { + return dir; + } + } + return null; + } } diff --git a/tests/unit/com/raytheon/uf/common/util/JettyServer.java b/tests/unit/com/raytheon/uf/common/util/JettyServer.java index 9aa4212b11..64b98aa5e1 100644 --- a/tests/unit/com/raytheon/uf/common/util/JettyServer.java +++ b/tests/unit/com/raytheon/uf/common/util/JettyServer.java @@ -26,8 +26,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.http.security.Constraint; -import org.eclipse.jetty.http.security.Credential; import org.eclipse.jetty.security.ConstraintMapping; import org.eclipse.jetty.security.ConstraintSecurityHandler; import org.eclipse.jetty.security.HashLoginService; @@ -39,6 +37,8 @@ import org.eclipse.jetty.server.bio.SocketConnector; import org.eclipse.jetty.server.ssl.SslSocketConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.util.security.Constraint; +import org.eclipse.jetty.util.security.Credential; import com.raytheon.uf.common.comm.HttpTestConstants; diff --git a/tests/unit/com/raytheon/uf/edex/event/TestEventBusHandler.java b/tests/unit/com/raytheon/uf/edex/event/TestEventBusHandler.java index 55084f0247..c12ef4b954 100644 --- a/tests/unit/com/raytheon/uf/edex/event/TestEventBusHandler.java +++ b/tests/unit/com/raytheon/uf/edex/event/TestEventBusHandler.java @@ -49,4 +49,14 @@ public class TestEventBusHandler extends EdexEventBusHandler { public TestEventBusHandler() { super(new SynchronousEventBusFactory()); } + + /** + * Overridden to return false, because the transaction semantics are + * different with tests. + */ + @Override + protected boolean isTransactionActive() { + return false; + } + }