Skip to content

Commit

Permalink
adds more junits
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Jun 25, 2023
1 parent ed1e30f commit 1af7354
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ jacoco_min_coverage_required=0.80

spring_boot_version=3.1.1
spring_cloud_version=2022.0.3
spring_cloud_aws_version=3.0.1
spring_dependency_management_version=1.1.0
logstash_logback_encoder_version=7.3
commons_io_version=2.13.0
springdoc_openapi_version=2.1.0
testcontainers.version=1.18.3

Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
package com.learning.mfscreener;

import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.learning.mfscreener.common.AbstractIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;

class ApplicationIntegrationTest extends AbstractIntegrationTest {

@Test
void contextLoads() throws Exception {
this.mockMvc.perform(get("/actuator/info")).andExpect(status().isOk());
void actuatorLoaded() throws Exception {
this.mockMvc
.perform(get("/actuator").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$._links.self.href").value("http://localhost/actuator"))
.andExpect(jsonPath("$._links.health.href").value("http://localhost/actuator/health"))
.andExpect(jsonPath("$._links.health-path.href").value("http://localhost/actuator/health/{*path}"))
.andExpect(jsonPath("$._links.info.href").value("http://localhost/actuator/info"))
.andExpect(jsonPath("$._links.configprops.href").value("http://localhost/actuator/configprops"))
.andExpect(jsonPath("$._links.configprops-prefix.href")
.value("http://localhost/actuator/configprops/{prefix}"))
.andExpect(jsonPath("$._links.env.href").value("http://localhost/actuator/env"))
.andExpect(jsonPath("$._links.env-toMatch.href").value("http://localhost/actuator/env/{toMatch}"))
.andExpect(jsonPath("$._links.logfile.href").value("http://localhost/actuator/logfile"))
.andExpect(jsonPath("$._links.loggers.href").value("http://localhost/actuator/loggers"))
.andExpect(jsonPath("$._links.loggers-name.href").value("http://localhost/actuator/loggers/{name}"))
.andExpect(jsonPath("$._links.metrics.href").value("http://localhost/actuator/metrics"))
.andExpect(jsonPath("$._links.metrics-requiredMetricName.href")
.value("http://localhost/actuator/metrics/{requiredMetricName}"));
}

@Test
void actuatorInfo() throws Exception {
this.mockMvc
.perform(get("/actuator/info").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.size()", is(4)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

import com.learning.mfscreener.common.AbstractIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;

class NavControllerIT extends AbstractIntegrationTest {

@Test
void shouldThrowExceptionWhenSchemeNotFound() throws Exception {
this.mockMvc
.perform(get("/api/nav/{schemeCode}", 1))
.perform(get("/api/nav/{schemeCode}", 1).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound())
.andExpect(header().string("Content-Type", is("application/problem+json")))
.andExpect(jsonPath("$.type", is("about:blank")))
Expand All @@ -28,7 +29,7 @@ void shouldThrowExceptionWhenSchemeNotFound() throws Exception {
@Test
void shouldLoadDataWhenSchemeFound() throws Exception {
this.mockMvc
.perform(get("/api/nav/{schemeCode}", 120503L))
.perform(get("/api/nav/{schemeCode}", 120503L).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(header().string("Content-Type", is("application/json")))
.andExpect(jsonPath("$.schemeCode", is(120503L), Long.class))
Expand All @@ -41,7 +42,8 @@ void shouldLoadDataWhenSchemeFound() throws Exception {
@Test
void shouldLoadDataWhenSchemeFoundAndLoadHistoricalData() throws Exception {
this.mockMvc
.perform(get("/api/nav/{schemeCode}/{date}", 120503L, "2022-12-20"))
.perform(get("/api/nav/{schemeCode}/{date}", 120503L, "2022-12-20")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(header().string("Content-Type", is("application/json")))
.andExpect(jsonPath("$.schemeCode", is(120503L), Long.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

import com.learning.mfscreener.common.AbstractIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;

class SchemeControllerIT extends AbstractIntegrationTest {

@Test
void fetchSchemes() throws Exception {
this.mockMvc
.perform(get("/api/scheme/{schemeName}", "sbi small cap"))
.perform(get("/api/scheme/{schemeName}", "sbi small cap").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(header().string("Content-Type", is("application/json")))
.andExpect(jsonPath("$.size()", is(4)))
Expand All @@ -25,7 +26,8 @@ void fetchSchemes() throws Exception {
@Test
void fetchSchemesByFundName() throws Exception {
this.mockMvc
.perform(get("/api/scheme/fund/{fundName}", "Mirae Asset Mutual fund"))
.perform(get("/api/scheme/fund/{fundName}", "Mirae Asset Mutual fund")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(header().string("Content-Type", is("application/json")))
.andExpect(jsonPath("$.size()", is(0)));
Expand Down

0 comments on commit 1af7354

Please sign in to comment.