Skip to content

Commit

Permalink
Prefixed db-profiles nflow.db.*, added multiple db-profile check
Browse files Browse the repository at this point in the history
  • Loading branch information
eputtone committed Jun 14, 2014
1 parent 6b199f3 commit 29ec54c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ jdk:
- openjdk7
- oraclejdk8
env:
- SPRING_PROFILES_ACTIVE=nflow.h2
- SPRING_PROFILES_ACTIVE=nflow.postgresql
- SPRING_PROFILES_ACTIVE=nflow.mysql
- SPRING_PROFILES_ACTIVE=nflow.db.h2
- SPRING_PROFILES_ACTIVE=nflow.db.postgresql
- SPRING_PROFILES_ACTIVE=nflow.db.mysql
addons:
postgresql: "9.3"
before_script:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;

@Profile("!nflow.mysql,!nflow.postgresql")
@Profile("nflow.db.h2")
@Configuration
public class H2DatabaseConfiguration extends DatabaseConfiguration {
public H2DatabaseConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile("nflow.mysql")
@Profile("nflow.db.mysql")
@Configuration
public class MysqlDatabaseConfiguration extends DatabaseConfiguration {
public MysqlDatabaseConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile("nflow.postgresql")
@Profile("nflow.db.postgresql")
@Configuration
public class PgDatabaseConfiguration extends DatabaseConfiguration {
public PgDatabaseConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.nitorcreations.nflow.engine.BaseNflowTest;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={DaoTestConfiguration.class})
@ActiveProfiles("nflow.db.h2")
public abstract class BaseDaoTest extends BaseNflowTest {

@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nitorcreations.nflow.jetty.spring;

import static java.util.Arrays.asList;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
Expand All @@ -25,6 +26,22 @@ public NflowStandardEnvironment(Map<String, Object> overrideProperties) {
addActiveProfile(profile);
}
}
setupDbProfile();
}

private void setupDbProfile() {
boolean dbProfileDefined = false;
for (String profile : asList(getActiveProfiles())) {
if (profile.startsWith("nflow.db")) {
if (dbProfileDefined) {
throw new RuntimeException("Multiple nflow.db-profiles defined");
}
dbProfileDefined = true;
}
}
if (!dbProfileDefined) {
addActiveProfile("nflow.db.h2");
}
}

private void addPropertyResource(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ private void startStop(String profiles) throws Exception {
@Test
@Ignore
public void startNflowJettyMysql() throws Exception {
startStop("nflow.mysql");
startStop("nflow.db.mysql");
}

@Test
@Ignore
public void startNflowJettyPostgreSQL() throws Exception {
startStop("nflow.postgresql");
startStop("nflow.db.postgresql");
}

}

0 comments on commit 29ec54c

Please sign in to comment.