Skip to content

Commit

Permalink
Issue #169: Add host tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mk23 committed Feb 9, 2018
1 parent eee0949 commit 4a8d65f
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions src/test/java/com/github/mk23/jmxproxy/core/tests/HostTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.github.mk23.jmxproxy.core.tests;

import com.github.mk23.jmxproxy.core.Host;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class HostTest {
private final ObjectMapper om = new ObjectMapper();

@Rule public TestName name = new TestName();

private String asJson(Object object) throws JsonProcessingException {
return om.writeValueAsString(object);
}

@Before
public void printTestName() {
System.out.println(" -> " + name.getMethodName());
}

@Test
public void checkEmptyHost() throws Exception {
final Host host = new Host();
final String expected = new String("{}");

assertThat("check empty host", asJson(host), is(expected));
}

@Test
public void checkEmptyHostMBeanList() throws Exception {
final Host host = new Host();
final String expected = new String("[]");

assertThat("check empty host mbean list", asJson(host.getMBeans()), is(expected));
}

@Test
public void checkMissingMBean() throws Exception {
final Host host = new Host();
final String expected = new String("null");

assertThat("check missing mbean", asJson(host.getMBean("bean")), is(expected));
}

@Test
public void checkDuplicateMBean() throws Exception {
final Host host = new Host();
assertTrue(host.addMBean("bean") == host.addMBean("bean"));
}

@Test
public void checkAddDefaultMBeanFull() throws Exception {
final Host host = new Host();
host.addMBean("bean");

final String expected = new String("{\"bean\":{}}");

assertThat("check add default mbean full", asJson(host), is(expected));
}

@Test
public void checkAddDefaultMBeanList() throws Exception {
final Host host = new Host();
host.addMBean("bean");

final String expected = new String("[\"bean\"]");

assertThat("check add default mbean list", asJson(host.getMBeans()), is(expected));
}

@Test
public void checkAddDefaultMBeanBare() throws Exception {
final Host host = new Host();
host.addMBean("bean");

final String expected = new String("{}");

assertThat("check add default mbean bare", asJson(host.getMBean("bean")), is(expected));
}

@Test
public void checkAddExplicitMBeanFull() throws Exception {
final Host host = new Host();
host.addMBean("bean", 1);

final String expected = new String("{\"bean\":{}}");

assertThat("check add explicit mbean full", asJson(host), is(expected));
}

@Test
public void checkAddExplicitMBeanList() throws Exception {
final Host host = new Host();
host.addMBean("bean", 1);

final String expected = new String("[\"bean\"]");

assertThat("check add explicit mbean list", asJson(host.getMBeans()), is(expected));
}

@Test
public void checkAddExplicitMBeanBare() throws Exception {
final Host host = new Host();
host.addMBean("bean", 1);

final String expected = new String("{}");

assertThat("check add explicit mbean bare", asJson(host.getMBean("bean")), is(expected));
}

@Test
public void checkRemoveMBean() throws Exception {
final Host host = new Host();
host.addMBean("bean");
host.removeMBean("bean");

final String expected = new String("{}");

assertThat("check remove mbean", asJson(host), is(expected));
}
}

0 comments on commit 4a8d65f

Please sign in to comment.