package org.onap.policy.models.base;
+import com.google.re2j.Pattern;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.LinkedHashMap;
implements PfConceptGetter<C>, PfAuthorative<List<Map<String, A>>> {
private static final long serialVersionUID = -324211738823208318L;
+ private static final Pattern KEY_ID_PATTERN = Pattern.compile(PfKey.KEY_ID_REGEXP);
+
@EmbeddedId
private PfConceptKey key;
for (Entry<String, A> incomingConceptEntry : incomingConceptMap.entrySet()) {
PfConceptKey conceptKey = new PfConceptKey();
- if (incomingConceptEntry.getKey().matches(PfKey.KEY_ID_REGEXP)) {
+ if (KEY_ID_PATTERN.matches(incomingConceptEntry.getKey())) {
conceptKey = new PfConceptKey(incomingConceptEntry.getKey());
} else {
conceptKey.setName(incomingConceptEntry.getKey());
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
*/
public PfTimestampKey(@NonNull final PfTimestampKey copyConcept) {
super(copyConcept);
- this.timeStamp = new Date(copyConcept.getTimeStamp().getTime());
+ long millis = copyConcept.getTimeStamp().getTime();
+ this.timeStamp = new Date(millis);
}
/**
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
String errorMessage =
"Policy Framework DAO class not found for DAO plugin \"" + daoParameters.getPluginClass() + "\"";
- LOGGER.error(errorMessage, e);
+ LOGGER.error(errorMessage);
throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, e);
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
} catch (final Exception ex) {
String errorMessage = "Creation of Policy Framework persistence unit \""
+ daoParameters.getPersistenceUnit() + "\" failed";
- LOGGER.warn(errorMessage, ex);
+ LOGGER.warn(errorMessage);
throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ex);
}
LOGGER.debug("Created Policy Framework persistence unit \"{}\"", daoParameters.getPersistenceUnit());
try {
if (filterMap != null) {
- StringBuilder bld = new StringBuilder(filterQueryString);
- for (String key : filterMap.keySet()) {
- bld.append("c." + key + "= :" + key + AND);
- }
- filterQueryString = bld.toString();
+ filterQueryString = buildFilter(filterMap, filterQueryString);
}
filterQueryString = addKeyFilterString(filterQueryString, name, startTime, endTime);
if (getRecordNum > 0) {
}
}
+ private String buildFilter(final Map<String, Object> filterMap, String filterQueryString) {
+ StringBuilder bld = new StringBuilder(filterQueryString);
+ for (String key : filterMap.keySet()) {
+ bld.append("c." + key + "= :" + key + AND);
+ }
+ return bld.toString();
+ }
+
@Override
public <T extends PfConcept> T get(final Class<T> someClass, final PfConceptKey key) {
- if (someClass == null) {
- return null;
- }
- final EntityManager mg = getEntityManager();
- try {
- final T t = mg.find(someClass, key);
- if (t != null) {
- mg.refresh(t);
- }
- return checkAndReturn(someClass, t);
- } finally {
- mg.close();
- }
+ return genericGet(someClass, key);
}
@Override
public <T extends PfConcept> T get(final Class<T> someClass, final PfReferenceKey key) {
- if (someClass == null) {
- return null;
- }
- final EntityManager mg = getEntityManager();
- try {
- final T t = mg.find(someClass, key);
- if (t != null) {
- mg.refresh(t);
- }
- return checkAndReturn(someClass, t);
- } finally {
- mg.close();
- }
+ return genericGet(someClass, key);
}
@Override
public <T extends PfConcept> T get(final Class<T> someClass, final PfTimestampKey key) {
+ return genericGet(someClass, key);
+ }
+
+ private <T extends PfConcept> T genericGet(final Class<T> someClass, final Object key) {
if (someClass == null) {
return null;
}
final EntityManager mg = getEntityManager();
long size = 0;
try {
- size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class)
+ /*
+ * Concatenation should be safe because the class name should be safe, thus
+ * disabling sonar.
+ */
+ size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) // NOSONAR
.getSingleResult();
} finally {
mg.close();
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
package org.onap.policy.models.dao;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
pfDao.getConcept(PfReferenceKey.class, nullRefKey);
pfDao.size(null);
- pfDao.close();
+ assertThatCode(() -> pfDao.close()).doesNotThrowAnyException();
}
private void testAllOps() {
resultsArray = (JSONArray) responseObj.get("results");
}
for (int i = 0; i < resultsArray.length(); i++) {
- // Object is a vserver
- if (resultsArray.getJSONObject(i).has("vserver")) {
+ final JSONObject resultObject = resultsArray.getJSONObject(i);
+
+ extractVserver(resultObject);
+ extractGenericVnf(resultObject);
+ extractServiceInstance(resultObject);
+ extractVfModule(resultObject);
+ extractCloudRegion(resultObject);
+ extractTenant(resultObject);
+ extractModelVer(resultObject);
+ }
+ }
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("vserver").toString()));
+ private void extractVserver(final JSONObject resultObject) {
+ if (resultObject.has("vserver")) {
- // Getting the vserver pojo again from the json
- Vserver vserver = this.getAaiObject(json, Vserver.class);
- this.inventoryResponseItems.add(vserver);
- }
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("vserver").toString()));
- // Object is a Generic VNF
- if (resultsArray.getJSONObject(i).has(GENERIC_VNF)) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject(GENERIC_VNF).toString()));
+ // Getting the vserver pojo again from the json
+ Vserver vserver = this.getAaiObject(json, Vserver.class);
+ this.inventoryResponseItems.add(vserver);
+ }
+ }
- // Getting the generic vnf pojo again from the json
- GenericVnf genericVnf = this.getAaiObject(json, GenericVnf.class);
+ private void extractGenericVnf(final JSONObject resultObject) {
+ if (resultObject.has(GENERIC_VNF)) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject(GENERIC_VNF).toString()));
- this.inventoryResponseItems.add(genericVnf);
- }
+ // Getting the generic vnf pojo again from the json
+ GenericVnf genericVnf = this.getAaiObject(json, GenericVnf.class);
- // Object is a Service Instance
- if (resultsArray.getJSONObject(i).has("service-instance")) {
+ this.inventoryResponseItems.add(genericVnf);
+ }
+ }
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("service-instance").toString()));
+ private void extractServiceInstance(final JSONObject resultObject) {
+ if (resultObject.has("service-instance")) {
- // Getting the employee pojo again from the json
- ServiceInstance serviceInstance = this.getAaiObject(json, ServiceInstance.class);
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("service-instance").toString()));
- this.inventoryResponseItems.add(serviceInstance);
- }
+ // Getting the employee pojo again from the json
+ ServiceInstance serviceInstance = this.getAaiObject(json, ServiceInstance.class);
- // Object is a VF Module
- if (resultsArray.getJSONObject(i).has(VF_MODULE)) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject(VF_MODULE).toString()));
+ this.inventoryResponseItems.add(serviceInstance);
+ }
+ }
- // Getting the vf module pojo again from the json
- VfModule vfModule = this.getAaiObject(json, VfModule.class);
+ private void extractVfModule(final JSONObject resultObject) {
+ if (resultObject.has(VF_MODULE)) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject(VF_MODULE).toString()));
- this.inventoryResponseItems.add(vfModule);
- }
+ // Getting the vf module pojo again from the json
+ VfModule vfModule = this.getAaiObject(json, VfModule.class);
- // Object is a CloudRegion
- if (resultsArray.getJSONObject(i).has("cloud-region")) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("cloud-region").toString()));
+ this.inventoryResponseItems.add(vfModule);
+ }
+ }
- // Getting the cloud region pojo again from the json
- CloudRegion cloudRegion = this.getAaiObject(json, CloudRegion.class);
+ private void extractCloudRegion(final JSONObject resultObject) {
+ if (resultObject.has("cloud-region")) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("cloud-region").toString()));
- this.inventoryResponseItems.add(cloudRegion);
- }
+ // Getting the cloud region pojo again from the json
+ CloudRegion cloudRegion = this.getAaiObject(json, CloudRegion.class);
- // Object is a Tenant
- if (resultsArray.getJSONObject(i).has("tenant")) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("tenant").toString()));
+ this.inventoryResponseItems.add(cloudRegion);
+ }
+ }
- // Getting the tenant pojo again from the json
- Tenant tenant = this.getAaiObject(json, Tenant.class);
+ private void extractTenant(final JSONObject resultObject) {
+ if (resultObject.has("tenant")) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("tenant").toString()));
- this.inventoryResponseItems.add(tenant);
- }
+ // Getting the tenant pojo again from the json
+ Tenant tenant = this.getAaiObject(json, Tenant.class);
- // Object is a ModelVer
- if (resultsArray.getJSONObject(i).has("model-ver")) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("model-ver").toString()));
+ this.inventoryResponseItems.add(tenant);
+ }
+ }
- // Getting the ModelVer pojo again from the json
- ModelVer modelVer = this.getAaiObject(json, ModelVer.class);
+ private void extractModelVer(final JSONObject resultObject) {
+ if (resultObject.has("model-ver")) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("model-ver").toString()));
- this.inventoryResponseItems.add(modelVer);
- }
+ // Getting the ModelVer pojo again from the json
+ ModelVer modelVer = this.getAaiObject(json, ModelVer.class);
+ this.inventoryResponseItems.add(modelVer);
}
-
}
private <T> T getAaiObject(StreamSource json, final Class<T> classOfResponse) {
* ============LICENSE_START=======================================================
* appc
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.Collection;
import java.util.Map;
import java.util.UUID;
-
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode
public class CommonHeader implements Serializable {
private static final long serialVersionUID = -3581658269910980336L;
+ ", RequestId=" + requestId + ", SubrequestId=" + subRequestId + ", RequestTrack=" + requestTrack
+ ", Flags=" + flags + "]";
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
- result = prime * result + ((flags == null) ? 0 : flags.hashCode());
- result = prime * result + ((originatorId == null) ? 0 : originatorId.hashCode());
- result = prime * result + ((requestId == null) ? 0 : requestId.hashCode());
- result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode());
- result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
- result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- CommonHeader other = (CommonHeader) obj;
- if (apiVer == null) {
- if (other.apiVer != null) {
- return false;
- }
- } else if (!apiVer.equals(other.apiVer)) {
- return false;
- }
- if (flags == null) {
- if (other.flags != null) {
- return false;
- }
- } else if (!flags.equals(other.flags)) {
- return false;
- }
- if (originatorId == null) {
- if (other.originatorId != null) {
- return false;
- }
- } else if (!originatorId.equals(other.originatorId)) {
- return false;
- }
- if (requestId == null) {
- if (other.requestId != null) {
- return false;
- }
- } else if (!requestId.equals(other.requestId)) {
- return false;
- }
- if (requestTrack == null) {
- if (other.requestTrack != null) {
- return false;
- }
- } else if (!requestTrack.equals(other.requestTrack)) {
- return false;
- }
- if (subRequestId == null) {
- if (other.subRequestId != null) {
- return false;
- }
- } else if (!subRequestId.equals(other.subRequestId)) {
- return false;
- }
- if (timeStamp == null) {
- return other.timeStamp == null;
- } else {
- return timeStamp.equals(other.timeStamp);
- }
- }
}
* ============LICENSE_START=======================================================
* appc
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode
public class Request implements Serializable {
private static final long serialVersionUID = -3912323643990646431L;
// Initiate an empty Request instance
}
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((action == null) ? 0 : action.hashCode());
- result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
- result = prime * result + ((objectId == null) ? 0 : objectId.hashCode());
- result = prime * result + ((payload == null) ? 0 : payload.hashCode());
- result = prime * result + ((targetId == null) ? 0 : targetId.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
-
- Request other = (Request) obj;
- if (action == null) {
- if (other.action != null) {
- return false;
- }
- } else if (!action.equals(other.action)) {
- return false;
- }
-
- if (commonHeader == null) {
- if (other.commonHeader != null) {
- return false;
- }
- } else if (!commonHeader.equals(other.commonHeader)) {
- return false;
- }
-
- if (objectId == null) {
- if (other.objectId != null) {
- return false;
- }
- } else if (!objectId.equals(other.objectId)) {
- return false;
- }
-
- if (payload == null) {
- if (other.payload != null) {
- return false;
- }
- } else if (!payload.equals(other.payload)) {
- return false;
- }
-
- if (targetId == null) {
- if (other.targetId != null) {
- return false;
- }
- } else if (!targetId.equals(other.targetId)) {
- return false;
- }
-
- return true;
- }
-
@Override
public String toString() {
return "Request [CommonHeader=" + commonHeader + ", Action=" + action + ", TargetId=" + targetId + ", ObjectId="
* ============LICENSE_START=======================================================
* appc
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode
public class Response implements Serializable {
private static final long serialVersionUID = 434953706339865151L;
public String toString() {
return "Response [CommonHeader=" + commonHeader + ", Status=" + status + ", Payload=" + payload + "]";
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
- result = prime * result + ((payload == null) ? 0 : payload.hashCode());
- result = prime * result + ((status == null) ? 0 : status.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- Response other = (Response) obj;
- if (commonHeader == null) {
- if (other.commonHeader != null) {
- return false;
- }
- } else if (!commonHeader.equals(other.commonHeader)) {
- return false;
- }
- if (payload == null) {
- if (other.payload != null) {
- return false;
- }
- } else if (!payload.equals(other.payload)) {
- return false;
- }
- if (status == null) {
- return other.status == null;
- } else {
- return status.equals(other.status);
- }
- }
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Bell Canada.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
package org.onap.policy.cds.client;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@Test
public void testCdsProcessorGrpcClientConstructor() {
- new CdsProcessorGrpcClient(listener, props).close();
+ assertThatCode(() -> new CdsProcessorGrpcClient(listener, props).close()).doesNotThrowAnyException();
}
@Test(expected = IllegalStateException.class)
* ============LICENSE_START=======================================================
* controlloop
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
public static final String VFC = "VFC";
public static final String VNF = "VNF";
public static final String PNF = "PNF";
+
+ private ControlLoopTargetType() {
+ // do nothing
+ }
}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * controlloop
- * ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class ControlLoopTargetTypeTest {
-
- @Test
- public void test() {
- assertEquals(ControlLoopTargetType.VM, "VM");
- assertEquals(ControlLoopTargetType.VF, "VF");
- assertEquals(ControlLoopTargetType.VFC, "VFC");
- assertEquals(ControlLoopTargetType.VNF, "VNF");
- assertEquals(ControlLoopTargetType.PNF, "PNF");
- }
-}
* ============LICENSE_START=======================================================
* rest
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.rest;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.bind.DatatypeConverter;
}
String auth = username + ":" + (password == null ? "" : password);
- return "Basic " + DatatypeConverter.printBase64Binary(auth.getBytes(Charset.forName("ISO-8859-1")));
+ return "Basic " + DatatypeConverter.printBase64Binary(auth.getBytes(StandardCharsets.ISO_8859_1));
}
}
* ============LICENSE_START=======================================================
* sdc
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
private static final long serialVersionUID = -1249276698549996806L;
+ /*
+ * Note the field names ending in "UUID" may not be changed without breaking the
+ * interface, due to limitations in the YAML encoder/decoder.
+ */
private UUID serviceUUID;
private UUID serviceInvariantUUID;
private String serviceName;
* ============LICENSE_START=======================================================
* sdc
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
private static final long serialVersionUID = 6285260780966679625L;
+ /*
+ * Note the field names ending in "UUID" may not be changed without breaking the
+ * interface, due to limitations in the YAML encoder/decoder.
+ */
private UUID personaModelUUID;
private UUID serviceUUID;
private UUID serviceInstanceUUID;
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Huawei. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
package org.onap.policy.sdnc;
+import static org.junit.Assert.assertNotNull;
+
import org.junit.Test;
import org.onap.policy.sdnc.util.Serialization;
import org.slf4j.Logger;
body = Serialization.gsonPretty.toJson(response);
logger.info("{}", body);
+ assertNotNull(body);
}
}
* ================================================================================
* Copyright (C) 2018 Huawei. All rights reserved.
* ================================================================================
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.sdnc;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.endsWith;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.UUID;
private RestManager mockedRestManager;
private Pair<Integer, String> httpResponsePutOk;
- private Pair<Integer, String> httpResponseGetOk;
private Pair<Integer, String> httpResponseBadResponse;
private Pair<Integer, String> httpResponseErr;
mockedRestManager = mock(RestManager.class);
httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
- httpResponseGetOk = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
httpResponseErr = mockedRestManager.new Pair<>(200, null);
}
SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Exception");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Exception"), anyMap(),
anyString(), anyString())).thenThrow(new RuntimeException("OzException"));
+ Thread managerThread = new Thread(manager);
+ managerThread.start();
+
+ managerThread.join(1000);
- managerThread.join(100);
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Null");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Null"), anyMap(),
anyString(), anyString())).thenReturn(null);
- managerThread.join(100);
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Error0");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Error0"), anyMap(),
anyString(), anyString())).thenReturn(httpResponseErr);
- managerThread.join(100);
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "BadResponse");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("OK"), anyMap(),
anyString(), anyString())).thenReturn(httpResponseBadResponse);
- managerThread.join(100);
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "OOK");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("OK"), anyMap(),
anyString(), anyString())).thenReturn(httpResponsePutOk);
- when(mockedRestManager.get(endsWith("1234"), eq(DOROTHY), eq("OK"), anyMap()))
- .thenReturn(httpResponseGetOk);
-
+ manager.run();
- managerThread.join(100);
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Override
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode
public class PciCommonHeader implements Serializable {
private static final long serialVersionUID = 5435363539127062114L;
+ ", requestId=" + requestId + ", subRequestId=" + subRequestId + ", requestTrack=" + requestTrack
+ ", flags=" + flags + "]";
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
- result = prime * result + ((flags == null) ? 0 : flags.hashCode());
- result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode());
- result = prime * result + ((requestId == null) ? 0 : requestId.hashCode());
- result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
- result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- PciCommonHeader other = (PciCommonHeader) obj;
- if (apiVer == null) {
- if (other.apiVer != null) {
- return false;
- }
- } else if (!apiVer.equals(other.apiVer)) {
- return false;
- }
- if (flags == null) {
- if (other.flags != null) {
- return false;
- }
- } else if (!flags.equals(other.flags)) {
- return false;
- }
- if (requestTrack == null) {
- if (other.requestTrack != null) {
- return false;
- }
- } else if (!requestTrack.equals(other.requestTrack)) {
- return false;
- }
- if (requestId == null) {
- if (other.requestId != null) {
- return false;
- }
- } else if (!requestId.equals(other.requestId)) {
- return false;
- }
- if (subRequestId == null) {
- if (other.subRequestId != null) {
- return false;
- }
- } else if (!subRequestId.equals(other.subRequestId)) {
- return false;
- }
- if (timeStamp == null) {
- return other.timeStamp == null;
- } else {
- return timeStamp.equals(other.timeStamp);
- }
- }
}
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode
public class PciRequest implements Serializable {
private static final long serialVersionUID = 323235565922846624L;
public String toString() {
return "PciRequest[commonHeader=" + commonHeader + ", action=" + action + ", payload=" + payload + "]";
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
- result = prime * result + ((action == null) ? 0 : action.hashCode());
- result = prime * result + ((payload == null) ? 0 : payload.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- PciRequest other = (PciRequest) obj;
- if (commonHeader == null) {
- if (other.commonHeader != null) {
- return false;
- }
- } else if (!commonHeader.equals(other.commonHeader)) {
- return false;
- }
- if (action == null) {
- if (other.action != null) {
- return false;
- }
- } else if (!action.equals(other.action)) {
- return false;
- }
- if (payload == null) {
- return other.payload == null;
- } else {
- return payload.equals(other.payload);
- }
- }
}
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
package org.onap.policy.sdnr;
import java.io.Serializable;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode(callSuper = true)
public class PciRequestWrapper extends PciWrapper implements Serializable {
private static final long serialVersionUID = 879766924715980798L;
public String toString() {
return "RequestWrapper [body=" + body + ", toString()=" + super.toString() + "]";
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((body == null) ? 0 : body.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- PciRequestWrapper other = (PciRequestWrapper) obj;
- if (body == null) {
- return other.body == null;
- } else {
- return body.equals(other.body);
- }
- }
}
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode
public class PciResponse implements Serializable {
private static final long serialVersionUID = 8375708697287669750L;
return "PciResponse[CommonHeader=" + commonHeader + ", Status=" + status + ", Payload="
+ payload + "]";
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
- result = prime * result + ((payload == null) ? 0 : payload.hashCode());
- result = prime * result + ((status == null) ? 0 : status.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- PciResponse other = (PciResponse) obj;
- if (commonHeader == null) {
- if (other.commonHeader != null) {
- return false;
- }
- } else if (!commonHeader.equals(other.commonHeader)) {
- return false;
- }
- if (payload == null) {
- if (other.payload != null) {
- return false;
- }
- } else if (!payload.equals(other.payload)) {
- return false;
- }
- if (status == null) {
- return other.status == null;
- } else {
- return status.equals(other.status);
- }
- }
}
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
package org.onap.policy.sdnr;
import java.io.Serializable;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode(callSuper = true)
public class PciResponseWrapper extends PciWrapper implements Serializable {
private static final long serialVersionUID = 109837814781086802L;
public String toString() {
return "ResponseWrapper [body=" + body + ", toString()=" + super.toString() + "]";
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((body == null) ? 0 : body.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- PciResponseWrapper other = (PciResponseWrapper) obj;
- if (body == null) {
- return other.body == null;
- } else {
- return body.equals(other.body);
- }
- }
}
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode
public class PciWrapper implements Serializable {
private static final long serialVersionUID = 375215806432396532L;
return "Wrapper [version=" + version + ", cambriaPartition=" + cambriaPartition + ", rpcName=" + rpcName
+ ", correlationId=" + correlationId + ", type=" + type + "]";
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((cambriaPartition == null) ? 0 : cambriaPartition.hashCode());
- result = prime * result + ((correlationId == null) ? 0 : correlationId.hashCode());
- result = prime * result + ((rpcName == null) ? 0 : rpcName.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- result = prime * result + ((version == null) ? 0 : version.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- PciWrapper other = (PciWrapper) obj;
- if (cambriaPartition == null) {
- if (other.cambriaPartition != null) {
- return false;
- }
- } else if (!cambriaPartition.equals(other.cambriaPartition)) {
- return false;
- }
- if (correlationId == null) {
- if (other.correlationId != null) {
- return false;
- }
- } else if (!correlationId.equals(other.correlationId)) {
- return false;
- }
- if (rpcName == null) {
- if (other.rpcName != null) {
- return false;
- }
- } else if (!rpcName.equals(other.rpcName)) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- if (version == null) {
- return other.version == null;
- } else {
- return version.equals(other.version);
- }
- }
}
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode
public class Status implements Serializable {
private static final long serialVersionUID = 877641506135467199L;
public String toString() {
return "Status [code = " + code + ", value = " + value + "]";
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + code;
- result = prime * result + ((value == null) ? 0 : value.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- Status other = (Status) obj;
- if (code != other.code) {
- return false;
- }
- if (value == null) {
- return other.value == null;
- } else {
- return value.equals(other.value);
- }
- }
}
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
+@EqualsAndHashCode
public class SoRequestDetails implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
this.subscriberInfo = soRequestDetails.subscriberInfo;
}
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- SoRequestDetails other = (SoRequestDetails) obj;
- if (cloudConfiguration == null) {
- if (other.cloudConfiguration != null) {
- return false;
- }
- } else if (!cloudConfiguration.equals(other.cloudConfiguration)) {
- return false;
- }
- if (configurationParameters == null) {
- if (other.configurationParameters != null) {
- return false;
- }
- } else if (!configurationParameters.equals(other.configurationParameters)) {
- return false;
- }
- if (modelInfo == null) {
- if (other.modelInfo != null) {
- return false;
- }
- } else if (!modelInfo.equals(other.modelInfo)) {
- return false;
- }
- if (relatedInstanceList == null) {
- if (other.relatedInstanceList != null) {
- return false;
- }
- } else if (!relatedInstanceList.equals(other.relatedInstanceList)) {
- return false;
- }
- if (requestInfo == null) {
- if (other.requestInfo != null) {
- return false;
- }
- } else if (!requestInfo.equals(other.requestInfo)) {
- return false;
- }
- if (requestParameters == null) {
- if (other.requestParameters != null) {
- return false;
- }
- } else if (!requestParameters.equals(other.requestParameters)) {
- return false;
- }
- if (subscriberInfo == null) {
- return other.subscriberInfo == null;
- } else {
- return subscriberInfo.equals(other.subscriberInfo);
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((cloudConfiguration == null) ? 0 : cloudConfiguration.hashCode());
- result = prime * result + ((configurationParameters == null) ? 0 : configurationParameters.hashCode());
- result = prime * result + ((modelInfo == null) ? 0 : modelInfo.hashCode());
- result = prime * result + ((relatedInstanceList == null) ? 0 : relatedInstanceList.hashCode());
- result = prime * result + ((requestInfo == null) ? 0 : requestInfo.hashCode());
- result = prime * result + ((requestParameters == null) ? 0 : requestParameters.hashCode());
- result = prime * result + ((subscriberInfo == null) ? 0 : subscriberInfo.hashCode());
- return result;
- }
-
@Override
public String toString() {
return "SORequestDetails [modelInfo=" + modelInfo + ", cloudConfiguration=" + cloudConfiguration
--- /dev/null
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ Copyright (C) 2020 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=========================================================
+-->
+
+<configuration scan="true" scanPeriod="60 seconds" debug="false">
+
+ <contextName>ModelImplSo</contextName>
+ <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
+ <property name="LOG_DIR" value="${java.io.tmpdir}/pf_logging/" />
+
+ <!-- USE FOR STD OUT ONLY -->
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+</configuration>
* ============LICENSE_START=======================================================
* vfc
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.. All rights reserved.
* Modifications Copyright (C) 2018-2019 AT&T Corporation. All rights reserved.
* ================================================================================
package org.onap.policy.vfc;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.endsWith;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
private RestManager mockedRestManager;
private Pair<Integer, String> httpResponsePutOk;
- private Pair<Integer, String> httpResponseGetOk;
private Pair<Integer, String> httpResponseBadResponse;
private Pair<Integer, String> httpResponseErr;
mockedRestManager = mock(RestManager.class);
httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
- httpResponseGetOk = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
httpResponseErr = mockedRestManager.new Pair<>(200, null);
}
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Exception");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(
startsWith(SOME_URL),
eq(DOROTHY),
anyString()))
.thenThrow(new RuntimeException("OzException"));
- managerThread.join();
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Null");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOME_URL),
eq(DOROTHY), eq("Null"), anyMap(), anyString(), anyString()))
.thenReturn(null);
- managerThread.join();
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Error0");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOME_URL),
eq(DOROTHY), eq("Error0"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseErr);
- managerThread.join();
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "BadResponse");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOME_URL),
eq(DOROTHY), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseBadResponse);
- managerThread.join();
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Ok");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOME_URL),
eq(DOROTHY), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponsePutOk);
- when(mockedRestManager.get(endsWith("1234"), eq(DOROTHY), eq("OK"), anyMap()))
- .thenReturn(httpResponseGetOk);
+ manager.run();
- managerThread.join();
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Override
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
}
for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {
- if (matchPolicyTypesExactly && areListsIdentical(pdpSubGroup.getSupportedPolicyTypes(), typeFilter)) {
- return true;
- } else if (!matchPolicyTypesExactly
- && findSupportedPolicyType(pdpSubGroup.getSupportedPolicyTypes(), typeFilter)) {
+ if (matchPolicyTypesExactly) {
+ if (areListsIdentical(pdpSubGroup.getSupportedPolicyTypes(), typeFilter)) {
+ return true;
+ }
+ } else if (findSupportedPolicyType(pdpSubGroup.getSupportedPolicyTypes(), typeFilter)) {
return true;
}
}
}
for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {
- if (matchPoliciesExactly && areListsIdentical(pdpSubGroup.getPolicies(), policyFilter)) {
- return true;
- } else if (!matchPoliciesExactly && findSingleElement(pdpSubGroup.getPolicies(), policyFilter)) {
+ if (matchPoliciesExactly) {
+ if (areListsIdentical(pdpSubGroup.getPolicies(), policyFilter)) {
+ return true;
+ }
+ } else if (findSingleElement(pdpSubGroup.getPolicies(), policyFilter)) {
return true;
}
}
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
}
if (properties != null) {
- result = validateProperties(result);
+ validateProperties(result);
}
if (pdpSubGroups == null) {
/**
* Validate the properties.
*
- * @param resultIn the incoming validation results so far
- * @return the revalidation results including the property validation results
+ * @param result where to place any new validation results
*/
- private PfValidationResult validateProperties(PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ private void validateProperties(PfValidationResult result) {
for (Entry<String, String> propertyEntry : properties.entrySet()) {
if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
"a property value may not be null or blank"));
}
}
-
- return result;
}
@Override
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
package org.onap.policy.models.provider;
import javax.ws.rs.core.Response;
-
import lombok.NonNull;
-
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.dao.impl.DefaultPfDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class PolicyModelsProviderFactory {
- private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPfDao.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(PolicyModelsProviderFactory.class);
/**
* Creates a new PolicyModelsProvider object from its implementation.
} catch (final Exception exc) {
String errorMessage = "could not find implementation of the \"PolicyModelsProvider\" interface \""
+ parameters.getImplementation() + "\"";
- LOGGER.warn(errorMessage, exc);
+ LOGGER.warn(errorMessage);
throw new PfModelException(Response.Status.NOT_FOUND, errorMessage, exc);
}
} catch (Exception exc) {
String errorMessage =
"could not create an instance of PolicyModelsProvider \"" + parameters.getImplementation() + "\"";
- LOGGER.warn(errorMessage, exc);
+ LOGGER.warn(errorMessage);
throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, exc);
}
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
}
private String getValue(final String value) {
- if (value != null && value.matches("[$][{].*[}]$")) {
+ if (value != null && value.startsWith("${") && value.endsWith("}")) {
return System.getenv(value.substring(2, value.length() - 1));
}
return value;
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
} catch (final CoderException e) {
final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath()
+ "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage();
- LOGGER.error(errorMessage, e);
+ LOGGER.error(errorMessage);
throw new DmaapSimException(errorMessage, e);
}
package org.onap.policy.models.sim.dmaap.provider;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
// use a real provider so we can test the real makeTimer() method
DmaapSimProvider prov2 = new DmaapSimProvider(params);
prov2.start();
- prov2.stop();
+ assertThatCode(() -> prov2.stop()).doesNotThrowAnyException();
}
@Test
public void testMakeTopicData() {
// use a real provider so we can test the real makeTopicData() method
DmaapSimProvider prov2 = new DmaapSimProvider(params);
- prov2.processDmaapMessageGet(TOPIC1, CONSUMER1, CONSUMER_ID1, 0, 0);
+ assertThatCode(() -> prov2.processDmaapMessageGet(TOPIC1, CONSUMER1, CONSUMER_ID1, 0, 0))
+ .doesNotThrowAnyException();
}
@Test
/*
* ============LICENSE_START=======================================================
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.sim.dmaap.startstop;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@Test
public void testMain_Help() {
final String[] NormalParameters = {"-h"};
- Main.main(NormalParameters);
+ assertThatCode(() -> Main.main(NormalParameters)).doesNotThrowAnyException();
}
@Test
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
private List<TopicSink> topicSinks;// topics to which pdp sends pdp status
private List<TopicSource> topicSources; // topics to which pdp listens to for messages from pap.
private static final String[] MSG_TYPE_NAMES = { "messageName" };
- private static final Random RANDOM = new Random();
+
+ /*
+ * This simulator is only used for testing. Consequently, it is safe to use a simple
+ * random number generator, thus the sonar is disabled.
+ */
+ private static final Random RANDOM = new Random(); // NOSONAR
/**
* Listens for messages on the topic, decodes them into a message, and then dispatches them.
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
package org.onap.policy.models.sim.pdp;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
import org.junit.Test;
import org.powermock.reflect.Whitebox;
@Test
public void test() throws Exception {
// verify that constructor does not throw an exception
- Whitebox.invokeConstructor(PdpSimulatorConstants.class);
+ assertThatCode(() -> Whitebox.invokeConstructor(PdpSimulatorConstants.class)).doesNotThrowAnyException();
}
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
package org.onap.policy.models.sim.pdp;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@Test
public void testPdpSimulator_Help() {
final String[] pdpSimulatorConfigParameters = { "-h" };
- PdpSimulatorMain.main(pdpSimulatorConfigParameters);
+ assertThatCode(() -> PdpSimulatorMain.main(pdpSimulatorConfigParameters)).doesNotThrowAnyException();
}
@Test
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
this.fromAuthorative(authorativeConcept);
}
- @Override
- public abstract int compareTo(JpaToscaConstraint otherConstraint);
-
/**
* Create instances of constraints of various types.
*
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
PfValidationResult result = super.validate(resultIn);
if (constraints != null) {
- result = validateConstraints(result);
+ validateConstraints(result);
}
if (properties != null) {
/**
* Validate the constraints.
*
- * @param result The result of validations up to now
- * @return the validation result
+ * @param result where to put the validation results
*/
- private PfValidationResult validateConstraints(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
+ private void validateConstraints(@NonNull final PfValidationResult result) {
for (JpaToscaConstraint constraint : constraints) {
if (constraint == null) {
result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
"data type constraint may not be null "));
}
}
- return result;
}
/**
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
}
if (properties != null) {
- result = validateProperties(result);
+ validateProperties(result);
}
if (targets != null) {
/**
* Validate the policy properties.
*
- * @param result The result of validations up to now
- * @return the validation result
+ * @param result where to put the validation results
*/
- private PfValidationResult validateProperties(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ private void validateProperties(final PfValidationResult result) {
for (Entry<String, String> propertyEntry : properties.entrySet()) {
if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
"policy property value may not be null "));
}
}
- return result;
}
/**
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
assertThatThrownBy(() -> {
tdt.validate(null);
- }).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ }).hasMessageMatching("result is marked .*on.*ull but is null");
ToscaDataType dat = new ToscaDataType();
dat.setName("name");