diff options
author | Sotiropoulos, Ioannis (is948x) <Ioannis.Sotiropoulos@amdocs.com> | 2018-07-10 17:57:43 +0100 |
---|---|---|
committer | Sotiropoulos, Ioannis (is948x) <Ioannis.Sotiropoulos@amdocs.com> | 2018-07-10 17:57:43 +0100 |
commit | d5322dbd0fa1e32d543b24824a28d6bf0a0b5497 (patch) | |
tree | 3fd9c7c2ce924395346601490e96327e47928afc /src/main/java/org/onap | |
parent | 600ca7e0b82c6932caa4f4ffb53e6c053525d9d5 (diff) |
Increase code coverage
Add tests to increase code coverage above 60 percent.
Issue-ID: AAI-1198
Change-Id: I4c2f964ce41d01521cc1313e32e34fb6460d49bf
Signed-off-by: Sotiropoulos, Ioannis (is948x) <Ioannis.Sotiropoulos@amdocs.com>
Diffstat (limited to 'src/main/java/org/onap')
5 files changed, 24 insertions, 49 deletions
diff --git a/src/main/java/org/onap/crud/dao/DataRouterDAO.java b/src/main/java/org/onap/crud/dao/DataRouterDAO.java index c0cf7c1..e5b6d5a 100644 --- a/src/main/java/org/onap/crud/dao/DataRouterDAO.java +++ b/src/main/java/org/onap/crud/dao/DataRouterDAO.java @@ -21,16 +21,12 @@ package org.onap.crud.dao; import org.eclipse.jetty.util.security.Password; -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.restclient.client.RestClient; import org.onap.aai.restclient.enums.RestAuthenticationMode; import org.onap.crud.dao.champ.ChampDao; import org.onap.crud.util.CrudServiceConstants; public class DataRouterDAO extends ChampDao { - private Logger logger = LoggerFactory.getInstance().getLogger(DataRouterDAO.class.getName()); - public DataRouterDAO(String url, String certPassword) { try { client = new RestClient().authenticationMode(RestAuthenticationMode.SSL_CERT).validateServerHostname(false) diff --git a/src/main/java/org/onap/crud/dao/champ/ChampDao.java b/src/main/java/org/onap/crud/dao/champ/ChampDao.java index 7bd4754..6817ea6 100644 --- a/src/main/java/org/onap/crud/dao/champ/ChampDao.java +++ b/src/main/java/org/onap/crud/dao/champ/ChampDao.java @@ -33,8 +33,6 @@ import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.message.BasicNameValuePair; import org.eclipse.jetty.util.security.Password; -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.cl.mdc.MdcContext; import org.onap.aai.logging.LoggingContext; import org.onap.aai.restclient.client.OperationResult; @@ -64,8 +62,6 @@ public class ChampDao implements GraphDao { protected static final String RELATIONSHIP_SUB_URL = "relationships"; protected static final String TRANSACTION_SUB_URL = "transaction"; - private Logger logger = LoggerFactory.getInstance().getLogger(ChampDao.class.getName()); - // We use a custom vertex serializer for champ because it expects "key" // instead of "id" protected static final Gson champGson = new GsonBuilder() @@ -209,7 +205,7 @@ public class ChampDao implements GraphDao { if (!edge.getType().equalsIgnoreCase(type)) { // We didn't find an edge with the supplied type, so just throw an // exception. - throw new CrudException("No edge with id " + id + "and type " + type + " found in graph", + throw new CrudException("No edge with id " + id + " and type " + type + " found in graph", javax.ws.rs.core.Response.Status.NOT_FOUND); } return getResult; @@ -537,7 +533,7 @@ public class ChampDao implements GraphDao { if (!edge.getType().equalsIgnoreCase(type)) { // We didn't find an edge with the supplied type, so just throw an // exception. - throw new CrudException("No edge with id " + id + "and type " + type + " found in graph", + throw new CrudException("No edge with id " + id + " and type " + type + " found in graph", javax.ws.rs.core.Response.Status.NOT_FOUND); } return edge; @@ -558,7 +554,7 @@ public class ChampDao implements GraphDao { if (!vert.getType().equalsIgnoreCase(type)) { // We didn't find a vertex with the supplied type, so just throw an // exception. - throw new CrudException("No vertex with id " + id + "and type " + type + " found in graph", + throw new CrudException("No vertex with id " + id + " and type " + type + " found in graph", javax.ws.rs.core.Response.Status.NOT_FOUND); } return vert; diff --git a/src/main/java/org/onap/crud/event/response/GraphEventResponseHandler.java b/src/main/java/org/onap/crud/event/response/GraphEventResponseHandler.java index d858384..83be4bc 100644 --- a/src/main/java/org/onap/crud/event/response/GraphEventResponseHandler.java +++ b/src/main/java/org/onap/crud/event/response/GraphEventResponseHandler.java @@ -42,12 +42,7 @@ public class GraphEventResponseHandler { public String handleVertexResponse(String version, GraphEvent event, GraphEventEnvelope response) throws CrudException { - handlePolicyViolations(event, response); - logResponse(event, response.getBody()); - - if (isErrorResponse(response.getBody())) { - throwOperationException(response); - } + validate(event, response); return CrudResponseBuilder.buildUpsertVertexResponse( OxmModelValidator.validateOutgoingPayload(version, response.getBody().getVertex().toVertex()), version); @@ -55,12 +50,7 @@ public class GraphEventResponseHandler { public String handleEdgeResponse(String version, GraphEvent event, GraphEventEnvelope response) throws CrudException { - handlePolicyViolations(event, response); - logResponse(event, response.getBody()); - - if (isErrorResponse(response.getBody())) { - throwOperationException(response); - } + validate(event, response); return CrudResponseBuilder.buildUpsertEdgeResponse( RelationshipSchemaValidator.validateOutgoingPayload(version, response.getBody().getEdge().toEdge()), @@ -68,23 +58,12 @@ public class GraphEventResponseHandler { } public String handleDeletionResponse(GraphEvent event, GraphEventEnvelope response) throws CrudException { - handlePolicyViolations(event, response); - logResponse(event, response.getBody()); - - if (isErrorResponse(response.getBody())) { - throwOperationException(response); - } - + validate(event, response); return ""; } public void handleBulkEventResponse(GraphEvent event, GraphEventEnvelope response) throws CrudException { - handlePolicyViolations(event, response); - logResponse(event, response.getBody()); - - if (isErrorResponse(response.getBody())) { - throwOperationException(response); - } + validate(event, response); } public boolean hasPolicyViolations(GraphEventEnvelope event) { @@ -92,6 +71,18 @@ public class GraphEventResponseHandler { && event.getPolicyViolations().getAsJsonArray().size() != 0; } + private void validate(GraphEvent event, GraphEventEnvelope response) throws CrudException { + handlePolicyViolations(event, response); + logResponse(event, response.getBody()); + + if (isErrorResponse(response.getBody())) { + throw new CrudException( + GraphEventResponseMessage.OPERATION_ERROR_EXCEPTION_MESSAGE + .getMessage(response.getBody().getTransactionId(), response.getBody().getErrorMessage()), + response.getBody().getHttpErrorStatus()); + } + } + private void handlePolicyViolations(GraphEvent event, GraphEventEnvelope response) throws CrudException { if (hasPolicyViolations(response)) { logPolicyViolation(event, response); @@ -126,13 +117,6 @@ public class GraphEventResponseHandler { //@formatter:on } - private void throwOperationException(GraphEventEnvelope response) throws CrudException { - throw new CrudException( - GraphEventResponseMessage.OPERATION_ERROR_EXCEPTION_MESSAGE - .getMessage(response.getBody().getTransactionId(), response.getBody().getErrorMessage()), - response.getBody().getHttpErrorStatus()); - } - private boolean isErrorResponse(GraphEvent response) { return GraphEventResult.FAILURE.equals(response.getResult()); } diff --git a/src/main/java/org/onap/crud/service/AaiResourceService.java b/src/main/java/org/onap/crud/service/AaiResourceService.java index 881f9fd..c2e0338 100644 --- a/src/main/java/org/onap/crud/service/AaiResourceService.java +++ b/src/main/java/org/onap/crud/service/AaiResourceService.java @@ -169,8 +169,9 @@ public class AaiResourceService { ImmutablePair<EntityTag, String> result = graphDataService.addEdge(EdgeRulesLoader.getLatestSchemaVersion(), type, payload);
response = Response.status(Status.CREATED).entity(result.getValue()).tag(result.getKey()).type(mediaType).build();
- } catch (CrudException e) {
-
+ } catch (CrudException ce) {
+ response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
+ } catch (Exception e) {
response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
diff --git a/src/main/java/org/onap/crud/service/CrudAsyncGraphEventCache.java b/src/main/java/org/onap/crud/service/CrudAsyncGraphEventCache.java index 3457cff..ff5170a 100644 --- a/src/main/java/org/onap/crud/service/CrudAsyncGraphEventCache.java +++ b/src/main/java/org/onap/crud/service/CrudAsyncGraphEventCache.java @@ -20,17 +20,15 @@ */ package org.onap.crud.service; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; - import java.util.concurrent.TimeUnit; - import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.crud.logging.CrudServiceMsgs; import org.onap.crud.service.CrudAsyncGraphDataService.CollectGraphResponse; import org.onap.crud.util.CrudProperties; import org.onap.crud.util.CrudServiceConstants; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; /** * Self expiring Cache to hold request transactionIds . Events are expired |