-
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.
Provide BiReUS repository URLs for featured mods
Fixes #134
- Loading branch information
1 parent
b12259b
commit 8a0092f
Showing
7 changed files
with
81 additions
and
5 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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/faforever/api/data/domain/FeaturedModEnricher.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,25 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.config.FafApiProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.PostLoad; | ||
|
||
@Component | ||
public class FeaturedModEnricher { | ||
private static FafApiProperties fafApiProperties; | ||
|
||
@Inject | ||
public void init(FafApiProperties fafApiProperties) { | ||
FeaturedModEnricher.fafApiProperties = fafApiProperties; | ||
} | ||
|
||
@PostLoad | ||
public void enrich(FeaturedMod featuredMod) { | ||
String technicalName = featuredMod.getTechnicalName(); | ||
String bireusUrlFormat = fafApiProperties.getFeaturedMod().getBireusUrlFormat(); | ||
|
||
featuredMod.setBireusUrl(String.format(bireusUrlFormat, technicalName)); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/test/java/com/faforever/api/data/domain/FeaturedModEnricherTest.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,36 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.config.FafApiProperties; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class FeaturedModEnricherTest { | ||
|
||
private FeaturedModEnricher featuredModEnricher; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
FafApiProperties fafApiProperties = new FafApiProperties(); | ||
fafApiProperties.getFeaturedMod().setBireusUrlFormat("http://example.com/%s"); | ||
|
||
featuredModEnricher = new FeaturedModEnricher(); | ||
featuredModEnricher.init(fafApiProperties); | ||
|
||
} | ||
|
||
@Test | ||
public void enrich() throws Exception { | ||
FeaturedMod featuredMod = new FeaturedMod(); | ||
featuredMod.setTechnicalName("faf"); | ||
|
||
featuredModEnricher.enrich(featuredMod); | ||
|
||
assertThat(featuredMod.getBireusUrl(), is("http://example.com/faf")); | ||
} | ||
} |