summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager/provider/src
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2019-10-07 08:11:34 +0200
committerZebek Bogumil <bogumil.zebek@nokia.com>2019-10-21 12:16:06 +0200
commitc7df5f53e2d525230170dc818572883de0bdf2ca (patch)
tree552b302141fc5183c39c17f82627005b3b3d2e53 /sdnr/wt/devicemanager/provider/src
parenta6557cbba03576e7593160fd2a6abe68f0af86b3 (diff)
Improve code quality
Issue-ID: CCSDK-1808 Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com> Change-Id: I004557c67b3440c41c00b6bf1a13e723f3ded0e4
Diffstat (limited to 'sdnr/wt/devicemanager/provider/src')
-rw-r--r--sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoder.java25
-rw-r--r--sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPm.java26
-rw-r--r--sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoderTest.java38
-rw-r--r--sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPmTest.java104
4 files changed, 171 insertions, 22 deletions
diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoder.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoder.java
index 2e8b44fd7..4decc24d7 100644
--- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoder.java
+++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoder.java
@@ -19,13 +19,16 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl;
class URLParamEncoder {
+ private URLParamEncoder() {
+ }
+
+ private static final String UNSAFE_CHARSET = " %$&+,/:;=?@<>#%";
+
public static String encode(String input) {
StringBuilder resultStr = new StringBuilder();
for (char ch : input.toCharArray()) {
if (isUnsafe(ch)) {
- resultStr.append('%');
- resultStr.append(toHex(ch / 16));
- resultStr.append(toHex(ch % 16));
+ resultStr.append(escape(ch));
} else {
resultStr.append(ch);
}
@@ -33,14 +36,18 @@ class URLParamEncoder {
return resultStr.toString();
}
- private static char toHex(int ch) {
- return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10);
- }
-
private static boolean isUnsafe(char ch) {
- if (ch > 128 || ch < 0) {
+ if (ch > 128) {
return true;
}
- return " %$&+,/:;=?@<>#%".indexOf(ch) >= 0;
+ return UNSAFE_CHARSET.indexOf(ch) >= 0;
+ }
+
+ private static String escape(char ch){
+ return String.format("%c%c%c", '%', toHex(ch / 16), toHex(ch % 16));
+ }
+
+ private static char toHex(int ch) {
+ return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10);
}
}
diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPm.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPm.java
index 196493cde..5c7cd03bd 100644
--- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPm.java
+++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPm.java
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/**
* ============LICENSE_START========================================================================
* ONAP : ccsdk feature sdnr wt
* =================================================================================================
@@ -6,28 +6,28 @@
* =================================================================================================
* 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
- *
+ * <p>
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
* 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.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container;
-import java.util.ArrayList;
-import java.util.List;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance24Hours;
-public class AllPm {
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
- private final static AllPm EMPTY = new AllPm();
+public class AllPm {
private final List<EsHistoricalPerformance15Minutes> pm15 = new ArrayList<>();
private final List<EsHistoricalPerformance24Hours> pm24 = new ArrayList<>();
@@ -41,19 +41,19 @@ public class AllPm {
}
public List<EsHistoricalPerformance15Minutes> getPm15() {
- return pm15;
+ return Collections.unmodifiableList(pm15);
}
public List<EsHistoricalPerformance24Hours> getPm24() {
- return pm24;
+ return Collections.unmodifiableList(pm24);
}
- public Object size() {
- return pm15.size()+pm24.size();
+ public int size() {
+ return pm15.size() + pm24.size();
}
public static AllPm getEmpty() {
- return EMPTY;
+ return new AllPm();
}
}
diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoderTest.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoderTest.java
new file mode 100644
index 000000000..cc4a43677
--- /dev/null
+++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoderTest.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk feature sdnr wt
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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=========================================================
+ ******************************************************************************/
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+
+public class URLParamEncoderTest {
+
+ @Test
+ public void shouldEncodeStringsToFormatAcceptableByURL(){
+ assertEquals("test", URLParamEncoder.encode("test"));
+ assertEquals("test%20str", URLParamEncoder.encode("test str"));
+ assertEquals("test%23%24str", URLParamEncoder.encode("test#$str"));
+ assertEquals("test%20%25%24%26%2B%2C%2F%3A%3B%3D%3F%40%3C%3E%23%25str", URLParamEncoder.encode("test %$&+,/:;=?@<>#%str"));
+
+ }
+}
diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPmTest.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPmTest.java
new file mode 100644
index 000000000..538dcd47a
--- /dev/null
+++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPmTest.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk feature sdnr wt
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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=========================================================
+ ******************************************************************************/
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance24Hours;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+
+public class AllPmTest {
+
+ private AllPm allPm;
+
+ @Before
+ public void setUp(){
+ allPm = AllPm.getEmpty();
+ }
+
+ @Test
+ public void shouldCreateEmptyInstance() {
+ assertEquals(0, allPm.size());
+ }
+
+
+ @Test
+ public void shouldBePossibleToAdd15MinutesPerformanceMeasurements() {
+ // given
+ final EsHistoricalPerformance15Minutes esHistoricalPerformance15Minutes_1 = mock(EsHistoricalPerformance15Minutes.class);
+ final EsHistoricalPerformance15Minutes esHistoricalPerformance15Minutes_2 = mock(EsHistoricalPerformance15Minutes.class);
+
+ allPm.add(esHistoricalPerformance15Minutes_1);
+ allPm.add(esHistoricalPerformance15Minutes_2);
+
+
+ // when
+ final List<EsHistoricalPerformance15Minutes> pm15size = allPm.getPm15();
+ final List<EsHistoricalPerformance24Hours> pm24size = allPm.getPm24();
+
+ // then
+ assertEquals(2, pm15size.size());
+ assertEquals(0, pm24size.size());
+ }
+
+ @Test
+ public void shouldBePossibleToAdd24HoursPerformanceMeasurements() {
+ // given
+ final EsHistoricalPerformance24Hours esHistoricalPerformance24Hours_1 = mock(EsHistoricalPerformance24Hours.class);
+ final EsHistoricalPerformance24Hours esHistoricalPerformance24Hours_2 = mock(EsHistoricalPerformance24Hours.class);
+
+ allPm.add(esHistoricalPerformance24Hours_1);
+ allPm.add(esHistoricalPerformance24Hours_2);
+
+
+ // when
+ final List<EsHistoricalPerformance15Minutes> pm15size = allPm.getPm15();
+ final List<EsHistoricalPerformance24Hours> pm24size = allPm.getPm24();
+
+ // then
+ assertEquals(0, pm15size.size());
+ assertEquals(2, pm24size.size());
+ }
+
+ @Test
+ public void shouldBePossibleToAddPerformanceMeasurements() {
+ // given
+ final EsHistoricalPerformance15Minutes esHistoricalPerformance15Minutes = mock(EsHistoricalPerformance15Minutes.class);
+ final EsHistoricalPerformance24Hours esHistoricalPerformance24Hours = mock(EsHistoricalPerformance24Hours.class);
+
+ allPm.add(esHistoricalPerformance15Minutes);
+ allPm.add(esHistoricalPerformance24Hours);
+
+ // when
+ final int size = allPm.size();
+
+ // then
+ assertEquals(2, size);
+ }
+
+
+}