Skip to content

Commit

Permalink
Rettet tester (satte eksplisitt ID før persistering), fjernet warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc3092 committed Oct 17, 2023
1 parent 62767ab commit 23ad0c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package no.nav.dolly.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import no.nav.dolly.MockedJwtAuthenticationTokenUtils;
import no.nav.dolly.domain.jpa.Bestilling;
import no.nav.dolly.domain.jpa.BestillingMal;
import no.nav.dolly.domain.jpa.Bruker;
import no.nav.dolly.domain.jpa.Testgruppe;
import no.nav.dolly.repository.BestillingMalRepository;
import no.nav.dolly.repository.BestillingRepository;
import no.nav.dolly.repository.BrukerFavoritterRepository;
import no.nav.dolly.repository.BrukerRepository;
import no.nav.dolly.repository.IdentRepository;
import no.nav.dolly.repository.TestgruppeRepository;
import no.nav.dolly.repository.*;
import org.flywaydb.core.Flyway;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -31,14 +25,9 @@
import java.time.LocalDate;
import java.time.LocalDateTime;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
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.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand All @@ -48,20 +37,18 @@
@EnableAutoConfiguration
@ComponentScan("no.nav.dolly")
@AutoConfigureMockMvc(addFilters = false)
public class BestillingMalServiceTest {
class BestillingMalServiceTest {

private final static String MALNAVN = "test";
private final static String NYTT_MALNAVN = "nyttMalnavn";
private final static String BEST_KRITERIER = "Testeteste";
private static final Bruker DUMMY_EN = Bruker.builder()
.id(1L)
.brukerId("testbruker_en")
.brukernavn("test_en")
.brukertype(Bruker.Brukertype.AZURE)
.epost("epost@test_en")
.build();
private static final Bruker DUMMY_TO = Bruker.builder()
.id(2L)
.brukerId("testbruker_to")
.brukernavn("test_to")
.brukertype(Bruker.Brukertype.AZURE)
Expand All @@ -88,8 +75,6 @@ public class BestillingMalServiceTest {
@Autowired
private IdentRepository identRepository;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private Flyway flyway;

@Transactional
Expand All @@ -114,8 +99,8 @@ public void afterEach() {
void shouldCreateAndGetMaler()
throws Exception {

var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).get();
var bruker_to = brukerRepository.findBrukerByBrukerId(DUMMY_TO.getBrukerId()).get();
var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).orElseThrow();
var bruker_to = brukerRepository.findBrukerByBrukerId(DUMMY_TO.getBrukerId()).orElseThrow();
saveDummyBestillingMal(bruker_en);
saveDummyBestillingMal(bruker_to);

Expand All @@ -136,7 +121,7 @@ void shouldCreateAndGetMaler()
void shouldCreateMalerFromExistingOrder()
throws Exception {

var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).get();
var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).orElseThrow();
var testgruppe = saveDummyGruppe();
var bestilling = saveDummyBestilling(bruker_en, testgruppe);

Expand All @@ -157,7 +142,7 @@ void shouldCreateMalerFromExistingOrder()
void shouldCreateUpdateAndDeleteMal()
throws Exception {

var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).get();
var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).orElseThrow();
var bestillingMal = saveDummyBestillingMal(bruker_en);

mockMvc.perform(put("/api/v1/bestilling/malbestilling/{id}", bestillingMal.getId())
Expand Down Expand Up @@ -193,7 +178,6 @@ Bestilling saveDummyBestilling(Bruker bruker, Testgruppe testgruppe) {
return bestillingRepository.save(
Bestilling
.builder()
.id(1L)
.gruppe(testgruppe)
.ferdig(false)
.antallIdenter(1)
Expand All @@ -215,7 +199,6 @@ Testgruppe saveDummyGruppe() {
.navn(TESTGRUPPE)
.hensikt(TESTGRUPPE)
.datoEndret(LocalDate.now())
.id(1L)
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.dolly.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import no.nav.dolly.MockedJwtAuthenticationTokenUtils;
import no.nav.dolly.domain.jpa.Bruker;
import no.nav.dolly.domain.jpa.OrganisasjonBestilling;
Expand All @@ -25,14 +24,9 @@

import java.time.LocalDateTime;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
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.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand All @@ -42,20 +36,18 @@
@EnableAutoConfiguration
@ComponentScan("no.nav.dolly")
@AutoConfigureMockMvc(addFilters = false)
public class OrganisasjonBestillingMalServiceTest {
class OrganisasjonBestillingMalServiceTest {

private final static String MALNAVN = "test";
private final static String NYTT_MALNAVN = "nyttMalnavn";
private final static String BEST_KRITERIER = "Testeteste";
private static final Bruker DUMMY_EN = Bruker.builder()
.id(1L)
.brukernavn("test_en")
.brukerId("testbruker_en")
.brukertype(Bruker.Brukertype.AZURE)
.epost("epost@test_en")
.build();
private static final Bruker DUMMY_TO = Bruker.builder()
.id(2L)
.brukernavn("test_to")
.brukerId("testbruker_to")
.brukertype(Bruker.Brukertype.AZURE)
Expand All @@ -73,8 +65,6 @@ public class OrganisasjonBestillingMalServiceTest {
@Autowired
private BrukerRepository brukerRepository;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private Flyway flyway;

@BeforeEach
Expand All @@ -99,8 +89,8 @@ public void afterEach() {
void shouldCreateAndGetMaler()
throws Exception {

var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).get();
var bruker_to = brukerRepository.findBrukerByBrukerId(DUMMY_TO.getBrukerId()).get();
var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).orElseThrow();
var bruker_to = brukerRepository.findBrukerByBrukerId(DUMMY_TO.getBrukerId()).orElseThrow();
saveDummyBestillingMal(bruker_en);
saveDummyBestillingMal(bruker_to);

Expand All @@ -121,7 +111,7 @@ void shouldCreateAndGetMaler()
void shouldCreateMalerFromExistingOrder()
throws Exception {

var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).get();
var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).orElseThrow();
var bestilling = saveDummyBestilling(bruker_en);

mockMvc.perform(post("/api/v1/organisasjon/bestilling/malbestilling")
Expand All @@ -141,7 +131,7 @@ void shouldCreateMalerFromExistingOrder()
void shouldCreateUpdateAndDeleteMal()
throws Exception {

var bruker_to = brukerRepository.findBrukerByBrukerId(DUMMY_TO.getBrukerId()).get();
var bruker_to = brukerRepository.findBrukerByBrukerId(DUMMY_TO.getBrukerId()).orElseThrow();
var bestillingMal = saveDummyBestillingMal(bruker_to);

mockMvc.perform(put("/api/v1/organisasjon/bestilling/malbestilling/{id}", bestillingMal.getId())
Expand Down

0 comments on commit 23ad0c6

Please sign in to comment.