Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tool-up-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
elis
tool-up-backend
Commits
78536023
Commit
78536023
authored
9 years ago
by
Thiemo Belmega
Browse files
Options
Downloads
Patches
Plain Diff
Load database properties from file
parent
5e427d61
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/de/unipotsdam/cs/toolup/database/ToolUpProperties.java
+29
-1
29 additions, 1 deletion
src/de/unipotsdam/cs/toolup/database/ToolUpProperties.java
test/de/unipotsdam/cs/toolup/database/ToolUpPropertiesTest.java
+58
-0
58 additions, 0 deletions
...e/unipotsdam/cs/toolup/database/ToolUpPropertiesTest.java
with
87 additions
and
1 deletion
src/de/unipotsdam/cs/toolup/database/ToolUpProperties.java
+
29
−
1
View file @
78536023
package
de.unipotsdam.cs.toolup.database
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.InvalidPropertiesFormatException
;
import
java.util.Properties
;
public
class
ToolUpProperties
{
private
static
final
String
DB_USERNAME
=
"root"
;
...
...
@@ -8,9 +15,30 @@ public class ToolUpProperties {
private
static
final
String
SERVER_ADRESS
=
"localhost"
;
private
static
final
String
DATABASE_CONNECTOR
=
"jdbc:mysql://"
;
private
static
final
String
DB_PASSWORD
=
""
;
private
static
String
DATABASE_URL
=
null
;
private
static
Properties
PROPERTIES
=
null
;
static
File
PROPERTIES_FILE
=
new
File
(
"Tool.UP_cfg.xml"
);
public
static
String
getDatabaseUrl
()
{
return
DATABASE_CONNECTOR
+
SERVER_ADRESS
+
":"
+
SERVER_PORT
+
"/"
+
DB_SCHEMA
+
"?user="
+
DB_USERNAME
+
"&pw="
+
DB_PASSWORD
;
if
(
DATABASE_URL
==
null
){
DATABASE_URL
=
DATABASE_CONNECTOR
+
SERVER_ADRESS
+
":"
+
SERVER_PORT
+
"/"
+
DB_SCHEMA
+
"?user="
+
DB_USERNAME
+
"&pw="
+
DB_PASSWORD
;
}
return
DATABASE_URL
;
}
public
static
Properties
getProperties
()
throws
InvalidPropertiesFormatException
,
FileNotFoundException
,
IOException
{
if
(
PROPERTIES
==
null
){
loadPropertiesFromFile
();
}
return
PROPERTIES
;
}
private
static
synchronized
void
loadPropertiesFromFile
()
throws
InvalidPropertiesFormatException
,
FileNotFoundException
,
IOException
{
if
(
PROPERTIES
==
null
){
PROPERTIES
=
new
Properties
();
PROPERTIES
.
loadFromXML
(
new
FileInputStream
(
PROPERTIES_FILE
));
}
}
}
This diff is collapsed.
Click to expand it.
test/de/unipotsdam/cs/toolup/database/ToolUpPropertiesTest.java
0 → 100644
+
58
−
0
View file @
78536023
package
de.unipotsdam.cs.toolup.database
;
import
static
org
.
testng
.
AssertJUnit
.
assertEquals
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.util.InvalidPropertiesFormatException
;
import
java.util.Properties
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Test
;
public
class
ToolUpPropertiesTest
{
private
static
final
String
KEY_SERVERADRESS
=
"database server adress"
;
private
static
final
String
VALUE_SERVERADRESS
=
"localhost"
;
private
static
final
String
KEY_SERVERPORT
=
"database server port"
;
private
static
final
Object
VALUE_SERVERPORT
=
"3306"
;
private
static
final
String
KEY_USERNAME
=
"database user name"
;
private
static
final
String
VALUE_USERNAME
=
"root"
;
private
static
final
String
KEY_PASSWORD
=
"database password"
;
private
static
final
String
VALUE_PASSWORD
=
""
;
private
static
final
String
KEY_SCHEMA
=
"database schema"
;
private
static
final
String
VALUE_SCHEMA
=
"test"
;
File
PROPERTIES_FILE
=
new
File
(
"Tool.UP_cfg_template.xml"
);
@BeforeMethod
public
void
prepareConfigFile
()
throws
FileNotFoundException
,
IOException
{
Properties
props
=
new
Properties
();
props
.
put
(
KEY_SERVERADRESS
,
VALUE_SERVERADRESS
);
props
.
put
(
KEY_SERVERPORT
,
VALUE_SERVERPORT
);
props
.
put
(
KEY_USERNAME
,
VALUE_USERNAME
);
props
.
put
(
KEY_PASSWORD
,
VALUE_PASSWORD
);
props
.
put
(
KEY_SCHEMA
,
VALUE_SCHEMA
);
props
.
storeToXML
(
new
FileOutputStream
(
PROPERTIES_FILE
),
null
,
"utf-8"
);
}
@Test
public
void
testThatPropertiesAreLoaded
()
throws
InvalidPropertiesFormatException
,
FileNotFoundException
,
IOException
{
//arrange
//act
Properties
props
=
ToolUpProperties
.
getProperties
();
//assert
assertEquals
(
VALUE_SERVERADRESS
,
props
.
getProperty
(
KEY_SERVERADRESS
));
assertEquals
(
VALUE_SERVERPORT
,
props
.
getProperty
(
KEY_SERVERPORT
));
assertEquals
(
VALUE_USERNAME
,
props
.
getProperty
(
KEY_USERNAME
));
assertEquals
(
VALUE_PASSWORD
,
props
.
getProperty
(
KEY_PASSWORD
));
assertEquals
(
VALUE_SCHEMA
,
props
.
getProperty
(
KEY_SCHEMA
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment