2

I am having an interesting issue where API exposed by Katharsis are not found when I am trying to call them under SpringBootTest. I am able to connect to Spring MVC APIs using the same approach but Kartharsis end points are returning HTTP 404 inside the test. I am able to connect to Kartharsis end points while connecting via outside processes like invoking the same via a browser.

I have tried multiple solutions by replacing Spring TestRestTemplate with RestTemplate or OkHTTP all are having same issue.

Here are snippet of my code:

public class ProgramControllerTest_Search extends WebApiLayerIntegrationTest{
            void "should get one program by id"() {
                given:
                    Program program = new Program(programTitle: "Test Title")
                    program = this.programRepository.save(program)
                when:
                    def response = this.testRestTemplate.getForEntity("jsonapi/programs/" + (program.id), Map.class)
                then: "response status is ok"
                    noExceptionThrown()
                    response.statusCode == HttpStatus.OK
                and: "response body has expected values"
                    response.body.data.id == program.id
                    response.body.data.attributes.programTitle == "Test Title"

            }
        }




        @Slf4j
        @Stepwise
        @SpringBootTest(classes = [EscobarApplication.class],
                webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
        @ActiveProfiles(["integration-test", "my-local-test-config"])
        public abstract class WebApiLayerIntegrationTest extends Specification {
            @LocalServerPort
            private int httpPort

            @Autowired
            protected TestRestTemplate testRestTemplate

            @Autowired
            private DataSourceProperties dsProp

            @PostConstruct
            void printTestEnvironmentInfo() {
                log.info(">>> WebApiLayerIntegrationTest, using Datasource: url=${dsProp.getUrl()}, user=${dsProp.getUsername()}.")
            }

            protected int getHttpPort() {
                return httpPort
            }
        }


        @Entity
        @Audited
        @JsonApiResource(type = "programs")
        public class Program extends BaseEntity {
            @Id @JsonApiId
            @GeneratedValue(strategy = GenerationType.AUTO)
            private Long id;

            @NotNull
            @Column(length = 128, name = "program_title")
            @Size(min = 2, max = 128)
            private String programTitle; 
        }
ninux
  • 31
  • 2

0 Answers0