@Test
 public void testDontConnectSftpIfNoSourceFilesInAnyTransfers() throws Exception {
   final BapSshCommonConfiguration defaultKeyInfo =
       new BapSshCommonConfiguration(TEST_PASSPHRASE, null, null, false);
   hostConfig = createWithDefaultKeyInfo(mockJSch, defaultKeyInfo);
   final BapSshTransfer transfer1 =
       new BapSshTransfer(
           "", "", "", "", false, false, "ls -la", 10000, false, false, false, null);
   final BapSshTransfer transfer2 =
       new BapSshTransfer("", "", "", "", false, false, "pwd", 10000, false, false, false, null);
   final ArrayList<BapSshTransfer> transfers = new ArrayList<BapSshTransfer>();
   transfers.addAll(Arrays.asList(transfer1, transfer2));
   final BapSshPublisher publisher =
       new BapSshPublisher(
           getHostConfig().getName(), false, transfers, false, false, null, null, null);
   expect(
           mockJSch.getSession(
               getHostConfig().getUsername(),
               getHostConfig().getHostname(),
               getHostConfig().getPort()))
       .andReturn(mockSession);
   mockSession.setPassword(defaultKeyInfo.getPassphrase());
   mockSession.setConfig((Properties) anyObject());
   mockSession.connect(getHostConfig().getTimeout());
   mockControl.replay();
   getHostConfig().createClient(buildInfo, publisher);
   mockControl.verify();
 }
コード例 #2
0
  public void testGetHandler_serviceDoesntExist() {
    mockControl.replay();

    assertNull(dispatcher.getHandler("makebelieve"));

    mockControl.verify();
  }
  @SuppressWarnings({"ThrowableInstanceNeverThrown"})
  @Test
  @Ignore
  public void shouldRethrowAnExceptionIfTheTaskFails() throws Exception {
    I_EncodeBusinessProcess mockBusinessProcess =
        mockControl.createMock(I_EncodeBusinessProcess.class);
    I_Work mockWork = mockControl.createMock(I_Work.class);
    CleanableProcessExtByRefBuilder mockCleanableProcessBuilder =
        mockControl.createMock(CleanableProcessExtByRefBuilder.class);
    EasyMock.expect(mockBusinessProcess.getProperty(DIRECTORY_KEY))
        .andThrow(new IllegalArgumentException());
    mockControl.replay();

    I_DefineTask task = createTask(mockCleanableProcessBuilder);
    try {
      task.evaluate(mockBusinessProcess, mockWork);
      fail();
    } catch (TaskFailedException e) {

      assertThat(e.getCause(), notNullValue());
      assertTrue(
          "Expected IllegalArgumentException. Got " + e.getCause(),
          e.getCause().getClass() == IllegalArgumentException.class);
      mockControl.verify();
    }
  }
  @SuppressWarnings({"ThrowableInstanceNeverThrown"})
  private void expectEvaluateCalled(
      final I_EncodeBusinessProcess mockBusinessProcess,
      final CleanableProcessExtByRef mockCleanableProcess,
      final CleanableProcessExtByRefBuilder mockCleanableProcessBuilder)
      throws Exception {

    File mockDirectoryFile = mockControl.createMock(File.class);
    I_GetConceptData mockRefset = mockControl.createMock(I_GetConceptData.class);

    EasyMock.expect(mockTerminologyWrapper.get()).andReturn(mockTermFactory);
    EasyMock.expect(mockBusinessProcess.getProperty(DIRECTORY_KEY)).andReturn(mockDirectoryFile);
    EasyMock.expect(mockBusinessProcess.getProperty(WORKING_REFSET_KEY)).andReturn(mockRefset);
    mockPropertyValidator.validate(mockDirectoryFile, "output directory");
    mockPropertyValidator.validate(mockRefset, "selected refset");

    EasyMock.expect(mockCleanableProcessBuilder.withTermFactory(mockTermFactory))
        .andReturn(mockCleanableProcessBuilder);
    EasyMock.expect(mockCleanableProcessBuilder.withSelectedDir(mockDirectoryFile))
        .andReturn(mockCleanableProcessBuilder);
    EasyMock.expect(mockCleanableProcessBuilder.withLogger(EasyMock.isA(Logger.class)))
        .andReturn(mockCleanableProcessBuilder);
    EasyMock.expect(mockCleanableProcessBuilder.build()).andReturn(mockCleanableProcess);
    I_ExtendByRef mockExt1 = mockControl.createMock(I_ExtendByRef.class);
    I_ExtendByRef mockExt2 = mockControl.createMock(I_ExtendByRef.class);
    EasyMock.expect(mockRefset.getConceptId()).andReturn(REFSET_CONCEPT_ID);
    // TODO fix this one
    // EasyMock.expect(mockTermFactory.getRefsetExtensionMembers(REFSET_CONCEPT_ID)).andReturn(Arrays.asList(mockExt1, mockExt2));

    mockCleanableProcess.processExtensionByReference(mockExt1);
    mockCleanableProcess.processExtensionByReference(mockExt2);
    EasyMock.expectLastCall().andThrow(new IllegalStateException());

    mockCleanableProcess.clean();
  }
コード例 #5
0
ファイル: ExampleTest.java プロジェクト: cnewday/webapp
 public void testDocumentChanged() {
   mock.documentAdded("document");
   mock.documentChanged("document");
   control.replay();
   classUnderTest.addDocument("document", new byte[0]);
   classUnderTest.addDocument("document", new byte[0]);
   control.verify();
 }
  @Before
  public void setup() {
    mockControl = EasyMock.createControl();
    mockTermFactory = mockControl.createMock(I_TermFactory.class);
    mockPropertyValidator = mockControl.createMock(PropertyValidator.class);

    mockTerminologyWrapper = mockControl.createMock(LocalVersionedTerminologyWrapper.class);
  }
コード例 #7
0
  public void testGetHandler() {
    PersonHandler handler = mockControl.createMock(PersonHandler.class);
    EasyMock.expect(personHandlerProvider.get()).andReturn(handler);

    mockControl.replay();

    assertSame(handler, dispatcher.getHandler(DataServiceServlet.PEOPLE_ROUTE));

    mockControl.verify();
  }
コード例 #8
0
ファイル: ExampleTest.java プロジェクト: cnewday/webapp
 public void testDocumentChanged1() {
   mock.documentAdded("document");
   mock.documentChanged("document");
   // EasyMock.expectLastCall().times(3);
   LastControl.lastControl().times(3);
   control.replay();
   classUnderTest.addDocument("document", new byte[0]);
   classUnderTest.addDocument("document", new byte[0]);
   classUnderTest.addDocument("document", new byte[0]);
   classUnderTest.addDocument("document", new byte[0]);
   control.verify();
 }
コード例 #9
0
  @Override
  @SuppressWarnings("unchecked")
  protected void setUp() throws Exception {
    super.setUp();

    mockControl = EasyMock.createControl();
    personHandlerProvider = (Provider<PersonHandler>) mockControl.createMock(Provider.class);
    appDataHandlerProvider = (Provider<AppDataHandler>) mockControl.createMock(Provider.class);
    activityHandlerProvider = (Provider<ActivityHandler>) mockControl.createMock(Provider.class);
    dispatcher =
        new StandardHandlerDispatcher(
            personHandlerProvider, activityHandlerProvider, appDataHandlerProvider);
  }
コード例 #10
0
  public void testAddHandler() {
    DataRequestHandler mockHandler = mockControl.createMock(DataRequestHandler.class);
    @SuppressWarnings("unchecked")
    Provider<DataRequestHandler> mockProvider = mockControl.createMock(Provider.class);
    dispatcher.addHandler("mock", mockProvider);

    EasyMock.expect(mockProvider.get()).andReturn(mockHandler);

    mockControl.replay();

    assertSame(mockHandler, dispatcher.getHandler("mock"));

    mockControl.verify();
  }
コード例 #11
0
 @Test
 public void createSoap12Fault() {
   SoapBinding sb = control.createMock(SoapBinding.class);
   EasyMock.expect(sb.getSoapVersion()).andReturn(Soap12.getInstance());
   setupJMSFault(true, SoapJMSConstants.getMismatchedSoapActionQName(), null);
   control.replay();
   SoapFaultFactory factory = new SoapFaultFactory(sb);
   SoapFault fault = (SoapFault) factory.createFault(jmsFault);
   assertEquals("reason", fault.getReason());
   assertEquals(Soap12.getInstance().getSender(), fault.getFaultCode());
   assertEquals(SoapJMSConstants.getMismatchedSoapActionQName(), fault.getSubCode());
   assertNull(fault.getDetail());
   assertNull(fault.getCause());
   control.verify();
 }
コード例 #12
0
ファイル: ExampleTest.java プロジェクト: cnewday/webapp
  protected void setUp() {
    classUnderTest = new ClassUnderTest();
    // control = EasyMock.createStrictControl();
    control = EasyMock.createNiceControl();

    mock = control.createMock(Collaborator.class);
    classUnderTest.addListener(mock);
  }
コード例 #13
0
  /** setUp */
  public void setUp() {
    ctrl = createControl();
    factory2 = ctrl.createMock(DAOFactory.class);

    wd1 = new WardDAO(factory);

    wd2 = new WardDAO(factory2);
  }
コード例 #14
0
ファイル: ExampleTest.java プロジェクト: cnewday/webapp
 public void testDocumentRemoved() {
   mock.documentAdded("document");
   EasyMock.expect(mock.voteForRemoval("document")).andReturn((byte) 42);
   mock.documentRemoved("document");
   control.replay();
   classUnderTest.addDocument("document", new byte[0]);
   assertTrue(classUnderTest.removeDocument("document"));
 }
コード例 #15
0
 private BapPublisher createAndAddMockPublisher(final String hostConfigurationName) {
   final BapPublisher mockPublisher = mockControl.createMock(BapPublisher.class);
   if (hostConfigurationName != null) {
     mockPublisher.setEffectiveEnvironmentInBuildInfo(
         (AbstractBuild) EasyMock.anyObject(), (BPBuildInfo) EasyMock.anyObject());
     EasyMock.expect(mockPublisher.getConfigName()).andReturn(hostConfigurationName);
   }
   publishers.add(mockPublisher);
   return mockPublisher;
 }
コード例 #16
0
 JMSFault setupJMSFault(boolean isSender, QName code, Object detail) {
   jmsFault = control.createMock(JMSFault.class);
   EasyMock.expect(jmsFault.getReason()).andReturn("reason");
   EasyMock.expect(jmsFault.isSender()).andReturn(isSender);
   EasyMock.expect(jmsFault.getSubCode()).andReturn(code);
   if (null != detail) {
     EasyMock.expect(jmsFault.getDetail()).andReturn(detail);
     JMSFaultType sft = new JMSFaultType();
     sft.setFaultCode(SoapJMSConstants.getContentTypeMismatchQName());
   }
   return jmsFault;
 }
  @Test
  @Ignore
  public void shouldCleanupResourcesIfAProcessorFails() throws Exception {
    I_EncodeBusinessProcess mockBusinessProcess =
        mockControl.createMock(I_EncodeBusinessProcess.class);
    I_Work mockWork = mockControl.createMock(I_Work.class);
    CleanableProcessExtByRef mockCleanableProcess =
        mockControl.createMock(CleanableProcessExtByRef.class);
    CleanableProcessExtByRefBuilder mockCleanableProcessBuilder =
        mockControl.createMock(CleanableProcessExtByRefBuilder.class);

    expectEvaluateCalled(mockBusinessProcess, mockCleanableProcess, mockCleanableProcessBuilder);
    mockControl.replay();

    I_DefineTask task = createTask(mockCleanableProcessBuilder);
    try {
      task.evaluate(mockBusinessProcess, mockWork);
      fail();
    } catch (TaskFailedException e) {
      assertThat(e.getCause(), notNullValue());
      assertTrue(
          "Expected IllegalStateException. Got " + e.getCause(),
          e.getCause().getClass() == IllegalStateException.class);
      mockControl.verify();
    }
  }
 @Test
 public void testFailToCreateSession() throws Exception {
   final JSchException exception = new JSchException("meh");
   hostConfig = createWithOverrideUsernameAndPassword(mockJSch);
   expect(
           mockJSch.getSession(
               getHostConfig().getUsername(),
               getHostConfig().getHostname(),
               getHostConfig().getPort()))
       .andThrow(exception);
   mockControl.replay();
   try {
     getHostConfig().createClient(buildInfo);
     fail();
   } catch (BapPublisherException bpe) {
     assertTrue(bpe.getMessage().contains(getHostConfig().getUsername()));
     assertTrue(bpe.getMessage().contains(getHostConfig().getHostname()));
     assertTrue(bpe.getMessage().contains(Integer.toString(getHostConfig().getPort())));
     assertTrue(bpe.getMessage().contains(exception.getLocalizedMessage()));
   }
   mockControl.verify();
 }
コード例 #19
0
 private BapPublisher createLabeledPublisher(final String label, final boolean expectPerform)
     throws Exception {
   final BapPublisher mockPublisher = mockControl.createMock(BapPublisher.class);
   mockPublisher.setEffectiveEnvironmentInBuildInfo(
       (AbstractBuild) EasyMock.anyObject(), (BPBuildInfo) EasyMock.anyObject());
   expect(mockPublisher.getLabel()).andReturn(new PublisherLabel(label)).anyTimes();
   EasyMock.expect(mockPublisher.getConfigName())
       .andReturn(hostConfiguration.getName())
       .anyTimes();
   if (expectPerform) {
     mockPublisher.perform(hostConfiguration, buildInfo);
   }
   publishers.add(mockPublisher);
   return mockPublisher;
 }
コード例 #20
0
  /** testRemoveWard2 */
  public void testRemoveWard2() {
    try {
      assertNotNull(wd1.removeWard(1L, 1L));
    } catch (DBException e) {
      // TODO
    }

    try {
      expect(factory2.getConnection()).andThrow(new SQLException());
      ctrl.replay();
      wd2.removeWard(1L, 1L);
      fail();
    } catch (Exception e) {
      // TODO
    }
  }
コード例 #21
0
  /** testUpdateWardRoom */
  public void testUpdateWardRoom() {
    WardRoomBean wb = new WardRoomBean(0, 0, 0, "name1", "status");
    try {
      assertEquals(0, wd1.updateWardRoom(wb));
    } catch (DBException e) {
      // TODO
    }

    try {
      expect(factory2.getConnection()).andThrow(new SQLException());
      ctrl.replay();
      wd2.updateWardRoom(wb);
      fail();
    } catch (Exception e) {
      // TODO
    }
  }
コード例 #22
0
  /** testAssignHCPToWard */
  public void testAssignHCPToWard() {
    try {
      assertTrue(wd1.assignHCPToWard(1L, 1L));
    } catch (DBException e) {
      // TODO
    } catch (ITrustException e) {
      // TODO
    }

    try {
      expect(factory2.getConnection()).andThrow(new SQLException());
      ctrl.replay();
      wd2.assignHCPToWard(1L, 1L);
      fail();
    } catch (Exception e) {
      // TODO
    }
  }
コード例 #23
0
  /** testgetAllHCPsAssignedToWard */
  public void testgetAllHCPsAssignedToWard() {
    List<PersonnelBean> list = new ArrayList<PersonnelBean>();

    try {
      list = wd1.getAllHCPsAssignedToWard(1L);
      assertNotNull(list);
    } catch (DBException e) {
      // TODO
    }

    try {
      expect(factory2.getConnection()).andThrow(new SQLException());
      ctrl.replay();
      wd2.getAllHCPsAssignedToWard(1L);
      fail();
    } catch (Exception e) {
      // TODO
    }
  }
コード例 #24
0
  /** testGetWardRoom */
  public void testGetWardRoom() {
    WardRoomBean wrb = new WardRoomBean(0, 0, 0, "name", "status");

    try {
      wrb = wd1.getWardRoom("0");
      assertNull(wrb);
    } catch (DBException e) {
      // TODO
    }

    try {
      expect(factory2.getConnection()).andThrow(new SQLException());
      ctrl.replay();
      wd2.getWardRoom("0");
      fail();
    } catch (Exception e) {
      // TODO
    }
  }
コード例 #25
0
  /** testGetHospitalByWard */
  public void testGetHospitalByWard() {
    HospitalBean hb = new HospitalBean();

    try {
      hb = wd1.getHospitalByWard("name");
      assertNull(hb);
    } catch (DBException e) {
      // TODO
    }

    try {
      expect(factory2.getConnection()).andThrow(new SQLException());
      ctrl.replay();
      wd2.getHospitalByWard("name");
      fail();
    } catch (Exception e) {
      // TODO
    }
  }
コード例 #26
0
  /** testgetAllWardsByHospitalID */
  public void testgetAllWardsByHospitalID() {
    List<WardBean> list = new ArrayList<WardBean>();

    try {
      list = wd1.getAllWardsByHospitalID("1");
      assertNotNull(list);
    } catch (DBException e) {
      // TODO
    }

    try {
      expect(factory2.getConnection()).andThrow(new SQLException());
      ctrl.replay();
      wd2.getAllWardsByHospitalID("1");
      fail();
    } catch (Exception e) {
      // TODO
    }
  }
コード例 #27
0
  /** testAddWard */
  public void testAddWard() {
    WardBean wb = new WardBean(0L, "name", 0L);

    try {
      assertTrue(wd1.addWard(wb));
    } catch (DBException e) {
      // TODO
    } catch (ITrustException e) {
      // TODO
    }

    try {
      expect(factory2.getConnection()).andThrow(new SQLException());
      ctrl.replay();
      wd2.addWard(wb);
      fail();
    } catch (Exception e) {
      // TODO
    }
  }
コード例 #28
0
  /** testGetWardRoomsByStatus */
  public void testGetWardRoomsByStatus() {

    List<WardRoomBean> list = new ArrayList<WardRoomBean>();

    try {
      list = wd1.getWardRoomsByStatus("status", 1L);
      assertNotNull(list);
    } catch (DBException e) {
      // TODO
    }

    try {
      expect(factory2.getConnection()).andThrow(new SQLException());
      ctrl.replay();
      wd2.getWardRoomsByStatus("status", 1L);
      fail();
    } catch (Exception e) {
      // TODO
    }
  }
コード例 #29
0
 private void assertResult(final Result expectedResult, final BPInstanceConfig instanceConfig) {
   mockControl.replay();
   assertEquals(expectedResult, instanceConfig.perform(build, buildInfo));
   mockControl.verify();
 }
コード例 #30
0
ファイル: ExampleTest.java プロジェクト: cnewday/webapp
 public void testRemoveNonExistingDocument() {
   control.replay();
   // This call should not lead to any notification
   // of the Mock Object:
   classUnderTest.removeDocument("Does not exist");
 }