@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();
 }
  @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();
    }
  }
  @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();
    }
  }
  public void testGetHandler_serviceDoesntExist() {
    mockControl.replay();

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

    mockControl.verify();
  }
Пример #5
0
 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"));
 }
Пример #6
0
 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();
 }
  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
 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();
 }
  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();
  }
Пример #10
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();
 }
  /** 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
    }
  }
  /** 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
    }
  }
  /** 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
    }
  }
  /** 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
    }
  }
  /** 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
    }
  }
  /** 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
    }
  }
  /** 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
    }
  }
  /** 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
    }
  }
  /** 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
    }
  }
 @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();
 }
 private BapSshClient assertCreateClient() {
   mockControl.replay();
   final BapSshClient client = getHostConfig().createClient(buildInfo);
   mockControl.verify();
   return client;
 }
 private void assertResult(final Result expectedResult, final BPInstanceConfig instanceConfig) {
   mockControl.replay();
   assertEquals(expectedResult, instanceConfig.perform(build, buildInfo));
   mockControl.verify();
 }
Пример #23
0
 public void testRemoveNonExistingDocument() {
   control.replay();
   // This call should not lead to any notification
   // of the Mock Object:
   classUnderTest.removeDocument("Does not exist");
 }