Skip to content

Commit

Permalink
Merge da72a0c into 306eb2f
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Jul 24, 2018
2 parents 306eb2f + da72a0c commit 06fbe9d
Show file tree
Hide file tree
Showing 47 changed files with 465 additions and 250 deletions.
20 changes: 9 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ tasks.withType(Test) {

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'propdeps'
apply plugin: 'idea'

Expand Down Expand Up @@ -198,6 +199,7 @@ task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {

apply plugin: 'com.bmuschko.docker-remote-api'
apply plugin: 'application'
mainClassName = 'com.faforever.api.FafApiApplication'

import com.bmuschko.gradle.docker.DockerRemoteApiPlugin
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
Expand Down Expand Up @@ -270,41 +272,40 @@ build.dependsOn inttest

dependencyManagement {
dependencies {
dependency("org.hibernate:hibernate-core:${hibernateVersion}")
dependency("org.hibernate:hibernate-entitymanager:${hibernateVersion}")
dependency("org.hibernate:hibernate-validator:${hibernateVersion}")
dependency("org.mockito:mockito-core:${mockitoVersion}")
}
}

dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
runtime("io.micrometer:micrometer-registry-prometheus")

compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-web")
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.ben-manes.caffeine:caffeine")
compile("com.github.FAForever:faf-java-commons:${fafCommonsVersion}")
compile("org.kohsuke:github-api:${githubApiVersion}")
compile("org.jolokia:jolokia-core")
compile("org.springframework.security:spring-security-jwt:${springSecurityJwtVersion}")
compile("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:${springSecurityOauth2AutoConfigureVersion}")
compile("org.springframework.security.oauth:spring-security-oauth2:${springSecurityOauth2Version}")
compile("org.springframework:spring-context-support:${springContextSupportVersion}")
compile("org.springframework.security:spring-security-jwt:${springSecurityJwtVersion}")
compile("org.eclipse.jgit:org.eclipse.jgit:${jgitVersionn}")
compile("org.jetbrains:annotations:${jetbrainsAnnotationsVersion}")
compile("com.google.guava:guava:${guavaVersion}")
compile("io.springfox:springfox-swagger-ui:${swaggerVersion}")
compile("io.springfox:springfox-swagger2:${swaggerVersion}")
compile("io.swagger:swagger-core:${swaggerCoreVersion}")
compile("javax.inject:javax.inject:${javaxInjectVersion}")
// When switching from Java 8 to 9, I got "class file for javax.interceptor.interceptorbinding not found". Adding this fixed it, but IDK what caused it.
compile("javax.interceptor:javax.interceptor-api:${javaxInterceptorApiVersion}")
compile("com.yahoo.elide:elide-core:${elideVersion}")
compile("com.yahoo.elide:elide-swagger:${elideVersion}")
compile("com.yahoo.elide:elide-datastore-hibernate5:${elideVersion}")
compile("org.hibernate:hibernate-java8:${hibernateVersion}")
// compile("org.glassfish.jersey.core:jersey-common:2.26")
compile("com.zaxxer:HikariCP:${hikariCpVersion}") {
exclude(module: 'tools')
Expand All @@ -317,9 +318,6 @@ dependencies {
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonDatatypeJsr310Version}")
compile("com.mandrillapp.wrapper.lutung:lutung:${lutungVersion}")
compile("org.apache.commons:commons-compress:${commonsCompressVersion}")
compile("io.prometheus:simpleclient_hotspot:${prometheusVersion}")
compile("io.prometheus:simpleclient_servlet:${prometheusVersion}")
compile("io.prometheus:simpleclient_spring_boot:${prometheusVersion}")
compile("org.json:json:${jsonVersion}")

compile("com.github.jasminb:jsonapi-converter:${jsonapiConverterVersion}")
Expand Down
17 changes: 8 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
profile=dev
springBootVersion=1.5.13.RELEASE
springBootVersion=2.0.3.RELEASE
jjwtVersion=0.7.0
javaxInjectVersion=1
elideVersion=3.1.4
hibernateVersion=5.1.0.Final
elideVersion=4.2.3
mysqlConnectorVersion=6.0.5
gradleDockerVersion=3.2.1
propdepsVersion=0.0.7
swaggerVersion=2.6.1
swaggerCoreVersion=1.5.8
coverallsGradlePluginVersion=2.4.0
hikariCpVersion=2.4.6
springSecurityJwtVersion=1.0.7.RELEASE
springSecurityOauth2Version=2.0.12.RELEASE
springContextSupportVersion=4.2.2.RELEASE
springSecurityJwtVersion=1.0.9.RELEASE
springSecurityOauth2AutoConfigureVersion=2.0.1.RELEASE
springSecurityOauth2Version=2.3.3.RELEASE
guavaVersion=21.0-rc1
jetbrainsAnnotationsVersion=13.0
springBootAdminClientVersion=1.4.5
springBootAdminClientVersion=2.0.0
luajVersion=3.0.1
nocatchVersion=1.1
junitAddonsVersion=1.4
Expand All @@ -26,13 +25,13 @@ jgitVersionn=4.5.0.201609210915-r
fafCommonsVersion=09ffb08f9538f66e6e9bccabceae1e6123a3fa27
h2Version=1.4.193
jacksonDatatypeJsr310Version=2.8.11
mockitoVersion=2.7.0
mockitoVersion=2.19.0
lutungVersion=0.0.7
commonsCompressVersion=1.13
jsonPath=2.2.0
jsonPathAssert=2.2.0
thymeleafVersion=3.0.5.RELEASE
prometheusVersion=0.0.26
jsonapiConverterVersion=0.8
codacyCoverageReporterVersion=4.0.0
jsonVersion=20180130
javaxInterceptorApiVersion=1.2
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.faforever.api;

import com.faforever.api.config.ApplicationProfile;
import com.faforever.api.config.ElideTestConfig;
import com.faforever.api.error.ErrorCode;
import com.faforever.api.utils.OAuthHelper;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand Down Expand Up @@ -34,7 +33,7 @@
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles(ApplicationProfile.INTEGRATION_TEST)
@Import({ElideTestConfig.class, OAuthHelper.class})
@Import({OAuthHelper.class})
@Transactional
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultUser.sql")
public abstract class AbstractIntegrationTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void meDataWithoutClan() throws Exception {
@WithUserDetails(AUTH_CLAN_MEMBER)
public void meDataWithClan() throws Exception {
Player player = getPlayer();
Clan clan = clanRepository.findOne(1);
Clan clan = clanRepository.findById(1).get();

mockMvc.perform(
get("/clans/me/"))
Expand Down
19 changes: 0 additions & 19 deletions src/inttest/java/com/faforever/api/config/ElideTestConfig.java

This file was deleted.

6 changes: 3 additions & 3 deletions src/inttest/java/com/faforever/api/data/AvatarElideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class AvatarElideTest extends AbstractIntegrationTest {

@Test
public void getUnusedAvatar() throws Exception {
Avatar avatar = avatarRepository.findOne(1);
Avatar avatar = avatarRepository.findById(1).get();

mockMvc.perform(get("/data/avatar/1"))
.andExpect(status().isOk())
Expand All @@ -52,7 +52,7 @@ public void getUnusedAvatar() throws Exception {

@Test
public void getAvatarWithPlayer() throws Exception {
Avatar avatar = avatarRepository.findOne(2);
Avatar avatar = avatarRepository.findById(2).get();

mockMvc.perform(get("/data/avatar/2"))
.andExpect(status().isOk())
Expand Down Expand Up @@ -80,7 +80,7 @@ public void moderatorCanAssignAvatar() throws Exception {
)
))
).andExpect(status().isCreated());
final Optional<AvatarAssignment> createdAssignment = avatarAssignmentRepository.findOneByAvatarAndPlayer(avatar, player);
Optional<AvatarAssignment> createdAssignment = avatarAssignmentRepository.findOneByAvatarIdAndPlayerId(1, 1);
assertThat(createdAssignment.isPresent(), is(true));
assertThat(createdAssignment.get().getPlayer().getId(), is(player.getId()));
assertThat(createdAssignment.get().getAvatar().getId(), is(avatar.getId()));
Expand Down
20 changes: 10 additions & 10 deletions src/inttest/java/com/faforever/api/data/ClanElideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public class ClanElideTest extends AbstractIntegrationTest {
@Test
@WithUserDetails(AUTH_CLAN_LEADER)
public void canDeleteMemberOfOwnClan() throws Exception {
assertNotNull(playerRepository.findOne(12).getClan());
assertNotNull(playerRepository.findById(12).get().getClan());

mockMvc.perform(
delete("/data/clanMembership/2")) // magic value from prepClanData.sql
.andExpect(status().isNoContent());
assertNull(playerRepository.findOne(12).getClan());
assertNull(playerRepository.findById(12).get().getClan());
}

@Test
Expand All @@ -75,13 +75,13 @@ public void cannotDeleteLeaderFromClan() throws Exception {
@Test
@WithUserDetails(AUTH_CLAN_MEMBER)
public void canLeaveClan() throws Exception {
assertNotNull(playerRepository.findOne(12).getClan());
assertNotNull(playerRepository.findById(12).get().getClan());

mockMvc.perform(
delete("/data/clanMembership/2")) // magic value from prepClanData.sql
.andExpect(status().isNoContent());

assertNull(playerRepository.findOne(12).getClan());
assertNull(playerRepository.findById(12).get().getClan());
}

@Test
Expand All @@ -105,28 +105,28 @@ public void getFilteredPlayerForClanInvite() throws Exception {
@Test
@WithUserDetails(AUTH_CLAN_LEADER)
public void canTransferLeadershipAsLeader() throws Exception {
assertThat(clanRepository.findOne(1).getLeader().getLogin(), is(AUTH_CLAN_LEADER));
assertThat(clanRepository.findById(1).get().getLeader().getLogin(), is(AUTH_CLAN_LEADER));

mockMvc.perform(
patch("/data/clan/1")
.content(generateTransferLeadershipContent(1, 12))) // magic value from prepClanData.sql
.andExpect(status().isNoContent());

assertThat(clanRepository.findOne(1).getLeader().getLogin(), is(AUTH_CLAN_MEMBER));
assertThat(clanRepository.findById(1).get().getLeader().getLogin(), is(AUTH_CLAN_MEMBER));
}

@Test
@WithUserDetails(AUTH_CLAN_MEMBER)
public void cannotTransferLeadershipAsMember() throws Exception {
assertThat(clanRepository.findOne(1).getLeader().getLogin(), is(AUTH_CLAN_LEADER));
assertThat(clanRepository.findById(1).get().getLeader().getLogin(), is(AUTH_CLAN_LEADER));

mockMvc.perform(
patch("/data/clan/1")
.content(generateTransferLeadershipContent(1, 12))) // magic value from prepClanData.sql
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.errors[0]", is("ForbiddenAccessException")));

assertThat(clanRepository.findOne(1).getLeader().getLogin(), is(AUTH_CLAN_LEADER));
assertThat(clanRepository.findById(1).get().getLeader().getLogin(), is(AUTH_CLAN_LEADER));
}

@Test
Expand All @@ -135,7 +135,7 @@ public void cannotTransferLeadershipToNonClanMember() throws Exception {
mockMvc.perform(
patch("/data/clan/1")
.content(generateTransferLeadershipContent(1, 1))) // magic value from prepClanData.sql
.andExpect(status().is5xxServerError()); // TODO: Catch javax.validation.ConstraintViolationException and wrap it into a regular ApiException
.andExpect(status().is4xxClientError()); // TODO: Catch javax.validation.ConstraintViolationException and wrap it into a regular ApiException
}

@SneakyThrows
Expand Down Expand Up @@ -174,7 +174,7 @@ public void canDeleteClanAsLeader() throws Exception {
.andExpect(status().isNoContent()); // TODO: Catch javax.validation.ConstraintViolationException and wrap it into a regular ApiException

assertFalse(clanRepository.findOneByName("Alpha Clan").isPresent());
clanMember.forEach(player -> assertNull(playerRepository.findOne(player.getId()).getClan()));
clanMember.forEach(player -> assertNull(playerRepository.findById(player.getId()).get().getClan()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void testRevealWinnerOnEndedSubjectWorks() throws Exception {
@WithUserDetails(AUTH_MODERATOR)
public void testRevealWinnerOnNoneEndedSubjectFails() throws Exception {
mockMvc.perform(patch("/data/votingSubject/1").content(PATCH_VOTING_SUBJECT_REVEAL_ID_1))
.andExpect(status().is(500));
.andExpect(status().is4xxClientError());
}

@Test
Expand Down
12 changes: 6 additions & 6 deletions src/inttest/java/com/faforever/api/user/UsersControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public void buildSteamLinkUrl() throws Exception {
@Test
@WithAnonymousUser
public void linkToSteam() throws Exception {
assertThat(userRepository.findOne(1).getSteamId(), nullValue());
assertThat(userRepository.findById(1).get().getSteamId(), nullValue());

String steamId = "1234";
String callbackUrl = "callbackUrl";
Expand All @@ -337,7 +337,7 @@ public void linkToSteam() throws Exception {
.andExpect(status().isFound())
.andExpect(redirectedUrl(callbackUrl));

assertThat(userRepository.findOne(2).getSteamId(), is(steamId));
assertThat(userRepository.findById(2).get().getSteamId(), is(steamId));
}

@Test
Expand Down Expand Up @@ -367,7 +367,7 @@ public void changeUsernameWithWrongScope() throws Exception {
@Test
@WithUserDetails(AUTH_USER)
public void changeUsernameSuccess() throws Exception {
assertThat(userRepository.findOne(1).getLogin(), is(AUTH_USER));
assertThat(userRepository.findById(1).get().getLogin(), is(AUTH_USER));

MultiValueMap<String, String> params = new HttpHeaders();
params.add("newUsername", NEW_USER);
Expand All @@ -378,13 +378,13 @@ public void changeUsernameSuccess() throws Exception {
.params(params))
.andExpect(status().isOk());

assertThat(userRepository.findOne(1).getLogin(), is(NEW_USER));
assertThat(userRepository.findById(1).get().getLogin(), is(NEW_USER));
}

@Test
@WithUserDetails(AUTH_MODERATOR)
public void changeUsernameTooEarly() throws Exception {
assertThat(userRepository.findOne(2).getLogin(), is(AUTH_MODERATOR));
assertThat(userRepository.findById(2).get().getLogin(), is(AUTH_MODERATOR));

MultiValueMap<String, String> params = new HttpHeaders();
params.add("newUsername", NEW_USER);
Expand All @@ -398,6 +398,6 @@ public void changeUsernameTooEarly() throws Exception {

assertApiError(result, ErrorCode.USERNAME_CHANGE_TOO_EARLY);

assertThat(userRepository.findOne(2).getLogin(), is(AUTH_MODERATOR));
assertThat(userRepository.findById(2).get().getLogin(), is(AUTH_MODERATOR));
}
}
9 changes: 5 additions & 4 deletions src/inttest/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ spring:
console:
enabled: true

security:
oauth2:
resource:
filter-order: 3

faf-api:
jwt:
Expand Down Expand Up @@ -70,3 +66,8 @@ faf-api:
mautic:
client-id: banana
client-secret: banana


logging:
level:
org.springframework.security: DEBUG
3 changes: 2 additions & 1 deletion src/inttest/resources/sql/prepDefaultUser.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ DELETE FROM login;

INSERT INTO oauth_clients (id, name, client_secret, client_type, redirect_uris, default_redirect_uri, default_scope)
VALUES
('test', 'test', 'test', 'public', 'http://localhost https://www.getpostman.com/oauth2/callback ', 'http://localhost',
('test', 'test', '{noop}test', 'public', 'http://localhost https://www.getpostman.com/oauth2/callback ',
'http://localhost',
'read_events read_achievements upload_map upload_mod upload_avatar write_account_data vote');

INSERT INTO login (id, login, email, password, steamid)
Expand Down
2 changes: 1 addition & 1 deletion src/inttest/resources/sql/prepVotingData.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DELETE FROM voting_subject;

INSERT INTO voting_subject (id, subject_key, begin_of_vote_time, end_of_vote_time, min_games_to_vote, description_key, topic_url)
VALUES
(1, 'subject', NOW(), DATE_ADD(NOW(), INTERVAL 1 YEAR), 0, 'des', 'www.google.de');
(1, 'subject', NOW() - INTERVAL 1 MINUTE, DATE_ADD(NOW(), INTERVAL 1 YEAR), 0, 'des', 'www.google.de');

INSERT INTO voting_subject (id, subject_key, reveal_winner, begin_of_vote_time, end_of_vote_time, min_games_to_vote, description_key, topic_url)
VALUES
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/faforever/api/FafApiApplication.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.faforever.api;

import com.faforever.api.config.FafApiProperties;
import io.prometheus.client.spring.boot.EnablePrometheusEndpoint;
import io.prometheus.client.spring.boot.EnableSpringBootMetricsCollector;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
@EnableTransactionManagement
@EnableConfigurationProperties({FafApiProperties.class})
public class FafApiApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
public interface AvatarAssignmentRepository extends JpaRepository<AvatarAssignment, Integer> {
Optional<AvatarAssignment> findOneByAvatarAndPlayer(Avatar avatar, Player player);

Optional<AvatarAssignment> findOneByAvatarIdAndPlayerId(int avatarId, int playerId);

Optional<AvatarAssignment> findOneById(Integer i);
}

0 comments on commit 06fbe9d

Please sign in to comment.