-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
135 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/test/java/com/faforever/api/data/JsonApiBanIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.faforever.api.data; | ||
|
||
import com.faforever.integration.TestDatabase; | ||
import com.faforever.integration.factories.BanFactory; | ||
import com.faforever.integration.utils.MockMvcHelper; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
import javax.inject.Inject; | ||
import javax.servlet.Filter; | ||
|
||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
@Import(TestDatabase.class) | ||
public class JsonApiBanIntegrationTest { | ||
|
||
private MockMvc mvc; | ||
private WebApplicationContext context; | ||
private Filter springSecurityFilterChain; | ||
|
||
private TestDatabase database; | ||
|
||
@Inject | ||
public void init(TestDatabase database, WebApplicationContext context, Filter springSecurityFilterChain) { | ||
this.context = context; | ||
this.springSecurityFilterChain = springSecurityFilterChain; | ||
this.database = database; | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
mvc = MockMvcBuilders | ||
.webAppContextSetup(context) | ||
.addFilter(springSecurityFilterChain) | ||
.build(); | ||
database.assertEmptyDatabase(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
// TODO: This is needed, because Elide has some problems with @Transactional annotation #71 | ||
database.tearDown(); | ||
} | ||
|
||
@Test | ||
public void getBansWithoutToken() throws Exception { | ||
BanFactory.builder().database(database).build(); | ||
assertEquals(1, database.getBanRepository().count()); | ||
assertEquals(2, database.getPlayerRepository().count()); | ||
|
||
MockMvcHelper.of(this.mvc).perform( | ||
get("/data/banInfo")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.data", hasSize(0))); | ||
|
||
assertEquals(1, database.getBanRepository().count()); | ||
assertEquals(2, database.getPlayerRepository().count()); | ||
} | ||
|
||
// TODO: implement more tests if permission system is ready #81 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/com/faforever/integration/factories/BanFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.faforever.integration.factories; | ||
|
||
import com.faforever.api.data.domain.BanInfo; | ||
import com.faforever.api.data.domain.BanLevel; | ||
import com.faforever.api.data.domain.Player; | ||
import com.faforever.integration.TestDatabase; | ||
import lombok.Builder; | ||
import lombok.SneakyThrows; | ||
import org.springframework.util.Assert; | ||
|
||
import java.time.OffsetDateTime; | ||
|
||
public class BanFactory { | ||
public static final String PLAYER_NAME_BANNED = "JUnitBannedPlayer"; | ||
public static final String PLAYER_NAME_AUTHOR = "JUnitBanAuthor"; | ||
public static final String DEFAULT_REASON = "This is a cool ban reason"; | ||
|
||
|
||
@Builder | ||
@SneakyThrows | ||
public static BanInfo createBan(Player player, Player author, String reason, | ||
BanLevel level, OffsetDateTime expiresAt, TestDatabase database) { | ||
Assert.notNull(database, "'database' must not be null"); | ||
BanInfo ban = new BanInfo() | ||
.setPlayer(player != null ? player : PlayerFactory.createPlayer(PLAYER_NAME_BANNED, database)) | ||
.setAuthor(author != null ? author : PlayerFactory.createPlayer(PLAYER_NAME_AUTHOR, database)) | ||
.setExpiresAt(expiresAt) | ||
.setLevel(level) | ||
.setReason(reason != null ? reason : DEFAULT_REASON); | ||
return database.getBanRepository().save(ban); | ||
} | ||
|
||
} |