Skip to content

Commit 84a9d45

Browse files
author
djhvscf
committed
Merge branch 'develop'
Conflicts: README.md
2 parents d20941a + 57b2dc3 commit 84a9d45

33 files changed

+623
-86
lines changed

.classpath

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5-
<classpathentry kind="lib" path="C:/Users/Dennis Hernandez/Documents/GitHub/mockaroo.api/dependencies/commons-io-1.3.2.jar"/>
6-
<classpathentry kind="lib" path="C:/Users/Dennis Hernandez/Documents/GitHub/mockaroo.api/dependencies/json-20140107.jar"/>
7-
<classpathentry kind="lib" path="C:/Users/Dennis Hernandez/Documents/GitHub/mockaroo.api/dependencies/jxl.jar"/>
8-
<classpathentry kind="lib" path="C:/Users/Dennis Hernandez/Documents/GitHub/mockaroo.api/dependencies/mysql-connector-java-5.1.31.jar"/>
5+
<classpathentry kind="lib" path="C:/Users/Dennis/Documents/GitHub/mockaroo.api/dependencies/commons-io-1.3.2.jar"/>
6+
<classpathentry kind="lib" path="C:/Users/Dennis/Documents/GitHub/mockaroo.api/dependencies/json-20140107.jar"/>
7+
<classpathentry kind="lib" path="C:/Users/Dennis/Documents/GitHub/mockaroo.api/dependencies/jxl.jar"/>
8+
<classpathentry kind="lib" path="C:/Users/Dennis/Documents/GitHub/mockaroo.api/dependencies/mysql-connector-java-5.1.31.jar"/>
99
<classpathentry kind="output" path="bin"/>
1010
</classpath>

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
*.project
22
.classpath
3-
*.classpath
4-
.settings/
3+
.settings/

README.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Mockaroo API
22
================
33

4-
Mockaroo API is an API that let us generate random data and insert into our data base. That's it.<br />
4+
Mockaroo API is an API that let us generate random data and insert into our data bases, create .xml, .xls, .json files. That's it.<br />
55
This API is based in JSON Objects.
66

77
Author Homepage: http://djhv92.wix.com/dennishernandez<br />
@@ -32,12 +32,15 @@ How to use it?
3232
3333
mockarooApi.Insert(data, dataAccess, "tableName", columnsTable);//Insert into a data base
3434
35-
MockarooFile test = new MockarooExcel("c:/temp/","test","testing","en", "EN");
36-
test.write(data); //Generate a Excel file
35+
MockarooFile excel = new MockarooExcel("c:/temp/","test","testing","en", "EN");
36+
excel.write(data); //Generate a Excel file
3737
3838
MockarooFile json = new MockarooJSON("c:/temp/", "test");
3939
json.write(data); //Generate a .json file
40-
40+
41+
MockarooFile xml = new MockarooXML("c:/temp/", "test", "lala");
42+
xml.write(data);
43+
4144
Dependencies
4245
=============
4346
Not yet.
@@ -53,3 +56,7 @@ Version: 0.1.0 - 18/July/2014
5356
Download mockarooapi.jar
5457
=======================
5558
https://github.com/djhvscf/mockaroo.api/releases/download/v0.1.0/mockarooapi.jar
59+
<<<<<<< HEAD
60+
=======
61+
62+
>>>>>>> develop

bin/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
/testMockarooApi
21
/com
-1.2 KB
Binary file not shown.
1.07 KB
Binary file not shown.
379 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-406 Bytes
Binary file not shown.
Binary file not shown.
File renamed without changes.

jar/v1.0.0/mockarooapi.jar

80 KB
Binary file not shown.

src/com/mockaroo/api/MockarooApi.java

+4-30
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.IOException;
44
import java.net.HttpURLConnection;
5-
import java.sql.SQLException;
65

76
import org.json.JSONArray;
87
import org.json.JSONObject;
@@ -11,9 +10,8 @@
1110
import com.mockaroo.api.classes.MockarooUrl;
1211
import com.mockaroo.api.exceptions.MockarooExceptionJSONArray;
1312
import com.mockaroo.api.exceptions.MockarooExceptionPing;
14-
import com.mockaroo.api.helpers.MockarooApiHelper;
1513
import com.mockaroo.api.helpers.MockarooPingHelper;
16-
import com.mockaroo.api.interfaces.IUrl;
14+
import com.mockaroo.api.interfaces.IMockarooUrl;
1715

1816
/**
1917
* Class base to MockarooApi
@@ -23,14 +21,11 @@
2321
*/
2422
public class MockarooApi {
2523

26-
private final IUrl url;
24+
private final IMockarooUrl url;
2725
private String key;
2826
private String contentType;
2927
private int countRegister;
3028
private final MockarooCreateJSONObject creater;
31-
private MockarooApiHelper mockarooApiHelper;
32-
private static final String messageExceptionInsertError = "An error ocurred inserting the data";
33-
private static final String INSERT_INTO = "INSERT INTO ";
3429

3530
/**
3631
* Constructor
@@ -47,7 +42,6 @@ public MockarooApi(String key, String contentType) throws MockarooExceptionPing
4742
this.setCountRegister(-1);
4843
url = MockarooUrl.getInstance(key, contentType);
4944
creater = new MockarooCreateJSONObject();
50-
mockarooApiHelper = new MockarooApiHelper();
5145
}
5246

5347
/**
@@ -66,7 +60,6 @@ public MockarooApi(String key, String contentType, int countRegister) throws Moc
6660
this.setCountRegister(countRegister);
6761
url = MockarooUrl.getInstance(key, contentType);
6862
creater = new MockarooCreateJSONObject();
69-
mockarooApiHelper = new MockarooApiHelper();
7063
}
7164

7265
/**
@@ -103,9 +96,9 @@ private void setKey(String key) {
10396

10497
/**
10598
* Get the url
106-
* @return {@link IUrl}
99+
* @return {@link IMockarooUrl}
107100
*/
108-
public IUrl getUrl() {
101+
public IMockarooUrl getUrl() {
109102
return url;
110103
}
111104

@@ -157,23 +150,4 @@ public JSONArray getJSONArray(HttpURLConnection conn, JSONArray columns) throws
157150
{
158151
return MockarooJSON.getJSONArray(conn, columns, this.getCountRegister());
159152
}
160-
161-
/**
162-
* Insert into the database specified
163-
* @param jsonObject JSONObject with the information
164-
* @param dataAccess Object Data Access layer
165-
* @param tableName Table to insert
166-
* @param values Values of the table
167-
* @throws ClassNotFoundException
168-
* @throws SQLException
169-
*/
170-
public void Insert(JSONObject jsonObject, MockarooDataAccess dataAccess, String tableName, String[] values) throws ClassNotFoundException, SQLException
171-
{
172-
String insertQuery = INSERT_INTO + tableName + mockarooApiHelper.generateValues(values) +
173-
mockarooApiHelper.generateValuesInsert(jsonObject);
174-
if(!dataAccess.Insert(insertQuery))
175-
{
176-
throw new SQLException(messageExceptionInsertError);
177-
}
178-
}
179153
}

src/com/mockaroo/api/MockarooDataAccess.java

+26-8
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,50 @@
33
import java.sql.Connection;
44
import java.sql.DriverManager;
55
import java.sql.SQLException;
6-
import java.sql.Statement;
6+
7+
import org.json.JSONObject;
8+
9+
import com.mockaroo.api.exceptions.MockarooExceptionValue;
10+
import com.mockaroo.api.helpers.MockarooDataAccessHelper;
11+
import com.mockaroo.api.helpers.MockarooValidatorHelper;
12+
import com.mockaroo.api.interfaces.IMockarooDataAccessHelper;
13+
import com.mockaroo.api.interfaces.IMockarooValidatorHelper;
714

815
/**
916
* Data access layer
1017
* @author Dennis Hernández Vargas
11-
* @version 0.1.0
12-
* @since 16/July/2014
18+
* @version 0.1.1
19+
* @since 19/July/2014
1320
*/
1421
public class MockarooDataAccess {
1522

1623
private String driverClassName;
1724
private String url;
1825
private String username;
1926
private String password;
27+
private IMockarooValidatorHelper validator = MockarooValidatorHelper.getInstance();
28+
private IMockarooDataAccessHelper mockarooDataAccessHelper;
29+
public static final String messageExceptionDriver = "The driver class name can't be empty";
30+
public static final String messageExceptionUrl = "The url server can't be empty";
31+
public static final String messageExceptionUsername = "The password can't be empty";
32+
public static final String messageExceptionPassword = "The password can't be empty";
2033

2134
/**
2235
* Default constructor
2336
* @param driverClassName Driver class name
2437
* @param url Server url
2538
* @param username User name
2639
* @param password User password
40+
* @throws MockarooExceptionValue
2741
*/
28-
public MockarooDataAccess(String driverClassName, String url, String username, String password)
42+
public MockarooDataAccess(String driverClassName, String url, String username, String password) throws MockarooExceptionValue
2943
{
44+
validator.validateString(driverClassName, messageExceptionDriver);
45+
validator.validateString(url, messageExceptionUrl);
46+
validator.validateString(username, messageExceptionUsername);
47+
validator.validateString(password, messageExceptionPassword);
48+
49+
mockarooDataAccessHelper = MockarooDataAccessHelper.getInstance();
3050
this.setDriverClassName(driverClassName);
3151
this.setUrl(url);
3252
this.setUsername(username);
@@ -116,10 +136,8 @@ private void setPassword(String password) {
116136
* @throws ClassNotFoundException
117137
* @throws SQLException
118138
*/
119-
protected boolean Insert(String sql) throws ClassNotFoundException, SQLException
139+
protected void Insert(String tableName, JSONObject jsonObject, String[] values) throws ClassNotFoundException, SQLException
120140
{
121-
Statement statement;
122-
statement = this.getConnection().createStatement();
123-
return !statement.execute(sql);
141+
mockarooDataAccessHelper.Insert(tableName, jsonObject, values, this.getConnection());
124142
}
125143
}

src/com/mockaroo/api/MockarooExcel.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
import jxl.write.WriteException;
99

1010
import com.mockaroo.api.classes.MockarooFile;
11+
import com.mockaroo.api.exceptions.MockarooExceptionValue;
1112
import com.mockaroo.api.helpers.MockarooExcelHelper;
13+
import com.mockaroo.api.helpers.MockarooValidatorHelper;
1214
import com.mockaroo.api.interfaces.IMockarooExcelHelper;
15+
import com.mockaroo.api.interfaces.IMockarooValidatorHelper;
1316

1417
/**
1518
* Class to create a Excel file
@@ -27,6 +30,13 @@ public class MockarooExcel extends MockarooFile {
2730
private String language;
2831
private String country;
2932
private static final String EXTENSION = ".xls";
33+
private IMockarooValidatorHelper validator = MockarooValidatorHelper.getInstance();
34+
public String messageExceptionPath = "The path can't be empty";
35+
public String messageExceptionInputFileName = "The input file namee can't be empty";
36+
public String messageExceptionSheetName = "The sheet name can't be empty";
37+
public String messageExceptionLanguage = "The language can't be empty";
38+
public String messageExceptionCountry = "The country can't be empty";
39+
3040

3141
/**
3242
* Constructor
@@ -36,10 +46,17 @@ public class MockarooExcel extends MockarooFile {
3646
* @param language Language
3747
* @param country Country
3848
* @throws WriteException
49+
* @throws MockarooExceptionValue
3950
*/
4051
public MockarooExcel(String path, String inputFileName, String sheetName, String language, String country)
41-
throws WriteException
52+
throws WriteException, MockarooExceptionValue
4253
{
54+
validator.validateString(path, messageExceptionPath);
55+
validator.validateString(inputFileName, messageExceptionInputFileName);
56+
validator.validateString(sheetName, messageExceptionSheetName);
57+
validator.validateString(language, messageExceptionLanguage);
58+
validator.validateString(country, messageExceptionCountry);
59+
4360
mockarooExcel = MockarooExcelHelper.getInstance();
4461
this.setPath(path);
4562
this.setInputFileName(inputFileName + EXTENSION);
@@ -55,10 +72,15 @@ public MockarooExcel(String path, String inputFileName, String sheetName, String
5572
* @param inputFileName Excel file name
5673
* @param sheetName Excel sheet name
5774
* @throws WriteException
75+
* @throws MockarooExceptionValue
5876
*/
5977
public MockarooExcel(String path, String inputFileName, String sheetName)
60-
throws WriteException
78+
throws WriteException, MockarooExceptionValue
6179
{
80+
validator.validateString(path, messageExceptionPath);
81+
validator.validateString(inputFileName, messageExceptionInputFileName);
82+
validator.validateString(sheetName, messageExceptionSheetName);
83+
6284
mockarooExcel = MockarooExcelHelper.getInstance();
6385
this.setPath(path);
6486
this.setInputFileName(inputFileName);

src/com/mockaroo/api/MockarooJSON.java

+15-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
import com.mockaroo.api.classes.MockarooFile;
1414
import com.mockaroo.api.exceptions.MockarooExceptionJSONArray;
15+
import com.mockaroo.api.exceptions.MockarooExceptionValue;
1516
import com.mockaroo.api.helpers.MockarooJSONHelper;
17+
import com.mockaroo.api.helpers.MockarooValidatorHelper;
18+
import com.mockaroo.api.interfaces.IMockarooJSONHelper;
19+
import com.mockaroo.api.interfaces.IMockarooValidatorHelper;
1620

1721
/**
1822
* Class base to Mockaroo JSON
@@ -23,29 +27,28 @@
2327
public class MockarooJSON extends MockarooFile {
2428

2529
private static final String messageExceptionJSONArray = "The count parameter can't be less than 0 or equal";
26-
private MockarooJSONHelper jsonHelper;
30+
private IMockarooJSONHelper jsonHelper;
2731
private String fileName;
2832
private static final String EXTENSION = ".json";
33+
private IMockarooValidatorHelper validator = MockarooValidatorHelper.getInstance();
34+
private static final String messageExceptionPath = "The path can't be empty";
35+
private static final String messageExceptionFileName = "The file name can't be empty";
2936

3037
/**
3138
* Constructor
3239
* @param path Where save the file .json
3340
* @param fileName File name
41+
* @throws MockarooExceptionValue
3442
*/
35-
public MockarooJSON(String path, String fileName)
43+
public MockarooJSON(String path, String fileName) throws MockarooExceptionValue
3644
{
37-
this.setJsonHelper(new MockarooJSONHelper());
45+
validator.validateString(path, messageExceptionPath);
46+
validator.validateString(fileName, messageExceptionFileName);
47+
48+
jsonHelper = MockarooJSONHelper .getInstance();
3849
this.setFileName(path + fileName + EXTENSION);
3950
}
4051

41-
/**
42-
* Get the json helper to write a .json
43-
* @return the jsonHelper
44-
*/
45-
private MockarooJSONHelper getJsonHelper() {
46-
return jsonHelper;
47-
}
48-
4952
/**
5053
* Get the file name
5154
* @return the fileName
@@ -54,14 +57,6 @@ private String getFileName() {
5457
return fileName;
5558
}
5659

57-
/**
58-
* Set the json helper
59-
* @param jsonHelper the jsonHelper to set
60-
*/
61-
private void setJsonHelper(MockarooJSONHelper jsonHelper) {
62-
this.jsonHelper = jsonHelper;
63-
}
64-
6560
/**
6661
* Set the file name
6762
* @param fileName the fileName to set
@@ -111,6 +106,6 @@ public static JSONArray getJSONArray(HttpURLConnection conn, JSONArray columns,
111106
@Override
112107
public void write(JSONObject jsonObject) throws IOException, WriteException
113108
{
114-
this.getJsonHelper().write(this.getFileName(), jsonObject);
109+
jsonHelper.write(this.getFileName(), jsonObject);
115110
}
116111
}

0 commit comments

Comments
 (0)