summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSunil Unnava <su622b@att.com>2018-02-28 14:21:40 -0500
committerSunil Unnava <su622b@att.com>2018-02-28 14:26:14 -0500
commitfbe26a20e749c3177f84cd05c67e757ac107b9a8 (patch)
tree6d452c8b04e67d9d85312b964d19d396f79cbbf0 /src
parent0d2012df4ac79e41371fba15241c5efcb327a7ad (diff)
changes for code coverage
Issue-ID: DMAAP-271 Change-Id: Ib8fd245fdbe9ef3457e8303c5379977b237ec09a Signed-off-by: Sunil Unnava <su622b@att.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/att/nsa/dmaap/service/EventsRestService.java116
-rw-r--r--src/main/java/com/att/nsa/dmaap/service/MMRestService.java96
-rw-r--r--src/main/java/com/att/nsa/dmaap/service/TopicRestService.java662
-rw-r--r--src/main/java/com/att/nsa/dmaap/service/TransactionRestService.java43
-rw-r--r--src/test/java/com/att/nsa/dmaap/service/EventsRestServiceTest.java216
-rw-r--r--src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java45
-rw-r--r--src/test/java/com/att/nsa/dmaap/service/TopicRestServiceTest.java411
-rw-r--r--src/test/java/com/att/nsa/dmaap/service/TransactionRestServiceTest.java40
8 files changed, 1100 insertions, 529 deletions
diff --git a/src/main/java/com/att/nsa/dmaap/service/EventsRestService.java b/src/main/java/com/att/nsa/dmaap/service/EventsRestService.java
index cda431c..6fbfd01 100644
--- a/src/main/java/com/att/nsa/dmaap/service/EventsRestService.java
+++ b/src/main/java/com/att/nsa/dmaap/service/EventsRestService.java
@@ -56,9 +56,10 @@ import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;
+
/**
- * This class is a CXF REST service which acts
- * as gateway for MR Event Service.
+ * This class is a CXF REST service which acts as gateway for MR Event Service.
+ *
* @author author
*
*/
@@ -69,7 +70,8 @@ public class EventsRestService {
/**
* Logger obj
*/
- //private Logger log = Logger.getLogger(EventsRestService.class.toString());
+ // private Logger log =
+ // Logger.getLogger(EventsRestService.class.toString());
private static final EELFLogger log = EELFManager.getInstance().getLogger(EventsRestService.class);
/**
* HttpServletRequest obj
@@ -83,7 +85,6 @@ public class EventsRestService {
@Context
private HttpServletResponse response;
-
/**
* Config Reader
*/
@@ -97,6 +98,8 @@ public class EventsRestService {
@Autowired
private DMaaPErrorMessages errorMessages;
+ private DMaaPContext dmaapContext = new DMaaPContext();
+
/**
* This method is used to consume messages.Taking three parameter
* topic,consumerGroup and consumerId .Consumer decide to which topic they
@@ -118,50 +121,44 @@ public class EventsRestService {
*/
@GET
@Path("/{topic}/{consumergroup}/{consumerid}")
- public void getEvents(@PathParam("topic") String topic, @PathParam("consumergroup")
- String consumergroup,
+ public void getEvents(@PathParam("topic") String topic, @PathParam("consumergroup") String consumergroup,
@PathParam("consumerid") String consumerid) throws CambriaApiException {
// log.info("Consuming message from topic " + topic );
- DMaaPContext dMaaPContext = getDmaapContext();
- dMaaPContext.setConsumerRequestTime(Utils.getFormattedDate(new Date()));
+ dmaapContext = getDmaapContext();
+ dmaapContext.setConsumerRequestTime(Utils.getFormattedDate(new Date()));
try {
- eventsService.getEvents(dMaaPContext, topic, consumergroup, consumerid);
- }
- catch (TopicExistsException e) {
+ eventsService.getEvents(dmaapContext, topic, consumergroup, consumerid);
+ } catch (TopicExistsException e) {
log.error("Error while reading data from topic [" + topic + "].", e);
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT,
- DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(), errorMessages.getConsumeMsgError()
- + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic, null, null,
- consumerid,
- request.getRemoteHost());
+ DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(),
+ errorMessages.getConsumeMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+ topic, null, null, consumerid, request.getRemoteHost());
log.info(errRes.toString());
throw new CambriaApiException(errRes);
- }
- catch (DMaaPAccessDeniedException | AccessDeniedException e) {
+ } catch (DMaaPAccessDeniedException | AccessDeniedException e) {
log.error("Error while reading data from topic [" + topic + "].", e);
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
- DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(), errorMessages.getConsumeMsgError()
- + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic, null, null,
- consumerid,
- request.getRemoteHost());
+ DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(),
+ errorMessages.getConsumeMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+ topic, null, null, consumerid, request.getRemoteHost());
log.info(errRes.toString());
throw new CambriaApiException(errRes);
}
-
+
catch (ConfigDbException | UnavailableException | IOException e) {
log.error("Error while reading data from topic [" + topic + "].", e);
-
+
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(), errorMessages.getConsumeMsgError()
- + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic, null, null,
- consumerid,
- request.getRemoteHost());
+ DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(),
+ errorMessages.getConsumeMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+ topic, null, null, consumerid, request.getRemoteHost());
log.info(errRes.toString());
throw new CambriaApiException(errRes);
@@ -192,36 +189,33 @@ public class EventsRestService {
try {
eventsService.pushEvents(getDmaapContext(), topic, msg, partitionKey, null);
- }
- catch ( TopicExistsException e) {
+ } catch (TopicExistsException e) {
log.error("Error while publishing to topic [" + topic + "].", e);
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT,
- DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
- + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
- Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+ DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+ errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+ topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
log.info(errRes.toString());
throw new CambriaApiException(errRes);
- }
- catch ( DMaaPAccessDeniedException | AccessDeniedException e) {
+ } catch (DMaaPAccessDeniedException | AccessDeniedException e) {
log.error("Error while publishing to topic [" + topic + "].", e);
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
- DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
- + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
- Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+ DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+ errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+ topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
log.info(errRes.toString());
throw new CambriaApiException(errRes);
}
-
-
- catch (ConfigDbException | IOException | missingReqdSetting e) {
+
+ catch (ConfigDbException | IOException | missingReqdSetting e) {
log.error("Error while publishing to topic [" + topic + "].", e);
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
- + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
- Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+ DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+ errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+ topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
log.info(errRes.toString());
throw new CambriaApiException(errRes);
}
@@ -250,40 +244,37 @@ public class EventsRestService {
// );
try {
- eventsService.pushEvents(getDmaapContext(), topic, request.getInputStream(),
- partitionKey,
+ eventsService.pushEvents(getDmaapContext(), topic, request.getInputStream(), partitionKey,
Utils.getFormattedDate(new Date()));
- }
-
- catch ( TopicExistsException e) {
+ }
+
+ catch (TopicExistsException e) {
log.error("Error while publishing to topic [" + topic + "].", e);
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT,
- DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
- + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
- Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+ DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+ errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+ topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
log.info(errRes.toString());
throw new CambriaApiException(errRes);
- }
- catch ( DMaaPAccessDeniedException| AccessDeniedException e) {
+ } catch (DMaaPAccessDeniedException | AccessDeniedException e) {
log.error("Error while publishing to topic [" + topic + "].", e);
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
- DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
- + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
- Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+ DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+ errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+ topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
log.info(errRes.toString());
throw new CambriaApiException(errRes);
}
-
- catch (ConfigDbException | IOException | missingReqdSetting e) {
+
+ catch (ConfigDbException | IOException | missingReqdSetting e) {
log.error("Error while publishing to topic : " + topic, e);
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), "Transaction-"
- + errorMessages.getPublishMsgError() + e.getMessage(), null,
- Utils.getFormattedDate(new Date()), topic, Utils.getUserApiKey(request),
- request.getRemoteHost(),
+ DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+ "Transaction-" + errorMessages.getPublishMsgError() + e.getMessage(), null,
+ Utils.getFormattedDate(new Date()), topic, Utils.getUserApiKey(request), request.getRemoteHost(),
null, null);
log.info(errRes.toString());
throw new CambriaApiException(errRes);
@@ -302,7 +293,6 @@ public class EventsRestService {
*/
private DMaaPContext getDmaapContext() {
- DMaaPContext dmaapContext = new DMaaPContext();
dmaapContext.setRequest(request);
dmaapContext.setResponse(response);
dmaapContext.setConfigReader(configReader);
diff --git a/src/main/java/com/att/nsa/dmaap/service/MMRestService.java b/src/main/java/com/att/nsa/dmaap/service/MMRestService.java
index ab457e5..a715e1f 100644
--- a/src/main/java/com/att/nsa/dmaap/service/MMRestService.java
+++ b/src/main/java/com/att/nsa/dmaap/service/MMRestService.java
@@ -27,7 +27,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
@@ -115,6 +114,8 @@ public class MMRestService {
@Autowired
private DMaaPErrorMessages errorMessages;
+ private DMaaPAAFAuthenticator dmaapAAFauthenticator = new DMaaPAAFAuthenticatorImpl();
+
/**
* This method is used for taking Configuration Object,HttpServletRequest
* Object,HttpServletRequest HttpServletResponse Object,HttpServletSession
@@ -178,7 +179,7 @@ public class MMRestService {
|| createMirrorMaker.getCreateMirrorMaker().getStatus() != null) {
sendErrResponse(ctx, "This is not a CreateMirrorMaker request. Please try again.");
}
-
+
// if empty, blank name is entered
else if (StringUtils.isBlank(name)) {
sendErrResponse(ctx, "Name can not be empty or blank.");
@@ -253,8 +254,8 @@ public class MMRestService {
// Check if request has listAllMirrorMaker and
// listAllMirrorMaker is empty
- if ((jsonOb != null) && (jsonOb.has("listAllMirrorMaker") &&
- jsonOb.getJSONObject("listAllMirrorMaker").length() == 0)) {
+ if ((jsonOb != null) && (jsonOb.has("listAllMirrorMaker")
+ && jsonOb.getJSONObject("listAllMirrorMaker").length() == 0)) {
jsonOb.put("messageID", randomStr);
InputStream inStream = null;
@@ -329,7 +330,7 @@ public class MMRestService {
|| updateMirrorMaker.getUpdateMirrorMaker().getStatus() != null) {
sendErrResponse(ctx, "This is not a UpdateMirrorMaker request. Please try again.");
}
-
+
// if empty, blank name is entered
else if (StringUtils.isBlank(name)) {
sendErrResponse(ctx, "Name can not be empty or blank.");
@@ -405,11 +406,11 @@ public class MMRestService {
// Check if request has DeleteMirrorMaker and
// DeleteMirrorMaker has MirrorMaker object with name variable
// and check if the name contain only alpha numeric
- if ((jsonOb != null) && (jsonOb.has("deleteMirrorMaker")
- && jsonOb.getJSONObject("deleteMirrorMaker").length() == 1
- && jsonOb.getJSONObject("deleteMirrorMaker").has("name")
- && !StringUtils.isBlank(jsonOb.getJSONObject("deleteMirrorMaker").getString("name"))
- && isAlphaNumeric(jsonOb.getJSONObject("deleteMirrorMaker").getString("name")))) {
+ if ((jsonOb != null)
+ && (jsonOb.has("deleteMirrorMaker") && jsonOb.getJSONObject("deleteMirrorMaker").length() == 1
+ && jsonOb.getJSONObject("deleteMirrorMaker").has("name")
+ && !StringUtils.isBlank(jsonOb.getJSONObject("deleteMirrorMaker").getString("name"))
+ && isAlphaNumeric(jsonOb.getJSONObject("deleteMirrorMaker").getString("name")))) {
jsonOb.put("messageID", randomStr);
InputStream inStream = null;
@@ -451,7 +452,7 @@ public class MMRestService {
for (int i = 0; i < jArray.length(); i++) {
jObj = jArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jObj.has(MESSAGE)) {
obj = jObj.getJSONObject(MESSAGE);
@@ -526,9 +527,7 @@ public class MMRestService {
boolean hasPermission = false;
- DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-
- if (aaf.aafAuthentication(ctx.getRequest(), permission)) {
+ if (dmaapAAFauthenticator.aafAuthentication(ctx.getRequest(), permission)) {
hasPermission = true;
}
return hasPermission;
@@ -556,7 +555,7 @@ public class MMRestService {
for (int i = 0; i < jsonArray.length(); i++) {
jsonObj = jsonArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jsonObj.has(MESSAGE)) {
obj = jsonObj.getJSONObject(MESSAGE);
@@ -577,7 +576,7 @@ public class MMRestService {
}
} catch (Exception e) {
- LOGGER.error("Exception: ", e);
+ LOGGER.error("Exception: ", e);
}
}
@@ -630,11 +629,9 @@ public class MMRestService {
// numeric
// and check if the request has namespace and namespace contains
// only alpha numeric
- if (jsonOb != null
- && jsonOb.length() == 2 && jsonOb.has("name")
- && !StringUtils.isBlank(jsonOb.getString("name"))
- && isAlphaNumeric(jsonOb.getString("name")) && jsonOb.has(NAMESPACE)
- && !StringUtils.isBlank(jsonOb.getString(NAMESPACE))) {
+ if (jsonOb != null && jsonOb.length() == 2 && jsonOb.has("name")
+ && !StringUtils.isBlank(jsonOb.getString("name")) && isAlphaNumeric(jsonOb.getString("name"))
+ && jsonOb.has(NAMESPACE) && !StringUtils.isBlank(jsonOb.getString(NAMESPACE))) {
String permission = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
"msgRtr.mirrormakeruser.aaf.create") + jsonOb.getString(NAMESPACE) + "|create";
@@ -681,7 +678,7 @@ public class MMRestService {
if (msgFrmSubscribe != null && msgFrmSubscribe.length() > 0
&& isListMirrorMaker(msgFrmSubscribe, randomStr)) {
-
+
JSONArray listMirrorMaker;
listMirrorMaker = getListMirrorMaker(msgFrmSubscribe, randomStr);
@@ -784,16 +781,18 @@ public class MMRestService {
LOGGER.error("JSONException: ", ex);
}
- // Check if the request has name and name contains only alpha numeric,
+ // Check if the request has name and name contains only alpha
+ // numeric,
// check if the request has namespace and
// check if the request has whitelistTopicName
// check if the topic name contains only alpha numeric
if (jsonOb != null && jsonOb.length() == 3 && jsonOb.has("name")
- && !StringUtils.isBlank(jsonOb.getString("name"))
- && isAlphaNumeric(jsonOb.getString("name"))
+ && !StringUtils.isBlank(jsonOb.getString("name")) && isAlphaNumeric(jsonOb.getString("name"))
&& jsonOb.has(NAMESPACE) && !StringUtils.isBlank(jsonOb.getString(NAMESPACE))
- && jsonOb.has("whitelistTopicName") && !StringUtils.isBlank(jsonOb.getString("whitelistTopicName"))
- && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(jsonOb.getString("whitelistTopicName").lastIndexOf(".")+1,
+ && jsonOb.has("whitelistTopicName")
+ && !StringUtils.isBlank(jsonOb.getString("whitelistTopicName"))
+ && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(
+ jsonOb.getString("whitelistTopicName").lastIndexOf(".") + 1,
jsonOb.getString("whitelistTopicName").length()))) {
String permission = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
@@ -843,7 +842,7 @@ public class MMRestService {
if (msgFrmSubscribe != null && msgFrmSubscribe.length() > 0
&& isListMirrorMaker(msgFrmSubscribe, randomStr)) {
-
+
listMirrorMaker = getListMirrorMaker(msgFrmSubscribe, randomStr);
String whitelist = null;
@@ -967,12 +966,15 @@ public class MMRestService {
LOGGER.error("JSONException: ", ex);
}
- // Check if the request has name and name contains only alpha numeric,
+ // Check if the request has name and name contains only alpha
+ // numeric,
// check if the request has namespace and
// check if the request has whitelistTopicName
- if (jsonOb != null && jsonOb.length() == 3 && jsonOb.has("name") && isAlphaNumeric(jsonOb.getString("name"))
- && jsonOb.has(NAMESPACE) && jsonOb.has("whitelistTopicName")
- && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(jsonOb.getString("whitelistTopicName").lastIndexOf(".")+1,
+ if (jsonOb != null && jsonOb.length() == 3 && jsonOb.has("name")
+ && isAlphaNumeric(jsonOb.getString("name")) && jsonOb.has(NAMESPACE)
+ && jsonOb.has("whitelistTopicName")
+ && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(
+ jsonOb.getString("whitelistTopicName").lastIndexOf(".") + 1,
jsonOb.getString("whitelistTopicName").length()))) {
String permission = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
@@ -1029,12 +1031,13 @@ public class MMRestService {
for (int i = 0; i < jsonArray.length(); i++) {
jsonObj = jsonArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jsonObj.has(MESSAGE)) {
obj = jsonObj.getJSONObject(MESSAGE);
}
- if (obj.has("messageID") && obj.get("messageID").equals(randomStr) && obj.has(LISTMIRRORMAKER)) {
+ if (obj.has("messageID") && obj.get("messageID").equals(randomStr)
+ && obj.has(LISTMIRRORMAKER)) {
listMirrorMaker = obj.getJSONArray(LISTMIRRORMAKER);
break;
}
@@ -1068,22 +1071,21 @@ public class MMRestService {
sendErrResponse(ctx, "The topic does not exist.");
}
-
if (removeTopic) {
UpdateWhiteList updateWhiteList = new UpdateWhiteList();
MirrorMaker mirrorMaker = new MirrorMaker();
-
+
mirrorMaker.setName(jsonOb.getString("name"));
mirrorMaker.setWhitelist(removeTopic(whitelist, topicToRemove));
-
+
String newRandom = getRandomNum();
-
+
updateWhiteList.setMessageID(newRandom);
updateWhiteList.setUpdateWhiteList(mirrorMaker);
-
+
Gson g = new Gson();
g.toJson(updateWhiteList);
-
+
InputStream inputStream;
inputStream = IOUtils.toInputStream(g.toJson(updateWhiteList), UTF_8);
callPubSubForWhitelist(newRandom, ctx, inputStream, getNamespace(topicToRemove));
@@ -1132,7 +1134,7 @@ public class MMRestService {
}
if (topicList.contains(topicToRemove)) {
- for (String topic: topicList) {
+ for (String topic : topicList) {
if (!topic.equals(topicToRemove)) {
newTopicList.add(topic);
}
@@ -1145,7 +1147,7 @@ public class MMRestService {
}
private void callPubSubForWhitelist(String randomStr, DMaaPContext ctx, InputStream inStream, String namespace) {
-
+
try {
mirrorService.pushEvents(ctx, topic, inStream, null, null);
long startTime = System.currentTimeMillis();
@@ -1167,7 +1169,7 @@ public class MMRestService {
for (int i = 0; i < jsonArray.length(); i++) {
jsonObj = jsonArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jsonObj.has(MESSAGE)) {
obj = jsonObj.getJSONObject(MESSAGE);
@@ -1231,18 +1233,18 @@ public class MMRestService {
return whitelist;
}
-
+
private JSONArray getListMirrorMaker(String msgFrmSubscribe, String randomStr) {
JSONObject jsonObj;
JSONArray jsonArray;
JSONArray listMirrorMaker = new JSONArray();
-
+
msgFrmSubscribe = removeExtraChar(msgFrmSubscribe);
jsonArray = new JSONArray(msgFrmSubscribe);
for (int i = 0; i < jsonArray.length(); i++) {
jsonObj = jsonArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jsonObj.has(MESSAGE)) {
obj = jsonObj.getJSONObject(MESSAGE);
@@ -1252,6 +1254,6 @@ public class MMRestService {
break;
}
}
- return listMirrorMaker;
+ return listMirrorMaker;
}
}
diff --git a/src/main/java/com/att/nsa/dmaap/service/TopicRestService.java b/src/main/java/com/att/nsa/dmaap/service/TopicRestService.java
index 6742cd5..50bd069 100644
--- a/src/main/java/com/att/nsa/dmaap/service/TopicRestService.java
+++ b/src/main/java/com/att/nsa/dmaap/service/TopicRestService.java
@@ -62,8 +62,8 @@ import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
/**
- * This class is a CXF REST service which acts
- * as gateway for MR Topic Service.
+ * This class is a CXF REST service which acts as gateway for MR Topic Service.
+ *
* @author author
*
*/
@@ -75,7 +75,8 @@ public class TopicRestService {
/**
* Logger obj
*/
- //private static final Logger LOGGER = Logger .getLogger(TopicRestService.class);
+ // private static final Logger LOGGER = Logger
+ // .getLogger(TopicRestService.class);
private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(TopicRestService.class);
/**
* Config Reader
@@ -100,76 +101,72 @@ public class TopicRestService {
* TopicService obj
*/
@Autowired
- private TopicService topicService;
-
+ private TopicService tService;
+
/**
* DMaaPErrorMessages obj
*/
@Autowired
private DMaaPErrorMessages errorMessages;
-
+
+ private DMaaPContext dmaapContext = new DMaaPContext();
+
/**
* mrNamespace
*/
- //@Value("${msgRtr.namespace.aaf}")
-// private String mrNamespace;
-
+ // @Value("${msgRtr.namespace.aaf}")
+ // private String mrNamespace;
/**
* Fetches a list of topics from the current kafka instance and converted
* into json object.
*
* @return list of the topics in json format
- * @throws AccessDeniedException
- * @throws CambriaApiException
+ * @throws AccessDeniedException
+ * @throws CambriaApiException
* @throws IOException
* @throws JSONException
- * */
+ */
@GET
- //@Produces(MediaType.TEXT_PLAIN)
+ // @Produces(MediaType.TEXT_PLAIN)
public void getTopics() throws CambriaApiException {
try {
-
+
LOGGER.info("Authenticating the user before fetching the topics");
- //String permission = "com.att.dmaap.mr.topic|*|view";
- String mrNameS= com.att.ajsc.beans.PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop,"msgRtr.namespace.aaf");
- String permission =mrNameS+"|"+"*"+"|"+"view";
+ // String permission = "com.att.dmaap.mr.topic|*|view";
+ String mrNameS = com.att.ajsc.beans.PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop,
+ "msgRtr.namespace.aaf");
+ String permission = mrNameS + "|" + "*" + "|" + "view";
DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
- //Check if client is using AAF CADI Basic Authorization
- //If yes then check for AAF role authentication else display all topics
- if(null!=getDmaapContext().getRequest().getHeader("Authorization"))
- {
- if(!aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
- {
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
- DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
- errorMessages.getNotPermitted1()+" read "+errorMessages.getNotPermitted2());
+ // Check if client is using AAF CADI Basic Authorization
+ // If yes then check for AAF role authentication else display all
+ // topics
+ if (null != getDmaapContext().getRequest().getHeader("Authorization")) {
+ if (!aaf.aafAuthentication(getDmaapContext().getRequest(), permission)) {
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+ DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+ errorMessages.getNotPermitted1() + " read " + errorMessages.getNotPermitted2());
LOGGER.info(errRes.toString());
throw new DMaaPAccessDeniedException(errRes);
-
-
+
}
- }
-
- LOGGER.info("Fetching all Topics");
-
- topicService.getTopics(getDmaapContext());
-
- LOGGER.info("Returning List of all Topics");
-
-
+ }
+
+ LOGGER.info("Fetching all Topics");
+
+ tService.getTopics(getDmaapContext());
+
+ LOGGER.info("Returning List of all Topics");
+
} catch (JSONException | ConfigDbException | IOException excp) {
- LOGGER.error(
- "Failed to retrieve list of all topics: "
- + excp.getMessage(), excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.GET_TOPICS_FAIL.getResponseCode(),
- errorMessages.getTopicsfailure()+ excp.getMessage());
+ LOGGER.error("Failed to retrieve list of all topics: " + excp.getMessage(), excp);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+ DMaaPResponseCode.GET_TOPICS_FAIL.getResponseCode(),
+ errorMessages.getTopicsfailure() + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
}
}
@@ -179,62 +176,56 @@ public class TopicRestService {
* into json object.
*
* @return list of the topics in json format
- * @throws AccessDeniedException
- * @throws CambriaApiException
+ * @throws AccessDeniedException
+ * @throws CambriaApiException
* @throws IOException
* @throws JSONException
- * */
+ */
@GET
@Path("/listAll")
- //@Produces(MediaType.TEXT_PLAIN)
+ // @Produces(MediaType.TEXT_PLAIN)
public void getAllTopics() throws CambriaApiException {
try {
-
+
LOGGER.info("Authenticating the user before fetching the topics");
- //String permission = "com.att.dmaap.mr.topic|*|view";
- String mrNameS= com.att.ajsc.beans.PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop,"msgRtr.namespace.aaf");
- String permission =mrNameS+"|"+"*"+"|"+"view";
+ // String permission = "com.att.dmaap.mr.topic|*|view";
+ String mrNameS = com.att.ajsc.beans.PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop,
+ "msgRtr.namespace.aaf");
+ String permission = mrNameS + "|" + "*" + "|" + "view";
DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
- //Check if client is using AAF CADI Basic Authorization
- //If yes then check for AAF role authentication else display all topics
- if(null!=getDmaapContext().getRequest().getHeader("Authorization"))
- {
- if(!aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
- {
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
- DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
- errorMessages.getNotPermitted1()+" read "+errorMessages.getNotPermitted2());
+ // Check if client is using AAF CADI Basic Authorization
+ // If yes then check for AAF role authentication else display all
+ // topics
+ if (null != getDmaapContext().getRequest().getHeader("Authorization")) {
+ if (!aaf.aafAuthentication(getDmaapContext().getRequest(), permission)) {
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+ DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+ errorMessages.getNotPermitted1() + " read " + errorMessages.getNotPermitted2());
LOGGER.info(errRes.toString());
throw new DMaaPAccessDeniedException(errRes);
-
-
+
}
- }
-
- LOGGER.info("Fetching all Topics");
-
- topicService.getAllTopics(getDmaapContext());
-
- LOGGER.info("Returning List of all Topics");
-
-
+ }
+
+ LOGGER.info("Fetching all Topics");
+
+ tService.getAllTopics(getDmaapContext());
+
+ LOGGER.info("Returning List of all Topics");
+
} catch (JSONException | ConfigDbException | IOException excp) {
- LOGGER.error(
- "Failed to retrieve list of all topics: "
- + excp.getMessage(), excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.GET_TOPICS_FAIL.getResponseCode(),
- errorMessages.getTopicsfailure()+ excp.getMessage());
+ LOGGER.error("Failed to retrieve list of all topics: " + excp.getMessage(), excp);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+ DMaaPResponseCode.GET_TOPICS_FAIL.getResponseCode(),
+ errorMessages.getTopicsfailure() + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
}
}
-
/**
* Returns details of the topic whose name is passed as a parameter
*
@@ -242,59 +233,55 @@ public class TopicRestService {
* - name of the topic
* @return details of a topic whose name is mentioned in the request in json
* format.
- * @throws AccessDeniedException
- * @throws DMaaPAccessDeniedException
+ * @throws AccessDeniedException
+ * @throws DMaaPAccessDeniedException
* @throws IOException
- * */
+ */
@GET
@Path("/{topicName}")
- //@Produces(MediaType.TEXT_PLAIN)
+ // @Produces(MediaType.TEXT_PLAIN)
public void getTopic(@PathParam("topicName") String topicName) throws CambriaApiException {
try {
-
- LOGGER.info("Authenticating the user before fetching the details about topic = "+ topicName);
+
+ LOGGER.info("Authenticating the user before fetching the details about topic = " + topicName);
DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-
- //String permission= "com.att.ecomp_test.crm.mr.topic|:topic.com.att.ecomp_test.crm.preDemo|view";
-
- //Check if client is using AAF CADI Basic Authorization
- //If yes then check for AAF role authentication else display all topics
- if(null!=getDmaapContext().getRequest().getHeader("Authorization"))
- {
+
+ // String permission=
+ // "com.att.ecomp_test.crm.mr.topic|:topic.com.att.ecomp_test.crm.preDemo|view";
+
+ // Check if client is using AAF CADI Basic Authorization
+ // If yes then check for AAF role authentication else display all
+ // topics
+ if (null != getDmaapContext().getRequest().getHeader("Authorization")) {
String permission = aaf.aafPermissionString(topicName, "view");
- if(!aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
- {
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
- DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
- errorMessages.getNotPermitted1()+" read "+errorMessages.getNotPermitted2());
- LOGGER.info(errRes.toString());
- throw new DMaaPAccessDeniedException(errRes);
- }
- }
-
- LOGGER.info("Fetching Topic: " + topicName);
-
- topicService.getTopic(getDmaapContext(), topicName);
-
- LOGGER.info("Fetched details of topic: " + topicName);
-
+ if (!aaf.aafAuthentication(getDmaapContext().getRequest(), permission)) {
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+ DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+ errorMessages.getNotPermitted1() + " read " + errorMessages.getNotPermitted2());
+ LOGGER.info(errRes.toString());
+ throw new DMaaPAccessDeniedException(errRes);
+ }
+ }
+
+ LOGGER.info("Fetching Topic: " + topicName);
+
+ tService.getTopic(getDmaapContext(), topicName);
+
+ LOGGER.info("Fetched details of topic: " + topicName);
+
} catch (ConfigDbException | IOException | TopicExistsException excp) {
- LOGGER.error("Failed to retrieve details of topic: " + topicName,
- excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.GET_TOPICS_DETAILS_FAIL.getResponseCode(),
- errorMessages.getTopicDetailsFail()+topicName+ excp.getMessage());
+ LOGGER.error("Failed to retrieve details of topic: " + topicName, excp);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+ DMaaPResponseCode.GET_TOPICS_DETAILS_FAIL.getResponseCode(),
+ errorMessages.getTopicDetailsFail() + topicName + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
-
+
}
}
-
-
/**
* This method is still not working. Need to check on post call and how to
* accept parameters for post call
@@ -303,57 +290,50 @@ public class TopicRestService {
* it will have the bean object
* @throws TopicExistsException
* @throws CambriaApiException
- * @throws JSONException
+ * @throws JSONException
* @throws IOException
* @throws AccessDeniedException
*
- * */
+ */
@POST
@Path("/create")
@Consumes({ MediaType.APPLICATION_JSON })
- //@Produces(MediaType.TEXT_PLAIN)
+ // @Produces(MediaType.TEXT_PLAIN)
public void createTopic(TopicBean topicBean) throws CambriaApiException, JSONException {
- try {
- LOGGER.info("Creating Topic."+topicBean.getTopicName());
-
- topicService.createTopic(getDmaapContext(), topicBean);
+ try {
+ LOGGER.info("Creating Topic." + topicBean.getTopicName());
+
+ tService.createTopic(getDmaapContext(), topicBean);
LOGGER.info("Topic created Successfully.");
- }
- catch (TopicExistsException ex){
-
- LOGGER.error("Error while creating a topic: " + ex.getMessage(),
- ex);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT,
- DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
- errorMessages.getCreateTopicFail()+ ex.getMessage());
- LOGGER.info(errRes.toString());
- throw new CambriaApiException(errRes);
-
-
-
-
- }catch (AccessDeniedException | DMaaPAccessDeniedException excp) {
- LOGGER.error("Error while creating a topic: " + excp.getMessage(),
- excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
- DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
- errorMessages.getCreateTopicFail()+ excp.getMessage());
+ } catch (TopicExistsException ex) {
+
+ LOGGER.error("Error while creating a topic: " + ex.getMessage(), ex);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT,
+ DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+ errorMessages.getCreateTopicFail() + ex.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
- }catch (CambriaApiException | IOException excp) {
- LOGGER.error("Error while creating a topic: " + excp.getMessage(),
- excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
- errorMessages.getCreateTopicFail()+ excp.getMessage());
+
+ } catch (AccessDeniedException | DMaaPAccessDeniedException excp) {
+ LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+ DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+ errorMessages.getCreateTopicFail() + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
+
+ } catch (CambriaApiException | IOException excp) {
+ LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+ DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+ errorMessages.getCreateTopicFail() + excp.getMessage());
+ LOGGER.info(errRes.toString());
+ throw new CambriaApiException(errRes);
+
}
}
@@ -362,45 +342,42 @@ public class TopicRestService {
*
* @param topicName
* topic
- * @throws CambriaApiException
+ * @throws CambriaApiException
* @throws IOException
- * */
+ */
@DELETE
@Path("/{topicName}")
- //@Produces(MediaType.TEXT_PLAIN)
+ // @Produces(MediaType.TEXT_PLAIN)
public void deleteTopic(@PathParam("topicName") String topicName) throws CambriaApiException {
try {
LOGGER.info("Deleting Topic: " + topicName);
- topicService.deleteTopic(getDmaapContext(), topicName);
+ tService.deleteTopic(getDmaapContext(), topicName);
LOGGER.info("Topic [" + topicName + "] deleted successfully.");
- } catch (DMaaPAccessDeniedException| AccessDeniedException excp) {
- LOGGER.error("Error while creating a topic: " + excp.getMessage(),
- excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
- DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
- errorMessages.getCreateTopicFail()+ excp.getMessage());
+ } catch (DMaaPAccessDeniedException | AccessDeniedException excp) {
+ LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+ DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+ errorMessages.getCreateTopicFail() + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
- }catch (IOException | ConfigDbException
- | CambriaApiException | TopicExistsException excp) {
+
+ } catch (IOException | ConfigDbException | CambriaApiException | TopicExistsException excp) {
LOGGER.error("Error while deleting topic: " + topicName, excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.DELETE_TOPIC_FAIL.getResponseCode(),
- errorMessages.getDeleteTopicFail()+ topicName + excp.getMessage());
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+ DMaaPResponseCode.DELETE_TOPIC_FAIL.getResponseCode(),
+ errorMessages.getDeleteTopicFail() + topicName + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
+
}
}
private DMaaPContext getDmaapContext() {
- DMaaPContext dmaapContext = new DMaaPContext();
dmaapContext.setRequest(request);
dmaapContext.setResponse(response);
dmaapContext.setConfigReader(configReader);
@@ -413,49 +390,48 @@ public class TopicRestService {
* This method will fetch the details of publisher by giving topic name
*
* @param topicName
- * @throws CambriaApiException
- * @throws AccessDeniedException
+ * @throws CambriaApiException
+ * @throws AccessDeniedException
*/
@GET
@Path("/{topicName}/producers")
- //@Produces(MediaType.TEXT_PLAIN)
- public void getPublishersByTopicName(
- @PathParam("topicName") String topicName) throws CambriaApiException {
+ // @Produces(MediaType.TEXT_PLAIN)
+ public void getPublishersByTopicName(@PathParam("topicName") String topicName) throws CambriaApiException {
try {
-
-// String permission = "com.att.dmaap.mr.topic"+"|"+topicName+"|"+"manage";
-// DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-// String permission = aaf.aafPermissionString(topicName, "view");
-// if(aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
-// {
- LOGGER.info("Fetching list of all the publishers for topic "
- + topicName);
-
- topicService.getPublishersByTopicName(getDmaapContext(), topicName);
-
- LOGGER.info("Returning list of all the publishers for topic "
- + topicName);
-// }else{
-// LOGGER.error("Error while fetching list of publishers for topic "+ topicName);
-//
-// ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
-// DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
-// errorMessages.getNotPermitted1()+" fetch list of publishers "+errorMessages.getNotPermitted2());
-// LOGGER.info(errRes);
-// throw new DMaaPAccessDeniedException(errRes);
-//
-// }
-
+
+ // String permission =
+ // "com.att.dmaap.mr.topic"+"|"+topicName+"|"+"manage";
+ // DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
+ // String permission = aaf.aafPermissionString(topicName, "view");
+ // if(aaf.aafAuthentication(getDmaapContext().getRequest(),
+ // permission))
+ // {
+ LOGGER.info("Fetching list of all the publishers for topic " + topicName);
+
+ tService.getPublishersByTopicName(getDmaapContext(), topicName);
+
+ LOGGER.info("Returning list of all the publishers for topic " + topicName);
+ // }else{
+ // LOGGER.error("Error while fetching list of publishers for topic
+ // "+ topicName);
+ //
+ // ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+ // DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+ // errorMessages.getNotPermitted1()+" fetch list of publishers
+ // "+errorMessages.getNotPermitted2());
+ // LOGGER.info(errRes);
+ // throw new DMaaPAccessDeniedException(errRes);
+ //
+ // }
+
} catch (IOException | ConfigDbException | TopicExistsException excp) {
- LOGGER.error("Error while fetching list of publishers for topic "
- + topicName, excp);
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.GET_PUBLISHERS_BY_TOPIC.getResponseCode(),
- "Error while fetching list of publishers for topic: "
- + topicName + excp.getMessage());
+ LOGGER.error("Error while fetching list of publishers for topic " + topicName, excp);
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+ DMaaPResponseCode.GET_PUBLISHERS_BY_TOPIC.getResponseCode(),
+ "Error while fetching list of publishers for topic: " + topicName + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
+
}
}
@@ -464,44 +440,38 @@ public class TopicRestService {
*
* @param topicName
* @param producerId
- * @throws CambriaApiException
+ * @throws CambriaApiException
*/
@PUT
@Path("/{topicName}/producers/{producerId}")
- public void permitPublisherForTopic(
- @PathParam("topicName") String topicName,
+ public void permitPublisherForTopic(@PathParam("topicName") String topicName,
@PathParam("producerId") String producerId) throws CambriaApiException {
try {
- LOGGER.info("Granting write access to producer [" + producerId
- + "] for topic " + topicName);
+ LOGGER.info("Granting write access to producer [" + producerId + "] for topic " + topicName);
- topicService.permitPublisherForTopic(getDmaapContext(), topicName,
- producerId);
+ tService.permitPublisherForTopic(getDmaapContext(), topicName, producerId);
- LOGGER.info("Write access has been granted to producer ["
- + producerId + "] for topic " + topicName);
+ LOGGER.info("Write access has been granted to producer [" + producerId + "] for topic " + topicName);
} catch (AccessDeniedException | DMaaPAccessDeniedException excp) {
- LOGGER.error("Error while creating a topic: " + excp.getMessage(),
- excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
- DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
- errorMessages.getCreateTopicFail()+ excp.getMessage());
+ LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+ DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+ errorMessages.getCreateTopicFail() + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
- }catch ( ConfigDbException | IOException
- | TopicExistsException excp) {
- LOGGER.error("Error while granting write access to producer ["
- + producerId + "] for topic " + topicName, excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
- DMaaPResponseCode.PERMIT_PUBLISHER_FOR_TOPIC.getResponseCode(),
- "Error while granting write access to producer ["
- + producerId + "] for topic " + topicName + excp.getMessage());
+
+ } catch (ConfigDbException | IOException | TopicExistsException excp) {
+ LOGGER.error("Error while granting write access to producer [" + producerId + "] for topic " + topicName,
+ excp);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+ DMaaPResponseCode.PERMIT_PUBLISHER_FOR_TOPIC.getResponseCode(),
+ "Error while granting write access to producer [" + producerId + "] for topic " + topicName
+ + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
+
}
}
@@ -510,39 +480,34 @@ public class TopicRestService {
*
* @param topicName
* @param producerId
- * @throws CambriaApiException
+ * @throws CambriaApiException
*/
@DELETE
@Path("/{topicName}/producers/{producerId}")
public void denyPublisherForTopic(@PathParam("topicName") String topicName,
@PathParam("producerId") String producerId) throws CambriaApiException {
try {
- LOGGER.info("Revoking write access to producer [" + producerId
- + "] for topic " + topicName);
+ LOGGER.info("Revoking write access to producer [" + producerId + "] for topic " + topicName);
- topicService.denyPublisherForTopic(getDmaapContext(), topicName,
- producerId);
+ tService.denyPublisherForTopic(getDmaapContext(), topicName, producerId);
- LOGGER.info("Write access revoked for producer [" + producerId
- + "] for topic " + topicName);
+ LOGGER.info("Write access revoked for producer [" + producerId + "] for topic " + topicName);
} catch (DMaaPAccessDeniedException | AccessDeniedException excp) {
- LOGGER.error("Error while creating a topic: " + excp.getMessage(),
- excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
- DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
- errorMessages.getCreateTopicFail()+ excp.getMessage());
+ LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+ DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+ errorMessages.getCreateTopicFail() + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
- }catch ( ConfigDbException | IOException
- | TopicExistsException excp) {
- LOGGER.error("Error while revoking write access for producer ["
- + producerId + "] for topic " + topicName, excp);
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
- DMaaPResponseCode.REVOKE_PUBLISHER_FOR_TOPIC.getResponseCode(),
- "Error while revoking write access to producer ["
- + producerId + "] for topic " + topicName + excp.getMessage());
+
+ } catch (ConfigDbException | IOException | TopicExistsException excp) {
+ LOGGER.error("Error while revoking write access for producer [" + producerId + "] for topic " + topicName,
+ excp);
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+ DMaaPResponseCode.REVOKE_PUBLISHER_FOR_TOPIC.getResponseCode(),
+ "Error while revoking write access to producer [" + producerId + "] for topic " + topicName
+ + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
}
@@ -552,55 +517,51 @@ public class TopicRestService {
* Get the consumer details by the topic name
*
* @param topicName
- * @throws AccessDeniedException
- * @throws CambriaApiException
+ * @throws AccessDeniedException
+ * @throws CambriaApiException
*/
@GET
@Path("/{topicName}/consumers")
- //@Produces(MediaType.TEXT_PLAIN)
- public void getConsumersByTopicName(@PathParam("topicName") String topicName) throws AccessDeniedException,
- CambriaApiException {
+ // @Produces(MediaType.TEXT_PLAIN)
+ public void getConsumersByTopicName(@PathParam("topicName") String topicName)
+ throws AccessDeniedException, CambriaApiException {
try {
-
-
-// String permission = "com.att.dmaap.mr.topic"+"|"+topicName+"|"+"view";
-// DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-// String permission = aaf.aafPermissionString(topicName, "view");
-// if(aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
-// {
- LOGGER.info("Fetching list of all consumers for topic " + topicName);
-
- topicService.getConsumersByTopicName(getDmaapContext(), topicName);
-
- LOGGER.info("Returning list of all consumers for topic "
- + topicName);
-
-// }else{
-// LOGGER.error(
-// "Error while fetching list of all consumers for topic "
-// + topicName);
-// ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
-// DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
-// errorMessages.getNotPermitted1()+" fetch list of consumers "+errorMessages.getNotPermitted2());
-// LOGGER.info(errRes);
-// throw new DMaaPAccessDeniedException(errRes);
-//
-//
-// }
-
-
-
+
+ // String permission =
+ // "com.att.dmaap.mr.topic"+"|"+topicName+"|"+"view";
+ // DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
+ // String permission = aaf.aafPermissionString(topicName, "view");
+ // if(aaf.aafAuthentication(getDmaapContext().getRequest(),
+ // permission))
+ // {
+ LOGGER.info("Fetching list of all consumers for topic " + topicName);
+
+ tService.getConsumersByTopicName(getDmaapContext(), topicName);
+
+ LOGGER.info("Returning list of all consumers for topic " + topicName);
+
+ // }else{
+ // LOGGER.error(
+ // "Error while fetching list of all consumers for topic "
+ // + topicName);
+ // ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+ // DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+ // errorMessages.getNotPermitted1()+" fetch list of consumers
+ // "+errorMessages.getNotPermitted2());
+ // LOGGER.info(errRes);
+ // throw new DMaaPAccessDeniedException(errRes);
+ //
+ //
+ // }
+
} catch (IOException | ConfigDbException | TopicExistsException excp) {
- LOGGER.error(
- "Error while fetching list of all consumers for topic "
- + topicName, excp);
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
- DMaaPResponseCode.GET_CONSUMERS_BY_TOPIC.getResponseCode(),
- "Error while fetching list of all consumers for topic: "
- + topicName+ excp.getMessage());
+ LOGGER.error("Error while fetching list of all consumers for topic " + topicName, excp);
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+ DMaaPResponseCode.GET_CONSUMERS_BY_TOPIC.getResponseCode(),
+ "Error while fetching list of all consumers for topic: " + topicName + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
+
}
}
@@ -609,33 +570,28 @@ public class TopicRestService {
*
* @param topicName
* @param consumerId
- * @throws CambriaApiException
+ * @throws CambriaApiException
*/
@PUT
@Path("/{topicName}/consumers/{consumerId}")
- public void permitConsumerForTopic(
- @PathParam("topicName") String topicName,
+ public void permitConsumerForTopic(@PathParam("topicName") String topicName,
@PathParam("consumerId") String consumerId) throws CambriaApiException {
try {
- LOGGER.info("Granting read access to consumer [" + consumerId
- + "] for topic " + topicName);
-
- topicService.permitConsumerForTopic(getDmaapContext(), topicName,
- consumerId);
-
- LOGGER.info("Read access granted to consumer [" + consumerId
- + "] for topic " + topicName);
- } catch (AccessDeniedException | ConfigDbException | IOException
- | TopicExistsException excp) {
- LOGGER.error("Error while granting read access to consumer ["
- + consumerId + "] for topic " + topicName, excp);
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
- DMaaPResponseCode.PERMIT_CONSUMER_FOR_TOPIC.getResponseCode(),
- "Error while granting read access to consumer ["
- + consumerId + "] for topic " + topicName+ excp.getMessage());
+ LOGGER.info("Granting read access to consumer [" + consumerId + "] for topic " + topicName);
+
+ tService.permitConsumerForTopic(getDmaapContext(), topicName, consumerId);
+
+ LOGGER.info("Read access granted to consumer [" + consumerId + "] for topic " + topicName);
+ } catch (AccessDeniedException | ConfigDbException | IOException | TopicExistsException excp) {
+ LOGGER.error("Error while granting read access to consumer [" + consumerId + "] for topic " + topicName,
+ excp);
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+ DMaaPResponseCode.PERMIT_CONSUMER_FOR_TOPIC.getResponseCode(),
+ "Error while granting read access to consumer [" + consumerId + "] for topic " + topicName
+ + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
+
}
}
@@ -644,45 +600,37 @@ public class TopicRestService {
*
* @param topicName
* @param consumerId
- * @throws CambriaApiException
+ * @throws CambriaApiException
*/
@DELETE
@Path("/{topicName}/consumers/{consumerId}")
public void denyConsumerForTopic(@PathParam("topicName") String topicName,
@PathParam("consumerId") String consumerId) throws CambriaApiException {
try {
- LOGGER.info("Revoking read access to consumer [" + consumerId
- + "] for topic " + topicName);
-
- topicService.denyConsumerForTopic(getDmaapContext(), topicName,
- consumerId);
-
- LOGGER.info("Read access revoked to consumer [" + consumerId
- + "] for topic " + topicName);
- } catch ( ConfigDbException | IOException
- | TopicExistsException excp) {
- LOGGER.error("Error while revoking read access to consumer ["
- + consumerId + "] for topic " + topicName, excp);
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
- DMaaPResponseCode.REVOKE_CONSUMER_FOR_TOPIC.getResponseCode(),
- "Error while revoking read access to consumer ["
- + consumerId + "] for topic " + topicName+ excp.getMessage());
- LOGGER.info(errRes.toString());
- throw new CambriaApiException(errRes);
- }catch (DMaaPAccessDeniedException | AccessDeniedException excp) {
- LOGGER.error("Error while creating a topic: " + excp.getMessage(),
+ LOGGER.info("Revoking read access to consumer [" + consumerId + "] for topic " + topicName);
+
+ tService.denyConsumerForTopic(getDmaapContext(), topicName, consumerId);
+
+ LOGGER.info("Read access revoked to consumer [" + consumerId + "] for topic " + topicName);
+ } catch (ConfigDbException | IOException | TopicExistsException excp) {
+ LOGGER.error("Error while revoking read access to consumer [" + consumerId + "] for topic " + topicName,
excp);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
- DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
- errorMessages.getCreateTopicFail()+ excp.getMessage());
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+ DMaaPResponseCode.REVOKE_CONSUMER_FOR_TOPIC.getResponseCode(),
+ "Error while revoking read access to consumer [" + consumerId + "] for topic " + topicName
+ + excp.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
-
- }
- }
+ } catch (DMaaPAccessDeniedException | AccessDeniedException excp) {
+ LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+ DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+ errorMessages.getCreateTopicFail() + excp.getMessage());
+ LOGGER.info(errRes.toString());
+ throw new CambriaApiException(errRes);
-
+ }
+ }
}
diff --git a/src/main/java/com/att/nsa/dmaap/service/TransactionRestService.java b/src/main/java/com/att/nsa/dmaap/service/TransactionRestService.java
index a44c2ad..1a870a1 100644
--- a/src/main/java/com/att/nsa/dmaap/service/TransactionRestService.java
+++ b/src/main/java/com/att/nsa/dmaap/service/TransactionRestService.java
@@ -47,9 +47,9 @@ import com.att.nsa.cambria.utils.ConfigurationReader;
import com.att.nsa.configs.ConfigDbException;
/**
- * This class is a CXF REST service
- * which acts as gateway for DMaaP
- * Transaction Ids.
+ * This class is a CXF REST service which acts as gateway for DMaaP Transaction
+ * Ids.
+ *
* @author author
*
*/
@@ -84,10 +84,13 @@ public class TransactionRestService {
@Autowired
private TransactionService transactionService;
+ private DMaaPContext dmaapContext = new DMaaPContext();
+
/**
*
* Returns a list of all the existing Transaction Ids
- * @throws CambriaApiException
+ *
+ * @throws CambriaApiException
*
* @throws IOException
* @exception ConfigDbException
@@ -104,11 +107,10 @@ public class TransactionRestService {
LOGGER.info("Returning list of all transactions.");
} catch (ConfigDbException | IOException e) {
- LOGGER.error("Error while retrieving list of all transactions: "
- + e.getMessage(), e);
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
- DMaaPResponseCode.RETRIEVE_TRANSACTIONS.getResponseCode(),
- "Error while retrieving list of all transactions:"+e.getMessage());
+ LOGGER.error("Error while retrieving list of all transactions: " + e.getMessage(), e);
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
+ DMaaPResponseCode.RETRIEVE_TRANSACTIONS.getResponseCode(),
+ "Error while retrieving list of all transactions:" + e.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
}
@@ -121,7 +123,7 @@ public class TransactionRestService {
*
* @param transactionId
* - id of transaction
- * @throws CambriaApiException
+ * @throws CambriaApiException
* @throws IOException
* @exception ConfigDbException
* @exception IOException
@@ -131,22 +133,18 @@ public class TransactionRestService {
*/
@GET
@Path("/{transactionId}")
- public void getTransactionObj(
- @PathParam("transactionId") String transactionId) throws CambriaApiException {
+ public void getTransactionObj(@PathParam("transactionId") String transactionId) throws CambriaApiException {
LOGGER.info("Fetching details of Transaction ID : " + transactionId);
try {
- transactionService.getTransactionObj(getDmaapContext(),
- transactionId);
+ transactionService.getTransactionObj(getDmaapContext(), transactionId);
} catch (ConfigDbException | JSONException | IOException e) {
- LOGGER.error("Error while retrieving transaction details for id: "
- + transactionId, e);
-
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
- DMaaPResponseCode.RETRIEVE_TRANSACTIONS_DETAILS.getResponseCode(),
- "Error while retrieving transaction details for id: ["
- + transactionId + "]: " + e.getMessage());
+ LOGGER.error("Error while retrieving transaction details for id: " + transactionId, e);
+
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
+ DMaaPResponseCode.RETRIEVE_TRANSACTIONS_DETAILS.getResponseCode(),
+ "Error while retrieving transaction details for id: [" + transactionId + "]: " + e.getMessage());
LOGGER.info(errRes.toString());
throw new CambriaApiException(errRes);
@@ -165,8 +163,7 @@ public class TransactionRestService {
* Object,HttpServlet Object
*
*/
- private DMaaPContext getDmaapContext() {
- DMaaPContext dmaapContext = new DMaaPContext();
+ public DMaaPContext getDmaapContext() {
dmaapContext.setConfigReader(configReader);
dmaapContext.setRequest(request);
dmaapContext.setResponse(response);
diff --git a/src/test/java/com/att/nsa/dmaap/service/EventsRestServiceTest.java b/src/test/java/com/att/nsa/dmaap/service/EventsRestServiceTest.java
index ff90bd7..05d39ba 100644
--- a/src/test/java/com/att/nsa/dmaap/service/EventsRestServiceTest.java
+++ b/src/test/java/com/att/nsa/dmaap/service/EventsRestServiceTest.java
@@ -19,6 +19,8 @@
*/
package com.att.nsa.dmaap.service;
+import java.util.Date;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -28,20 +30,26 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import static org.mockito.Mockito.when;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.api.mockito.PowerMockito;
import com.att.ajsc.beans.PropertiesMapBean;
import com.att.nsa.cambria.CambriaApiException;
import com.att.nsa.cambria.backends.ConsumerFactory.UnavailableException;
+import com.att.nsa.cambria.exception.DMaaPErrorMessages;
import com.att.nsa.cambria.service.EventsService;
import com.att.nsa.configs.ConfigDbException;
+import com.att.nsa.cambria.utils.Utils;
+import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
-import static org.mockito.Mockito.when;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Date;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
@@ -61,10 +69,10 @@ public class EventsRestServiceTest {
@Mock
private EventsService eventsService;
-
+
@Mock
ErrorResponse errorResponse;
-
+
@Mock
DMaaPContext dmaapContext;
@@ -75,7 +83,10 @@ public class EventsRestServiceTest {
ServletInputStream servletInputStream;
@Mock
- HttpServletRequest httpServReq;
+ HttpServletRequest request;
+
+ @Mock
+ private DMaaPErrorMessages errorMessages;
@Before
public void setUp() throws Exception {
@@ -93,6 +104,59 @@ public class EventsRestServiceTest {
}
+ @Test
+ public void testGetEvents_error() {
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(eventsService).getEvents(dmaapContext, "topicName",
+ "consumergroup", "consumerid");
+ } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
+ | UnavailableException | IOException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException e) {
+ assertTrue(false);
+ }
+
+ try {
+ eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).getEvents(dmaapContext, "topicName",
+ "consumergroup", "consumerid");
+ } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
+ | UnavailableException | IOException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException e) {
+ assertTrue(false);
+ }
+
+ try {
+ eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).getEvents(dmaapContext,
+ "topicName", "consumergroup", "consumerid");
+ } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
+ | UnavailableException | IOException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException e) {
+ assertTrue(false);
+ }
+
+ try {
+ eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ }
+
@Test(expected = TopicExistsException.class)
public void testGetEvents_TopicExistException() throws CambriaApiException, ConfigDbException, TopicExistsException,
UnavailableException, IOException, AccessDeniedException {
@@ -103,10 +167,10 @@ public class EventsRestServiceTest {
eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");
}
-
+
@Test(expected = DMaaPAccessDeniedException.class)
- public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException, TopicExistsException,
- UnavailableException, IOException, AccessDeniedException {
+ public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException,
+ TopicExistsException, UnavailableException, IOException, AccessDeniedException {
Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(dmaapContext,
"topicName", "consumergroup", "consumerid");
@@ -114,17 +178,22 @@ public class EventsRestServiceTest {
eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");
}
-
- /*@Test(expected = DMaaPAccessDeniedException.class)
- public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException, TopicExistsException,
- UnavailableException, IOException, AccessDeniedException {
- Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(dmaapContext,
- "topicName", "consumergroup", "consumerid");
-
- eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");
-
- }*/
+ /*
+ * @Test(expected = DMaaPAccessDeniedException.class) public void
+ * testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException,
+ * ConfigDbException, TopicExistsException, UnavailableException,
+ * IOException, AccessDeniedException {
+ *
+ * Mockito.doThrow(new
+ * DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(
+ * dmaapContext, "topicName", "consumergroup", "consumerid");
+ *
+ * eventsService.getEvents(dmaapContext, "topicName", "consumergroup",
+ * "consumerid");
+ *
+ * }
+ */
@Test
public void testPushEvents() throws CambriaApiException {
@@ -132,7 +201,59 @@ public class EventsRestServiceTest {
eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
}
-
+
+ @Test
+ public void testPushEvents_error() {
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(eventsService).pushEvents(dmaapContext, "topicName", iStream,
+ "partitionKey", null);
+ } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
+ | missingReqdSetting | IOException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException e) {
+ assertTrue(false);
+ }
+
+ try {
+ eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).pushEvents(dmaapContext, "topicName",
+ iStream, "partitionKey", null);
+ } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
+ | missingReqdSetting | IOException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException e) {
+ assertTrue(false);
+ }
+
+ try {
+ eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(dmaapContext,
+ "topicName", iStream, "partitionKey", null);
+ } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
+ | missingReqdSetting | IOException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException e) {
+ assertTrue(false);
+ }
+
+ try {
+ eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ }
@Test
public void testPushEvents_TopicExistException() throws CambriaApiException {
@@ -143,11 +264,64 @@ public class EventsRestServiceTest {
@Test
public void tesTPushEventsWithTransaction() throws CambriaApiException, IOException {
- // when(dmaapContext.getRequest()).th
- // thenReturn(httpServReq);
- when(httpServReq.getInputStream()).thenReturn(servletInputStream);
+ when(request.getInputStream()).thenReturn(servletInputStream);
eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
}
+ @Test
+ public void tesTPushEventsWithTransaction_error() throws IOException {
+ when(request.getInputStream()).thenReturn(servletInputStream);
+ ServletInputStream stream = request.getInputStream();
+
+ try {
+ PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(dmaapContext,
+ "topicName", stream, "partitionKey", Utils.getFormattedDate(new Date()));
+ } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
+ | missingReqdSetting | IOException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException e) {
+ assertTrue(false);
+ }
+
+ try {
+ eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).pushEvents(dmaapContext, "topicName",
+ stream, "partitionKey", Utils.getFormattedDate(new Date()));
+ } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
+ | missingReqdSetting | IOException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException e) {
+ assertTrue(false);
+ }
+
+ try {
+ eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(eventsService).pushEvents(dmaapContext, "topicName", stream,
+ "partitionKey", Utils.getFormattedDate(new Date()));
+ } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException
+ | missingReqdSetting | IOException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException e) {
+ assertTrue(false);
+ }
+
+ try {
+ eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ }
+
}
diff --git a/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java b/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
index 6fa5592..d85ef9b 100644
--- a/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
+++ b/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
@@ -163,19 +163,23 @@ public class MMRestServiceTest {
public void testCallCreateMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
TopicExistsException, JSONException, ConfigDbException {
prepareForTestCommon();
-
- String sampleJson = "{\"test\":\"test\"}";
+
+ // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
+ // name:\"test\", consumer:\"test\", producer:\"test\",
+ // whitelist:\"test\",status:\"test\" }}";
+ String sampleJson = "{ messageID:\"test\", createMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
- mmRestService.callCreateMirrorMaker(iStream);
+ mmRestService.callCreateMirrorMaker(inputSteam);
assertTrue(true);
+
}
@Test
public void testCallListAllMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
TopicExistsException, JSONException, ConfigDbException {
prepareForTestCommon();
-
- String sampleJson = "{\"test\":\"test\"}";
+
+ String sampleJson = "{ messageID:\"test\", createMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\", whitelist:\"test\",status:\"test\" }}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
mmRestService.callListAllMirrorMaker(inputSteam);
assertTrue(true);
@@ -184,24 +188,28 @@ public class MMRestServiceTest {
@Test
public void testCallUpdateMirrorMaker() throws ConfigDbException, CambriaApiException {
prepareForTestCommon();
-
-
- mmRestService.callUpdateMirrorMaker(iStream);
+
+ String sampleJson = "{ messageID:\"test\", updateMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\"}}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callUpdateMirrorMaker(inputSteam);
assertTrue(true);
}
@Test
public void testCallDeleteMirrorMaker() throws ConfigDbException, CambriaApiException {
prepareForTestCommon();
- mmRestService.callDeleteMirrorMaker(iStream);
+
+ String sampleJson = "{ messageID:\"test\", deleteMirrorMaker: { name:\"test\", consumer:\"test\", producer:\"test\", whitelist:\"test\",status:\"test\" }}";
+ InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
+ mmRestService.callDeleteMirrorMaker(inputSteam);
assertTrue(true);
}
@Test
public void testListWhiteList() throws ConfigDbException {
prepareForTestCommon();
-
- String sampleJson = "{\"test\":\"test\"}";
+
+ String sampleJson = "{ name:\"test\", namespace:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
mmRestService.listWhiteList(inputSteam);
assertTrue(true);
@@ -210,9 +218,9 @@ public class MMRestServiceTest {
@Test
public void testCreateWhiteList() throws ConfigDbException {
prepareForTestCommon();
- String sampleJson = "{\"test\":\"test\"}";
+ String sampleJson = "{ name:\"test\", namespace:\"test\", whitelistTopicName:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
-
+
mmRestService.createWhiteList(inputSteam);
assertTrue(true);
}
@@ -220,13 +228,13 @@ public class MMRestServiceTest {
@Test
public void testDeleteWhiteList() throws ConfigDbException {
prepareForTestCommon();
-
- String sampleJson = "{\"test\":\"test\"}";
+
+ String sampleJson = "{ name:\"test\", namespace:\"test\", whitelistTopicName:\"test\"}}";
InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
mmRestService.deleteWhiteList(inputSteam);
assertTrue(true);
}
-
+
private void prepareForTestCommon() throws ConfigDbException {
Assert.assertNotNull(mmRestService);
PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);
@@ -239,6 +247,9 @@ public class MMRestServiceTest {
PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
.thenReturn("admin");
+ PowerMockito
+ .when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf.create"))
+ .thenReturn("aafcreate");
PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))
.thenReturn("admin");
@@ -265,6 +276,8 @@ public class MMRestServiceTest {
PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
+ PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "aafcreatetest|create"))
+ .thenReturn(true);
PowerMockito.when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);
diff --git a/src/test/java/com/att/nsa/dmaap/service/TopicRestServiceTest.java b/src/test/java/com/att/nsa/dmaap/service/TopicRestServiceTest.java
index abaac0f..8778602 100644
--- a/src/test/java/com/att/nsa/dmaap/service/TopicRestServiceTest.java
+++ b/src/test/java/com/att/nsa/dmaap/service/TopicRestServiceTest.java
@@ -185,6 +185,40 @@ public class TopicRestServiceTest {
topicService.getTopics();
}
+ @Test
+ public void testGetTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
+
+ Assert.assertNotNull(topicService);
+
+ PowerMockito.mockStatic(PropertiesMapBean.class);
+
+ assertTrue(true);
+ when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
+ .thenReturn("namespace");
+
+ PowerMockito.mockStatic(DMaaPResponseBuilder.class);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(httpServReq.getHeader("Authorization")).thenReturn(null);
+
+ when(dmaapContext.getResponse()).thenReturn(httpServRes);
+ String perms = "namespace" + "|" + "*" + "|" + "view";
+ when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
+
+ when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).getTopics(dmaapContext);
+ } catch (JSONException | ConfigDbException | IOException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.getTopics();
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
@Test(expected = DMaaPAccessDeniedException.class)
public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
TopicExistsException, JSONException, ConfigDbException {
@@ -228,6 +262,36 @@ public class TopicRestServiceTest {
topicService.getAllTopics();
}
+ @Test
+ public void testGetAllTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
+
+ Assert.assertNotNull(topicService);
+ PowerMockito.mockStatic(PropertiesMapBean.class);
+
+ assertTrue(true);
+ when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
+ .thenReturn("namespace");
+
+ PowerMockito.mockStatic(DMaaPResponseBuilder.class);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(httpServReq.getHeader("Authorization")).thenReturn(null);
+
+ when(dmaapContext.getResponse()).thenReturn(httpServRes);
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).getAllTopics(dmaapContext);
+ } catch (JSONException | ConfigDbException | IOException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.getAllTopics();
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
@Test(expected = DMaaPAccessDeniedException.class)
public void testGetTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
TopicExistsException, JSONException, ConfigDbException {
@@ -273,6 +337,37 @@ public class TopicRestServiceTest {
}
@Test
+ public void testGetTopic_error() throws DMaaPAccessDeniedException, ConfigDbException {
+
+ Assert.assertNotNull(topicService);
+
+ PowerMockito.mockStatic(PropertiesMapBean.class);
+
+ assertTrue(true);
+ when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
+ .thenReturn("enfTopicName");
+
+ PowerMockito.mockStatic(DMaaPResponseBuilder.class);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(httpServReq.getHeader("Authorization")).thenReturn(null);
+
+ when(dmaapContext.getResponse()).thenReturn(httpServRes);
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).getTopic(dmaapContext, "topicName");
+ } catch (TopicExistsException | ConfigDbException | IOException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.getTopic("topicName");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
public void testCreateTopic()
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
@@ -290,6 +385,62 @@ public class TopicRestServiceTest {
}
@Test
+ public void testCreateTopic_error() {
+
+ Assert.assertNotNull(topicService);
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).createTopic(dmaapContext, topicBean);
+ } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.createTopic(topicBean);
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new TopicExistsException("error")).when(tService).createTopic(dmaapContext, topicBean);
+ } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.createTopic(topicBean);
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new AccessDeniedException()).when(tService).createTopic(dmaapContext, topicBean);
+ } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ } catch (CambriaApiException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.createTopic(topicBean);
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
public void testDeleteTopic()
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
@@ -307,6 +458,48 @@ public class TopicRestServiceTest {
}
@Test
+ public void testDeleteTopic_error()
+ throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
+
+ Assert.assertNotNull(topicService);
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).deleteTopic(dmaapContext, "enfTopicNamePlusExtra");
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
+ | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.deleteTopic("enfTopicNamePlusExtra");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new AccessDeniedException()).when(tService).deleteTopic(dmaapContext,
+ "enfTopicNamePlusExtra");
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
+ | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.deleteTopic("enfTopicNamePlusExtra");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
public void testGetPublishersByTopicName()
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
@@ -324,6 +517,33 @@ public class TopicRestServiceTest {
}
@Test
+ public void testGetPublishersByTopicName_error() {
+
+ Assert.assertNotNull(topicService);
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).getPublishersByTopicName(dmaapContext,
+ "enfTopicNamePlusExtra");
+ } catch (TopicExistsException | ConfigDbException | IOException e) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.getPublishersByTopicName("enfTopicNamePlusExtra");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
public void testPermitPublisherForTopic()
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
@@ -341,6 +561,49 @@ public class TopicRestServiceTest {
}
@Test
+ public void testPermitPublisherForTopic_error()
+ throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
+
+ Assert.assertNotNull(topicService);
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).permitPublisherForTopic(dmaapContext,
+ "enfTopicNamePlusExtra", "producerID");
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
+ | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new AccessDeniedException()).when(tService).permitPublisherForTopic(dmaapContext,
+ "enfTopicNamePlusExtra", "producerID");
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
+ | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
public void testDenyPublisherForTopic()
throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
@@ -358,6 +621,50 @@ public class TopicRestServiceTest {
}
@Test
+ public void testDenyPublisherForTopic_error()
+ throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
+
+ Assert.assertNotNull(topicService);
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).denyPublisherForTopic(dmaapContext,
+ "enfTopicNamePlusExtra", "producerID");
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
+ | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new AccessDeniedException()).when(tService).denyPublisherForTopic(dmaapContext,
+ "enfTopicNamePlusExtra", "producerID");
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
+ | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+
+ }
+
+ @Test
public void testGetConsumersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
TopicExistsException, AccessDeniedException {
@@ -375,6 +682,34 @@ public class TopicRestServiceTest {
}
@Test
+ public void testGetConsumersByTopicName_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, AccessDeniedException {
+
+ Assert.assertNotNull(topicService);
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).getConsumersByTopicName(dmaapContext,
+ "enfTopicNamePlusExtra");
+ } catch (TopicExistsException | ConfigDbException | IOException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.getConsumersByTopicName("enfTopicNamePlusExtra");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
TopicExistsException, AccessDeniedException {
@@ -390,9 +725,9 @@ public class TopicRestServiceTest {
topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
}
-
+
@Test
- public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ public void testPermitConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
TopicExistsException, AccessDeniedException {
Assert.assertNotNull(topicService);
@@ -405,6 +740,35 @@ public class TopicRestServiceTest {
TopicBean topicBean = new TopicBean();
topicBean.setTopicName("enfTopicNamePlusExtra");
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).permitConsumerForTopic(dmaapContext,
+ "enfTopicNamePlusExtra", "consumerID");
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
+ | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException,
+ IOException, TopicExistsException, AccessDeniedException {
+
+ Assert.assertNotNull(topicService);
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
}
@@ -425,4 +789,47 @@ public class TopicRestServiceTest {
topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
}
+ @Test
+ public void testDenyConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, AccessDeniedException {
+
+ Assert.assertNotNull(topicService);
+
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(tService).denyConsumerForTopic(dmaapContext,
+ "enfTopicNamePlusExtra", "consumerID");
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
+ | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+
+ try {
+ PowerMockito.doThrow(new AccessDeniedException()).when(tService).denyConsumerForTopic(dmaapContext,
+ "enfTopicNamePlusExtra", "consumerID");
+ } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
+ | DMaaPAccessDeniedException excp) {
+ assertTrue(false);
+ }
+
+ try {
+ topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
+ } catch (CambriaApiException excp) {
+ assertTrue(true);
+ }
+ }
+
}
diff --git a/src/test/java/com/att/nsa/dmaap/service/TransactionRestServiceTest.java b/src/test/java/com/att/nsa/dmaap/service/TransactionRestServiceTest.java
index 701cb3c..0952c25 100644
--- a/src/test/java/com/att/nsa/dmaap/service/TransactionRestServiceTest.java
+++ b/src/test/java/com/att/nsa/dmaap/service/TransactionRestServiceTest.java
@@ -22,6 +22,7 @@ package com.att.nsa.dmaap.service;
import static org.junit.Assert.*;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -42,6 +43,8 @@ import com.att.nsa.cambria.service.EventsService;
import com.att.nsa.cambria.service.TransactionService;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
+import com.att.aft.dme2.internal.jettison.json.JSONException;
+import org.powermock.api.mockito.PowerMockito;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ PropertiesMapBean.class })
@@ -70,6 +73,7 @@ public class TransactionRestServiceTest {
public void testGetAllTransactionObjs() throws CambriaApiException {
transactionRestService.getAllTransactionObjs();
+ assertTrue(true);
}
@@ -77,6 +81,42 @@ public class TransactionRestServiceTest {
public void testGetTransactionObj() throws CambriaApiException {
transactionRestService.getTransactionObj("transactionId");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGetAllTransactionObjsError() throws CambriaApiException {
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(transactionService).getAllTransactionObjs(dmaapContext);
+ } catch (ConfigDbException | IOException e) {
+ assertTrue(false);
+ }
+
+ try {
+ transactionRestService.getAllTransactionObjs();
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
+
+ }
+
+ @Test
+ public void testGetTransactionObjError() {
+
+ try {
+ PowerMockito.doThrow(new IOException()).when(transactionService).getTransactionObj(dmaapContext,
+ "transactionId");
+ } catch (ConfigDbException | JSONException | IOException e) {
+ assertTrue(false);
+ }
+
+ try {
+ transactionRestService.getTransactionObj("transactionId");
+ } catch (CambriaApiException e) {
+ assertTrue(true);
+ }
}