Skip to content
Snippets Groups Projects
Commit 6dbbc237 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6867 OZG-6904 implement controller

parent 13934c67
Branches
Tags
No related merge requests found
package de.ozgcloud.admin;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
import org.springframework.hateoas.server.core.DefaultLinkRelationProvider;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
@Configuration
public class AdministrationRepositoryRestConfigurer implements RepositoryRestConfigurer {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) {
config.setLinkRelationProvider(new DefaultLinkRelationProvider());
}
}
......@@ -5,13 +5,13 @@ import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.hateoas.server.core.Relation;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Getter;
import lombok.extern.jackson.Jacksonized;
@Relation(collectionRelation = "organisationsEinheitList")
@Getter
@Builder(toBuilder = true)
@Jacksonized
......@@ -21,13 +21,16 @@ public class OrganisationsEinheit {
static final String COLLECTION_NAME = "organisationsEinheit";
@JsonIgnore
@Id
private String id;
private String name;
private String anschrift;
private String organisationsEinheitId;
private String uebergeordneteOrganisationseinheitId;
private List<String> untergeordneteOrganisationseinheitId;
private String zufiId;
private List<String> untergeordneteOrganisationseinheitIds;
private SyncResult syncResult;
@JsonIgnore
private String zufiId;
}
\ No newline at end of file
......@@ -28,6 +28,6 @@ public class OrganisationsEinheitController {
@GetMapping("/{id}")
public EntityModel<OrganisationsEinheit> getById(@PathVariable String id) {
throw new UnsupportedOperationException("Not implemented yet");
return assembler.toModel(organisationsEinheitService.getOrganisationsEinheitById(id));
}
}
package de.ozgcloud.admin;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.hateoas.server.LinkRelationProvider;
import org.springframework.hateoas.server.core.DefaultLinkRelationProvider;
class AdministrationRepositoryRestConfigurerTest {
@InjectMocks
private AdministrationRepositoryRestConfigurer configurer;
@Nested
class TestConfigureRepositoryRestConfiguration {
@Captor
private ArgumentCaptor<LinkRelationProvider> linkRelationProviderArgumentCaptor;
@Test
void shouldUseDefaultLinkRelationProvider() {
var configuration = mock(RepositoryRestConfiguration.class);
configurer.configureRepositoryRestConfiguration(configuration, null);
verify(configuration).setLinkRelationProvider(linkRelationProviderArgumentCaptor.capture());
assertThat(linkRelationProviderArgumentCaptor.getValue()).isInstanceOf(DefaultLinkRelationProvider.class);
}
}
}
\ No newline at end of file
......@@ -84,4 +84,40 @@ class OrganisationsEinheitControllerTest {
return mockMvc.perform(get(OrganisationsEinheitController.PATH));
}
}
@Nested
class TestGetById {
private final OrganisationsEinheit organisationsEinheit = OrganisationsEinheitTestFactory.create();
@BeforeEach
void setUp() {
when(organisationsEinheitService.getOrganisationsEinheitById(OrganisationsEinheitTestFactory.ID)).thenReturn(organisationsEinheit);
}
@Test
void shouldCallService() {
doRequest();
verify(organisationsEinheitService).getOrganisationsEinheitById(OrganisationsEinheitTestFactory.ID);
}
@Test
void shouldCallAssembler() {
doRequest();
verify(assembler).toModel(organisationsEinheit);
}
@SneakyThrows
@Test
void shouldReturnHttpOk() {
doRequest().andExpect(status().isOk());
}
@SneakyThrows
private ResultActions doRequest() {
return mockMvc.perform(get(OrganisationsEinheitController.PATH + "/" + OrganisationsEinheitTestFactory.ID));
}
}
}
\ No newline at end of file
......@@ -39,7 +39,7 @@ class OrganisationsEinheitITCase {
@MockBean
private OrganisationsEinheitService service;
@MockBean
private JwtDecoder decoer;
private JwtDecoder decoder;
@Autowired
private MockMvc mockMvc;
......@@ -61,5 +61,51 @@ class OrganisationsEinheitITCase {
response.andDo(print()).andExpect(jsonPath("$._embedded.organisationsEinheitList").isNotEmpty());
}
@SneakyThrows
@Test
void shouldContainOrganisationsEinheit() {
mockMvc.perform(get(PATH))
.andExpect(jsonPath("$._embedded.organisationsEinheitList[0].name").value(OrganisationsEinheitTestFactory.NAME))
.andExpect(jsonPath("$._embedded.organisationsEinheitList[0].anschrift").value(OrganisationsEinheitTestFactory.ANSCHRIFT))
.andExpect(jsonPath("$._embedded.organisationsEinheitList[0].organisationsEinheitId").value(
OrganisationsEinheitTestFactory.ORGANISATIONS_EINHEIT_ID))
.andExpect(jsonPath("$._embedded.organisationsEinheitList[0].uebergeordneteOrganisationseinheitId").value(
OrganisationsEinheitTestFactory.UEBERGEORDNETE_ORGANISATIONSEINHEIT_ID))
.andExpect(jsonPath("$._embedded.organisationsEinheitList[0].untergeordneteOrganisationseinheitIds[0]").value(
OrganisationsEinheitTestFactory.UNTERGEORDNETE_ORGANISATIONSEINHEIT_ID.getFirst()))
.andExpect(jsonPath("$._embedded.organisationsEinheitList[0].zufiId").doesNotExist())
.andExpect(jsonPath("$._embedded.organisationsEinheitList[0].id").doesNotExist());
}
}
@DisplayName("Get by id")
@WithMockUser
@Nested
class TestGetById {
@BeforeEach
void init() {
when(service.getOrganisationsEinheitById(OrganisationsEinheitTestFactory.ID)).thenReturn(OrganisationsEinheitTestFactory.create());
}
@SneakyThrows
@Test
void shouldReturnOrganisationsEinheit() {
var response = mockMvc.perform(get(PATH + "/" + OrganisationsEinheitTestFactory.ID)).andExpect(status().isOk());
response
.andExpect(jsonPath("$.name").value(OrganisationsEinheitTestFactory.NAME))
.andExpect(jsonPath("$.anschrift").value(OrganisationsEinheitTestFactory.ANSCHRIFT))
.andExpect(jsonPath("$.organisationsEinheitId").value(
OrganisationsEinheitTestFactory.ORGANISATIONS_EINHEIT_ID))
.andExpect(jsonPath("$.uebergeordneteOrganisationseinheitId").value(
OrganisationsEinheitTestFactory.UEBERGEORDNETE_ORGANISATIONSEINHEIT_ID))
.andExpect(jsonPath("$.untergeordneteOrganisationseinheitIds[0]").value(
OrganisationsEinheitTestFactory.UNTERGEORDNETE_ORGANISATIONSEINHEIT_ID.getFirst()))
.andExpect(jsonPath("$.zufiId").doesNotExist())
.andExpect(jsonPath("$.id").doesNotExist());
}
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ public class OrganisationsEinheitTestFactory {
.anschrift(ANSCHRIFT)
.organisationsEinheitId(ORGANISATIONS_EINHEIT_ID)
.uebergeordneteOrganisationseinheitId(UEBERGEORDNETE_ORGANISATIONSEINHEIT_ID)
.untergeordneteOrganisationseinheitId(UNTERGEORDNETE_ORGANISATIONSEINHEIT_ID)
.untergeordneteOrganisationseinheitIds(UNTERGEORDNETE_ORGANISATIONSEINHEIT_ID)
.zufiId(ZUFI_ID)
.syncResult(SYNC_RESULT);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment