This blog post has been pushed to the respository after deployment to Heroku.
Let's hope this works!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void shouldPersistBattery() throws Exception { | |
Battery mockBattery = | |
new Battery("Gold Coast Mc", "9729", 50000); | |
mockMvc | |
.perform( | |
post("/batteries") | |
.content(objectMapper.writeValueAsString(mockBattery)) | |
.contentType(MediaType.APPLICATION_JSON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void shouldReturnAllBatteries() throws Exception { | |
mockMvc | |
.perform(get("/batteries/")) | |
.andDo(print()) | |
.andExpect(status().isOk()) | |
.andExpect(jsonPath("$").isArray()) | |
.andExpect(jsonPath("$", Matchers.hasSize(H2Bootstrap.mockBatteries.size()))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package np.com.roshanadhikary.testdemo; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | |
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | |
@SpringBootTest | |
@AutoConfigureMockMvc | |
class ApplicationTests { | |
// .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package np.com.roshanadhikary.testdemo; | |
@SpringBootTest | |
@AutoConfigureMockMvc | |
class ApplicationTests { | |
@Autowired | |
private MockMvc mockMvc; | |
@Autowired |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring.h2.console.enabled=true | |
spring.datasource.url=jdbc:h2:mem:testdb | |
spring.datasource.driverClassName=org.h2.Driver | |
spring.datasource.username=user | |
spring.datasource.password=password | |
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package np.com.roshanadhikary.testdemo.bootstrap; | |
/** | |
* Bootstrap the in-memory H2 database with some Battery resources when | |
* the application starts | |
*/ | |
@Configuration | |
public class H2Bootstrap { | |
private static final Logger logger = LoggerFactory.getLogger(H2Bootstrap.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package np.com.roshanadhikary.testdemo.repository; | |
import np.com.roshanadhikary.testdemo.entity.Battery; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
public interface BatteryRepository extends JpaRepository<Battery, Integer> { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package np.com.roshanadhikary.testdemo.entity; | |
import lombok.Data; | |
import lombok.NoArgsConstructor; | |
import lombok.NonNull; | |
import lombok.RequiredArgsConstructor; | |
import javax.persistence.*; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Find the distinct denominations required for a transaction | |
*/ | |
// list of denominations | |
const denoms = [1000, 500, 100, 50, 20, 10, 5, 2, 1]; | |
// return array of denoms smaller than or equal to the passed remainder | |
const getValidDenoms = (remainder) => { | |
return denoms.filter((el) => { | |
return el <= remainder; |
NewerOlder