Skip to content

Commit

Permalink
Issue #85: Add test for application config.
Browse files Browse the repository at this point in the history
  • Loading branch information
mk23 committed Jan 30, 2016
1 parent 3c9c09b commit 4adc2a1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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));
}
}
10 changes: 10 additions & 0 deletions src/test/resources/fixtures/app_config.json
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"
]
}

0 comments on commit 4adc2a1

Please sign in to comment.