Skip to content

Commit

Permalink
Migrate all entities to field level annotations
Browse files Browse the repository at this point in the history
Closes #346
  • Loading branch information
Brutus5000 committed Jun 28, 2021
1 parent b715dce commit 3d2480c
Show file tree
Hide file tree
Showing 74 changed files with 1,410 additions and 1,908 deletions.
15 changes: 0 additions & 15 deletions src/inttest/java/com/faforever/api/data/ClanElideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ public class ClanElideTest extends AbstractIntegrationTest {
@Test
@WithUserDetails(AUTH_CLAN_LEADER)
public void canDeleteMemberOfOwnClan() throws Exception {
assertNotNull(playerRepository.getOne(12).getClan());

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

@Test
Expand All @@ -76,13 +73,9 @@ public void cannotDeleteLeaderFromClan() throws Exception {
@Test
@WithUserDetails(AUTH_CLAN_MEMBER)
public void canLeaveClan() throws Exception {
assertNotNull(playerRepository.getOne(12).getClan());

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

assertNull(playerRepository.getOne(12).getClan());
}

@Test
Expand All @@ -106,30 +99,22 @@ public void getFilteredPlayerForClanInvite() throws Exception {
@Test
@WithUserDetails(AUTH_CLAN_LEADER)
public void canTransferLeadershipAsLeader() throws Exception {
assertThat(clanRepository.getOne(1).getLeader().getLogin(), is(AUTH_CLAN_LEADER));

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

assertThat(clanRepository.getOne(1).getLeader().getLogin(), is(AUTH_CLAN_MEMBER));
}

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

mockMvc.perform(
patch("/data/clan/1")
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
.content(generateTransferLeadershipContent(1, 12))) // magic value from prepClanData.sql
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.errors[0].detail", is("UpdatePermission Denied")));

assertThat(clanRepository.getOne(1).getLeader().getLogin(), is(AUTH_CLAN_LEADER));
}

@Test
Expand Down
8 changes: 4 additions & 4 deletions src/inttest/java/com/faforever/api/data/MapElideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void canUpdateMapRecommendationToTrueWithScopeAndRole() throws Exception
.content(MAP_RECOMMENDED_TRUE_ID_1))
.andExpect(status().isNoContent());

assertThat(mapRepository.getOne(1).getRecommended(), is(true));
assertThat(mapRepository.getOne(1).isRecommended(), is(true));
}

@Test
Expand All @@ -81,7 +81,7 @@ public void cannotUpdateMapRecommendationToTrueWithoutScope() throws Exception {
.content(MAP_RECOMMENDED_TRUE_ID_1))
.andExpect(status().isForbidden());

assertThat(mapRepository.getOne(1).getRecommended(), is(false));
assertThat(mapRepository.getOne(1).isRecommended(), is(false));
}

@Test
Expand All @@ -94,7 +94,7 @@ public void cannotUpdateMapRecommendationToTrueWithoutRole() throws Exception {
.content(MAP_RECOMMENDED_TRUE_ID_1))
.andExpect(status().isForbidden());

assertThat(mapRepository.getOne(1).getRecommended(), is(false));
assertThat(mapRepository.getOne(1).isRecommended(), is(false));
}

@Test
Expand All @@ -107,7 +107,7 @@ public void canUpdateMapRecommendationToFalseWithScopeAndRole() throws Exception
.content(MAP_RECOMMENDED_FALSE_ID_1))
.andExpect(status().isNoContent());

assertThat(mapRepository.getOne(1).getRecommended(), is(false));
assertThat(mapRepository.getOne(1).isRecommended(), is(false));
}

@Test
Expand Down
8 changes: 4 additions & 4 deletions src/inttest/java/com/faforever/api/data/ModElideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void canUpdateModRecommendationToTrueWithScopeAndRole() throws Exception
.content(MOD_RECOMMENDED_TRUE_ID_1))
.andExpect(status().isNoContent());

assertThat(modRepository.getOne(1).getRecommended(), is(true));
assertThat(modRepository.getOne(1).isRecommended(), is(true));
}

@Test
Expand All @@ -81,7 +81,7 @@ public void cannotUpdateModRecommendationToTrueWithoutScope() throws Exception {
.content(MOD_RECOMMENDED_TRUE_ID_1))
.andExpect(status().isForbidden());

assertThat(modRepository.getOne(1).getRecommended(), is(false));
assertThat(modRepository.getOne(1).isRecommended(), is(false));
}

@Test
Expand All @@ -94,7 +94,7 @@ public void cannotUpdateModRecommendationToTrueWithoutRole() throws Exception {
.content(MOD_RECOMMENDED_TRUE_ID_1))
.andExpect(status().isForbidden());

assertThat(modRepository.getOne(1).getRecommended(), is(false));
assertThat(modRepository.getOne(1).isRecommended(), is(false));
}

@Test
Expand All @@ -107,7 +107,7 @@ public void canUpdateModRecommendationToFalseWithScopeAndRole() throws Exception
.content(MOD_RECOMMENDED_FALSE_ID_1))
.andExpect(status().isNoContent());

assertThat(modRepository.getOne(1).getRecommended(), is(false));
assertThat(modRepository.getOne(1).isRecommended(), is(false));
}

@Test
Expand Down
4 changes: 0 additions & 4 deletions src/inttest/java/com/faforever/api/data/UserNoteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,10 @@ public void cannotCreateUserNoteWithoutRole() throws Exception {

@Test
public void canCreateUserNoteWithScopeAndRole() throws Exception {
assertThat(playerRepository.getOne(3).getUserNotes().size(), is(0));

mockMvc.perform(post("/data/userNote")
.with(getOAuthTokenWithTestUser(OAuthScope._READ_SENSIBLE_USERDATA, GroupPermission.ROLE_ADMIN_ACCOUNT_NOTE))
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE)
.content(testPost))
.andExpect(status().isCreated());

assertThat(playerRepository.getOne(3).getUserNotes().size(), is(1));
}
}
1 change: 1 addition & 0 deletions src/inttest/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ logging:
org.springframework.security: DEBUG
org.springframework.transaction.interceptor: trace
org.springframework.orm.jpa.JpaTransactionManager: trace
com.yahoo: DEBUG
50 changes: 11 additions & 39 deletions src/main/java/com/faforever/api/client/OAuthClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.faforever.api.client;

import lombok.Setter;
import lombok.Data;
import org.jetbrains.annotations.Nullable;
import org.springframework.util.Assert;

Expand All @@ -15,71 +15,43 @@

@Entity
@Table(name = "oauth_clients")
@Setter
@Data
public class OAuthClient {

private String id;
private String name;
private String clientSecret;
private ClientType clientType;
private String redirectUris;
private String defaultRedirectUri;
private String defaultScope;
private String iconUrl;
private Boolean autoApproveScopes;

@Id
@Column(name = "id")
public String getId() {
return id;
}
private String id;

@NotNull
@Column(name = "name")
public String getName() {
return name;
}
private String name;

@NotNull
@Column(name = "client_secret")
public String getClientSecret() {
return clientSecret;
}
private String clientSecret;

@NotNull
@Column(name = "client_type")
public ClientType getClientType() {
return clientType;
}
private ClientType clientType;

@NotNull
@Column(name = "redirect_uris")
public String getRedirectUris() {
return redirectUris;
}
private String redirectUris;

@NotNull
@Column(name = "default_redirect_uri")
public String getDefaultRedirectUri() {
return defaultRedirectUri;
}
private String defaultRedirectUri;

@NotNull
@Column(name = "default_scope")
public String getDefaultScope() {
return defaultScope;
}
private String defaultScope;

@Column(name = "icon_url")
public String getIconUrl() {
return iconUrl;
}
private String iconUrl;

@Column(name = "auto_approve_scopes")
@Nullable
public Boolean isAutoApproveScopes() {
return autoApproveScopes;
}
private Boolean autoApproveScopes;

@Converter(autoApply = true)
public static class ClientTypeConverter implements AttributeConverter<ClientType, String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class UserGroupPublicCheck extends OperationCheck<UserGroup> {

@Override
public boolean ok(UserGroup object, RequestScope requestScope, Optional<ChangeSpec> changeSpec) {
return object.isPublic();
return object.isPublic_();
}
}
44 changes: 0 additions & 44 deletions src/main/java/com/faforever/api/data/domain/AbstractEntity.java

This file was deleted.

Loading

0 comments on commit 3d2480c

Please sign in to comment.