Package de.hsh.graja.modules.junit
Class JunitBroker
java.lang.Object
de.hsh.graja.modules.junit.JunitBroker
This class serves requests from assignment grader instances, that are create by JUnit.
It stores comments from graders and delivers information to graders such as the current workspace.
-
Method Summary
Modifier and TypeMethodDescriptionClass<?>
getClassForName
(String name) Graders must call this method to load classes from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain.WorkspacegetCVVp()
Class<?>
getInterfaceForName
(String name) Graders must call this method to load interfaces from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain.getOrRegisterCommentsFromGrader
(String testMethodKey) A grader can register it's own comments using this method.Class<?>
getPublicClassForName
(String name) Graders must call this method to load classes from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain.Class<?>
Graders must call this method to load interfaces from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain.<Base> Class<? extends Base>
getPublicSubclassForName
(String fqn, Class<Base> baseClass) Returns the class as a subclass of Base.<Base> Class<? extends Base>
getSubclassForName
(String fqn, Class<Base> baseClass) Returns the class as a subclass of Base.long
Class<?>
readClassIntoGraderProtectionDomain
(String code, String fullyQualifiedClassname, Class<?> graderClass, StringBuilder errorLog) Sometimes a grader wants to compile code that is generated on the fly.Class<?>
readClassIntoSubmissionProtectionDomain
(String code, String fullyQualifiedClassname, StringBuilder errorLog) Sometimes a grader wants to compile code that is generated on the fly.void
registerDefaultASTPosFromGrader
(String testMethodKey, ASTPos pos) A grader can register a default AST pos using this method.retrieveCommentsFromSingleTestMethod
(String testMethodKey) Detaches and returns the comments collected from a single test method
-
Method Details
-
readClassIntoGraderProtectionDomain
public Class<?> readClassIntoGraderProtectionDomain(String code, String fullyQualifiedClassname, Class<?> graderClass, StringBuilder errorLog) throws IOException, ClassNotFoundException Sometimes a grader wants to compile code that is generated on the fly. This method compiles that generated code and loads the resulting bytecode using the class loader that loaded the grader. For an elaborate example seeCompileString
.- Parameters:
code
- program source code that must specify a single classfullyQualifiedClassname
- the name of the class- Returns:
- the compiled byte code
- Throws:
IOException
- in case of I/O errors when generating / reading filesClassNotFoundException
- if the source code does not specify a single class
-
readClassIntoSubmissionProtectionDomain
public Class<?> readClassIntoSubmissionProtectionDomain(String code, String fullyQualifiedClassname, StringBuilder errorLog) throws IOException, ClassNotFoundException Sometimes a grader wants to compile code that is generated on the fly. This method compiles that generated code and loads the resulting bytecode using the class loader that loaded the grader. For an elaborate example seeCompileString
.- Parameters:
code
- program source code that must specify a single classfullyQualifiedClassname
- the name of the class- Returns:
- the compiled byte code
- Throws:
IOException
- in case of I/O errors when generating / reading filesClassNotFoundException
- if the source code does not specify a single class
-
getCurrentWorkspace
Workspace- Returns:
- workspace
-
getTimeoutAt
public long getTimeoutAt()- Returns:
- the current grader should not run after the return value of this method interpreted as milliseconds like System.currentTimeMillis()
-
getCVVp
- Returns:
- the variation resolution, if there is any; null, if there is none.
-
getOrRegisterCommentsFromGrader
A grader can register it's own comments using this method. Then when a test finishes, the corresponding comments are automatically put near the test method name in the comment output.- Parameters:
testMethodKey
-- Returns:
- the sequence of comments registered so far (may be an empty sequence but will never be null)
-
registerDefaultASTPosFromGrader
A grader can register a default AST pos using this method. Then when a test finishes, the corresponding comments are automatically put in the code oriented feedback near the specified position.- Parameters:
testMethodKey
-pos
-
-
retrieveCommentsFromSingleTestMethod
Detaches and returns the comments collected from a single test method- Parameters:
testMethodKey
-- Returns:
- comments collected from a single test method
-
getClassForName
Graders must call this method to load classes from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain. If the class cannot be found, this method fails with a org.junit.Assert.fail.- Parameters:
name
-- Returns:
- the class object
-
getInterfaceForName
Graders must call this method to load interfaces from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain. If the interface cannot be found, this method fails with a org.junit.Assert.fail.- Parameters:
name
-- Returns:
- the interface as a class object
-
getPublicClassForName
Graders must call this method to load classes from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain. If the class cannot be found or is not public, this method fails with a org.junit.Assert.fail.- Parameters:
name
-- Returns:
- the class object
-
getPublicInterfaceForName
Graders must call this method to load interfaces from student submissions, since this method guarantees that student code is loaded into the appropriate protection domain. If the interface cannot be found or is not public, this method fails with a org.junit.Assert.fail.- Parameters:
name
-- Returns:
- the class object
-
getSubclassForName
Returns the class as a subclass of Base. fails, if the class is not found or it is not a subclass of Base. Subclass here means including Base itself.- Parameters:
fqn
-baseClass
-- Returns:
- the class object
-
getPublicSubclassForName
Returns the class as a subclass of Base. fails, if the class is not found or it is not public or it is not a subclass of Base. Subclass here means including Base itself.- Parameters:
fqn
-baseClass
-- Returns:
- the class object
-