Skip to content

Commit 8e3a454

Browse files
committed
TDD: Write PropertyRepository test code
1 parent 8e562d5 commit 8e3a454

File tree

6 files changed

+401
-47
lines changed

6 files changed

+401
-47
lines changed

Core/src/main/java/root/core/repository/constracts/PropertyRepository.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
public interface PropertyRepository {
1515

16-
boolean isFileExist(String filePath);
17-
1816
PropertiesConfiguration getConfiguration(String config) throws PropertyNotLoadedException;
1917

2018
void save(String filePath, PropertiesConfiguration config);
@@ -37,8 +35,6 @@ public interface PropertyRepository {
3735

3836
String getCommonResource(String key);
3937

40-
int getIntegerCommonResource(String key);
41-
4238
String[] getCommonResources(String key);
4339

4440
String[] getDBMonitoringContents();
@@ -53,16 +49,12 @@ public interface PropertyRepository {
5349

5450
Map<String, String> getMonitoringPresetMap();
5551

56-
String getLastUseMonitoringPresetName();
57-
5852
String getLastUseMonitoringPresetName(String filePath);
5953

6054
String[] getMonitoringDBNames();
6155

6256
String[] getMonitoringServerNames();
6357

64-
boolean isMonitoringContent(String toggleId);
65-
6658
void createNewPropertiesFile(String filePath, String type);
6759

6860
JdbcConnectionInfo getJdbcConnectionInfo(String dbName);

Repository/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/build/
22
/bin/
33
/report
4-
/src/test/resources/dbconfig.txt
4+
/src/test/resources/dbconfig.txt
5+
/config

Repository/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
implementation 'commons-io:commons-io:2.8.0'
1818
implementation 'org.apache.commons:commons-configuration2:2.7'
1919
implementation 'org.apache.commons:commons-lang3:3.11'
20+
implementation 'commons-beanutils:commons-beanutils:1.9.4'
2021

2122
// Apache POI
2223
implementation 'org.apache.poi:poi:3.17'

Repository/src/main/java/root/repository/implement/PropertyRepositoryImpl.java

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ public static PropertyRepository getInstance() {
6666

6767
/****************************************************************************/
6868

69-
@Override
70-
public boolean isFileExist(String filePath) {
71-
return new File(filePath).exists();
72-
}
73-
7469
/**
7570
* Configuration 객체를 반환한다. TODO 굳이 메서드를 Wrapping 해서 호출할 필요가 있을까..? Controller와
7671
* 의존성 제거목적으로 일단 이렇게 함..
@@ -87,12 +82,15 @@ public PropertiesConfiguration getConfiguration(String name) throws PropertyNotL
8782
throw new PropertyNotLoadedException("monitoringConfig properties file is not loaded");
8883
}
8984
return monitoringConfig;
85+
} else if (name.equals("commonConfig") || name.equals("rememberConfig")) {
86+
Configuration config = combinedConfig.getConfiguration(name);
87+
if (config == null) {
88+
throw new PropertyNotLoadedException(name + " properties file is not loaded");
89+
}
90+
return (PropertiesConfiguration) config;
9091
}
9192

92-
if (combinedConfig == null) {
93-
throw new PropertyNotLoadedException("combinedConfig properties file is not loaded");
94-
}
95-
return (PropertiesConfiguration) combinedConfig.getConfiguration(name);
93+
throw new PropertyNotLoadedException("there is no properties file");
9694
}
9795

9896
/**
@@ -137,9 +135,9 @@ public void save(String filePath, PropertiesConfiguration config) {
137135

138136
@Override
139137
public void saveDBConnectionInfo(String filePath, Map<String, JdbcConnectionInfo> dbConfig) {
138+
loadConnectionInfoConfig(filePath);
140139
PropertiesConfiguration config = connInfoConfig;
141140

142-
// TODO dbnames property..
143141
String dbNames = "";
144142
for (String dbName : dbConfig.keySet()) {
145143
dbNames += dbName + ",";
@@ -187,6 +185,7 @@ public void saveDBConnectionInfo(String filePath, Map<String, JdbcConnectionInfo
187185

188186
writer.writeln(layout.getCanonicalFooterCooment(true));
189187
writer.flush();
188+
writer.close();
190189

191190
log.info("[" + filePath + "] 파일 저장이 성공적으로 완료되었습니다.");
192191
} catch (Exception e) {
@@ -197,9 +196,9 @@ public void saveDBConnectionInfo(String filePath, Map<String, JdbcConnectionInfo
197196

198197
@Override
199198
public void saveServerConnectionInfo(String filePath, Map<String, JschConnectionInfo> serverConfig) {
199+
loadConnectionInfoConfig(filePath);
200200
PropertiesConfiguration config = connInfoConfig;
201201

202-
// TODO servernames property..
203202
String serverNames = "";
204203
for (String serverName : serverConfig.keySet()) {
205204
serverNames += serverName + ",";
@@ -248,6 +247,7 @@ public void saveServerConnectionInfo(String filePath, Map<String, JschConnection
248247

249248
writer.writeln(layout.getCanonicalFooterCooment(true));
250249
writer.flush();
250+
writer.close();
251251

252252
log.info("[" + filePath + "] 파일 저장이 성공적으로 완료되었습니다.");
253253
} catch (Exception e) {
@@ -289,7 +289,7 @@ private static PropertiesConfiguration load(String filePath) {
289289
try {
290290
return builder.getConfiguration();
291291
} catch (ConfigurationException e) {
292-
e.printStackTrace();
292+
log.error(e.getMessage());
293293
return null;
294294
}
295295
}
@@ -364,14 +364,6 @@ public String getCommonResource(String key) {
364364
return combinedConfig.getString(key);
365365
}
366366

367-
/**
368-
* commons.properties에서 값을 읽어 반환한다.
369-
*/
370-
@Override
371-
public int getIntegerCommonResource(String key) {
372-
return combinedConfig.getInt(key);
373-
}
374-
375367
/**
376368
* commons.properties에서 값을 읽어 반환한다.
377369
*/
@@ -442,16 +434,6 @@ public Map<String, String> getMonitoringPresetMap() {
442434
return presetMap;
443435
}
444436

445-
/**
446-
* 최근 사용한 Monitoring Preset 이름을 반환한다. 단, 최근 사용한 Preset이 없을 때, NULL을 반환한다.
447-
*
448-
* @return
449-
*/
450-
@Override
451-
public String getLastUseMonitoringPresetName() {
452-
return connInfoConfig.subset("monitoring.setting.preset.lastuse").getString("");
453-
}
454-
455437
/**
456438
* 최근 사용한 Monitoring Preset 이름을 반환한다. 단, 최근 사용한 Preset이 없을 때, NULL을 반환한다.
457439
*
@@ -461,7 +443,7 @@ public String getLastUseMonitoringPresetName() {
461443
@Override
462444
public String getLastUseMonitoringPresetName(String filePath) {
463445
load(filePath);
464-
return connInfoConfig.subset("monitoring.setting.preset.lastuse").getString("");
446+
return connInfoConfig.getString("monitoring.setting.preset.lastuse");
465447
}
466448

467449
/**
@@ -480,11 +462,6 @@ public String[] getMonitoringServerNames() {
480462
return connInfoConfig.getStringArray("servernames");
481463
}
482464

483-
@Override
484-
public boolean isMonitoringContent(String toggleId) {
485-
return monitoringConfig.containsKey(toggleId) == false ? true : monitoringConfig.getBoolean(toggleId);
486-
}
487-
488465
/**
489466
* 지정된 경로에 새로운 파일을 생성한다.
490467
*
@@ -519,7 +496,7 @@ public void createNewPropertiesFile(String filePath, String type) {
519496

520497
}
521498
} catch (IOException e) {
522-
e.printStackTrace();
499+
log.error(e.getMessage());
523500
}
524501
}
525502

@@ -554,6 +531,7 @@ public JschConnectionInfo getJschConnectionInfo(String serverName) {
554531
try {
555532
serverOS = ServerOS.valueOf(connInfoConfig.getString(serverName + ".server.os"));
556533
} catch (Exception e) {
534+
log.error(e.getMessage());
557535
}
558536
String serverPort = connInfoConfig.getString(serverName + ".server.port");
559537
String serverUserName = connInfoConfig.getString(serverName + ".server.username");

Repository/src/main/java/root/service/implement/FilePropertyService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package root.service.implement;
22

3+
import java.io.File;
34
import java.util.ArrayList;
45
import java.util.Arrays;
56
import java.util.HashMap;
@@ -60,7 +61,7 @@ public List<String> getConnectionInfoList() throws PropertyNotFoundException {
6061
@Override
6162
public String getLastUseConnectionInfoFilePath() {
6263
String filePath = propRepo.getLastUseConnInfoFilePath();
63-
return propRepo.isFileExist(filePath) ? filePath : null;
64+
return new File(filePath).exists() ? filePath : null;
6465
}
6566

6667
/**

0 commit comments

Comments
 (0)