Package org.springframework.batch.admin.web

Source Code of org.springframework.batch.admin.web.StepExecutionProgressTests

/*
* Copyright 2009-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.admin.web;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Date;
import java.util.Locale;

import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.admin.history.StepExecutionHistory;
import org.springframework.batch.admin.web.StepExecutionProgress;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.test.MetaDataInstanceFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.support.StaticMessageSource;

public class StepExecutionProgressTests {

  private StepExecutionProgress progress;

  @Before
  public void setUp() {
    StepExecution stepExecution = MetaDataInstanceFactory
        .createStepExecution();
    stepExecution.setEndTime(new Date());
    StepExecutionHistory history = new StepExecutionHistory("step");
    // history.append(stepExecution);
    progress = new StepExecutionProgress(MetaDataInstanceFactory
        .createStepExecution(), history);
  }

  @Test
  public void testGetEstimatedPercentCompleteMessage() {
    String message = progress.getEstimatedPercentCompleteMessage()
        .getDefaultMessage();
    // System.err.println(message);
    assertTrue("Wrong message: [" + message + "]", message
        .contains("50% complete"));
    assertTrue("Wrong message: [" + message + "]", message
        .matches(".*after [0-9]* ms.*"));
  }

  @Test
  public void testGetEstimatedPercentCompleteMessageSourceResolvable() {
    MessageSource messageSource = new StaticMessageSource();
    String message = messageSource.getMessage(progress
        .getEstimatedPercentCompleteMessage(), Locale.UK);
    assertTrue("Wrong message: [" + message + "]", message
        .contains("50% complete"));
    assertTrue("Wrong message: [" + message + "]", message
        .matches(".*after [0-9]* ms.*"));
  }

  @Test
  public void testGetEstimatedPercentComplete() {
    assertEquals(0.5, progress.getEstimatedPercentComplete(), 0.01);
  }

}
TOP

Related Classes of org.springframework.batch.admin.web.StepExecutionProgressTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.