-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup of test environment #34
base: master
Are you sure you want to change the base?
Changes from all commits
92c11f9
c01c48b
4224575
a5cc918
7c29917
3386fd8
8be2550
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package de.marvinbrieger.toothbrushgame.mocks; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
public class ApplicationUserMocks { | ||
|
||
public static JSONObject MARVINS_DEVICE; | ||
|
||
public static JSONObject ELIAS_DEVICE; | ||
|
||
static { | ||
try { | ||
MARVINS_DEVICE = new JSONObject() | ||
.put("deviceId", "marvins device") | ||
.put("password", "marvins password"); | ||
|
||
ELIAS_DEVICE = new JSONObject() | ||
.put("deviceId", "elias device") | ||
.put("password", "elias password"); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,26 @@ | ||
package de.marvinbrieger.toothbrushgame.mocks; | ||
|
||
import de.marvinbrieger.toothbrushgame.domain.Game; | ||
import de.marvinbrieger.toothbrushgame.domain.GameStatus; | ||
import de.marvinbrieger.toothbrushgame.domain.MurderAssignment; | ||
import de.marvinbrieger.toothbrushgame.domain.Player; | ||
import de.marvinbrieger.toothbrushgame.services.AssignmentGeneratorService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static de.marvinbrieger.toothbrushgame.mocks.GamePreferencesMocks.STANDARD_PREFERENCES; | ||
import static de.marvinbrieger.toothbrushgame.mocks.PlayerMocks.ELIAS; | ||
import static de.marvinbrieger.toothbrushgame.mocks.PlayerMocks.STORED_ALEX; | ||
import static de.marvinbrieger.toothbrushgame.mocks.PlayerMocks.STORED_ELIAS; | ||
import static de.marvinbrieger.toothbrushgame.mocks.PlayerMocks.STORED_KIPF; | ||
import static de.marvinbrieger.toothbrushgame.mocks.PlayerMocks.STORED_MARVIN; | ||
import static de.marvinbrieger.toothbrushgame.mocks.PlayerMocks.STORED_NEUMANN; | ||
import static de.marvinbrieger.toothbrushgame.mocks.PlayerMocks.STORED_WINTER; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
public class GameMocks { | ||
|
||
public static final Game SOFTSKILL_GAME; | ||
|
||
public static final Game STORED_SOFTSKILL_GAME; | ||
|
||
public static final Game SOFTSKILL_GAME_MARVIN_JOINED; | ||
|
||
public static final Game SOFTSKILL_GAME_STARTED; | ||
public static JSONObject SOFTSKILL_GAME; | ||
|
||
static { | ||
SOFTSKILL_GAME = new Game(null, "Softskillkurs SE 14", STANDARD_PREFERENCES, | ||
null, ELIAS, null, null, null); | ||
|
||
List<Player> storedPlayers = new ArrayList(); | ||
storedPlayers.add(STORED_ELIAS); | ||
STORED_SOFTSKILL_GAME = new Game(1L, "Softskillkurs SE 14", STANDARD_PREFERENCES, | ||
"ANTZUF", STORED_ELIAS, GameStatus.PREPARATION, storedPlayers, null); | ||
|
||
List<Player> playersMarvinJoined = new ArrayList(); | ||
playersMarvinJoined.add(STORED_ELIAS); | ||
playersMarvinJoined.add(STORED_MARVIN); | ||
SOFTSKILL_GAME_MARVIN_JOINED = new Game(1L, "Softskillkurs SE 14", STANDARD_PREFERENCES, | ||
"ANTZUF", STORED_ELIAS, GameStatus.PREPARATION, playersMarvinJoined, null); | ||
|
||
List<Player> playersStartedGame = getPlayersList(); | ||
Game startedGame = new Game(1L, "Softskillkurs SE 14", STANDARD_PREFERENCES, | ||
"ANTZUF", STORED_ELIAS, GameStatus.RUNNING, playersStartedGame, null); | ||
AssignmentGeneratorService assignmentHelperService = new AssignmentGeneratorService(); | ||
List<MurderAssignment> murderAssignments = assignmentHelperService.generateKillAssignments(startedGame); | ||
startedGame.setMurderAssignments(murderAssignments); | ||
SOFTSKILL_GAME_STARTED = startedGame; | ||
try { | ||
SOFTSKILL_GAME = new JSONObject() | ||
.put("title", "SE 14") | ||
.put("preferences", new JSONObject() | ||
.put("dailyReassignment", false) | ||
.put("noAttestors", true) | ||
.put("furtherRules", "nicht beim Essen töten")) | ||
.put("owner", new JSONObject() | ||
.put("playerName", "Marvin")); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private static List<Player> getPlayersList() { | ||
List<Player> players = new ArrayList(); | ||
players.add(STORED_ELIAS); | ||
players.add(STORED_MARVIN); | ||
players.add(STORED_ALEX); | ||
players.add(STORED_KIPF); | ||
players.add(STORED_WINTER); | ||
players.add(STORED_NEUMANN); | ||
return players; | ||
} | ||
|
||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.marvinbrieger.toothbrushgame.utils; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class DbCleaningHelper { | ||
|
||
public static void truncateAllTables(Connection conn) throws SQLException { | ||
conn.createStatement().executeUpdate("SET FOREIGN_KEY_CHECKS=0"); | ||
ResultSet rs = conn.createStatement(). | ||
executeQuery("SELECT table_name FROM information_schema.tables WHERE table_schema = SCHEMA()"); | ||
|
||
while (rs.next()) { | ||
String tableName = rs.getString(1); | ||
conn.createStatement().executeUpdate("TRUNCATE TABLE " + tableName); | ||
} | ||
conn.createStatement().executeUpdate("SET FOREIGN_KEY_CHECKS=1"); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.marvinbrieger.toothbrushgame.utils; | ||
|
||
import org.json.JSONObject; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
|
||
abstract public class MockMvcHelper { | ||
|
||
public static MockHttpServletRequestBuilder withJsonHeaders(MockHttpServletRequestBuilder builder) { | ||
return builder.contentType(MediaType.APPLICATION_JSON) | ||
.characterEncoding("utf-8"); | ||
} | ||
|
||
} | ||
Comment on lines
+9
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There must be a more Spring style approch for doing that, probably something like: @Component
public class ContentTypeHeaderMockMvcBuilderCustomizer implements MockMvcBuilderCustomizer {
@Override
public void customize(ConfigurableMockMvcBuilder<?> builder) {
RequestBuilder improvedBuilder = MockMvcRequestBuilders.get("any")
.contentType(MediaType.APPLICATION_JSON)
.characterEncoding(StandardCharsets.UTF_8.name());
builder.defaultRequest(improvedBuilder);
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found and adapted from https://stackoverflow.com/questions/50532856/mockmvc-configure-a-header-for-all-requests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right and there are couples of other techniques. On the other side you wrote it to me yourself. Sometimes spring config stuff is complicated and especially it is not very domain specific. The whole utils stuff i wrote isn't in the spring style but it feasible to write down shortly the things we need. However in this special case it might be worth to adapt your solution :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we do not use checked exceptions? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as i remember there was a compilation problem and I made the quick fix. You are right we had this agreement, but then I ask myself why this compilation problem was on master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I remember Intelij suggested to add it because of compilation problems. But why then was it necessary? I pulled from master?
I check this out