import net.pterodactylus.sone.web.page.FreenetRequest
import java.text.SimpleDateFormat
import java.util.TimeZone
+import javax.inject.Inject
/**
* The “get status” AJAX handler returns all information that is necessary to
* update the web interface in real-time.
*/
-class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter, timeZone: TimeZone = TimeZone.getDefault()):
+class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter, timeZone: TimeZone):
JsonPage("getStatus.ajax", webInterface) {
+ @Inject constructor(webInterface: WebInterface, elementLoader: ElementLoader, timeTextConverter: TimeTextConverter, l10nFilter: L10nFilter):
+ this(webInterface, elementLoader, timeTextConverter, l10nFilter, TimeZone.getDefault())
+
private val dateFormatter = SimpleDateFormat("MMM d, yyyy, HH:mm:ss").apply {
this.timeZone = timeZone
}
package net.pterodactylus.sone.web.ajax
import com.fasterxml.jackson.databind.JsonNode
+import net.pterodactylus.sone.core.ElementLoader
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.data.Sone.SoneStatus.downloading
import net.pterodactylus.sone.data.Sone.SoneStatus.inserting
import net.pterodactylus.sone.freenet.L10nFilter
import net.pterodactylus.sone.freenet.L10nText
import net.pterodactylus.sone.test.deepMock
+import net.pterodactylus.sone.test.getInstance
+import net.pterodactylus.sone.test.isProvidedByMock
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
import net.pterodactylus.sone.text.TimeText
import net.pterodactylus.sone.text.TimeTextConverter
import net.pterodactylus.sone.utils.jsonArray
+import net.pterodactylus.sone.web.baseInjector
import net.pterodactylus.util.notify.Notification
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.emptyIterable
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.hasEntry
+import org.hamcrest.Matchers.notNullValue
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers.any
))
}
+ @Test
+ fun `page can be created by dependency injection`() {
+ assertThat(baseInjector.createChildInjector(
+ ElementLoader::class.isProvidedByMock(),
+ TimeTextConverter::class.isProvidedByMock(),
+ L10nFilter::class.isProvidedByMock()
+ ).getInstance<GetStatusAjaxPage>(), notNullValue())
+ }
+
private fun JsonNode.toMap() = fields().asSequence().map { it.key!! to if (it.value.isNull) null else it.value.asText()!! }.toMap()
}