-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
command line usage msg and validation
- Loading branch information
1 parent
e642363
commit c8c9367
Showing
7 changed files
with
313 additions
and
12 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
.../com/github/eostermueller/heapspank/leakyspank/console/CommandLineParameterException.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,19 @@ | ||
package com.github.eostermueller.heapspank.leakyspank.console; | ||
|
||
public class CommandLineParameterException extends Exception { | ||
|
||
private String proposedConfigClassName = null; | ||
public CommandLineParameterException(String string) { | ||
super(string); | ||
} | ||
public CommandLineParameterException(String string, Throwable t) { | ||
super(string, t); | ||
} | ||
public String getProposedConfigClassName() { | ||
return this.proposedConfigClassName; | ||
} | ||
public void setProposedConfigClassName(String val) { | ||
this.proposedConfigClassName = val; | ||
} | ||
|
||
} |
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
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
9 changes: 9 additions & 0 deletions
9
...com/github/eostermueller/heapspank/leakyspank/console/FifteenSecondJMapHistoInterval.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,9 @@ | ||
package com.github.eostermueller.heapspank.leakyspank.console; | ||
|
||
public class FifteenSecondJMapHistoInterval extends DefaultConfig { | ||
@Override | ||
public int getjMapHistoIntervalSeconds() { | ||
return 15; | ||
} | ||
|
||
} |
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
85 changes: 85 additions & 0 deletions
85
src/test/java/com/github/eostermueller/heapspank/leakyspank/TestConfig.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,85 @@ | ||
package com.github.eostermueller.heapspank.leakyspank; | ||
|
||
import com.github.eostermueller.heapspank.leakyspank.console.Config; | ||
|
||
public class TestConfig implements Config { | ||
|
||
@Override | ||
public int getScreenRefreshIntervalSeconds() { | ||
// TODO Auto-generated method stub | ||
return 99; | ||
} | ||
|
||
@Override | ||
public void setScreenRefreshIntervalSeconds(int screenRefreshIntervalSeconds) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public int getjMapHistoIntervalSeconds() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void setjMapHistoIntervalSeconds(int jMapHistoIntervalSeconds) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void setjMapCountPerWindow(int jMapCountPerWindow) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public int getjMapCountPerWindow() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void setSuspectCountPerWindow(int suspectCountPerWindow) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public int getSuspectCountPerWindow() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long getPid() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void setViewClass(String viewClass) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public String getViewClass() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getMaxIterations() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void setArgs(String[] args) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
src/test/java/com/github/eostermueller/heapspank/leakyspank/TestCustomConfigClass.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,89 @@ | ||
package com.github.eostermueller.heapspank.leakyspank; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
import com.github.eostermueller.heapspank.leakyspank.console.CommandLineParameterException; | ||
import com.github.eostermueller.heapspank.leakyspank.console.Config; | ||
import com.github.eostermueller.heapspank.leakyspank.console.DefaultConfig; | ||
|
||
public class TestCustomConfigClass { | ||
|
||
@Test | ||
public void test() throws CommandLineParameterException { | ||
|
||
String args[] = { "-config", "com.github.eostermueller.heapspank.leakyspank.TestConfig" }; | ||
Config testConfig = DefaultConfig.createNew(args); | ||
assertEquals("Could not load test configuration class from classpath", 99, testConfig.getScreenRefreshIntervalSeconds()); | ||
|
||
} | ||
|
||
@Test | ||
public void testConfigClassNameNotInClasspath() { | ||
|
||
String nameOfClassThatDoesNotExist = "com.github.eostermueller.heapspank.leakyspank.DoesNotExist"; | ||
String args[] = { | ||
"-config", | ||
nameOfClassThatDoesNotExist | ||
}; | ||
|
||
|
||
try { | ||
DefaultConfig.createNew(args); | ||
fail("Should have thrown an exception because the class name after -config parm does not exist."); | ||
} catch (CommandLineParameterException e) { | ||
assertEquals( | ||
"Could not find right message", | ||
"Unable to create [" + e.getProposedConfigClassName() + "]. Not in the classpath?", | ||
e.getMessage() ); | ||
assertEquals(nameOfClassThatDoesNotExist, e.getProposedConfigClassName()); | ||
assertEquals("did not find correct cause", ClassNotFoundException.class, e.getCause().getClass()); | ||
} | ||
|
||
} | ||
@Test | ||
public void testMissingClassName() { | ||
|
||
String args[] = { | ||
"-config", | ||
/* "com.github.eostermueller.heapspank.leakyspank.TestConfig" */ | ||
}; | ||
|
||
Config testConfig; | ||
try { | ||
testConfig = DefaultConfig.createNew(args); | ||
fail("Should have thrown an exception because the class was missing as a command line argument."); | ||
} catch (CommandLineParameterException e) { | ||
assertEquals( | ||
"Could not find right message", | ||
"parameter after -config must be name of a class that implements com.github.eostermueller.heapspank.leakyspank.console.Config", | ||
e.getMessage() ); | ||
assertNull(e.getProposedConfigClassName()); | ||
} | ||
} | ||
@Test | ||
public void testClassNameWithoutCorrectImplementation() { | ||
|
||
|
||
//The correct interface is com.github.eostermueller.heapspank.leakyspank.console.Config | ||
String nameOfClassThatDoesNotImplementCorrectInterface = "com.github.eostermueller.heapspank.leakyspank.TestCustomConfigClass"; | ||
String args[] = { | ||
"-config", | ||
nameOfClassThatDoesNotImplementCorrectInterface | ||
}; | ||
|
||
try { | ||
Config testConfig = DefaultConfig.createNew(args); | ||
fail("Should have thrown an exception because the class name after -config parm does not exist."); | ||
} catch (CommandLineParameterException e) { | ||
assertEquals( | ||
"Could not find right message", | ||
"The -config class [" + e.getProposedConfigClassName() + "] must implement com.github.eostermueller.heapspank.leakyspank.console.Config", | ||
e.getMessage() ); | ||
assertEquals(nameOfClassThatDoesNotImplementCorrectInterface, e.getProposedConfigClassName()); | ||
assertNull("did not find correct cause", e.getCause()); | ||
} | ||
|
||
} | ||
} |