function test_encode_decode()
    {
        $xml = <<<XML
<Register>
  <S DisplayName="DisplayName-azeckoski-123456" FirstName="First" LastName="Lastazeckoski-123456"
    StudentID="101" Email="*****@*****.**" URL="http://sakaiproject.org" ClickerID="11111111"></S>
</Register>
XML;
        $result = iclicker_service::decode_registration($xml);
        $this->assertNotNull($result);
        $this->assertNotNull($result->clicker_id);
        $this->assertNotNull($result->owner_id);
        $this->assertEqual($result->clicker_id, '11111111');
        $this->assertEqual($result->owner_id, 101);
        //$this->assertEqual($result->user_username, 'student01'); // DISABLED - username might be different for this user id
        $xml = <<<XML
<coursegradebook courseid="BFW61">
  <user id="101" usertype="S">
    <lineitem name="05/05/2009" pointspossible="100" type="iclicker polling scores" score="100"/>
    <lineitem name="06/06/2009" pointspossible="50" type="iclicker polling scores" score="50"/>
  </user>
  <user id="102" usertype="S">
    <lineitem name="06/06/2009" pointspossible="50" type="iclicker polling scores" score="30"/>
    <lineitem name="07/07/2009" pointspossible="100" type="iclicker polling scores" score="80"/>
  </user>
</coursegradebook>
XML;
        $result = iclicker_service::decode_gradebook($xml);
        $this->assertNotNull($result);
        $this->assertNotNull($result->course_id);
        $this->assertEqual($result->course_id, 'BFW61');
        $this->assertNotNull($result->students);
        $this->assertNotNull($result->items);
        $this->assertEqual(count($result->students), 2);
        $this->assertEqual(count($result->items), 3);
        $this->assertNotNull($result->items['05/05/2009']);
        $this->assertNotNull($result->items['06/06/2009']);
        $this->assertNotNull($result->items['07/07/2009']);
        $xml = <<<XML
<StudentRoster>
    <S StudentID="student01" FirstName="student01" LastName="student01" URL="https://www.iclicker.com/" CourseName="">
        <Registration ClickerId="11111111" WhenAdded="2009-01-27" Enabled="True" />
        <Registration ClickerId="22222222" WhenAdded="2009-01-27" Enabled="True" />
    </S>
</StudentRoster>
XML;
        $result = iclicker_service::decode_ws_xml($xml);
        $this->assertNotNull($result);
        $this->assertTrue(is_array($result));
        $this->assertEqual(count($result), 2);
        $this->assertNotNull($result[0]);
        $this->assertNotNull($result[0]->clicker_id);
        $this->assertNotNull($result[0]->owner_id);
        $this->assertNotNull($result[0]->timecreated);
        $this->assertNotNull($result[0]->activated);
        $this->assertEqual($result[0]->clicker_id, '11111111');
        $this->assertEqual($result[0]->user_username, 'student01');
        /* Fails in windows for some reason - not sure why
           Fail: blocks/iclicker/simpletest/test_iclicker_service.php / ► iclicker_services_test / ► test_encode_decode / ►
           Equal expectation fails because [Integer: 1233032400] differs from [Integer: 1233014400] by 18000
           */
        //$this->assertEqual($result[0]->timecreated, 1233014400);
        $this->assertEqual($result[0]->activated, true);
        // no good way to test this right now
        //$result = iclicker_service::encode_courses($instructor_id);
        //$result = iclicker_service::encode_enrollments($course_id);
        //$result = iclicker_service::encode_gradebook_results($course_id, $result_items);
        $clicker_registration = new stdClass();
        $clicker_registration->owner_id = 101;
        $clicker_registration->clicker_id = '12345678';
        $clicker_registration->activated = true;
        $result = iclicker_service::encode_registration($clicker_registration);
        $this->assertNotNull($result);
        //$this->assertTrue(stripos($result, 'student01') > 0); // DISABLED - username might be different for this user id
        $this->assertTrue(stripos($result, '12345678') > 0);
        $this->assertTrue(stripos($result, 'True') > 0);
        $registrations = array($clicker_registration);
        $result = iclicker_service::encode_registration_result($registrations, true, 'hello');
        $this->assertNotNull($result);
        $this->assertTrue(stripos($result, 'True') > 0);
        $this->assertTrue(stripos($result, 'hello') > 0);
        $result = iclicker_service::encode_registration_result($registrations, false, 'failed');
        $this->assertNotNull($result);
        $this->assertTrue(stripos($result, 'False') > 0);
        $this->assertTrue(stripos($result, 'failed') > 0);
    }
             $status = 404;
             //NOT_FOUND
         }
     }
 } else {
     // POST
     if ("gradebook" == $pathSeg0) {
         // handle retrieval of the list of students
         $course_id = $pathSeg1;
         if ($course_id == null) {
             throw new InvalidArgumentException("valid course_id must be included in the URL /gradebook/{course_id}");
         }
         iclicker_get_and_check_current_user("upload grades into the gradebook");
         $xml = iclicker_get_xml_data($cntlr);
         try {
             $gradebook = iclicker_service::decode_gradebook($xml);
             // process gradebook data
             $results = iclicker_service::save_gradebook($gradebook);
             // generate the output
             $output = iclicker_service::encode_gradebook_results($results);
             if (!$output) {
                 // special RETURN, non-XML, no failures in save
                 $cntlr->setStatus(200);
                 $cntlr->setContentType("text/plain");
                 $output = "True";
                 $cntlr->sendResponse($output);
                 return;
                 // SHORT CIRCUIT
             } else {
                 // failures occurred during save
                 $status = 200;