X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=dist%2Fhttp-resources%2F2.0.0%2Fxref-test%2Fde%2Fjuplo%2Fhttpresources%2FHttpResourceExpiredFetchNotFoundTest.html;fp=dist%2Fhttp-resources%2F2.0.0%2Fxref-test%2Fde%2Fjuplo%2Fhttpresources%2FHttpResourceExpiredFetchNotFoundTest.html;h=7fff14c1d2e1141c7e8fc41cf179877b96f678cd;hb=96ec104e2974d001e9bc82c3af8b21029b2042d4;hp=0000000000000000000000000000000000000000;hpb=de1fa457a1c69c673d4dd5c0a2c9af568f74ea12;p=website diff --git a/dist/http-resources/2.0.0/xref-test/de/juplo/httpresources/HttpResourceExpiredFetchNotFoundTest.html b/dist/http-resources/2.0.0/xref-test/de/juplo/httpresources/HttpResourceExpiredFetchNotFoundTest.html new file mode 100644 index 00000000..7fff14c1 --- /dev/null +++ b/dist/http-resources/2.0.0/xref-test/de/juplo/httpresources/HttpResourceExpiredFetchNotFoundTest.html @@ -0,0 +1,188 @@ + + +
++1 package de.juplo.httpresources; +2 +3 import org.junit.jupiter.api.BeforeEach; +4 import org.junit.jupiter.api.DisplayName; +5 import org.junit.jupiter.api.Test; +6 import org.junit.jupiter.api.extension.ExtendWith; +7 import org.mockito.Mock; +8 import org.mockito.junit.jupiter.MockitoExtension; +9 import org.mockito.junit.jupiter.MockitoSettings; +10 import org.mockito.quality.Strictness; +11 import org.slf4j.Logger; +12 import org.slf4j.LoggerFactory; +13 import org.springframework.cache.support.NoOpCache; +14 import org.springframework.http.HttpHeaders; +15 import org.springframework.test.context.junit.jupiter.SpringExtension; +16 +17 import java.io.FileNotFoundException; +18 import java.net.URI; +19 import java.time.Clock; +20 import java.time.ZoneId; +21 +22 import static de.juplo.httpresources.TestUtil.*; +23 import static org.assertj.core.api.Assertions.assertThat; +24 import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +25 import static org.mockito.ArgumentMatchers.any; +26 import static org.mockito.Mockito.when; +27 +28 +29 @DisplayName(("HttpResource - Expired - Fetch: Not Found")) +30 @ExtendWith({ SpringExtension.class, MockitoExtension.class }) +31 @MockitoSettings(strictness = Strictness.LENIENT) +32 public class HttpResourceExpiredFetchNotFoundTest +33 { +34 private final static Logger LOG = LoggerFactory.getLogger(HttpResourceExpiredFetchNotFoundTest.class); +35 +36 @Mock +37 HttpResourceFetcher fetcher; +38 +39 HttpResources resources; +40 URI uri; +41 HttpResource resource; +42 +43 +44 /************** SETUP */ +45 +46 @BeforeEach +47 public void setUp() +48 { +49 Clock clock = Clock.fixed(NOW.toInstant(), ZoneId.of("GMT")); +50 resources = new HttpResources(fetcher, clock); +51 uri = URI.create("http://foo/bar"); +52 resource = new HttpResource(resources, fetcher, clock, uri); +53 resource.data = DATA_EXPIRED; +54 +55 // Everything is possible, nothing is necessary: Only defines behavior! +56 +57 HttpHeaders headers = new HttpHeaders(); +58 headers.setContentType(MIME_TYPE_CONTENT_TYPE_HTML); +59 +60 when(fetcher.fetch(any(), any())).thenReturn(DATA_NOT_FOUND); +61 } +62 +63 +64 /*************** For calls, that do not trigger a fetch see: HttpResourceNotExpiredTest */ +65 +66 +67 /*************** Results for calls, that did trigger a fetch */ +68 +69 @Test +70 @DisplayName(("fetch() reports modifications")) +71 public void test_fetch_ReportsModifications() +72 { +73 LOG.info("<-- start of test-case"); +74 +75 assertThat(resource.fetch()).isTrue(); +76 } +77 +78 @Test +79 @DisplayName(("exists() is false")) +80 public void test_exists_ReportsFalse() +81 { +82 LOG.info("<-- start of test-case"); +83 +84 assertThat(resource.exists()).isFalse(); +85 } +86 +87 @Test +88 @DisplayName(("isReadable() is false")) +89 public void test_isReadable_ReportsFalse() +90 { +91 LOG.info("<-- start of test-case"); +92 +93 assertThat(resource.isReadable()).isFalse(); +94 } +95 +96 @Test +97 @DisplayName(("isModified() reports modifications")) +98 public void test_isModified_ReportsModifications() +99 { +100 LOG.info("<-- start of test-case"); +101 +102 assertThat(resource.isModified()).isTrue(); +103 } +104 +105 @Test +106 @DisplayName(("getInputStream() throws FileNotFoundException")) +107 public void test_HasNoContent() +108 { +109 LOG.info("<-- start of test-case"); +110 +111 assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() -> resource.getInputStream()); +112 } +113 +114 +115 /*************** Expected state after calls, that did trigger a fetch */ +116 +117 @Test +118 @DisplayName(("fetch() updates data")) +119 public void test_fetch_UpdatesData() +120 { +121 LOG.info("<-- start of test-case"); +122 +123 resource.fetch(); +124 +125 assertThat(resource.data).isSameAs(DATA_NOT_FOUND); +126 } +127 +128 @Test +129 @DisplayName(("exists() updates data")) +130 public void test_exists_UpdatesData() +131 { +132 LOG.info("<-- start of test-case"); +133 +134 resource.exists(); +135 +136 assertThat(resource.data).isSameAs(DATA_NOT_FOUND); +137 } +138 +139 @Test +140 @DisplayName(("isReadable() updates data")) +141 public void test_isReadable_UpdatesData() +142 { +143 LOG.info("<-- start of test-case"); +144 +145 resource.isReadable(); +146 +147 assertThat(resource.data).isSameAs(DATA_NOT_FOUND); +148 } +149 +150 @Test +151 @DisplayName(("isModified() updates data")) +152 public void test_isModified_UpdatesData() +153 { +154 LOG.info("<-- start of test-case"); +155 +156 resource.isModified(); +157 +158 assertThat(resource.data).isSameAs(DATA_NOT_FOUND); +159 } +160 +161 @Test +162 @DisplayName(("getInputStream() updates data")) +163 public void test_getInputStream_UpdatesData() +164 { +165 LOG.info("<-- start of test-case"); +166 +167 try +168 { +169 resource.getInputStream(); +170 } +171 catch(Exception e) {} +172 +173 assertThat(resource.data).isSameAs(DATA_NOT_FOUND); +174 } +175 } ++