-
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 #57: Add attribute history tests.
- Loading branch information
Showing
2 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
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
243 changes: 243 additions & 0 deletions
243
src/test/java/com/topsy/jmxproxy/core/tests/HistoryTest.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,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); | ||
} | ||
} |