Skip to content

Commit 7d50007

Browse files
author
Manuel Perez Belmonte
committed
modified configuration for tests
1 parent 48b1bc9 commit 7d50007

File tree

9 files changed

+270
-90
lines changed

9 files changed

+270
-90
lines changed

pom.xml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,24 @@
150150
<autoReleaseAfterClose>false</autoReleaseAfterClose>
151151
</configuration>
152152
</plugin>
153+
<plugin>
154+
<groupId>org.apache.maven.plugins</groupId>
155+
<artifactId>maven-surefire-plugin</artifactId>
156+
<version>2.19</version>
157+
<configuration>
158+
<argLine>-Xmx1024m</argLine>
159+
<environmentVariables>
160+
<HIBERNATEURL>jdbc:postgresql://postgres/ece</HIBERNATEURL>
161+
<HIBERNATEUSERNAME>elastest</HIBERNATEUSERNAME>
162+
<HIBERNATEPASSWORD>elastestpassword</HIBERNATEPASSWORD>
163+
<!--<HIBERNATEURL>jdbc:postgresql://localhost/ece2</HIBERNATEURL>-->
164+
<!--<HIBERNATEUSERNAME>ubuntu</HIBERNATEUSERNAME>-->
165+
<!--<HIBERNATEPASSWORD>pass1234</HIBERNATEPASSWORD>-->
166+
<HIBERNATEDRIVER>org.postgresql.Driver</HIBERNATEDRIVER>
167+
<HIBERNATEDIALECT>org.hibernate.dialect.PostgreSQL9Dialect</HIBERNATEDIALECT>
168+
</environmentVariables>
169+
</configuration>
170+
</plugin>
153171
</plugins>
154172
</build>
155-
156-
157173
</project>

src/main/java/io/elastest/ece/application/APIController.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
import org.slf4j.LoggerFactory;
1111
import org.springframework.stereotype.Controller;
1212
import org.springframework.ui.Model;
13-
import org.springframework.web.bind.annotation.PathVariable;
1413
import org.springframework.web.bind.annotation.RequestMapping;
1514
import org.springframework.web.bind.annotation.RequestMethod;
1615
import org.springframework.web.bind.annotation.RequestParam;
1716

1817
import javax.annotation.PostConstruct;
19-
import javax.transaction.Transactional;
2018
import java.util.ArrayList;
2119
import java.util.HashMap;
2220
import java.util.List;

src/main/java/io/elastest/ece/load/Loader.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public class Loader {
4141
*/
4242
private Loader(String path) throws Exception {
4343
// only if object is created by createInstance (which gives it context)
44-
if (!path.isEmpty()) {
44+
if (path == null) {
45+
settings = new Settings(new Properties());
46+
} else if (!path.isEmpty()) {
4547
// start with loading config file
4648
Properties properties = loadAndParseConfigurationFile(path);
4749

@@ -53,8 +55,17 @@ private Loader(String path) throws Exception {
5355
}
5456
}
5557

58+
/**
59+
* Public empty initializer
60+
*/
61+
public static void createInstance() throws Exception {
62+
if (singleton == null)
63+
singleton = new Loader(null);
64+
}
65+
5666
/**
5767
* When creating instance, we need it to have context
68+
*
5869
* @param path for the configuration file
5970
*/
6071
public static void createInstance(String path) throws Exception {
@@ -65,6 +76,7 @@ public static void createInstance(String path) throws Exception {
6576

6677
/**
6778
* Access settings from Loader class
79+
*
6880
* @return settings object or null
6981
*/
7082
public static Settings getSettings() {
@@ -77,6 +89,7 @@ public static Settings getSettings() {
7789

7890
/**
7991
* Load and parse configuration file
92+
*
8093
* @return null or property object
8194
*/
8295
private Properties loadAndParseConfigurationFile(String path) {

src/main/java/io/elastest/ece/load/Settings.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.elastest.ece.load.model.HibernateCredentials;
2020

21+
import java.util.Map;
2122
import java.util.Properties;
2223

2324
/**
@@ -62,12 +63,32 @@ public Settings(Properties prop) {
6263
*/
6364
private HibernateCredentials loadHibernateConfiguration() {
6465
HibernateCredentials hibernateCredentials = new HibernateCredentials();
66+
Map<String, String> env = System.getenv();
6567

66-
hibernateCredentials.setHibernateURL(properties.getProperty("HibernateURL"));
67-
hibernateCredentials.setHibernateUsername(properties.getProperty("HibernateUsername"));
68-
hibernateCredentials.setHibernatePassword(properties.getProperty("HibernatePassword"));
69-
hibernateCredentials.setHibernateDriver(properties.getProperty("HibernateDriver"));
70-
hibernateCredentials.setHibernateDialect(properties.getProperty("HibernateDialect"));
68+
if (env.containsKey("HIBERNATEURL"))
69+
hibernateCredentials.setHibernateURL(env.get("HIBERNATEURL"));
70+
else
71+
hibernateCredentials.setHibernateURL(properties.getProperty("HibernateURL"));
72+
73+
if (env.containsKey("HIBERNATEUSERNAME"))
74+
hibernateCredentials.setHibernateUsername(env.get("HIBERNATEUSERNAME"));
75+
else
76+
hibernateCredentials.setHibernateUsername(properties.getProperty("HibernateUsername"));
77+
78+
if (env.containsKey("HIBERNATEPASSWORD"))
79+
hibernateCredentials.setHibernatePassword(env.get("HIBERNATEPASSWORD"));
80+
else
81+
hibernateCredentials.setHibernatePassword(properties.getProperty("HibernatePassword"));
82+
83+
if (env.containsKey("HIBERNATEDRIVER"))
84+
hibernateCredentials.setHibernateDriver(env.get("HIBERNATEDRIVER"));
85+
else
86+
hibernateCredentials.setHibernateDriver(properties.getProperty("HibernateDriver"));
87+
88+
if (env.containsKey("HIBERNATEDIALECT"))
89+
hibernateCredentials.setHibernateDialect(env.get("HIBERNATEDIALECT"));
90+
else
91+
hibernateCredentials.setHibernateDialect(properties.getProperty("HibernateDialect"));
7192

7293
return hibernateCredentials;
7394
}

src/main/java/io/elastest/ece/model/CostModel.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public class CostModel {
4343

4444
private String description;
4545

46-
protected CostModel(){}
46+
protected CostModel() {
47+
}
4748

4849
public CostModel(String name, String type, Map fix_cost) {
4950
this.name = name;
@@ -111,4 +112,22 @@ public Map<String, String> getComponents() {
111112
public void setComponents(Map<String, String> components) {
112113
this.components = components;
113114
}
115+
116+
@Override
117+
public boolean equals(Object o) {
118+
119+
if (o == this) return true;
120+
if (!(o instanceof CostModel)) {
121+
return false;
122+
}
123+
124+
CostModel costModel = (CostModel) o;
125+
126+
return (costModel.getName().equals(((CostModel) o).getName())
127+
&& costModel.getType().equals(((CostModel) o).getType())
128+
&& costModel.getVar_rate().equals(((CostModel) o).getVar_rate())
129+
&& costModel.getFix_cost().equals(((CostModel) o).getFix_cost())
130+
&& costModel.getComponents().equals(((CostModel) o).getComponents())
131+
&& costModel.getDescription().equals(((CostModel) o).getDescription()));
132+
}
114133
}

src/main/resources/application.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ logging.file=ece.log
55
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%-5level] - %msg%n
66
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
77
server.port=8888
8+
# Hibernate connection credentials
9+
HibernateURL=jdbc:postgresql://postgres/ece
10+
HibernateUsername=elastest
11+
HibernatePassword=elastestpassword
12+
HibernateDriver=org.postgresql.Driver
13+
HibernateDialect=org.hibernate.dialect.PostgreSQL9Dialect

src/test/java/elastest/io/ece/APIControllerTest.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)