Fakultas Ilmu Komputer UI

Commit 2b090a06 authored by WINALDO AMADEA HESTU's avatar WINALDO AMADEA HESTU
Browse files

Merge branch 'winaldo' into 'staging'

add some html code

See merge request !21
parents e6e755db ca6dc5f5
Pipeline #134137 passed with stages
in 22 minutes and 28 seconds
package id.ac.ui.cs.advprog.landiandfriends.forms;
import lombok.Data;
import lombok.Generated;
@Generated
@Data
public class AddPaymentForm {
private String name;
......
package id.ac.ui.cs.advprog.landiandfriends.forms;
import lombok.Data;
import lombok.Generated;
@Generated
@Data
public class CreateAddressForm {
......
package id.ac.ui.cs.advprog.landiandfriends.forms;
import lombok.Data;
import lombok.Generated;
@Generated
@Data
public class CreateArticleForm {
private String title;
......
......@@ -3,7 +3,9 @@ package id.ac.ui.cs.advprog.landiandfriends.forms;
import lombok.Data;
import java.util.List;
import lombok.Generated;
@Generated
@Data
public class CreateBookForm {
......
package id.ac.ui.cs.advprog.landiandfriends.forms;
import lombok.Data;
import lombok.Generated;
@Generated
@Data
public class EditProfileForm {
......
package id.ac.ui.cs.advprog.landiandfriends.forms;
import lombok.Data;
import lombok.Generated;
@Generated
@Data
public class RegisterAdmin{
private String email;
......
package id.ac.ui.cs.advprog.landiandfriends.forms;
import lombok.Data;
import lombok.Generated;
@Generated
@Data
public class RegisterForm {
private String email;
......
......@@ -58,8 +58,11 @@ public class ArticleServiceImpl implements ArticleService{
public void deleteArticle(Integer id){
Optional<Articles> art = repo.findById(id);
Articles objArt = art.get();
repo.delete(objArt);
if(art.isPresent()){
Articles objArt = art.get();
repo.delete(objArt);
}
}
}
......
......@@ -14,6 +14,8 @@ import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
......@@ -102,7 +104,7 @@ public class BookServiceImpl implements BookService {
}
public List<String> getSearchedBookTitles(String title){
return bookRepository.findAll().stream().filter(e -> e.getTitle().equals(title)).map(Book::getTitle).toList();
return bookRepository.findAll().stream().filter(e -> e.getTitle().equals(title)).map(Book::getTitle).collect(Collectors.toList());
}
......
......@@ -92,7 +92,7 @@
</thead>
<tbody th:each="user : ${all_users}" th:remove="tag">
<div th:if="${#strings.toString(user.roles.getName())} == 'USER'">
<td th:text="${user.user_id}">...</td>
<td th:text="${user.userId}">...</td>
<td th:text="${user.email}">...</td>
<td>
<div th:switch="${user.active}">
......
......@@ -8,6 +8,6 @@
<h1>You Have Successfully Banned
<span th:text="${username}" th:remove="tag">Success</span>
</h1>
<button type="button" th:onclick="|window.location.href='/admin/list-user'|">Go Back To User <List></List></button>
<button type="button" th:onclick="|window.location.href='/admin/list-user'|">Go Back To User List <List></List></button>
</body>
</html>
package id.ac.ui.cs.advprog.landiandfriends.controller;
import id.ac.ui.cs.advprog.landiandfriends.model.Articles;
import id.ac.ui.cs.advprog.landiandfriends.model.Book;
import id.ac.ui.cs.advprog.landiandfriends.model.User;
import id.ac.ui.cs.advprog.landiandfriends.repository.UserRepository;
import id.ac.ui.cs.advprog.landiandfriends.service.PaymentServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.UserServiceImpl;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
@WebMvcTest(controllers = AdminController.class)
class AdminControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private UserServiceImpl userService;
@MockBean
private PaymentServiceImpl paymentService;
@MockBean
private UserRepository userRepository;
@Test
@WithMockUser(authorities={"ADMIN"})
void allUser() throws Exception {
List<User> userList = new ArrayList<>();
when(userService.allUsers()).thenReturn(userList);
mockMvc.perform(get("/admin/list-user"))
.andExpect(status().isOk())
.andExpect(handler().methodName("allUser"))
.andExpect(model().attributeExists( "username", "all_users"))
.andExpect(view().name("listuser"));
verify(userService, times(1)).allUsers();
}
@Test
@WithMockUser(authorities={"ADMIN"})
void whenPostBanUserValid() throws Exception {
User user = new User();
UserServiceImpl userService = mock(UserServiceImpl.class);
user.setUsername("Fauzan");
Mockito.lenient().doNothing().when(userService).banUser("Fauzan");
MvcResult result = mockMvc.perform(post("/admin/ban/Fauzan")
.with(csrf()))
.andExpect(handler().methodName("updateUser"))
.andReturn();
assertEquals(302, result.getResponse().getStatus());
}
@Test
@WithMockUser(authorities={"ADMIN"})
void whenSuccessValid() throws Exception {
mockMvc.perform(get("/admin/success"))
.andExpect(status().isOk())
.andExpect(handler().methodName("success"))
.andExpect(view().name("successBan")).andExpect(status().is(200));
}
}
\ No newline at end of file
......@@ -229,5 +229,16 @@ class CuratorControllerTest {
.andExpect(view().name("article-create"));
}
@Test
@WithMockUser(authorities={"CURATOR"})
void whenPostRemoveArticleValid() throws Exception {
MvcResult result = mockMvc.perform(post("/curator/delete/5")
.with(csrf()))
.andExpect(handler().methodName("deleteArticle"))
.andReturn();
assertEquals(302, result.getResponse().getStatus());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment