Sfoglia il codice sorgente

need to fix the tests

thulasi 6 anni fa
parent
commit
e55d75ece8

BIN
.DS_Store Vedi File


+ 9
- 0
.idea/ZCW-ORM-SimpleAccount.iml Vedi File

@@ -0,0 +1,9 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+    <exclude-output />
5
+    <content url="file://$MODULE_DIR$" />
6
+    <orderEntry type="inheritedJdk" />
7
+    <orderEntry type="sourceFolder" forTests="false" />
8
+  </component>
9
+</module>

+ 6
- 0
.idea/misc.xml Vedi File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="JavaScriptSettings">
4
+    <option name="languageLevel" value="ES6" />
5
+  </component>
6
+</project>

+ 8
- 0
.idea/modules.xml Vedi File

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/.idea/ZCW-ORM-SimpleAccount.iml" filepath="$PROJECT_DIR$/.idea/ZCW-ORM-SimpleAccount.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
.idea/vcs.xml Vedi File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="" vcs="Git" />
5
+  </component>
6
+</project>

+ 147
- 0
.idea/workspace.xml Vedi File

@@ -0,0 +1,147 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ChangeListManager">
4
+    <list default="true" id="6d0cf3b7-f5c6-4934-8776-bb08ce67f415" name="Default Changelist" comment="">
5
+      <change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
6
+    </list>
7
+    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
8
+    <option name="SHOW_DIALOG" value="false" />
9
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
10
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
11
+    <option name="LAST_RESOLUTION" value="IGNORE" />
12
+  </component>
13
+  <component name="FUSProjectUsageTrigger">
14
+    <session id="1272851442">
15
+      <usages-collector id="statistics.lifecycle.project">
16
+        <counts>
17
+          <entry key="project.closed" value="2" />
18
+          <entry key="project.open.time.0" value="1" />
19
+          <entry key="project.open.time.1" value="1" />
20
+          <entry key="project.opened" value="2" />
21
+        </counts>
22
+      </usages-collector>
23
+    </session>
24
+  </component>
25
+  <component name="Git.Settings">
26
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
27
+  </component>
28
+  <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
29
+  <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
30
+  <component name="JsGulpfileManager">
31
+    <detection-done>true</detection-done>
32
+    <sorting>DEFINITION_ORDER</sorting>
33
+  </component>
34
+  <component name="ProjectFrameBounds">
35
+    <option name="x" value="10" />
36
+    <option name="y" value="32" />
37
+    <option name="width" value="1260" />
38
+    <option name="height" value="688" />
39
+  </component>
40
+  <component name="ProjectView">
41
+    <navigator proportions="" version="1">
42
+      <foldersAlwaysOnTop value="true" />
43
+    </navigator>
44
+    <panes>
45
+      <pane id="ProjectPane">
46
+        <subPane>
47
+          <expand>
48
+            <path>
49
+              <item name="ZCW-ORM-SimpleAccount" type="b2602c69:ProjectViewProjectNode" />
50
+              <item name="ZCW-ORM-SimpleAccount" type="462c0819:PsiDirectoryNode" />
51
+            </path>
52
+          </expand>
53
+          <select />
54
+        </subPane>
55
+      </pane>
56
+      <pane id="Scope">
57
+        <subPane subId="Scope 'Project Files'; set:Project Files; class com.intellij.psi.search.scope.ProjectFilesScope">
58
+          <expand>
59
+            <path>
60
+              <item name="ZCW-ORM-SimpleAccount" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
61
+              <item name="ZCW-ORM-SimpleAccount" type="2674bda8:ScopeViewTreeModel$GroupNode" />
62
+            </path>
63
+          </expand>
64
+          <select />
65
+        </subPane>
66
+      </pane>
67
+      <pane id="PackagesPane" />
68
+    </panes>
69
+  </component>
70
+  <component name="PropertiesComponent">
71
+    <property name="WebServerToolWindowFactoryState" value="false" />
72
+    <property name="aspect.path.notification.shown" value="true" />
73
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542628358221" />
74
+    <property name="jdk.selected.JAVA_MODULE" value="1.8" />
75
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
76
+    <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
77
+    <property name="nodejs_npm_path_reset_for_default_project" value="true" />
78
+  </component>
79
+  <component name="RunDashboard">
80
+    <option name="ruleStates">
81
+      <list>
82
+        <RuleState>
83
+          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
84
+        </RuleState>
85
+        <RuleState>
86
+          <option name="name" value="StatusDashboardGroupingRule" />
87
+        </RuleState>
88
+      </list>
89
+    </option>
90
+  </component>
91
+  <component name="SvnConfiguration">
92
+    <configuration />
93
+  </component>
94
+  <component name="TaskManager">
95
+    <task active="true" id="Default" summary="Default task">
96
+      <changelist id="6d0cf3b7-f5c6-4934-8776-bb08ce67f415" name="Default Changelist" comment="" />
97
+      <created>1542235356736</created>
98
+      <option name="number" value="Default" />
99
+      <option name="presentableId" value="Default" />
100
+      <updated>1542235356736</updated>
101
+      <workItem from="1542235358010" duration="411000" />
102
+      <workItem from="1542332829227" duration="35000" />
103
+    </task>
104
+    <servers />
105
+  </component>
106
+  <component name="TimeTrackingManager">
107
+    <option name="totallyTimeSpent" value="446000" />
108
+  </component>
109
+  <component name="ToolWindowManager">
110
+    <frame x="10" y="32" width="1260" height="688" extended-state="0" />
111
+    <layout>
112
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2536946" />
113
+      <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
114
+      <window_info id="Image Layers" order="2" />
115
+      <window_info id="Designer" order="3" />
116
+      <window_info id="UI Designer" order="4" />
117
+      <window_info id="Capture Tool" order="5" />
118
+      <window_info id="Favorites" order="6" side_tool="true" />
119
+      <window_info anchor="bottom" id="Message" order="0" />
120
+      <window_info anchor="bottom" id="Find" order="1" />
121
+      <window_info anchor="bottom" id="Run" order="2" />
122
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
123
+      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
124
+      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
125
+      <window_info anchor="bottom" id="TODO" order="6" />
126
+      <window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
127
+      <window_info anchor="bottom" id="Terminal" order="8" />
128
+      <window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
129
+      <window_info anchor="bottom" id="Version Control" order="10" />
130
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
131
+      <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
132
+      <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
133
+      <window_info anchor="right" id="Palette" order="3" />
134
+      <window_info anchor="right" id="Capture Analysis" order="4" />
135
+      <window_info anchor="right" id="Theme Preview" order="5" />
136
+      <window_info anchor="right" id="Palette&#9;" order="6" />
137
+      <window_info anchor="right" id="Database" order="7" />
138
+      <window_info anchor="right" id="Maven Projects" order="8" />
139
+    </layout>
140
+  </component>
141
+  <component name="TypeScriptGeneratedFilesManager">
142
+    <option name="version" value="1" />
143
+  </component>
144
+  <component name="VcsContentAnnotationSettings">
145
+    <option name="myLimit" value="2678400000" />
146
+  </component>
147
+</project>

+ 2
- 0
simpleAccount.iml Vedi File

@@ -0,0 +1,2 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="JAVA_MODULE" version="4" />

BIN
src/.DS_Store Vedi File


BIN
src/main/.DS_Store Vedi File


+ 64
- 0
src/main/java/Account.java Vedi File

@@ -0,0 +1,64 @@
1
+import com.j256.ormlite.field.DatabaseField;
2
+import com.j256.ormlite.table.DatabaseTable;
3
+
4
+@DatabaseTable(tableName = "account")
5
+public class Account {
6
+
7
+    public static final String NAME_FIELD_NAME = "name";
8
+    public static final String PASSWORD_FIELD_NAME = "password";
9
+
10
+    @DatabaseField(columnName = "id", generatedId = true)
11
+    private int id;
12
+
13
+    @DatabaseField(columnName = "name", canBeNull = false)
14
+    private String name;
15
+
16
+    @DatabaseField(columnName = "password")
17
+    private String password;
18
+
19
+    Account() {
20
+        // all persisted classes must define a no-arg constructor with at least package visibility
21
+    }
22
+
23
+    public Account(String name) {
24
+        this.name = name;
25
+    }
26
+
27
+    public Account(String name, String password) {
28
+        this.name = name;
29
+        this.password = password;
30
+    }
31
+
32
+    public int getId() {
33
+        return id;
34
+    }
35
+
36
+    public String getName() {
37
+        return name;
38
+    }
39
+
40
+    public void setName(String name) {
41
+        this.name = name;
42
+    }
43
+
44
+    public String getPassword() {
45
+        return password;
46
+    }
47
+
48
+    public void setPassword(String password) {
49
+        this.password = password;
50
+    }
51
+
52
+    @Override
53
+    public int hashCode() {
54
+        return name.hashCode();
55
+    }
56
+
57
+    @Override
58
+    public boolean equals(Object other) {
59
+        if (other == null || other.getClass() != getClass()) {
60
+            return false;
61
+        }
62
+        return name.equals(((Account) other).name);
63
+    }
64
+}

+ 78
- 0
src/main/java/AccountApp.java Vedi File

@@ -0,0 +1,78 @@
1
+import com.j256.ormlite.dao.Dao;
2
+import com.j256.ormlite.dao.DaoManager;
3
+import com.j256.ormlite.jdbc.JdbcConnectionSource;
4
+import com.j256.ormlite.support.ConnectionSource;
5
+
6
+public class AccountApp {
7
+
8
+    // we are using a MySQl database
9
+    private final static String DATABASE_URL = "jdbc:mysql://localhost:3306/orm_lab?useUnicode=true";
10
+    private final static String YOURUSERNAME = "root";
11
+    private final static String YOURPASSWORD = null;
12
+    private Dao<Account, Integer> accountDao;
13
+
14
+    public static void main(String[] args) throws Exception {
15
+        // turn our static method into an instance of Main
16
+        new AccountApp().doMain(args);
17
+    }
18
+
19
+    private void doMain(String[] args) throws Exception {
20
+        ConnectionSource connectionSource = null;
21
+        try {
22
+            // create our data-source for the database
23
+            connectionSource = new JdbcConnectionSource(DATABASE_URL, YOURUSERNAME, YOURPASSWORD);
24
+            // setup our  DAOs
25
+            setupDao(connectionSource);
26
+            // read, write and delete some data
27
+            processData();
28
+
29
+           // System.out.println("\n\nIt seems to have worked\n\n");
30
+        } finally {
31
+            // destroy the data source which should close underlying connections
32
+            if (connectionSource != null) {
33
+                connectionSource.close();
34
+            }
35
+        }
36
+    }
37
+
38
+    /**
39
+     * Read and write some example data.
40
+     */
41
+    private void processData() throws Exception {
42
+        Console console = new Console();
43
+        String name = console.readString("Enter your name : ");
44
+        String password = console.readString("Enter your password : ");
45
+        Account account = new Account(name, password);
46
+        account.setPassword(password);
47
+        Service driver = new Service(accountDao, account);
48
+
49
+       boolean check = true;
50
+       while (check){
51
+            int option = console.readInteger("Enter your choice\n1.create\n2.read\n3.update\n4.delete\n5.exit");
52
+            switch (option){
53
+                case 1: driver.create();
54
+                        break;
55
+                case 2: driver.read();
56
+                        break;
57
+                case 3: driver.update();
58
+                        break;
59
+                case 4: driver.delete();
60
+                        break;
61
+                case 5: check = false;
62
+                        break;
63
+                default: console.printString("Invalid input");
64
+            }
65
+       }
66
+
67
+    }
68
+
69
+
70
+    /**
71
+     * Setup our  DAOs
72
+     */
73
+    private void setupDao(ConnectionSource connectionSource) throws Exception {
74
+
75
+        accountDao = DaoManager.createDao(connectionSource, Account.class);
76
+
77
+    }
78
+}

+ 24
- 0
src/main/java/Console.java Vedi File

@@ -0,0 +1,24 @@
1
+import java.util.Random;
2
+import java.util.Scanner;
3
+
4
+public class Console {
5
+    private Scanner input;
6
+
7
+    public Console() {
8
+        this.input = new Scanner(System.in);
9
+    }
10
+
11
+    public int readInteger(String s) {
12
+        System.out.println(s);
13
+        return input.nextInt();
14
+    }
15
+
16
+    public String readString(String print) {
17
+        System.out.println(print);
18
+        return input.next();
19
+    }
20
+
21
+    public void printString(String print_statement) {
22
+        System.out.println(print_statement);
23
+    }
24
+}

+ 307
- 0
src/main/java/MockDao.java Vedi File

@@ -0,0 +1,307 @@
1
+import com.j256.ormlite.dao.*;
2
+import com.j256.ormlite.field.DataType;
3
+import com.j256.ormlite.field.FieldType;
4
+import com.j256.ormlite.stmt.*;
5
+import com.j256.ormlite.support.ConnectionSource;
6
+import com.j256.ormlite.support.DatabaseConnection;
7
+import com.j256.ormlite.support.DatabaseResults;
8
+import com.j256.ormlite.table.ObjectFactory;
9
+
10
+import java.sql.SQLException;
11
+import java.util.ArrayList;
12
+import java.util.Collection;
13
+import java.util.List;
14
+import java.util.Map;
15
+import java.util.concurrent.Callable;
16
+
17
+public class MockDao implements Dao<Account, Integer> {
18
+    Account account = new Account();
19
+
20
+
21
+    public Account queryForId(Integer integer) throws SQLException {
22
+        return null;
23
+    }
24
+
25
+    public Account queryForFirst(PreparedQuery<Account> preparedQuery) throws SQLException {
26
+        return null;
27
+    }
28
+
29
+    public List<Account> queryForAll() throws SQLException {
30
+        List<Account> accounts = new ArrayList<Account>();
31
+        account.setName("xyz");
32
+        account.setPassword("raw");
33
+        return accounts;
34
+    }
35
+
36
+    public List<Account> queryForEq(String s, Object o) throws SQLException {
37
+        return null;
38
+    }
39
+
40
+    public List<Account> queryForMatching(Account account) throws SQLException {
41
+        return null;
42
+    }
43
+
44
+    public List<Account> queryForMatchingArgs(Account account) throws SQLException {
45
+        return null;
46
+    }
47
+
48
+    public List<Account> queryForFieldValues(Map<String, Object> map) throws SQLException {
49
+        return null;
50
+    }
51
+
52
+    public List<Account> queryForFieldValuesArgs(Map<String, Object> map) throws SQLException {
53
+        return null;
54
+    }
55
+
56
+    public Account queryForSameId(Account account) throws SQLException {
57
+        return null;
58
+    }
59
+
60
+    public QueryBuilder<Account, Integer> queryBuilder() {
61
+        return null;
62
+    }
63
+
64
+    public UpdateBuilder<Account, Integer> updateBuilder() {
65
+        return null;
66
+    }
67
+
68
+    public DeleteBuilder<Account, Integer> deleteBuilder() {
69
+        return null;
70
+    }
71
+
72
+    public List<Account> query(PreparedQuery<Account> preparedQuery) throws SQLException {
73
+        return null;
74
+    }
75
+
76
+    public int create(Account account) throws SQLException {
77
+        return 1;
78
+    }
79
+
80
+    public Account createIfNotExists(Account account) throws SQLException {
81
+        return null;
82
+    }
83
+
84
+    public CreateOrUpdateStatus createOrUpdate(Account account) throws SQLException {
85
+        return null;
86
+    }
87
+
88
+    public int update(Account account) throws SQLException {
89
+        return 1;
90
+    }
91
+
92
+    public int updateId(Account account, Integer integer) throws SQLException {
93
+        return 0;
94
+    }
95
+
96
+    public int update(PreparedUpdate<Account> preparedUpdate) throws SQLException {
97
+        return 0;
98
+    }
99
+
100
+    public int refresh(Account account) throws SQLException {
101
+        return 0;
102
+    }
103
+
104
+    public int delete(Account account) throws SQLException {
105
+        return 1;
106
+    }
107
+
108
+    public int deleteById(Integer integer) throws SQLException {
109
+        return 0;
110
+    }
111
+
112
+    public int delete(Collection<Account> collection) throws SQLException {
113
+        return 0;
114
+    }
115
+
116
+    public int deleteIds(Collection<Integer> collection) throws SQLException {
117
+        return 0;
118
+    }
119
+
120
+    public int delete(PreparedDelete<Account> preparedDelete) throws SQLException {
121
+        return 1;
122
+    }
123
+
124
+    public CloseableIterator<Account> iterator() {
125
+        return null;
126
+    }
127
+
128
+    public CloseableIterator<Account> iterator(int i) {
129
+        return null;
130
+    }
131
+
132
+    public CloseableIterator<Account> iterator(PreparedQuery<Account> preparedQuery) throws SQLException {
133
+        return null;
134
+    }
135
+
136
+    public CloseableIterator<Account> iterator(PreparedQuery<Account> preparedQuery, int i) throws SQLException {
137
+        return null;
138
+    }
139
+
140
+    public CloseableWrappedIterable<Account> getWrappedIterable() {
141
+        return null;
142
+    }
143
+
144
+    public CloseableWrappedIterable<Account> getWrappedIterable(PreparedQuery<Account> preparedQuery) {
145
+        return null;
146
+    }
147
+
148
+    public void closeLastIterator() throws SQLException {
149
+
150
+    }
151
+
152
+    public GenericRawResults<String[]> queryRaw(String s, String... strings) throws SQLException {
153
+        return null;
154
+    }
155
+
156
+    public <UO> GenericRawResults<UO> queryRaw(String s, RawRowMapper<UO> rawRowMapper, String... strings) throws SQLException {
157
+        return null;
158
+    }
159
+
160
+    public <UO> GenericRawResults<UO> queryRaw(String s, DataType[] dataTypes, RawRowObjectMapper<UO> rawRowObjectMapper, String... strings) throws SQLException {
161
+        return null;
162
+    }
163
+
164
+    public GenericRawResults<Object[]> queryRaw(String s, DataType[] dataTypes, String... strings) throws SQLException {
165
+        return null;
166
+    }
167
+
168
+    public long queryRawValue(String s, String... strings) throws SQLException {
169
+        return 0;
170
+    }
171
+
172
+    public int executeRaw(String s, String... strings) throws SQLException {
173
+        return 0;
174
+    }
175
+
176
+    public int executeRawNoArgs(String s) throws SQLException {
177
+        return 0;
178
+    }
179
+
180
+    public int updateRaw(String s, String... strings) throws SQLException {
181
+        return 0;
182
+    }
183
+
184
+    public <CT> CT callBatchTasks(Callable<CT> callable) throws Exception {
185
+        return null;
186
+    }
187
+
188
+    public String objectToString(Account account) {
189
+        return null;
190
+    }
191
+
192
+    public boolean objectsEqual(Account account, Account t1) throws SQLException {
193
+        return false;
194
+    }
195
+
196
+    public Integer extractId(Account account) throws SQLException {
197
+        return null;
198
+    }
199
+
200
+    public Class<Account> getDataClass() {
201
+        return null;
202
+    }
203
+
204
+    public FieldType findForeignFieldType(Class<?> aClass) {
205
+        return null;
206
+    }
207
+
208
+    public boolean isUpdatable() {
209
+        return false;
210
+    }
211
+
212
+    public boolean isTableExists() throws SQLException {
213
+        return false;
214
+    }
215
+
216
+    public long countOf() throws SQLException {
217
+        return 0;
218
+    }
219
+
220
+    public long countOf(PreparedQuery<Account> preparedQuery) throws SQLException {
221
+        return 0;
222
+    }
223
+
224
+    public void assignEmptyForeignCollection(Account account, String s) throws SQLException {
225
+
226
+    }
227
+
228
+    public <FT> ForeignCollection<FT> getEmptyForeignCollection(String s) throws SQLException {
229
+        return null;
230
+    }
231
+
232
+    public void setObjectCache(boolean b) throws SQLException {
233
+
234
+    }
235
+
236
+    public void setObjectCache(ObjectCache objectCache) throws SQLException {
237
+
238
+    }
239
+
240
+    public ObjectCache getObjectCache() {
241
+        return null;
242
+    }
243
+
244
+    public void clearObjectCache() {
245
+
246
+    }
247
+
248
+    public Account mapSelectStarRow(DatabaseResults databaseResults) throws SQLException {
249
+        return null;
250
+    }
251
+
252
+    public GenericRowMapper<Account> getSelectStarRowMapper() throws SQLException {
253
+        return null;
254
+    }
255
+
256
+    public RawRowMapper<Account> getRawRowMapper() {
257
+        return null;
258
+    }
259
+
260
+    public boolean idExists(Integer integer) throws SQLException {
261
+        return false;
262
+    }
263
+
264
+    public DatabaseConnection startThreadConnection() throws SQLException {
265
+        return null;
266
+    }
267
+
268
+    public void endThreadConnection(DatabaseConnection databaseConnection) throws SQLException {
269
+
270
+    }
271
+
272
+    public void setAutoCommit(boolean b) throws SQLException {
273
+
274
+    }
275
+
276
+    public void setAutoCommit(DatabaseConnection databaseConnection, boolean b) throws SQLException {
277
+
278
+    }
279
+
280
+    public boolean isAutoCommit() throws SQLException {
281
+        return false;
282
+    }
283
+
284
+    public boolean isAutoCommit(DatabaseConnection databaseConnection) throws SQLException {
285
+        return false;
286
+    }
287
+
288
+    public void commit(DatabaseConnection databaseConnection) throws SQLException {
289
+
290
+    }
291
+
292
+    public void rollBack(DatabaseConnection databaseConnection) throws SQLException {
293
+
294
+    }
295
+
296
+    public ConnectionSource getConnectionSource() {
297
+        return null;
298
+    }
299
+
300
+    public void setObjectFactory(ObjectFactory<Account> objectFactory) {
301
+
302
+    }
303
+
304
+    public CloseableIterator<Account> closeableIterator() {
305
+        return null;
306
+    }
307
+}

+ 98
- 0
src/main/java/Service.java Vedi File

@@ -0,0 +1,98 @@
1
+import com.j256.ormlite.dao.Dao;
2
+
3
+
4
+import java.sql.SQLException;
5
+import java.util.List;
6
+
7
+public class Service {
8
+    private Account account;
9
+    private Dao<Account, Integer> accountDao;
10
+    Console console;
11
+
12
+    public Service(Dao<Account, Integer> accountDao, Account account) {
13
+        this.accountDao = accountDao;
14
+        this.account = account;
15
+        console = new Console();
16
+
17
+    }
18
+
19
+    public int create() {
20
+        try {
21
+            accountDao.create(account);
22
+            return 1;
23
+        } catch (SQLException e) {
24
+            e.printStackTrace();
25
+        }
26
+        return 0;
27
+    }
28
+
29
+    public int read(){
30
+        String name = readName();
31
+        String  id = ""+console.readInteger("Enter your id to get the account details");
32
+        try {
33
+            List<Account> accountList =
34
+                    accountDao.queryBuilder().where()
35
+                            .eq(account.getName(), name)
36
+                            .and()
37
+                            .eq(""+account.getId(), id)
38
+                            .query();
39
+            return accountList.size();
40
+        } catch (SQLException e) {
41
+            e.printStackTrace();
42
+        }
43
+        return 0;
44
+    }
45
+
46
+    public int update(){
47
+        int choice = console.readInteger("Enter 1 to change the name \n2 to change the password");
48
+        if(choice == 1){
49
+           updateName();
50
+           return 1;
51
+        }
52
+        else {
53
+            updatePassword();
54
+        }
55
+        return 0;
56
+    }
57
+
58
+    public int delete(){
59
+        try {
60
+            accountDao.delete(account);
61
+            return 1;
62
+        } catch (SQLException e) {
63
+            e.printStackTrace();
64
+        }
65
+        return 0;
66
+    }
67
+
68
+    public void updateName(){
69
+        String name = readName();
70
+        account.setName(name);
71
+        try {
72
+            accountDao.update(account);
73
+        } catch (SQLException e) {
74
+            e.printStackTrace();
75
+        }
76
+    }
77
+
78
+    public void updatePassword(){
79
+        String password = readPassword();
80
+        account.setPassword(password);
81
+        try {
82
+            accountDao.update(account);
83
+        } catch (SQLException e) {
84
+            e.printStackTrace();
85
+        }
86
+    }
87
+
88
+    public String readName(){
89
+       String name =  console.readString("Enter your name : ");
90
+       return name;
91
+    }
92
+
93
+    public String readPassword(){
94
+        String password = console.readString("Enter your password : ");
95
+        return password;
96
+    }
97
+
98
+}

+ 39
- 0
src/test/java/AccountServiceTest.java Vedi File

@@ -0,0 +1,39 @@
1
+import org.junit.Test;
2
+import org.junit.Assert;
3
+
4
+
5
+public class AccountServiceTest {
6
+
7
+   MockDao dao = new MockDao();
8
+   Account account = new Account();
9
+   Service service = new Service(dao,account);
10
+
11
+   @Test
12
+    public void testCreate(){
13
+      int expected = 1;
14
+      int actual = service.create();
15
+      Assert.assertEquals(expected, actual);
16
+   }
17
+
18
+   @Test
19
+   public void testUpdate(){
20
+      int expected = 1;
21
+      int actual = service.create();
22
+      Assert.assertEquals(expected, actual);
23
+   }
24
+
25
+   @Test
26
+   public void testDelete(){
27
+      int expected = 1;
28
+      int actual = service.delete();
29
+      Assert.assertEquals(expected, actual);
30
+   }
31
+
32
+   @Test
33
+   public void testRead(){
34
+      service.create();
35
+      int expected = 1;
36
+      int actual = service.read();
37
+      Assert.assertEquals(expected, actual);
38
+   }
39
+}

BIN
target/classes/Account.class Vedi File


BIN
target/classes/AccountApp.class Vedi File


BIN
target/classes/AccountServiceTest.class Vedi File


BIN
target/classes/Console.class Vedi File


BIN
target/classes/MockDao.class Vedi File


BIN
target/classes/Service.class Vedi File