diff options
author | Ram Koya <rk541m@att.com> | 2018-08-29 14:14:48 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-08-29 14:14:48 +0000 |
commit | 8d860081e35507c1ef39d4ea062524a32f54cefe (patch) | |
tree | 72abeb593691e8d7a409fbcf42a20d940251a06c /datarouter-prov/src | |
parent | 5de761010725bb21a45c434a93a26748b9a3b6ba (diff) | |
parent | e240b998e7c4bff081abafe54d0d2aea73983f0b (diff) |
Merge "Add BaseLogRecord Unit Tests"
Diffstat (limited to 'datarouter-prov/src')
-rw-r--r-- | datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecordTest.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecordTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecordTest.java new file mode 100644 index 00000000..69016f24 --- /dev/null +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecordTest.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * ============LICENSE_START================================================== + * * org.onap.dmaap + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.dmaap.datarouter.provisioning.beans; + +import org.jetbrains.annotations.NotNull; +import org.junit.Assert; +import org.junit.Test; +import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject; + +import java.text.ParseException; + +public class BaseLogRecordTest { + + private BaseLogRecord baseLogRecord; + + @Test + public void Validate_Constructor_Creates_Object_With_Get_Methods() throws ParseException { + String[] args = {"2018-08-29-10-10-10-543.", "DLX", "238465493.fileName", + "1", "/publish/1/fileName", "285"}; + baseLogRecord = new BaseLogRecord(args); + Assert.assertEquals("238465493.fileName", baseLogRecord.getPublishId()); + Assert.assertEquals(1, baseLogRecord.getFeedid()); + Assert.assertEquals("", baseLogRecord.getRequestUri()); + Assert.assertEquals("GET", baseLogRecord.getMethod()); + Assert.assertEquals("", baseLogRecord.getContentType()); + Assert.assertEquals(285, baseLogRecord.getContentLength()); + } + + @Test + public void Validate_AsJsonObject_Correct_Json_Object_After_Set_Methods() throws ParseException { + String[] args = {"2018-08-29-10-10-10-543.", "DEL", "238465493.fileName", + "1", "", "/delete/1", "DELETE", "application/octet-stream", "285"}; + baseLogRecord = new BaseLogRecord(args); + baseLogRecord.setContentLength(265); + baseLogRecord.setEventTime(1535533810543L); + baseLogRecord.setPublishId("2345657324.fileName"); + baseLogRecord.setFeedid(2); + baseLogRecord.setRequestUri("/delete/2"); + baseLogRecord.setMethod("PUT"); + baseLogRecord.setContentType("application/json"); + LOGJSONObject baseLogRecordJson = createBaseLogRecordJson(); + String baseLogRecordString = stripBracketFromJson(baseLogRecordJson); + String baseLogRecordStringObject = stripBracketFromJson(baseLogRecord.asJSONObject()); + Assert.assertTrue(baseLogRecordStringObject.matches(baseLogRecordString)); + } + + private LOGJSONObject createBaseLogRecordJson() { + LOGJSONObject baseLogRecordJson = new LOGJSONObject(); + baseLogRecordJson.put("date", "2018-08-29T[0-1][0-9]:10:10.543Z"); + baseLogRecordJson.put("publishId", "2345657324.fileName"); + baseLogRecordJson.put("requestURI", "/delete/2"); + baseLogRecordJson.put("method", "PUT"); + baseLogRecordJson.put("contentType", "application/json"); + baseLogRecordJson.put("contentLength", 265); + return baseLogRecordJson; + } + + private String stripBracketFromJson(LOGJSONObject baseLogRecordJson) { + String baseLogRecordString = baseLogRecordJson.toString(); + baseLogRecordString = baseLogRecordString.substring(1, baseLogRecordString.length() - 1); + return baseLogRecordString; + } +} |