summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pom.xml15
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java3
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java5
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java70
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsService.java267
-rw-r--r--src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java81
-rw-r--r--src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReqTest.java69
-rw-r--r--src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java50
-rw-r--r--src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java23
-rw-r--r--src/test/java/org/onap/clamp/clds/model/CldsDbServiceCacheTest.java30
-rw-r--r--src/test/java/org/onap/clamp/clds/service/CldsInfoProviderTest.java58
11 files changed, 419 insertions, 252 deletions
diff --git a/pom.xml b/pom.xml
index d849473d9..bc863d4f2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -543,6 +543,13 @@
<version>1.2.0</version>
<scope>test</scope>
</dependency>
+ <!-- TESTING -->
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.10.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
@@ -598,7 +605,7 @@
</resources>
<plugins>
- <!-- Scan Clamp code and generate the swagger.json file with all the
+ <!-- Scan Clamp code and generate the swagger.json file with all the
APIs -->
<plugin>
<groupId>com.sebastian-daschner</groupId>
@@ -618,8 +625,8 @@
</executions>
</plugin>
- <!-- Read the swagger.json file and the definition from SwaggerConfig.java;
- generate a list of .adoc files containing the APIs info in more structured
+ <!-- Read the swagger.json file and the definition from SwaggerConfig.java;
+ generate a list of .adoc files containing the APIs info in more structured
way -->
<plugin>
<groupId>io.github.swagger2markup</groupId>
@@ -654,7 +661,7 @@
</executions>
</plugin>
- <!-- Run the generated asciidoc through Asciidoctor to generate other
+ <!-- Run the generated asciidoc through Asciidoctor to generate other
documentation types, such as PDFs or HTML5 -->
<plugin>
<groupId>org.asciidoctor</groupId>
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java
index bf08a2395..2ebab88bb 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2018 Nokia
* ===================================================================
*
*/
@@ -320,6 +321,6 @@ public class OperationalPolicyReq {
if (prList == null || prList.isEmpty()) {
return new PolicyResult[0];
}
- return prList.stream().map(stringElem -> PolicyResult.toResult(stringElem)).toArray(PolicyResult[]::new);
+ return prList.stream().map(PolicyResult::toResult).toArray(PolicyResult[]::new);
}
} \ No newline at end of file
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
index 9cad683af..8796bae1c 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2018 Nokia
* ===================================================================
*
*/
@@ -149,10 +150,10 @@ public class SdcSingleController {
if (this.getControllerStatus() != SdcSingleControllerStatus.STOPPED) {
throw new SdcControllerException("The controller is already initialized, call the closeSDC method first");
}
- if (this.distributionClient == null) {
+ if (distributionClient == null) {
distributionClient = DistributionClientFactory.createDistributionClient();
}
- IDistributionClientResult result = this.distributionClient.init(sdcConfig, new SdcNotificationCallBack(this));
+ IDistributionClientResult result = distributionClient.init(sdcConfig, new SdcNotificationCallBack(this));
if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
logger.error("SDC distribution client init failed with reason:" + result.getDistributionMessageResult());
this.changeControllerStatus(SdcSingleControllerStatus.STOPPED);
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java b/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java
new file mode 100644
index 000000000..66890aa1f
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 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============================================
+ * Modifications copyright (c) 2018 Nokia
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.service;
+
+import static org.onap.clamp.clds.service.CldsService.RESOURCE_NAME;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import java.io.InputStream;
+import java.util.Properties;
+import org.onap.clamp.clds.model.CldsInfo;
+import org.onap.clamp.clds.util.ResourceFileUtil;
+
+class CldsInfoProvider {
+
+ private static final String CLDS_VERSION = "clds.version";
+ private final CldsService cldsService;
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(CldsInfoProvider.class);
+
+
+ CldsInfoProvider(CldsService cldsService) {
+ this.cldsService = cldsService;
+ }
+
+ CldsInfo getCldsInfo(){
+ CldsInfo cldsInfo = new CldsInfo();
+ cldsInfo.setUserName(cldsService.getUserName());
+ cldsInfo.setCldsVersion(getCldsVersionFromProps());
+
+ cldsInfo.setPermissionReadCl(cldsService.isAuthorizedNoException(cldsService.permissionReadCl));
+ cldsInfo.setPermissionUpdateCl(cldsService.isAuthorizedNoException(cldsService.permissionUpdateCl));
+ cldsInfo.setPermissionReadTemplate(cldsService.isAuthorizedNoException(cldsService.permissionReadTemplate));
+ cldsInfo.setPermissionUpdateTemplate(cldsService.isAuthorizedNoException(cldsService.permissionUpdateTemplate));
+ return cldsInfo;
+ }
+
+ private String getCldsVersionFromProps() {
+ String cldsVersion = "";
+ Properties props = new Properties();
+ try (InputStream resourceStream = ResourceFileUtil.getResourceAsStream(RESOURCE_NAME)) {
+ props.load(resourceStream);
+ cldsVersion = props.getProperty(CLDS_VERSION);
+ } catch (Exception ex) {
+ logger.error("Exception caught during the clds.version reading", ex);
+ }
+ return cldsVersion;
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java
index 7cc9af9b7..3bd771cd4 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2018 Nokia
* ===================================================================
*
*/
@@ -32,6 +33,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.io.InputStream;
import java.security.GeneralSecurityException;
+import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Properties;
@@ -86,6 +88,7 @@ import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl;
import org.onap.clamp.clds.transform.XslTransformer;
import org.onap.clamp.clds.util.JacksonUtils;
import org.onap.clamp.clds.util.LoggingUtils;
+import org.onap.clamp.clds.util.ResourceFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
@@ -101,49 +104,57 @@ public class CldsService extends SecureServiceBase {
@Produce(uri = "direct:processSubmit")
private CamelProxy camelProxy;
- protected static final EELFLogger securityLogger = EELFManager.getInstance().getSecurityLogger();
- private static final String RESOURCE_NAME = "clds-version.properties";
+ protected static final EELFLogger securityLogger = EELFManager.getInstance()
+ .getSecurityLogger();
+ static final String RESOURCE_NAME = "clds-version.properties";
public static final String GLOBAL_PROPERTIES_KEY = "files.globalProperties";
- @Value("${clamp.config.security.permission.type.cl:permission-type-cl}")
- private String cldsPersmissionTypeCl;
- @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}")
- private String cldsPermissionTypeClManage;
- @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}")
- private String cldsPermissionTypeClEvent;
- @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}")
- private String cldsPermissionTypeFilterVf;
- @Value("${clamp.config.security.permission.type.template:permission-type-template}")
- private String cldsPermissionTypeTemplate;
- @Value("${clamp.config.security.permission.instance:dev}")
- private String cldsPermissionInstance;
- private SecureServicePermission permissionReadCl;
- private SecureServicePermission permissionUpdateCl;
- private SecureServicePermission permissionReadTemplate;
- private SecureServicePermission permissionUpdateTemplate;
-
- @PostConstruct
- private final void afterConstruction() {
+ private final String cldsPersmissionTypeCl;
+ private final String cldsPermissionTypeClManage;
+ private final String cldsPermissionTypeClEvent;
+ private final String cldsPermissionTypeFilterVf;
+ private final String cldsPermissionTypeTemplate;
+ private final String cldsPermissionInstance;
+ final SecureServicePermission permissionReadCl;
+ final SecureServicePermission permissionUpdateCl;
+ final SecureServicePermission permissionReadTemplate;
+ final SecureServicePermission permissionUpdateTemplate;
+
+ private final CldsDao cldsDao;
+ private final XslTransformer cldsBpmnTransformer;
+ private final ClampProperties refProp;
+ private final SdcCatalogServices sdcCatalogServices;
+ private final DcaeDispatcherServices dcaeDispatcherServices;
+ private final DcaeInventoryServices dcaeInventoryServices;
+
+ @Autowired
+ public CldsService(CldsDao cldsDao, XslTransformer cldsBpmnTransformer, ClampProperties refProp,
+ SdcCatalogServices sdcCatalogServices, DcaeDispatcherServices dcaeDispatcherServices,
+ DcaeInventoryServices dcaeInventoryServices,
+ @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") String cldsPersmissionTypeCl,
+ @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}") String cldsPermissionTypeClManage,
+ @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}") String cldsPermissionTypeClEvent,
+ @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}") String cldsPermissionTypeFilterVf,
+ @Value("${clamp.config.security.permission.type.template:permission-type-template}") String cldsPermissionTypeTemplate,
+ @Value("${clamp.config.security.permission.instance:dev}") String cldsPermissionInstance
+ ) {
+ this.cldsDao = cldsDao;
+ this.cldsBpmnTransformer = cldsBpmnTransformer;
+ this.refProp = refProp;
+ this.sdcCatalogServices = sdcCatalogServices;
+ this.dcaeDispatcherServices = dcaeDispatcherServices;
+ this.dcaeInventoryServices = dcaeInventoryServices;
+ this.cldsPersmissionTypeCl = cldsPersmissionTypeCl;
+ this.cldsPermissionTypeClManage = cldsPermissionTypeClManage;
+ this.cldsPermissionTypeClEvent = cldsPermissionTypeClEvent;
+ this.cldsPermissionTypeFilterVf = cldsPermissionTypeFilterVf;
+ this.cldsPermissionTypeTemplate = cldsPermissionTypeTemplate;
+ this.cldsPermissionInstance = cldsPermissionInstance;
permissionReadCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "read");
permissionUpdateCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "update");
- permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance,
- "read");
- permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance,
- "update");
+ permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance, "read");
+ permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance, "update");
}
- @Autowired
- private CldsDao cldsDao;
- @Autowired
- private XslTransformer cldsBpmnTransformer;
- @Autowired
- private ClampProperties refProp;
- @Autowired
- private SdcCatalogServices sdcCatalogServices;
- @Autowired
- private DcaeDispatcherServices dcaeDispatcherServices;
- @Autowired
- private DcaeInventoryServices dcaeInventoryServices;
-
/*
* @return list of CLDS-Monitoring-Details: CLOSELOOP_NAME | Close loop name
* used in the CLDS application (prefix: ClosedLoop- + unique ClosedLoop ID)
@@ -176,28 +187,13 @@ public class CldsService extends SecureServiceBase {
@Path("/cldsInfo")
@Produces(MediaType.APPLICATION_JSON)
public CldsInfo getCldsInfo() {
- CldsInfo cldsInfo = new CldsInfo();
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsService: GET cldsInfo", getPrincipalName());
LoggingUtils.setTimeContext(startTime, new Date());
- // Get the user info
- cldsInfo.setUserName(getUserName());
- // Get CLDS application version
- String cldsVersion = "";
- Properties props = new Properties();
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try (InputStream resourceStream = loader.getResourceAsStream(RESOURCE_NAME)) {
- props.load(resourceStream);
- cldsVersion = props.getProperty("clds.version");
- } catch (Exception ex) {
- logger.error("Exception caught during the clds.version reading", ex);
- }
- cldsInfo.setCldsVersion(cldsVersion);
- // Get the user list of permissions
- cldsInfo.setPermissionReadCl(isAuthorizedNoException(permissionReadCl));
- cldsInfo.setPermissionUpdateCl(isAuthorizedNoException(permissionUpdateCl));
- cldsInfo.setPermissionReadTemplate(isAuthorizedNoException(permissionReadTemplate));
- cldsInfo.setPermissionUpdateTemplate(isAuthorizedNoException(permissionUpdateTemplate));
+
+ CldsInfoProvider cldsInfoProvider = new CldsInfoProvider(this);
+ CldsInfo cldsInfo = cldsInfoProvider.getCldsInfo();
+
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
LoggingUtils.setResponseContext("0", "Get cldsInfo success", this.getClass().getName());
@@ -224,11 +220,13 @@ public class CldsService extends SecureServiceBase {
cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
cldsHealthCheck.setHealthCheckStatus("UP");
cldsHealthCheck.setDescription("OK");
- LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName());
+ LoggingUtils
+ .setResponseContext("0", "Get healthcheck success", this.getClass().getName());
} catch (Exception e) {
healthcheckFailed = true;
logger.error("CLAMP application DB Error", e);
- LoggingUtils.setResponseContext("999", "Get healthcheck failed", this.getClass().getName());
+ LoggingUtils
+ .setResponseContext("999", "Get healthcheck failed", this.getClass().getName());
cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
cldsHealthCheck.setHealthCheckStatus("DOWN");
cldsHealthCheck.setDescription("NOT-OK");
@@ -237,7 +235,8 @@ public class CldsService extends SecureServiceBase {
LoggingUtils.setTimeContext(startTime, new Date());
logger.info("GET healthcheck completed");
if (healthcheckFailed) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(cldsHealthCheck).build();
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(cldsHealthCheck)
+ .build();
} else {
return Response.status(Response.Status.OK).entity(cldsHealthCheck).build();
}
@@ -343,18 +342,10 @@ public class CldsService extends SecureServiceBase {
logger.info("PUT propText={}", cldsModel.getPropText());
logger.info("PUT imageText={}", cldsModel.getImageText());
cldsModel.setName(modelName);
- if (cldsModel.getTemplateName() != null) {
- CldsTemplate template = cldsDao.getTemplate(cldsModel.getTemplateName());
- if (template != null) {
- cldsModel.setTemplateId(template.getId());
- cldsModel.setDocText(template.getPropText());
- // This is to provide the Bpmn XML when Template part in UI is
- // disabled
- cldsModel.setBpmnText(template.getBpmnText());
- }
- }
- updateAndInsertNewEvent(cldsModel.getName(), cldsModel.getControlNamePrefix(), cldsModel.getEvent(),
- CldsEvent.ACTION_MODIFY);
+ fillInCldsModel(cldsModel);
+ updateAndInsertNewEvent(cldsModel.getName(), cldsModel.getControlNamePrefix(),
+ cldsModel.getEvent(),
+ CldsEvent.ACTION_MODIFY);
cldsModel.save(cldsDao, getUserId());
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
@@ -420,16 +411,16 @@ public class CldsService extends SecureServiceBase {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response putModelAndProcessAction(@PathParam("action") String action,
- @PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model)
- throws TransformerException, ParseException {
+ @PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model)
+ throws TransformerException, ParseException {
Date startTime = new Date();
CldsModel retrievedModel = null;
Boolean errorCase = false;
try {
LoggingUtils.setRequestContext("CldsService: Process model action", getPrincipalName());
String actionCd = action.toUpperCase();
- SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage,
- cldsPermissionInstance, actionCd);
+ SecureServicePermission permisionManage = SecureServicePermission
+ .create(cldsPermissionTypeClManage, cldsPermissionInstance, actionCd);
isAuthorized(permisionManage);
isAuthorizedForVf(model);
String userId = getUserId();
@@ -444,7 +435,8 @@ public class CldsService extends SecureServiceBase {
this.fillInCldsModel(model);
// save model to db
model.setName(modelName);
- updateAndInsertNewEvent(modelName, model.getControlNamePrefix(), model.getEvent(), CldsEvent.ACTION_MODIFY);
+ updateAndInsertNewEvent(modelName, model.getControlNamePrefix(), model.getEvent(),
+ CldsEvent.ACTION_MODIFY);
model.save(cldsDao, getUserId());
// get vars and format if necessary
String prop = model.getPropText();
@@ -456,30 +448,27 @@ public class CldsService extends SecureServiceBase {
// Flag indicates whether it is triggered by Validation Test button
// from
// UI
- boolean isTest = false;
- if (test != null && test.equalsIgnoreCase("true")) {
- isTest = true;
- } else {
+ boolean isTest = Boolean.getBoolean(test);
+ if (!isTest) {
String actionTestOverride = refProp.getStringValue("action.test.override");
- if (actionTestOverride != null && actionTestOverride.equalsIgnoreCase("true")) {
+ if (Boolean.getBoolean(actionTestOverride)) {
logger.info("PUT actionTestOverride={}", actionTestOverride);
logger.info("PUT override test indicator and setting it to true");
isTest = true;
}
}
logger.info("PUT isTest={}", isTest);
- boolean isInsertTestEvent = false;
String insertTestEvent = refProp.getStringValue("action.insert.test.event");
- if (insertTestEvent != null && insertTestEvent.equalsIgnoreCase("true")) {
- isInsertTestEvent = true;
- }
+ boolean isInsertTestEvent = Boolean.getBoolean(insertTestEvent);
+
logger.info("PUT isInsertTestEvent={}", isInsertTestEvent);
// determine if requested action is permitted
model.validateAction(actionCd);
logger.info("modelProp - " + prop);
logger.info("docText - " + docText);
try {
- String result = camelProxy.submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest,
+ String result = camelProxy
+ .submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest,
userId, isInsertTestEvent, model.getEvent().getActionCd());
logger.info("Starting Camel flow on request, result is: ", result);
} catch (SdcCommunicationException | PolicyClientException | BadRequestException e) {
@@ -548,10 +537,7 @@ public class CldsService extends SecureServiceBase {
}
// Flag indicates whether it is triggered by Validation Test button from
// UI
- boolean isTest = false;
- if (test != null && test.equalsIgnoreCase("true")) {
- isTest = true;
- }
+ boolean isTest = Boolean.valueOf(test);
int instanceCount = 0;
if (dcaeEvent.getInstances() != null) {
instanceCount = dcaeEvent.getInstances().size();
@@ -761,14 +747,15 @@ public class CldsService extends SecureServiceBase {
return emptyServiceObjectNode;
}
- private void createVfObjectNode(ObjectNode vfObjectNode2, List<SdcResource> rawCldsSdcResourceList) {
+ private void createVfObjectNode(ObjectNode vfObjectNode2,
+ List<SdcResource> rawCldsSdcResourceList) {
ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();
ObjectNode vfNode = mapper.createObjectNode();
vfNode.put("", "");
// To remove repeated resource instance name from
// resourceInstanceList
List<SdcResource> cldsSdcResourceList = sdcCatalogServices
- .removeDuplicateSdcResourceInstances(rawCldsSdcResourceList);
+ .removeDuplicateSdcResourceInstances(rawCldsSdcResourceList);
/**
* Creating vf resource node using cldsSdcResource Object
*/
@@ -785,12 +772,14 @@ public class CldsService extends SecureServiceBase {
*/
ObjectNode locationJsonNode;
try {
- locationJsonNode = (ObjectNode) mapper.readValue(refProp.getStringValue("ui.location.default"),
+ locationJsonNode = (ObjectNode) mapper
+ .readValue(refProp.getStringValue("ui.location.default"),
JsonNode.class);
} catch (IOException e) {
- logger.error("Unable to load ui.location.default JSON in clds-references.properties properly", e);
+ logger.error(
+ "Unable to load ui.location.default JSON in clds-references.properties properly", e);
throw new CldsConfigException(
- "Unable to load ui.location.default JSON in clds-references.properties properly", e);
+ "Unable to load ui.location.default JSON in clds-references.properties properly", e);
}
vfObjectNode2.putPOJO("location", locationJsonNode);
/**
@@ -802,9 +791,10 @@ public class CldsService extends SecureServiceBase {
try {
alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class);
} catch (IOException e) {
- logger.error("Unable to ui.alarm.default JSON in clds-references.properties properly", e);
- throw new CldsConfigException("Unable to load ui.alarm.default JSON in clds-references.properties properly",
- e);
+ logger
+ .error("Unable to ui.alarm.default JSON in clds-references.properties properly", e);
+ throw new CldsConfigException(
+ "Unable to load ui.alarm.default JSON in clds-references.properties properly", e);
}
vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode);
}
@@ -840,12 +830,14 @@ public class CldsService extends SecureServiceBase {
fillInCldsModel(model);
String bpmnJson = cldsBpmnTransformer.doXslTransformToString(model.getBpmnText());
logger.info("PUT bpmnJson={}", bpmnJson);
- SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage,
+ SecureServicePermission permisionManage = SecureServicePermission
+ .create(cldsPermissionTypeClManage,
cldsPermissionInstance, CldsEvent.ACTION_DEPLOY);
isAuthorized(permisionManage);
isAuthorizedForVf(model);
- ModelProperties modelProp = new ModelProperties(modelName, model.getControlName(), CldsEvent.ACTION_DEPLOY,
- false, bpmnJson, model.getPropText());
+ ModelProperties modelProp = new ModelProperties(modelName, model.getControlName(),
+ CldsEvent.ACTION_DEPLOY,
+ false, bpmnJson, model.getPropText());
checkForDuplicateServiceVf(modelName, model.getPropText());
String deploymentId = "";
// If model is already deployed then pass same deployment id
@@ -854,9 +846,11 @@ public class CldsService extends SecureServiceBase {
} else {
deploymentId = "closedLoop_" + UUID.randomUUID() + "_deploymentId";
}
- String createNewDeploymentStatusUrl = dcaeDispatcherServices.createNewDeployment(deploymentId,
+ String createNewDeploymentStatusUrl = dcaeDispatcherServices
+ .createNewDeployment(deploymentId,
model.getTypeId(), modelProp.getGlobal().getDeployParameters());
- String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(createNewDeploymentStatusUrl);
+ String operationStatus = dcaeDispatcherServices
+ .getOperationStatusWithRetry(createNewDeploymentStatusUrl);
if ("succeeded".equalsIgnoreCase(operationStatus)) {
String artifactName = model.getControlName();
if (artifactName != null) {
@@ -866,16 +860,20 @@ public class CldsService extends SecureServiceBase {
/* set dcae events */
dcaeEvent.setArtifactName(artifactName);
dcaeEvent.setEvent(DcaeEvent.EVENT_DEPLOYMENT);
- CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), getUserId(), dcaeEvent.getCldsActionCd(),
- CldsEvent.ACTION_STATE_RECEIVED, null);
+ CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), getUserId(),
+ dcaeEvent.getCldsActionCd(),
+ CldsEvent.ACTION_STATE_RECEIVED, null);
model.setDeploymentId(deploymentId);
model.save(cldsDao, getUserId());
} else {
- logger.info("Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+ logger.info("Deploy model (" + modelName + ") failed...Operation Status is - "
+ + operationStatus);
throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR,
- "Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+ "Deploy model (" + modelName + ") failed...Operation Status is - "
+ + operationStatus);
}
- logger.info("Deploy model (" + modelName + ") succeeded...Deployment Id is - " + deploymentId);
+ logger.info(
+ "Deploy model (" + modelName + ") succeeded...Deployment Id is - " + deploymentId);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
LoggingUtils.setResponseContext("0", "Deploy model success", this.getClass().getName());
@@ -899,13 +897,16 @@ public class CldsService extends SecureServiceBase {
LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName());
Boolean errorCase = false;
try {
- SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage,
+ SecureServicePermission permisionManage = SecureServicePermission
+ .create(cldsPermissionTypeClManage,
cldsPermissionInstance, CldsEvent.ACTION_UNDEPLOY);
isAuthorized(permisionManage);
isAuthorizedForVf(model);
- String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(),
+ String operationStatusUndeployUrl = dcaeDispatcherServices
+ .deleteExistingDeployment(model.getDeploymentId(),
model.getTypeId());
- String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(operationStatusUndeployUrl);
+ String operationStatus = dcaeDispatcherServices
+ .getOperationStatusWithRetry(operationStatusUndeployUrl);
if ("succeeded".equalsIgnoreCase(operationStatus)) {
String artifactName = model.getControlName();
if (artifactName != null) {
@@ -915,19 +916,23 @@ public class CldsService extends SecureServiceBase {
// set dcae events
dcaeEvent.setArtifactName(artifactName);
dcaeEvent.setEvent(DcaeEvent.EVENT_UNDEPLOYMENT);
- CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), dcaeEvent.getCldsActionCd(),
- CldsEvent.ACTION_STATE_RECEIVED, null);
+ CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(),
+ dcaeEvent.getCldsActionCd(),
+ CldsEvent.ACTION_STATE_RECEIVED, null);
model.setDeploymentId(null);
model.save(cldsDao, getUserId());
} else {
- logger.info("Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+ logger.info("Undeploy model (" + modelName + ") failed...Operation Status is - "
+ + operationStatus);
throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR,
- "Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+ "Undeploy model (" + modelName + ") failed...Operation Status is - "
+ + operationStatus);
}
logger.info("Undeploy model (" + modelName + ") succeeded.");
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Undeploy model success", this.getClass().getName());
+ LoggingUtils
+ .setResponseContext("0", "Undeploy model success", this.getClass().getName());
auditLogger.info("Undeploy model completed");
} catch (Exception e) {
errorCase = true;
@@ -939,21 +944,26 @@ public class CldsService extends SecureServiceBase {
return Response.status(Response.Status.OK).entity(model).build();
}
- private void checkForDuplicateServiceVf(String modelName, String modelPropText) throws IOException {
- JsonNode globalNode = JacksonUtils.getObjectMapperInstance().readTree(modelPropText).get("global");
+ private void checkForDuplicateServiceVf(String modelName, String modelPropText)
+ throws IOException {
+ JsonNode globalNode = JacksonUtils.getObjectMapperInstance().readTree(modelPropText)
+ .get("global");
String service = AbstractModelElement.getValueByName(globalNode, "service");
List<String> resourceVf = AbstractModelElement.getValuesByName(globalNode, "vf");
if (service != null && resourceVf != null && !resourceVf.isEmpty()) {
List<CldsModelProp> cldsModelPropList = cldsDao.getDeployedModelProperties();
for (CldsModelProp cldsModelProp : cldsModelPropList) {
- JsonNode currentNode = JacksonUtils.getObjectMapperInstance().readTree(cldsModelProp.getPropText())
- .get("global");
+ JsonNode currentNode = JacksonUtils.getObjectMapperInstance()
+ .readTree(cldsModelProp.getPropText())
+ .get("global");
String currentService = AbstractModelElement.getValueByName(currentNode, "service");
List<String> currentVf = AbstractModelElement.getValuesByName(currentNode, "vf");
if (currentVf != null && !currentVf.isEmpty()) {
- if (!modelName.equalsIgnoreCase(cldsModelProp.getName()) && service.equalsIgnoreCase(currentService)
- && resourceVf.get(0).equalsIgnoreCase(currentVf.get(0))) {
- throw new BadRequestException("Same Service/VF already exists in " + cldsModelProp.getName()
+ if (!modelName.equalsIgnoreCase(cldsModelProp.getName()) && service
+ .equalsIgnoreCase(currentService)
+ && resourceVf.get(0).equalsIgnoreCase(currentVf.get(0))) {
+ throw new BadRequestException(
+ "Same Service/VF already exists in " + cldsModelProp.getName()
+ " model, please select different Service/VF.");
}
}
@@ -961,13 +971,14 @@ public class CldsService extends SecureServiceBase {
}
}
- private void updateAndInsertNewEvent(String cldsModelName, String cldsControlNamePrfx, CldsEvent event,
- String newAction) {
+ private void updateAndInsertNewEvent(String cldsModelName, String cldsControlNamePrfx,
+ CldsEvent event,
+ String newAction) {
// If model action is in submit/resubmit/distributed and user try
// to save then we are changing action back to create.
if (event != null && (CldsEvent.ACTION_SUBMIT.equalsIgnoreCase(event.getActionCd())
- || CldsEvent.ACTION_RESUBMIT.equalsIgnoreCase(event.getActionCd())
- || CldsEvent.ACTION_DISTRIBUTE.equalsIgnoreCase(event.getActionCd()))) {
+ || CldsEvent.ACTION_RESUBMIT.equalsIgnoreCase(event.getActionCd())
+ || CldsEvent.ACTION_DISTRIBUTE.equalsIgnoreCase(event.getActionCd()))) {
CldsEvent newEvent = new CldsEvent();
newEvent.setUserid(getUserId());
newEvent.setActionCd(newAction);
diff --git a/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java b/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java
deleted file mode 100644
index dac8705e8..000000000
--- a/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 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============================================
- * ===================================================================
- *
- */
-
-package org.onap.clamp.clds.client.req;
-
-import static org.junit.Assert.assertTrue;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.sdc.Resource;
-import org.onap.policy.sdc.ResourceType;
-
-public class OperationalPolicyReqTest {
-
- @Test
- public void convertToResourceTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
- IllegalArgumentException, InvocationTargetException {
- Method method = OperationalPolicyReq.class.getDeclaredMethod("convertToResource", List.class,
- ResourceType.class);
- method.setAccessible(true);
- // return method.invoke(targetObject, argObjects);
- List<String> stringList = new ArrayList<>();
- stringList.add("test1");
- stringList.add("test2");
- stringList.add("test3");
- stringList.add("test4");
- Resource[] resources = (Resource[]) method.invoke(null, stringList, ResourceType.VF);
-
- assertTrue(resources.length == 4);
- assertTrue("test1".equals(resources[0].getResourceName()));
- assertTrue("test2".equals(resources[1].getResourceName()));
- assertTrue("test3".equals(resources[2].getResourceName()));
- assertTrue("test4".equals(resources[3].getResourceName()));
- }
-
- @Test
- public void convertToPolicyResultTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
- IllegalArgumentException, InvocationTargetException {
- Method method = OperationalPolicyReq.class.getDeclaredMethod("convertToPolicyResult", List.class);
- method.setAccessible(true);
- // return method.invoke(targetObject, argObjects);
- List<String> stringList = new ArrayList<>();
- stringList.add("FAILURE");
- stringList.add("SUCCESS");
- stringList.add("FAILURE_GUARD");
- stringList.add("FAILURE_TIMEOUT");
- PolicyResult[] policyResult = (PolicyResult[]) method.invoke(null, stringList);
-
- assertTrue(policyResult.length == 4);
- assertTrue(policyResult[0].equals(PolicyResult.FAILURE));
- assertTrue(policyResult[1].equals(PolicyResult.SUCCESS));
- assertTrue(policyResult[2].equals(PolicyResult.FAILURE_GUARD));
- assertTrue(policyResult[3].equals(PolicyResult.FAILURE_TIMEOUT));
- }
-}
diff --git a/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReqTest.java b/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReqTest.java
new file mode 100644
index 000000000..d5e3069b2
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReqTest.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 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============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.client.req.policy;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.sdc.Resource;
+import org.onap.policy.sdc.ResourceType;
+
+public class OperationalPolicyReqTest {
+
+ @Test
+ public void shouldConvertGivenStringsToResourceObjects()
+ throws NoSuchMethodException, SecurityException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException {
+
+ //given
+ List<String> stringList = Arrays.asList("test1", "test2", "test3", "test4");
+
+ //when
+ Resource[] resources = OperationalPolicyReq.convertToResource(stringList, ResourceType.VF);
+
+ //then
+ assertThat(resources).extracting(Resource::getResourceName)
+ .containsExactly("test1", "test2", "test3", "test4");
+ }
+
+ @Test
+ public void shouldConvertGivenStringsToPolicyResults()
+ throws NoSuchMethodException, SecurityException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException {
+ //given
+ List<String> stringList = Arrays.asList("FAILURE", "SUCCESS", "FAILURE_GUARD", "FAILURE_TIMEOUT");
+
+ //when
+ PolicyResult[] policyResults = OperationalPolicyReq.convertToPolicyResult(stringList);
+
+ //then
+ assertThat(policyResults)
+ .containsExactly(PolicyResult.FAILURE, PolicyResult.SUCCESS,
+ PolicyResult.FAILURE_GUARD, PolicyResult.FAILURE_TIMEOUT);
+ }
+}
diff --git a/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java b/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
index ec5c196b9..c04357ded 100644
--- a/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
+++ b/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
@@ -17,15 +17,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2018 Nokia
* ===================================================================
*
*/
package org.onap.clamp.clds.config;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import java.util.Collections;
import org.junit.Test;
import org.onap.clamp.clds.service.CldsUser;
@@ -47,34 +50,49 @@ public class CldsUserJsonDecoderTest {
@Test
public void testDecodingDoubleUsers() {
+
+ //when
CldsUser[] usersArray = CldsUserJsonDecoder
- .decodeJson(CldsUserJsonDecoderTest.class.getResourceAsStream("/clds/clds-users-two-users.json"));
- assertEquals(usersArray.length, 2);
- assertEquals(usersArray[0].getUser(), user1);
- assertEquals(usersArray[1].getUser(), user2);
- assertEquals(usersArray[0].getPassword(), password);
- assertEquals(usersArray[1].getPassword(), password);
- assertArrayEquals(usersArray[0].getPermissionsString(), normalPermissionsArray);
- assertArrayEquals(usersArray[1].getPermissionsString(), normalPermissionsArray);
+ .decodeJson(CldsUserJsonDecoderTest.class.getResourceAsStream("/clds/clds-users-two-users.json"));
+
+ //then
+ assertThat(usersArray).hasSize(2);
+ assertThat(usersArray[0])
+ .extracting(CldsUser::getUser, CldsUser::getPassword, CldsUser::getPermissionsString)
+ .containsExactly(user1, password, normalPermissionsArray);
+
+ assertThat(usersArray[1])
+ .extracting(CldsUser::getUser, CldsUser::getPassword, CldsUser::getPermissionsString)
+ .containsExactly(user2, password, normalPermissionsArray);
+
}
@Test
public void testDecodingNoPermission() {
+ // when
CldsUser[] usersArray = CldsUserJsonDecoder
.decodeJson(this.getClass().getResourceAsStream("/clds/clds-users-no-permission.json"));
- assertEquals(usersArray.length, 1);
- assertEquals(usersArray[0].getUser(), user1);
- assertEquals(usersArray[0].getPassword(), null);
- assertArrayEquals(usersArray[0].getPermissionsString(), new String[0]);
+
+ //then
+ assertThat(usersArray).hasSize(1);
+ CldsUser user = usersArray[0];
+ assertThat(user.getUser()).isEqualTo(user1);
+ assertThat(user.getPassword()).isEqualTo(null);
+ assertThat(user.getPermissionsString()).isEmpty();
}
@Test
public void testDecodingIncompletePermissions() {
+
+ //when
CldsUser[] usersArray = CldsUserJsonDecoder
.decodeJson(this.getClass().getResourceAsStream("/clds/clds-users-incomplete-permissions.json"));
- assertEquals(usersArray.length, 1);
- assertEquals(usersArray[0].getUser(), user1);
- assertEquals(usersArray[0].getPassword(), password);
- assertArrayEquals(usersArray[0].getPermissionsString(), incompletePermissionsArray);
+
+ //then
+ assertThat(usersArray).hasSize(1);
+ CldsUser user = usersArray[0];
+ assertThat(user.getUser()).isEqualTo(user1);
+ assertThat(user.getPassword()).isEqualTo(password);
+ assertThat(user.getPermissionsString()).isEqualTo(incompletePermissionsArray);
}
}
diff --git a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java
index 00d5dffbb..1a1621271 100644
--- a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java
+++ b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java
@@ -16,10 +16,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2018 Nokia
+ * ================================================================================
+ *
*/
package org.onap.clamp.clds.config.sdc;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -43,7 +47,7 @@ import org.onap.clamp.clds.util.ResourceFileUtil;
public class SdcSingleControllerConfigurationTest {
private SdcSingleControllerConfiguration loadControllerConfiguration(String fileName, String sdcControllerName)
- throws JsonParseException, JsonMappingException, IOException {
+ throws IOException {
JsonNode jsonNode = new ObjectMapper().readValue(ResourceFileUtil.getResourceAsStream(fileName),
JsonNode.class);
SdcSingleControllerConfiguration sdcSingleControllerConfiguration = new SdcSingleControllerConfiguration(
@@ -63,17 +67,16 @@ public class SdcSingleControllerConfigurationTest {
assertEquals("hostname:8080", sdcConfig.getAsdcAddress());
assertEquals(10, sdcConfig.getPollingInterval());
assertEquals(30, sdcConfig.getPollingTimeout());
- assertEquals(SdcSingleControllerConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST.size(),
- sdcConfig.getRelevantArtifactTypes().size());
- assertTrue(sdcConfig.activateServerTLSAuth());
+
+ assertThat(SdcSingleControllerConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST)
+ .hasSameSizeAs(sdcConfig.getRelevantArtifactTypes());
assertEquals("ThePassword", sdcConfig.getKeyStorePassword());
- assertArrayEquals(new String[] {
- "localhost"
- }, sdcConfig.getMsgBusAddress().toArray());
+ assertTrue(sdcConfig.activateServerTLSAuth());
+ assertThat(sdcConfig.getMsgBusAddress()).contains("localhost");
}
@Test(expected = SdcParametersException.class)
- public final void testAllRequiredParameters() throws JsonParseException, JsonMappingException, IOException {
+ public final void testAllRequiredParameters() throws IOException {
SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
"sdc-controller1");
// No exception should be raised
@@ -84,7 +87,7 @@ public class SdcSingleControllerConfigurationTest {
@Test
public final void testAllRequiredParametersEmptyEncrypted()
- throws JsonParseException, JsonMappingException, IOException {
+ throws IOException {
SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration(
"clds/sdc-controller-config-empty-encrypted.json", "sdc-controller1");
sdcConfig.testAllRequiredParameters();
@@ -92,7 +95,7 @@ public class SdcSingleControllerConfigurationTest {
}
@Test
- public final void testConsumerGroupWithNull() throws JsonParseException, JsonMappingException, IOException {
+ public final void testConsumerGroupWithNull() throws IOException {
SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json",
"sdc-controller1");
assertTrue(sdcConfig.getConsumerGroup() == null);
diff --git a/src/test/java/org/onap/clamp/clds/model/CldsDbServiceCacheTest.java b/src/test/java/org/onap/clamp/clds/model/CldsDbServiceCacheTest.java
index 36563a25a..3fe29dc0f 100644
--- a/src/test/java/org/onap/clamp/clds/model/CldsDbServiceCacheTest.java
+++ b/src/test/java/org/onap/clamp/clds/model/CldsDbServiceCacheTest.java
@@ -17,12 +17,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2018 Nokia
* ===================================================================
*
*/
package org.onap.clamp.clds.model;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -30,38 +32,46 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
-
import org.junit.Test;
public class CldsDbServiceCacheTest {
@Test
public void testConstructor() throws IOException, ClassNotFoundException {
+ // given
CldsServiceData cldsServiceData = new CldsServiceData();
cldsServiceData.setServiceUUID("testUUID");
- cldsServiceData.setAgeOfRecord(Long.valueOf(100));
+ cldsServiceData.setAgeOfRecord(100L);
cldsServiceData.setServiceInvariantUUID("testInvariantUUID");
+
CldsVfData cldsVfData = new CldsVfData();
cldsVfData.setVfName("vf");
+
CldsVfKPIData cldsVfKpiData = new CldsVfKPIData();
cldsVfKpiData.setFieldPath("fieldPath");
cldsVfKpiData.setFieldPathValue("fieldValue");
+
List<CldsVfKPIData> cldsKpiList = new ArrayList<>();
cldsKpiList.add(cldsVfKpiData);
cldsVfData.setCldsKPIList(cldsKpiList);
+
List<CldsVfData> cldsVfs = new ArrayList<>();
cldsVfs.add(cldsVfData);
cldsServiceData.setCldsVfs(cldsVfs);
+
CldsDbServiceCache cldsDbServiceCache = new CldsDbServiceCache(cldsServiceData);
+
+ // when
ObjectInputStream reader = new ObjectInputStream(cldsDbServiceCache.getCldsDataInstream());
CldsServiceData cldsServiceDataResult = (CldsServiceData) reader.readObject();
- assertNotNull(cldsServiceDataResult);
- assertNotNull(cldsServiceDataResult.getCldsVfs());
- assertEquals(cldsServiceDataResult.getCldsVfs().size(), 1);
- assertNotNull(cldsServiceDataResult.getCldsVfs().get(0).getCldsKPIList());
- assertEquals(cldsServiceDataResult.getCldsVfs().get(0).getCldsKPIList().size(), 1);
- assertEquals(cldsServiceDataResult.getServiceInvariantUUID(), "testInvariantUUID");
- assertEquals(cldsServiceDataResult.getServiceUUID(), "testUUID");
- assertEquals(cldsServiceDataResult.getAgeOfRecord(), Long.valueOf(100L));
+
+ // then
+ assertThat(cldsServiceDataResult).isNotNull();
+ assertThat(cldsServiceDataResult.getCldsVfs()).hasSize(1);
+ assertThat(cldsServiceDataResult.getCldsVfs().get(0).getCldsKPIList()).hasSize(1);
+
+ assertThat(cldsServiceDataResult.getServiceInvariantUUID()).isEqualTo("testInvariantUUID");
+ assertThat(cldsServiceDataResult.getServiceUUID()).isEqualTo("testUUID");
+ assertThat(cldsServiceDataResult.getAgeOfRecord()).isEqualTo(100L);
}
}
diff --git a/src/test/java/org/onap/clamp/clds/service/CldsInfoProviderTest.java b/src/test/java/org/onap/clamp/clds/service/CldsInfoProviderTest.java
new file mode 100644
index 000000000..d5f7c15b6
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/service/CldsInfoProviderTest.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * 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.clamp.clds.service;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+import org.onap.clamp.clds.model.CldsInfo;
+
+
+public class CldsInfoProviderTest {
+
+ private static final String TEST_USERNAME = "TEST_USERNAME";
+
+ @Test
+ public void shouldProvideCldsInfoFromContext() throws Exception {
+
+ // given
+ CldsService serviceBase = mock(CldsService.class);
+ when(serviceBase.getUserName()).thenReturn(TEST_USERNAME);
+ when(serviceBase.isAuthorizedNoException(any())).thenReturn(true);
+ CldsInfoProvider cldsInfoProvider = new CldsInfoProvider(serviceBase);
+
+ // when
+ CldsInfo cldsInfo = cldsInfoProvider.getCldsInfo();
+
+ // then
+ assertThat(cldsInfo.getUserName()).isEqualTo(TEST_USERNAME);
+ assertThat(cldsInfo.isPermissionReadCl()).isTrue();
+ assertThat(cldsInfo.isPermissionReadTemplate()).isTrue();
+ assertThat(cldsInfo.isPermissionUpdateCl()).isTrue();
+ assertThat(cldsInfo.isPermissionUpdateTemplate()).isTrue();
+ }
+} \ No newline at end of file