package at.asitplus.eidas.specific.connector.test.health; import java.io.IOException; import org.apache.commons.io.IOUtils; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.health.Health; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import at.asitplus.eidas.specific.connector.health.EidasNodeMetadataHealthIndicator; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "/spring/SpringTest-context_healthcheck.xml" }) @TestPropertySource(locations = {"classpath:/config/junit_config_2_springboot.properties"}) @WebAppConfiguration public class EidasNodeMetadataHealthIndicatorNoEndpointTest { @Autowired EidasNodeMetadataHealthIndicator health; private static MockWebServer mockWebServer = null; /** * Testclass initializer. * * @throws IOException In case of an error */ @BeforeClass public static void classInitializer() throws IOException { mockWebServer = new MockWebServer(); mockWebServer.start(40900); mockWebServer.url("/mockup"); } @AfterClass public static void resetTestEnviroment() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, IOException { mockWebServer.shutdown(); } @Test public void noEndpointInConfiguration() throws IOException { //set-up status mockWebServer.enqueue(new MockResponse().setResponseCode(200) .setBody(IOUtils.toString(EidasNodeMetadataHealthIndicatorNoEndpointTest.class .getResourceAsStream("/config/log4j.properties"), "UTF-8")) .setHeader("Content-Type", MediaType.APPLICATION_XML)); //perform test Health status = health.health(); //validate state Assert.assertEquals("wrong healthState", Health.unknown().build().getStatus(), status.getStatus()); } }