Skip to content

Commit 9856dc7

Browse files
committed
chore: clean up unnecessary file changes
1 parent 1c4f45c commit 9856dc7

File tree

8 files changed

+560
-560
lines changed

8 files changed

+560
-560
lines changed
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package com.group4.ticketingservice.config
2-
3-
import org.modelmapper.ModelMapper
4-
import org.springframework.context.annotation.Bean
5-
import org.springframework.context.annotation.Configuration
6-
7-
@Configuration
8-
class MapperConfig {
9-
@Bean
10-
fun modelMapper(): ModelMapper {
11-
val modelMapper = ModelMapper()
12-
modelMapper.configuration.isFieldMatchingEnabled = true
13-
return ModelMapper()
14-
}
15-
}
1+
package com.group4.ticketingservice.config
2+
3+
import org.modelmapper.ModelMapper
4+
import org.springframework.context.annotation.Bean
5+
import org.springframework.context.annotation.Configuration
6+
7+
@Configuration
8+
class MapperConfig {
9+
@Bean
10+
fun modelMapper(): ModelMapper {
11+
val modelMapper = ModelMapper()
12+
modelMapper.configuration.isFieldMatchingEnabled = true
13+
return ModelMapper()
14+
}
15+
}
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
package com.group4.ticketingservice.util
2-
3-
import com.google.gson.JsonDeserializationContext
4-
import com.google.gson.JsonDeserializer
5-
import com.google.gson.JsonElement
6-
import com.google.gson.JsonPrimitive
7-
import com.google.gson.JsonSerializationContext
8-
import com.google.gson.JsonSerializer
9-
import java.lang.reflect.Type
10-
import java.time.LocalDateTime
11-
import java.time.format.DateTimeFormatter
12-
13-
class DateTimeConverter : JsonSerializer<LocalDateTime>, JsonDeserializer<LocalDateTime> {
14-
private val FORMATTER = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS"
15-
.let { DateTimeFormatter.ofPattern(it) }
16-
17-
override fun serialize(src: LocalDateTime?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
18-
return JsonPrimitive(FORMATTER.format(src))
19-
}
20-
21-
override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): LocalDateTime? {
22-
return FORMATTER.parse(json!!.asJsonPrimitive.asString) as LocalDateTime?
23-
}
24-
}
1+
package com.group4.ticketingservice.util
2+
3+
import com.google.gson.JsonDeserializationContext
4+
import com.google.gson.JsonDeserializer
5+
import com.google.gson.JsonElement
6+
import com.google.gson.JsonPrimitive
7+
import com.google.gson.JsonSerializationContext
8+
import com.google.gson.JsonSerializer
9+
import java.lang.reflect.Type
10+
import java.time.LocalDateTime
11+
import java.time.format.DateTimeFormatter
12+
13+
class DateTimeConverter : JsonSerializer<LocalDateTime>, JsonDeserializer<LocalDateTime> {
14+
private val FORMATTER = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS"
15+
.let { DateTimeFormatter.ofPattern(it) }
16+
17+
override fun serialize(src: LocalDateTime?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
18+
return JsonPrimitive(FORMATTER.format(src))
19+
}
20+
21+
override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): LocalDateTime? {
22+
return FORMATTER.parse(json!!.asJsonPrimitive.asString) as LocalDateTime?
23+
}
24+
}
Lines changed: 133 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,133 @@
1-
package com.group4.ticketingservice.controller
2-
3-
import com.google.gson.Gson
4-
import com.group4.ticketingservice.dto.BookingCreateRequest
5-
import com.group4.ticketingservice.dto.BookingDeleteRequest
6-
import com.group4.ticketingservice.dto.BookingUpdateRequest
7-
import com.group4.ticketingservice.entity.Booking
8-
import com.group4.ticketingservice.entity.Performance
9-
import com.group4.ticketingservice.entity.User
10-
import com.group4.ticketingservice.service.BookingService
11-
import com.ninjasquad.springmockk.MockkBean
12-
import io.mockk.every
13-
import io.mockk.junit5.MockKExtension
14-
import org.junit.jupiter.api.Test
15-
import org.junit.jupiter.api.extension.ExtendWith
16-
import org.springframework.beans.factory.annotation.Autowired
17-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
18-
import org.springframework.http.MediaType
19-
import org.springframework.test.web.servlet.MockMvc
20-
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
21-
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
22-
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
23-
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
24-
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
25-
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
26-
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
27-
import java.time.Duration
28-
import java.time.LocalDateTime
29-
30-
@ExtendWith(MockKExtension::class)
31-
@WebMvcTest(BookingController::class)
32-
class BookingControllerTest(
33-
@Autowired val mockMvc: MockMvc
34-
) {
35-
@MockkBean
36-
private lateinit var bookingService: BookingService
37-
38-
private val sampleBookingCreateRequest = BookingCreateRequest(
39-
performanceId = 1,
40-
userId = 1
41-
)
42-
private val sampleBookingDeleteRequest = BookingDeleteRequest(
43-
id = 1
44-
)
45-
private val sampleUser: User = User(id = 1, name = "John Doe", email = "[email protected]")
46-
private val samplePerformance: Performance = Performance(
47-
id = 1,
48-
title = "test title",
49-
date = LocalDateTime.now(),
50-
bookingEndTime = LocalDateTime.now() + Duration.ofHours(2),
51-
bookingStartTime = LocalDateTime.now() + Duration.ofHours(1),
52-
maxAttendees = 10
53-
)
54-
private val sampleBooking: Booking = Booking(
55-
id = 1,
56-
user = sampleUser,
57-
performance = samplePerformance
58-
)
59-
60-
// createBooking
61-
@Test
62-
fun `POST bookings should return created booking`() {
63-
every { bookingService.createBooking(1, 1) } returns sampleBooking
64-
65-
mockMvc.perform(
66-
post("/bookings")
67-
.contentType(MediaType.APPLICATION_JSON)
68-
.content(Gson().toJson(sampleBookingCreateRequest))
69-
)
70-
.andExpect(status().isOk)
71-
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
72-
.andExpect(jsonPath("$.id").value(sampleBooking.id))
73-
.andExpect(jsonPath("$.userId").value(sampleBooking.user.id))
74-
.andExpect(jsonPath("$.performanceId").value(sampleBooking.performance.id))
75-
}
76-
77-
@Test
78-
fun `GET bookings should return booking`() {
79-
every { bookingService.getBooking(1) } returns sampleBooking
80-
81-
mockMvc.perform(
82-
get("/bookings/1")
83-
.contentType(MediaType.APPLICATION_JSON)
84-
)
85-
.andExpect(status().isOk)
86-
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
87-
.andExpect(jsonPath("$.id").value(sampleBooking.id))
88-
.andExpect(jsonPath("$.userId").value(sampleBooking.user.id))
89-
.andExpect(jsonPath("$.performanceId").value(sampleBooking.performance.id))
90-
}
91-
92-
@Test
93-
fun `PUT bookings should return updated booking`() {
94-
val bookingUpdateRequest = BookingUpdateRequest(
95-
performanceId = 2
96-
)
97-
val updatedBooking = Booking(
98-
id = 1,
99-
user = sampleUser,
100-
performance = Performance(
101-
id = 2,
102-
title = "test title 2",
103-
date = LocalDateTime.now(),
104-
bookingEndTime = LocalDateTime.now() + Duration.ofHours(2),
105-
bookingStartTime = LocalDateTime.now() + Duration.ofHours(1),
106-
maxAttendees = 10
107-
)
108-
)
109-
every { bookingService.updateBooking(1, 2) } returns updatedBooking
110-
111-
mockMvc.perform(
112-
put("/bookings/1")
113-
.contentType(MediaType.APPLICATION_JSON)
114-
.content(Gson().toJson(bookingUpdateRequest))
115-
)
116-
.andExpect(status().isOk)
117-
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
118-
.andExpect(jsonPath("$.id").value(updatedBooking.id))
119-
.andExpect(jsonPath("$.userId").value(updatedBooking.user.id))
120-
.andExpect(jsonPath("$.performanceId").value(updatedBooking.performance.id))
121-
}
122-
123-
@Test
124-
fun `DELETE bookings should return no content`() {
125-
every { bookingService.deleteBooking(1) } returns Unit
126-
127-
mockMvc.perform(
128-
delete("/bookings/${sampleBookingDeleteRequest.id}")
129-
.contentType(MediaType.APPLICATION_JSON)
130-
)
131-
.andExpect(status().isNoContent)
132-
}
133-
}
1+
package com.group4.ticketingservice.controller
2+
3+
import com.google.gson.Gson
4+
import com.group4.ticketingservice.dto.BookingCreateRequest
5+
import com.group4.ticketingservice.dto.BookingDeleteRequest
6+
import com.group4.ticketingservice.dto.BookingUpdateRequest
7+
import com.group4.ticketingservice.entity.Booking
8+
import com.group4.ticketingservice.entity.Performance
9+
import com.group4.ticketingservice.entity.User
10+
import com.group4.ticketingservice.service.BookingService
11+
import com.ninjasquad.springmockk.MockkBean
12+
import io.mockk.every
13+
import io.mockk.junit5.MockKExtension
14+
import org.junit.jupiter.api.Test
15+
import org.junit.jupiter.api.extension.ExtendWith
16+
import org.springframework.beans.factory.annotation.Autowired
17+
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
18+
import org.springframework.http.MediaType
19+
import org.springframework.test.web.servlet.MockMvc
20+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
21+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
22+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
23+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
24+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
25+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
26+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
27+
import java.time.Duration
28+
import java.time.LocalDateTime
29+
30+
@ExtendWith(MockKExtension::class)
31+
@WebMvcTest(BookingController::class)
32+
class BookingControllerTest(
33+
@Autowired val mockMvc: MockMvc
34+
) {
35+
@MockkBean
36+
private lateinit var bookingService: BookingService
37+
38+
private val sampleBookingCreateRequest = BookingCreateRequest(
39+
performanceId = 1,
40+
userId = 1
41+
)
42+
private val sampleBookingDeleteRequest = BookingDeleteRequest(
43+
id = 1
44+
)
45+
private val sampleUser: User = User(id = 1, name = "John Doe", email = "[email protected]")
46+
private val samplePerformance: Performance = Performance(
47+
id = 1,
48+
title = "test title",
49+
date = LocalDateTime.now(),
50+
bookingEndTime = LocalDateTime.now() + Duration.ofHours(2),
51+
bookingStartTime = LocalDateTime.now() + Duration.ofHours(1),
52+
maxAttendees = 10
53+
)
54+
private val sampleBooking: Booking = Booking(
55+
id = 1,
56+
user = sampleUser,
57+
performance = samplePerformance
58+
)
59+
60+
// createBooking
61+
@Test
62+
fun `POST bookings should return created booking`() {
63+
every { bookingService.createBooking(1, 1) } returns sampleBooking
64+
65+
mockMvc.perform(
66+
post("/bookings")
67+
.contentType(MediaType.APPLICATION_JSON)
68+
.content(Gson().toJson(sampleBookingCreateRequest))
69+
)
70+
.andExpect(status().isOk)
71+
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
72+
.andExpect(jsonPath("$.id").value(sampleBooking.id))
73+
.andExpect(jsonPath("$.userId").value(sampleBooking.user.id))
74+
.andExpect(jsonPath("$.performanceId").value(sampleBooking.performance.id))
75+
}
76+
77+
@Test
78+
fun `GET bookings should return booking`() {
79+
every { bookingService.getBooking(1) } returns sampleBooking
80+
81+
mockMvc.perform(
82+
get("/bookings/1")
83+
.contentType(MediaType.APPLICATION_JSON)
84+
)
85+
.andExpect(status().isOk)
86+
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
87+
.andExpect(jsonPath("$.id").value(sampleBooking.id))
88+
.andExpect(jsonPath("$.userId").value(sampleBooking.user.id))
89+
.andExpect(jsonPath("$.performanceId").value(sampleBooking.performance.id))
90+
}
91+
92+
@Test
93+
fun `PUT bookings should return updated booking`() {
94+
val bookingUpdateRequest = BookingUpdateRequest(
95+
performanceId = 2
96+
)
97+
val updatedBooking = Booking(
98+
id = 1,
99+
user = sampleUser,
100+
performance = Performance(
101+
id = 2,
102+
title = "test title 2",
103+
date = LocalDateTime.now(),
104+
bookingEndTime = LocalDateTime.now() + Duration.ofHours(2),
105+
bookingStartTime = LocalDateTime.now() + Duration.ofHours(1),
106+
maxAttendees = 10
107+
)
108+
)
109+
every { bookingService.updateBooking(1, 2) } returns updatedBooking
110+
111+
mockMvc.perform(
112+
put("/bookings/1")
113+
.contentType(MediaType.APPLICATION_JSON)
114+
.content(Gson().toJson(bookingUpdateRequest))
115+
)
116+
.andExpect(status().isOk)
117+
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
118+
.andExpect(jsonPath("$.id").value(updatedBooking.id))
119+
.andExpect(jsonPath("$.userId").value(updatedBooking.user.id))
120+
.andExpect(jsonPath("$.performanceId").value(updatedBooking.performance.id))
121+
}
122+
123+
@Test
124+
fun `DELETE bookings should return no content`() {
125+
every { bookingService.deleteBooking(1) } returns Unit
126+
127+
mockMvc.perform(
128+
delete("/bookings/${sampleBookingDeleteRequest.id}")
129+
.contentType(MediaType.APPLICATION_JSON)
130+
)
131+
.andExpect(status().isNoContent)
132+
}
133+
}

0 commit comments

Comments
 (0)