Skip to content

Commit 8d07f7c

Browse files
committed
URL PATH of Actions - Controller Methods Refactoring
1 parent 99e0134 commit 8d07f7c

File tree

4 files changed

+52
-32
lines changed

4 files changed

+52
-32
lines changed

src/main/java/org/woehlke/simpleworklist/context/ContextService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public interface ContextService {
1313

1414
Context findByIdAndUserAccount(long newContextId, UserAccount userAccount);
1515

16-
void createNewContext(NewContextForm newContext, UserAccount user);
16+
Context createNewContext(NewContextForm newContext, UserAccount user);
1717

18-
void updateContext(Context context);
18+
Context updateContext(Context context);
1919

2020
boolean delete(Context context);
2121

src/main/java/org/woehlke/simpleworklist/context/ContextServiceImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ public Context findByIdAndUserAccount(long newContextId, UserAccount userAccount
4747

4848
@Override
4949
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
50-
public void createNewContext(NewContextForm newContext, UserAccount user) {
50+
public Context createNewContext(NewContextForm newContext, UserAccount user) {
5151
log.info("createNewContext");
5252
Context context = new Context();
5353
context.setNameEn(newContext.getNameEn());
5454
context.setNameDe(newContext.getNameDe());
5555
context.setUserAccount(user);
56-
contextRepository.saveAndFlush(context);
56+
return contextRepository.saveAndFlush(context);
5757
}
5858

5959
@Override
6060
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
61-
public void updateContext(Context context) {
61+
public Context updateContext(Context context) {
6262
log.info("updateContext");
63-
contextRepository.saveAndFlush(context);
63+
return contextRepository.saveAndFlush(context);
6464
}
6565

6666
@Override
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.woehlke.simpleworklist.config;
2+
3+
import lombok.Getter;
4+
import org.woehlke.simpleworklist.context.NewContextForm;
5+
import org.woehlke.simpleworklist.language.Language;
6+
import org.woehlke.simpleworklist.user.account.UserAccount;
7+
8+
import java.util.Date;
9+
10+
@Getter
11+
public class TestDataUser {
12+
13+
private final String[] emails = { "test01@test.de", "test02@test.de", "test03@test.de" };
14+
private final String[] passwords = { "test01pwd", "test02pwd", "test03pwd"};
15+
private final String[] fullnames = { "test01 Name", "test02 Name", "test03 Name"};
16+
17+
private final String username_email = "undefined@test.de";
18+
private final String password = "ASDFG";
19+
private final String full_name = "UNDEFINED_NAME";
20+
21+
private final UserAccount[] testUser;
22+
private final NewContextForm[] newContext;
23+
24+
public TestDataUser(){
25+
Date lastLoginTimestamp = new Date();
26+
testUser = new UserAccount[emails.length];
27+
newContext = new NewContextForm[emails.length];
28+
for (int i = 0; i < testUser.length; i++) {
29+
testUser[i] = new UserAccount();
30+
testUser[i].setUserEmail(emails[i]);
31+
testUser[i].setUserPassword(passwords[i]);
32+
testUser[i].setUserFullname(fullnames[i]);
33+
testUser[i].setDefaultLanguage(Language.EN);
34+
testUser[i].setLastLoginTimestamp(lastLoginTimestamp);
35+
newContext[i] = new NewContextForm("testDe_"+i,"testEn_"+i);
36+
}
37+
}
38+
}

src/test/java/org/woehlke/simpleworklist/userstories/F001ServerStartsTest.java

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.springframework.test.web.servlet.MockMvc;
1616
import org.springframework.web.context.WebApplicationContext;
1717
import org.woehlke.simpleworklist.config.ApplicationProperties;
18+
import org.woehlke.simpleworklist.config.TestDataUser;
1819
import org.woehlke.simpleworklist.context.ContextService;
1920
import org.woehlke.simpleworklist.context.NewContextForm;
2021
import org.woehlke.simpleworklist.language.Language;
@@ -54,39 +55,20 @@ public class F001ServerStartsTest {
5455
@Autowired
5556
protected ContextService contextService;
5657

57-
protected static String[] emails = {"test01//@Test.de", "test02//@Test.de", "test03//@Test.de"};
58-
protected static String[] passwords = {"test01pwd", "test02pwd", "test03pwd"};
59-
protected static String[] fullnames = {"test01 Name", "test02 Name", "test03 Name"};
60-
61-
protected static String username_email = "undefined//@Test.de";
62-
protected static String password = "ASDFG";
63-
protected static String full_name = "UNDEFINED_NAME";
64-
65-
protected static UserAccount[] testUser = new UserAccount[emails.length];
66-
67-
static {
68-
Date lastLoginTimestamp = new Date();
69-
for (int i = 0; i < testUser.length; i++) {
70-
testUser[i] = new UserAccount();
71-
testUser[i].setUserEmail(emails[i]);
72-
testUser[i].setUserPassword(passwords[i]);
73-
testUser[i].setUserFullname(fullnames[i]);
74-
testUser[i].setDefaultLanguage(Language.EN);
75-
testUser[i].setLastLoginTimestamp(lastLoginTimestamp);
76-
}
77-
}
58+
private TestDataUser testDataUser = new TestDataUser();
7859

7960
@BeforeEach
8061
public void setUp() throws Exception {
8162
log.info(" //@BeforeEach ");
8263
this.base = new URL("http://localhost:" + port + "/");
8364
this.mockMvc = webAppContextSetup(wac).build();
84-
for (UserAccount u : testUser) {
85-
UserAccount a = userAccountService.findByUserEmail(u.getUserEmail());
65+
for (int i = 0; i < testDataUser.getTestUser().length; i++) {
66+
UserAccount a = userAccountService.findByUserEmail(testDataUser.getTestUser()[i].getUserEmail());
8667
if (a == null) {
87-
NewContextForm newContext = new NewContextForm("test","test");
88-
contextService.createNewContext(newContext,u);
89-
userAccountService.saveAndFlush(u);
68+
//NewContextForm newContext = new NewContextForm("test","test");
69+
//contextService.createNewContext(newContext,u);
70+
UserAccount persisted = userAccountService.saveAndFlush(testDataUser.getTestUser()[i]);
71+
testDataUser.getTestUser()[i] = persisted;
9072
}
9173
}
9274
}

0 commit comments

Comments
 (0)