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
import com.coxautodev.graphql.tools.GraphQLMutationResolver; | |
import donald.apiwithspringboot.model.Blog; | |
import donald.apiwithspringboot.model.mutation.CreateBlog; | |
import donald.apiwithspringboot.repository.BlogRepository; | |
import lombok.AllArgsConstructor; | |
import org.springframework.stereotype.Component; | |
import org.springframework.transaction.annotation.Transactional; | |
@Component |
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
@Override | |
protected void configure(HttpSecurity httpSecurity) throws Exception { | |
httpSecurity.csrf().disable() | |
.authorizeRequests().antMatchers("/authenticate","/user").permitAll(). | |
anyRequest().authenticated().and(). | |
exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and().sessionManagement() | |
.sessionCreationPolicy(SessionCreationPolicy.STATELESS); | |
httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class); | |
httpSecurity.logout().logoutSuccessUrl("/authenticate").logoutUrl("/logout").permitAll(); | |
} |
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
<dependency> | |
<groupId>com.graphql-java</groupId> | |
<artifactId>graphql-java-tools</artifactId> | |
<version>5.2.4</version> | |
</dependency> | |
<dependency> | |
<groupId>com.graphql-java</groupId> | |
<artifactId>graphiql-spring-boot-starter</artifactId> | |
<version>5.0.2</version> | |
</dependency> |
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
type Blog { | |
id: Int, | |
title: String, | |
content: String | |
} | |
type Query { | |
blogs(count: Int):[Blog] | |
blog(id: Int):Blog | |
} |
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
@Service | |
public class BlogService { | |
private final BlogRepository blogRepository; | |
public BlogService(final BlogRepository blogRepository){this.blogRepository = blogRepository;} | |
@Transactional(readOnly = true) | |
public List<Blog> getAllBlogs(final int count){ | |
return this.blogRepository.findAll().stream().limit(count).collect(Collectors.toList()); |
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
@Component | |
public class BlogQuery implements GraphQLQueryResolver { | |
@Autowired | |
private BlogService blogService; | |
public List<Blog> getBlogs(final int count){ | |
return this.blogService.getAllBlogs(count); | |
} |
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
@Override | |
protected void configure(HttpSecurity httpSecurity) throws Exception { | |
httpSecurity.csrf().disable() | |
.authorizeRequests().antMatchers("/authenticate","/user").permitAll(). | |
anyRequest().authenticated().and(). | |
exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and().sessionManagement() |
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
class Blogs: | |
def get_blog_info(self, query, token): | |
request = requests.post(API_SERVER_URL + API_GRAPH_QL_PATH, json={'query': query}, headers={"Authorization": f"Bearer {token}"}) | |
if request.status_code == 200: | |
return request.json() | |
else: | |
raise Exception("Query failed to run by returning code of {}. {}".format(request.status_code, query)) |
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
class TestGetBlogsInfo: | |
user_api = User() | |
restapi_query = RestAPIDatabase() | |
random_gen = RandomGenerator() | |
blog_graphql_api = Blogs() | |
@pytestrail.case('C8') | |
def test_get_all_blog_id_and_contents_with_count(self, set_up_mysql): | |
username = self.random_gen.random_string(8) + '@gmail.com' | |
query = """ |
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
from appium import webdriver | |
class TestChrome: | |
def test_open_web_page(self): | |
platform_name = 'Android' | |
platform_version = '10' | |
device_name = 'Galaxy A51' |