Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eclipse Projects
Eclipse openK User Modules
org.eclipse.openk-usermodules.gridFailureInformation.backend
Commits
c8e574d6
Commit
c8e574d6
authored
Mar 03, 2020
by
Holger Rudolph
Browse files
[SI-65] controller for ref tables and unit tests
Signed-off-by:
Holger Rudolph
<
holger.rudolph@pta.de
>
parent
29283b8e
Changes
20
Hide whitespace changes
Inline
Side-by-side
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/FailureClassificationController.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.controller
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiResponse
;
import
io.swagger.annotations.ApiResponses
;
import
lombok.extern.log4j.Log4j2
;
import
org.eclipse.openk.gridfailureinformation.service.FailureClassificationService
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureClassificationDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@Log4j2
@RestController
@RequestMapping
(
"/failure-classifications"
)
public
class
FailureClassificationController
{
@Autowired
private
FailureClassificationService
failureClassificationService
;
@ApiOperation
(
value
=
"Anzeigen aller Störungsmeldungsklassen"
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Erfolgreich durchgeführt"
)})
@GetMapping
public
List
<
FailureClassificationDto
>
findBranches
()
{
return
failureClassificationService
.
getFailureClassifications
();
}
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/FailureTypeController.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.controller
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiResponse
;
import
io.swagger.annotations.ApiResponses
;
import
lombok.extern.log4j.Log4j2
;
import
org.eclipse.openk.gridfailureinformation.service.FailureTypeService
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureTypeDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@Log4j2
@RestController
@RequestMapping
(
"/failure-types"
)
public
class
FailureTypeController
{
@Autowired
private
FailureTypeService
failureTypeService
;
@ApiOperation
(
value
=
"Anzeigen aller Störungsmeldungstypen"
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Erfolgreich durchgeführt"
)})
@GetMapping
public
List
<
FailureTypeDto
>
findBranches
()
{
return
failureTypeService
.
getFailureTypes
();
}
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/StatusController.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.controller
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiResponse
;
import
io.swagger.annotations.ApiResponses
;
import
lombok.extern.log4j.Log4j2
;
import
org.eclipse.openk.gridfailureinformation.service.StatusService
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.StatusDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@Log4j2
@RestController
@RequestMapping
(
"/status"
)
public
class
StatusController
{
@Autowired
private
StatusService
statusService
;
@ApiOperation
(
value
=
"Anzeigen aller Status"
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Erfolgreich durchgeführt"
)})
@GetMapping
public
List
<
StatusDto
>
findStatus
()
{
return
statusService
.
getStatus
();
}
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/FailureClassificationMapper.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.mapper
;
import
org.eclipse.openk.gridfailureinformation.model.RefFailureClassification
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureClassificationDto
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
FailureClassificationMapper
{
FailureClassificationDto
toFailureClassificationDto
(
RefFailureClassification
refFailureClassification
);
RefFailureClassification
toRefFailureClassification
(
FailureClassificationDto
failureClassificationDto
);
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/FailureTypeMapper.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.mapper
;
import
org.eclipse.openk.gridfailureinformation.model.RefFailureType
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureTypeDto
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
FailureTypeMapper
{
FailureTypeDto
toFailureTypeDto
(
RefFailureType
refFailureType
);
RefFailureType
toRefFailureType
(
FailureTypeDto
failureTypeDto
);
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/StatusMapper.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.mapper
;
import
org.eclipse.openk.gridfailureinformation.model.RefStatus
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.StatusDto
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
StatusMapper
{
StatusDto
toStatusDto
(
RefStatus
refStatus
);
RefStatus
toRefStatus
(
StatusDto
statusDto
);
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureClassificationService.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.service
;
import
org.eclipse.openk.gridfailureinformation.mapper.FailureClassificationMapper
;
import
org.eclipse.openk.gridfailureinformation.repository.FailureClassificationRepository
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureClassificationDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
public
class
FailureClassificationService
{
@Autowired
private
FailureClassificationRepository
failureClassificationRepository
;
@Autowired
private
FailureClassificationMapper
failureClassificationMapper
;
public
List
<
FailureClassificationDto
>
getFailureClassifications
()
{
return
failureClassificationRepository
.
findAll
().
stream
()
.
map
(
failureClassificationMapper:
:
toFailureClassificationDto
)
.
collect
(
Collectors
.
toList
());
}
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java
View file @
c8e574d6
...
@@ -106,7 +106,7 @@ public class FailureInformationService {
...
@@ -106,7 +106,7 @@ public class FailureInformationService {
if
(
sourceDto
.
getFailureTypeId
()
!=
null
)
{
if
(
sourceDto
.
getFailureTypeId
()
!=
null
)
{
destTblFailureInformation
.
setRefFailureType
(
failureTypeRepository
destTblFailureInformation
.
setRefFailureType
(
failureTypeRepository
.
findByUuid
(
sourceDto
.
getFailure
Classification
Id
())
.
findByUuid
(
sourceDto
.
getFailure
Type
Id
())
.
orElseThrow
(()
->
new
NotFoundException
(
"failure.type.uuid.not.existing"
)));
.
orElseThrow
(()
->
new
NotFoundException
(
"failure.type.uuid.not.existing"
)));
}
}
else
{
else
{
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureTypeService.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.service
;
import
org.eclipse.openk.gridfailureinformation.mapper.FailureTypeMapper
;
import
org.eclipse.openk.gridfailureinformation.repository.FailureTypeRepository
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureTypeDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
public
class
FailureTypeService
{
@Autowired
private
FailureTypeRepository
failureTypeRepository
;
@Autowired
private
FailureTypeMapper
failureTypeMapper
;
public
List
<
FailureTypeDto
>
getFailureTypes
()
{
return
failureTypeRepository
.
findAll
().
stream
()
.
map
(
failureTypeMapper:
:
toFailureTypeDto
)
.
collect
(
Collectors
.
toList
());
}
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/StatusService.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.service
;
import
org.eclipse.openk.gridfailureinformation.mapper.StatusMapper
;
import
org.eclipse.openk.gridfailureinformation.repository.StatusRepository
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.StatusDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
public
class
StatusService
{
@Autowired
private
StatusRepository
statusRepository
;
@Autowired
private
StatusMapper
statusMapper
;
public
List
<
StatusDto
>
getStatus
()
{
return
statusRepository
.
findAll
().
stream
()
.
map
(
statusMapper:
:
toStatusDto
)
.
collect
(
Collectors
.
toList
());
}
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/FailureClassificationDto.java
View file @
c8e574d6
...
@@ -27,3 +27,4 @@ public class FailureClassificationDto implements Serializable {
...
@@ -27,3 +27,4 @@ public class FailureClassificationDto implements Serializable {
private
String
classification
;
private
String
classification
;
private
String
description
;
private
String
description
;
}
}
gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java
View file @
c8e574d6
...
@@ -20,9 +20,7 @@ import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapperI
...
@@ -20,9 +20,7 @@ import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapperI
import
org.eclipse.openk.gridfailureinformation.mapper.VersionMapper
;
import
org.eclipse.openk.gridfailureinformation.mapper.VersionMapper
;
import
org.eclipse.openk.gridfailureinformation.mapper.VersionMapperImpl
;
import
org.eclipse.openk.gridfailureinformation.mapper.VersionMapperImpl
;
import
org.eclipse.openk.gridfailureinformation.mapper.*
;
import
org.eclipse.openk.gridfailureinformation.mapper.*
;
import
org.eclipse.openk.gridfailureinformation.service.BranchService
;
import
org.eclipse.openk.gridfailureinformation.service.*
;
import
org.eclipse.openk.gridfailureinformation.service.FailureInformationService
;
import
org.eclipse.openk.gridfailureinformation.service.VersionService
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
import
org.springframework.boot.test.context.ConfigFileApplicationContextInitializer
;
import
org.springframework.boot.test.context.ConfigFileApplicationContextInitializer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -39,18 +37,33 @@ public class TestConfiguration {
...
@@ -39,18 +37,33 @@ public class TestConfiguration {
VersionMapper
versionMapper
()
{
return
new
VersionMapperImpl
();
}
VersionMapper
versionMapper
()
{
return
new
VersionMapperImpl
();
}
@Bean
@Bean
FailureInformationMapper
gridF
ailureInformationMapper
()
{
return
new
FailureInformationMapperImpl
();
}
FailureInformationMapper
f
ailureInformationMapper
()
{
return
new
FailureInformationMapperImpl
();
}
@Bean
@Bean
BranchMapper
branchMapper
()
{
return
new
BranchMapperImpl
();
}
BranchMapper
branchMapper
()
{
return
new
BranchMapperImpl
();
}
@Bean
FailureClassificationMapper
failureClassificationMapper
()
{
return
new
FailureClassificationMapperImpl
();
}
@Bean
FailureTypeMapper
failureTypeMapper
()
{
return
new
FailureTypeMapperImpl
();
}
@Bean
StatusMapper
statusMapper
()
{
return
new
StatusMapperImpl
();
}
@Bean
@Bean
public
VersionService
myVersionService
()
{
public
VersionService
myVersionService
()
{
return
new
VersionService
();
return
new
VersionService
();
}
}
@Bean
@Bean
public
FailureInformationService
my
Grid
FailureInformationService
()
{
public
FailureInformationService
myFailureInformationService
()
{
return
new
FailureInformationService
();
return
new
FailureInformationService
();
}
}
...
@@ -59,4 +72,18 @@ public class TestConfiguration {
...
@@ -59,4 +72,18 @@ public class TestConfiguration {
return
new
BranchService
();
return
new
BranchService
();
}
}
@Bean
public
FailureClassificationService
myFailureClassificationService
()
{
return
new
FailureClassificationService
();
}
@Bean
public
FailureTypeService
myFailureTypeService
()
{
return
new
FailureTypeService
();
}
@Bean
public
StatusService
myStatusService
()
{
return
new
StatusService
();
}
}
}
gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/FailureClassificationControllerTest.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.controller
;
import
org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication
;
import
org.eclipse.openk.gridfailureinformation.service.FailureClassificationService
;
import
org.eclipse.openk.gridfailureinformation.support.MockDataHelper
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureClassificationDto
;
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.boot.test.mock.mockito.MockBean
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
java.util.List
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
@SpringBootTest
(
classes
=
GridFailureInformationApplication
.
class
)
@AutoConfigureMockMvc
public
class
FailureClassificationControllerTest
{
@MockBean
private
FailureClassificationService
failureClassificationService
;
@Autowired
private
MockMvc
mockMvc
;
@Test
public
void
shouldReturnFailureClassifications
()
throws
Exception
{
List
<
FailureClassificationDto
>
failureClassificationDtoList
=
MockDataHelper
.
mockFailureClassificationDtoList
();
when
(
failureClassificationService
.
getFailureClassifications
()).
thenReturn
(
failureClassificationDtoList
);
mockMvc
.
perform
(
get
(
"/failure-classifications"
))
.
andExpect
(
status
().
is2xxSuccessful
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
));
}
}
\ No newline at end of file
gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/FailureTypeControllerTest.java
0 → 100644
View file @
c8e574d6
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package
org.eclipse.openk.gridfailureinformation.controller
;
import
org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication
;
import
org.eclipse.openk.gridfailureinformation.service.FailureTypeService
;
import
org.eclipse.openk.gridfailureinformation.support.MockDataHelper
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureTypeDto
;
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.boot.test.mock.mockito.MockBean
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
java.util.List
;