Skip to content
GitLab
Menu
Projects
Groups
Snippets
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
29bab923
Commit
29bab923
authored
Feb 27, 2020
by
Ina Curdt
Browse files
SI-127
parents
641dd156
31ba4eff
Changes
20
Expand all
Hide whitespace changes
Inline
Side-by-side
gfsBackendService/Dockerfile
deleted
100644 → 0
View file @
641dd156
FROM
openjdk:8-jre-alpine
COPY
/target/contact-base-data.jar /usr/src/cbd/
WORKDIR
usr/src/cbd
CMD
["java", "-jar", "-Dspring.config.name=application_localdev", "contact-base-data.jar"]
\ No newline at end of file
gfsBackendService/Dockerfile_DevServerUnsecure
View file @
29bab923
FROM openjdk:8-jre-alpine
COPY /target/
contact-base-data
.jar /usr/src/cbd/
COPY /target/
grid-failure-Information.backend.service
.jar /usr/src/cbd/
WORKDIR usr/src/cbd
CMD ["java", "-jar", "-Dspring.profiles.active=devserver-unsecure", "contact-base-data.jar"]
\ No newline at end of file
CMD ["java", "-jar", "-Dspring.profiles.active=devserver-unsecure", "grid-failure-Information.backend.service.jar"]
\ No newline at end of file
gfsBackendService/grid-failure-info.log
View file @
29bab923
This diff is collapsed.
Click to expand it.
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/constants/Constants.java
View file @
29bab923
...
...
@@ -15,9 +15,20 @@
package
org.eclipse.openk.gridfailureinformation.constants
;
public
final
class
Constants
{
public
static
final
String
VOLTAGE_LEVEL_NS
=
"NS"
;
public
static
final
String
VOLTAGE_LEVEL_MS
=
"MS"
;
public
static
final
String
VOLTAGE_LEVEL_HS
=
"HS"
;
public
static
final
String
PRESSURE_LEVEL_ND
=
"ND"
;
public
static
final
String
PRESSURE_LEVEL_MD
=
"MD"
;
public
static
final
String
PRESSURE_LEVEL_HD
=
"HD"
;
public
static
final
String
DB_VERSION_NOT_PRESENT
=
"DB-Version-not_present"
;
public
static
final
String
INTERNAL_SHORT
=
"I"
;
public
static
final
String
EXTERNAL_SHORT
=
"E"
;
private
Constants
()
{
// empty Constructor for the sake of SONAR
}
public
static
final
String
DB_VERSION_NOT_PRESENT
=
"DB-Version-not_present"
;
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/BranchController.java
View file @
29bab923
...
...
@@ -19,9 +19,9 @@ 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.
Grid
FailureInformationService
;
import
org.eclipse.openk.gridfailureinformation.service.FailureInformationService
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.
Grid
FailureInformationDto
;
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
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/
Grid
FailureInformationController.java
→
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/FailureInformationController.java
View file @
29bab923
...
...
@@ -18,8 +18,9 @@ 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.GridFailureInformationService
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto
;
import
org.eclipse.openk.gridfailureinformation.exceptions.BadRequestException
;
import
org.eclipse.openk.gridfailureinformation.service.FailureInformationService
;
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
;
...
...
@@ -36,19 +37,19 @@ import java.util.UUID;
@Log4j2
@RestController
@RequestMapping
(
"/grid-failure-informations"
)
public
class
Grid
FailureInformationController
{
public
class
FailureInformationController
{
@Value
(
"${gridFailureInformation.maxListSize}"
)
int
maxListSize
;
@Autowired
private
Grid
FailureInformationService
gridF
ailureInformationService
;
private
FailureInformationService
f
ailureInformationService
;
@ApiOperation
(
value
=
"Anzeigen aller Störungsinformationen"
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Erfolgreich durchgeführt"
)})
@GetMapping
public
List
<
Grid
FailureInformationDto
>
findFailureInfos
()
{
return
gridF
ailureInformationService
.
findFailureInformations
(
PageRequest
.
of
(
0
,
maxListSize
)).
getContent
();
public
List
<
FailureInformationDto
>
findFailureInfos
()
{
return
f
ailureInformationService
.
findFailureInformations
(
PageRequest
.
of
(
0
,
maxListSize
)).
getContent
();
}
@PostMapping
...
...
@@ -57,9 +58,9 @@ public class GridFailureInformationController {
@ApiResponse
(
code
=
201
,
message
=
"Störungsinformation erfolgreich angelegt"
),
@ApiResponse
(
code
=
500
,
message
=
"Konnte nicht durchgeführt werden"
)
})
public
ResponseEntity
<
Grid
FailureInformationDto
>
insertFailureInfo
(
@Validated
@RequestBody
Grid
FailureInformationDto
gfDto
)
{
Grid
FailureInformationDto
savedgfDto
=
gridF
ailureInformationService
.
insert
Grid
Failure
(
gfDto
);
public
ResponseEntity
<
FailureInformationDto
>
insertFailureInfo
(
@Validated
@RequestBody
FailureInformationDto
gfDto
)
{
FailureInformationDto
savedgfDto
=
f
ailureInformationService
.
insertFailure
Info
(
gfDto
);
URI
location
=
ServletUriComponentsBuilder
.
fromCurrentRequestUri
()
.
path
(
"/{uuid}"
)
...
...
@@ -68,22 +69,21 @@ public class GridFailureInformationController {
return
ResponseEntity
.
created
(
location
).
body
(
savedgfDto
);
}
// @PutMapping("/{contactUuid}")
// @Secured({"ROLE_KON-ADMIN", "ROLE_KON-WRITER"})
// @ApiOperation(value = "Ändern einer externen Person")
// @ApiResponses(value = {
// @ApiResponse(code = 200, message = "Firma wurde aktualisiert"),
// @ApiResponse(code = 400, message = "Ungültige Eingabe"),
// @ApiResponse(code = 404, message = "Nicht gefunden")})
// public ResponseEntity updateCompany(@PathVariable UUID contactUuid, @Validated @RequestBody CompanyDto companyDto) {
//
// if (!companyDto.getContactUuid().equals(contactUuid)) {
// throw new BadRequestException("invalid.uuid.path.object");
// }
//
// companyService.updateCompany(companyDto);
// return ResponseEntity.ok().build();
// }
@PutMapping
(
"/{failureInfoUuid}"
)
@ApiOperation
(
value
=
"Ändern einer Störungsinformation"
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Störungsinformation wurde aktualisiert"
),
@ApiResponse
(
code
=
400
,
message
=
"Ungültige Eingabe"
),
@ApiResponse
(
code
=
404
,
message
=
"Nicht gefunden"
)})
public
ResponseEntity
updateFailureInfo
(
@PathVariable
UUID
failureInfoUuid
,
@Validated
@RequestBody
FailureInformationDto
failureInfoDto
)
{
if
(!
failureInfoDto
.
getUuid
().
equals
(
failureInfoUuid
))
{
throw
new
BadRequestException
(
"invalid.uuid.path.object"
);
}
failureInformationService
.
updateFailureInfo
(
failureInfoDto
);
return
ResponseEntity
.
ok
().
build
();
}
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/BranchMapper.java
View file @
29bab923
...
...
@@ -17,7 +17,7 @@ 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.
Grid
FailureInformationDto
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mapping
;
import
org.mapstruct.Mappings
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/GridFailureInformationMapper.java
View file @
29bab923
...
...
@@ -15,7 +15,7 @@
package
org.eclipse.openk.gridfailureinformation.mapper
;
import
org.eclipse.openk.gridfailureinformation.model.TblFailureInformation
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.
Grid
FailureInformationDto
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mapping
;
import
org.mapstruct.Mappings
;
...
...
@@ -36,7 +36,7 @@ public interface GridFailureInformationMapper {
@Mapping
(
source
=
"refBranch.name"
,
target
=
"branch"
),
@Mapping
(
source
=
"refBranch.colorCode"
,
target
=
"branchColorCode"
)
})
Grid
FailureInformationDto
to
Grid
FailureInformationDto
(
TblFailureInformation
tblFailureInformation
);
FailureInformationDto
toFailureInformationDto
(
TblFailureInformation
tblFailureInformation
);
@Mappings
({
@Mapping
(
target
=
"refFailureClassification.uuid"
,
source
=
"failureClassificationId"
),
...
...
@@ -51,7 +51,7 @@ public interface GridFailureInformationMapper {
@Mapping
(
target
=
"refBranch.name"
,
source
=
"branch"
),
@Mapping
(
target
=
"refBranch.colorCode"
,
source
=
"branchColorCode"
)
})
TblFailureInformation
to
Ref
FailureInformation
(
Grid
FailureInformationDto
grid
FailureInformationDto
);
TblFailureInformation
to
Tbl
FailureInformation
(
FailureInformationDto
FailureInformationDto
);
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationRepository.java
View file @
29bab923
...
...
@@ -19,8 +19,11 @@ 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
;
@Repository
public
interface
FailureInformationRepository
extends
JpaRepository
<
TblFailureInformation
,
Long
>
{
Optional
<
TblFailureInformation
>
findByUuid
(
UUID
uuid
);
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/BranchService.java
View file @
29bab923
...
...
@@ -20,7 +20,7 @@ import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMap
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.
Grid
FailureInformationDto
;
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
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/
Grid
FailureInformationService.java
→
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java
View file @
29bab923
...
...
@@ -19,7 +19,7 @@ import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import
org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMapper
;
import
org.eclipse.openk.gridfailureinformation.model.TblFailureInformation
;
import
org.eclipse.openk.gridfailureinformation.repository.*
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.
Grid
FailureInformationDto
;
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
;
...
...
@@ -30,7 +30,7 @@ import java.util.UUID;
@Service
public
class
Grid
FailureInformationService
{
public
class
FailureInformationService
{
@Autowired
private
FailureInformationRepository
failureInformationRepository
;
...
...
@@ -51,18 +51,32 @@ public class GridFailureInformationService {
private
GridFailureInformationMapper
gridFailureInformationMapper
;
public
Page
<
Grid
FailureInformationDto
>
findFailureInformations
(
Pageable
pageable
)
{
return
failureInformationRepository
.
findAll
(
pageable
).
map
(
gridFailureInformationMapper:
:
to
Grid
FailureInformationDto
);
public
Page
<
FailureInformationDto
>
findFailureInformations
(
Pageable
pageable
)
{
return
failureInformationRepository
.
findAll
(
pageable
).
map
(
gridFailureInformationMapper:
:
toFailureInformationDto
);
}
public
Grid
FailureInformationDto
insert
Grid
Failure
(
Grid
FailureInformationDto
gfi
Dto
){
TblFailureInformation
tbl
Gfi
ToSave
=
gridFailureInformationMapper
.
to
Ref
FailureInformation
(
gfi
Dto
);
tbl
Gfi
ToSave
.
setUuid
(
UUID
.
randomUUID
());
setFromGridFailureInformationDto
(
tbl
GfiToSave
,
gfi
Dto
);
return
gridFailureInformationMapper
.
to
Grid
FailureInformationDto
(
failureInformationRepository
.
save
(
tbl
Gfi
ToSave
));
public
FailureInformationDto
insertFailure
Info
(
FailureInformationDto
failureInfo
Dto
){
TblFailureInformation
tbl
FailureInformation
ToSave
=
gridFailureInformationMapper
.
to
Tbl
FailureInformation
(
failureInfo
Dto
);
tbl
FailureInformation
ToSave
.
setUuid
(
UUID
.
randomUUID
());
setFromGridFailureInformationDto
(
tbl
FailureInformationToSave
,
failureInfo
Dto
);
return
gridFailureInformationMapper
.
toFailureInformationDto
(
failureInformationRepository
.
save
(
tbl
FailureInformation
ToSave
));
}
private
void
setFromGridFailureInformationDto
(
TblFailureInformation
destTblFailureInformation
,
GridFailureInformationDto
sourceDto
)
{
public
FailureInformationDto
updateFailureInfo
(
FailureInformationDto
failureInfoDto
)
{
TblFailureInformation
tblFailureInformation
=
failureInformationRepository
.
findByUuid
(
failureInfoDto
.
getUuid
())
.
orElseThrow
(()
->
new
NotFoundException
(
"failure.info.uuid.not.existing"
));
TblFailureInformation
tblFailureInformationToSave
=
gridFailureInformationMapper
.
toTblFailureInformation
(
failureInfoDto
);
tblFailureInformationToSave
.
setId
(
tblFailureInformation
.
getId
());
setFromGridFailureInformationDto
(
tblFailureInformationToSave
,
failureInfoDto
);
TblFailureInformation
savedFailureInformation
=
failureInformationRepository
.
save
(
tblFailureInformationToSave
);
return
gridFailureInformationMapper
.
toFailureInformationDto
(
savedFailureInformation
);
}
private
void
setFromGridFailureInformationDto
(
TblFailureInformation
destTblFailureInformation
,
FailureInformationDto
sourceDto
)
{
if
(
sourceDto
.
getBranchId
()
!=
null
)
{
destTblFailureInformation
.
setRefBranch
(
branchRepository
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/FailureClassificationDto.java
0 → 100644
View file @
29bab923
/*
*******************************************************************************
* 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.viewmodel
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.UUID
;
@Data
public
class
FailureClassificationDto
implements
Serializable
{
@JsonProperty
(
"id"
)
private
UUID
uuid
;
private
String
classification
;
private
String
description
;
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/
Grid
FailureInformationDto.java
→
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/FailureInformationDto.java
View file @
29bab923
...
...
@@ -22,7 +22,7 @@ import java.util.Date;
import
java.util.UUID
;
@Data
public
class
Grid
FailureInformationDto
implements
Serializable
{
public
class
FailureInformationDto
implements
Serializable
{
@JsonProperty
(
"id"
)
private
UUID
uuid
;
private
String
responsibility
;
...
...
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/FailureTypeDto.java
0 → 100644
View file @
29bab923
/*
*******************************************************************************
* 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.viewmodel
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.UUID
;
@Data
public
class
FailureTypeDto
implements
Serializable
{
@JsonProperty
(
"id"
)
private
UUID
uuid
;
private
String
type
;
private
String
description
;
}
gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/StatusDto.java
0 → 100644
View file @
29bab923
/*
*******************************************************************************
* 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.viewmodel
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.UUID
;
@Data
public
class
StatusDto
implements
Serializable
{
@JsonProperty
(
"id"
)
private
UUID
uuid
;
private
String
status
;
private
boolean
isInternal
;
private
boolean
isExternal
;
}
gfsBackendService/src/main/resources/messages.properties
View file @
29bab923
...
...
@@ -4,5 +4,6 @@ branch.uuid.not.existing=Die \u00fcbergebene UUID einer Branche existiert nicht.
failure.classification.uuid.not.existing
=
Die
\u
00fcbergebene UUID einer Fehlerklassifizierung existiert nicht.
failure.type.uuid.not.existing
=
Die
\u
00fcbergebene UUID eines Fehlertyps existiert nicht.
status.uuid.not.existing
=
Die
\u
00fcbergebene UUID eines Status existiert nicht.
failure.info.uuid.not.existing
=
Die
\u
00fcbergebene UUID einer Störungsmeldung existiert nicht.
gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java
View file @
29bab923
...
...
@@ -17,7 +17,7 @@ package org.eclipse.openk.gridfailureinformation.config;
import
org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication
;
import
org.eclipse.openk.gridfailureinformation.mapper.*
;
import
org.eclipse.openk.gridfailureinformation.service.BranchService
;
import
org.eclipse.openk.gridfailureinformation.service.
Grid
FailureInformationService
;
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.test.context.ConfigFileApplicationContextInitializer
;
...
...
@@ -46,13 +46,13 @@ public class TestConfiguration {
}
@Bean
public
BranchService
myBranch
Service
()
{
return
new
Branch
Service
();
public
FailureInformationService
myGridFailureInformation
Service
()
{
return
new
FailureInformation
Service
();
}
@Bean
public
GridFailureInformationService
myGridFailureInformation
Service
()
{
return
new
GridFailureInformation
Service
();
public
BranchService
myBranch
Service
()
{
return
new
Branch
Service
();
}
}
gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/FailureInformationControllerTest.java
0 → 100644
View file @
29bab923
/*
*******************************************************************************
* 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
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication
;
import
org.eclipse.openk.gridfailureinformation.model.TblFailureInformation
;
import
org.eclipse.openk.gridfailureinformation.service.FailureInformationService
;
import
org.eclipse.openk.gridfailureinformation.support.MockDataHelper
;
import
org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto
;
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.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
java.util.Date
;
import
java.util.UUID
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
when
;
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
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
@SpringBootTest
(
classes
=
GridFailureInformationApplication
.
class
)
@AutoConfigureMockMvc
public
class
FailureInformationControllerTest
{
@MockBean
private
FailureInformationService
failureInformationService
;
@Autowired
private
MockMvc
mockMvc
;
@Test
public
void
shouldFindFailureInfos
()
throws
Exception
{
Page
<
FailureInformationDto
>
page
=
MockDataHelper
.
mpckGridFailureInformationDtoPage
();
when
(
failureInformationService
.
findFailureInformations
(
any
(
Pageable
.
class
))).
thenReturn
(
page
);
mockMvc
.
perform
(
get
(
"/grid-failure-informations"
))
.
andExpect
(
status
().
is2xxSuccessful
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
));
}
@Test
public
void
shouldUpdateFailureInformation
()
throws
Exception
{
FailureInformationDto
failureInfoDto
=
MockDataHelper
.
mockFailureInformationDto
();
when
(
failureInformationService
.
updateFailureInfo
(
any
(
FailureInformationDto
.
class
))).
thenReturn
(
failureInfoDto
);
mockMvc
.
perform
(
put
(
"/grid-failure-informations/{failureInfoUuid}"
,
failureInfoDto
.
getUuid
().
toString
())
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
new
ObjectMapper
().
writeValueAsString
(
failureInfoDto
)))
.
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
mockMvc
.
perform
(
put
(
"/grid-failure-informations/{failureInfoUuid}"
,
UUID
.
randomUUID
().
toString
())
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
new
ObjectMapper
().
writeValueAsString
(
failureInfoDto
)))
.
andExpect
(
status
().
isBadRequest
());
}
@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
0 → 100644
View file @
29bab923
/*
*******************************************************************************
* 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.
*