Skip to content

Commit

Permalink
Issue #57: Add attribute history tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mk23 committed May 10, 2015
1 parent b706f4a commit a207b0f
Show file tree
Hide file tree
Showing 2 changed files with 247 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/topsy/jmxproxy/core/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public Attribute(Object attributeValue) {
this.attributeValue = attributeValue;
}

public Object getAttributeValue() {
return attributeValue;
}

public void serialize(JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException {
buildJson(jgen, attributeValue);
}
Expand Down
243 changes: 243 additions & 0 deletions src/test/java/com/topsy/jmxproxy/core/tests/HistoryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
package com.topsy.jmxproxy.core.tests;

import com.topsy.jmxproxy.core.Attribute;
import com.topsy.jmxproxy.core.History;

import java.util.ArrayList;

import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class HistoryTest {
private Object[] getAttributeValues(Attribute[] attributes) {
ArrayList<Object> al = new ArrayList<Object>(attributes.length);
for (Attribute a : attributes) {
al.add(a.getAttributeValue());
}
return al.toArray(new Object[al.size()]);
}

@Test
public void check0Single() throws Exception {
History history = new History(3);
assertNull(history.getAttribute());
}
@Test
public void check0ArrayFull() throws Exception {
History history = new History(3);
assertTrue(history.getAttributes().length == 0);
}
@Test
public void check0ArrayTen() throws Exception {
History history = new History(3);
assertTrue(history.getAttributes(10).length == 0);
}
@Test
public void check0ArrayTwo() throws Exception {
History history = new History(3);
assertTrue(history.getAttributes(2).length == 0);
}
@Test
public void check0ArrayOne() throws Exception {
History history = new History(3);
assertTrue(history.getAttributes(1).length == 0);
}

@Test
public void check1Single() throws Exception {
History history = new History(3);
String target = new String("1");

history.addAttributeValue(new String("1"));
assertEquals(history.getAttribute().getAttributeValue(), target);
}
@Test
public void check1ArrayFull() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("1") };

history.addAttributeValue(new String("1"));
assertArrayEquals(getAttributeValues(history.getAttributes()), target);
}
@Test
public void check1ArrayTen() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("1") };

history.addAttributeValue(new String("1"));
assertArrayEquals(getAttributeValues(history.getAttributes(10)), target);
}
@Test
public void check1ArrayTwo() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("1") };

history.addAttributeValue(new String("1"));
assertArrayEquals(getAttributeValues(history.getAttributes(2)), target);
}
@Test
public void check1ArrayOne() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("1") };

history.addAttributeValue(new String("1"));
assertArrayEquals(getAttributeValues(history.getAttributes(1)), target);
}

@Test
public void check2Single() throws Exception {
History history = new History(3);
String target = new String("2");

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
assertEquals(history.getAttribute().getAttributeValue(), target);
}
@Test
public void check2ArrayFull() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("2"), new String("1") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
assertArrayEquals(getAttributeValues(history.getAttributes()), target);
}
@Test
public void check2ArrayTen() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("2"), new String("1") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
assertArrayEquals(getAttributeValues(history.getAttributes(10)), target);
}
@Test
public void check2ArrayTwo() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("2"), new String("1") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
assertArrayEquals(getAttributeValues(history.getAttributes(2)), target);
}
@Test
public void check2ArrayOne() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("2") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
assertArrayEquals(getAttributeValues(history.getAttributes(1)), target);
}

@Test
public void check3Single() throws Exception {
History history = new History(3);
String target = new String("3");

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
assertEquals(history.getAttribute().getAttributeValue(), target);
}
@Test
public void check3ArrayFull() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("3"), new String("2"), new String("1") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
assertArrayEquals(getAttributeValues(history.getAttributes()), target);
}
@Test
public void check3ArrayTen() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("3"), new String("2"), new String("1") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
assertArrayEquals(getAttributeValues(history.getAttributes(10)), target);
}
@Test
public void check3ArrayTwo() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("3"), new String("2") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
assertArrayEquals(getAttributeValues(history.getAttributes(2)), target);
}
@Test
public void check3ArrayOne() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("3") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
assertArrayEquals(getAttributeValues(history.getAttributes(1)), target);
}

@Test
public void check4Single() throws Exception {
History history = new History(3);
String target = new String("4");

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
history.addAttributeValue(new String("4"));
assertEquals(history.getAttribute().getAttributeValue(), target);
}
@Test
public void check4ArrayFull() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("4"), new String("3"), new String("2") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
history.addAttributeValue(new String("4"));
assertArrayEquals(getAttributeValues(history.getAttributes()), target);
}
@Test
public void check4ArrayTen() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("4"), new String("3"), new String("2") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
history.addAttributeValue(new String("4"));
assertArrayEquals(getAttributeValues(history.getAttributes(10)), target);
}
@Test
public void check4ArrayTwo() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("4"), new String("3") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
history.addAttributeValue(new String("4"));
assertArrayEquals(getAttributeValues(history.getAttributes(2)), target);
}
@Test
public void check4ArrayOne() throws Exception {
History history = new History(3);
String[] target = new String[] { new String("4") };

history.addAttributeValue(new String("1"));
history.addAttributeValue(new String("2"));
history.addAttributeValue(new String("3"));
history.addAttributeValue(new String("4"));
assertArrayEquals(getAttributeValues(history.getAttributes(1)), target);
}
}

0 comments on commit a207b0f

Please sign in to comment.