public void testQueryForLong() throws Exception {
    String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3";

    mockResultSetMetaData.getColumnCount();
    ctrlResultSetMetaData.setReturnValue(1);

    mockResultSet.getMetaData();
    ctrlResultSet.setReturnValue(mockResultSetMetaData);
    mockResultSet.next();
    ctrlResultSet.setReturnValue(true);
    mockResultSet.getLong(1);
    ctrlResultSet.setReturnValue(87);
    mockResultSet.wasNull();
    ctrlResultSet.setReturnValue(false);
    mockResultSet.next();
    ctrlResultSet.setReturnValue(false);
    mockResultSet.close();
    ctrlResultSet.setVoidCallable();

    mockStatement.executeQuery(sql);
    ctrlStatement.setReturnValue(mockResultSet);
    mockStatement.getWarnings();
    ctrlStatement.setReturnValue(null);
    mockStatement.close();
    ctrlStatement.setVoidCallable();

    mockConnection.createStatement();
    ctrlConnection.setReturnValue(mockStatement);

    replay();

    JdbcTemplate template = new JdbcTemplate(mockDataSource);
    long l = template.queryForLong(sql);
    assertEquals("Return of a long", 87, l);
  }
  public void testQueryForObjectWithIntegerAndNull() throws Exception {
    String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3";

    mockResultSetMetaData.getColumnCount();
    ctrlResultSetMetaData.setReturnValue(1);

    mockResultSet.getMetaData();
    ctrlResultSet.setReturnValue(mockResultSetMetaData);
    mockResultSet.next();
    ctrlResultSet.setReturnValue(true);
    mockResultSet.getInt(1);
    ctrlResultSet.setReturnValue(0);
    mockResultSet.wasNull();
    ctrlResultSet.setReturnValue(true);
    mockResultSet.next();
    ctrlResultSet.setReturnValue(false);
    mockResultSet.close();
    ctrlResultSet.setVoidCallable();

    mockStatement.executeQuery(sql);
    ctrlStatement.setReturnValue(mockResultSet);
    mockStatement.getWarnings();
    ctrlStatement.setReturnValue(null);
    mockStatement.close();
    ctrlStatement.setVoidCallable();

    mockConnection.createStatement();
    ctrlConnection.setReturnValue(mockStatement);

    replay();

    JdbcTemplate template = new JdbcTemplate(mockDataSource);
    assertNull(template.queryForObject(sql, Integer.class));
  }
 protected void replay() {
   super.replay();
   ctrlStatement.replay();
   ctrlPreparedStatement.replay();
   ctrlResultSet.replay();
   ctrlResultSetMetaData.replay();
 }
 public void testGetServletPathWithSemicolon() throws Exception {
   control.expectAndReturn(requestMock.getRequestURI(), "/friend/mycontext/jim;bob");
   control.expectAndReturn(requestMock.getServletPath(), "/mycontext/jim");
   control.replay();
   assertEquals("/mycontext/jim;bob", RequestUtils.getServletPath(requestMock));
   control.verify();
 }
 @Test
 public void defaultName() {
   control = MockControl.createControl(IMethods.class);
   String expected = "EasyMock for " + IMethods.class.toString();
   String actual = control.getMock().toString();
   assertEquals(expected, actual);
 }
 @Test
 public void zeroOrMoreNoCalls() {
   mock.hasNext();
   control.setReturnValue(false, MockControl.ZERO_OR_MORE);
   control.replay();
   control.verify();
 }
 public void testLocalSessionFactoryBeanWithEntityInterceptor() throws Exception {
   LocalSessionFactoryBean sfb =
       new LocalSessionFactoryBean() {
         protected Configuration newConfiguration() {
           return new Configuration() {
             public Configuration setInterceptor(Interceptor interceptor) {
               throw new IllegalArgumentException(interceptor.toString());
             }
           };
         }
       };
   sfb.setMappingResources(new String[0]);
   sfb.setDataSource(new DriverManagerDataSource());
   MockControl interceptorControl = MockControl.createControl(Interceptor.class);
   Interceptor entityInterceptor = (Interceptor) interceptorControl.getMock();
   interceptorControl.replay();
   sfb.setEntityInterceptor(entityInterceptor);
   try {
     sfb.afterPropertiesSet();
     fail("Should have thrown IllegalArgumentException");
   } catch (IllegalArgumentException ex) {
     // expected
     assertTrue("Correct exception", ex.getMessage().equals(entityInterceptor.toString()));
   }
 }
  /** Check that a transaction is created and committed. */
  public void testTransactionShouldSucceedWithNotNew() throws Exception {
    TransactionAttribute txatt = new DefaultTransactionAttribute();

    MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
    tas.register(getNameMethod, txatt);

    MockControl statusControl = MockControl.createControl(TransactionStatus.class);
    TransactionStatus status = (TransactionStatus) statusControl.getMock();
    MockControl ptmControl = MockControl.createControl(PlatformTransactionManager.class);
    PlatformTransactionManager ptm = (PlatformTransactionManager) ptmControl.getMock();
    // expect a transaction
    ptm.getTransaction(txatt);
    ptmControl.setReturnValue(status, 1);
    ptm.commit(status);
    ptmControl.setVoidCallable(1);
    ptmControl.replay();

    TestBean tb = new TestBean();
    ITestBean itb = (ITestBean) advised(tb, ptm, tas);

    checkTransactionStatus(false);
    // verification!?
    itb.getName();
    checkTransactionStatus(false);

    ptmControl.verify();
  }
  protected void setUp() throws Exception {
    containerControl = MockControl.createStrictControl(ObjectContainer.class);
    container = (ObjectContainer) containerControl.getMock();

    templateControl = MockClassControl.createStrictControl(Db4oTemplate.class);
    template = (Db4oTemplate) templateControl.getMock();
  }
  public void testInterception3() throws Exception {
    contextMap.put(
        ActionContext.PARAMETERS,
        new LinkedHashMap() {
          private static final long serialVersionUID = 0L;

          {
            put("param1", new String[] {"paramValueOne"});
            put("param2", new String[] {"paramValueTwo"});
          }
        });

    actionInvocationControl.replay();

    ParameterRemoverInterceptor interceptor = new ParameterRemoverInterceptor();
    interceptor.setParamNames("param1,param2");
    interceptor.setParamValues("paramValue1,paramValue2");
    interceptor.intercept(actionInvocation);

    Map params = (Map) contextMap.get(ActionContext.PARAMETERS);
    assertEquals(params.size(), 2);
    assertTrue(params.containsKey("param1"));
    assertTrue(params.containsKey("param2"));
    assertEquals(((String[]) params.get("param1"))[0], "paramValueOne");
    assertEquals(((String[]) params.get("param2"))[0], "paramValueTwo");

    actionInvocationControl.verify();
  }
  /*
   * Make sure that we fallback to default provider
   *
   * Test method for
   * 'org.springmodules.jcr.support.AbstractSessionHolderProviderManager.getSessionProvider(SessionFactory)'
   */
  public void testDifferentSessionProvider() {
    // sanity check

    customProvider =
        new SessionHolderProvider() {

          /**
           * @see org.springmodules.jcr.SessionHolderProvider#acceptsRepository(java.lang.String)
           */
          public boolean acceptsRepository(String repo) {
            return false;
          }

          /**
           * @see org.springmodules.jcr.SessionHolderProvider#createSessionHolder(javax.jcr.Session)
           */
          public SessionHolder createSessionHolder(Session session) {
            return null;
          }
        };
    providers = new ArrayList();
    providers.add(customProvider);

    sfCtrl.replay();
    sessCtrl.replay();
    repoCtrl.replay();

    assertSame(
        GenericSessionHolderProvider.class, providerManager.getSessionProvider(repo).getClass());
  }
  protected void tearDown() throws Exception {
    sfCtrl.verify();
    sessCtrl.verify();
    repoCtrl.verify();

    super.tearDown();
  }
 @Test
 public void zeroOrMoreOneCall() {
   mock.hasNext();
   control.setReturnValue(false, MockControl.ZERO_OR_MORE);
   control.replay();
   assertFalse(mock.hasNext());
   control.verify();
 }
  public void testExcute() {
    qrMock.reset();
    qrMock.expectAndReturn(
        qrContentService.findQRContentListForPuzzleSolvingGame(gameId), new ArrayList<QRContent>());
    qrMock.replay();

    assertEquals(action.execute(), "success");
  }
  protected void setUp() throws Exception {
    qrMock = MockControl.createControl(IQRContentService.class);
    qrContentService = (IQRContentService) qrMock.getMock();

    action = new RecountPuzzleSolvingGameQRCodeAction();
    action.setQrContentService(qrContentService);
    action.setGameId(gameId);
  }
 public void testIsWritable() throws Exception {
   authorizerControl.expectAndReturn(authorizer.hasPermission(0, 0, project, "edit"), true);
   writableTableTag.setPermissions("edit,delete");
   authorizerControl.replay();
   boolean isWritable = writableTableTag.isWritable();
   assertEquals("table should be writable", true, isWritable);
   authorizerControl.verify();
 }
  public void testReplaceEmpty() throws Exception {
    mockInitialQueue_.hasPendingMessages();
    controlInitialQueue_.setReturnValue(false);
    controlInitialQueue_.replay();
    controlReplacementQueue_.replay();

    objectUnderTest_.replaceDelegate(mockReplacementQueue_);
  }
Exemple #18
0
 /** Invokes {@link org.easymock.MockControl#reset()}on all controls. */
 public void resetControls() {
   Iterator i = controls.iterator();
   while (i.hasNext()) {
     MockControl c = (MockControl) i.next();
     c.reset();
   }
   if (parent != null) parent.resetControls();
 }
 protected void tearDown() throws Exception {
   super.tearDown();
   if (shouldVerify()) {
     ctrlStatement.verify();
     ctrlPreparedStatement.verify();
     ctrlResultSet.verify();
     ctrlResultSetMetaData.verify();
   }
 }
Exemple #20
0
 public void testDivisionByZero() {
   Sample4 sample4 = new Sample4();
   sample4.setEventLogger(logger);
   int a = 3;
   int b = 0;
   logger.logDivisionByZero(a);
   loggerControl.replay();
   sample4.div(a, b);
   loggerControl.verify();
 }
 @Test
 public void testSuspendedDoesNothing() throws Exception {
   mockMessageSupplier_.getConnected();
   controlMessageSupplier_.setReturnValue(true);
   mockMessageSupplier_.isSuspended();
   controlMessageSupplier_.setReturnValue(true);
   controlMessageSupplier_.replay();
   objectUnderTest_.runPull();
   controlMessageSupplier_.verify();
 }
  protected void setUp() throws Exception {
    super.setUp();

    controlInitialQueue_ = MockControl.createControl(MessageQueueAdapter.class);
    mockInitialQueue_ = (MessageQueueAdapter) controlInitialQueue_.getMock();
    objectUnderTest_ = new RWLockEventQueueDecorator(mockInitialQueue_);

    controlReplacementQueue_ = MockControl.createControl(MessageQueueAdapter.class);
    mockReplacementQueue_ = (MessageQueueAdapter) controlReplacementQueue_.getMock();
  }
Exemple #23
0
  protected void setUp() throws Exception {
    control = MockControl.createControl(UserRequestTabManager.class);
    userRequestTabManager = (UserRequestTabManager) control.getMock();

    action = new UserRequestTabAction();
    action.setUserRequestTabManager(userRequestTabManager);

    ActionContext ctx = ActionContext.getContext();
    MockHttpServletRequest request = new MockHttpServletRequest();
  }
Exemple #24
0
  protected IJavaType createJavaType(
      MockContainer container, String fullyQualifiedName, boolean exists) {
    MockControl control = container.newControl(IJavaType.class);
    IJavaType type = (IJavaType) control.getMock();

    control.expectAndReturn(
        type.getFullyQualifiedName(), fullyQualifiedName, MockControl.ZERO_OR_MORE);
    control.expectAndReturn(type.exists(), exists, MockControl.ZERO_OR_MORE);
    return type;
  }
Exemple #25
0
  public void testIterateAttributeValuesWithEmptyAttribute() {
    String expectedAttributeName = "someAttribute";

    BasicAttribute expectedAttribute = new BasicAttribute(expectedAttributeName);

    handlerControl.replay();

    LdapUtils.iterateAttributeValues(expectedAttribute, handlerMock);

    handlerControl.verify();
  }
  /*
   * Default provider is used even on empty list.
   *
   * Test method for
   * 'org.springmodules.jcr.support.AbstractSessionHolderProviderManager.getSessionProvider(SessionFactory)'
   */
  public void testDefaultSessionProvider() {
    // sanity check
    assertSame(providers, providerManager.getProviders());

    sfCtrl.replay();
    sessCtrl.replay();
    repoCtrl.replay();

    SessionHolderProvider provider = providerManager.getSessionProvider(repo);
    assertSame(GenericSessionHolderProvider.class, provider.getClass());
  }
  protected void setUp() throws Exception {
    super.setUp();

    contextControl = MockControl.createControl(Context.class);
    contextMock = (Context) contextControl.getMock();

    contextControl2 = MockControl.createControl(Context.class);
    contextMock2 = (Context) contextControl2.getMock();

    tested = new DefaultDirObjectFactory();
  }
  public void testMultipleStartsAreIgnored() {
    mockTaskProcessor_.executeTaskPeriodically(0, null, false);
    controlTaskProcessor_.setMatcher(MockControl.ALWAYS_MATCHER);
    controlTaskProcessor_.setReturnValue(mockScheduledFuture_);
    replayAll();

    objectUnderTest_.startTask(2000);
    objectUnderTest_.startTask(2000);

    verifyAll();
  }
  protected void setUp() throws Exception {
    super.setUp();
    control = MockControl.createControl(ICityBroadcastDAO.class);
    mock = (ICityBroadcastDAO) control.getMock();

    control2 = MockControl.createControl(IUserDAO.class);
    mock2 = (IUserDAO) control2.getMock();
    // mock2.findBySetby(1);
    // control2.setReturnValue(new ArrayList<Strongholds>());

  }
  public void testGetMyMsg() {
    service = new GetCityBroadcastService();
    service.setCityBroadcastDao(mock);
    service.setUserDao(mock2);

    control.reset();
    mock.findBySpeakerid(1);
    control.setReturnValue(new ArrayList<CityBroadcast>());
    control.replay();
    assertNotNull(service.getMyMsg(1));
  }