Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
naming-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Harrisson
naming-backend
Commits
95c1d745
Commit
95c1d745
authored
2 years ago
by
Lars Johansson
Browse files
Options
Downloads
Patches
Plain Diff
Remove unused exceptions
parent
b647ee8c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/openepics/names/util/ExceptionUtil.java
+0
-112
0 additions, 112 deletions
src/main/java/org/openepics/names/util/ExceptionUtil.java
src/test/java/org/openepics/names/util/ExceptionUtilTest.java
+0
-47
0 additions, 47 deletions
...test/java/org/openepics/names/util/ExceptionUtilTest.java
with
0 additions
and
159 deletions
src/main/java/org/openepics/names/util/ExceptionUtil.java
+
0
−
112
View file @
95c1d745
...
@@ -19,7 +19,6 @@
...
@@ -19,7 +19,6 @@
package
org.openepics.names.util
;
package
org.openepics.names.util
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.server.ResponseStatusException
;
/**
/**
* Utility class to assist in handling of exceptions.
* Utility class to assist in handling of exceptions.
...
@@ -49,117 +48,6 @@ public class ExceptionUtil {
...
@@ -49,117 +48,6 @@ public class ExceptionUtil {
throw
new
IllegalStateException
(
"Utility class"
);
throw
new
IllegalStateException
(
"Utility class"
);
}
}
/**
* Convert service http status exception to response status exception.
*
* @param e service http status exception
* @return response status exception
*/
public
static
ResponseStatusException
convertException
(
ServiceHttpStatusException
e
)
{
switch
(
e
.
getHttpStatus
())
{
case
BAD_REQUEST:
throw
ExceptionUtil
.
createResponseStatusExceptionBadRequest
();
case
UNAUTHORIZED:
throw
ExceptionUtil
.
createResponseStatusExceptionUnauthorized
();
case
FORBIDDEN:
throw
ExceptionUtil
.
createResponseStatusExceptionForbidden
();
case
NOT_FOUND:
throw
ExceptionUtil
.
createResponseStatusExceptionNotFound
();
case
CONFLICT:
throw
ExceptionUtil
.
createResponseStatusExceptionConflict
();
case
INTERNAL_SERVER_ERROR:
throw
ExceptionUtil
.
createResponseStatusExceptionInternalServerError
();
case
NOT_IMPLEMENTED:
throw
ExceptionUtil
.
createResponseStatusExceptionNotImplemented
();
default
:
throw
ExceptionUtil
.
createResponseStatusExceptionInternalServerError
();
}
}
/**
* Create response status exception.
* Intended for communication from server to client.
*
* @param status http status
* @param reason reason
* @param cause cause
* @return response status exception
*/
protected
static
ResponseStatusException
createResponseStatusException
(
HttpStatus
status
,
String
reason
,
Throwable
cause
)
{
return
new
ResponseStatusException
(
status
,
reason
,
cause
);
}
/**
* Create response status exception for {@link HttpStatus#BAD_REQUEST}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected
static
ResponseStatusException
createResponseStatusExceptionBadRequest
()
{
return
createResponseStatusException
(
HttpStatus
.
BAD_REQUEST
,
OPERATION_COULD_NOT_BE_PERFORMED
,
null
);
}
/**
* Create response status exception for {@link HttpStatus#UNAUTHORIZED}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected
static
ResponseStatusException
createResponseStatusExceptionUnauthorized
()
{
return
createResponseStatusException
(
HttpStatus
.
UNAUTHORIZED
,
OPERATION_COULD_NOT_BE_PERFORMED
,
null
);
}
/**
* Create response status exception for {@link HttpStatus#FORBIDDEN}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected
static
ResponseStatusException
createResponseStatusExceptionForbidden
()
{
return
createResponseStatusException
(
HttpStatus
.
FORBIDDEN
,
OPERATION_COULD_NOT_BE_PERFORMED
,
null
);
}
/**
* Create response status exception for {@link HttpStatus#NOT_FOUND}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected
static
ResponseStatusException
createResponseStatusExceptionNotFound
()
{
return
createResponseStatusException
(
HttpStatus
.
NOT_FOUND
,
OPERATION_COULD_NOT_BE_PERFORMED
,
null
);
}
/**
* Create response status exception for {@link HttpStatus#CONFLICT}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected
static
ResponseStatusException
createResponseStatusExceptionConflict
()
{
return
createResponseStatusException
(
HttpStatus
.
CONFLICT
,
OPERATION_COULD_NOT_BE_PERFORMED
,
null
);
}
/**
* Create response status exception for {@link HttpStatus#INTERNAL_SERVER_ERROR}.
* Intended for communication from server to client.
*
* @return response status exception
*/
public
static
ResponseStatusException
createResponseStatusExceptionInternalServerError
()
{
return
createResponseStatusException
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
OPERATION_COULD_NOT_BE_PERFORMED
,
null
);
}
/**
* Create response status exception for {@link HttpStatus#NOT_IMPLEMENTED}.
* Intended for communication from server to client.
*
* @return response status exception
*/
public
static
ResponseStatusException
createResponseStatusExceptionNotImplemented
()
{
return
createResponseStatusException
(
HttpStatus
.
NOT_IMPLEMENTED
,
OPERATION_COULD_NOT_BE_PERFORMED
,
null
);
}
/**
/**
* Create service http status exception.
* Create service http status exception.
* Intended for communication inside server.
* Intended for communication inside server.
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/openepics/names/util/ExceptionUtilTest.java
+
0
−
47
View file @
95c1d745
...
@@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
...
@@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.server.ResponseStatusException
;
/**
/**
* Unit tests for ExceptionUtil class.
* Unit tests for ExceptionUtil class.
...
@@ -34,52 +33,6 @@ import org.springframework.web.server.ResponseStatusException;
...
@@ -34,52 +33,6 @@ import org.springframework.web.server.ResponseStatusException;
*/
*/
public
class
ExceptionUtilTest
{
public
class
ExceptionUtilTest
{
/**
* Test of create response status exception.
*/
@Test
public
void
createResponseStatusException
()
{
ResponseStatusException
exception
=
ExceptionUtil
.
createResponseStatusException
(
HttpStatus
.
I_AM_A_TEAPOT
,
null
,
null
);
assertEquals
(
HttpStatus
.
I_AM_A_TEAPOT
,
exception
.
getStatus
());
assertNull
(
exception
.
getReason
());
assertNull
(
exception
.
getCause
());
exception
=
ExceptionUtil
.
createResponseStatusExceptionBadRequest
();
assertEquals
(
HttpStatus
.
BAD_REQUEST
,
exception
.
getStatus
());
assertEquals
(
ExceptionUtil
.
OPERATION_COULD_NOT_BE_PERFORMED
,
exception
.
getReason
());
assertEquals
(
null
,
exception
.
getCause
());
exception
=
ExceptionUtil
.
createResponseStatusExceptionUnauthorized
();
assertEquals
(
HttpStatus
.
UNAUTHORIZED
,
exception
.
getStatus
());
assertEquals
(
ExceptionUtil
.
OPERATION_COULD_NOT_BE_PERFORMED
,
exception
.
getReason
());
assertEquals
(
null
,
exception
.
getCause
());
exception
=
ExceptionUtil
.
createResponseStatusExceptionForbidden
();
assertEquals
(
HttpStatus
.
FORBIDDEN
,
exception
.
getStatus
());
assertEquals
(
ExceptionUtil
.
OPERATION_COULD_NOT_BE_PERFORMED
,
exception
.
getReason
());
assertEquals
(
null
,
exception
.
getCause
());
exception
=
ExceptionUtil
.
createResponseStatusExceptionNotFound
();
assertEquals
(
HttpStatus
.
NOT_FOUND
,
exception
.
getStatus
());
assertEquals
(
ExceptionUtil
.
OPERATION_COULD_NOT_BE_PERFORMED
,
exception
.
getReason
());
assertEquals
(
null
,
exception
.
getCause
());
exception
=
ExceptionUtil
.
createResponseStatusExceptionConflict
();
assertEquals
(
HttpStatus
.
CONFLICT
,
exception
.
getStatus
());
assertEquals
(
ExceptionUtil
.
OPERATION_COULD_NOT_BE_PERFORMED
,
exception
.
getReason
());
assertEquals
(
null
,
exception
.
getCause
());
exception
=
ExceptionUtil
.
createResponseStatusExceptionInternalServerError
();
assertEquals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
exception
.
getStatus
());
assertEquals
(
ExceptionUtil
.
OPERATION_COULD_NOT_BE_PERFORMED
,
exception
.
getReason
());
assertEquals
(
null
,
exception
.
getCause
());
exception
=
ExceptionUtil
.
createResponseStatusExceptionNotImplemented
();
assertEquals
(
HttpStatus
.
NOT_IMPLEMENTED
,
exception
.
getStatus
());
assertEquals
(
ExceptionUtil
.
OPERATION_COULD_NOT_BE_PERFORMED
,
exception
.
getReason
());
assertEquals
(
null
,
exception
.
getCause
());
}
/**
/**
* Test of create service http status exception.
* Test of create service http status exception.
*/
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment