Feature/test tmdbapi (#23)
* feat: TMDBServiceImplTest - get [now_playing] movie list in Korean * add: json-simple dependency * fix: 하단 공백 추가
This commit is contained in:
5
.idea/workspace.xml
generated
5
.idea/workspace.xml
generated
@@ -1,10 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="2a93e153-a90c-44db-b1da-6c4424693422" name="Changes" comment="">
|
<list default="true" id="2a93e153-a90c-44db-b1da-6c4424693422" name="Changes" comment="" />
|
||||||
<change afterPath="$PROJECT_DIR$/server/src/main/java/com/ticketing/server/global/config/SwaggerConfig.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/server/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/server/build.gradle.kts" afterDir="false" />
|
|
||||||
</list>
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ dependencies {
|
|||||||
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
||||||
implementation("com.lmax:disruptor:3.4.2")
|
implementation("com.lmax:disruptor:3.4.2")
|
||||||
implementation("io.jsonwebtoken:jjwt-api:0.11.2")
|
implementation("io.jsonwebtoken:jjwt-api:0.11.2")
|
||||||
|
implementation("com.googlecode.json-simple:json-simple:1.1.1")
|
||||||
|
|
||||||
modules {
|
modules {
|
||||||
module("org.springframework.boot:spring-boot-starter-logging") {
|
module("org.springframework.boot:spring-boot-starter-logging") {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.ticketing.server.global.config;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.time.Duration;
|
||||||
|
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.client.BufferingClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RestTemplateConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
|
||||||
|
return restTemplateBuilder
|
||||||
|
.requestFactory(() -> new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()))
|
||||||
|
.setConnectTimeout(Duration.ofMillis(5000)) // connection-timeout
|
||||||
|
.setReadTimeout(Duration.ofMillis(5000)) // read-timeout
|
||||||
|
.additionalMessageConverters(new StringHttpMessageConverter(Charset.forName("UTF-8")))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.ticketing.server.movie.service;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.service.interfaces.TMDBService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TMBDServiceImpl implements TMDBService {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.ticketing.server.movie.service.interfaces;
|
||||||
|
|
||||||
|
public interface TMDBService {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package com.ticketing.server.movie.service;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class TMDBServiceImplTest {
|
||||||
|
|
||||||
|
@Value("${tmdb.api-key}")
|
||||||
|
private String apiKey;
|
||||||
|
|
||||||
|
@Value("${tmdb.read-access-token}")
|
||||||
|
private String readAccessToken;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("TMDB Service Test - Get [Now Playing] movies")
|
||||||
|
void shouldAbleToGetMovieList() throws Exception {
|
||||||
|
// given
|
||||||
|
assertNotNull(apiKey);
|
||||||
|
assertNotNull(readAccessToken);
|
||||||
|
|
||||||
|
ArrayList<Charset> acceptCharset = new ArrayList<>();
|
||||||
|
acceptCharset.add(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setAcceptCharset(acceptCharset);
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.setBearerAuth(readAccessToken);
|
||||||
|
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put("api_key", apiKey);
|
||||||
|
params.put("language", "ko");
|
||||||
|
|
||||||
|
HttpEntity<?> request = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
// when
|
||||||
|
ResponseEntity<?> response = restTemplate.exchange(
|
||||||
|
"https://api.themoviedb.org/3/movie/now_playing?" + mapToUrlParam(params),
|
||||||
|
HttpMethod.GET,
|
||||||
|
request,
|
||||||
|
String.class
|
||||||
|
);
|
||||||
|
|
||||||
|
// JSONParser parser = new JSONParser();
|
||||||
|
// Object obj = parser.parse(String.valueOf(response));
|
||||||
|
// Object results = ((JSONObject) obj).get("results");
|
||||||
|
//
|
||||||
|
// ArrayList<String> movieList = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// ArrayList<JSONObject> jsonMovieList = new ArrayList<>();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(response.getStatusCode().is2xxSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String mapToUrlParam(Map<String, String> params) {
|
||||||
|
StringBuffer paramData = new StringBuffer();
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> param : params.entrySet()) {
|
||||||
|
if (paramData.length() != 0) {
|
||||||
|
paramData.append('&');
|
||||||
|
}
|
||||||
|
|
||||||
|
paramData.append(param.getKey());
|
||||||
|
paramData.append('=');
|
||||||
|
paramData.append(param.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return paramData.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -22,3 +22,8 @@ jwt:
|
|||||||
prefix: Bearer
|
prefix: Bearer
|
||||||
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK
|
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK
|
||||||
token-validity-in-seconds: 86400
|
token-validity-in-seconds: 86400
|
||||||
|
|
||||||
|
tmdb:
|
||||||
|
api-key: 0d1503b6dcbfe1c514299b5564c649b8
|
||||||
|
read-access-token: eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwZDE1MDNiNmRjYmZlMWM1MTQyOTliNTU2NGM2NDliOCIsInN1YiI6IjYyOWYwODRlNzI2ZmIxMTA2NDA4MjI2NCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.rs8KZea8QLyashILiggWFx2s46lgUtzo-xSWoDgE58A
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user