-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #85: Add test for application config.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/test/java/com/github/mk23/jmxproxy/conf/tests/AppConfigTest.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,48 @@ | ||
package com.github.mk23.jmxproxy.conf.tests; | ||
|
||
import com.github.mk23.jmxproxy.conf.AppConfig; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.dropwizard.util.Duration; | ||
|
||
import java.io.IOException; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import static io.dropwizard.testing.FixtureHelpers.fixture; | ||
|
||
public class AppConfigTest { | ||
private final ObjectMapper om = new ObjectMapper(); | ||
|
||
private String asJson(Object object) throws JsonProcessingException { | ||
return om.writeValueAsString(object); | ||
} | ||
|
||
private String jsonFixture(String filename) throws IOException { | ||
return om.writeValueAsString(om.readValue(fixture(filename), JsonNode.class)); | ||
} | ||
|
||
/* Configuration tests */ | ||
@Test | ||
public void checkValidConfiguration() throws Exception { | ||
final AppConfig appConfig = new AppConfig() | ||
.setCleanInterval(Duration.milliseconds(12)) | ||
.setCacheDuration(Duration.seconds(23)) | ||
.setAccessDuration(Duration.seconds(404276)) | ||
.setHistorySize(11) | ||
.setAllowedEndpoints(Arrays.asList("localhost:1100", "remotehost:2211")); | ||
|
||
final String expectedResult = jsonFixture("fixtures/app_config.json"); | ||
final String acquiredResult = asJson(appConfig); | ||
|
||
assertThat("valid configuration", acquiredResult, is(expectedResult)); | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"cleanInterval": 12, | ||
"cacheDuration": 23000, | ||
"accessDuration": 404276000, | ||
"historySize": 11, | ||
"allowedEndpoints": [ | ||
"localhost:1100", | ||
"remotehost:2211" | ||
] | ||
} |