Ejemplo n.º 1
0
  /**
   * Creates a sample list and tests CSV functionality. Requires a list of columns set under
   * "exportColumns" as well as a parameter "lde=1" to be present on the requesting URL.
   *
   * @throws Exception
   */
  public void testExport() throws Exception {

    mcontext.expects(atLeastOnce()).method("getOut").withNoArguments().will(returnValue(writer));
    csv.setExportColumns("column1,column2,column3");

    int tagval = csv.doStartTag();
    assertEquals(Tag.EVAL_BODY_INCLUDE, tagval);
    tagval = csv.doEndTag();
    assertEquals(Tag.EVAL_PAGE, tagval);

    mresp.verify();
    mreq.verify();
    mcontext.verify();
  }
  /** Tests change in processing property when processing starts and finishes. */
  public void testProcessingPC() {
    listener
        .expects(once())
        .method("propertyChanged")
        .with(same(feed), eq(AbstractFeed.PROP_PROCESSING), eq(false), eq(true))
        .id("started");
    listener
        .expects(once())
        .method("propertyChanged")
        .with(same(feed), eq(AbstractFeed.PROP_PROCESSING), eq(true), eq(false))
        .after("started")
        .id("finished");
    listener
        .expects(once())
        .method("propertyChanged")
        .with(same(feed), eq(AbstractFeed.PROP_PROCESSING), eq(true), eq(false))
        .after("finished");

    feed.processingStarted();
    feed.processingStarted();
    feed.processingFinished();
    feed.processingFinished();

    disableLogging();
    feed.processingFinished();
    enableLogging();

    listener.verify();
  }
  public void testVisitsEachFieldInHeirarchy() {
    // setup
    Mock mockBlock = new Mock(ReflectionProvider.Visitor.class);

    // expect
    mockBlock
        .expects(once())
        .method("visit")
        .with(eq("a"), eq(int.class), eq(WithFields.class), ANYTHING);
    mockBlock
        .expects(once())
        .method("visit")
        .with(eq("b"), eq(int.class), eq(WithFields.class), ANYTHING);
    mockBlock
        .expects(once())
        .method("visit")
        .with(eq("c"), eq(int.class), eq(SubClassWithFields.class), ANYTHING);

    // execute
    reflectionProvider.visitSerializableFields(
        new SubClassWithFields(), (ReflectionProvider.Visitor) mockBlock.proxy());

    // verify
    mockBlock.verify();
  }
 /*
  * Call reset() in the catch blocks for these two methods,
  * otherwise the MockObjectTestCase infrastructure picks up
  * the errors and rethrows the exception.
  */
 public void testFailsWhenCalledFewerThanTheExactNumberOfTimes() {
   proxy.m();
   try {
     mock.verify();
   } catch (AssertionFailedError err) {
     mock.reset();
     return;
   }
   fail("Should have failed");
 }
  public void testSaveServiceLevelAgreement() throws Exception {
    // set expected behavior on dao
    serviceLevelAgreementDAO
        .expects(once())
        .method("saveServiceLevelAgreement")
        .with(same(serviceLevelAgreement))
        .isVoid();

    serviceLevelAgreementManager.saveServiceLevelAgreement(serviceLevelAgreement);
    serviceLevelAgreementDAO.verify();
  }
 public void testGetServiceLevelAgreement() throws Exception {
   // set expected behavior on dao
   serviceLevelAgreementDAO
       .expects(once())
       .method("getServiceLevelAgreement")
       .will(returnValue(new ServiceLevelAgreement()));
   serviceLevelAgreement =
       serviceLevelAgreementManager.getServiceLevelAgreement(serviceLevelAgreementId);
   assertTrue(serviceLevelAgreement != null);
   serviceLevelAgreementDAO.verify();
 }
 /*
  * Call reset() in the catch blocks for these two methods,
  * otherwise the MockObjectTestCase infrastructure picks up
  * the errors and rethrows the exception.
  */
 @Test
 public void failsWhenCalledFewerThanTheExactNumberOfTimes() {
   proxy.m();
   try {
     mock.verify();
   } catch (Error error) {
     if (!(error instanceof MockAssertionError)) {
       fail("Should have failed");
     }
     mock.reset();
   }
 }
  public void testRemoveSLA() throws Exception {

    serviceLevelAgreementDAO
        .expects(once())
        .method("removeServiceLevelAgreement")
        .with(eq(1234))
        .isVoid();

    serviceLevelAgreementManager.removeServiceLevelAgreement("1234");

    serviceLevelAgreementDAO.verify();
  }
  public void testGetServiceLevelAgreements() throws Exception {
    List<ServiceLevelAgreement> results = new ArrayList<ServiceLevelAgreement>();
    serviceLevelAgreement = new ServiceLevelAgreement();
    results.add(serviceLevelAgreement);

    // set expected behavior on dao
    serviceLevelAgreementDAO
        .expects(once())
        .method("getServiceLevelAgreements")
        .will(returnValue(results));

    List<ServiceLevelAgreement> serviceLevelAgreements =
        serviceLevelAgreementManager.getServiceLevelAgreements(null);
    assertTrue(serviceLevelAgreements.size() == 1);
    serviceLevelAgreementDAO.verify();
  }
  @SuppressWarnings("unchecked")
  public void testShouldSupportCustomRepositoriesSuchAsAtlassian() throws Exception {
    startWebServer();
    Vector<?> expected = toVector("SPACE", "PAGE", Boolean.TRUE, Boolean.TRUE);
    String right = FileUtils.readFileToString(spec("spec.html"), "UTF-8");
    handler
        .expects(new InvokeOnceMatcher())
        .method("getRenderedSpecification")
        .with(eq(""), eq(""), eq(expected))
        .will(new ReturnStub(right));

    createAtlassianRepository("repo").addTest("PAGE");
    mojo.execute();

    handler.verify();
    assertDownloaded("repo", "PAGE.html");
  }
  /** Tests firing propery change events on invalidness reasons changes. */
  public void testInvalidnessReasonPC() {
    listener
        .expects(once())
        .method("propertyChanged")
        .with(same(feed), eq(AbstractFeed.PROP_INVALIDNESS_REASON), NULL, eq("r1"))
        .id("1");
    listener
        .expects(once())
        .method("propertyChanged")
        .with(same(feed), eq(AbstractFeed.PROP_INVALIDNESS_REASON), eq("r1"), eq("r2"))
        .after("1")
        .id("2");
    listener
        .expects(once())
        .method("propertyChanged")
        .with(same(feed), eq(AbstractFeed.PROP_INVALIDNESS_REASON), eq("r2"), NULL)
        .after("2");

    feed.setInvalidnessReason("r1");
    feed.setInvalidnessReason("r2");
    feed.setInvalidnessReason(null);

    listener.verify();
  }
  public void testVisitsFieldsHiddenBySubclass() {
    // setup
    Mock mockBlock = new Mock(ReflectionProvider.Visitor.class);

    // expect
    mockBlock
        .expects(once())
        .method("visit")
        .with(eq("b"), eq(int.class), eq(WithFields.class), ANYTHING)
        .id("first");
    mockBlock
        .expects(once())
        .method("visit")
        .with(eq("b"), eq(int.class), eq(SubClassWithHiddenFields.class), ANYTHING)
        .after("first");
    mockBlock.expects(once()).method("visit").with(eq("a"), ANYTHING, ANYTHING, ANYTHING);

    // execute
    reflectionProvider.visitSerializableFields(
        new SubClassWithHiddenFields(), (ReflectionProvider.Visitor) mockBlock.proxy());

    // verify
    mockBlock.verify();
  }
 public void testPassesWhenCalledTheExactNumberOfTimes() {
   proxy.m();
   proxy.m();
   mock.verify();
 }
  /** Tests that events for identical values aren't fired. */
  public void testSkipIdenticalPropertyValues() {
    feed.firePropertyChanged("test", null, null);
    feed.firePropertyChanged("test", "a", "a");

    listener.verify();
  }