UpgradeCatalog210 extends AbstractUpgradeCatalog { protected String updateHiveEnvContent(String hiveEnvContent) { if(hiveEnvContent == null) { return null; } String oldAuxJarRegex = "if\\s*\\[\\s*\"\\$\\{HIVE_AUX_JARS_PATH\\}\"\\s*!=\\s*\"\"\\s*];\\s*then\\s*\\n" + "\\s*export\\s+HIVE_AUX_JARS_PATH\\s*=\\s*\\$\\{HIVE_AUX_JARS_PATH\\}\\s*\\n" + "\\s*elif\\s*\\[\\s*-d\\s*\"/usr/hdp/current/hive-webhcat/share/hcatalog\"\\s*\\];\\s*then\\s*\\n" + "\\s*export\\s+HIVE_AUX_JARS_PATH\\s*=\\s*/usr/hdp/current/hive-webhcat/share/hcatalog\\s*\n" + "\\s*fi"; String newAuxJarPath = "if [ \"${HIVE_AUX_JARS_PATH}\" != \"\" ]; then\n" + " if [ -f \"${HIVE_AUX_JARS_PATH}\" ]; then \n" + " export HIVE_AUX_JARS_PATH=${HIVE_AUX_JARS_PATH}\n" + " elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then\n" + " export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog/hive-hcatalog-core.jar\n" + " fi\n" + "elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then\n" + " export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog/hive-hcatalog-core.jar\n" + "fi"; return hiveEnvContent.replaceAll(oldAuxJarRegex, Matcher.quoteReplacement(newAuxJarPath)); } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion();  }
@Test public void TestUpdateHiveEnvContent() { EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); bind(ConfigHelper.class).toInstance(mockConfigHelper); bind(Clusters.class).toInstance(mockClusters); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); } }); String content = "# Start HIVE_AUX_JARS_PATH \n" + "if [ \"${HIVE_AUX_JARS_PATH}\" != \"\" ]; then\n" + " export HIVE_AUX_JARS_PATH=${HIVE_AUX_JARS_PATH}\n" + "elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then \n" + " export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog\n" + "fi\n" + "#End HIVE_AUX_JARS_PATH"; String expectedContent = "# Start HIVE_AUX_JARS_PATH \n" + "if [ \"${HIVE_AUX_JARS_PATH}\" != \"\" ]; then\n" + " if [ -f \"${HIVE_AUX_JARS_PATH}\" ]; then \n" + " export HIVE_AUX_JARS_PATH=${HIVE_AUX_JARS_PATH}\n" + " elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then\n" + " export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog/hive-hcatalog-core.jar\n" + " fi\n" + "elif [ -d \"/usr/hdp/current/hive-webhcat/share/hcatalog\" ]; then\n" + " export HIVE_AUX_JARS_PATH=/usr/hdp/current/hive-webhcat/share/hcatalog/hive-hcatalog-core.jar\n" + "fi\n" + "#End HIVE_AUX_JARS_PATH"; String modifiedContent = mockInjector.getInstance(UpgradeCatalog210.class).updateHiveEnvContent(content); Assert.assertEquals(modifiedContent, expectedContent); }