Updated based on doc review.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>spring-cloud-task-edu-samples</artifactId>
|
||||
<groupId>io.spring</groupId>
|
||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>billrun</artifactId>
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package io.spring.billrun.configuration;
|
||||
|
||||
import io.spring.billrun.model.Bill;
|
||||
import io.spring.billrun.model.Usage;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
|
||||
public class BillProcessor implements ItemProcessor<Usage, Bill> {
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package io.spring.billrun.configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.spring.billrun.model.Bill;
|
||||
import io.spring.billrun.model.Usage;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -59,7 +61,7 @@ public class BillingConfiguration {
|
||||
private Resource usageResource;
|
||||
|
||||
@Bean
|
||||
public Job job1(ItemReader<Usage> reader, ItemProcessor<Usage,Bill> itemProcessor, ItemWriter<Bill> writer) {
|
||||
public Job job1(ItemReader<Usage> reader, ItemProcessor<Usage, Bill> itemProcessor, ItemWriter<Bill> writer) {
|
||||
Step step = stepBuilderFactory.get("BillProcessing")
|
||||
.<Usage, Bill>chunk(1)
|
||||
.reader(reader)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.billrun.configuration;
|
||||
package io.spring.billrun.model;
|
||||
|
||||
public class Bill {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.billrun.configuration;
|
||||
package io.spring.billrun.model;
|
||||
|
||||
public class Usage {
|
||||
|
||||
@@ -2,29 +2,26 @@ package io.spring.billrun;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.billrun.configuration.Usage;
|
||||
import io.spring.billrun.model.Bill;
|
||||
import io.spring.billrun.model.Usage;
|
||||
import javax.sql.DataSource;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.batch.test.context.SpringBatchTest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@SpringBatchTest
|
||||
public class BillrunApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@@ -36,46 +33,26 @@ public class BillrunApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobResults() throws Exception{
|
||||
public void testJobResults() {
|
||||
testResult();
|
||||
}
|
||||
|
||||
|
||||
private void testResult() {
|
||||
List<BillStatement> billStatements = this.jdbcTemplate.query("select ID, " +
|
||||
"first_name, last_name, minutes, data_usage, bill_amount FROM bill_statements",
|
||||
(rs, rowNum) -> new BillStatement(rs.getLong("id"),
|
||||
List<Bill> billStatements = this.jdbcTemplate.query("select id, " +
|
||||
"first_name, last_name, minutes, data_usage, bill_amount " +
|
||||
"FROM bill_statements ORDER BY id",
|
||||
(rs, rowNum) -> new Bill(rs.getLong("id"),
|
||||
rs.getString("FIRST_NAME"), rs.getString("LAST_NAME"),
|
||||
rs.getLong("MINUTES"), rs.getLong("DATA_USAGE"),
|
||||
rs.getLong("DATA_USAGE"), rs.getLong("MINUTES"),
|
||||
rs.getDouble("bill_amount")));
|
||||
assertThat(billStatements.size()).isEqualTo(5);
|
||||
|
||||
BillStatement billStatement = billStatements.get(0);
|
||||
assertThat(billStatement.getBillAmount()).isEqualTo(6);
|
||||
assertThat(billStatement.getFirstName()).isEqualTo("jane");
|
||||
assertThat(billStatement.getLastName()).isEqualTo("doe");
|
||||
assertThat(billStatement.getId()).isEqualTo(1);
|
||||
assertThat(billStatement.getMinutes()).isEqualTo(500);
|
||||
assertThat(billStatement.getDataUsage()).isEqualTo(1000);
|
||||
assertEquals(5, billStatements.size());
|
||||
|
||||
Bill billStatement = billStatements.get(0);
|
||||
assertEquals(6, billStatement.getBillAmount(), 1e-15);
|
||||
assertEquals("jane", billStatement.getFirstName());
|
||||
assertEquals("doe", billStatement.getLastName());
|
||||
assertEquals(new Long(1), billStatement.getId());
|
||||
assertEquals(new Long(500), billStatement.getMinutes());
|
||||
assertEquals(new Long(1000), billStatement.getDataUsage());
|
||||
}
|
||||
|
||||
public static class BillStatement extends Usage {
|
||||
|
||||
public BillStatement(Long id, String firstName, String lastName, Long minutes, Long dataUsage, double billAmount) {
|
||||
super(id, firstName, lastName, minutes, dataUsage);
|
||||
this.billAmount = billAmount;
|
||||
}
|
||||
|
||||
private double billAmount;
|
||||
|
||||
public double getBillAmount() {
|
||||
return billAmount;
|
||||
}
|
||||
|
||||
public void setBillAmount(double billAmount) {
|
||||
this.billAmount = billAmount;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>spring-cloud-task-edu-samples</artifactId>
|
||||
<groupId>io.spring</groupId>
|
||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>billsetuptask</artifactId>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2019 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
|
||||
* https://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,
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@@ -39,8 +39,8 @@ public class BillsetuptaskApplicationTests {
|
||||
public void testRepository() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
|
||||
int result = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(*) FROM BILL_STATEMENTS", Integer.class);
|
||||
"SELECT COUNT(*) FROM BILL_STATEMENTS", Integer.class);
|
||||
|
||||
assertThat(result).isEqualTo(0);
|
||||
assertEquals(0, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<artifactId>spring-cloud-task-edu-samples</artifactId>
|
||||
<groupId>io.spring</groupId>
|
||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Spring Cloud Task EDU Samples</name>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user