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
29283b8e
Commit
29283b8e
authored
Mar 03, 2020
by
Ina Curdt
Browse files
sonar work
parent
be33e8a6
Changes
12
Hide whitespace changes
Inline
Side-by-side
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/BranchController.java
View file @
29283b8e
...
...
@@ -19,16 +19,11 @@ import io.swagger.annotations.ApiResponse;
import
io.swagger.annotations.ApiResponses
;
import
lombok.extern.log4j.Log4j2
;
import
org.eclipse.openk.gridfailureinformation.service.BranchService
;
import
org.eclipse.openk.gridfailureinformation.service.FailureInformationService
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.domain.PageRequest
;
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
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/FailureInformationController.java
View file @
29283b8e
...
...
@@ -27,11 +27,8 @@ import org.springframework.data.domain.PageRequest;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.annotation.Secured
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.servlet.support.ServletUriComponentsBuilder
;
import
java.net.URI
;
import
java.util.List
;
import
java.util.UUID
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/BranchMapper.java
View file @
29283b8e
...
...
@@ -15,12 +15,8 @@
package
org.eclipse.openk.gridfailureinformation.mapper
;
import
org.eclipse.openk.gridfailureinformation.model.RefBranch
;
import
org.eclipse.openk.gridfailureinformation.model.TblFailureInformation
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mapping
;
import
org.mapstruct.Mappings
;
import
org.mapstruct.ReportingPolicy
;
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/FailureInformationMapper.java
View file @
29283b8e
...
...
@@ -51,7 +51,7 @@ public interface FailureInformationMapper {
@Mapping
(
target
=
"refBranch.name"
,
source
=
"branch"
),
@Mapping
(
target
=
"refBranch.colorCode"
,
source
=
"branchColorCode"
)
})
TblFailureInformation
toTblFailureInformation
(
FailureInformationDto
F
ailureInformationDto
);
TblFailureInformation
toTblFailureInformation
(
FailureInformationDto
f
ailureInformationDto
);
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/BranchRepository.java
View file @
29283b8e
...
...
@@ -18,7 +18,6 @@ package org.eclipse.openk.gridfailureinformation.repository;
import
org.eclipse.openk.gridfailureinformation.model.RefBranch
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.UUID
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureClassificationRepository.java
View file @
29283b8e
...
...
@@ -15,11 +15,9 @@
package
org.eclipse.openk.gridfailureinformation.repository
;
import
org.eclipse.openk.gridfailureinformation.model.RefBranch
;
import
org.eclipse.openk.gridfailureinformation.model.RefFailureClassification
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.UUID
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationRepository.java
View file @
29283b8e
...
...
@@ -18,7 +18,6 @@ package org.eclipse.openk.gridfailureinformation.repository;
import
org.eclipse.openk.gridfailureinformation.model.TblFailureInformation
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.Optional
;
import
java.util.UUID
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureTypeRepository.java
View file @
29283b8e
...
...
@@ -15,7 +15,6 @@
package
org.eclipse.openk.gridfailureinformation.repository
;
import
org.eclipse.openk.gridfailureinformation.model.RefBranch
;
import
org.eclipse.openk.gridfailureinformation.model.RefFailureType
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/StatusRepository.java
View file @
29283b8e
...
...
@@ -15,11 +15,9 @@
package
org.eclipse.openk.gridfailureinformation.repository
;
import
org.eclipse.openk.gridfailureinformation.model.RefBranch
;
import
org.eclipse.openk.gridfailureinformation.model.RefStatus
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.UUID
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/BranchService.java
View file @
29283b8e
...
...
@@ -14,22 +14,14 @@
*/
package
org.eclipse.openk.gridfailureinformation.service
;
import
org.eclipse.openk.gridfailureinformation.mapper.BranchMapper
;
import
org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapper
;
import
org.eclipse.openk.gridfailureinformation.repository.BranchRepository
;
import
org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
public
class
BranchService
{
...
...
gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/FailureInformationControllerTest.java
View file @
29283b8e
...
...
@@ -99,13 +99,15 @@ public class FailureInformationControllerTest {
.
andExpect
(
status
().
is2xxSuccessful
());
}
@Test
public
void
shouldNotUpdateFailureInformationDueToException
()
throws
Exception
{
FailureInformationDto
failureInfoDto
=
MockDataHelper
.
mockFailureInformationDto
();
when
(
failureInformationService
.
updateFailureInfo
(
any
(
FailureInformationDto
.
class
))).
thenReturn
(
failureInfoDto
);
// provide different
exception
in url and object
// provide different
UUID
in url and object
mockMvc
.
perform
(
put
(
"/grid-failure-informations/{failureInfoUuid}"
,
UUID
.
randomUUID
().
toString
())
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
new
ObjectMapper
().
writeValueAsString
(
failureInfoDto
)))
...
...
@@ -113,42 +115,42 @@ public class FailureInformationControllerTest {
}
//
@Test
//
public void shouldInsertFailureInformation() throws Exception {
//
FailureInformationDto failureInfoDto = MockDataHelper.mockFailureInformationDto();
//
//
when( failureInformationService.insertFailureInfo(any(FailureInformationDto.class))).thenReturn(failureInfoDto);
//
//
mockMvc.perform(post("/grid-failure-informations")
//
.contentType(MediaType.APPLICATION_JSON)
//
.content(new ObjectMapper().writeValueAsString(failureInfoDto)))
//
.andExpect(jsonPath("$.responsibility", is(failureInfoDto.getResponsibility())))
//
.andExpect(jsonPath("$.internExtern", is(failureInfoDto.getInternExtern())))
//
.andExpect(jsonPath("$.voltageLevel", is(failureInfoDto.getVoltageLevel())))
//
.andExpect(jsonPath("$.pressureLevel", is(failureInfoDto.getPressureLevel())))
//
.andExpect(jsonPath("$.failureBegin", is(failureInfoDto.getFailureBegin().toString())))
//
.andExpect(jsonPath("$.failureEndPlanned", is(failureInfoDto.getFailureEndPlanned().toString())))
//
.andExpect(jsonPath("$.failureEndResupplied", is(failureInfoDto.getFailureEndResupplied().toString())))
//
.andExpect(jsonPath("$.probableReason", is(failureInfoDto.getProbableReason())))
//
.andExpect(jsonPath("$.internalRemark", is(failureInfoDto.getInternalRemark())))
//
.andExpect(jsonPath("$.postcode", is(failureInfoDto.getPostcode())))
//
.andExpect(jsonPath("$.city", is(failureInfoDto.getCity())))
//
.andExpect(jsonPath("$.district", is(failureInfoDto.getDistrict())))
//
.andExpect(jsonPath("$.street", is(failureInfoDto.getStreet())))
//
.andExpect(jsonPath("$.housenumber", is(failureInfoDto.getHousenumber())))
//
.andExpect(jsonPath("$.stationDescription", is(failureInfoDto.getStationDescription())))
//
.andExpect(jsonPath("$.stationCoords", is(failureInfoDto.getStationCoords())))
//
.andExpect(jsonPath("$.radius", is(failureInfoDto.getRadius())))
//
.andExpect(jsonPath("$.failureClassificationId", is(failureInfoDto.getFailureClassificationId().toString())))
//
.andExpect(jsonPath("$.failureClassification", is(failureInfoDto.getFailureClassification())))
//
.andExpect(jsonPath("$.failureTypeId", is(failureInfoDto.getFailureTypeId().toString())))
//
.andExpect(jsonPath("$.statusInternId", is(failureInfoDto.getStatusInternId().toString())))
//
.andExpect(jsonPath("$.statusExternId", is(failureInfoDto.getStatusExternId().toString())))
//
.andExpect(jsonPath("$.branchId", is(failureInfoDto.getBranchId().toString())))
//
.andExpect(jsonPath("$.branch", is(failureInfoDto.getBranch())))
//
.andExpect(jsonPath("$.branchColorCode", is(failureInfoDto.getBranchColorCode())))
//
//
.andExpect(status().is2xxSuccessful());
//
}
@Test
public
void
shouldInsertFailureInformation
()
throws
Exception
{
FailureInformationDto
failureInfoDto
=
MockDataHelper
.
mockFailureInformationDto
();
when
(
failureInformationService
.
insertFailureInfo
(
any
(
FailureInformationDto
.
class
))).
thenReturn
(
failureInfoDto
);
mockMvc
.
perform
(
post
(
"/grid-failure-informations"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
new
ObjectMapper
().
writeValueAsString
(
failureInfoDto
)))
.
andExpect
(
jsonPath
(
"$.responsibility"
,
is
(
failureInfoDto
.
getResponsibility
())))
.
andExpect
(
jsonPath
(
"$.internExtern"
,
is
(
failureInfoDto
.
getInternExtern
())))
.
andExpect
(
jsonPath
(
"$.voltageLevel"
,
is
(
failureInfoDto
.
getVoltageLevel
())))
.
andExpect
(
jsonPath
(
"$.pressureLevel"
,
is
(
failureInfoDto
.
getPressureLevel
())))
//
.andExpect(jsonPath("$.failureBegin", is(failureInfoDto.getFailureBegin().toString())))
//
.andExpect(jsonPath("$.failureEndPlanned", is(failureInfoDto.getFailureEndPlanned().toString())))
//
.andExpect(jsonPath("$.failureEndResupplied", is(failureInfoDto.getFailureEndResupplied().toString())))
.
andExpect
(
jsonPath
(
"$.probableReason"
,
is
(
failureInfoDto
.
getProbableReason
())))
.
andExpect
(
jsonPath
(
"$.internalRemark"
,
is
(
failureInfoDto
.
getInternalRemark
())))
.
andExpect
(
jsonPath
(
"$.postcode"
,
is
(
failureInfoDto
.
getPostcode
())))
.
andExpect
(
jsonPath
(
"$.city"
,
is
(
failureInfoDto
.
getCity
())))
.
andExpect
(
jsonPath
(
"$.district"
,
is
(
failureInfoDto
.
getDistrict
())))
.
andExpect
(
jsonPath
(
"$.street"
,
is
(
failureInfoDto
.
getStreet
())))
.
andExpect
(
jsonPath
(
"$.housenumber"
,
is
(
failureInfoDto
.
getHousenumber
())))
.
andExpect
(
jsonPath
(
"$.stationDescription"
,
is
(
failureInfoDto
.
getStationDescription
())))
.
andExpect
(
jsonPath
(
"$.stationCoords"
,
is
(
failureInfoDto
.
getStationCoords
())))
.
andExpect
(
jsonPath
(
"$.radius"
,
is
(
failureInfoDto
.
getRadius
())))
.
andExpect
(
jsonPath
(
"$.failureClassificationId"
,
is
(
failureInfoDto
.
getFailureClassificationId
().
toString
())))
.
andExpect
(
jsonPath
(
"$.failureClassification"
,
is
(
failureInfoDto
.
getFailureClassification
())))
.
andExpect
(
jsonPath
(
"$.failureTypeId"
,
is
(
failureInfoDto
.
getFailureTypeId
().
toString
())))
.
andExpect
(
jsonPath
(
"$.statusInternId"
,
is
(
failureInfoDto
.
getStatusInternId
().
toString
())))
.
andExpect
(
jsonPath
(
"$.statusExternId"
,
is
(
failureInfoDto
.
getStatusExternId
().
toString
())))
.
andExpect
(
jsonPath
(
"$.branchId"
,
is
(
failureInfoDto
.
getBranchId
().
toString
())))
.
andExpect
(
jsonPath
(
"$.branch"
,
is
(
failureInfoDto
.
getBranch
())))
.
andExpect
(
jsonPath
(
"$.branchColorCode"
,
is
(
failureInfoDto
.
getBranchColorCode
())))
.
andExpect
(
status
().
is2xxSuccessful
());
}
}
\ No newline at end of file
gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationServiceTest.java
View file @
29283b8e
...
...
@@ -29,10 +29,8 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.test.context.ContextConfiguration
;
import
java.util.Optional
;
import
java.util.UUID
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
...
...
@@ -137,6 +135,47 @@ public class FailureInformationServiceTest {
}
@Test
public
void
shouldUpdateFailureInformation_emptyReferences
()
{
FailureInformationDto
fiDto
=
MockDataHelper
.
mockFailureInformationDto
();
fiDto
.
setBranchId
(
null
);
fiDto
.
setFailureClassificationId
(
null
);
fiDto
.
setFailureTypeId
(
null
);
fiDto
.
setStatusExternId
(
null
);
fiDto
.
setStatusInternId
(
null
);
TblFailureInformation
fiTbl
=
MockDataHelper
.
mockTblFailureInformation
();
fiTbl
.
setRefBranch
(
null
);
fiTbl
.
setRefFailureClassification
(
null
);
fiTbl
.
setRefFailureType
(
null
);
fiTbl
.
setRefStatusExtern
(
null
);
fiTbl
.
setRefStatusIntern
(
null
);
when
(
failureInformationRepository
.
findByUuid
(
any
(
UUID
.
class
))).
thenReturn
(
Optional
.
of
(
fiTbl
));
when
(
failureInformationRepository
.
save
(
any
(
TblFailureInformation
.
class
))).
thenReturn
(
fiTbl
);
FailureInformationDto
savedDto
=
failureInformationService
.
updateFailureInfo
(
fiDto
);
assertEquals
(
fiTbl
.
getUuid
(),
savedDto
.
getUuid
());
assertEquals
(
fiTbl
.
getResponsibility
(),
savedDto
.
getResponsibility
());
assertEquals
(
fiTbl
.
getInternExtern
(),
savedDto
.
getInternExtern
());
assertEquals
(
fiTbl
.
getVoltageLevel
(),
savedDto
.
getVoltageLevel
());
assertEquals
(
fiTbl
.
getPressureLevel
(),
savedDto
.
getPressureLevel
());
assertEquals
(
fiTbl
.
getFailureBegin
(),
savedDto
.
getFailureBegin
());
assertEquals
(
fiTbl
.
getFailureEndPlanned
(),
savedDto
.
getFailureEndPlanned
());
assertEquals
(
fiTbl
.
getFailureEndResupplied
(),
savedDto
.
getFailureEndResupplied
());
assertEquals
(
fiTbl
.
getProbableReason
(),
savedDto
.
getProbableReason
());
assertEquals
(
fiTbl
.
getInternalRemark
(),
savedDto
.
getInternalRemark
());
assertEquals
(
fiTbl
.
getPostcode
(),
savedDto
.
getPostcode
());
assertEquals
(
fiTbl
.
getCity
(),
savedDto
.
getCity
());
assertEquals
(
fiTbl
.
getDistrict
(),
savedDto
.
getDistrict
());
assertEquals
(
fiTbl
.
getStreet
(),
savedDto
.
getStreet
());
assertEquals
(
fiTbl
.
getHousenumber
(),
savedDto
.
getHousenumber
());
assertEquals
(
fiTbl
.
getStationDescription
(),
savedDto
.
getStationDescription
());
assertEquals
(
fiTbl
.
getStationCoords
(),
savedDto
.
getStationCoords
());
assertEquals
(
fiTbl
.
getRadius
(),
savedDto
.
getRadius
());
}
@Test
public
void
shouldNotUpdateFailureInformation_Exception_FailureInformationNotFound
()
{
FailureInformationDto
fiDto
=
MockDataHelper
.
mockFailureInformationDto
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment