(followed:onap-java-style) removed redundant code. merged all changes in one commit for one repo.
Issue-Id:DCAEGEN2-92
Change-Id: I072e02dbedd93c01fcf3a297170cb2f7286b3b72
Signed-off-by: Bharat saraswal <bharat.saraswal@huawei.com>
27 files changed:
* @return return true if Dynamic Properties are present
*/
public boolean isDynamicPropertiesPresent() {
* @return return true if Dynamic Properties are present
*/
public boolean isDynamicPropertiesPresent() {
- return dynamicProperties.size() == 0;
+ return dynamicProperties.isEmpty();
*/
public interface DynamicPropertiesProvider extends DCAEAnalyticsModel {
*/
public interface DynamicPropertiesProvider extends DCAEAnalyticsModel {
/**
* Adds dynamic properties in a Map object
*
/**
* Adds dynamic properties in a Map object
*
*/
public enum AlertAction implements CEFModel {
*/
public enum AlertAction implements CEFModel {
SERVICE_ANOMALY("SERVICE-ANOMALY"),
UNKNOWN(null);
SERVICE_ANOMALY("SERVICE-ANOMALY"),
UNKNOWN(null);
+ private final String name;
AlertType(String name) {
this.name = name;
AlertType(String name) {
this.name = name;
public String getName() {
return name;
}
public String getName() {
return name;
}
@Data
@EqualsAndHashCode(callSuper = true)
public abstract class BaseCEFModel extends BaseDynamicPropertiesProvider implements CEFModel {
@Data
@EqualsAndHashCode(callSuper = true)
public abstract class BaseCEFModel extends BaseDynamicPropertiesProvider implements CEFModel {
* @author Rajiv Singla. Creation Date: 08/15/2017.
*/
public interface CEFModel extends DCAEAnalyticsModel {
* @author Rajiv Singla. Creation Date: 08/15/2017.
*/
public interface CEFModel extends DCAEAnalyticsModel {
*/
public enum Criticality implements CEFModel {
*/
public enum Criticality implements CEFModel {
private CommonEventHeader commonEventHeader;
/**
private CommonEventHeader commonEventHeader;
/**
- * MeasurementsForVfScaling fields
+ * Measurements for Vf scaling fields
*
* @param measurementsForVfScalingFields New value for MeasurementsForVfScaling
* @return MeasurementsForVfScaling fields
*
* @param measurementsForVfScalingFields New value for MeasurementsForVfScaling
* @return MeasurementsForVfScaling fields
private MeasurementsForVfScalingFields measurementsForVfScalingFields;
/**
private MeasurementsForVfScalingFields measurementsForVfScalingFields;
/**
- * Threshold crossing Fields
+ * Threshold crossing alert Fields.
*
* @param thresholdCrossingAlertFields New value for Threshold crossing Fields
* @return Threshold crossing Fields
*/
private ThresholdCrossingAlertFields thresholdCrossingAlertFields;
*
* @param thresholdCrossingAlertFields New value for Threshold crossing Fields
* @return Threshold crossing Fields
*/
private ThresholdCrossingAlertFields thresholdCrossingAlertFields;
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
* Common Event Format - Event
*
* @param event New value for Event
* @return Common Event Format Event
*/
private Event event;
* Common Event Format - Event
*
* @param event New value for Event
* @return Common Event Format Event
*/
private Event event;
public class PerformanceCounter extends BaseCEFModel {
private static final long serialVersionUID = 1L;
public class PerformanceCounter extends BaseCEFModel {
private static final long serialVersionUID = 1L;
- * Performance Counter Criticality
+ * Performance Counter Criticality.
*
* @param criticality New value for Criticality
* @return Performance Counter Criticality
*/
private Criticality criticality;
*
* @param criticality New value for Criticality
* @return Performance Counter Criticality
*/
private Criticality criticality;
/**
* Performance Counter Name
*
/**
* Performance Counter Name
*
* @return Performance Counter Name
*/
private String name;
* @return Performance Counter Name
*/
private String name;
- /**
- * Performance Counter Threshold Crossed
+
+ /**
+ * Performance Counter for Threshold Crossed.
*
* @param thresholdCrossed New value for Performance Counter Threshold Crossed
* @return Performance Counter Threshold Crossed
*/
private String thresholdCrossed;
*
* @param thresholdCrossed New value for Performance Counter Threshold Crossed
* @return Performance Counter Threshold Crossed
*/
private String thresholdCrossed;
- * Performance Counter Value
+ * Performance Counter Value.
*
* @param value New Performance Counter Value
* @return Performance Counter Value
*/
private String value;
*
* @param value New Performance Counter Value
* @return Performance Counter Value
*/
private String value;
*/
public enum Priority implements CEFModel {
*/
public enum Priority implements CEFModel {
- High, Medium, Normal, Low;
-
+ High,
+ Medium,
+ Normal,
+ Low
package org.openecomp.dcae.apod.analytics.model.domain.cef;
package org.openecomp.dcae.apod.analytics.model.domain.cef;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Data;
import lombok.EqualsAndHashCode;
-import java.util.List;
-
/**
* Common Event Format - Fields Specific to threshold crossing alert events
*
/**
* Common Event Format - Fields Specific to threshold crossing alert events
*
private static final long serialVersionUID = 1L;
/**
private static final long serialVersionUID = 1L;
/**
- * Additional Performance counters
+ * Additional Performance counters parameters.
*
* @param additionalParameters New value for Additional Performance counters
* @return Additional Performance counters
*
* @param additionalParameters New value for Additional Performance counters
* @return Additional Performance counters
private List<PerformanceCounter> additionalParameters;
/**
private List<PerformanceCounter> additionalParameters;
/**
*
* @param alertAction New Event Action
*
* @param alertAction New Event Action
+ * @return Event alert action
*/
private AlertAction alertAction;
*/
private AlertAction alertAction;
* @return Version of the thresholdCrossingAlertFields block
*/
private Integer thresholdCrossingFieldsVersion;
* @return Version of the thresholdCrossingAlertFields block
*/
private Integer thresholdCrossingFieldsVersion;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Properties;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Properties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utility class containing methods for IO related operations
/**
* Utility class containing methods for IO related operations
* @param <T> binding Class Type
*
* @return binding Class Object which properties populated from JSON File Location
* @param <T> binding Class Type
*
* @return binding Class Object which properties populated from JSON File Location
+ * @throws IOException when fails to do IO operations
- public static final <T> T convertToJsonObject(String fileLocation, Class<T> bindingClass) {
+ public static final <T> T convertToJsonObject(String fileLocation, Class<T> bindingClass) throws IOException {
// Load Resource from give path
final InputStream resourceAsStream = loadResourceAsStream(fileLocation);
// Load Resource from give path
final InputStream resourceAsStream = loadResourceAsStream(fileLocation);
// If resource is null throw an exception
if (resourceAsStream == null) {
final String errorMessage = String.format("Invalid File location: %s", fileLocation);
// If resource is null throw an exception
if (resourceAsStream == null) {
final String errorMessage = String.format("Invalid File location: %s", fileLocation);
- throw new RuntimeException(errorMessage, new FileNotFoundException(errorMessage));
+ throw new IOException(errorMessage, new FileNotFoundException(errorMessage));
}
// Parse input stream
try (InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream, Charset.forName("UTF-8"))) {
return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(inputStreamReader, bindingClass);
}
// Parse input stream
try (InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream, Charset.forName("UTF-8"))) {
return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(inputStreamReader, bindingClass);
} catch (JsonMappingException | JsonParseException e) {
// If parsing fails due to Invalid Json or Json IO Issues throw an exception
} catch (JsonMappingException | JsonParseException e) {
// If parsing fails due to Invalid Json or Json IO Issues throw an exception
fileLocation);
LOG.error(errorMessage);
fileLocation);
LOG.error(errorMessage);
- throw new RuntimeException(errorMessage, e);
-
+ throw new IOException(errorMessage, e);
} catch (IOException e) {
// If parsing fails due to IO Issues throw an exception
final String errorMessage = String.format("IO Error while parsing Json File location: %s", fileLocation);
LOG.error(errorMessage);
} catch (IOException e) {
// If parsing fails due to IO Issues throw an exception
final String errorMessage = String.format("IO Error while parsing Json File location: %s", fileLocation);
LOG.error(errorMessage);
- throw new RuntimeException(errorMessage, e);
-
+ throw new IOException(errorMessage, e);
// If properties file is not present throw an exception
if (propertiesFileInputStream == null) {
final String errorMessage = String.format("Invalid Properties File at location: %s",
// If properties file is not present throw an exception
if (propertiesFileInputStream == null) {
final String errorMessage = String.format("Invalid Properties File at location: %s",
- propertiesFileLocation);
+ propertiesFileLocation);
+ //TODO: discuss and change this excpeiton as well.
throw new RuntimeException(errorMessage, new FileNotFoundException(errorMessage));
}
throw new RuntimeException(errorMessage, new FileNotFoundException(errorMessage));
}
// Load Resource from give path
return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileLocation);
}
// Load Resource from give path
return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileLocation);
}
* @author Rajiv Singla. Creation Date: 08/15/2017.
*/
public abstract class BaseCEFModelMixin extends BaseDynamicPropertiesProviderMixin {
* @author Rajiv Singla. Creation Date: 08/15/2017.
*/
public abstract class BaseCEFModelMixin extends BaseDynamicPropertiesProviderMixin {
* @author Rajiv Singla. Creation Date: 08/15/2017.
*/
public abstract class EventListenerMixin extends BaseCEFModelMixin {
* @author Rajiv Singla. Creation Date: 08/15/2017.
*/
public abstract class EventListenerMixin extends BaseCEFModelMixin {
* @author Rajiv Singla. Creation Date: 08/15/2017.
*/
public abstract class EventMixin extends BaseCEFModelMixin {
* @author Rajiv Singla. Creation Date: 08/15/2017.
*/
public abstract class EventMixin extends BaseCEFModelMixin {
protected static ObjectMapper objectMapper;
protected static ObjectMapper objectMapper;
+ /**
+ * Before running test cases need to assign object mapper.
+ */
@BeforeClass
public static void beforeClass() {
final AnalyticsModelObjectMapperSupplier analyticsModelObjectMapperSupplier =
@BeforeClass
public static void beforeClass() {
final AnalyticsModelObjectMapperSupplier analyticsModelObjectMapperSupplier =
- * Deserialize given Json file location to given model class and returns it back without any validation check
+ * Deserialize given Json file location to given model class and returns it back without any validation check.
*
* @param jsonFileLocation Classpath location of the json file
* @param modelClass Model Class type
*
* @param jsonFileLocation Classpath location of the json file
* @param modelClass Model Class type
/**
* Deserialize given Json file location to given model class and then validates deserialization by comparing it
/**
* Deserialize given Json file location to given model class and then validates deserialization by comparing it
- * with given expected Object
+ * with given expected Object.
*
* @param jsonFileLocation Classpath location of the json file
* @param modelClass Model Class type
*
* @param jsonFileLocation Classpath location of the json file
* @param modelClass Model Class type
+ /**
+ * Serialize model to json.
+ * @param model model
+ * @return json
+ * @throws JsonProcessingException when fails to process object
+ */
public static String serializeModelToJson(Object model) throws JsonProcessingException {
return objectMapper.writeValueAsString(model);
}
/**
public static String serializeModelToJson(Object model) throws JsonProcessingException {
return objectMapper.writeValueAsString(model);
}
/**
- * Converts given model to json string and compare it with json present at given file location
+ * Converts given model to json string and compare it with json present at given file location.
*
* @param model Model which needs to be compared
* @param expectedJsonFileLocation Location of file containing expected json string
*
* @param model Model which needs to be compared
* @param expectedJsonFileLocation Location of file containing expected json string
assertJson(expectedModelString, actualModelString);
return model;
} catch (IOException | JSONException ex) {
assertJson(expectedModelString, actualModelString);
return model;
} catch (IOException | JSONException ex) {
- LOG.error("Error while doing assert Json serialization Assertion: model: {}, " +
- "expected Json File Location: {}, Exception {}", model, expectedJsonFileLocation, ex);
+ LOG.error("Error while doing assert Json serialization Assertion: model: {}, "
+ + "expected Json File Location: {}, Exception {}", model, expectedJsonFileLocation, ex);
throw new RuntimeException(ex);
}
throw new RuntimeException(ex);
}
}
/**
* Checks both serialization and deserialization.
}
/**
* Checks both serialization and deserialization.
* First checks deserialization and then serialize the deserialized object back to json
* and check if matches the given json file location string
*
* First checks deserialization and then serialize the deserialized object back to json
* and check if matches the given json file location string
*
public class AAITest extends BaseAnalyticsModelUnitTest {
private AAI aai;
public class AAITest extends BaseAnalyticsModelUnitTest {
private AAI aai;
+ private static final String GENERIC_VNF_ID = "testVNFID";
+ private static final String CHANGED_GENERIC_VNF_ID = "changedVNFID";
@Before
public void before() {
@Before
public void before() {
}
@Test
public void getGenericVNFId() throws Exception {
}
@Test
public void getGenericVNFId() throws Exception {
- final String genericVNFId = "testVNFID";
- aai.setGenericVNFId(genericVNFId);
- assertThat("VNFID must be same", aai.getGenericVNFId(), is(genericVNFId));
+ aai.setGenericVNFId(GENERIC_VNF_ID);
+ assertThat("VNFID must be same", aai.getGenericVNFId(), is(GENERIC_VNF_ID));
}
@Test
public void setGenericVNFId() throws Exception {
final String genericVNFId = "testVNFID";
}
@Test
public void setGenericVNFId() throws Exception {
final String genericVNFId = "testVNFID";
- aai.setGenericVNFId(genericVNFId);
- final String changedGenericVNFId = "changedVNFID";
- aai.setGenericVNFId(changedGenericVNFId);
- assertThat("VNFID must be same as changed VNFID", aai.getGenericVNFId(), is(changedGenericVNFId));
-
+ aai.setGenericVNFId(GENERIC_VNF_ID);
+ aai.setGenericVNFId(CHANGED_GENERIC_VNF_ID);
+ assertThat("VNFID must be same as changed VNFID", aai.getGenericVNFId(), is(CHANGED_GENERIC_VNF_ID));
*/
public class TCAVESResponseTest extends BaseAnalyticsModelUnitTest {
*/
public class TCAVESResponseTest extends BaseAnalyticsModelUnitTest {
- final String tcaVESCEFResponseJsonFileLocation = "data/json/facade/tca_ves_cef_response.json";
-
+ private static final String TCA_VES_CEF_RESPONSE_JSON_FILE_LOCATION = "data/json/facade/tca_ves_cef_response.json";
@Test
public void testTCAPolicyJsonConversions() throws Exception {
final TCAVESResponse vesCEFMessageResponse =
@Test
public void testTCAPolicyJsonConversions() throws Exception {
final TCAVESResponse vesCEFMessageResponse =
- assertJsonConversions(tcaVESCEFResponseJsonFileLocation, TCAVESResponse.class);
+ assertJsonConversions(TCA_VES_CEF_RESPONSE_JSON_FILE_LOCATION, TCAVESResponse.class);
assertThat("VES CEF Message Response AAI generics VNF Id must match",
vesCEFMessageResponse.getAai().getGenericVNFId(), is("vpp-test(?)"));
assertThat("VES CEF Message Response AAI generics VNF Id must match",
vesCEFMessageResponse.getAai().getGenericVNFId(), is("vpp-test(?)"));
vesCEFMessageResponse.getClosedLoopEventStatus(), is("ONSET"));
}
vesCEFMessageResponse.getClosedLoopEventStatus(), is("ONSET"));
}
assertEquals("App Description much with json settings file value", "Test App Description", appDescription);
}
assertEquals("App Description much with json settings file value", "Test App Description", appDescription);
}
- @Test(expected = RuntimeException.class)
+ @Test(expected = IOException.class)
public void testConvertToJsonObjectWhenFileLocationIsInvValid() throws Exception {
AnalyticsModelIOUtils.convertToJsonObject("InvalidFileLocation", ConfigHolder.class);
}
public void testConvertToJsonObjectWhenFileLocationIsInvValid() throws Exception {
AnalyticsModelIOUtils.convertToJsonObject("InvalidFileLocation", ConfigHolder.class);
}
- @Test(expected = RuntimeException.class)
+ @Test(expected = IOException.class)
public void testConvertToJsonObjectWhenJsonFileHasInvalidJson() throws Exception {
AnalyticsModelIOUtils.convertToJsonObject(INVALID_TEST_CONFIG_FILE_LOCATION, ConfigHolder.class);
}
public void testConvertToJsonObjectWhenJsonFileHasInvalidJson() throws Exception {
AnalyticsModelIOUtils.convertToJsonObject(INVALID_TEST_CONFIG_FILE_LOCATION, ConfigHolder.class);
}
@Test
public void testValidPropertiesFileLoading() throws Exception {
final Properties properties =
@Test
public void testValidPropertiesFileLoading() throws Exception {
final Properties properties =
final Properties mockProperties = Mockito.mock(Properties.class);
doThrow(new IOException()).when(mockProperties).load(any(InputStream.class));
AnalyticsModelIOUtils.loadPropertiesFile(TEST_PROPERTIES_FILE_LOCATION, mockProperties);
final Properties mockProperties = Mockito.mock(Properties.class);
doThrow(new IOException()).when(mockProperties).load(any(InputStream.class));
AnalyticsModelIOUtils.loadPropertiesFile(TEST_PROPERTIES_FILE_LOCATION, mockProperties);
return appDescription;
}
}
return appDescription;
}
}
*/
public class TCAVESResponseMixinTest extends BaseAnalyticsModelUnitTest {
*/
public class TCAVESResponseMixinTest extends BaseAnalyticsModelUnitTest {
- final String tcaVESCEFResponseJsonFileLocation = "data/json/facade/tca_ves_cef_response.json";
+ private static final String TCA_VES_CEF_RESPONSE_JSON_FILE_LOCATION = "data/json/facade/tca_ves_cef_response.json";
@Test
public void testTCAPolicyJsonConversions() throws Exception {
final TCAVESResponse vesCEFMessageResponse =
@Test
public void testTCAPolicyJsonConversions() throws Exception {
final TCAVESResponse vesCEFMessageResponse =
- assertJsonConversions(tcaVESCEFResponseJsonFileLocation, TCAVESResponse.class);
+ assertJsonConversions(TCA_VES_CEF_RESPONSE_JSON_FILE_LOCATION, TCAVESResponse.class);
assertThat("VES CEF Message Response AAI generics VNF Id must match",
vesCEFMessageResponse.getAai().getGenericVNFId(), is("vpp-test(?)"));
assertThat("VES CEF Message Response AAI generics VNF Id must match",
vesCEFMessageResponse.getAai().getGenericVNFId(), is("vpp-test(?)"));
vesCEFMessageResponse.getTargetType(), is("VNF"));
testSerialization(vesCEFMessageResponse, getClass());
vesCEFMessageResponse.getTargetType(), is("VNF"));
testSerialization(vesCEFMessageResponse, getClass());
*/
public class TCAPolicyMixinTest extends BaseAnalyticsModelUnitTest {
*/
public class TCAPolicyMixinTest extends BaseAnalyticsModelUnitTest {
- final String tcaPolicyJsonFileLocation = "data/json/policy/tca_policy.json";
+ private static final String TCA_POLICY_JSON_FILE_LOCATION = "data/json/policy/tca_policy.json";
@Test
public void testTCAPolicyJsonConversions() throws Exception {
@Test
public void testTCAPolicyJsonConversions() throws Exception {
- final TCAPolicy tcaPolicy = assertJsonConversions(tcaPolicyJsonFileLocation, TCAPolicy.class);
+ final TCAPolicy tcaPolicy = assertJsonConversions(TCA_POLICY_JSON_FILE_LOCATION, TCAPolicy.class);
assertThat("TCA Policy Metrics Per Event Name must be 2",
tcaPolicy.getMetricsPerEventName().size(), is(2));
assertThat("TCA Policy Metrics Per Event Name must be 2",
tcaPolicy.getMetricsPerEventName().size(), is(2));
tcaPolicy.getMetricsPerEventName().get(0).getThresholds().size(), is(3));
testSerialization(tcaPolicy, getClass());
tcaPolicy.getMetricsPerEventName().get(0).getThresholds().size(), is(3));
testSerialization(tcaPolicy, getClass());
final String newLine = System.getProperty("line.separator");
String line = reader.readLine();
while (line != null) {
final String newLine = System.getProperty("line.separator");
String line = reader.readLine();
while (line != null) {
- result.append(line);
- result.append(newLine);
+ result.append(line)
+ .append(newLine);
line = reader.readLine();
}
jsonFileInputStream.close();
line = reader.readLine();
}
jsonFileInputStream.close();
* @author Rajiv Singla . Creation Date: 10/6/2016.
*/
public abstract class BaseDCAEAnalyticsUnitTest extends BaseDCAEAnalyticsCommonTest {
* @author Rajiv Singla . Creation Date: 10/6/2016.
*/
public abstract class BaseDCAEAnalyticsUnitTest extends BaseDCAEAnalyticsCommonTest {
private static final Logger LOG = LoggerFactory.getLogger(GuiceJUnitRunner.class);
private static final Logger LOG = LoggerFactory.getLogger(GuiceJUnitRunner.class);
- private Injector injector;
+ private final Injector injector;
public GuiceJUnitRunner(Class<?> klass) throws InitializationError {
super(klass);
public GuiceJUnitRunner(Class<?> klass) throws InitializationError {
super(klass);
Module[] modules = new Module[classes.length];
for (int i = 0; i < classes.length; i++) {
try {
Module[] modules = new Module[classes.length];
for (int i = 0; i < classes.length; i++) {
try {
- modules[i] = (Module) (classes[i]).newInstance();
+ modules[i] = (Module) classes[i].newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new InitializationError(e);
}
} catch (InstantiationException | IllegalAccessException e) {
throw new InitializationError(e);
}