Skip to content

Commit

Permalink
remove unused export functionality in RestReportInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
F43nd1r committed Apr 30, 2021
1 parent 473c8b4 commit f201e29
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,7 @@ class RestReportInterface(private val dataService: DataService) {
return ResponseEntity.ok().build<Any>()
}

@PreAuthorize("hasRole(T(com.faendir.acra.model.User\$Role).USER)")
@RequestMapping(value = [EXPORT_PATH], produces = [MediaType.APPLICATION_JSON_VALUE], method = [RequestMethod.GET])
fun export(@RequestParam(name = PARAM_APP) appId: String, @RequestParam(name = PARAM_ID, required = false) id: String?,
@RequestParam(name = PARAM_MAIL, required = false) mail: String?): ResponseEntity<String> {
val app = dataService.findApp(appId) ?: return ResponseEntity.notFound().build()
var where: BooleanExpression? = null
var name = ""
if (mail != null && mail.isNotEmpty()) {
where = QReport.report.userEmail.eq(mail)
name += "_$mail"
}
if (id != null && id.isNotEmpty()) {
where = QReport.report.installationId.eq(id).and(where)
name += "_$id"
}
if (name.isEmpty()) {
return ResponseEntity.badRequest().build()
}
val headers = HttpHeaders()
headers.setContentDispositionFormData("attachment", "reports$name.json")
return ResponseEntity.ok().headers(headers).body(dataService.getFromReports(app, where, QReport.report.content).joinToString(", ", "[", "]"))
}

companion object {
const val EXPORT_PATH = "export"
const val PARAM_APP = "app_id"
const val PARAM_ID = "id"
const val PARAM_MAIL = "mail"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,16 @@ package com.faendir.acra.rest

import com.faendir.acra.model.App
import com.faendir.acra.rest.RestReportInterface.Companion.ATTACHMENT
import com.faendir.acra.rest.RestReportInterface.Companion.EXPORT_PATH
import com.faendir.acra.rest.RestReportInterface.Companion.PARAM_APP
import com.faendir.acra.rest.RestReportInterface.Companion.PARAM_ID
import com.faendir.acra.rest.RestReportInterface.Companion.PARAM_MAIL
import com.faendir.acra.rest.RestReportInterface.Companion.REPORT
import com.faendir.acra.rest.RestReportInterface.Companion.REPORT_PATH
import com.faendir.acra.service.DataService
import com.faendir.acra.service.UserService
import com.ninjasquad.springmockk.MockkBean
import com.querydsl.core.types.Expression
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import org.json.JSONArray
import org.json.JSONObject
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -47,13 +40,9 @@ import org.springframework.mock.web.MockMultipartFile
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.test.context.support.WithMockUser
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import strikt.api.expectThat
import strikt.assertions.isA
import strikt.assertions.isEqualTo

/**
* @author lukas
Expand All @@ -79,7 +68,6 @@ class RestReportInterfaceTest {
fun setUp() {
val app = mockk<App>()
every { dataService.findApp(TEST_STRING) } returns app
every { dataService.getFromReports(any(), any(), any<Expression<Any>>()) } returns listOf("{\"name\":\"a\"}", "{\"name\":\"b\"}")
every { dataService.createNewReport(any(), any(), any()) } just runs
}

Expand All @@ -97,35 +85,6 @@ class RestReportInterfaceTest {
verify(exactly = 1) { dataService.createNewReport(any(), any(), any()) }
}

@Test
fun exportWithId() {
mvc.perform(get("/$EXPORT_PATH").param(PARAM_APP, TEST_STRING).param(PARAM_ID, TEST_STRING)).andExpect(status().isOk).andExpect {
val array = JSONArray(it.response.contentAsString)
expectThat(array) {
get(JSONArray::length).isEqualTo(2)
get { get(0) }.isA<JSONObject>()
}
}
}

@Test
fun exportWithMail() {
mvc.perform(get("/$EXPORT_PATH").param(PARAM_APP, TEST_STRING).param(PARAM_MAIL, TEST_STRING)).andExpect(status().isOk).andExpect {
expectThat(JSONArray(it.response.contentAsString)) {
get(JSONArray::length).isEqualTo(2)
get { get(0) }.isA<JSONObject>()
}
}
}

@Test
fun exportInvalid() {
mvc.perform(get("/$EXPORT_PATH").param(PARAM_APP, TEST_STRING)).andExpect(status().is4xxClientError)
mvc.perform(get("/$EXPORT_PATH").param(PARAM_ID, TEST_STRING)).andExpect(status().is4xxClientError)
mvc.perform(get("/$EXPORT_PATH").param(PARAM_MAIL, TEST_STRING)).andExpect(status().is4xxClientError)
mvc.perform(get("/$EXPORT_PATH")).andExpect(status().is4xxClientError)
}

companion object {
private const val TEST_STRING = "TEST"
}
Expand Down

0 comments on commit f201e29

Please sign in to comment.