Skip to content

Commit

Permalink
News-Revision-Zuordnug gefixt
Browse files Browse the repository at this point in the history
  • Loading branch information
commel committed Apr 4, 2024
1 parent 3e155ea commit 41cc389
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/main/java/de/holarse/backend/db/NewsRevision.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class NewsRevision extends RevisionedNode {
@Column(length = 512)
private String teaser;

@OneToOne(mappedBy = "nodeRevision")
private News news;

@ManyToOne(cascade = { CascadeType.ALL })
@JoinColumn(name="news_category_id", referencedColumnName = "id")
private NewsCategory newsCategory;
Expand Down Expand Up @@ -50,10 +53,7 @@ public void setNewsCategory(NewsCategory newsCategory) {

@Override
public String toString() {
return "NewsRevision{" +
"title='" + title + '\'' +
", content='" + content + '\'' +
", newsCategory=" + newsCategory +
'}';
return "NewsRevision{id=" + getId() + ", "+ "title=" + title + ", content=" + content + ", teaser=" + teaser + ", newsCategory=" + newsCategory + '}';
}

}
5 changes: 3 additions & 2 deletions src/main/java/de/holarse/web/controller/NewsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.view.RedirectView;

Expand All @@ -45,7 +46,7 @@ public class NewsController {
final static transient Logger logger = LoggerFactory.getLogger(NewsController.class);

@Autowired
private NewsRepository newsRepository;
NewsRepository newsRepository;

@Autowired
private NodeSlugRepository nodeSlugRepository;
Expand All @@ -69,7 +70,7 @@ public class NewsController {
private NewsCategoryRepository newsCategoryRepository;

@GetMapping
public ModelAndView index(@PageableDefault(sort = {"title"}, value = NEWS_ARTICLES_DEFAULT_PAGE_SIZE) final Pageable pageable, final ModelAndView mv) {
public ModelAndView index(@PageableDefault(sort = {"title"}, value = NEWS_ARTICLES_DEFAULT_PAGE_SIZE) final PageRequest pageable, final ModelAndView mv) {
mv.setViewName("layouts/bare");
mv.addObject("title", "Die Linuxspiele-Seite für Linuxspieler");
mv.addObject(WebDefines.DEFAULT_VIEW_ATTRIBUTE_NAME, "sites/news/index");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
Expand Down
73 changes: 73 additions & 0 deletions src/test/java/de/holarse/web/controller/NewsControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package de.holarse.web.controller;

import de.holarse.backend.db.repositories.NewsRepository;
import java.util.ArrayList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.test.context.support.WithAnonymousUser;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static org.mockito.Mockito.when;

/**
*
* @author comrad
*/
public class NewsControllerTest {

// private NewsController controller;
//
// @Mock
// private NewsRepository newsRepositoryMock;
//
// @BeforeEach
// public void setup() throws Exception {
// MockitoAnnotations.openMocks(this);
// controller = new NewsController();
// controller.newsRepository = newsRepositoryMock;
// }
//
// @Test
// public void testIndex() throws Exception {
// when(newsRepositoryMock.findFrontpageItems(PageRequest.of(1, 5))).thenReturn(new ArrayList<>());
//
// MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
// mockMvc.perform(get("/news")).andExpect(status().isOk());
// }
//
// @Test
// public void testShowExisting() throws Exception {
// when(newsRepositoryMock.findBySlug(ArgumentMatchers.anyString())).thenReturn();
//
// MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
// mockMvc.perform(get("/news/hello-world")).andExpect(status().isOk());
// }
//
// @Test
// public void testShowNotExisting() throws Exception {
// MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
// mockMvc.perform(get("/news/i-do-not-exist")).andExpect(status().isNotFound());
// }
//
// @Test
// @WithAnonymousUser
// public void testShowNotPublishedAsUser() throws Exception {
// MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
// mockMvc.perform(get("/news/unpublished-news")).andExpect(status().isOk());
// }
//
// @Test
// @WithMockUser(roles = "ADMIN")
// public void testShowNotPublishedAsAdmin() throws Exception {
// MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
// mockMvc.perform(get("/news/published-news")).andExpect(status().isOk());
// }

}

0 comments on commit 41cc389

Please sign in to comment.