aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors/actor.appclcm/src
diff options
context:
space:
mode:
authorGabriel <adam.krysiak@nokia.com>2018-08-31 11:20:43 +0200
committerGabriel <adam.krysiak@nokia.com>2018-09-05 14:46:22 +0200
commit09543cac5d1052d87adafaf55bd94475fd86ca68 (patch)
tree7850d55b0c5edb5a3e2ed92e8f6f71b45eccc2db /controlloop/common/actors/actor.appclcm/src
parent142e8876995fd51139fd79cdfa64b6e285f5fb08 (diff)
Add appc lcm request formatter
Formatter is used to dash case recipe in URL and camel case it in body. Issue-ID: POLICY-1083 Change-Id: I908ae93665f3d069b3a032ae378b7775ebe1110a Signed-off-by: Gabriel <adam.krysiak@nokia.com>
Diffstat (limited to 'controlloop/common/actors/actor.appclcm/src')
-rw-r--r--controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java12
-rw-r--r--controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java47
-rw-r--r--controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatterTest.java98
3 files changed, 152 insertions, 5 deletions
diff --git a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
index 1d4af389f..b4151a9f9 100644
--- a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
+++ b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
@@ -3,13 +3,14 @@
* AppcLcmActorServiceProvider
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications copyright (c) 2018 Nokia
* ================================================================================
* 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.
@@ -196,10 +197,12 @@ public class AppcLcmActorServiceProvider implements Actor {
* The actual LCM request is placed in a wrapper used to send through dmaap. The current
* version is 2.0 as of R1.
*/
+ AppcLcmRecipeFormatter lcmRecipeFormatter = new AppcLcmRecipeFormatter(policy.getRecipe());
+
LcmRequestWrapper dmaapRequest = new LcmRequestWrapper();
dmaapRequest.setVersion("2.0");
dmaapRequest.setCorrelationId(onset.getRequestId() + "-" + operation.getSubRequestId());
- dmaapRequest.setRpcName(policy.getRecipe().toLowerCase());
+ dmaapRequest.setRpcName(lcmRecipeFormatter.getUrlRecipe());
dmaapRequest.setType("request");
/* This is the actual request that is placed in the dmaap wrapper. */
@@ -226,8 +229,7 @@ public class AppcLcmActorServiceProvider implements Actor {
* An action is required for all APPC requests, this will be the recipe specified in the
* policy.
*/
- appcRequest.setAction(
- policy.getRecipe().substring(0, 1).toUpperCase() + policy.getRecipe().substring(1).toLowerCase());
+ appcRequest.setAction(lcmRecipeFormatter.getBodyRecipe());
/*
* For R1, the payloads will not be required for the Restart, Rebuild, or Migrate recipes.
diff --git a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java
new file mode 100644
index 000000000..c9feb0d2a
--- /dev/null
+++ b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java
@@ -0,0 +1,47 @@
+/*
+ * ============LICENSE_START=======================================================
+ *
+ * ================================================================================
+ * Copyright (C) 2018 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.policy.controlloop.actor.appclcm;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.stream.Collectors;
+
+class AppcLcmRecipeFormatter {
+
+ private final String dashCasedRecipe;
+
+ AppcLcmRecipeFormatter(String dashCasedRecipe) {
+ this.dashCasedRecipe = dashCasedRecipe;
+ }
+
+ String getUrlRecipe() {
+ return dashCasedRecipe.toLowerCase();
+ }
+
+ String getBodyRecipe() {
+ return Lists.newArrayList(dashCasedRecipe.split("-"))
+ .stream()
+ .map(String::toLowerCase)
+ .map(StringUtils::capitalize)
+ .collect(Collectors.joining(""));
+ }
+}
diff --git a/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatterTest.java b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatterTest.java
new file mode 100644
index 000000000..e63b04acd
--- /dev/null
+++ b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatterTest.java
@@ -0,0 +1,98 @@
+/*
+ * ============LICENSE_START=======================================================
+ *
+ * ================================================================================
+ * Copyright (C) 2018 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.policy.controlloop.actor.appclcm;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+
+public class AppcLcmRecipeFormatterTest {
+
+ @Test
+ public void shouldCorrectlyFormatRestartRequestWhenRestartGiven() {
+ //given
+ AppcLcmRecipeFormatter recipeFormatter = new AppcLcmRecipeFormatter("Restart");
+ String expectedUrlRecipe = "restart";
+ String expectedBodyRecipe = "Restart";
+
+ //when
+ String actualUrlRecipe = recipeFormatter.getUrlRecipe();
+ String actualBodyRecipe = recipeFormatter.getBodyRecipe();
+
+ //then
+ assertEquals(expectedUrlRecipe, actualUrlRecipe);
+ assertEquals(expectedBodyRecipe, actualBodyRecipe);
+ }
+
+ @Test
+ public void shouldReturnCapitalizedBodySingleWordRecipe() {
+ //given
+ AppcLcmRecipeFormatter recipeFormatter = new AppcLcmRecipeFormatter("moDify");
+ String expectedRecipe = "Modify";
+
+ //when
+ String actualRecipe = recipeFormatter.getBodyRecipe();
+
+ //then
+ assertEquals(expectedRecipe, actualRecipe);
+ }
+
+ @Test
+ public void shouldReturnCapitalizeAndJoinedBodyMultiWordRecipe() {
+ //given
+ AppcLcmRecipeFormatter recipeFormatter = new AppcLcmRecipeFormatter("coNfig-moDify");
+ String expectedRecipe = "ConfigModify";
+
+ //when
+ String actualRecipe = recipeFormatter.getBodyRecipe();
+
+ //then
+ assertEquals(expectedRecipe, actualRecipe);
+ }
+
+ @Test
+ public void shouldReturnLowercasedUrlSingleWordRecipe() {
+ //given
+ AppcLcmRecipeFormatter recipeFormatter = new AppcLcmRecipeFormatter("ModIfy");
+ String expectedRecipe = "modify";
+
+ //when
+ String actualRecipe = recipeFormatter.getUrlRecipe();
+
+ //then
+ assertEquals(expectedRecipe, actualRecipe);
+ }
+
+ @Test
+ public void shouldReturnLowercasedDashJoinedUrlMultiWordRecipe() {
+ //given
+ AppcLcmRecipeFormatter recipeFormatter = new AppcLcmRecipeFormatter("Config-MoDify");
+ String expectedRecipe = "config-modify";
+
+ //when
+ String actualRecipe = recipeFormatter.getUrlRecipe();
+
+ //then
+ assertEquals(expectedRecipe, actualRecipe);
+ }
+} \ No newline at end of file