From ebaab76841e7c7cfee0143e6c40c6e1ae3204309 Mon Sep 17 00:00:00 2001 From: Mukesh Paliwal Date: Tue, 24 May 2022 10:30:48 +0530 Subject: CodeCoverage improvement for dcaegen2-analytics-tca-gen2 Issue-ID: DCAEGEN2-3159 Signed-off-by: Mukesh Paliwal Change-Id: I0aaae42e30a83eac41957114a3090d584b43d42a --- .../dcae/analytics/model/DmaapMrConstantsTest.java | 33 +++++++++++ .../model/ecomplogger/AnalyticsErrorTypeTest.java | 34 +++++++++++ .../util/function/JsonStringToMapFunctionTest.java | 65 ++++++++++++++++++++++ .../function/JsonToJavaObjectBiFunctionTest.java | 48 ++++++++++++++++ .../util/function/StringToURLFunctionTest.java | 42 ++++++++++++++ .../util/function/URLToHttpGetFunctionTest.java | 40 +++++++++++++ .../util/json/mixin/cef/AlertTypeMixinTest.java | 13 ++++- .../model/util/json/mixin/cef/CriticalityTest.java | 34 +++++++++++ .../util/json/mixin/common/ConfigSourceTest.java | 35 ++++++++++++ .../supplier/AnalyticsRequestIdSupplierTest.java | 33 +++++++++++ .../supplier/CreationTimestampSupplierTest.java | 41 ++++++++++++++ .../model/util/supplier/RandomIdSupplierTest.java | 32 +++++++++++ .../model/util/supplier/UnboundedSupplierTest.java | 61 ++++++++++++++++++++ 13 files changed, 510 insertions(+), 1 deletion(-) create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/DmaapMrConstantsTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/ecomplogger/AnalyticsErrorTypeTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/JsonStringToMapFunctionTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/JsonToJavaObjectBiFunctionTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/StringToURLFunctionTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/URLToHttpGetFunctionTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CriticalityTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/common/ConfigSourceTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/AnalyticsRequestIdSupplierTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/CreationTimestampSupplierTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/RandomIdSupplierTest.java create mode 100644 dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/UnboundedSupplierTest.java (limited to 'dcae-analytics/dcae-analytics-model/src/test/java') diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/DmaapMrConstantsTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/DmaapMrConstantsTest.java new file mode 100644 index 0000000..2410eca --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/DmaapMrConstantsTest.java @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model; + +import org.junit.jupiter.api.Test; + +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DmaapMrConstantsTest { + @Test + public void DmaapHeadersTest () throws Exception { + Set dmaapConstatnts = DmaapMrConstants.getDmaapmappedHeaders(); + assertEquals("X-RequestID", dmaapConstatnts.iterator().next()); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/ecomplogger/AnalyticsErrorTypeTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/ecomplogger/AnalyticsErrorTypeTest.java new file mode 100644 index 0000000..157a447 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/ecomplogger/AnalyticsErrorTypeTest.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.ecomplogger; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AnalyticsErrorTypeTest { + @Test + public void getErrorCodeTest () throws Exception { + AnalyticsErrorType analyticsErrorType = AnalyticsErrorType.SCHEMA_ERROR; + int errCode = analyticsErrorType.getErrorCode(); + String errDesc = analyticsErrorType.getErrorDescription(); + assertEquals(400, errCode); + assertEquals("Schema Error", errDesc); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/JsonStringToMapFunctionTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/JsonStringToMapFunctionTest.java new file mode 100644 index 0000000..b2b75b6 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/JsonStringToMapFunctionTest.java @@ -0,0 +1,65 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.function; + +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class JsonStringToMapFunctionTest { + @Test + public void applyTest() throws Exception { + JsonStringToMapFunction jsonStringToMapFunction = new JsonStringToMapFunction(); + Map jObj = jsonStringToMapFunction.apply("{\"name\":\"test\",\"company\":\"test123\"}"); + assertEquals("test", jObj.get("name")); + } + + @Test + public void applyTestObject() throws Exception { + JsonStringToMapFunction jsonStringToMapFunction = new JsonStringToMapFunction(); + Map jObj = jsonStringToMapFunction. + apply("{\"name\":\"test\",\"company\":\"test123\",\"testObj\":{\"status\":\"true\"}}"); + assertEquals("test", jObj.get("name")); + } + + @Test + public void applyTestArray() throws Exception { + JsonStringToMapFunction jsonStringToMapFunction = new JsonStringToMapFunction(); + Map jObj = jsonStringToMapFunction. + apply("{\"name\":\"test\",\"company\":\"test123\",\"testObj\":[{\"status\":\"true\"}]}"); + assertEquals("test", jObj.get("name")); + } + + @Test + public void applyTest1() throws Exception { + JsonStringToMapFunction jsonStringToMapFunction = new JsonStringToMapFunction("abc"); + Map jObj = jsonStringToMapFunction.apply("{\"name\":\"test\",\"company\":\"test123\"}"); + assertEquals("test", jObj.get("abc.name")); + } + + @Test + public void applyTest2() throws Exception { + JsonStringToMapFunction jsonStringToMapFunction = new JsonStringToMapFunction("xyz", "|"); + Map jObj = jsonStringToMapFunction.apply("{\"name\":\"test\",\"company\":\"test123\"}"); + assertEquals("test123", jObj.get("xyz|company")); + } + +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/JsonToJavaObjectBiFunctionTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/JsonToJavaObjectBiFunctionTest.java new file mode 100644 index 0000000..6d4452d --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/JsonToJavaObjectBiFunctionTest.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.function; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import java.util.Map; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class JsonToJavaObjectBiFunctionTest { + @Test + public void apply () throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + JsonToJavaObjectBiFunction jsonToJavaObjectBiFunction = new JsonToJavaObjectBiFunction(objectMapper); + TypeReference stringTypeRef = new TypeReference(){}; + Optional optional = jsonToJavaObjectBiFunction.apply(stringTypeRef, "{\"name\":\"test\",\"company\":\"test123\"}"); + assertTrue(optional.isPresent()); + } + + @Test + public void applyError () throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + JsonToJavaObjectBiFunction jsonToJavaObjectBiFunction = new JsonToJavaObjectBiFunction(objectMapper); + TypeReference stringTypeRef = new TypeReference(){}; + Optional optional = jsonToJavaObjectBiFunction.apply(stringTypeRef, "{\"name\":\"test\",\"company\":\"test123\"}"); + assertTrue(optional.isEmpty()); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/StringToURLFunctionTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/StringToURLFunctionTest.java new file mode 100644 index 0000000..11fdb37 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/StringToURLFunctionTest.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.function; + +import org.junit.jupiter.api.Test; + +import java.net.URL; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class StringToURLFunctionTest { + @Test + public void apply () throws Exception { + StringToURLFunction stringToURLFunction = new StringToURLFunction (); + Optional optionalURL = stringToURLFunction.apply("https://localhost:8080/test"); + assertTrue(optionalURL.isPresent()); + } + + @Test + public void applyException () throws Exception { + StringToURLFunction stringToURLFunction = new StringToURLFunction (); + Optional optionalURL = stringToURLFunction.apply(""); + assertTrue(optionalURL.isEmpty()); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/URLToHttpGetFunctionTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/URLToHttpGetFunctionTest.java new file mode 100644 index 0000000..13a17f5 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/function/URLToHttpGetFunctionTest.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.function; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class URLToHttpGetFunctionTest { + @Test + public void apply () throws Exception { + URL url = new URL("http://localhost:8080"); + URLToHttpGetFunction urlToHttpGetFunction = new URLToHttpGetFunction(); + HttpURLConnection httpURLConnection = Mockito.mock(HttpURLConnection.class); + Mockito.when(httpURLConnection.getResponseCode()).thenReturn(200); + Optional optional = urlToHttpGetFunction.apply(url); + assertTrue(optional.isEmpty()); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixinTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixinTest.java index d3368de..ab19775 100644 --- a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixinTest.java +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixinTest.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ============LICENSE_START======================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Huawei. 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. @@ -19,6 +20,7 @@ package org.onap.dcae.analytics.model.util.json.mixin.cef; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion.ANALYTICS_MODEL_OBJECT_MAPPER; import org.assertj.core.api.Assertions; @@ -51,4 +53,13 @@ class AlertTypeMixinTest extends BaseAnalyticsModelTest { .isEqualTo(AlertType.CARD_ANOMALY); } + @Test + public void forvalueTest() throws Exception { + assertEquals(AlertType.CARD_ANOMALY, AlertTypeMixin.forValue("CARD-ANOMALY")); + assertEquals(AlertType.ELEMENT_ANOMALY, AlertTypeMixin.forValue("ELEMENT-ANOMALY")); + assertEquals(AlertType.INTERFACE_ANOMALY, AlertTypeMixin.forValue("INTERFACE-ANOMALY")); + assertEquals(AlertType.SERVICE_ANOMALY, AlertTypeMixin.forValue("SERVICE-ANOMALY")); + assertEquals(AlertType.UNKNOWN, AlertTypeMixin.forValue("UNKNOWN")); + } + } diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CriticalityTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CriticalityTest.java new file mode 100644 index 0000000..1defec7 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CriticalityTest.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.json.mixin.cef; + +import org.junit.jupiter.api.Test; +import org.onap.dcae.analytics.model.cef.Criticality; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CriticalityTest { + + @Test + public void testCriticality () throws Exception { + assertEquals("UNKNOWN", Criticality.UNKNOWN.toString()); + assertEquals("MAJ", Criticality.MAJ.toString()); + assertEquals("CRIT", Criticality.CRIT.toString()); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/common/ConfigSourceTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/common/ConfigSourceTest.java new file mode 100644 index 0000000..4051ca5 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/common/ConfigSourceTest.java @@ -0,0 +1,35 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.json.mixin.common; + +import org.junit.jupiter.api.Test; +import org.onap.dcae.analytics.model.common.ConfigSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ConfigSourceTest { + @Test + public void testConfigSource () throws Exception { + assertEquals("CONFIG_BINDING_SERVICE", ConfigSource.CONFIG_BINDING_SERVICE.toString()); + assertEquals("CLASSPATH", ConfigSource.CLASSPATH.toString()); + assertEquals("MONGO", ConfigSource.MONGO.toString()); + assertEquals("REDIS", ConfigSource.REDIS.toString()); + assertEquals("REST_API", ConfigSource.REST_API.toString()); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/AnalyticsRequestIdSupplierTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/AnalyticsRequestIdSupplierTest.java new file mode 100644 index 0000000..ce278d7 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/AnalyticsRequestIdSupplierTest.java @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.supplier; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class AnalyticsRequestIdSupplierTest { + @Test + public void getTest () throws Exception { + AnalyticsRequestIdSupplier analyticsRequestIdSupplier = + new AnalyticsRequestIdSupplier(); + String str = analyticsRequestIdSupplier.get(); + assertNotNull(str); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/CreationTimestampSupplierTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/CreationTimestampSupplierTest.java new file mode 100644 index 0000000..17134a5 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/CreationTimestampSupplierTest.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.supplier; + +import org.junit.jupiter.api.Test; + +import java.util.Date; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class CreationTimestampSupplierTest { + @Test + public void getTest () throws Exception { + CreationTimestampSupplier creationTimestampSupplier = + new CreationTimestampSupplier(); + String str = creationTimestampSupplier.get(); + assertNotNull(str); + } + + @Test + public void getParsedDateTest () throws Exception { + Date date = CreationTimestampSupplier.getParsedDate("2020-08-24T21:49:31.702+0400"); + assertNotNull(date.getTime()); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/RandomIdSupplierTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/RandomIdSupplierTest.java new file mode 100644 index 0000000..6805978 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/RandomIdSupplierTest.java @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.supplier; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class RandomIdSupplierTest { + @Test + public void getTest () throws Exception { + RandomIdSupplier randomIdSupplier = new RandomIdSupplier(100); + String maxNumber = randomIdSupplier.get(); + assertNotNull(maxNumber); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/UnboundedSupplierTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/UnboundedSupplierTest.java new file mode 100644 index 0000000..6b1fe7d --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/supplier/UnboundedSupplierTest.java @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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========================================================= + * + */ +package org.onap.dcae.analytics.model.util.supplier; + +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class UnboundedSupplierTest { + @Test + public void getTest () throws Exception { + Map str = new HashMap(); + str.put("name", "test"); + Map str2 = new HashMap(); + str2.put("name1", "test1"); + UnboundedSupplier unboundedSupplier = + new UnboundedSupplier(UnboundedSupplier.GenerationMode.ROUND_ROBIN, str, str2); + String s = unboundedSupplier.get().toString(); + assertTrue(unboundedSupplier.get().toString().contains("test")); + } + + @Test + public void getRandomTest () throws Exception { + Map str = new HashMap(); + str.put("name", "test"); + Map str2 = new HashMap(); + str2.put("name1", "test1"); + UnboundedSupplier unboundedSupplier = + new UnboundedSupplier(UnboundedSupplier.GenerationMode.RANDOM, str, str2); + String s = unboundedSupplier.get().toString(); + assertTrue(unboundedSupplier.get().toString().contains("test")); + } + + @Test + public void getTest1 () throws Exception { + Map str = new HashMap(); + str.put("name", "test"); + UnboundedSupplier unboundedSupplier = + new UnboundedSupplier(str); + assertTrue(unboundedSupplier.get().toString().contains("test")); + } +} -- cgit 1.2.3-korg