View Javadoc
1   /*
2    * Copyright 2009-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.batch.admin.web;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertTrue;
20  
21  import java.util.Date;
22  import java.util.Locale;
23  
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.springframework.batch.admin.domain.StepExecutionHistory;
27  import org.springframework.batch.admin.domain.StepExecutionProgress;
28  import org.springframework.batch.core.StepExecution;
29  import org.springframework.batch.test.MetaDataInstanceFactory;
30  import org.springframework.context.MessageSource;
31  import org.springframework.context.support.StaticMessageSource;
32  
33  public class StepExecutionProgressTests {
34  
35  	private StepExecutionProgress progress;
36  
37  	@Before
38  	public void setUp() {
39  		StepExecution stepExecution = MetaDataInstanceFactory
40  				.createStepExecution();
41  		stepExecution.setEndTime(new Date());
42  		StepExecutionHistory history = new StepExecutionHistory("step");
43  		// history.append(stepExecution);
44  		progress = new StepExecutionProgress(MetaDataInstanceFactory
45  				.createStepExecution(), history);
46  	}
47  
48  	@Test
49  	public void testGetEstimatedPercentCompleteMessage() {
50  		String message = progress.getEstimatedPercentCompleteMessage()
51  				.getDefaultMessage();
52  		// System.err.println(message);
53  		assertTrue("Wrong message: [" + message + "]", message
54  				.contains("50% complete"));
55  		assertTrue("Wrong message: [" + message + "]", message
56  				.matches(".*after [0-9]* ms.*"));
57  	}
58  
59  	@Test
60  	public void testGetEstimatedPercentCompleteMessageSourceResolvable() {
61  		MessageSource messageSource = new StaticMessageSource();
62  		String message = messageSource.getMessage(progress
63  				.getEstimatedPercentCompleteMessage(), Locale.UK);
64  		assertTrue("Wrong message: [" + message + "]", message
65  				.contains("50% complete"));
66  		assertTrue("Wrong message: [" + message + "]", message
67  				.matches(".*after [0-9]* ms.*"));
68  	}
69  
70  	@Test
71  	public void testGetEstimatedPercentComplete() {
72  		assertEquals(0.5, progress.getEstimatedPercentComplete(), 0.01);
73  	}
74  
75  }