Skip to content

Commit

Permalink
#41 use MySQL database for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Oct 31, 2017
1 parent 10ca316 commit fbff4ef
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ git:
before_install:
- sudo /etc/init.d/mysql stop
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.10.0/docker-compose-`uname -s`-`uname -m` > /tmp/docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` > /tmp/docker-compose
- chmod +x /tmp/docker-compose
- sudo mv /tmp/docker-compose /usr/local/bin

install:
- git clone https://github.com/FAForever/faf-stack.git faf-stack
&& pushd faf-stack
&& git checkout 024322dfef9c600f458b91baeb1b4a7326b31580
&& git checkout 17.10.26
&& cp -r config.template config
&& popd
- docker-compose -f faf-stack/docker-compose.yml up -d faf-db
Expand Down
27 changes: 24 additions & 3 deletions src/inttest/java/com/faforever/api/user/UserControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.faforever.api.AbstractIntegrationTest;
import com.faforever.api.data.domain.User;
import com.faforever.api.email.EmailSender;
import com.faforever.api.error.ErrorCode;
import com.faforever.api.security.OAuthScope;
import com.google.common.collect.Sets;
Expand All @@ -26,18 +27,38 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class UserControllerTest extends AbstractIntegrationTest {
public static final String NEW_USER = "newUser";
public static final String NEW_PASSWORD = "newPassword";
public static final String NEW_EMAIL = "test@faforever.com";

@MockBean
private AnopeUserRepository anopeUserRepository;

@MockBean
private EmailSender emailSender;

@Autowired
private UserRepository userRepository;

@Test
public void registerWithSuccess() throws Exception {
MultiValueMap<String, String> params = new HttpHeaders();
params.add("username", NEW_USER);
params.add("email", NEW_EMAIL);
params.add("password", NEW_PASSWORD);

mockMvc.perform(post("/users/register").params(params))
.andExpect(status().isOk());

verify(emailSender, times(1)).sendMail(anyString(), anyString(), eq(NEW_EMAIL), anyString(), anyString());
}

@Test
@WithUserDetails(AUTH_USER)
public void changePasswordWithSuccess() throws Exception {
MultiValueMap<String, String> params = new HttpHeaders();
params.add("currentPassword", AUTH_USER);
params.add("newPassword", "newPassword");
params.add("newPassword", NEW_PASSWORD);

RequestPostProcessor oauthToken = oAuthHelper.addBearerToken(Sets.newHashSet(OAuthScope._WRITE_ACCOUNT_DATA));
mockMvc.perform(post("/users/changePassword").with(oauthToken).params(params))
Expand All @@ -53,7 +74,7 @@ public void changePasswordWithSuccess() throws Exception {
public void changePasswordWithWrongScope() throws Exception {
MultiValueMap<String, String> params = new HttpHeaders();
params.add("currentPassword", AUTH_USER);
params.add("newPassword", "newPassword");
params.add("newPassword", NEW_PASSWORD);

RequestPostProcessor oauthToken = oAuthHelper.addBearerToken(Collections.emptySet());
mockMvc.perform(post("/users/changePassword").with(oauthToken).params(params))
Expand All @@ -65,7 +86,7 @@ public void changePasswordWithWrongScope() throws Exception {
public void changePasswordWithWrongPassword() throws Exception {
MultiValueMap<String, String> params = new HttpHeaders();
params.add("currentPassword", "wrongPassword");
params.add("newPassword", "newPassword");
params.add("newPassword", NEW_PASSWORD);

RequestPostProcessor oauthToken = oAuthHelper.addBearerToken(Sets.newHashSet(OAuthScope._WRITE_ACCOUNT_DATA));
MvcResult mvcResult = mockMvc.perform(post("/users/changePassword").with(oauthToken).params(params))
Expand Down
16 changes: 11 additions & 5 deletions src/inttest/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ spring:
profiles:
include: int
datasource:
url: jdbc:h2:mem:faf
username: root
password: banana
driverClassName: org.h2.Driver
url: jdbc:mysql://${DATABASE_ADDRESS:localhost}/${DATABASE_NAME:faf}?useSSL=false
name: ${DATABASE_NAME:faf}
username: ${DATABASE_USERNAME:faf-java-api}
password: ${DATABASE_PASSWORD:banana}
jpa:
show-sql: true
hibernate:
ddl-auto: create
ddl-auto: ${DATABASE_DDL_AUTO:none}
properties:
hibernate:
current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext
Expand All @@ -29,3 +29,9 @@ faf-api:
website-url-format: "http://example.com/%s"
user:
minimum-days-between-username-change: 30
registration:
activation-url-format: "http://localhost/users/activate?token=%s"
subject: "Integration test registration"
html-format: "Integration test registration html body"
from-email: "integration-test@faforever.com"
from-name: "integration-test@faforever.com"
2 changes: 1 addition & 1 deletion src/main/java/com/faforever/api/data/domain/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public int getId() {
return id;
}

@Column(name = "key")
@Column(name = "`key`")
public String getKey() {
return key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public interface NameRecordRepository extends JpaRepository<NameRecord, Integer>
@Query(value = "SELECT datediff(now(), change_time) FROM name_history WHERE user_id = :userId AND datediff(now(), change_time) <= :maximumDaysAgo ORDER BY change_time DESC LIMIT 1", nativeQuery = true)
Optional<Integer> getDaysSinceLastNewRecord(@Param("userId") Integer userId, @Param("maximumDaysAgo") Integer maximumDaysAgo);

@Query(value = "SELECT user_id FROM name_history WHERE previous_name = ':name' AND now() > date_add(change_time, INTERVAL :months MONTH) ORDER BY change_time DESC LIMIT 1", nativeQuery = true)
@Query(value = "SELECT user_id FROM name_history WHERE previous_name = :name AND now() > date_add(change_time, INTERVAL :months MONTH) ORDER BY change_time DESC LIMIT 1", nativeQuery = true)
Optional<Integer> getLastUsernameOwnerWithinMonths(@Param("name") String name, @Param("months") Integer months);
}
4 changes: 4 additions & 0 deletions src/main/resources/config/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ faf-api:
featured-mods-target-directory: ${FEATURED_MODS_TARGET_DIRECTORY}
registration:
activation-url-format: ${ACTIVATION_URL_FORMAT}
subject: ${REGISTRATION_EMAIL_SUBJECT}
html-format: ${REGISTRATION_EMAIL_BODY}
from-email: ${REGISTRATION_EMAIL_FROM_EMAIL}
from-name: ${REGISTRATION_EMAIL_FROM_NAME}
password-reset:
password-reset-url-format: ${PASSWORD_RESET_URL_FORMAT}
mail:
Expand Down

0 comments on commit fbff4ef

Please sign in to comment.