Skip to content
Snippets Groups Projects
Commit 086b805b authored by evilimkova's avatar evilimkova
Browse files

Delete old tests

parent 8c5dfb12
No related branches found
No related tags found
4 merge requests!31M2,!29M2 exercise,!27Draft: M2 user,!19M2 certificate
Pipeline #
package org.fuseri.modulecertificate;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.fuseri.model.dto.certificate.CertificateCreateDto;
import org.fuseri.model.dto.certificate.CertificateDto;
import org.fuseri.model.dto.course.CourseDto;
import org.fuseri.model.dto.course.LanguageTypeDto;
import org.fuseri.model.dto.course.ProficiencyLevelDto;
import org.fuseri.model.dto.user.AddressDto;
import org.fuseri.model.dto.user.UserDto;
import org.fuseri.modulecertificate.service.CertificateController;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
class ModuleCertificateCertificateControllerTests {
@Autowired
private MockMvc mockMvc;
@Autowired
ObjectMapper objectMapper;
@Test
void generateCertificate() throws Exception {
CertificateDto expectedResponse = new CertificateDto();
String response = mockMvc.perform(post("/certificates/generate")
.content(asJsonString(new CertificateCreateDto(
new UserDto("novakovat","novakova@gamil.com", "Tereza",
"Nováková", new AddressDto()),
new CourseDto("AJ1", 10, LanguageTypeDto.ENGLISH, ProficiencyLevelDto.A1))))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
CertificateController certificateController = objectMapper.readValue(response, CertificateController.class);
assertThat("response", certificateController.find(0L), is(instanceOf(expectedResponse.getClass())));
}
@Test
void deleteCertificate() throws Exception {
String response = mockMvc.perform(delete("/certificates/delete")
.param("id", "1"))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
}
public static String asJsonString(final Object obj) {
try {
return new ObjectMapper().writeValueAsString(obj);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment