Gitbub actions workflow for running tests throws an error org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:80/event/DEB-12345": Connect to localhost:80 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:80 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused) at
jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-unit-test-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-unit-test-
- uses: actions/setup-java@v1
with:
java-version: 11
- name: Run unit test
run:
mvn -s ${MAVEN_SETTINGS_FILE} clean test -U -Dspring.profiles.active=test
- name: Create coverage report files
run:
mvn jacoco:report
- name: Upload code coverage results
uses: actions/upload-artifact@v2
with:
name: code-coverage-file
path: target/site/jacoco/jacoco.xml
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
@Slf4j
public class CoreDbEventControllerITest {
@Value("${server.port}")
private int serverPort;
private String orderNumber = "DEB-12345";
@Test
public void when_get_core_db_event_endpoint_is_called_then_http_response_is_returned_and_http_status_200(){
var endpointUrl = String.format("http://localhost:%s/event/%s", 80, orderNumber);
log.info("endpointurl : "+ endpointUrl);
TestRestTemplate testRestTemplate = new TestRestTemplate();
//Given
ResponseEntity<CoreDbEventResponse> response = testRestTemplate.getForEntity(endpointUrl,
CoreDbEventResponse.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
}
Can someone help me how to map the port 80 to container port on Gitactions?