Skip to content

Commit

Permalink
Update tests configuration (disabled jBPM exec service for unit tests)
Browse files Browse the repository at this point in the history
- Also started to design configuration separation between Unit and
Integration tests
  • Loading branch information
lorenzo-biava committed Jun 16, 2016
1 parent 251dfc6 commit 8024938
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 211 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.reply.orchestrator.command;

import it.reply.orchestrator.config.WebAppConfigurationAware;
import it.reply.orchestrator.config.specific.WebAppConfigurationAware;
import it.reply.orchestrator.dto.RankCloudProvidersMessage;
import it.reply.orchestrator.service.WorkflowConstants;
import it.reply.orchestrator.service.commands.BaseRankCloudProvidersCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.github.springtestdbunit.annotation.DatabaseTearDown;

import it.reply.orchestrator.config.WebAppConfigurationAware;
import it.reply.orchestrator.config.specific.WebAppConfigurationAware;
import it.reply.orchestrator.service.commands.Notify;
import it.reply.workflowmanager.utils.Constants;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

@Configuration
@ComponentScan(basePackages = { "it.reply.orchestrator", "it.reply.workflowmanager" })
@ComponentScan(basePackages = { "it.reply.orchestrator", "it.reply.workflowmanager" },
excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX,
pattern = "it.reply.orchestrator.config.specific.*") })
public class ApplicationConfigTest {

@Bean
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package it.reply.orchestrator.config.specific;

import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;

import com.github.springtestdbunit.DbUnitTestExecutionListener;

import it.reply.orchestrator.config.ApplicationConfig;
import it.reply.orchestrator.config.PersistenceConfigTest;
import it.reply.orchestrator.config.WebAppInitializer;
import it.reply.orchestrator.config.WebMvcConfig;
import it.reply.orchestrator.config.WorkflowConfigProducerBean;
import it.reply.orchestrator.config.WorklfowPersistenceConfigTest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;

import javax.inject.Inject;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextHierarchy({
@ContextConfiguration(name = "baseContext",
classes = { ApplicationConfig.class, WebAppInitializer.class, WebMvcConfig.class,
PersistenceConfigTest.class, WorklfowPersistenceConfigTest.class }),
@ContextConfiguration(name = "workflowContext",
classes = { WebAppConfigurationAware.Config.class }) })
@TestPropertySource(locations = { "classpath:application-test.properties" })
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class })
public abstract class WebAppConfigurationAware {

private static final Logger LOG = LogManager.getLogger(WebAppConfigurationAware.class);

@Inject
protected WebApplicationContext wac;
protected MockMvc mockMvc;

@BeforeClass
public static void generalSetup() {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"bitronix.tm.jndi.BitronixInitialContextFactory");
}

@AfterClass
public static void generalCleanup() {
System.clearProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY);
}

@Before
public void before() {
this.mockMvc = webAppContextSetup(this.wac).build();
}

@Configuration
static class Config {
@Bean
@Primary
public WorkflowConfigProducerBean produceWorkflowConfigProducerBean() {
return new WorkflowConfigProducerBean() {

@Override
public int getExecutorServiceThreadPoolSize() {
// Disable jBPM Executor Service during Unit Tests (to avoid transaction/concurrency
// issues)
LOG.warn(
"Disable jBPM Executor Service during Unit Tests (to avoid transaction/concurrency issues)");
return 0;
}

};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package it.reply.orchestrator.config.specific;

import it.reply.orchestrator.IntegrationTest;

import org.junit.experimental.categories.Category;

@Category(IntegrationTest.class)
// @ContextHierarchy({ @ContextConfiguration(name = "workflowContext",
// classes = { WebAppConfigurationAwareIT.Config.class }, inheritLocations = false) })
public abstract class WebAppConfigurationAwareIT extends WebAppConfigurationAware {

/**
* The override is not working - enable in the future.
*/
// private static final Logger LOG = LogManager.getLogger(WebAppConfigurationAware.class);
//
// @Configuration
// static class Config {
// @Bean
// @Primary
// public WorkflowConfigProducerBean produceWorkflowConfigProducerBean() {
// return new WorkflowConfigProducerBean() {
//
// @Override
// public int getExecutorServiceThreadPoolSize() {
// // Enable jBPM Executor Service during Integration Tests
// LOG.warn("Enable jBPM Executor Service during Integration Tests");
// return 2;
// }
//
// };
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.github.springtestdbunit.annotation.DatabaseTearDown;

import it.reply.orchestrator.config.WebAppConfigurationAware;
import it.reply.orchestrator.config.specific.WebAppConfigurationAware;
import it.reply.orchestrator.dto.request.DeploymentRequest;
import it.reply.orchestrator.util.TestUtil;
import it.reply.orchestrator.utils.CommonUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.github.springtestdbunit.annotation.DatabaseTearDown;

import it.reply.orchestrator.config.WebAppConfigurationAware;
import it.reply.orchestrator.config.specific.WebAppConfigurationAware;

import org.junit.Before;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import es.upv.i3m.grycap.file.NoNullOrEmptyFile;
import es.upv.i3m.grycap.file.Utf8File;

import it.reply.orchestrator.config.WebAppConfigurationAware;
import it.reply.orchestrator.config.specific.WebAppConfigurationAware;

import org.junit.Before;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.github.springtestdbunit.annotation.DatabaseTearDown;

import it.reply.orchestrator.config.WebAppConfigurationAware;
import it.reply.orchestrator.config.specific.WebAppConfigurationAware;
import it.reply.orchestrator.dal.entity.Resource;
import it.reply.orchestrator.dal.repository.ResourceRepository;

Expand Down
50 changes: 25 additions & 25 deletions src/test/java/it/reply/orchestrator/service/ChronosServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package it.reply.orchestrator.service;

import it.reply.orchestrator.config.WebAppConfigurationAware;
import it.reply.orchestrator.service.commands.chronos.DeployOnChronos;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class ChronosServiceTest extends WebAppConfigurationAware {

@Autowired
private DeployOnChronos service;

private String deploymentId = "deployment_id";

@Test
public void customizeTemplateWithDeplymentIdSuccessfully() throws Exception {

// service.chronosHelloWorld(deploymentId, false);
// service.chronosHelloWorld(deploymentId, true);

// assertEquals(deploymentId, templateDeploymentId);
}

}
// package it.reply.orchestrator.service;
//
// import it.reply.orchestrator.config.specific.WebAppConfigurationAwareIT;
// import it.reply.orchestrator.service.commands.chronos.DeployOnChronos;
//
// import org.junit.Test;
// import org.springframework.beans.factory.annotation.Autowired;
//
// public class ChronosServiceTest extends WebAppConfigurationAwareIT {
//
// @Autowired
// private DeployOnChronos service;
//
// private String deploymentId = "deployment_id";
//
// @Test
// public void customizeTemplateWithDeplymentIdSuccessfully() throws Exception {
//
// // service.chronosHelloWorld(deploymentId, false);
// // service.chronosHelloWorld(deploymentId, true);
//
// // assertEquals(deploymentId, templateDeploymentId);
// }
//
// }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;

import it.reply.orchestrator.config.WebAppConfigurationAware;
import it.reply.orchestrator.config.specific.WebAppConfigurationAwareIT;
import it.reply.orchestrator.dto.ranker.CloudProviderRankerRequest;
import it.reply.orchestrator.dto.ranker.RankedCloudProvider;
import it.reply.utils.json.JsonUtility;
Expand All @@ -21,7 +21,7 @@
import java.util.Arrays;
import java.util.List;

public class CloudProviderRankerServiceTest extends WebAppConfigurationAware {
public class CloudProviderRankerServiceTest extends WebAppConfigurationAwareIT {

@Autowired
private CloudProviderRankerService cloudProviderRankerService;
Expand Down
Loading

0 comments on commit 8024938

Please sign in to comment.