コード例 #1
0
 @Test
 public void noInfoOnNoAuthUser() {
   GetJobController gjc = new GetJobController(null);
   MockHttpServletRequest rq = new MockHttpServletRequest();
   JSONObject got = gjc.getJSONObject(rq, null);
   assertNotNull(got);
   assertEquals(got.toString(), "{}");
 }
コード例 #2
0
  @Test
  public void noInfoOnNotExistingId() {
    this.clearDatabase();

    // no job inserted here
    GetJobController gjc = new GetJobController(TeztBeanSimpleFactory.getAdmin());
    MockHttpServletRequest rq = new MockHttpServletRequest();
    rq.setParameter("id", "321");
    JSONObject got = gjc.getJSONObject(rq, null);
    assertNotNull(got);
    assertEquals(got.toString(), "{}");
  }
コード例 #3
0
  @Test
  public void getJobWithId() {
    this.clearDatabase();

    // ↘ this is the job
    JSONObject jobSurvey = new JSONObject();
    try {
      jobSurvey.put("foo", "bar");
      List<String> animals = new ArrayList<String>();
      animals.add("dog");
      animals.add("cat");
      animals.add("mouse");
      jobSurvey.put("zoo", animals);
    } catch (JSONException e) {
      fail("should not throw " + e);
    }

    // ↘ get job of this booking as json
    Booking booking = TeztBeanSimpleFactory.getNewValidBooking();
    booking.setBooked();
    booking.insert();
    Job document = new Job();
    document.setJobId(booking.getId());
    document.setUsername(booking.getUsername());
    document.setStep(0);
    document.setIdJobDataProcessing("foo");
    document.setJobSurvey(jobSurvey);
    assertTrue(document.insertOrUpdate());

    // ↘ get json stuff being tested
    GetJobController gjc = new GetJobController(booking.getUser());
    MockHttpServletRequest rq = new MockHttpServletRequest();
    rq.setParameter("id", booking.getId() + "");
    JSONObject got = gjc.getJSONObject(rq, null);

    // ↘ test results
    try {
      assertEquals("bar", got.getString("foo"));
      @SuppressWarnings("rawtypes")
      Map zoo = (Map) got.get("zoo");
      assertEquals("dog", zoo.get("0"));
      assertEquals("cat", zoo.get("1"));
      assertEquals("mouse", zoo.get("2"));
    } catch (JSONException e) {
      fail("should not throw " + e);
    }
  }