-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testcontainers changes are implemented, and more tests are added
- Loading branch information
musab.bozkurt
committed
Feb 4, 2024
1 parent
d56c0eb
commit 908d3e9
Showing
21 changed files
with
1,179 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "ebe84f96-4ce4-4dcf-98b5-ebc2a6120236", | ||
"name": "Unit Test Service", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | ||
"_exporter_id": "31512047" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "Create Tutorial", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"var response = JSON.parse(responseBody);", | ||
"", | ||
"pm.test(\"Status code is 201\", function () {", | ||
" pm.response.to.have.status(201);", | ||
" postman.setEnvironmentVariable(\"tutorialId\", response.id);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"title\": \"title\",\n \"description\": \"description\",\n \"published\": true\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "http://localhost:8080/api/tutorials", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "8080", | ||
"path": [ | ||
"api", | ||
"tutorials" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "Get Tutorial by Id", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"var response = JSON.parse(responseBody);", | ||
"", | ||
"pm.test(\"Status code is 200\", function () {", | ||
" pm.response.to.have.status(200);", | ||
" postman.setEnvironmentVariable(\"tutorialId\", response.id);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "http://localhost:8080/api/tutorials/:tutorialId", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "8080", | ||
"path": [ | ||
"api", | ||
"tutorials", | ||
":tutorialId" | ||
], | ||
"variable": [ | ||
{ | ||
"key": "tutorialId", | ||
"value": "{{tutorialId}}" | ||
} | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "Update Tutorial by Id", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"var response = JSON.parse(responseBody);", | ||
"", | ||
"pm.test(\"Status code is 200\", function () {", | ||
" pm.response.to.have.status(200);", | ||
" postman.setEnvironmentVariable(\"tutorialId\", response.id);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "PUT", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"title\": \"updatedTitle\",\n \"description\": \"updateddescription\",\n \"published\": true\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "http://localhost:8080/api/tutorials/:tutorialId", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "8080", | ||
"path": [ | ||
"api", | ||
"tutorials", | ||
":tutorialId" | ||
], | ||
"variable": [ | ||
{ | ||
"key": "tutorialId", | ||
"value": "{{tutorialId}}" | ||
} | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "Get All Tutorials", | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "http://localhost:8080/api/tutorials", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "8080", | ||
"path": [ | ||
"api", | ||
"tutorials" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/mb/livedataservice/api/controller/TutorialController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.mb.livedataservice.api.controller; | ||
|
||
import com.mb.livedataservice.api.request.ApiTutorialRequest; | ||
import com.mb.livedataservice.api.request.ApiTutorialUpdateRequest; | ||
import com.mb.livedataservice.api.response.ApiTutorialResponse; | ||
import com.mb.livedataservice.mapper.TutorialMapper; | ||
import com.mb.livedataservice.service.TutorialService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api") | ||
@CrossOrigin(origins = "http://localhost:8081") | ||
public class TutorialController { | ||
|
||
private final TutorialService tutorialService; | ||
private final TutorialMapper tutorialMapper; | ||
|
||
@PostMapping("/tutorials") | ||
public ResponseEntity<ApiTutorialResponse> createTutorial(@RequestBody ApiTutorialRequest apiTutorialRequest) { | ||
return new ResponseEntity<>(tutorialMapper.map(tutorialService.save(tutorialMapper.map(apiTutorialRequest))), HttpStatus.CREATED); | ||
} | ||
|
||
@GetMapping("/tutorials/{id}") | ||
public ResponseEntity<ApiTutorialResponse> getTutorialById(@PathVariable("id") long id) { | ||
return ResponseEntity.ok(tutorialMapper.map(tutorialService.findById(id))); | ||
} | ||
|
||
@GetMapping("/tutorials") | ||
public ResponseEntity<List<ApiTutorialResponse>> getAllTutorials(@RequestParam(required = false) String title) { | ||
return ResponseEntity.ok(tutorialMapper.map(tutorialService.findByTitleContaining(title))); | ||
} | ||
|
||
@PutMapping("/tutorials/{id}") | ||
public ResponseEntity<ApiTutorialResponse> updateTutorial(@PathVariable("id") long id, @RequestBody ApiTutorialUpdateRequest apiTutorialUpdateRequest) { | ||
return new ResponseEntity<>(tutorialMapper.map(tutorialService.update(id, tutorialMapper.map(apiTutorialUpdateRequest))), HttpStatus.OK); | ||
} | ||
|
||
@DeleteMapping("/tutorials/{id}") | ||
public ResponseEntity<HttpStatus> deleteTutorial(@PathVariable("id") long id) { | ||
tutorialService.deleteById(id); | ||
return new ResponseEntity<>(HttpStatus.NO_CONTENT); | ||
} | ||
|
||
@DeleteMapping("/tutorials") | ||
public ResponseEntity<HttpStatus> deleteAllTutorials() { | ||
tutorialService.deleteAll(); | ||
return new ResponseEntity<>(HttpStatus.NO_CONTENT); | ||
} | ||
|
||
@GetMapping("/tutorials/published") | ||
public ResponseEntity<List<ApiTutorialResponse>> findByPublished() { | ||
return new ResponseEntity<>(tutorialMapper.map(tutorialService.findByPublished(true)), HttpStatus.OK); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mb/livedataservice/api/request/ApiTutorialRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mb.livedataservice.api.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@ToString | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ApiTutorialRequest { | ||
|
||
private String title; | ||
|
||
private String description; | ||
|
||
private boolean published; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mb/livedataservice/api/request/ApiTutorialUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mb.livedataservice.api.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@ToString | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ApiTutorialUpdateRequest { | ||
|
||
private String title; | ||
|
||
private String description; | ||
|
||
private boolean published; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/mb/livedataservice/api/response/ApiTutorialResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mb.livedataservice.api.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@ToString | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ApiTutorialResponse { | ||
|
||
private long id; | ||
|
||
private String title; | ||
|
||
private String description; | ||
|
||
private boolean published; | ||
} |
Oops, something went wrong.