From 4adc2a1e025f4443cf7daea0db8d7d5788eb3475 Mon Sep 17 00:00:00 2001 From: Max Kalika Date: Fri, 29 Jan 2016 23:17:16 -0800 Subject: [PATCH] Issue #85: Add test for application config. --- .../jmxproxy/conf/tests/AppConfigTest.java | 48 +++++++++++++++++++ src/test/resources/fixtures/app_config.json | 10 ++++ 2 files changed, 58 insertions(+) create mode 100644 src/test/java/com/github/mk23/jmxproxy/conf/tests/AppConfigTest.java create mode 100644 src/test/resources/fixtures/app_config.json diff --git a/src/test/java/com/github/mk23/jmxproxy/conf/tests/AppConfigTest.java b/src/test/java/com/github/mk23/jmxproxy/conf/tests/AppConfigTest.java new file mode 100644 index 0000000..9ea07a7 --- /dev/null +++ b/src/test/java/com/github/mk23/jmxproxy/conf/tests/AppConfigTest.java @@ -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)); + } +} diff --git a/src/test/resources/fixtures/app_config.json b/src/test/resources/fixtures/app_config.json new file mode 100644 index 0000000..40819ad --- /dev/null +++ b/src/test/resources/fixtures/app_config.json @@ -0,0 +1,10 @@ +{ + "cleanInterval": 12, + "cacheDuration": 23000, + "accessDuration": 404276000, + "historySize": 11, + "allowedEndpoints": [ + "localhost:1100", + "remotehost:2211" + ] +}