Permalink
Browse files

BATCHADM-121: test GET for all .json resources

  • Loading branch information...
1 parent 2ed361d commit e5fc053854b3beec046ba24a391c76001759a372 @dsyer dsyer committed Aug 18, 2011
View
@@ -2,6 +2,7 @@ bin
lib
derby*
target
+*/src/META-INF
*/src/main/webapp/META-INF
*/src/main/java/META-INF
.settings
@@ -104,16 +104,6 @@
</property>
</bean>
- <bean name="jobs/executions/steps.json" parent="standard.json">
- <property name="attributes">
- <props merge="true">
- <prop key="body">/manager/steps/json/executions.ftl</prop>
- <prop key="titleCode">step.executions.title</prop>
- <prop key="titleText">Spring Batch Admin: Step Executions</prop>
- </props>
- </property>
- </bean>
-
<bean name="jobs/executions/step" parent="standard">
<property name="attributes">
<props merge="true">
@@ -9,7 +9,6 @@ GET/jobs/executions.json=
DELETE/jobs/executions.json=
GET/jobs/executions/{jobExecutionId}.json=
DELETE/jobs/executions/{jobExecutionId}.json=
-GET/jobs/executions/{jobExecutionId}/steps.json=
GET/jobs/executions/{jobExecutionId}/steps/{stepExecutionId}.json=
GET/jobs/{jobName}/executions.json=
GET/jobs/{jobName}/{jobInstanceId}.json=
@@ -1,31 +0,0 @@
-<#import "/spring.ftl" as spring />
-<#if jobExecutionInfo??>"jobExecution" : {
- "id" : "${jobExecutionInfo.id?c}",
- "name" : "${jobExecutionInfo.name}",
- <#assign url><@spring.url relativeUrl="${servletPath}/jobs/executions/${jobExecutionInfo.id?c}.json"/></#assign>
- "resource" : "${baseUrl}${url}"
-},
-</#if>
-"stepExecutions" : {<#if stepExecutions?? && stepExecutions?size!=0>
- <#list stepExecutions as stepExecutionInfo>
- "${stepExecutionInfo.stepExecution.id?c}" : {
- <#assign url><@spring.url relativeUrl="${servletPath}/jobs/executions/${stepExecutionInfo.jobExecutionId?c}/steps/${stepExecutionInfo.id?c}/progress"/></#assign>
- "id" : "${stepExecutionInfo.stepExecution.id?c}",
- "name" : "${stepExecutionInfo.name}",
- "resource" : "${baseUrl}${url}",
- "status" : "${stepExecutionInfo.stepExecution.status}",
- "startTime" : "${stepExecutionInfo.startTime}",
- "duration" : "${stepExecutionInfo.duration}",
- "readCount" : ${stepExecutionInfo.stepExecution.readCount?c},
- "writeCount" : ${stepExecutionInfo.stepExecution.writeCount?c},
- "filterCount" : ${stepExecutionInfo.stepExecution.filterCount?c},
- "readSkipCount" : ${stepExecutionInfo.stepExecution.readSkipCount?c},
- "writeSkipCount" : ${stepExecutionInfo.stepExecution.writeSkipCount?c},
- "processSkipCount" : ${stepExecutionInfo.stepExecution.processSkipCount?c},
- "commitCount" : ${stepExecutionInfo.stepExecution.commitCount?c},
- "rollbackCount" : ${stepExecutionInfo.stepExecution.rollbackCount?c},
- "exitCode" : "${stepExecutionInfo.stepExecution.exitStatus.exitCode}",
- "exitDescription" : "${stepExecutionInfo.stepExecution.exitStatus.exitDescription?replace('\t','\\t')?replace('\n','\\n')?replace('\r','')}"
-}<#if stepExecutionInfo_index != stepExecutions?size-1>,</#if></#list>
-</#if>
-}
@@ -20,7 +20,9 @@
import static org.junit.Assert.assertNotNull;
import java.io.File;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -33,9 +35,12 @@
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.poller.DirectPoller;
import org.springframework.batch.poller.Poller;
+import org.springframework.beans.factory.config.PropertiesFactoryBean;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
+import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
/**
@@ -124,13 +129,6 @@ public JsonWrapper call() throws Exception {
assertNotNull(wrapper.get("jobExecution.status"));
assertNotNull(wrapper.get("jobExecution.id"));
- // Verify that there are step executions
- result = template.exchange(serverRunning.getUrl() + "/jobs/executions/" + jobExecution.get("jobExecution.id") + "/steps.json",
- HttpMethod.GET, null, String.class);
- wrapper = new JsonWrapper(result.getBody());
- assertNotNull(wrapper.get("jobExecution"));
- assertNotNull(wrapper.get("stepExecutions"));
-
}
@Test
@@ -168,5 +166,35 @@ public JsonWrapper call() throws Exception {
assertEquals(BatchStatus.STOPPED, status);
}
+
+ @Test
+ public void testListedResourcesWithGet() throws Exception {
+
+ Map<String,String> params = new HashMap<String, String>();
+ params.put("jobName", "job2");
+ // These should be there if the previous test cases worked
+ params.put("jobInstanceId", "0");
+ params.put("jobExecutionId", "0");
+ params.put("stepExecutionId", "0");
+
+ RestTemplate template = new RestTemplate();
+
+ PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
+ propertiesFactoryBean.setLocation(new ClassPathResource("/org/springframework/batch/admin/web/manager/json-resources.properties"));
+ propertiesFactoryBean.afterPropertiesSet();
+ Properties properties = propertiesFactoryBean.getObject();
+
+ for (String path : properties.stringPropertyNames()) {
+ if (!StringUtils.hasText(path) || !path.startsWith("GET")) {
+ continue;
+ }
+ path = path.substring(path.indexOf("/"));
+ ResponseEntity<String> result = template.exchange(serverRunning.getUrl() + path, HttpMethod.GET,
+ null, String.class, params);
+ JsonWrapper wrapper = new JsonWrapper(result.getBody());
+ // System.err.println(wrapper);
+ assertNotNull(wrapper);
+ }
+ }
}

0 comments on commit e5fc053

Please sign in to comment.