Class JunitBroker

java.lang.Object
de.hsh.graja.modules.junit.JunitBroker

public class JunitBroker extends Object
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 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 see CompileString.
      Parameters:
      code - program source code that must specify a single class
      fullyQualifiedClassname - the name of the class
      Returns:
      the compiled byte code
      Throws:
      IOException - in case of I/O errors when generating / reading files
      ClassNotFoundException - 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 see CompileString.
      Parameters:
      code - program source code that must specify a single class
      fullyQualifiedClassname - the name of the class
      Returns:
      the compiled byte code
      Throws:
      IOException - in case of I/O errors when generating / reading files
      ClassNotFoundException - if the source code does not specify a single class
    • getCurrentWorkspace

      public Path 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

      public CVVp getCVVp()
      Returns:
      the variation resolution, if there is any; null, if there is none.
    • getOrRegisterCommentsFromGrader

      public Sequence getOrRegisterCommentsFromGrader(String testMethodKey)
      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

      public void registerDefaultASTPosFromGrader(String testMethodKey, ASTPos pos)
      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

      public CommentFromGrader retrieveCommentsFromSingleTestMethod(String testMethodKey)
      Detaches and returns the comments collected from a single test method
      Parameters:
      testMethodKey -
      Returns:
      comments collected from a single test method
    • getClassForName

      public Class<?> 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. If the class cannot be found, this method fails with a org.junit.Assert.fail.
      Parameters:
      name -
      Returns:
      the class object
    • getInterfaceForName

      public 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. 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

      public 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. 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

      public Class<?> getPublicInterfaceForName(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. 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

      public <Base> Class<? extends Base> getSubclassForName(String fqn, Class<Base> baseClass)
      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

      public <Base> Class<? extends Base> getPublicSubclassForName(String fqn, Class<Base> baseClass)
      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