Skip to content

Commit

Permalink
Merge branch 'release/v1.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed May 27, 2018
2 parents 642531a + 08c6542 commit 656f4d5
Show file tree
Hide file tree
Showing 75 changed files with 1,325 additions and 310 deletions.
54 changes: 54 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions .idea/runConfigurations/FafApiApplication.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ apply plugin: 'propdeps'
apply plugin: 'idea'

group = 'faforever'
version = '1.0.0'
version = '1.4.1'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -191,7 +191,7 @@ configurations {
task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
main = "com.codacy.CodacyCoverageReporter"
classpath = configurations.codacy
args = ["-l", "Java", "-r", "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"]
args = ["report", "-l", "Java", "-r", "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"]
}

// DOCKER
Expand Down Expand Up @@ -285,6 +285,7 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-mail")
compile("de.codecentric:spring-boot-admin-starter-client:${springBootAdminClientVersion}")

compile("com.github.FAForever:faf-java-commons:${fafCommonsVersion}")
Expand Down Expand Up @@ -332,5 +333,5 @@ dependencies {
testCompile("com.jayway.jsonpath:json-path:${jsonPath}")
testCompile("com.jayway.jsonpath:json-path-assert:${jsonPathAssert}")

codacy("com.github.codacy:codacy-coverage-reporter:-SNAPSHOT")
codacy("com.github.codacy:codacy-coverage-reporter:${codacyCoverageReporterVersion}")
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ jsonPathAssert=2.2.0
thymeleafVersion=3.0.5.RELEASE
prometheusVersion=0.0.26
jsonapiConverterVersion=0.8
codacyCoverageReporterVersion=4.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@Transactional
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultUser.sql")
public abstract class AbstractIntegrationTest {
protected final static String AUTH_WEBSITE = "WEBSITE";
protected final static String AUTH_USER = "USER";
protected final static String AUTH_MODERATOR = "MODERATOR";
protected final static String AUTH_ADMIN = "ADMIN";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.faforever.api.AbstractIntegrationTest;
import com.faforever.api.data.domain.Avatar;
import com.faforever.api.security.AuditService;
import com.faforever.api.security.OAuthScope;
import com.faforever.api.utils.FileHandlingHelper;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.test.context.support.WithUserDetails;
Expand All @@ -22,6 +24,9 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand All @@ -30,6 +35,8 @@
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepAvatarData.sql")
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:sql/cleanAvatarData.sql")
public class AvatarControllerTest extends AbstractIntegrationTest {
@SpyBean
AuditService auditServiceSpy;

@Autowired
AvatarRepository avatarRepository;
Expand All @@ -45,6 +52,8 @@ public void moderatorCanUpload() throws Exception {
final Avatar avatar = avatarRepository.findOneByUrl("http://localhost/faf/avatars/avatar3.png").get();
assertThat(avatar.getUrl(), is("http://localhost/faf/avatars/avatar3.png"));
assertThat(avatar.getTooltip(), is("Best avatar"));

verify(auditServiceSpy, times(1)).logMessage(any());
}

@Test
Expand All @@ -59,6 +68,7 @@ public void moderatorCanReupload() throws Exception {
final Avatar avatar = avatarRepository.findOneByUrl("http://localhost/faf/avatars/avatar1.png").get();
assertThat(avatar.getUrl(), is("http://localhost/faf/avatars/avatar1.png"));
assertThat(avatar.getTooltip(), is("Best avatar"));
verify(auditServiceSpy, times(1)).logMessage(any());
}

@Test
Expand All @@ -70,6 +80,7 @@ public void moderatorCanDeleteAvatar() throws Exception {
.with(getOAuthToken(OAuthScope._UPLOAD_AVATAR))
).andExpect(status().isNoContent());
assertThat(avatarRepository.findById(1), is(Optional.empty()));
verify(auditServiceSpy, times(1)).logMessage(any());
}

@Test
Expand All @@ -79,6 +90,7 @@ public void nonModeratorCannotUpload() throws Exception {
createAvatarUploadRequest()
.with(getOAuthToken(OAuthScope._UPLOAD_AVATAR))
).andExpect(status().isForbidden());
verify(auditServiceSpy, times(0)).logMessage(any());
}

@Test
Expand All @@ -88,6 +100,7 @@ public void nonModeratorCannotReupload() throws Exception {
createAvatarReuploadRequest(1)
.with(getOAuthToken(OAuthScope._UPLOAD_AVATAR))
).andExpect(status().isForbidden());
verify(auditServiceSpy, times(0)).logMessage(any());
}

@Test
Expand All @@ -97,6 +110,7 @@ public void nonModeratorCannotDelete() throws Exception {
delete("/avatars/1")
.with(getOAuthToken(OAuthScope._UPLOAD_AVATAR))
).andExpect(status().isForbidden());
verify(auditServiceSpy, times(0)).logMessage(any());
}

@Test
Expand All @@ -106,6 +120,7 @@ public void moderatorWithoutScopeCannotUpload() throws Exception {
createAvatarUploadRequest()
.with(getOAuthToken())
).andExpect(status().isForbidden());
verify(auditServiceSpy, times(0)).logMessage(any());
}

@Test
Expand All @@ -115,6 +130,7 @@ public void moderatorWithoutScopeCannotReupload() throws Exception {
createAvatarReuploadRequest(1)
.with(getOAuthToken())
).andExpect(status().isForbidden());
verify(auditServiceSpy, times(0)).logMessage(any());
}

@Test
Expand All @@ -124,6 +140,7 @@ public void moderatorWithoutScopeCannotDelete() throws Exception {
delete("/avatars/1")
.with(getOAuthToken())
).andExpect(status().isForbidden());
verify(auditServiceSpy, times(0)).logMessage(any());
}

@After
Expand Down
91 changes: 91 additions & 0 deletions src/inttest/java/com/faforever/api/data/MapVersionElideTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.faforever.api.data;

import com.faforever.api.AbstractIntegrationTest;
import org.junit.Test;
import org.springframework.security.test.context.support.WithUserDetails;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultUser.sql")
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepMapVersion.sql")
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:sql/cleanMapVersion.sql")
public class MapVersionElideTest extends AbstractIntegrationTest {

private static final String MAP_VERSION_HIDE_FALSE_ID_1 = "{\n" +
" \"data\": {\n" +
" \"type\": \"mapVersion\",\n" +
" \"id\": \"1\",\n" +
" \"attributes\": {\n" +
" \t\"hidden\": false\n" +
" }\n" +
" } \n" +
"}";
private static final String MAP_VERSION_HIDE_TRUE_ID_1 = "{\n" +
" \"data\": {\n" +
" \"type\": \"mapVersion\",\n" +
" \"id\": \"1\",\n" +
" \"attributes\": {\n" +
" \t\"hidden\": true\n" +
" }\n" +
" } \n" +
"}";
private static final String MAP_VERSION_RANKED_FALSE_ID_1 = "{\n" +
" \"data\": {\n" +
" \"type\": \"mapVersion\",\n" +
" \"id\": \"1\",\n" +
" \"attributes\": {\n" +
" \t\"ranked\": false\n" +
" }\n" +
" } \n" +
"}";
private static final String MAP_VERSION_RANKED_TRUE_ID_1 = "{\n" +
" \"data\": {\n" +
" \"type\": \"mapVersion\",\n" +
" \"id\": \"1\",\n" +
" \"attributes\": {\n" +
" \t\"ranked\": true\n" +
" }\n" +
" } \n" +
"}";


@WithUserDetails(AUTH_USER)
@Test
public void testUpdateHideToTrueDoesWork() throws Exception {
mockMvc.perform(
patch("/data/mapVersion/1")
.content(MAP_VERSION_HIDE_TRUE_ID_1))
.andExpect(status().isNoContent());
}

@WithUserDetails(AUTH_USER)
@Test
public void testUpdateHideToFalseDoesNotWork() throws Exception {
mockMvc.perform(
patch("/data/mapVersion/1")
.content(MAP_VERSION_HIDE_FALSE_ID_1))
.andExpect(status().isForbidden());
}


@WithUserDetails(AUTH_USER)
@Test
public void testUpdateRankedToFalseDoesWork() throws Exception {
mockMvc.perform(
patch("/data/mapVersion/1")
.content(MAP_VERSION_RANKED_FALSE_ID_1))
.andExpect(status().isNoContent());
}

@WithUserDetails(AUTH_USER)
@Test
public void testUpdateRankedToTrueDoesNotWork() throws Exception {
mockMvc.perform(
patch("/data/mapVersion/1")
.content(MAP_VERSION_RANKED_TRUE_ID_1))
.andExpect(status().isForbidden());
}
}
Loading

0 comments on commit 656f4d5

Please sign in to comment.