Skip to content

Commit

Permalink
#118=481: Uses Mockito to set properties accordinly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Laguna authored and Daniel Laguna committed May 4, 2017
1 parent 7909e0c commit d3967b6
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions dotCMS/src/integration-test/java/com/dotcms/osgi/OSGIUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import com.dotmarketing.util.OSGIUtil;

import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.mockito.Mockito;

import java.io.File;

Expand All @@ -24,27 +24,18 @@
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OSGIUtilTest {

private static String FELIX_BASE_DIR;
private static final String FELIX_BASE_DIR_KEY = "felix.base.dir";

@BeforeClass
public static void prepare() throws Exception {
IntegrationTestInitService.getInstance().init();

FELIX_BASE_DIR = Config.getStringProperty(FELIX_BASE_DIR_KEY, Config.CONTEXT.getRealPath("/WEB-INF") + File.separator + "felix");
Mockito.when(Config.CONTEXT.getRealPath("/WEB-INF/felix")).thenReturn(Config.getStringProperty("context.path.felix","/WEB-INF/felix"));

// Initialize OSGI
initializeOSGIFramework();
}

@AfterClass
public static void restartOSGIAfterFinishing() {
Config.setProperty(FELIX_BASE_DIR_KEY, FELIX_BASE_DIR);

// Restores original state of the OSGi framework
restartOSGi();
}

/**
* Initialize Mock OSGI Framework
*/
Expand All @@ -68,6 +59,14 @@ private static void restartOSGi() {
initializeOSGIFramework();
}

/**
* Restart the OSGI Framework
*/
private static void restartOSGi(String felixBasePath) {
Config.setProperty(FELIX_BASE_DIR_KEY, felixBasePath);
restartOSGi();
}

/**
* Test the felix deploy path is the default path
*/
Expand Down Expand Up @@ -109,7 +108,7 @@ public void test03CustomFelixDeployPath() throws Exception {
removeFolder(deployFelixPath);
removeFolder(customFelixPath);

Config.setProperty(FELIX_BASE_DIR_KEY, FELIX_BASE_DIR);
restartOSGi(contextFelixPath);
}

/**
Expand All @@ -131,7 +130,7 @@ public void test04CustomFelixUndeployPath() throws Exception {
removeFolder(undeployFelixPath);
removeFolder(customFelixPath);

Config.setProperty(FELIX_BASE_DIR_KEY, FELIX_BASE_DIR);
restartOSGi(contextFelixPath);
}

/**
Expand Down

0 comments on commit d3967b6

Please sign in to comment.